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();
}
}
\ No newline at end of file
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());