public String toString() { return CharUtils.toString(value); }
/** * Insert a codepoint into the buffer, automatically dealing with surrogate pairs */ public static void insert(CharSequence s, int i, int c) { if (!(s instanceof StringBuilder) && !(s instanceof StringBuffer)) { insert(new StringBuilder(s), i, c); } else { if (i > 0 && i < s.length()) { char ch = s.charAt(i); boolean low = isLowSurrogate(ch); if (low) { if (low && isHighSurrogate(s.charAt(i - 1))) { i--; } } } if (s instanceof StringBuffer) ((StringBuffer)s).insert(i, toString(c)); else if (s instanceof StringBuilder) ((StringBuilder)s).insert(i, toString(c)); } }
/** * Set the character at a given location, automatically dealing with surrogate pairs */ public static void setChar(CharSequence s, int i, int c) { if (!(s instanceof StringBuilder) && !(s instanceof StringBuffer)) { setChar(new StringBuilder(s), i, c); } else { int l = 1; char ch = s.charAt(i); boolean high = isHighSurrogate(ch); boolean low = isLowSurrogate(ch); if (high || low) { if (high && (i + 1) < s.length() && isLowSurrogate(s.charAt(i + 1))) l++; else { if (low && i > 0 && isHighSurrogate(s.charAt(i - 1))) { i--; l++; } } } if (s instanceof StringBuffer) ((StringBuffer)s).replace(i, i + l, toString(c)); else if (s instanceof StringBuilder) ((StringBuilder)s).replace(i, i + l, toString(c)); } }
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())); } } }