Counts the number of Unicode code points in the subsequence of the specified character sequence, as delineated by beginIndex and endIndex. Any surrogate values with missing pair values will be counted as one code point. @param seq the CharSequence to look through.
(CharSequence seq, int beginIndex,
int endIndex)
| 2510 | * @since 1.5 |
| 2511 | */ |
| 2512 | public static int codePointCount(CharSequence seq, int beginIndex, |
| 2513 | int endIndex) { |
| 2514 | if (seq == null) { |
| 2515 | throw new NullPointerException(); |
| 2516 | } |
| 2517 | int len = seq.length(); |
| 2518 | if (beginIndex < 0 || endIndex > len || beginIndex > endIndex) { |
| 2519 | throw new IndexOutOfBoundsException(); |
| 2520 | } |
| 2521 | |
| 2522 | int result = 0; |
| 2523 | for (int i = beginIndex; i < endIndex; i++) { |
| 2524 | char c = seq.charAt(i); |
| 2525 | if (isHighSurrogate(c)) { |
| 2526 | if (++i < endIndex) { |
| 2527 | c = seq.charAt(i); |
| 2528 | if (!isLowSurrogate(c)) { |
| 2529 | result++; |
| 2530 | } |
| 2531 | } |
| 2532 | } |
| 2533 | result++; |
| 2534 | } |
| 2535 | return result; |
| 2536 | } |
| 2537 | |
| 2538 | /** |
| 2539 | * Counts the number of Unicode code points in the subsequence of the |
no test coverage detected