for utf8Length byte byte classBytes pointerCp if 0x80 int utf8_len for

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
for (i = 1; i <= utf8Length; ) {
byte b = (byte) classBytes[pointerCp + 2 + i];
if ((b & 0x80) != 0) {
int utf8_len;
for (utf8_len = 8; utf8_len--> 0 && ((b >> utf8_len) & 1) == 1; );
utf8_len = 7 - utf8_len;
int utf8_value = 0, offset = 0;
for (int j = utf8_len; j--> 1; ) {
utf8_value |= (classBytes[pointerCp + 2 + i + j] & 0x3F) << offset;
offset += 6;
}
utf8_value |= (b & (0xFF >> (utf8_len + 1))) << offset;
if (utf8_value < 0x80) {
s += escapeChar((char) utf8_value);
} else if (utf8_value <= 0x07FF) {
if (isPrintableChar((char) utf8_value))
s += (char) utf8_value;
else
s += String.format("\\x%04X", utf8_value);
} else {
if (utf8_value >= 0xFFFF) {
for (int k = 4; k--> 0; ) {
int chr = (utf8_value >> (k * 8) & 0xFF);
if (chr == 0)
continue;
s += "\\" + chr;
}
} else {
s += String.format("\\u%04X", utf8_value);
}
}
i += utf8_len;
} else {
s += escapeChar((char) classBytes[pointerCp + 2 + i]);
++i;
}
}