3 comments

[ 4.4 ms ] story [ 16.0 ms ] thread
Why is that what is meant? I am struggling to think of a situation where the number of characters is actually needed.

What you get from this call is the number of Unicode code points, which doesn't reflect the number of "characters" using any common definition at all.

I'm concerned that misinformed advice like this will lead to even more broken implementations of things like line breaking.

Do you have an example of the behavior you're describing? The article offers a demonstration that seems to work as the author described:

https://play.rust-lang.org/?gist=5d3174958c76718508f6ab45660...

But now I'm curious. Aren't the characters in the example above comprised of multiple Unicode code points?

Unicode is more complicated than that. First of all, there is not a single definition of what the idea of a "single character" even is. It could be code points, composed characters, grapheme clusters, or something else.

However, in practice there are very few situations where a programmer would ever need to make this distinction for arbitrary text. If you give me an example of where you feel that you need to split an arbitrary string by "character", I'm pretty sure I'll be able to counter that with an explanation as to why that is not the right thing to do.