Treating a Java char as a complete character breaks on surrogate pairs and can split user-readable text incorrectly. BreakIterator.getCharacterInstance() finds boundaries that preserve surrogate pairs, combining character sequences, ligature clusters, and modifiers. section 6.1
Find character boundaries
BreakIterator iterator = BreakIterator.getCharacterInstance(); iterator.setText(string); iterator.first(); int from = iterator.next(rowLength * rowNumber); int to = iterator.next(rowLength - 1); section 6.1
Avoid character-processing failures by following these rules:
- Use codepoint-aware int overloads for character classification instead of char overloads. section 6.1
- Use special text APIs for user-readable text, and isolate text processing in utilities or reusable libraries such as ICU4J. section 6.1
