CESU-8: Difference between revisions
Matthiaspaul (talk | contribs) +link |
fix terminology |
||
Line 1: | Line 1: | ||
The '''Compatibility Encoding Scheme for UTF-16: 8-Bit''' ('''CESU-8''') is a variant of [[UTF-8]] that is described in [[Unicode]] Technical Report #26 [http://www.unicode.org/reports/tr26/]. |
The '''Compatibility Encoding Scheme for UTF-16: 8-Bit''' ('''CESU-8''') is a variant of [[UTF-8]] that is described in [[Unicode]] Technical Report #26 [http://www.unicode.org/reports/tr26/]. It encodes character sequences to byte sequences in two stages. First the string is encoded according to [[UTF-16]], using [[surrogate pair]]s to represent code points outside the range U+0000 to U+FFFF. Then each UTF-16 code unit is further encoded according to the rules of UTF-8, ignoring UTF-8's prohibition against encoding surrogates. CESU-8 needs six bytes (3 bytes per surrogate) for each Unicode supplementary character while UTF-8 needs only four. Each CESU-8 character code (1, 2, or 3 bytes) can be converted to exactly one UTF-16 code unit (2 bytes). |
||
The encoding of Unicode supplementary characters works out to <code>11101101 1010yyyy 10xxxxxx 11101101 1011xxxx 10xxxxxx</code> (yyyy represents the top five bits of the character minus one i.e. U+10**** becomes 1111, U+01**** becomes 0000, x represents the remaining bits of the character). |
The encoding of Unicode supplementary characters works out to <code>11101101 1010yyyy 10xxxxxx 11101101 1011xxxx 10xxxxxx</code> (yyyy represents the top five bits of the character minus one i.e. U+10**** becomes 1111, U+01**** becomes 0000, x represents the remaining bits of the character). |
Revision as of 19:33, 18 November 2016
The Compatibility Encoding Scheme for UTF-16: 8-Bit (CESU-8) is a variant of UTF-8 that is described in Unicode Technical Report #26 [1]. It encodes character sequences to byte sequences in two stages. First the string is encoded according to UTF-16, using surrogate pairs to represent code points outside the range U+0000 to U+FFFF. Then each UTF-16 code unit is further encoded according to the rules of UTF-8, ignoring UTF-8's prohibition against encoding surrogates. CESU-8 needs six bytes (3 bytes per surrogate) for each Unicode supplementary character while UTF-8 needs only four. Each CESU-8 character code (1, 2, or 3 bytes) can be converted to exactly one UTF-16 code unit (2 bytes).
The encoding of Unicode supplementary characters works out to 11101101 1010yyyy 10xxxxxx 11101101 1011xxxx 10xxxxxx
(yyyy represents the top five bits of the character minus one i.e. U+10**** becomes 1111, U+01**** becomes 0000, x represents the remaining bits of the character).
CESU-8 is not an official part of the Unicode Standard, because Unicode Technical Reports are informative documents only. It should be used exclusively for internal processing and never for external data exchange.
CESU-8 is similar to Java's Modified UTF-8 but does not have the special encoding of the NUL character (U+0000).
The Oracle database actually uses CESU-8 for its "UTF8" character set. Standard UTF-8 can be obtained using the character set "AL32UTF8" (since Oracle version 9.0).
Examples
Encoding | Unicode code point | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
U+0045 | U+0205 | U+10400 | |||||||||||||||||
E | ȅ | 𐐀 | |||||||||||||||||
UTF-8 | 45 | C8 | 85 | F0 | 90 | 90 | 80 | ||||||||||||
UTF-16 | 0045 | 0205 | D801 | DC00 | |||||||||||||||
CESU-8 | 45 | C8 | 85 | ED | A0 | 81 | ED | B0 | 80 |