public String(int[] codePoints, int offset, int count) { if (offset < 0) { throw new IndexOutOfRangeException(); } if (count < 0) { throw new IndexOutOfRangeException(); } // Note: offset or count might be near -1>>>1. if (offset > codePoints.Length - count) { throw new IndexOutOfRangeException(); } int end = offset + count; // Pass 1: Compute precise size of char[] int n = count; for (int i = offset; i < end; i++) { int c = codePoints[i]; if (Character.isBmpCodePoint(c)) { continue; } else if (Character.isValidCodePoint(c)) { n++; } else { throw new IllegalArgumentException(); } } // Pass 2: Allocate and fill in char[] char[] v = new char[n]; for (int i = offset, j = 0; i < end; i++, j++) { int c = codePoints[i]; if (Character.isBmpCodePoint(c)) { v[j] = (char)c; } else { Character.toSurrogates(c, v, j++); } } this.value = v; }
private int lastIndexOfSupplementary(int ch, int fromIndex) { if (Character.isValidCodePoint(ch)) { char[] value = this.value; char hi = Character.highSurrogate(ch); char lo = Character.lowSurrogate(ch); int i = Math.min(fromIndex, value.Length - 2); for (; i >= 0; i--) { if (value[i] == hi && value[i + 1] == lo) { return(i); } } } return(-1); }
private int indexOfSupplementary(int ch, int fromIndex) { if (Character.isValidCodePoint(ch)) { char[] value = this.value; char hi = Character.highSurrogate(ch); char lo = Character.lowSurrogate(ch); int max = value.Length - 1; for (int i = fromIndex; i < max; i++) { if (value[i] == hi && value[i + 1] == lo) { return(i); } } } return(-1); }
public virtual AbstractStringBuilder appendCodePoint(int codePoint) { int count = this.count; if (Character.isBmpCodePoint(codePoint)) { ensureCapacityInternal(count + 1); value[count] = (char)codePoint; this.count = count + 1; } else if (Character.isValidCodePoint(codePoint)) { ensureCapacityInternal(count + 2); Character.toSurrogates(codePoint, value, count); this.count = count + 2; } else { throw new IllegalArgumentException(); } return(this); }