| 587 | // Parse object: { string : value, ... } |
| 588 | template<unsigned parseFlags, typename InputStream, typename Handler> |
| 589 | void ParseObject(InputStream& is, Handler& handler) { |
| 590 | RAPIDJSON_ASSERT(is.Peek() == '{'); |
| 591 | is.Take(); // Skip '{' |
| 592 | |
| 593 | if (RAPIDJSON_UNLIKELY(!handler.StartObject())) |
| 594 | RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); |
| 595 | |
| 596 | SkipWhitespaceAndComments<parseFlags>(is); |
| 597 | RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; |
| 598 | |
| 599 | if (Consume(is, '}')) { |
| 600 | if (RAPIDJSON_UNLIKELY(!handler.EndObject(0))) // empty object |
| 601 | RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); |
| 602 | return; |
| 603 | } |
| 604 | |
| 605 | for (SizeType memberCount = 0;;) { |
| 606 | if (RAPIDJSON_UNLIKELY(is.Peek() != '"')) |
| 607 | RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissName, is.Tell()); |
| 608 | |
| 609 | ParseString<parseFlags>(is, handler, true); |
| 610 | RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; |
| 611 | |
| 612 | SkipWhitespaceAndComments<parseFlags>(is); |
| 613 | RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; |
| 614 | |
| 615 | if (RAPIDJSON_UNLIKELY(!Consume(is, ':'))) |
| 616 | RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissColon, is.Tell()); |
| 617 | |
| 618 | SkipWhitespaceAndComments<parseFlags>(is); |
| 619 | RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; |
| 620 | |
| 621 | ParseValue<parseFlags>(is, handler); |
| 622 | RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; |
| 623 | |
| 624 | SkipWhitespaceAndComments<parseFlags>(is); |
| 625 | RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; |
| 626 | |
| 627 | ++memberCount; |
| 628 | |
| 629 | switch (is.Peek()) { |
| 630 | case ',': |
| 631 | is.Take(); |
| 632 | SkipWhitespaceAndComments<parseFlags>(is); |
| 633 | RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID; |
| 634 | break; |
| 635 | case '}': |
| 636 | is.Take(); |
| 637 | if (RAPIDJSON_UNLIKELY(!handler.EndObject(memberCount))) |
| 638 | RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell()); |
| 639 | return; |
| 640 | default: |
| 641 | RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, is.Tell()); break; // This useless break is only for making warning and coverage happy |
| 642 | } |
| 643 | |
| 644 | if (parseFlags & kParseTrailingCommasFlag) { |
| 645 | if (is.Peek() == '}') { |
| 646 | if (RAPIDJSON_UNLIKELY(!handler.EndObject(memberCount))) |
nothing calls this directly
no test coverage detected