3 ms·
If your code never needs to handle Arabic, Hindi, or Thai, and you're 100% sure that a user will never paste an Emoji into your text box, then sure - go ahead a
by dmazzoni 3y ago
If your code never needs to handle Arabic, Hindi, or Thai, and you're 100% sure that a user will never paste an Emoji into your text box, then sure - go ahead and use unicode code points.
Seriously, just try inserting an emoji into your app, then see what happens if you iterate over code points. It doesn't work, your app is broken.
Also, note that in many languages it takes more than one keystroke to type a single character, so your idea of "a single key-stroke" as an abstraction is definitely wrong.
Your abstraction of "how much text should disappear when I press backspace once" is reasonable. One unicode code point is definitely NOT the right answer, though, it's one extended grapheme cluster. Kind of annoying, but it's the only way that works.
- invalidname 3y agoWhat's the problem with Arabic, Hindi or Thai? Do you mean RTL? That should work fine even with char's. Emojis and some special characters do have a problem but the base languages should be fine with the 16 bit unicode.