private String readName() throws IOException { if (current=='"' || current=='\'') return readStringInternal(false); StringBuilder name=new StringBuilder(); int space=-1, start=index; while (true) { if (current==':') { if (name.length()==0) throw error("Found ':' but no key name (for an empty key name use quotes)"); else if (space>=0 && space!=name.length()) { index=start+space; throw error("Found whitespace in your key name (use quotes to include)"); } return name.toString(); } else if (isWhiteSpace(current)) { if (space<0) space=name.length(); } else if (current<' ') { throw error("Name is not closed"); } else if (JsonValue.isPunctuatorChar(current)) { throw error("Found '" + (char)current + "' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)"); } else name.append((char)current); read(); } }
private String readName() throws IOException { if (current=='"' || current=='\'') return readStringInternal(false); StringBuilder name=new StringBuilder(); int space=-1, start=index; while (true) { if (current==':') { if (name.length()==0) throw error("Found ':' but no key name (for an empty key name use quotes)"); else if (space>=0 && space!=name.length()) { index=start+space; throw error("Found whitespace in your key name (use quotes to include)"); } return name.toString(); } else if (isWhiteSpace(current)) { if (space<0) space=name.length(); } else if (current<' ') { throw error("Name is not closed"); } else if (JsonValue.isPunctuatorChar(current)) { throw error("Found '" + (char)current + "' where a key name was expected (check your syntax or use quotes if the key name includes {}[],: or whitespace)"); } else name.append((char)current); read(); } }
JsonValue checkTrailing(JsonValue v) throws ParseException, IOException { skipWhiteSpace(); if (!isEndOfText()) throw error("Extra characters in input: "+current); return v; }
JsonValue checkTrailing(JsonValue v) throws ParseException, IOException { skipWhiteSpace(); if (!isEndOfText()) throw error("Extra characters in input: "+current); return v; }
int first=current; if (JsonValue.isPunctuatorChar(first)) throw error("Found a punctuator character '" + (char)first + "' when expecting a quoteless string (check your syntax)"); value.append((char)current); for (;;) {
int first=current; if (JsonValue.isPunctuatorChar(first)) throw error("Found a punctuator character '" + (char)first + "' when expecting a quoteless string (check your syntax)"); value.append((char)current); for (;;) {
if (current<0) throw error("Bad multiline string"); else if (current=='\'') { triple++;
if (current<0) throw error("Bad multiline string"); else if (current=='\'') { triple++;
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; }
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; }