| 332 | |
| 333 | template<class Stream> |
| 334 | bool JsonSkipper<Stream>::SkipNumber() { |
| 335 | // Please note that in standard JSON, number literals must start with a digit or a |
| 336 | // minus sign (in the case of negative numbers). Positive numbers should be written |
| 337 | // directly without a '+', and '0.123' should not be abbreviated as '.123'. |
| 338 | // Numbers starting with '.' or '+' in JSON are considered invalid values, which is |
| 339 | // consistent with the behavior of rapidjson. |
| 340 | // Despite the fact that special values such as Inf and NaN are not supported in |
| 341 | // standard JSON (they are considered invalid values), rapidjson does support them. |
| 342 | // We have already enabled the parsing flag kParseNanAndInfFlag in the |
| 343 | // JsonParser::Parse() to support parsing Inf and NaN, so this function also supports |
| 344 | // them accordingly. |
| 345 | Consume('-'); |
| 346 | if (UNLIKELY(s_.Peek() == '0')) { |
| 347 | s_.Take(); |
| 348 | } else if (LIKELY(s_.Peek() >= '1' && s_.Peek() <= '9')) { |
| 349 | while (LIKELY(s_.Peek() >= '0' && s_.Peek() <= '9')) s_.Take(); |
| 350 | } else if (LIKELY(s_.Peek() == 'N')) { |
| 351 | s_.Take(); |
| 352 | ERROR_IF_FALSE(Consume('a'), kParseErrorValueInvalid); |
| 353 | ERROR_IF_FALSE(Consume('N'), kParseErrorValueInvalid); |
| 354 | return true; |
| 355 | } else if (LIKELY(s_.Peek() == 'I')) { |
| 356 | s_.Take(); |
| 357 | ERROR_IF_FALSE(Consume('n'), kParseErrorValueInvalid); |
| 358 | ERROR_IF_FALSE(Consume('f'), kParseErrorValueInvalid); |
| 359 | if (UNLIKELY(s_.Peek() == 'i')) { |
| 360 | s_.Take(); |
| 361 | ERROR_IF_FALSE(Consume('n'), kParseErrorValueInvalid); |
| 362 | ERROR_IF_FALSE(Consume('i'), kParseErrorValueInvalid); |
| 363 | ERROR_IF_FALSE(Consume('t'), kParseErrorValueInvalid); |
| 364 | ERROR_IF_FALSE(Consume('y'), kParseErrorValueInvalid); |
| 365 | } |
| 366 | return true; |
| 367 | } else ERROR_IF_FALSE(false, kParseErrorValueInvalid); |
| 368 | |
| 369 | if (Consume('.')) { |
| 370 | ERROR_IF_FALSE(s_.Peek() >= '0' && s_.Peek() <= '9', kParseErrorNumberMissFraction); |
| 371 | while (LIKELY(s_.Peek() >= '0' && s_.Peek() <= '9')) s_.Take(); |
| 372 | } |
| 373 | |
| 374 | if (Consume('e') || Consume('E')) { |
| 375 | if (!Consume('+')) Consume('-'); |
| 376 | ERROR_IF_FALSE(s_.Peek() >= '0' && s_.Peek() <= '9', kParseErrorNumberMissExponent); |
| 377 | while (LIKELY(s_.Peek() >= '0' && s_.Peek() <= '9')) s_.Take(); |
| 378 | } |
| 379 | return true; |
| 380 | } |
| 381 | |
| 382 | template<class Stream> |
| 383 | bool JsonSkipper<Stream>::SkipObject() { |