/** * Returns the next {@code length} characters of the input. * * <p>The returned string shares its backing character array with this * tokener's input string. If a reference to the returned string may be held * indefinitely, you should use {@code new String(result)} to copy it first * to avoid memory leaks. * * @throws JSONException if the remaining input is not long enough to * satisfy this request. */ public String next(int length) throws JSONException { if (pos + length > in.length()) { throw syntaxError(length + " is out of bounds"); } String result = in.substring(pos, pos + length); pos += length; return result; }
/** * Returns the next {@code length} characters of the input. * * <p> * The returned string shares its backing character array with this tokener's input string. If a * reference to the returned string may be held indefinitely, you should use * {@code new String(result)} to copy it first to avoid memory leaks. * * @param length The desired number of characters to return. * @return The next few characters. * @throws JSONException if the remaining input is not long enough to satisfy this request. */ public String next(int length) throws JSONException { if (pos + length > in.length()) { throw syntaxError(length + " is out of bounds"); } String result = in.substring(pos, pos + length); pos += length; return result; }
/** * Consume the next character, and check that it matches a specified * character. * @param c The character to match. * @return The character. * @throws JSONException if the character does not match. */ public char next(char c) throws JSONException { char n = this.next(); if (n != c) { if(n > 0) { throw this.syntaxError("Expected '" + c + "' and instead saw '" + n + "'"); } throw this.syntaxError("Expected '" + c + "' and instead saw ''"); } return n; }
/** * Returns the next available character if it equals {@code c}. Otherwise an * exception is thrown. */ public char next(char c) throws JSONException { char result = next(); if (result != c) { throw syntaxError("Expected " + c + " but was " + result); } return result; }
/** * Consume the next character, and check that it matches a specified * character. * @param c The character to match. * @return The character. * @throws JSONException if the character does not match. */ public char next(char c) throws JSONException { char n = this.next(); if (n != c) { throw this.syntaxError("Expected '" + c + "' and instead saw '" + n + "'"); } return n; }
/** * Returns the next available character if it equals {@code c}. Otherwise an exception is thrown. * * @param c The character we are looking for. * @return the next character. * @throws JSONException If the next character isn't {@code c} */ public char next(char c) throws JSONException { char result = next(); if (result != c) { throw syntaxError("Expected " + c + " but was " + result); } return result; }
case 'u': if (pos + 4 > in.length()) { throw syntaxError("Unterminated escape sequence"); return (char) Integer.parseInt(hex, 16); } catch (NumberFormatException nfe) { throw syntaxError("Invalid escape sequence: " + hex);
case 'u': if (pos + 4 > in.length()) { throw syntaxError("Unterminated escape sequence");
throw syntaxError("Unterminated escape sequence"); throw syntaxError("Unterminated string");
/** * Get the next n characters. * * @param n The number of characters to take. * @return A string of n characters. * @throws JSONException * Substring bounds error if there are not * n characters remaining in the source string. */ public String next(int n) throws JSONException { if (n == 0) { return ""; } char[] chars = new char[n]; int pos = 0; while (pos < n) { chars[pos] = this.next(); if (this.end()) { throw this.syntaxError("Substring bounds error"); } pos += 1; } return new String(chars); }
switch (nextCleanInternal()) { case -1: throw syntaxError("Unterminated array"); case ']': if (hasTrailingSeparator) { continue; default: throw syntaxError("Unterminated array");
switch (nextCleanInternal()) { case -1: throw syntaxError("Unterminated array"); case ']': if (hasTrailingSeparator) { continue; default: throw syntaxError("Unterminated array");
/** * Get the next n characters. * * @param n The number of characters to take. * @return A string of n characters. * @throws JSONException * Substring bounds error if there are not * n characters remaining in the source string. */ public String next(int n) throws JSONException { if (n == 0) { return ""; } char[] chars = new char[n]; int pos = 0; while (pos < n) { chars[pos] = this.next(); if (this.end()) { throw this.syntaxError("Substring bounds error"); } pos += 1; } return new String(chars); }
return ja; throw x.syntaxError("Bad character '" + c + "' (" + (int)c + ").");
throw this.syntaxError("Missing value");
throw x.syntaxError("A JSONObject text must begin with '{'"); switch (c) { case 0: throw x.syntaxError("A JSONObject text must end with '}'"); case '}': return; throw x.syntaxError("Expected a ':' after a key"); return; default: throw x.syntaxError("Expected a ',' or '}'");
this(); if (x.nextClean() != '[') { throw x.syntaxError("A JSONArray text must start with '['"); return; default: throw x.syntaxError("Expected a ',' or ']'");
this(); if (x.nextClean() != '[') { throw x.syntaxError("A JSONArray text must start with '['"); return; default: throw x.syntaxError("Expected a ',' or ']'");
/** * Returns the next value from the input. * * @return a {@link JSONObject}, {@link JSONArray}, String, Boolean, * Integer, Long, Double or {@link JSONObject#NULL}. * @throws JSONException if the input is malformed. */ public Object nextValue() throws JSONException { int c = nextCleanInternal(); switch (c) { case -1: throw syntaxError("End of input"); case '{': return readObject(); case '[': return readArray(); case '\'': case '"': return nextString((char) c); default: pos--; return readLiteral(); } }
/** * Returns the next value from the input. * * @return a {@link JSONObject}, {@link JSONArray}, String, Boolean, Integer, Long, Double or * {@link JSONObject#NULL}. * @throws JSONException if the input is malformed. */ public Object nextValue() throws JSONException { int c = nextCleanInternal(); switch (c) { case -1: throw syntaxError("End of input"); case '{': return readObject(); case '[': return readArray(); case '\'': case '"': return nextString((char) c); default: pos--; return readLiteral(); } }