4 ms·
> If the internal representation were UTF-8, simplistically, `charAt(i)` would change from O(1) to O(N). 16 bits is not enough space to store all unicode chara
by Phrodo_00 3y ago
> If the internal representation were UTF-8, simplistically, `charAt(i)` would change from O(1) to O(N).
16 bits is not enough space to store all unicode characters. Does that mean that java's charAt won't join chars for codepoints over U+FFFF?
Edit: Yeah, that's exactly what happens[1]. That's not a very nice implementation at all .
> Because 16-bit encoding supports 2^16 (65,536) characters, which is insufficient to define all characters in use throughout the world, the Unicode standard was extended to 0x10FFFF, which supports over one million characters. The definition of a character in the Java programming language could not be changed from 16 bits to 32 bits without causing millions of Java applications to no longer run properly. To correct the definition, a scheme was developed to handle characters that could not be encoded in 16 bits.
> The characters with values that are outside of the 16-bit range, and within the range from 0x10000 to 0x10FFFF, are called supplementary characters and are defined as a pair of char values.
[1] https://docs.oracle.com/javase/tutorial/i18n/text/unicode.html https://docs.oracle.com/javase/tutorial/i18n/text/unicode.ht...