Fixing NativeGlobal.encode: it was broken for chars beyond 0xFFFF as it sb.setLength(k) was called after k was increased to consume the second char from UTF-16 encoding to build UCS-4.

This commit is contained in:
igor%mir2.org 2004-02-12 19:05:47 +00:00
Родитель 35fa66391e
Коммит 0bdc147fa8
1 изменённых файлов: 6 добавлений и 6 удалений

Просмотреть файл

@ -535,6 +535,12 @@ public class NativeGlobal implements Serializable, IdFunctionMaster
sb.append(C);
}
} else {
if (sb == null) {
sb = new StringBuffer(length + 3);
sb.append(str);
sb.setLength(k);
utf8buf = new byte[6];
}
if (0xDC00 <= C && C <= 0xDFFF) {
throw cx.reportRuntimeError0("msg.bad.uri");
}
@ -552,12 +558,6 @@ public class NativeGlobal implements Serializable, IdFunctionMaster
}
V = ((C - 0xD800) << 10) + (C2 - 0xDC00) + 0x10000;
}
if (utf8buf == null) {
utf8buf = new byte[6];
sb = new StringBuffer(length + 3);
sb.append(str);
sb.setLength(k);
}
int L = oneUcs4ToUtf8Char(utf8buf, V);
for (int j = 0; j < L; j++) {
int d = 0xff & utf8buf[j];