Instantly share code, notes, and snippets.

Embed
What would you like to do?
fun extractGraphemeClusters(input: String): List<String> {
val characters = mutableListOf<String>()
val iterator = BreakIterator.getCharacterInstance()
iterator.setText(input)
var start = iterator.first()
var iterated = false
while (!iterated) {
val next = iterator.next()
if (next == BreakIterator.DONE) {
iterated = true
continue
}
val extracted = input.substring(start, next)
start = next
characters += extracted
}
return characters
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment