-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Getting the first character of a string is way too verbose #24617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We don't generally handle Unicode characters/glyphs in the core library. The One point against Runes is that characters are often the wrong level of abstraction anyway - one should probably be using grapheme clusters - characters + combining marks because the first charactor of "e\u0301" is "e", but the first grapheme cluster is "é". We don't have support for grapheme clusters at all. The problem with Unicode libraries is that they are basically very large tables where something innocuously looking like I would personally love to have strings be sequences of code points, which is also what we started with, but it is very hard to compile efficiently to JavaScript and at the time, it was impossible to do efficiently in Dartium where all DOM strings were UTF-16. |
If s[0] doesn't give you the first character then IMHO it shouldn't give you anything. Having a core API return a surrogate is a terrible API affordance, because it looks very much like it does the right thing in testing, then as soon as someone uses an emoji, it breaks in a way that requires substantial rewriting of all the string manipulation code. That's a separate bug, though. Filed #24619 . FWIW, in Flutter we already have the ICU tables (we need them for rendering). In general, for embedders like Flutter, the need to compile to JS doesn't exist, and our DOM-equivalent can be whatever we want it to be. It would be a shame to restrict our API to the lowest common denominator requirements of earlier embedders... |
A deviation would prevent to share code between platforms. |
That is true. That's more an issue for #24619 than this bug, though. |
Closing in favour of #28404 |
As far as I can tell, this is how you truncate a string to its first character:
s = new String.fromCharCode(s.runes.first)
That's far too verbose. Ideally it'd be something like
s = s[0]
ors = s.first
.Ideally, we'd drop the entire UTF-16 encoding thing and just have String be a pure-Unicode class.
The text was updated successfully, but these errors were encountered: