4396 } |
4396 } |
4397 return c2; |
4397 return c2; |
4398 } |
4398 } |
4399 |
4399 |
4400 /** |
4400 /** |
|
4401 * Returns the leading surrogate (a |
|
4402 * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit"> |
|
4403 * high surrogate code unit</a>) of the |
|
4404 * <a href="http://www.unicode.org/glossary/#surrogate_pair"> |
|
4405 * surrogate pair</a> |
|
4406 * representing the specified supplementary character (Unicode |
|
4407 * code point) in the UTF-16 encoding. If the specified character |
|
4408 * is not a |
|
4409 * <a href="Character.html#supplementary">supplementary character</a>, |
|
4410 * an unspecified {@code char} is returned. |
|
4411 * |
|
4412 * <p>If |
|
4413 * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)} |
|
4414 * is {@code true}, then |
|
4415 * {@link #isHighSurrogate isHighSurrogate}{@code (highSurrogate(x))} and |
|
4416 * {@link #toCodePoint toCodePoint}{@code (highSurrogate(x), }{@link #lowSurrogate lowSurrogate}{@code (x)) == x} |
|
4417 * are also always {@code true}. |
|
4418 * |
|
4419 * @param codePoint a supplementary character (Unicode code point) |
|
4420 * @return the leading surrogate code unit used to represent the |
|
4421 * character in the UTF-16 encoding |
|
4422 * @since 1.7 |
|
4423 */ |
|
4424 public static char highSurrogate(int codePoint) { |
|
4425 return (char) ((codePoint >>> 10) |
|
4426 + (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10))); |
|
4427 } |
|
4428 |
|
4429 /** |
|
4430 * Returns the trailing surrogate (a |
|
4431 * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit"> |
|
4432 * low surrogate code unit</a>) of the |
|
4433 * <a href="http://www.unicode.org/glossary/#surrogate_pair"> |
|
4434 * surrogate pair</a> |
|
4435 * representing the specified supplementary character (Unicode |
|
4436 * code point) in the UTF-16 encoding. If the specified character |
|
4437 * is not a |
|
4438 * <a href="Character.html#supplementary">supplementary character</a>, |
|
4439 * an unspecified {@code char} is returned. |
|
4440 * |
|
4441 * <p>If |
|
4442 * {@link #isSupplementaryCodePoint isSupplementaryCodePoint(x)} |
|
4443 * is {@code true}, then |
|
4444 * {@link #isLowSurrogate isLowSurrogate}{@code (lowSurrogate(x))} and |
|
4445 * {@link #toCodePoint toCodePoint}{@code (}{@link #highSurrogate highSurrogate}{@code (x), lowSurrogate(x)) == x} |
|
4446 * are also always {@code true}. |
|
4447 * |
|
4448 * @param codePoint a supplementary character (Unicode code point) |
|
4449 * @return the trailing surrogate code unit used to represent the |
|
4450 * character in the UTF-16 encoding |
|
4451 * @since 1.7 |
|
4452 */ |
|
4453 public static char lowSurrogate(int codePoint) { |
|
4454 return (char) ((codePoint & 0x3ff) + MIN_LOW_SURROGATE); |
|
4455 } |
|
4456 |
|
4457 /** |
4401 * Converts the specified character (Unicode code point) to its |
4458 * Converts the specified character (Unicode code point) to its |
4402 * UTF-16 representation. If the specified code point is a BMP |
4459 * UTF-16 representation. If the specified code point is a BMP |
4403 * (Basic Multilingual Plane or Plane 0) value, the same value is |
4460 * (Basic Multilingual Plane or Plane 0) value, the same value is |
4404 * stored in <code>dst[dstIndex]</code>, and 1 is returned. If the |
4461 * stored in <code>dst[dstIndex]</code>, and 1 is returned. If the |
4405 * specified code point is a supplementary character, its |
4462 * specified code point is a supplementary character, its |
4468 } |
4525 } |
4469 } |
4526 } |
4470 |
4527 |
4471 static void toSurrogates(int codePoint, char[] dst, int index) { |
4528 static void toSurrogates(int codePoint, char[] dst, int index) { |
4472 // We write elements "backwards" to guarantee all-or-nothing |
4529 // We write elements "backwards" to guarantee all-or-nothing |
4473 dst[index+1] = (char)((codePoint & 0x3ff) + MIN_LOW_SURROGATE); |
4530 dst[index+1] = lowSurrogate(codePoint); |
4474 dst[index] = (char)((codePoint >>> 10) |
4531 dst[index] = highSurrogate(codePoint); |
4475 + (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10))); |
|
4476 } |
4532 } |
4477 |
4533 |
4478 /** |
4534 /** |
4479 * Returns the number of Unicode code points in the text range of |
4535 * Returns the number of Unicode code points in the text range of |
4480 * the specified char sequence. The text range begins at the |
4536 * the specified char sequence. The text range begins at the |