On Tue, Mar 16, 2010 at 13:58, Ulf Zibis <[email protected]> wrote:
> Additionally, toUpperCaseCharArray(), codePointCountImpl(), String(int[],
> int, int) would profit from consecutive use of isBMPCodePoint +
> isSupplementaryCodePoint() or isHighSurrogate() + isLowSurrogate.
For codePointCountImpl(), I do not agree.
For String(int[], int, int), I do agree.
Here is my latest more readable and more performant implementation:
int end = offset + count;
// Pass 1: Compute precise size of char[]
int n = 0;
for (int i = offset; i < end; i++) {
int c = codePoints[i];
if (Character.isBMPCodePoint(c))
n += 1;
else if (Character.isSupplementaryCodePoint(c))
n += 2;
else throw new IllegalArgumentException(Integer.toString(c));
}
// Pass 2: Allocate and fill in char[]
char[] v = new char[n];
for (int i = offset, j = 0; i < end; i++) {
int c = codePoints[i];
if (Character.isBMPCodePoint(c)) {
v[j++] = (char) c;
} else {
Character.toSurrogates(c, v, j);
j += 2;
}
}
Martin