TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A string of unexpected lengths

45 pointsby thomasballingerover 10 years ago

2 comments

panicover 10 years ago
Swift&#x27;s String class (<a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html" rel="nofollow">https:&#x2F;&#x2F;developer.apple.com&#x2F;library&#x2F;ios&#x2F;documentation&#x2F;Swift&#x2F;...</a>) uses extended grapheme clusters as characters. If you need the raw Unicode scalars or UTF-16&#x2F;UTF-8 code units, there are separate &quot;views&quot; 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!
评论 #9086195 未加载
评论 #9085860 未加载
ChuckMcMover 10 years ago
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.
评论 #9083237 未加载