Converts the specified Unicode code point into a UTF-16 encoded sequence and copies the value(s) into the char array dst, starting at index dstIndex. @param codePoint the Unicode code point to encode. @param dst the destination array to copy the encoded value i
(int codePoint, char[] dst, int dstIndex)
| 2433 | * @since 1.5 |
| 2434 | */ |
| 2435 | public static int toChars(int codePoint, char[] dst, int dstIndex) { |
| 2436 | if (!isValidCodePoint(codePoint)) { |
| 2437 | throw new IllegalArgumentException(); |
| 2438 | } |
| 2439 | if (dst == null) { |
| 2440 | throw new NullPointerException(); |
| 2441 | } |
| 2442 | if (dstIndex < 0 || dstIndex >= dst.length) { |
| 2443 | throw new IndexOutOfBoundsException(); |
| 2444 | } |
| 2445 | |
| 2446 | if (isSupplementaryCodePoint(codePoint)) { |
| 2447 | if (dstIndex == dst.length - 1) { |
| 2448 | throw new IndexOutOfBoundsException(); |
| 2449 | } |
| 2450 | // See RFC 2781, Section 2.1 |
| 2451 | // http://www.faqs.org/rfcs/rfc2781.html |
| 2452 | int cpPrime = codePoint - 0x10000; |
| 2453 | int high = 0xD800 | ((cpPrime >> 10) & 0x3FF); |
| 2454 | int low = 0xDC00 | (cpPrime & 0x3FF); |
| 2455 | dst[dstIndex] = (char) high; |
| 2456 | dst[dstIndex + 1] = (char) low; |
| 2457 | return 2; |
| 2458 | } |
| 2459 | |
| 2460 | dst[dstIndex] = (char) codePoint; |
| 2461 | return 1; |
| 2462 | } |
| 2463 | |
| 2464 | /** |
| 2465 | * Converts the specified Unicode code point into a UTF-16 encoded sequence |
no test coverage detected