private ParseException error(String message) { int column=index-lineOffset; int offset=isEndOfText()?index:index-1; return new ParseException(message, offset, line, column-1); }
private ParseException error(String message) { int column=index-lineOffset; int offset=isEndOfText()?index:index-1; return new ParseException(message, offset, line, column-1); }
JsonValue checkTrailing(JsonValue v) throws ParseException, IOException { skipWhiteSpace(); if (!isEndOfText()) throw error("Extra characters in input: "+current); return v; }
private ParseException expected(String expected) { if (isEndOfText()) { return error("Unexpected end of input"); } return error("Expected "+expected); }
JsonValue checkTrailing(JsonValue v) throws ParseException, IOException { skipWhiteSpace(); if (!isEndOfText()) throw error("Extra characters in input: "+current); return v; }
private ParseException expected(String expected) { if (isEndOfText()) { return error("Unexpected end of input"); } return error("Expected "+expected); }
private JsonObject readObject(boolean objectWithoutBraces) throws IOException { if (!objectWithoutBraces) read(); JsonObject object=new JsonObject(); skipWhiteSpace(); while (true) { if (objectWithoutBraces) { if (isEndOfText()) break; } else { if (isEndOfText()) throw error("End of input while parsing an object (did you forget a closing '}'?)"); if (readIf('}')) break; } String name=readName(); skipWhiteSpace(); if (!readIf(':')) { throw expected("':'"); } skipWhiteSpace(); object.add(name, readValue()); skipWhiteSpace(); if (readIf(',')) skipWhiteSpace(); // , is optional } return object; }
private JsonObject readObject(boolean objectWithoutBraces) throws IOException { if (!objectWithoutBraces) read(); JsonObject object=new JsonObject(); skipWhiteSpace(); while (true) { if (objectWithoutBraces) { if (isEndOfText()) break; } else { if (isEndOfText()) throw error("End of input while parsing an object (did you forget a closing '}'?)"); if (readIf('}')) break; } String name=readName(); skipWhiteSpace(); if (!readIf(':')) { throw expected("':'"); } skipWhiteSpace(); object.add(name, readValue()); skipWhiteSpace(); if (readIf(',')) skipWhiteSpace(); // , is optional } return object; }
private void skipWhiteSpace() throws IOException { while (!isEndOfText()) { while (isWhiteSpace()) read(); if (current=='#' || current=='/' && peek()=='/') { do { read(); } while (current>=0 && current!='\n'); } else if (current=='/' && peek()=='*') { read(); do { read(); } while (current>=0 && !(current=='*' && peek()=='/')); read(); read(); } else break; } }
private void skipWhiteSpace() throws IOException { while (!isEndOfText()) { while (isWhiteSpace()) read(); if (current=='#' || current=='/' && peek()=='/') { do { read(); } while (current>=0 && current!='\n'); } else if (current=='/' && peek()=='*') { read(); do { read(); } while (current>=0 && !(current=='*' && peek()=='/')); read(); read(); } else break; } }
private JsonArray readArray() throws IOException { read(); JsonArray array=new JsonArray(); skipWhiteSpace(); if (readIf(']')) { return array; } while (true) { skipWhiteSpace(); array.add(readValue()); skipWhiteSpace(); if (readIf(',')) skipWhiteSpace(); // , is optional if (readIf(']')) break; else if (isEndOfText()) throw error("End of input while parsing an array (did you forget a closing ']'?)"); } return array; }
private JsonArray readArray() throws IOException { read(); JsonArray array=new JsonArray(); skipWhiteSpace(); if (readIf(']')) { return array; } while (true) { skipWhiteSpace(); array.add(readValue()); skipWhiteSpace(); if (readIf(',')) skipWhiteSpace(); // , is optional if (readIf(']')) break; else if (isEndOfText()) throw error("End of input while parsing an array (did you forget a closing ']'?)"); } return array; }