/** * Get the previous codepoint */ public Codepoint previous() { if (value == 0) throw new IndexOutOfBoundsException(); return new Codepoint(value - 1); } }
public Codepoint clone() { try { return (Codepoint)super.clone(); } catch (CloneNotSupportedException e) { return new Codepoint(value); } }
/** * Get the next codepoint */ public Codepoint next() { if (value == 0x10ffff) throw new IndexOutOfBoundsException(); return new Codepoint(value + 1); }
/** * Return the number of characters used to represent the codepoint (will return 1 or 2) */ public static int length(int c) { return new Codepoint(c).getCharCount(); }
private Codepoint toCodepoint(char[] chars) { return (chars == null) ? null : (chars.length == 1) ? new Codepoint(chars[0]) : CharUtils .toSupplementary(chars[0], chars[1]); }
/** * Converts the high and low surrogate into a supplementary codepoint */ public static Codepoint toSupplementary(char high, char low) { if (!isHighSurrogate(high)) throw new IllegalArgumentException("Invalid High Surrogate"); if (!isLowSurrogate(low)) throw new IllegalArgumentException("Invalid Low Surrogate"); return new Codepoint(((high - '\uD800') << 10) + (low - '\uDC00') + 0x010000); }
/** * Return the codepoint at the given location, automatically dealing with surrogate pairs */ public static Codepoint codepointAt(CharSequence s, int i) { char c = s.charAt(i); if (c < 0xD800 || c > 0xDFFF) return new Codepoint(c); if (isHighSurrogate(c)) { if (s.length() != i) { char low = s.charAt(i + 1); if (isLowSurrogate(low)) return toSupplementary(c, low); } } else if (isLowSurrogate(c)) { if (i >= 1) { char high = s.charAt(i - 1); if (isHighSurrogate(high)) return toSupplementary(high, c); } } return new Codepoint(c); }
/** * Return the codepoint at the given location, automatically dealing with surrogate pairs */ public static Codepoint codepointAt(String s, int i) { char c = s.charAt(i); if (c < 0xD800 || c > 0xDFFF) return new Codepoint(c); if (isHighSurrogate(c)) { if (s.length() != i) { char low = s.charAt(i + 1); if (isLowSurrogate(low)) return toSupplementary(c, low); } } else if (isLowSurrogate(c)) { if (i >= 1) { char high = s.charAt(i - 1); if (isHighSurrogate(high)) return toSupplementary(high, c); } } return new Codepoint(c); }
/** * True if all the characters in chars are within the set [low,high] */ public static boolean inRange(char[] chars, int low, int high) { for (int i = 0; i < chars.length; i++) { char n = chars[i]; Codepoint cp = (isHighSurrogate(n) && i + 1 < chars.length && isLowSurrogate(chars[i + 1])) ? toSupplementary(n, chars[i++]) : new Codepoint(n); int c = cp.getValue(); if (c < low || c > high) return false; } return true; }
throw new RuntimeException("Bidi Exception"); return r != -1 ? new Codepoint(r) : null;