1 |
/* DecoderUTF8.java -- Decoder for the UTF-8 character encoding. |
/* DecoderUTF8.java -- Decoder for the UTF-8 character encoding. |
2 |
Copyright (C) 1998 Free Software Foundation, Inc. |
Copyright (C) 1998, 2003 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
88 |
int num_chars = 0; |
int num_chars = 0; |
89 |
|
|
90 |
// Scan the buffer with minimal validation checks |
// Scan the buffer with minimal validation checks |
91 |
for (int i = offset; i < len; i++) |
for (int i = offset; i < offset + len; i++) |
92 |
{ |
{ |
93 |
// Three byte encoding case. |
// Three byte encoding case. |
94 |
if ((buf[i] & 0xE0) == 0xE0) // 224 |
if ((buf[i] & 0xE0) == 0xE0) // 224 |
134 |
int val; |
int val; |
135 |
|
|
136 |
// Scan the buffer with full validation checks |
// Scan the buffer with full validation checks |
137 |
for (int i = buf_offset; i < len; i++) |
for (int i = buf_offset; i < buf_offset + len; i++) |
138 |
{ |
{ |
139 |
// Three byte encoding case. |
// Three byte encoding case. |
140 |
if ((buf[i] & 0xE0) == 0xE0) // 224 |
if ((buf[i] & 0xE0) == 0xE0) // 224 |
197 |
// Note that this method of reading a single byte at a time is |
// Note that this method of reading a single byte at a time is |
198 |
// inefficient and should probably be replaced |
// inefficient and should probably be replaced |
199 |
|
|
200 |
for (int i = offset; i < len; i++) |
for (int i = offset; i < offset + len; i++) |
201 |
{ |
{ |
202 |
// Read a byte |
// Read a byte |
203 |
int b = in.read(); |
int b = in.read(); |
249 |
} |
} |
250 |
|
|
251 |
cbuf[i] = (char)val; |
cbuf[i] = (char)val; |
252 |
|
|
253 |
|
// if no more bytes available, terminate loop early, instead of |
254 |
|
// blocking in in.read(). |
255 |
|
// Do not test this in the for condition: it must call in.read() at |
256 |
|
// least once (and thus block if "in" is empty). |
257 |
|
if (in.available() <= 0) |
258 |
|
return (1 + i - offset); |
259 |
} |
} |
260 |
|
|
261 |
return(len); |
return(len); |