| 204 | } |
| 205 | |
| 206 | std::unique_ptr<JsonLoader::Value> JsonLoader::parse_number() { |
| 207 | const char* p = m_buf; |
| 208 | |
| 209 | auto loop_digit = [this](const char*& p) { |
| 210 | if (not std::isdigit(*p)) { |
| 211 | m_state = State::BAD_DIGIT; |
| 212 | return; |
| 213 | } |
| 214 | while (std::isdigit(*p)) { |
| 215 | p++; |
| 216 | } |
| 217 | return; |
| 218 | }; |
| 219 | |
| 220 | if ('-' == *p) |
| 221 | p++; |
| 222 | if ('0' == *p) |
| 223 | p++; |
| 224 | else { |
| 225 | loop_digit(std::ref(p)); |
| 226 | } |
| 227 | if ('.' == *p) { |
| 228 | p++; |
| 229 | loop_digit(std::ref(p)); |
| 230 | } |
| 231 | |
| 232 | if ('e' == *p || 'E' == *p) { |
| 233 | p++; |
| 234 | if ('+' == *p || '-' == *p) |
| 235 | p++; |
| 236 | loop_digit(std::ref(p)); |
| 237 | } |
| 238 | std::unique_ptr<JsonLoader::NumberValue> pNum = |
| 239 | std::make_unique<JsonLoader::NumberValue>(); |
| 240 | pNum->m_value = strtod(m_buf, nullptr); |
| 241 | |
| 242 | m_buf = p; |
| 243 | |
| 244 | std::unique_ptr<JsonLoader::Value> ret = std::move(pNum); |
| 245 | return ret; |
| 246 | } |
| 247 | |
| 248 | std::unique_ptr<JsonLoader::Value> JsonLoader::parse_value() { |
| 249 | switch (*m_buf) { |