private int hexval(int hexdig) { if (hexdig>='0' && hexdig <='9') { return hexdig-'0'; } else if (hexdig>='A' && hexdig <='F') { return hexdig+(10-'A'); } else if (hexdig>='a' && hexdig <='f') { return hexdig+(10-'a'); } throw err("invalid hex digit"); }
private final void pop() { if (--ptr<0) { throw err("Unbalanced container"); } else { state = stack[ptr]; } }
private final void pop() { if (--ptr<0) { throw err("Unbalanced container"); } else { state = stack[ptr]; } }
private int hexval(int hexdig) { if (hexdig>='0' && hexdig <='9') { return hexdig-'0'; } else if (hexdig>='A' && hexdig <='F') { return hexdig+(10-'A'); } else if (hexdig>='a' && hexdig <='f') { return hexdig+(10-'a'); } throw err("invalid hex digit"); }
private void getMore() throws IOException { fill(); if (start>=end) { throw err(null); } }
private void getMore() throws IOException { fill(); if (start>=end) { throw err(null); } }
protected void handleNonDoubleQuoteString(int ch, boolean isName) throws IOException { if (ch == '\'') { stringTerm = ch; if ((flags & ALLOW_SINGLE_QUOTES) == 0) { throw err("Single quoted strings not allowed"); } } else { if (isName && (flags & ALLOW_UNQUOTED_KEYS) == 0 || !isName && (flags & ALLOW_UNQUOTED_STRING_VALUES) == 0 || eof) { if (isName) { throw err("Expected quoted string"); } else { throw err(null); } } if (!isUnquotedStringStart(ch)) { throw err(null); } stringTerm = 0; // signal for unquoted string out.reset(); out.unsafeWrite(ch); } }
protected void handleNonDoubleQuoteString(int ch, boolean isName) throws IOException { if (ch == '\'') { stringTerm = ch; if ((flags & ALLOW_SINGLE_QUOTES) == 0) { throw err("Single quoted strings not allowed"); } } else { if (isName && (flags & ALLOW_UNQUOTED_KEYS) == 0 || !isName && (flags & ALLOW_UNQUOTED_STRING_VALUES) == 0 || eof) { if (isName) { throw err("Expected quoted string"); } else { throw err(null); } } if (!isUnquotedStringStart(ch)) { throw err(null); } stringTerm = 0; // signal for unquoted string out.reset(); out.unsafeWrite(ch); } }
/** Returns the characters of a JSON numeric value. * <p/>The underlying buffer of the returned <code>CharArr</code> should *not* be * modified as it may be shared with the input buffer. * <p/>The returned <code>CharArr</code> will only be valid up until * the next JSONParser method is called. Any required data should be * read before that point. */ public CharArr getNumberChars() throws IOException { int ev=0; if (valstate==0) ev = nextEvent(); if (valstate == LONG || valstate == NUMBER) { valstate=0; return out; } else if (valstate==BIGNUMBER) { continueNumber(out); valstate=0; return out; } else { throw err("Unexpected " + ev); } }
/** Reads a JSON numeric value into the output. */ public void getNumberChars(CharArr output) throws IOException { int ev=0; if (valstate==0) ev=nextEvent(); if (valstate == LONG || valstate == NUMBER) output.write(this.out); else if (valstate==BIGNUMBER) { continueNumber(output); } else { throw err("Unexpected " + ev); } valstate=0; }
/** Returns the characters of a JSON numeric value. * <p/>The underlying buffer of the returned <code>CharArr</code> should *not* be * modified as it may be shared with the input buffer. * <p/>The returned <code>CharArr</code> will only be valid up until * the next JSONParser method is called. Any required data should be * read before that point. */ public CharArr getNumberChars() throws IOException { int ev=0; if (valstate==0) ev = nextEvent(); if (valstate == LONG || valstate == NUMBER) { valstate=0; return out; } else if (valstate==BIGNUMBER) { continueNumber(out); valstate=0; return out; } else { throw err("Unexpected " + ev); } }
/** Reads a JSON numeric value into the output. */ public void getNumberChars(CharArr output) throws IOException { int ev=0; if (valstate==0) ev=nextEvent(); if (valstate == LONG || valstate == NUMBER) output.write(this.out); else if (valstate==BIGNUMBER) { continueNumber(output); } else { throw err("Unexpected " + ev); } valstate=0; }
private int readExp(CharArr arr, int lim) throws IOException { nstate |= HAS_EXPONENT; int ch = getChar(); lim--; if (ch=='+' || ch=='-') { arr.write(ch); ch = getChar(); lim--; } // make sure at least one digit is read. if (ch<'0' || ch>'9') { throw err("missing exponent number"); } arr.write(ch); return readExpDigits(arr,lim); }
private int readExp(CharArr arr, int lim) throws IOException { nstate |= HAS_EXPONENT; int ch = getChar(); lim--; if (ch=='+' || ch=='-') { arr.write(ch); ch = getChar(); lim--; } // make sure at least one digit is read. if (ch<'0' || ch>'9') { throw err("missing exponent number"); } arr.write(ch); return readExpDigits(arr,lim); }
protected void getSlashComment() throws IOException { int ch = getChar(); if (ch == '/') { getNewlineComment(); return; } if (ch != '*') { throw err("Invalid comment: expected //, /*, or #"); } ch = getChar(); for (;;) { if (ch == '*') { ch = getChar(); if (ch == '/') { return; } else if (ch == '*') { // handle cases of *******/ continue; } } if (ch == -1) { return; } ch = getChar(); } }
protected void getSlashComment() throws IOException { int ch = getChar(); if (ch == '/') { getNewlineComment(); return; } if (ch != '*') { throw err("Invalid comment: expected //, /*, or #"); } ch = getChar(); for (;;) { if (ch == '*') { ch = getChar(); if (ch == '/') { return; } else if (ch == '*') { // handle cases of *******/ continue; } } if (ch == -1) { return; } ch = getChar(); } }
private char readEscapedChar() throws IOException { int ch = getChar(); switch (ch) { case '"' : return '"'; case '\'' : return '\''; case '\\' : return '\\'; case '/' : return '/'; case 'n' : return '\n'; case 'r' : return '\r'; case 't' : return '\t'; case 'f' : return '\f'; case 'b' : return '\b'; case 'u' : return (char)( (hexval(getChar()) << 12) | (hexval(getChar()) << 8) | (hexval(getChar()) << 4) | (hexval(getChar()))); } if ( (flags & ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER) != 0 && ch != EOF) { return (char)ch; } throw err("Invalid character escape"); }
private char readEscapedChar() throws IOException { int ch = getChar(); switch (ch) { case '"' : return '"'; case '\'' : return '\''; case '\\' : return '\\'; case '/' : return '/'; case 'n' : return '\n'; case 'r' : return '\r'; case 't' : return '\t'; case 'f' : return '\f'; case 'b' : return '\b'; case 'u' : return (char)( (hexval(getChar()) << 12) | (hexval(getChar()) << 8) | (hexval(getChar()) << 4) | (hexval(getChar()))); } if ( (flags & ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER) != 0 && ch != EOF) { return (char)ch; } throw err("Invalid character escape"); }