Use String instead of char or code points in Java
horstmann.com
horstmann.com
https://github.com/spullara/interviewcode/blob/master/src/ma...
Really unfortunate that Java/Windows standardized on Unicode-16 a little early.
Quite sure neither the char array nor the String constructor pretend to be thread safe and messing with the input of a constructor in parallel would break most java code in existence in weird and unexpected ways.
boolean foo() {
System.out.println("hello world".startsWith("hello"));
}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.
I would have thought the closest equivalent would be a grapheme cluster.
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.
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.
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.
So would you add z̃ as a character even though it isn't actually used in any known languages, because a tilde is used over 12 other letters already, so you might as well make characters for all of them?
Or would you skip it and only pick ones in known use...and then constantly update the tables every time you discover an obscure use of diacriticals?
My understanding is that there are some languages / writing systems where the problem is far more challenging - the possible combination of different modifiers could result in millions of possible characters, many of which are plausible even though most aren't known to be used in practice.
I think the reality is that human written language is extremely complex, and any attempt to simplify it too much will end up leaving out some languages.