mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
4993841: (str) java.lang.Character should have a toString(int) method
Reviewed-by: martin, rriggs, sherman, smarks
This commit is contained in:
parent
a131e1668f
commit
3d4edcc571
4 changed files with 91 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2018, 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
|
||||
|
@ -3157,4 +3157,27 @@ public final class String
|
|||
"begin " + begin + ", end " + end + ", length " + length);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string representation of the {@code codePoint}
|
||||
* argument.
|
||||
*
|
||||
* @param codePoint a {@code codePoint}.
|
||||
* @return a string of length {@code 1} or {@code 2} containing
|
||||
* as its single character the argument {@code codePoint}.
|
||||
* @throws IllegalArgumentException if the specified
|
||||
* {@code codePoint} is not a {@linkplain Character#isValidCodePoint
|
||||
* valid Unicode code point}.
|
||||
*/
|
||||
static String valueOfCodePoint(int codePoint) {
|
||||
if (COMPACT_STRINGS && StringLatin1.canEncode(codePoint)) {
|
||||
return new String(StringLatin1.toBytes((char)codePoint), LATIN1);
|
||||
} else if (Character.isBmpCodePoint(codePoint)) {
|
||||
return new String(StringUTF16.toBytes((char)codePoint), UTF16);
|
||||
} else if (Character.isSupplementaryCodePoint(codePoint)) {
|
||||
return new String(StringUTF16.toBytesSupplementary(codePoint), UTF16);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Not a valid Unicode code point");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue