4 ms·
> You cannot use them for string-wise operations like substring without explicitly casting or converting them to a string. Why on earth not? Any slice of a str
by Veedrac 11y ago
> You cannot use them for string-wise operations like substring without explicitly casting or converting them to a string.
Why on earth not? Any slice of a string (with a non-pathological internal encoding) with ends on codepoint boundaries is itself a valid string. Losing that information sounds like a whole lot of pointless hassle and potential for harm. It also forces the internal string encoding to be part of the interface, since taking a slice of a string and getting a byte array requires knowing how the string is encoded to use it, but getting another string means that such details are private.
It's true that they're byte offsets, but that doesn't matter. The parser doesn't care whether it's on the 10543th grapheme or the 10597th. It just wants to know where its stuff is.