String consumeToEnd() { bufferUp(); String data = cacheString(charBuf, stringCache, bufPos, bufLength - bufPos); bufPos = bufLength; return data; }
String consumeDigitSequence() { bufferUp(); int start = bufPos; while (bufPos < bufLength) { char c = charBuf[bufPos]; if (c >= '0' && c <= '9') bufPos++; else break; } return cacheString(charBuf, stringCache, start, bufPos - start); }
String consumeHexSequence() { bufferUp(); int start = bufPos; while (bufPos < bufLength) { char c = charBuf[bufPos]; if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')) bufPos++; else break; } return cacheString(charBuf, stringCache, start, bufPos - start); }
String consumeToAnySorted(final char... chars) { bufferUp(); final int start = bufPos; final int remaining = bufLength; final char[] val = charBuf; while (bufPos < remaining) { if (Arrays.binarySearch(chars, val[bufPos]) >= 0) break; bufPos++; } return bufPos > start ? cacheString(charBuf, stringCache, start, bufPos -start) : ""; }
String consumeLetterSequence() { bufferUp(); int start = bufPos; while (bufPos < bufLength) { char c = charBuf[bufPos]; if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || Character.isLetter(c)) bufPos++; else break; } return cacheString(charBuf, stringCache, start, bufPos - start); }
String consumeTagName() { // '\t', '\n', '\r', '\f', ' ', '/', '>', nullChar bufferUp(); final int start = bufPos; final int remaining = bufLength; final char[] val = charBuf; while (bufPos < remaining) { final char c = val[bufPos]; if (c == '\t'|| c == '\n'|| c == '\r'|| c == '\f'|| c == ' '|| c == '/'|| c == '>'|| c == TokeniserState.nullChar) break; bufPos++; } return bufPos > start ? cacheString(charBuf, stringCache, start, bufPos -start) : ""; }
String consumeData() { // &, <, null bufferUp(); final int start = bufPos; final int remaining = bufLength; final char[] val = charBuf; while (bufPos < remaining) { final char c = val[bufPos]; if (c == '&'|| c == '<' || c == TokeniserState.nullChar) break; bufPos++; } return bufPos > start ? cacheString(charBuf, stringCache, start, bufPos -start) : ""; }
/** * Read characters until the first of any delimiters is found. * @param chars delimiters to scan for * @return characters read up to the matched delimiter. */ public String consumeToAny(final char... chars) { bufferUp(); final int start = bufPos; final int remaining = bufLength; final char[] val = charBuf; OUTER: while (bufPos < remaining) { for (char c : chars) { if (val[bufPos] == c) break OUTER; } bufPos++; } return bufPos > start ? cacheString(charBuf, stringCache, start, bufPos -start) : ""; }
String consumeTo(String seq) { int offset = nextIndexOf(seq); if (offset != -1) { String consumed = cacheString(charBuf, stringCache, bufPos, offset); bufPos += offset; return consumed; } else { return consumeToEnd(); } }
String consumeLetterThenDigitSequence() { bufferUp(); int start = bufPos; while (bufPos < bufLength) { char c = charBuf[bufPos]; if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || Character.isLetter(c)) bufPos++; else break; } while (!isEmptyNoBufferUp()) { char c = charBuf[bufPos]; if (c >= '0' && c <= '9') bufPos++; else break; } return cacheString(charBuf, stringCache, start, bufPos - start); }
/** * Reads characters up to the specific char. * @param c the delimiter * @return the chars read */ public String consumeTo(char c) { int offset = nextIndexOf(c); if (offset != -1) { String consumed = cacheString(charBuf, stringCache, bufPos, offset); bufPos += offset; return consumed; } else { return consumeToEnd(); } }