/** * Get the text up but not including the specified character or the * end of line, whichever comes first. * @param delimiter A delimiter character. * @return A string. */ public String nextTo(char delimiter) throws JSONException { StringBuilder sb = new StringBuilder(); for (;;) { char c = this.next(); if (c == delimiter || c == 0 || c == '\n' || c == '\r') { if (c != 0) { this.back(); } return sb.toString().trim(); } sb.append(c); } }
/** * Get the text up but not including one of the specified delimiter * characters or the end of line, whichever comes first. * @param delimiters A set of delimiter characters. * @return A string, trimmed. */ public String nextTo(String delimiters) throws JSONException { char c; StringBuilder sb = new StringBuilder(); for (;;) { c = this.next(); if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') { if (c != 0) { this.back(); } return sb.toString().trim(); } sb.append(c); } }
/** * Get the text up but not including the specified character or the * end of line, whichever comes first. * @param delimiter A delimiter character. * @return A string. * @throws JSONException Thrown if there is an error while searching * for the delimiter */ public String nextTo(char delimiter) throws JSONException { StringBuilder sb = new StringBuilder(); for (;;) { char c = this.next(); if (c == delimiter || c == 0 || c == '\n' || c == '\r') { if (c != 0) { this.back(); } return sb.toString().trim(); } sb.append(c); } }
/** * Get the text up but not including one of the specified delimiter * characters or the end of line, whichever comes first. * @param delimiters A set of delimiter characters. * @return A string, trimmed. * @throws JSONException Thrown if there is an error while searching * for the delimiter */ public String nextTo(String delimiters) throws JSONException { char c; StringBuilder sb = new StringBuilder(); for (;;) { c = this.next(); if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') { if (c != 0) { this.back(); } return sb.toString().trim(); } sb.append(c); } }
/** * Determine if the source string still contains characters that next() * can consume. * @return true if not yet at the end of the source. */ public boolean more() throws JSONException { this.next(); if (this.end()) { return false; } this.back(); return true; }
/** * Skip characters until the next character is the requested character. * If the requested character is not found, no characters are skipped. * @param to A character to skip to. * @return The requested character, or zero if the requested character * is not found. */ public char skipTo(char to) throws JSONException { char c; try { long startIndex = this.index; long startCharacter = this.character; long startLine = this.line; this.reader.mark(1000000); do { c = this.next(); if (c == 0) { this.reader.reset(); this.index = startIndex; this.character = startCharacter; this.line = startLine; return c; } } while (c != to); } catch (IOException exception) { throw new JSONException(exception); } this.back(); return c; }
private Object parse(String json) throws JSONException { JSONTokener tokener = new JSONTokener(json); char c = tokener.nextClean(); //peak ahead tokener.back(); //revert if (c == '{') { //json object JSONObject o = new JSONObject(tokener); return toMap(o); } else if (c == '[') { JSONArray a = new JSONArray(tokener); return toList(a); } else { //raw json value Object value = tokener.nextValue(); return convertIfNecessary(value); } }
throw new JSONException(exception); this.back(); return c;
/** * Get the text up but not including one of the specified delimiter * characters or the end of line, whichever comes first. * @param delimiters A set of delimiter characters. * @return A string, trimmed. * @throws JSONException Thrown if there is an error while searching * for the delimiter */ public String nextTo(String delimiters) throws JSONException { char c; StringBuilder sb = new StringBuilder(); for (;;) { c = this.next(); if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') { if (c != 0) { this.back(); } return sb.toString().trim(); } sb.append(c); } }
/** * Get the text up but not including the specified character or the * end of line, whichever comes first. * @param delimiter A delimiter character. * @return A string. * @throws JSONException Thrown if there is an error while searching * for the delimiter */ public String nextTo(char delimiter) throws JSONException { StringBuilder sb = new StringBuilder(); for (;;) { char c = this.next(); if (c == delimiter || c == 0 || c == '\n' || c == '\r') { if (c != 0) { this.back(); } return sb.toString().trim(); } sb.append(c); } }
throw new JSONException(exception); this.back(); return c;