[Python-Dev] UCS2/UCS4 default
Paul Moore
p.f.moore at gmail.com
Thu Jul 3 17:32:37 CEST 2008
On 03/07/2008, Guido van Rossum <guido at python.org> wrote:
> I don't see an answer there to the question of whether the length()
> method of a Java String object containing a single surrogate pair
> returns 1 or 2; I suspect it returns 2.
It appears you're right:
>type testucs.java
class testucs {
public static void main(String[] args) {
StringBuilder s = new StringBuilder("Hello, ");
s.appendCodePoint(0x2F81A);
System.out.println(s); // Display the string.
System.out.println(s.length());
}
}
>java testucs
Hello, ?
9
>java -version
java version "1.6.0_05"
Java(TM) SE Runtime Environment (build 1.6.0_05-b13)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)
> Python 3 supports things like
> chr(0x12345) and ord("\U00012345"). (And so does Python 2, using
> unichr and unicode literals.)
And Java doesn't appear to - that appendCodePoint() method was
wonderfully hard to find :-)
Paul.
More information about the Python-Dev
mailing list