/** * 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(); }
/** * Insert a codepoint into the buffer, automatically dealing with surrogate pairs */ public static void insert(CharSequence s, int i, Codepoint c) { insert(s, i, c.getValue()); }
public byte[] toBytes() { try { return toBytes(DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
/** * 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; }
public Codepoint clone() { try { return (Codepoint)super.clone(); } catch (CloneNotSupportedException e) { return new Codepoint(value); } }
/** * Create a Codepoint from a CharSequence. Length must equal 1 */ public Codepoint(CharSequence value) { this(valueFromCharSequence(value)); }
public char[] toChars() { return toString().toCharArray(); }
/** * Return the number of characters used to represent the codepoint (will return 1 or 2) */ public static int length(Codepoint c) { return c.getCharCount(); }
/** * Get the number of chars necessary to represent this codepoint. Returns 2 if this is a supplementary codepoint */ public int getCharCount() { return toChars().length; }
int r = -1; if (this.rep == null) { r = super.next().getValue(); if (r != -1) { if (Nameprep.isLCat(r)) while (r != -1 && Nameprep.isB1(r)) { Codepoint cp = super.next(); r = cp != null ? cp.getValue() : -1; && (!firstisrandalcat || !Nameprep.isRandAL((r == -1) ? peek(position()).getValue() : r))) { throw new RuntimeException("Bidi Exception"); return r != -1 ? new Codepoint(r) : null;
/** * Get the next codepoint */ public Codepoint next() { if (value == 0x10ffff) throw new IndexOutOfBoundsException(); return new Codepoint(value + 1); }
/** * Create a Codepoint from a byte array with the specified charset encoding. Length must equal 1 */ public Codepoint(byte[] bytes, String encoding) throws UnsupportedEncodingException { this.value = valueFromCharSequence(new String(bytes, encoding)); }
public byte[] toBytes(String encoding) throws UnsupportedEncodingException { return toString().getBytes(encoding); }
/** * True if the character is a valid unicode codepoint */ public static boolean isValid(Codepoint c) { return isValid(c.getValue()); }
/** * Get the previous codepoint */ public Codepoint previous() { if (value == 0) throw new IndexOutOfBoundsException(); return new Codepoint(value - 1); } }
/** * Create a Codepoint from a byte array using the default encoding (UTF-8) */ public Codepoint(byte[] bytes) { try { this.value = valueFromCharSequence(new String(bytes, DEFAULT_ENCODING)); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
/** * Create a codepoint from a surrogate pair */ public Codepoint(char high, char low) { this(CharUtils.toSupplementary(high, low).getValue()); }
private Codepoint toCodepoint(char[] chars) { return (chars == null) ? null : (chars.length == 1) ? new Codepoint(chars[0]) : CharUtils .toSupplementary(chars[0], chars[1]); }
/** * Append the specified codepoint to the buffer, automatically handling surrogate pairs */ public static void append(Appendable buf, Codepoint c) { append(buf, c.getValue()); }
/** * 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); }