@Override public int limit() { return internal.limit(); }
/** * Set the iterator position */ public void position(int n) { if (n < 0 || n > limit()) throw new ArrayIndexOutOfBoundsException(n); position = n; }
/** * Return the final index position */ public int lastPosition() { int p = position(); return (p > -1) ? (p >= limit()) ? p : p - 1 : -1; }
/** * Returns true if the char at the specified index is a high surrogate */ public boolean isHigh(int index) { if (index < 0 || index > limit()) throw new ArrayIndexOutOfBoundsException(index); return CharUtils.isHighSurrogate(get(index)); }
/** * Returns true if the char at the specified index is a low surrogate */ public boolean isLow(int index) { if (index < 0 || index > limit()) throw new ArrayIndexOutOfBoundsException(index); return CharUtils.isLowSurrogate(get(index)); }
/** * Peek the specified chars in the iterator. If the codepoint is not supplemental, the char array will have a single * member. If the codepoint is supplemental, the char array will have two members, representing the high and low * surrogate chars */ private char[] peekChars(int pos) throws InvalidCharacterException { if (pos < 0 || pos >= limit()) return null; char c1 = get(pos); if (CharUtils.isHighSurrogate(c1) && pos < limit()) { char c2 = get(pos + 1); if (CharUtils.isLowSurrogate(c2)) { return new char[] {c1, c2}; } else { throw new InvalidCharacterException(c2); } } else if (CharUtils.isLowSurrogate(c1) && pos > 1) { char c2 = get(pos - 1); if (CharUtils.isHighSurrogate(c2)) { return new char[] {c2, c1}; } else { throw new InvalidCharacterException(c2); } } else return new char[] {c1}; }
/** * Return the next chars. If the codepoint is not supplemental, the char array will have a single member. If the * codepoint is supplemental, the char array will have two members, representing the high and low surrogate chars */ public char[] nextChars() throws InvalidCharacterException { if (hasNext()) { if (isNextSurrogate()) { char c1 = get(); if (CharUtils.isHighSurrogate(c1) && position() < limit()) { char c2 = get(); if (CharUtils.isLowSurrogate(c2)) { return new char[] {c1, c2}; } else { throw new InvalidCharacterException(c2); } } else if (CharUtils.isLowSurrogate(c1) && position() > 0) { char c2 = get(position() - 2); if (CharUtils.isHighSurrogate(c2)) { return new char[] {c1, c2}; } else { throw new InvalidCharacterException(c2); } } } return new char[] {get()}; } return null; }