/[classpath]/classpath/gnu/java/nio/charset/UTF_16Decoder.java
ViewVC logotype

Diff of /classpath/gnu/java/nio/charset/UTF_16Decoder.java

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

revision 1.3.2.3 by gnu_andrew, Tue Aug 16 16:22:36 2005 UTC revision 1.3.2.4 by gnu_andrew, Sun Nov 27 21:00:36 2005 UTC
# Line 54  final class UTF_16Decoder extends Charse Line 54  final class UTF_16Decoder extends Charse
54    static final int BIG_ENDIAN = 0;    static final int BIG_ENDIAN = 0;
55    static final int LITTLE_ENDIAN = 1;    static final int LITTLE_ENDIAN = 1;
56    static final int UNKNOWN_ENDIAN = 2;    static final int UNKNOWN_ENDIAN = 2;
57      static final int MAYBE_BIG_ENDIAN = 3;
58      static final int MAYBE_LITTLE_ENDIAN = 4;
59    
60    private static final char BYTE_ORDER_MARK = 0xFEFF;    private static final char BYTE_ORDER_MARK = 0xFEFF;
61    private static final char REVERSED_BYTE_ORDER_MARK = 0xFFFE;    private static final char REVERSED_BYTE_ORDER_MARK = 0xFFFE;
# Line 81  final class UTF_16Decoder extends Charse Line 83  final class UTF_16Decoder extends Charse
83              byte b2 = in.get ();              byte b2 = in.get ();
84    
85              // handle byte order mark              // handle byte order mark
86              if (byteOrder == UNKNOWN_ENDIAN)              if (byteOrder == UNKNOWN_ENDIAN ||
87                    byteOrder == MAYBE_BIG_ENDIAN ||
88                    byteOrder == MAYBE_LITTLE_ENDIAN)
89                {                {
90                  char c = (char) (((b1 & 0xFF) << 8) | (b2 & 0xFF));                  char c = (char) (((b1 & 0xFF) << 8) | (b2 & 0xFF));
91                  if (c == BYTE_ORDER_MARK)                  if (c == BYTE_ORDER_MARK)
92                    {                    {
93                        if (byteOrder == MAYBE_LITTLE_ENDIAN)
94                          {
95                            return CoderResult.malformedForLength (2);
96                          }
97                      byteOrder = BIG_ENDIAN;                      byteOrder = BIG_ENDIAN;
98                      inPos += 2;                      inPos += 2;
99                      continue;                      continue;
100                    }                    }
101                  else if (c == REVERSED_BYTE_ORDER_MARK)                  else if (c == REVERSED_BYTE_ORDER_MARK)
102                    {                    {
103                        if (byteOrder == MAYBE_BIG_ENDIAN)
104                          {
105                            return CoderResult.malformedForLength (2);
106                          }
107                      byteOrder = LITTLE_ENDIAN;                      byteOrder = LITTLE_ENDIAN;
108                      inPos += 2;                      inPos += 2;
109                      continue;                      continue;
110                    }                    }
111                  else                  else
112                    {                    {
113                      // assume big endian, do not consume bytes,                      // assume big or little endian, do not consume bytes,
114                      // continue with normal processing                      // continue with normal processing
115                      byteOrder = BIG_ENDIAN;                      byteOrder = (byteOrder == MAYBE_LITTLE_ENDIAN ?
116                                     LITTLE_ENDIAN : BIG_ENDIAN);
117                    }                    }
118                }                }
119    

Legend:
Removed from v.1.3.2.3  
changed lines
  Added in v.1.3.2.4

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