--- a/jdk/src/share/classes/sun/nio/cs/Surrogate.java Wed Jun 30 16:11:31 2010 -0700
+++ b/jdk/src/share/classes/sun/nio/cs/Surrogate.java Wed Jun 30 16:11:32 2010 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -34,8 +34,9 @@
* Utility class for dealing with surrogates.
*
* @author Mark Reinhold
+ * @author Martin Buchholz
+ * @author Ulf Zibis
*/
-
public class Surrogate {
private Surrogate() { }
@@ -75,16 +76,9 @@
}
/**
- * Tells whether or not the given UCS-4 character is in the Basic
- * Multilingual Plane, and can be represented using a single char.
- */
- public static boolean isBMPCodePoint(int uc) {
- return uc >> 16 == 0;
- }
-
- /**
* Tells whether or not the given UCS-4 character must be represented as a
* surrogate pair in UTF-16.
+ * Use of {@link Character#isSupplementaryCodePoint} is generally preferred.
*/
public static boolean neededFor(int uc) {
return Character.isSupplementaryCodePoint(uc);
@@ -110,6 +104,7 @@
/**
* Converts the given surrogate pair into a 32-bit UCS-4 character.
+ * Use of {@link Character#toCodePoint} is generally preferred.
*/
public static int toUCS4(char c, char d) {
assert Character.isHighSurrogate(c) && Character.isLowSurrogate(d);
@@ -290,8 +285,9 @@
* error() will return a descriptive result object
*/
public int generate(int uc, int len, CharBuffer dst) {
- if (Surrogate.isBMPCodePoint(uc)) {
- if (Surrogate.is(uc)) {
+ if (Character.isBmpCodePoint(uc)) {
+ char c = (char) uc;
+ if (Character.isSurrogate(c)) {
error = CoderResult.malformedForLength(len);
return -1;
}
@@ -299,10 +295,10 @@
error = CoderResult.OVERFLOW;
return -1;
}
- dst.put((char)uc);
+ dst.put(c);
error = null;
return 1;
- } else if (Character.isSupplementaryCodePoint(uc)) {
+ } else if (Character.isValidCodePoint(uc)) {
if (dst.remaining() < 2) {
error = CoderResult.OVERFLOW;
return -1;
@@ -334,8 +330,9 @@
* error() will return a descriptive result object
*/
public int generate(int uc, int len, char[] da, int dp, int dl) {
- if (Surrogate.isBMPCodePoint(uc)) {
- if (Surrogate.is(uc)) {
+ if (Character.isBmpCodePoint(uc)) {
+ char c = (char) uc;
+ if (Character.isSurrogate(c)) {
error = CoderResult.malformedForLength(len);
return -1;
}
@@ -343,10 +340,10 @@
error = CoderResult.OVERFLOW;
return -1;
}
- da[dp] = (char)uc;
+ da[dp] = c;
error = null;
return 1;
- } else if (Character.isSupplementaryCodePoint(uc)) {
+ } else if (Character.isValidCodePoint(uc)) {
if (dl - dp < 2) {
error = CoderResult.OVERFLOW;
return -1;