@Override protected char get(int index) { return internal.get(index); }
@Override protected char get() { return internal.get(); }
/** * 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)); }
private boolean isNextSurrogate() { if (!hasNext()) return false; char c = get(position()); return CharUtils.isHighSurrogate(c) || CharUtils.isLowSurrogate(c); }
/** * 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; }