Created
May 15, 2017 18:51
-
-
Save lopcode/e222b2dcd9278592659852c26fc6cc07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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