Swift's String class (<a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html" rel="nofollow">https://developer.apple.com/library/ios/documentation/Swift/...</a>) uses extended grapheme clusters as characters. If you need the raw Unicode scalars or UTF-16/UTF-8 code units, there are separate "views" into the string that let you iterate over these.<p>Using extended grapheme clusters as characters means truncation, concatenation, length measurement and transformations like reversal all work in the expected way, even in the presence of combining characters. More standard libraries should consider adopting this model!
Here I thought everyone learned this when they started colorizing their bash prompt and suddenly their terminal session would wrap the line before the cursor got to the right side of the screen :-)<p>The article fails to discuss non-monospaced fonts, which make this problem even more pronounced. For a long time Word would screw up a ligature if it also included a color change. The only hope is length(source_data, rendering_environment) as a function.