4 ms·
You know what, just stop coding alltogether. Go touch grass. Code points are Unicode's closest equivalent to "single graphical character" and everything you've
by Zondartul 3y ago
You know what, just stop coding alltogether. Go touch grass.
Code points are Unicode's closest equivalent to "single graphical character" and everything you've been doing when iterating ASCII strings can be done using code points. It's also the closest thing to "a single key-stroke" and "how much text should disappear when I press backspace once".
The linked article suggests basically doing nothing because a few edge cases exist.
- dwaite 3y ago> Code points are Unicode's closest equivalent to "single graphical character" and everything you've been doing when iterating ASCII strings can be done using code points. I would have thought the closest equivalent would be a grapheme cluster.
- deleted 3y ago[deleted]
- pie_flavor 3y agoNo, Unicode's closest equivalent to 'single graphical character' is extended grapheme clusters, and they are explicitly defined as what should disappear when you press backspace once. Neither code points nor graphemes are equivalent to keystrokes in CJK languages; each character, precomposed or not, is written as a combination of other characters. I appreciate the desire to round off a few edge cases, but remember that this is the majority of the world's population here (not counting English/commonly-used-in-English words like jalapeño - hope that ñ is precomposed!). The only thing you can iterate ASCII-style is English minus all the diacritics in loanwords, same as ASCII itself.
- dmazzoni 3y agoIf 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.
- deleted 3y ago[deleted]