private void readRequiredChar(char ch) throws IOException { if (!readIf(ch)) { throw expected("'"+ch+"'"); } }
private String readName() throws IOException { if (current!='"') { throw expected("name"); } return readStringInternal(); }
private String readName() throws IOException { if (current!='"') { throw expected("name"); } return readStringInternal(); }
private void readRequiredChar(char ch) throws IOException { if (!readIf(ch)) { throw expected("'"+ch+"'"); } }
private boolean readFraction() throws IOException { if (!readIf('.')) { return false; } if (!readDigit()) { throw expected("digit"); } while (readDigit()) { } return true; }
private boolean readFraction() throws IOException { if (!readIf('.')) { return false; } if (!readDigit()) { throw expected("digit"); } while (readDigit()) { } return true; }
private JsonValue readNumber() throws IOException { startCapture(); readIf('-'); int firstDigit=current; if (!readDigit()) { throw expected("digit"); } if (firstDigit!='0') { while (readDigit()) { } } readFraction(); readExponent(); return new JsonNumber(Double.parseDouble(endCapture())); }
private JsonValue readNumber() throws IOException { startCapture(); readIf('-'); int firstDigit=current; if (!readDigit()) { throw expected("digit"); } if (firstDigit!='0') { while (readDigit()) { } } readFraction(); readExponent(); return new JsonNumber(Double.parseDouble(endCapture())); }
private boolean readExponent() throws IOException { if (!readIf('e') && !readIf('E')) { return false; } if (!readIf('+')) { readIf('-'); } if (!readDigit()) { throw expected("digit"); } while (readDigit()) { } return true; }
private boolean readExponent() throws IOException { if (!readIf('e') && !readIf('E')) { return false; } if (!readIf('+')) { readIf('-'); } if (!readDigit()) { throw expected("digit"); } while (readDigit()) { } return true; }
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 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 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 JsonValue readValue() throws IOException { switch(current) { case 'n': return readNull(); case 't': return readTrue(); case 'f': return readFalse(); case '"': return readString(); case '[': return readArray(); case '{': return readObject(); case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return readNumber(); default: throw expected("value"); } }
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 JsonValue readValue() throws IOException { switch(current) { case 'n': return readNull(); case 't': return readTrue(); case 'f': return readFalse(); case '"': return readString(); case '[': return readArray(); case '{': return readObject(); case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return readNumber(); default: throw expected("value"); } }
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 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; }