public int nextEvent()

in solr/solrj/src/java/org/noggit/JSONParser.java [1044:1150]


  public int nextEvent() throws IOException {
    if (valstate != 0) {
      if (valstate == STRING) {
        readStringChars2(devNull, start);
      } else if (valstate == BIGNUMBER) {
        continueNumber(devNull);
      }
      valstate = 0;
    }

    int ch;
    outer:
    for (; ; ) {
      switch (state) {
        case 0:
          event = next(getChar());
          if (event == STRING && (flags & OPTIONAL_OUTER_BRACES) != 0) {
            if (start > 0) start--;
            missingOpeningBrace = true;
            stringTerm = 0;
            valstate = 0;
            event = next('{');
          }
          return event;
        case DID_OBJSTART:
          ch = getCharExpected('"');
          if (ch == '}') {
            pop();
            return event = OBJECT_END;
          }
          if (ch == '"') {
            stringTerm = ch;
          } else if (ch == ',' && (flags & ALLOW_EXTRA_COMMAS) != 0) {
            continue outer;
          } else {
            handleNonDoubleQuoteString(ch, true);
          }
          state = DID_MEMNAME;
          valstate = STRING;
          return event = STRING;
        case DID_MEMNAME:
          ch = getCharExpected(':');
          if (ch != ':') {
            if ((ch == '{' || ch == '[')
                && (flags & ALLOW_MISSING_COLON_COMMA_BEFORE_OBJECT) != 0) {
              start--;
            } else {
              throw err("Expected key,value separator ':'");
            }
          }
          state = DID_MEMVAL; // set state first because it might be pushed...
          return event = next(getChar());
        case DID_MEMVAL:
          ch = getCharExpected(',');
          if (ch == '}') {
            pop();
            return event = OBJECT_END;
          } else if (ch != ',') {
            if ((flags & ALLOW_EXTRA_COMMAS) != 0
                && (ch == '\'' || ch == '"' || Character.isLetter(ch))) {
              start--;
            } else if (missingOpeningBrace && ch == -1 && (flags & OPTIONAL_OUTER_BRACES) != 0) {
              missingOpeningBrace = false;
              pop();
              return event = OBJECT_END;
            } else throw err("Expected ',' or '}'");
          }
          ch = getCharExpected('"');
          if (ch == '"') {
            stringTerm = ch;
          } else if ((ch == ',' || ch == '}') && (flags & ALLOW_EXTRA_COMMAS) != 0) {
            if (ch == ',') continue outer;
            pop();
            return event = OBJECT_END;
          } else {
            handleNonDoubleQuoteString(ch, true);
          }
          state = DID_MEMNAME;
          valstate = STRING;
          return event = STRING;
        case DID_ARRSTART:
          ch = getCharNWS();
          if (ch == ']') {
            pop();
            return event = ARRAY_END;
          }
          state = DID_ARRELEM; // set state first, might be pushed...
          return event = next(ch);
        case DID_ARRELEM:
          ch = getCharExpected(',');
          if (ch == ',') {
            // state = DID_ARRELEM;  // redundant
            return event = next(getChar());
          } else if (ch == ']') {
            pop();
            return event = ARRAY_END;
          } else {
            if ((ch == '{' || ch == '[')
                && (flags & ALLOW_MISSING_COLON_COMMA_BEFORE_OBJECT) != 0) {
              return event = next(ch);
            } else {
              throw err("Expected ',' or ']'");
            }
          }
      }
    } // end for(;;)
  }