/** * Get the text up but not including the specified character or the * end of line, whichever comes first. * @param d A delimiter character. * @return A string. */ public String nextTo(char d) { StringBuffer sb = new StringBuffer(); for (;;) { char c = next(); if (c == d || c == 0 || c == '\n' || c == '\r') { if (c != 0) { back(); } return sb.toString().trim(); } sb.append(c); } }
/** * 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) { char c; int index = this.myIndex; do { c = next(); if (c == 0) { this.myIndex = index; return c; } } while (c != to); back(); return c; }
/** * Get the text up but not including one of the specified delimeter * 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) { char c; StringBuffer sb = new StringBuffer(); for (;;) { c = next(); if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') { if (c != 0) { back(); } return sb.toString().trim(); } sb.append(c); } }
/** * Get the next value. The value can be wrapped in quotes. The value can * be empty. * @param x A JSONTokener of the source text. * @return The value string, or null if empty. * @throws JSONException if the quoted string is badly formed. */ private static String getValue(JSONTokener x) throws JSONException { char c; do { c = x.next(); } while (c <= ' ' && c != 0); switch (c) { case 0: return null; case '"': case '\'': return x.nextString(c); case ',': x.back(); return ""; default: x.back(); return x.nextTo(','); } }
throw x.syntaxError("Detected unclosed array."); x.back(); for (;;) { if (x.nextClean() == ',') { x.back(); } else { x.back(); c = x.nextClean(); x.back(); if ( c == '{' || c == '[') { x.back(); break; case ']': return; case 0 : throw x.syntaxError("A JSONObject text must end with '}'"); case '}': return; default : x.back(); key = x.nextValue().toString(); x.back(); if ( c == '{' || c == '[') { x.back(); break; case '}': return;