| ▲ | ks2048 a day ago | ||||||||||||||||||||||
I think using "extended grapheme clusters" (EGC) (rather than code points or bytes) is a good idea. But, why not let you do "x[:2]" (or "x[0..<2]") for s String with the first two EGCs? (maybe better yet - make that return "String?") | |||||||||||||||||||||||
| ▲ | ezfe a day ago | parent | next [-] | ||||||||||||||||||||||
Because that implies that String is a random access collection. You cannot constant-time index into a String, so the API doesn't allow you to use array indexing. If you know it's safe to do you can get a representation as a list of UInt8 and then index into that. | |||||||||||||||||||||||
| ▲ | zzo38computer a day ago | parent | prev [-] | ||||||||||||||||||||||
I disagree. I think it should be indexed by bytes. One reason is what the other comment explains about not being constant-time (which is a significant reason), although the other is that this restricts it to Unicode (which has its own problems) and to specific versions of Unicode, and can potentially cause problems when using a different version of Unicode. A separate library can be used to deal with code points and/or EGC if this is important for a specific application; these features should not be inherent to the string type. | |||||||||||||||||||||||
| |||||||||||||||||||||||