MCPcopy
hub / github.com/google/gson / doPeek

Method doPeek

gson/src/main/java/com/google/gson/stream/JsonReader.java:581–730  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

579 }
580
581 @SuppressWarnings("fallthrough")
582 int doPeek() throws IOException {
583 int peekStack = stack[stackSize - 1];
584 if (peekStack == JsonScope.EMPTY_ARRAY) {
585 stack[stackSize - 1] = JsonScope.NONEMPTY_ARRAY;
586 } else if (peekStack == JsonScope.NONEMPTY_ARRAY) {
587 // Look for a comma before the next element.
588 int c = nextNonWhitespace(true);
589 switch (c) {
590 case ']':
591 peeked = PEEKED_END_ARRAY;
592 return peeked;
593 case ';':
594 checkLenient(); // fall-through
595 case ',':
596 break;
597 default:
598 throw syntaxError("Unterminated array");
599 }
600 } else if (peekStack == JsonScope.EMPTY_OBJECT || peekStack == JsonScope.NONEMPTY_OBJECT) {
601 stack[stackSize - 1] = JsonScope.DANGLING_NAME;
602 // Look for a comma before the next element.
603 if (peekStack == JsonScope.NONEMPTY_OBJECT) {
604 int c = nextNonWhitespace(true);
605 switch (c) {
606 case '}':
607 peeked = PEEKED_END_OBJECT;
608 return peeked;
609 case ';':
610 checkLenient(); // fall-through
611 case ',':
612 break;
613 default:
614 throw syntaxError("Unterminated object");
615 }
616 }
617 int c = nextNonWhitespace(true);
618 switch (c) {
619 case '"':
620 peeked = PEEKED_DOUBLE_QUOTED_NAME;
621 return peeked;
622 case '\'':
623 checkLenient();
624 peeked = PEEKED_SINGLE_QUOTED_NAME;
625 return peeked;
626 case '}':
627 if (peekStack != JsonScope.NONEMPTY_OBJECT) {
628 peeked = PEEKED_END_OBJECT;
629 return peeked;
630 } else {
631 throw syntaxError("Expected name");
632 }
633 default:
634 checkLenient();
635 pos--; // Don't consume the first character in an unquoted string.
636 if (isLiteral((char) c)) {
637 peeked = PEEKED_UNQUOTED_NAME;
638 return peeked;

Callers 15

beginArrayMethod · 0.95
endArrayMethod · 0.95
beginObjectMethod · 0.95
endObjectMethod · 0.95
hasNextMethod · 0.95
peekMethod · 0.95
nextNameMethod · 0.95
nextStringMethod · 0.95
nextBooleanMethod · 0.95
nextNullMethod · 0.95
nextDoubleMethod · 0.95
nextLongMethod · 0.95

Calls 8

nextNonWhitespaceMethod · 0.95
checkLenientMethod · 0.95
syntaxErrorMethod · 0.95
isLiteralMethod · 0.95
fillBufferMethod · 0.95
peekKeywordMethod · 0.95
peekNumberMethod · 0.95

Tested by

no test coverage detected