]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Character.java (toChars,toCodePoint): Correct these methods to use algorithms from...
authorChris Burdess <dog@gnu.org>
Mon, 9 Jan 2006 23:22:45 +0000 (23:22 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Mon, 9 Jan 2006 23:22:45 +0000 (23:22 +0000)
2006-01-08  Chris Burdess  <dog@gnu.org>

* java/lang/Character.java (toChars,toCodePoint): Correct these
  methods to use algorithms from Unicode specification.

From-SVN: r109516

libjava/ChangeLog
libjava/java/lang/Character.java

index 3770c6716076dda653b29a1c51bce736c75dc672..e8060abf1b2cf5cbd7c85018c0364bea3ede97b4 100644 (file)
@@ -1,3 +1,8 @@
+2006-01-08  Chris Burdess  <dog@gnu.org>
+
+       * java/lang/Character.java (toChars,toCodePoint): Correct these
+         methods to use algorithms from Unicode specification.
+
 2006-01-08  Tom Tromey  <tromey@redhat.com>
 
        * java/lang/StringBuilder.java (appendCodePoint): New method.
index 3cb73d0cbba67ca04e7e4b001f1b234159211583..f56117fdb3108c3ea1e7983f5dcd2ffa72973826 100644 (file)
@@ -2320,11 +2320,11 @@ public final class Character implements Serializable, Comparable
       {
         // Write second char first to cause IndexOutOfBoundsException
         // immediately.
-        dst[dstIndex + 1] = (char) ((codePoint & 0x3ff)
-                                    + (int) MIN_LOW_SURROGATE );
-        dst[dstIndex] = (char) ((codePoint >> 10) + (int) MIN_HIGH_SURROGATE);
+        final int cp2 = codePoint - 0x10000;
+        dst[dstIndex + 1] = (char) ((cp2 % 0x400) + (int) MIN_LOW_SURROGATE);
+        dst[dstIndex] = (char) ((cp2 / 0x400) + (int) MIN_HIGH_SURROGATE);
         result = 2;
-    }
+      }
     else
       {
         dst[dstIndex] = (char) codePoint;
@@ -2433,7 +2433,8 @@ public final class Character implements Serializable, Comparable
    */
   public static int toCodePoint(char high, char low)
   {
-    return ((high - MIN_HIGH_SURROGATE) << 10) + (low - MIN_LOW_SURROGATE);
+    return ((high - MIN_HIGH_SURROGATE) * 0x400) +
+      (low - MIN_LOW_SURROGATE) + 0x10000;
   }
 
   /**