This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: Character fix


I'm checking this in on the trunk and the 4.1 branch.

This pulls in a small Character fix from Chris Burdess.

Tom

Index: ChangeLog
from  Chris Burdess  <dog@gnu.org>

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

Index: java/lang/Character.java
===================================================================
--- java/lang/Character.java	(revision 109497)
+++ java/lang/Character.java	(working copy)
@@ -2320,11 +2320,11 @@
       {
         // 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 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;
   }
 
   /**



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]