/** * Verifies a sequence of codepoints using the specified profile */ public static void verifyNot(char[] array, Profile profile) throws InvalidCharacterException { CodepointIterator rci = CodepointIterator.forCharArray(array).restrict(profile.filter(), false, true); while (rci.hasNext()) rci.next(); }
@Override protected char get(int index) { return internal.get(index); }
@Override public boolean isHigh(int index) { return internal.isHigh(index); }
/** * 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; }
public static String encode(char[] chars, boolean[] case_flags) throws IOException { StringBuilder buf = new StringBuilder(); CodepointIterator ci = CodepointIterator.forCharArray(chars); int n, delta, h, b, bias, m, q, k, t; n = initial_n; bias = initial_bias; int i = -1; while (ci.hasNext()) { i = ci.next().getValue(); if (basic(i)) { if (case_flags != null) { buf.append((char)delimiter); while (h < chars.length) { ci.position(0); i = -1; m = Integer.MAX_VALUE; while (ci.hasNext()) { i = ci.next().getValue(); if (i >= n && i < m) m = i; delta += (m - n) * (h + 1); n = m; ci.position(0); i = -1; while (ci.hasNext()) { i = ci.next().getValue(); if (i < n) {
private static void decompose(CharSequence source, Form form, StringBuilder buf) throws IOException { StringBuilder internal = new StringBuilder(); CodepointIterator ci = CodepointIterator.forCharSequence(source); boolean canonical = form.isCanonical(); while (ci.hasNext()) { Codepoint c = ci.next(); internal.setLength(0); UnicodeCharacterDatabase.decompose(c.getValue(), canonical, internal); CodepointIterator ii = CodepointIterator.forCharSequence(internal); while (ii.hasNext()) { Codepoint ch = ii.next(); int i = findInsertionPoint(buf, ch.getValue()); buf.insert(i, CharUtils.toString(ch.getValue())); } } }
/** * Return the total number of codepoints in the buffer. Each surrogate pair counts as a single codepoint */ public static int length(CharSequence c) { return length(CodepointIterator.forCharSequence(c)); }
/** * Get a CodepointIterator that can iterate over unicode codepoints in this pipe. The pipe must be readable */ public CodepointIterator getIterator() { checkNotFlipped(); return CodepointIterator.forReadableByteChannel(pipe.source(), charset); }
/** * Return the total number of codepoints in the buffer. Each surrogate pair counts as a single codepoint */ public static int length(char[] c) { return length(CodepointIterator.forCharArray(c)); }
@Override public int limit() { return internal.limit(); }
@Override public boolean isLow(int index) { return internal.isLow(index); }
@Override public boolean hasNext() { return internal.hasNext(); }
@Override public Codepoint next() { return internal.next(); }