harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r680390 - /harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
Date Mon, 28 Jul 2008 16:26:00 GMT
Author: tellison
Date: Mon Jul 28 09:25:59 2008
New Revision: 680390

URL: http://svn.apache.org/viewvc?rev=680390&view=rev
Log:
Fix UTF-8 decoder.
Failing test was org.apache.harmony.luni.tests.java.io.OutputStreamWriterTest#testBlockIO

Modified:
    harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java

Modified: harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java?rev=680390&r1=680389&r2=680390&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
Mon Jul 28 09:25:59 2008
@@ -62,7 +62,7 @@
             29892736  // (0111o000b << 18)+(1o000000b << 12)+(1o000000b <<
6)+(1o000000b)
     };
     
-    private static final int headerBits[] = { -1, 0x1F, 0x0F, 0x07 };
+    private static final int lowerEncodingLimit[] = { -1, 0x80, 0x800, 0x10000 };
 
     public UTF_8(String canonicalName, String[] aliases) {
         super(canonicalName, aliases);
@@ -130,7 +130,7 @@
                         jchar = jchar & 0x7F;
                         int tail = remainingBytes[jchar];
 
-                        if (tail == -1 || (jchar & headerBits[tail]) == 0) {
+                        if (tail == -1) {
                             in.position(inIndex - in.arrayOffset());
                             out.position(outIndex - out.arrayOffset());
                             return CoderResult.malformedForLength(1);
@@ -149,8 +149,8 @@
                             jchar = (jchar << 6) + nextByte;
                         }
                         jchar -= remainingNumbers[tail];
-                        if (jchar == 0x7F) {
-                            // U+007F should have been encoded in a single octet
+                        if (jchar < lowerEncodingLimit[tail]) {
+                            // Should have been encoded in fewer octets
                             in.position(inIndex - in.arrayOffset());
                             out.position(outIndex - out.arrayOffset());
                             return CoderResult.malformedForLength(1);
@@ -175,7 +175,7 @@
                         if (jchar < 0) {
                             jchar = jchar & 0x7F;
                             int tail = remainingBytes[jchar];
-                            if ((tail == -1) || (jchar & headerBits[tail]) == 0) {
+                            if (tail == -1) {
                                 return CoderResult.malformedForLength(1);
                             }
                             if (limit - pos < 1 + tail) {
@@ -192,8 +192,8 @@
                                 jchar = (jchar << 6) + nextByte;
                             }
                             jchar -= remainingNumbers[tail];
-                            if (jchar == 0x7F) {
-                                // U+007F should have been encoded in a single octet
+                            if (jchar < lowerEncodingLimit[tail]) {
+                                // Should have been encoded in a fewer octets
                                 return CoderResult.malformedForLength(1);
                             }
                             pos += tail;



Mime
View raw message