Commit 42801b98 by Chris Burdess Committed by Tom Tromey

Character.java (toChars,toCodePoint): Correct these methods to use algorithms…

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

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
parent f289c6a1
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> 2006-01-08 Tom Tromey <tromey@redhat.com>
* java/lang/StringBuilder.java (appendCodePoint): New method. * java/lang/StringBuilder.java (appendCodePoint): New method.
......
...@@ -2320,11 +2320,11 @@ public final class Character implements Serializable, Comparable ...@@ -2320,11 +2320,11 @@ public final class Character implements Serializable, Comparable
{ {
// Write second char first to cause IndexOutOfBoundsException // Write second char first to cause IndexOutOfBoundsException
// immediately. // immediately.
dst[dstIndex + 1] = (char) ((codePoint & 0x3ff) final int cp2 = codePoint - 0x10000;
+ (int) MIN_LOW_SURROGATE ); dst[dstIndex + 1] = (char) ((cp2 % 0x400) + (int) MIN_LOW_SURROGATE);
dst[dstIndex] = (char) ((codePoint >> 10) + (int) MIN_HIGH_SURROGATE); dst[dstIndex] = (char) ((cp2 / 0x400) + (int) MIN_HIGH_SURROGATE);
result = 2; result = 2;
} }
else else
{ {
dst[dstIndex] = (char) codePoint; dst[dstIndex] = (char) codePoint;
...@@ -2433,7 +2433,8 @@ public final class Character implements Serializable, Comparable ...@@ -2433,7 +2433,8 @@ public final class Character implements Serializable, Comparable
*/ */
public static int toCodePoint(char high, char low) 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;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment