/** * Determine if the source string still contains characters that next() * can consume.<p> * * @return true if not yet at the end of the source * @throws JSONException if something goes wrong */ public boolean more() throws JSONException { char nextChar = next(); if (nextChar == 0) { return false; } back(); return true; }
/** * Determine if the source string still contains characters that next() * can consume.<p> * * @return true if not yet at the end of the source * @throws JSONException if something goes wrong */ public boolean more() throws JSONException { char nextChar = next(); if (nextChar == 0) { return false; } back(); return true; }
/** * Get the text up but not including one of the specified delimiter * characters or the end of line, whichever comes first.<p> * * @param delimiters a set of delimiter characters * @return a string, trimmed * @throws JSONException if something goes wrong */ public String nextTo(String delimiters) throws JSONException { 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 text up but not including the specified character or the * end of line, whichever comes first.<p> * * @param d a delimiter character * @return a string * @throws JSONException if something goes wrong */ public String nextTo(char d) throws JSONException { 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); } }
/** * Get the text up but not including the specified character or the * end of line, whichever comes first.<p> * * @param d a delimiter character * @return a string * @throws JSONException if something goes wrong */ public String nextTo(char d) throws JSONException { 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); } }
/** * Get the text up but not including one of the specified delimiter * characters or the end of line, whichever comes first.<p> * * @param delimiters a set of delimiter characters * @return a string, trimmed * @throws JSONException if something goes wrong */ public String nextTo(String delimiters) throws JSONException { 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); } }
/** * Skip characters until the next character is the requested character. * If the requested character is not found, no characters are skipped.<p> * * @param to a character to skip to * @return the requested character, or zero if the requested character * is not found * @throws JSONException if something goes wrong */ public char skipTo(char to) throws JSONException { char c; try { int startIndex = m_index; m_reader.mark(Integer.MAX_VALUE); do { c = next(); if (c == 0) { m_reader.reset(); m_index = startIndex; return c; } } while (c != to); } catch (IOException exc) { throw new JSONException(exc); } back(); return c; }
/** * Skip characters until the next character is the requested character. * If the requested character is not found, no characters are skipped.<p> * * @param to a character to skip to * @return the requested character, or zero if the requested character * is not found * @throws JSONException if something goes wrong */ public char skipTo(char to) throws JSONException { char c; try { int startIndex = this.m_index; m_reader.mark(Integer.MAX_VALUE); do { c = next(); if (c == 0) { m_reader.reset(); this.m_index = startIndex; return c; } } while (c != to); } catch (IOException exc) { throw new JSONException(exc); } back(); return c; }
/** * Get the next value. The value can be wrapped in quotes. The value can * be empty.<p> * * @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 == '\t')); switch (c) { case 0: return null; case '"': case '\'': return x.nextString(c); case ',': x.back(); return ""; default: x.back(); return x.nextTo(','); } } }
/** * Get the next value. The value can be wrapped in quotes. The value can * be empty.<p> * * @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 == '\t'); switch (c) { case 0: return null; case '"': case '\'': return x.nextString(c); case ',': x.back(); return ""; default: x.back(); return x.nextTo(','); } } }