src/share/classes/java/lang/CharSequence.java
Print this page
*** 177,204 ****
class CodePointIterator implements PrimitiveIterator.OfInt {
int cur = 0;
@Override
public void forEachRemaining(IntConsumer block) {
! while (cur < length()) {
! int cp = Character.codePointAt(CharSequence.this, cur);
! cur += Character.charCount(cp);
! block.accept(cp);
}
}
public boolean hasNext() {
return cur < length();
}
public int nextInt() {
! if (!hasNext()) {
throw new NoSuchElementException();
}
! int cp = Character.codePointAt(CharSequence.this, cur);
! cur += Character.charCount(cp);
! return cp;
}
}
return StreamSupport.intStream(() ->
Spliterators.spliteratorUnknownSize(
--- 177,227 ----
class CodePointIterator implements PrimitiveIterator.OfInt {
int cur = 0;
@Override
public void forEachRemaining(IntConsumer block) {
! final int length = length();
! int i = cur;
! try {
! while (i < length) {
! char c1 = charAt(i++);
! if (!Character.isHighSurrogate(c1) || i >= length) {
! block.accept(c1);
! } else {
! char c2 = charAt(i);
! if (Character.isLowSurrogate(c2)) {
! i++;
! block.accept(Character.toCodePoint(c1, c2));
! } else {
! block.accept(c1);
! }
! }
! }
! } finally {
! cur = i;
}
}
public boolean hasNext() {
return cur < length();
}
public int nextInt() {
! final int length = length();
!
! if (cur >= length) {
throw new NoSuchElementException();
}
! char c1 = charAt(cur++);
! if (Character.isHighSurrogate(c1) && cur < length) {
! char c2 = charAt(cur);
! if (Character.isLowSurrogate(c2)) {
! cur++;
! return Character.toCodePoint(c1, c2);
! }
! }
! return c1;
}
}
return StreamSupport.intStream(() ->
Spliterators.spliteratorUnknownSize(