4 ms·
At the very least least you need to know which code point clusters are one visual character for stepping the cursor left and right through text in a text editin
by kaetemi 5y ago
At the very least least you need to know which code point clusters are one visual character for stepping the cursor left and right through text in a text editing control.
Which is 99% of the work to also calculate the length in those terms.
- forgotmypw17 5y agoAlso, for doing `substr()` to limit the length of a title, for example. I'm still struggling with this in one place, where, for some reason, Cyrillic characters get cut in half.
- AndriyKunitsyn 5y agoIf your substr() cuts characters in half, then the reason is simple - it's either not aware of multi-byte encodings, so it cuts by bytes instead of cutting by characters, or the encoding it uses is different from the encoding of your string, so substr() cuts it wrong. You may visualize all that by converting your strings to lists of bytes.
- kaetemi 5y agoThat's the point. You can lose accents, or other parts of a character, even if you are aware of the encoding. You need to be aware of the modifiers as well.