/[classpath]/classpath/gnu/java/io/decode/DecoderUTF8.java
ViewVC logotype

Diff of /classpath/gnu/java/io/decode/DecoderUTF8.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by mark, Tue Jan 22 22:26:57 2002 UTC revision 1.4 by mark, Sat Aug 16 13:16:53 2003 UTC
# Line 1  Line 1 
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    
# Line 88  charsInByteArray(byte[] buf, int offset, Line 88  charsInByteArray(byte[] buf, int offset,
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
# Line 134  convertToChars(byte[] buf, int buf_offse Line 134  convertToChars(byte[] buf, int buf_offse
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
# Line 197  read(char[] cbuf, int offset, int len) t Line 197  read(char[] cbuf, int offset, int len) t
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();
# Line 249  read(char[] cbuf, int offset, int len) t Line 249  read(char[] cbuf, int offset, int len) t
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);

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26