[github-405] more performant codepoint util code. Thanks to StanBertrand. This closes #405

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905932 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2022-12-12 14:59:35 +00:00
parent f8fd8eb2e3
commit e9aa298e1e
2 changed files with 1 additions and 2 deletions

View File

@ -23,7 +23,7 @@ import java.util.Iterator;
public class CodepointsUtil {
public static Iterator<String> iteratorFor(String text) {
return text.codePoints()
.mapToObj(codePoint -> new StringBuilder().appendCodePoint(codePoint).toString())
.mapToObj(codePoint -> new String(Character.toChars(codePoint)))
.iterator();
}
}

View File

@ -35,7 +35,6 @@ class TestCodepointsUtil {
void testIterator() {
final String unicodeSurrogates = "\uD835\uDF4A\uD835\uDF4B\uD835\uDF4C\uD835\uDF4D\uD835\uDF4E"
+ "abcdef123456";
Iterator<String> sci = CodepointsUtil.iteratorFor(unicodeSurrogates);
List<String> codePoints = new ArrayList<>();
CodepointsUtil.iteratorFor(unicodeSurrogates).forEachRemaining(codePoints::add);
assertEquals(17, codePoints.size());