equal
deleted
inserted
replaced
3588 * @see Character#isValidCodePoint(int) |
3588 * @see Character#isValidCodePoint(int) |
3589 * @since 1.5 |
3589 * @since 1.5 |
3590 */ |
3590 */ |
3591 public static UnicodeBlock of(int codePoint) { |
3591 public static UnicodeBlock of(int codePoint) { |
3592 if (!isValidCodePoint(codePoint)) { |
3592 if (!isValidCodePoint(codePoint)) { |
3593 throw new IllegalArgumentException(); |
3593 throw new IllegalArgumentException( |
|
3594 String.format("Not a valid Unicode code point: 0x%X", codePoint)); |
3594 } |
3595 } |
3595 |
3596 |
3596 int top, bottom, current; |
3597 int top, bottom, current; |
3597 bottom = 0; |
3598 bottom = 0; |
3598 top = blockStarts.length; |
3599 top = blockStarts.length; |
3647 * @since 1.5 |
3648 * @since 1.5 |
3648 */ |
3649 */ |
3649 public static final UnicodeBlock forName(String blockName) { |
3650 public static final UnicodeBlock forName(String blockName) { |
3650 UnicodeBlock block = map.get(blockName.toUpperCase(Locale.US)); |
3651 UnicodeBlock block = map.get(blockName.toUpperCase(Locale.US)); |
3651 if (block == null) { |
3652 if (block == null) { |
3652 throw new IllegalArgumentException(); |
3653 throw new IllegalArgumentException("Not a valid block name: " |
|
3654 + blockName); |
3653 } |
3655 } |
3654 return block; |
3656 return block; |
3655 } |
3657 } |
3656 } |
3658 } |
3657 |
3659 |
7392 * @see Character#isValidCodePoint(int) |
7394 * @see Character#isValidCodePoint(int) |
7393 * |
7395 * |
7394 */ |
7396 */ |
7395 public static UnicodeScript of(int codePoint) { |
7397 public static UnicodeScript of(int codePoint) { |
7396 if (!isValidCodePoint(codePoint)) |
7398 if (!isValidCodePoint(codePoint)) |
7397 throw new IllegalArgumentException(); |
7399 throw new IllegalArgumentException( |
|
7400 String.format("Not a valid Unicode code point: 0x%X", codePoint)); |
7398 int type = getType(codePoint); |
7401 int type = getType(codePoint); |
7399 // leave SURROGATE and PRIVATE_USE for table lookup |
7402 // leave SURROGATE and PRIVATE_USE for table lookup |
7400 if (type == UNASSIGNED) |
7403 if (type == UNASSIGNED) |
7401 return UNKNOWN; |
7404 return UNKNOWN; |
7402 int index = Arrays.binarySearch(scriptStarts, codePoint); |
7405 int index = Arrays.binarySearch(scriptStarts, codePoint); |
8086 return 1; |
8089 return 1; |
8087 } else if (isValidCodePoint(codePoint)) { |
8090 } else if (isValidCodePoint(codePoint)) { |
8088 toSurrogates(codePoint, dst, dstIndex); |
8091 toSurrogates(codePoint, dst, dstIndex); |
8089 return 2; |
8092 return 2; |
8090 } else { |
8093 } else { |
8091 throw new IllegalArgumentException(); |
8094 throw new IllegalArgumentException( |
|
8095 String.format("Not a valid Unicode code point: 0x%X", codePoint)); |
8092 } |
8096 } |
8093 } |
8097 } |
8094 |
8098 |
8095 /** |
8099 /** |
8096 * Converts the specified character (Unicode code point) to its |
8100 * Converts the specified character (Unicode code point) to its |
8114 } else if (isValidCodePoint(codePoint)) { |
8118 } else if (isValidCodePoint(codePoint)) { |
8115 char[] result = new char[2]; |
8119 char[] result = new char[2]; |
8116 toSurrogates(codePoint, result, 0); |
8120 toSurrogates(codePoint, result, 0); |
8117 return result; |
8121 return result; |
8118 } else { |
8122 } else { |
8119 throw new IllegalArgumentException(); |
8123 throw new IllegalArgumentException( |
|
8124 String.format("Not a valid Unicode code point: 0x%X", codePoint)); |
8120 } |
8125 } |
8121 } |
8126 } |
8122 |
8127 |
8123 static void toSurrogates(int codePoint, char[] dst, int index) { |
8128 static void toSurrogates(int codePoint, char[] dst, int index) { |
8124 // We write elements "backwards" to guarantee all-or-nothing |
8129 // We write elements "backwards" to guarantee all-or-nothing |
10176 * |
10181 * |
10177 * @since 1.7 |
10182 * @since 1.7 |
10178 */ |
10183 */ |
10179 public static String getName(int codePoint) { |
10184 public static String getName(int codePoint) { |
10180 if (!isValidCodePoint(codePoint)) { |
10185 if (!isValidCodePoint(codePoint)) { |
10181 throw new IllegalArgumentException(); |
10186 throw new IllegalArgumentException( |
|
10187 String.format("Not a valid Unicode code point: 0x%X", codePoint)); |
10182 } |
10188 } |
10183 String name = CharacterName.getInstance().getName(codePoint); |
10189 String name = CharacterName.getInstance().getName(codePoint); |
10184 if (name != null) |
10190 if (name != null) |
10185 return name; |
10191 return name; |
10186 if (getType(codePoint) == UNASSIGNED) |
10192 if (getType(codePoint) == UNASSIGNED) |