@Override public Codepoint next() throws InvalidCharacterException { Codepoint cp = super.next(); int v = cp.getValue(); if (v != -1 && check(v)) { if (scanningOnly) { position(position() - 1); return null; } else throw new InvalidCharacterException(v); } return cp; }
@Override public char[] nextChars() throws InvalidCharacterException { char[] chars = super.nextChars(); if (chars != null && chars.length > 0) { if (chars.length == 1 && check(chars[0])) { if (scanningOnly) { position(position() - 1); return null; } else throw new InvalidCharacterException(chars[0]); } else if (chars.length == 2) { int cp = CharUtils.toSupplementary(chars[0], chars[1]).getValue(); if (check(cp)) { if (scanningOnly) { position(position() - 2); return null; } else throw new InvalidCharacterException(cp); } } } return chars; }
/** * 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; }