MCPcopy Create free account
hub / github.com/davidgiven/luje / codePointCount

Method codePointCount

lib/java/lang/Character.java:2512–2536  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 2

codePointCountMethod · 0.95
codePointCountMethod · 0.95

Calls 4

isHighSurrogateMethod · 0.95
isLowSurrogateMethod · 0.95
lengthMethod · 0.65
charAtMethod · 0.65

Tested by

no test coverage detected