4 ms·
Could you take a crack at explaining code-unit vs code-point? I'd never heard of them, and they sort of looked like the same thing on Wikipedia.
by DigitalJack 13y ago
Could you take a crack at explaining code-unit vs code-point? I'd never heard of them, and they sort of looked like the same thing on Wikipedia.
- aardvark179 13y agoA code unit is the minimal bit length for a character in a particular encoding, so in UTF16 that's 16 bits and in UTF8 it's 8 bits. A code point is a character, that may be encoded by a single code unit or may require multiple code units. Mostly Java handles strings as 16bit code units, code point functions were only introduced at 1.5.
- DigitalJack 13y agoSo, a dumb question, If a code unit is the minimal bit length for encoding a character: why would you need more than one to encode a character? Is this just a way of saying "variable bit length character encoding?"
- lmm 13y agoIf your character encoding is fixed-bit-length then a code point and a code unit are the same thing yes. If your character encoding is variable-bit-length then a code point is a "character" and a code unit is the thing that a character may be 1 or more of (i.e. a byte in utf8, or a 2-byte thingummy in utf16). The point is that it's better to treat strings as sequences of unicode codepoints ("characters") than treat them as sequences of 16-bit utf16 units like Java does.