in solr/solrj/src/java/org/noggit/JSONParser.java [881:1019]
private int next(int ch) throws IOException {
// TODO: try my own form of indirect jump... look up char class and index directly into handling
// implementation?
for (; ; ) {
switch (ch) {
// this is not the exclusive list of whitespace chars... the rest are handled in default:
case ' ':
case '\t':
case '\r':
case '\n':
// calling getCharNWS here seems faster than letting the switch handle it
ch = getCharNWS();
break;
case '"':
stringTerm = '"';
valstate = STRING;
return STRING;
case '\'':
if ((flags & ALLOW_SINGLE_QUOTES) == 0) {
throw err("Single quoted strings not allowed");
}
stringTerm = '\'';
valstate = STRING;
return STRING;
case '{':
push();
state = DID_OBJSTART;
return OBJECT_START;
case '[':
push();
state = DID_ARRSTART;
return ARRAY_START;
case '0':
out.reset();
// special case '0'? If next char isn't '.' val=0
ch = getChar();
if (ch == '.') {
start--;
ch = '0';
readNumber('0', false);
return valstate;
} else if (ch > '9' || ch < '0') {
out.unsafeWrite('0');
if (ch != -1) start--;
lval = 0;
valstate = LONG;
return LONG;
} else {
throw err("Leading zeros not allowed");
}
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
out.reset();
lval = readNumber(ch, false);
return valstate;
case '-':
out.reset();
out.unsafeWrite('-');
ch = getChar();
if (ch < '0' || ch > '9') throw err("expected digit after '-'");
lval = readNumber(ch, true);
return valstate;
case 't':
// TODO: test performance of this non-branching inline version.
// if ((('r'-getChar())|('u'-getChar())|('e'-getChar())) != 0) throw err("");
if (matchBareWord(JSONUtil.TRUE_CHARS)) {
bool = true;
valstate = BOOLEAN;
return valstate;
} else {
valstate = STRING;
return STRING;
}
case 'f':
if (matchBareWord(JSONUtil.FALSE_CHARS)) {
bool = false;
valstate = BOOLEAN;
return valstate;
} else {
valstate = STRING;
return STRING;
}
case 'n':
if (matchBareWord(JSONUtil.NULL_CHARS)) {
valstate = NULL;
return valstate;
} else {
valstate = STRING;
return STRING;
}
case '/':
getSlashComment();
ch = getChar();
break;
case '#':
getNewlineComment();
ch = getChar();
break;
case ']': // This only happens with a trailing comma (or an error)
if (state != DID_ARRELEM || (flags & ALLOW_EXTRA_COMMAS) == 0) {
throw err("Unexpected array closer ]");
}
pop();
return event = ARRAY_END;
case '}': // This only happens with a trailing comma (or an error)
if (state != DID_MEMVAL || (flags & ALLOW_EXTRA_COMMAS) == 0) {
throw err("Unexpected object closer }");
}
pop();
return event = ARRAY_END;
case ',': // This only happens with input like [1,]
if ((state != DID_ARRELEM && state != DID_MEMVAL) || (flags & ALLOW_EXTRA_COMMAS) == 0) {
throw err("Unexpected comma");
}
ch = getChar();
break;
case -1:
if (getLevel() > 0) throw err("Premature EOF");
return EOF;
default:
// Handle unusual unicode whitespace like no-break space (0xA0)
if (isWhitespace(ch)) {
ch = getChar(); // getCharNWS() would also work
break;
}
handleNonDoubleQuoteString(ch, false);
valstate = STRING;
return STRING;
// throw err(null);
}
}
}