protected int getCharExpected(int expected) throws IOException { for(;;) { int ch = getChar(); if (ch==expected) return expected; if (ch==' ') continue; return getCharNWS(ch); } }
protected void getNewlineComment() throws IOException { // read a # or a //, so go until newline for (;;) { int ch = getChar(); // don't worry about DOS /r/n... we'll stop on the \r and let the rest of the whitespace // eater consume the \n if (ch == '\n' || ch == '\r' || ch == -1) { return; } } }
protected void getNewlineComment() throws IOException { // read a # or a //, so go until newline for (;;) { int ch = getChar(); // don't worry about DOS /r/n... we'll stop on the \r and let the rest of the whitespace // eater consume the \n if (ch == '\n' || ch == '\r' || ch == -1) { return; } } }
protected int getCharExpected(int expected) throws IOException { for(;;) { int ch = getChar(); if (ch==expected) return expected; if (ch==' ') continue; return getCharNWS(ch); } }
private int readExpDigits(CharArr arr, int lim) throws IOException { while (--lim>=0) { int ch = getChar(); if (ch>='0' && ch<='9') { arr.write(ch); } else { if (ch!=-1) start--; // back up return NUMBER; } } return BIGNUMBER; }
private int readExpDigits(CharArr arr, int lim) throws IOException { while (--lim>=0) { int ch = getChar(); if (ch>='0' && ch<='9') { arr.write(ch); } else { if (ch!=-1) start--; // back up return NUMBER; } } return BIGNUMBER; }
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"); }
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); }
private int readFrac(CharArr arr, int lim) throws IOException { nstate = HAS_FRACTION; // deliberate set instead of '|' while(--lim>=0) { int ch = getChar(); if (ch>='0' && ch<='9') { arr.write(ch); } else if (ch=='e' || ch=='E') { arr.write(ch); return readExp(arr,lim); } else { if (ch!=-1) start--; // back up return NUMBER; } } return BIGNUMBER; }
private int readFrac(CharArr arr, int lim) throws IOException { nstate = HAS_FRACTION; // deliberate set instead of '|' while(--lim>=0) { int ch = getChar(); if (ch>='0' && ch<='9') { arr.write(ch); } else if (ch=='e' || ch=='E') { arr.write(ch); return readExp(arr,lim); } else { if (ch!=-1) start--; // back up return NUMBER; } } return BIGNUMBER; }
protected int getCharNWS(int ch) throws IOException { for (;;) { // getCharNWS is normally called in the context of expecting certain JSON special characters // such as ":}"]," // all of these characters are below 64 (including comment chars '/' and '#', so we can make this the fast path // even w/o checking the range first. We'll only get some false-positives while using bare strings (chars "IJMc") if (((WS_MASK >> ch) & 0x01) == 0) { return ch; } else if (ch <= ' ') { // this will only be true if one of the whitespace bits was set // whitespace... get new char at bottom of loop } else if (ch == '/') { getSlashComment(); } else if (ch == '#') { getNewlineComment(); } else if (!isWhitespace(ch)) { // we'll only reach here with certain bare strings, errors, or strange whitespace like 0xa0 return ch; } ch = getChar(); } }
protected int getCharNWS(int ch) throws IOException { for (;;) { // getCharNWS is normally called in the context of expecting certain JSON special characters // such as ":}"]," // all of these characters are below 64 (including comment chars '/' and '#', so we can make this the fast path // even w/o checking the range first. We'll only get some false-positives while using bare strings (chars "IJMc") if (((WS_MASK >> ch) & 0x01) == 0) { return ch; } else if (ch <= ' ') { // this will only be true if one of the whitespace bits was set // whitespace... get new char at bottom of loop } else if (ch == '/') { getSlashComment(); } else if (ch == '#') { getNewlineComment(); } else if (!isWhitespace(ch)) { // we'll only reach here with certain bare strings, errors, or strange whitespace like 0xa0 return ch; } ch = getChar(); } }
private void readStringBare(CharArr arr) throws IOException { if (arr != out) { arr.append(out); } for(;;) { int ch = getChar(); if (!isUnquotedStringChar(ch)) { if (ch == -1) break; if (ch == '\\') { arr.write(readEscapedChar()); continue; } start--; break; } if (ch == '\\') { arr.write(readEscapedChar()); continue; } arr.write(ch); } }
private void readStringBare(CharArr arr) throws IOException { if (arr != out) { arr.append(out); } for(;;) { int ch = getChar(); if (!isUnquotedStringChar(ch)) { if (ch == -1) break; if (ch == '\\') { arr.write(readEscapedChar()); continue; } start--; break; } if (ch == '\\') { arr.write(readEscapedChar()); continue; } arr.write(ch); } }
private void continueNumber(CharArr arr) throws IOException { if (arr != out) arr.write(out); if ((nstate & HAS_EXPONENT)!=0){ readExpDigits(arr, Integer.MAX_VALUE); return; } if (nstate != 0) { readFrac(arr, Integer.MAX_VALUE); return; } for(;;) { int ch = getChar(); if (ch>='0' && ch <='9') { arr.write(ch); } else if (ch=='.') { arr.write(ch); readFrac(arr,Integer.MAX_VALUE); return; } else if (ch=='e' || ch=='E') { arr.write(ch); readExp(arr,Integer.MAX_VALUE); return; } else { if (ch!=-1) start--; return; } } }
private void continueNumber(CharArr arr) throws IOException { if (arr != out) arr.write(out); if ((nstate & HAS_EXPONENT)!=0){ readExpDigits(arr, Integer.MAX_VALUE); return; } if (nstate != 0) { readFrac(arr, Integer.MAX_VALUE); return; } for(;;) { int ch = getChar(); if (ch>='0' && ch <='9') { arr.write(ch); } else if (ch=='.') { arr.write(ch); readFrac(arr,Integer.MAX_VALUE); return; } else if (ch=='e' || ch=='E') { arr.write(ch); readExp(arr,Integer.MAX_VALUE); return; } else { if (ch!=-1) start--; return; } } }