[kaffe] CVS kaffe (kaz): gnu/java/nio/charset/UnicodeLittle.java

Kaffe CVS cvs-commits at kaffe.org
Mon Jun 27 10:08:45 PDT 2005


PatchSet 6668 
Date: 2005/06/27 17:03:07
Author: kaz
Branch: HEAD
Tag: (none) 
Log:
2005-06-27  Ito Kazumitsu  <kaz at maczuka.gcd.org>

        * gnu/java/nio/charset/UnicodeLittle.java
        (newDecoder): Set the endianness to UTF_16Decoder.MAYBE_LITTLE_ENDIAN.

        * gnu/java/nio/charset/UTF_16Decoder.java
        (MAYBE_BIG_ENDIAN, MAYBE_LITTLE_ENDIAN): New constants.
        (decodeLoop): If the byte order is MAYBE_LITTLE_ENDIAN or
        MAYBE_BIG_ENDIAN, assume the default endianness to be little or
        big respectively.

Members: 
	ChangeLog:1.4193->1.4194 
	libraries/javalib/gnu/java/nio/charset/UTF_16Decoder.java:1.4->1.5 
	libraries/javalib/gnu/java/nio/charset/UnicodeLittle.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4193 kaffe/ChangeLog:1.4194
--- kaffe/ChangeLog:1.4193	Mon Jun 27 12:01:22 2005
+++ kaffe/ChangeLog	Mon Jun 27 17:03:07 2005
@@ -1,3 +1,14 @@
+2005-06-27  Ito Kazumitsu  <kaz at maczuka.gcd.org>
+
+        * gnu/java/nio/charset/UnicodeLittle.java
+	(newDecoder): Set the endianness to UTF_16Decoder.MAYBE_LITTLE_ENDIAN.
+
+	* gnu/java/nio/charset/UTF_16Decoder.java
+	(MAYBE_BIG_ENDIAN, MAYBE_LITTLE_ENDIAN): New constants.
+	(decodeLoop): If the byte order is MAYBE_LITTLE_ENDIAN or
+	MAYBE_BIG_ENDIAN, assume the default endianness to be little or
+	big respectively.
+
 2005-06-27  Guilhem Lavaux  <guilhem at kaffe.org>
 
 	* config/sparc/bsdi3/md.h,
Index: kaffe/libraries/javalib/gnu/java/nio/charset/UTF_16Decoder.java
diff -u kaffe/libraries/javalib/gnu/java/nio/charset/UTF_16Decoder.java:1.4 kaffe/libraries/javalib/gnu/java/nio/charset/UTF_16Decoder.java:1.5
--- kaffe/libraries/javalib/gnu/java/nio/charset/UTF_16Decoder.java:1.4	Fri Jun 24 15:57:28 2005
+++ kaffe/libraries/javalib/gnu/java/nio/charset/UTF_16Decoder.java	Mon Jun 27 17:03:10 2005
@@ -54,6 +54,8 @@
   static final int BIG_ENDIAN = 0;
   static final int LITTLE_ENDIAN = 1;
   static final int UNKNOWN_ENDIAN = 2;
+  static final int MAYBE_BIG_ENDIAN = 3;
+  static final int MAYBE_LITTLE_ENDIAN = 4;
 
   private static final char BYTE_ORDER_MARK = 0xFEFF;
   private static final char REVERSED_BYTE_ORDER_MARK = 0xFFFE;
@@ -81,26 +83,37 @@
             byte b2 = in.get ();
 
             // handle byte order mark
-            if (byteOrder == UNKNOWN_ENDIAN)
+            if (byteOrder == UNKNOWN_ENDIAN ||
+                byteOrder == MAYBE_BIG_ENDIAN ||
+                byteOrder == MAYBE_LITTLE_ENDIAN)
               {
                 char c = (char) (((b1 & 0x00FF) << 8) | (b2 & 0x00FF));
                 if (c == BYTE_ORDER_MARK)
                   {
+                    if (byteOrder == MAYBE_LITTLE_ENDIAN)
+                      {
+                        return CoderResult.malformedForLength (2);
+                      }
                     byteOrder = BIG_ENDIAN;
                     inPos += 2;
                     continue;
                   }
                 else if (c == REVERSED_BYTE_ORDER_MARK)
                   {
+                    if (byteOrder == MAYBE_BIG_ENDIAN)
+                      {
+                        return CoderResult.malformedForLength (2);
+                      }
                     byteOrder = LITTLE_ENDIAN;
                     inPos += 2;
                     continue;
                   }
                 else
                   {
-                    // assume big endian, do not consume bytes,
+                    // assume big or little endian, do not consume bytes,
                     // continue with normal processing
-                    byteOrder = BIG_ENDIAN;
+                    byteOrder = (byteOrder == MAYBE_LITTLE_ENDIAN ?
+                                 LITTLE_ENDIAN : BIG_ENDIAN);
                   }
               }
 
Index: kaffe/libraries/javalib/gnu/java/nio/charset/UnicodeLittle.java
diff -u kaffe/libraries/javalib/gnu/java/nio/charset/UnicodeLittle.java:1.2 kaffe/libraries/javalib/gnu/java/nio/charset/UnicodeLittle.java:1.3
--- kaffe/libraries/javalib/gnu/java/nio/charset/UnicodeLittle.java:1.2	Fri Jun 24 15:57:28 2005
+++ kaffe/libraries/javalib/gnu/java/nio/charset/UnicodeLittle.java	Mon Jun 27 17:03:10 2005
@@ -64,7 +64,7 @@
 
   public CharsetDecoder newDecoder ()
   {
-    return new UTF_16Decoder (this, UTF_16Decoder.LITTLE_ENDIAN);
+    return new UTF_16Decoder (this, UTF_16Decoder.MAYBE_LITTLE_ENDIAN);
   }
 
   public CharsetEncoder newEncoder ()




More information about the kaffe mailing list