private JsonValue readFalse() throws IOException { read(); readRequiredChar('a'); readRequiredChar('l'); readRequiredChar('s'); readRequiredChar('e'); return JsonValue.FALSE; }
private boolean readIf(char ch) throws IOException { if (current!=ch) { return false; } read(); return true; }
private JsonArray readArray() throws IOException { read(); JsonArray array=new JsonArray(); skipWhiteSpace(); if (readIf(']')) { return array; } do { skipWhiteSpace(); array.add(readValue()); skipWhiteSpace(); } while (readIf(',')); if (!readIf(']')) { throw expected("',' or ']'"); } return array; }
private JsonObject readObject() throws IOException { read(); JsonObject object=new JsonObject(); skipWhiteSpace(); if (readIf('}')) { return object; } do { skipWhiteSpace(); String name=readName(); skipWhiteSpace(); if (!readIf(':')) { throw expected("':'"); } skipWhiteSpace(); object.add(name, readValue()); skipWhiteSpace(); } while (readIf(',')); if (!readIf('}')) { throw expected("',' or '}'"); } return object; }
JsonValue parse() throws IOException { read(); skipWhiteSpace(); JsonValue result=readValue(); skipWhiteSpace(); if (!isEndOfText()) throw error("Unexpected character"); return result; }
private String readStringInternal() throws IOException { read(); startCapture(); while (current!='"') { if (current=='\\') { pauseCapture(); readEscape(); startCapture(); } else if (current<0x20) { throw expected("valid string character"); } else { read(); } } String string=endCapture(); read(); return string; }
private JsonObject readObject() throws IOException { read(); JsonObject object=new JsonObject(); skipWhiteSpace(); if (readIf('}')) { return object; } do { skipWhiteSpace(); String name=readName(); skipWhiteSpace(); if (!readIf(':')) { throw expected("':'"); } skipWhiteSpace(); object.add(name, readValue()); skipWhiteSpace(); } while (readIf(',')); if (!readIf('}')) { throw expected("',' or '}'"); } return object; }
private JsonValue readNull() throws IOException { read(); readRequiredChar('u'); readRequiredChar('l'); readRequiredChar('l'); return JsonValue.NULL; }
private JsonArray readArray() throws IOException { read(); JsonArray array=new JsonArray(); skipWhiteSpace(); if (readIf(']')) { return array; } do { skipWhiteSpace(); array.add(readValue()); skipWhiteSpace(); } while (readIf(',')); if (!readIf(']')) { throw expected("',' or ']'"); } return array; }
JsonValue parse() throws IOException { read(); skipWhiteSpace(); JsonValue result=readValue(); skipWhiteSpace(); if (!isEndOfText()) throw error("Unexpected character"); return result; }
private String readStringInternal() throws IOException { read(); startCapture(); while (current!='"') { if (current=='\\') { pauseCapture(); readEscape(); startCapture(); } else if (current<0x20) { throw expected("valid string character"); } else { read(); } } String string=endCapture(); read(); return string; }
private boolean readIf(char ch) throws IOException { if (current!=ch) { return false; } read(); return true; }
private JsonValue readTrue() throws IOException { read(); readRequiredChar('r'); readRequiredChar('u'); readRequiredChar('e'); return JsonValue.TRUE; }
private void skipWhiteSpace() throws IOException { while (isWhiteSpace()) { read(); } }
private JsonValue readNull() throws IOException { read(); readRequiredChar('u'); readRequiredChar('l'); readRequiredChar('l'); return JsonValue.NULL; }
private boolean readDigit() throws IOException { if (!isDigit()) { return false; } read(); return true; }
private JsonValue readTrue() throws IOException { read(); readRequiredChar('r'); readRequiredChar('u'); readRequiredChar('e'); return JsonValue.TRUE; }
private void skipWhiteSpace() throws IOException { while (isWhiteSpace()) { read(); } }
private JsonValue readFalse() throws IOException { read(); readRequiredChar('a'); readRequiredChar('l'); readRequiredChar('s'); readRequiredChar('e'); return JsonValue.FALSE; }
private boolean readDigit() throws IOException { if (!isDigit()) { return false; } read(); return true; }