| > The 24 Bits (3 Bytes) [3]u8 to u24 example is exactly related to utf-8 that covers all the languages but excludes the emojis. I'm not familiar with Zig, so maybe it's doing something weird here, but that doesn't really make sense with Unicode in general. First, the largest Unicode codepoint that will ever be allocated is U+10FFFF [0], which is less than 2^21, so all Unicode characters will fit in a 24-bit integer. Perhaps you're thinking of UCS-2 or UTF-16 without surrogates, which are both 16 bits wide and are limited to the BMP [1] [2] (and therefore don't include most emojis). Second, while the characters needed for most languages lie within the BMP, not all of them do [3], so it isn't really possible to support all languages while excluding emoji, aside from using the Unicode character database to exclude certain categories [4] [5]. [0]: https://www.unicode.org/faq/utf_bom.html#gen0 [1]: https://www.unicode.org/faq/utf_bom.html#utf16-11 [2]: https://en.wikipedia.org/wiki/Universal_Coded_Character_Set [3]: https://en.wikipedia.org/wiki/Plane_(Unicode)#Supplementary_... [4]: https://www.unicode.org/reports/tr44/tr44-34.html#General_Ca... [5]: https://en.wikipedia.org/wiki/Unicode_character_property#Gen... |
utf-8 encodes code points in one to four bytes, it is byte oriented vs utf-16 etc. In zig u8 is a byte, and is also (by convention) a char, although there isn't an explicit char type in zig. Technically there are chars in languages that need all 4 bytes in utf-8, but almost all of them are historical or emoji's in utf-8.
24bits (3 bytes) in utf-8 gets you Chinese, Japanese, Korean. 16 bits (2 bytes) gets you Latin letters with diacritics, Greek, and Arabic scripts. With 8 bits (1 byte) getting you Standard ASCII etc...
There is a point you could make that it may have been better to use utf-16 etc... and that we should have dropped ascii/latin-1 support, but once again go up to the 'Basic Multilingual Plane' in your [3] and notice that is covered by 24bits (3 bytes) in utf-8 encoding.
[0] https://en.wikipedia.org/wiki/UTF-8