private boolean ensureEnoughData(int size) { if (!eof && pointer + size >= dataLength) { update(); } return (this.pointer + size) < dataLength; }
public StreamReader(Reader reader) { this.name = "'reader'"; this.buffer = ""; this.stream = reader; this.eof = false; this.data = new char[BUFFER_SIZE]; this.update(); }
private boolean ensureEnoughData(int size) { if (!eof && pointer + size >= dataLength) { update(); } return (this.pointer + size) < dataLength; }
public StreamReader(Reader reader) { this.name = "'reader'"; this.buffer = ""; this.stream = reader; this.eof = false; this.data = new char[1024]; this.update(); }
/** * Peek the next index-th character * * @param index * @return the next index-th character */ public char peek(int index) { if (this.pointer + index + 1 > this.buffer.length()) { update(); } return this.buffer.charAt(this.pointer + index); }
public int peek() { if (this.pointer == this.buffer.length()) { update(); } if (this.pointer == this.buffer.length()) { return -1; } return this.buffer.codePointAt(this.pointer); }
/** * peek the next length characters * * @param length * @return the next length characters */ public String prefix(int length) { if (this.pointer + length >= this.buffer.length()) { update(); } if (this.pointer + length > this.buffer.length()) { return this.buffer.substring(this.pointer); } return this.buffer.substring(this.pointer, this.pointer + length); }
/** * Peek the next index-th code point * * @param index * @return the next index-th code point */ public int peek(int index) { int offset = 0; int nextIndex = 0; int codePoint; do { if (this.pointer + offset == this.buffer.length()) { update(); } if (this.pointer + offset == this.buffer.length()) { return -1; } codePoint = this.buffer.codePointAt(this.pointer + offset); offset += Character.charCount(codePoint); nextIndex++; } while (nextIndex <= index); return codePoint; }
/** * peek the next length code points * * @param length * @return the next length code points */ public String prefix(int length) { final StringBuilder builder = new StringBuilder(); int offset = 0; int resultLength = 0; while (resultLength < length) { if (this.pointer + offset == this.buffer.length()) { update(); } if (this.pointer + offset == this.buffer.length()) { break; } int c = this.buffer.codePointAt(this.pointer + offset); builder.appendCodePoint(c); offset += Character.charCount(c); resultLength++; } return builder.toString(); }
/** * read the next length characters and move the pointer. * if the last character is high surrogate one more character will be read * * @param length */ public void forward(int length) { int c; for (int i = 0; i < length; i++) { if (this.pointer == this.buffer.length()) { update(); } if (this.pointer == this.buffer.length()) { break; } c = this.buffer.codePointAt(this.pointer); this.pointer += Character.charCount(c); this.index += Character.charCount(c); if (Constant.LINEBR.has(c) || (c == '\r' && buffer.charAt(pointer) != '\n')) { this.line++; this.column = 0; } else if (c != 0xFEFF) { this.column++; } } if (this.pointer == this.buffer.length()) { update(); } }
/** * read the next length characters and move the pointer. * * @param length */ public void forward(int length) { if (this.pointer + length + 1 >= this.buffer.length()) { update(); } char ch = 0; for (int i = 0; i < length; i++) { ch = this.buffer.charAt(this.pointer); this.pointer++; this.index++; if (Constant.LINEBR.has(ch) || (ch == '\r' && buffer.charAt(pointer) != '\n')) { this.line++; this.column = 0; } else if (ch != '\uFEFF') { this.column++; } } }