harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r996904 - in /harmony/enhanced/java/trunk/classlib/modules/nio_char/src: main/java/org/apache/harmony/niochar/charset/UTF_8.java test/java/tests/api/java/nio/charset/UTF8CharsetTest.java
Date Tue, 14 Sep 2010 14:05:44 GMT
Author: tellison
Date: Tue Sep 14 14:05:44 2010
New Revision: 996904

URL: http://svn.apache.org/viewvc?rev=996904&view=rev
Log:
Apply patch and test case for HARMONY-6640 (UTF8 decoder doesn't properly decode supplementary
characters)

Modified:
    harmony/enhanced/java/trunk/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
    harmony/enhanced/java/trunk/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java?rev=996904&r1=996903&r2=996904&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
Tue Sep 14 14:05:44 2010
@@ -157,8 +157,17 @@ public class UTF_8 extends Charset {
                         }
                         inIndex += tail;
                     }
-                    cArr[outIndex++] = (char) jchar;
-                    outRemaining--;
+                    if (jchar <= 0xffff) {
+                      cArr[outIndex++] = (char) jchar;
+                      outRemaining--;
+                    } else {
+                      if (outRemaining < 2) {
+                          return CoderResult.OVERFLOW;
+                      }
+                      cArr[outIndex++] = (char) ((jchar >> 0xA) + 0xD7C0);
+                      cArr[outIndex++] = (char) ((jchar & 0x3FF) + 0xDC00);
+                      outRemaining -= 2;
+                    }
                 }
                 in.position(inIndex - in.arrayOffset());
                 out.position(outIndex - out.arrayOffset());
@@ -198,9 +207,18 @@ public class UTF_8 extends Charset {
                             }
                             pos += tail;
                         }
+                        if (jchar <= 0xffff) {
+                          out.put((char) jchar);
+                          outRemaining--;
+                        } else {
+                          if (outRemaining < 2) {
+                              return CoderResult.OVERFLOW;
+                          }
+                          out.put((char) ((jchar >> 0xA) + 0xD7C0));
+                          out.put((char) ((jchar & 0x3FF) + 0xDC00));
+                          outRemaining -= 2;
+                        }
                         pos++;
-                        out.put((char) jchar);
-                        outRemaining--;
                     }
                     return CoderResult.UNDERFLOW;
                 } finally {

Modified: harmony/enhanced/java/trunk/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java?rev=996904&r1=996903&r2=996904&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java
Tue Sep 14 14:05:44 2010
@@ -16,6 +16,8 @@
 
 package tests.api.java.nio.charset;
 
+import java.io.UnsupportedEncodingException;
+
 /**
  * Test UTF-8 charset.
  */
@@ -50,4 +52,11 @@ public class UTF8CharsetTest extends Abs
 		byte[] output = new byte[] { 97, 98, -27, -76, -108, -26, -107, -113 };
 		internalTestEncode(input, output);
 	}
+	
+    public void test_surrogate() throws UnsupportedEncodingException {
+        // U+1D11E: MUSICAL SYMBOL G CLEF
+        String s = new StringBuilder().appendCodePoint(0x1D11E).toString();
+        byte utf8[] = s.getBytes("UTF-8");
+        assertEquals(s, new String(utf8, 0, utf8.length, "UTF-8"));
+    }
 }



Mime
View raw message