/** * 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)); }
/** * Verifies a sequence of codepoints using the specified profile */ public static void verify(String s, Profile profile) throws InvalidCharacterException { if (s == null) return; verify(CodepointIterator.forCharSequence(s), profile); }
public static String prep(String s) { NameprepCodepointIterator r = null; try { StringBuilder buf = new StringBuilder(); CodepointIterator ci = CodepointIterator.forCharSequence(s); r = new NameprepCodepointIterator(ci); while (r.hasNext()) { Codepoint cp = r.next(); int i = cp != null ? cp.getValue() : -1; if (i != -1) { CharUtils.append(buf, cp); } } String n = Normalizer.normalize(buf.toString(), Normalizer.Form.KC).toString(); CharUtils.verify(CodepointIterator.forCharSequence(n), new Filter() { public boolean accept(int c) { return isProhibited(c); } }); return n; } catch (Throwable e) { return null; } }
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())); } } }