Skip to content

Instantly share code, notes, and snippets.

@lopcode
Created May 15, 2017 18:51
Show Gist options
  • Save lopcode/e222b2dcd9278592659852c26fc6cc07 to your computer and use it in GitHub Desktop.
Save lopcode/e222b2dcd9278592659852c26fc6cc07 to your computer and use it in GitHub Desktop.
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