4 ms·
Going by bytes is also simple and objective. And also totally arbitrary, just like going by codepoints. Which is the most useful for dealing with strings in pr
by shawnz 6y ago
Going by bytes is also simple and objective. And also totally arbitrary, just like going by codepoints.
Which is the most useful for dealing with strings in practice though? Are either interpretations useful at all?
- dahfizz 6y agoGoing byte by byte is useless. You can't do anything with a single byte of a unicode codepoint (unless, by luck, the codepoint is encoded in a single byte). Codepoint is the smallest useful unit of a unicode string. It is a character, and you can do all the character things with it. If you wanted to implement a toUpper() function for example, you would want to iterate over all the codepoints.
- masklinn 6y ago> If you wanted to implement a toUpper() function for example, you would want to iterate over all the codepoints. Nope. In order to deal with special casings you will have to span multiple codepoints, at which point it's no more work with whatever the code units are.