| 672 | } |
| 673 | |
| 674 | bool OurReader::readObject(Token& token) { |
| 675 | Token tokenName; |
| 676 | StringContainer name; |
| 677 | Value init(objectValue); |
| 678 | currentValue().swapPayload(init); |
| 679 | currentValue().setOffsetStart(token.start_ - begin_); |
| 680 | while (readTokenSkippingComments(tokenName)) { |
| 681 | if (tokenName.type_ == tokenObjectEnd && (name.empty() || features_.allowTrailingCommas_)) { // empty object or trailing comma |
| 682 | return true; |
| 683 | } |
| 684 | name.clear(); |
| 685 | if (tokenName.type_ == tokenString) { |
| 686 | if (!decodeString(tokenName, name)) |
| 687 | return recoverFromError(tokenObjectEnd); |
| 688 | } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { |
| 689 | Value numberName; |
| 690 | if (!decodeNumber(tokenName, numberName)) |
| 691 | return recoverFromError(tokenObjectEnd); |
| 692 | name = numberName.asString(); |
| 693 | } else { |
| 694 | break; |
| 695 | } |
| 696 | if (name.length() >= (1U << 30)) |
| 697 | throwRuntimeError("keylength >= 2^30"); |
| 698 | if (features_.rejectDupKeys_ && currentValue().isMember(name)) { |
| 699 | StringContainer msg = "Duplicate key: '" + name + "'"; |
| 700 | return addErrorAndRecover(msg, tokenName, tokenObjectEnd); |
| 701 | } |
| 702 | |
| 703 | Token colon; |
| 704 | if (!readToken(colon) || colon.type_ != tokenMemberSeparator) { |
| 705 | return addErrorAndRecover("Missing ':' after object member name", colon, tokenObjectEnd); |
| 706 | } |
| 707 | Value& value = currentValue()[name]; |
| 708 | nodes_.push(&value); |
| 709 | bool ok = readValue(); |
| 710 | nodes_.pop(); |
| 711 | if (!ok) { // error already set |
| 712 | return recoverFromError(tokenObjectEnd); |
| 713 | } |
| 714 | |
| 715 | Token comma; |
| 716 | if (!readTokenSkippingComments(comma) || |
| 717 | (comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator)) { |
| 718 | return addErrorAndRecover("Missing ',' or '}' in object declaration", |
| 719 | comma, tokenObjectEnd); |
| 720 | } |
| 721 | if (comma.type_ == tokenObjectEnd) |
| 722 | return true; |
| 723 | } |
| 724 | return addErrorAndRecover("Missing '}' or object member name", tokenName, |
| 725 | tokenObjectEnd); |
| 726 | } |
| 727 | |
| 728 | bool OurReader::readArray(Token& token) { |
| 729 | Value init(arrayValue); |
nothing calls this directly
no test coverage detected