# HG changeset patch # User mduigou # Date 1370543974 25200 # Node ID c2c0c5f9aa6511aaca88896b22cfe6404595d375 # Parent f38c5cfccd38aca2dbd0dd97466e1152ff937139# Parent acb3c688a1b83539f30fdcc333f5ac7d2cc7fcc9 Merge diff -r f38c5cfccd38 -r c2c0c5f9aa65 jdk/src/share/classes/java/lang/CharSequence.java --- a/jdk/src/share/classes/java/lang/CharSequence.java Thu Jun 06 20:43:05 2013 +0400 +++ b/jdk/src/share/classes/java/lang/CharSequence.java Thu Jun 06 11:39:34 2013 -0700 @@ -179,10 +179,25 @@ @Override public void forEachRemaining(IntConsumer block) { - while (cur < length()) { - int cp = Character.codePointAt(CharSequence.this, cur); - cur += Character.charCount(cp); - block.accept(cp); + 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; } } @@ -191,12 +206,20 @@ } public int nextInt() { - if (!hasNext()) { + final int length = length(); + + if (cur >= length) { throw new NoSuchElementException(); } - int cp = Character.codePointAt(CharSequence.this, cur); - cur += Character.charCount(cp); - return cp; + 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; } }