95 |
// Package-private to avoid a trampoline constructor. |
// Package-private to avoid a trampoline constructor. |
96 |
Decoder (Charset cs) |
Decoder (Charset cs) |
97 |
{ |
{ |
98 |
super (cs, 1.0f, 1.0f); |
super (cs, 0.9f, 0.25f); |
99 |
} |
} |
100 |
|
|
101 |
protected CoderResult decodeLoop (ByteBuffer in, CharBuffer out) |
protected CoderResult decodeLoop (ByteBuffer in, CharBuffer out) |
108 |
{ |
{ |
109 |
char c; |
char c; |
110 |
byte b1 = in.get (); |
byte b1 = in.get (); |
111 |
int highNibble = (b1 >> 4) & 0xF; |
int highNibble = ((b1 & 0xFF) >> 4) & 0xF; |
|
|
|
112 |
switch (highNibble) |
switch (highNibble) |
113 |
{ |
{ |
114 |
case 0: case 1: case 2: case 3: |
case 0: case 1: case 2: case 3: |
155 |
inPos += 3; |
inPos += 3; |
156 |
break; |
break; |
157 |
|
|
158 |
|
case 0xF: |
159 |
|
byte b4; |
160 |
|
if (in.remaining () < 3) |
161 |
|
return CoderResult.UNDERFLOW; |
162 |
|
if((b1&0x0F) > 4) |
163 |
|
return CoderResult.malformedForLength (4); |
164 |
|
if (out.remaining () < 2) |
165 |
|
return CoderResult.OVERFLOW; |
166 |
|
if (!isContinuation (b2 = in.get ())) |
167 |
|
return CoderResult.malformedForLength (3); |
168 |
|
if (!isContinuation (b3 = in.get ())) |
169 |
|
return CoderResult.malformedForLength (2); |
170 |
|
if (!isContinuation (b4 = in.get ())) |
171 |
|
return CoderResult.malformedForLength (1); |
172 |
|
int n = (((b1 & 0x3) << 18) |
173 |
|
| ((b2 & 0x3F) << 12) |
174 |
|
| ((b3 & 0x3F) << 6) |
175 |
|
| (b4 & 0x3F)) - 0x10000; |
176 |
|
char c1 = (char)(0xD800 | (n & 0xFFC00)>>10); |
177 |
|
char c2 = (char)(0xDC00 | (n & 0x003FF)); |
178 |
|
out.put (c1); |
179 |
|
out.put (c2); |
180 |
|
inPos += 4; |
181 |
|
break; |
182 |
|
|
183 |
default: |
default: |
184 |
return CoderResult.malformedForLength (1); |
return CoderResult.malformedForLength (1); |
185 |
} |
} |
241 |
// u uuuu zzzz yyyy yyxx xxxx 1101 10ww wwzz zzyy 1111 0uuu 10uu zzzz 10yy yyyy 10xx xxxx |
// u uuuu zzzz yyyy yyxx xxxx 1101 10ww wwzz zzyy 1111 0uuu 10uu zzzz 10yy yyyy 10xx xxxx |
242 |
// + 1101 11yy yyxx xxxx |
// + 1101 11yy yyxx xxxx |
243 |
// Note: uuuuu = wwww + 1 |
// Note: uuuuu = wwww + 1 |
|
|
|
244 |
if (c <= 0x7F) |
if (c <= 0x7F) |
245 |
{ |
{ |
246 |
if (remaining < 1) |
if (remaining < 1) |
279 |
// int value2 = (c - 0xD800) * 0x400 + (d - 0xDC00) + 0x10000; |
// int value2 = (c - 0xD800) * 0x400 + (d - 0xDC00) + 0x10000; |
280 |
int value = (((c & 0x3FF) << 10) | (d & 0x3FF)) + 0x10000; |
int value = (((c & 0x3FF) << 10) | (d & 0x3FF)) + 0x10000; |
281 |
// assert value == value2; |
// assert value == value2; |
282 |
out.put ((byte) (0xF0 | (value >> 18))); |
out.put ((byte) (0xF0 | ((value >> 18) & 0x07))); |
283 |
out.put ((byte) (0x80 | ((value >> 12) & 0x3F))); |
out.put ((byte) (0x80 | ((value >> 12) & 0x3F))); |
284 |
out.put ((byte) (0x80 | ((value >> 6) & 0x3F))); |
out.put ((byte) (0x80 | ((value >> 6) & 0x3F))); |
285 |
out.put ((byte) (0x80 | ((value ) & 0x3F))); |
out.put ((byte) (0x80 | ((value ) & 0x3F))); |
|
|
|
286 |
inPos += 2; |
inPos += 2; |
287 |
} |
} |
288 |
else |
else |