#[non_exhaustive]pub enum MultiByte {
ShiftJis,
EucJp,
Iso2022Jp,
Gbk,
Gb18030,
Big5,
EucKr,
}Expand description
A multi-byte encoding of the WHATWG Encoding Standard: the legacy encodings of Chinese, Japanese and Korean text that browsers, mail and old files still use. Each is the standard’s: the Windows variants where the web uses them (Shift_JIS is Windows’ code page 932, EUC-KR its 949, GBK its 936).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
ShiftJis
Shift_JIS: Japanese as Windows writes it (code page 932, windows-31j: JIS X 0208 with the NEC and IBM extensions, half-width katakana, the user-defined rows as the Private Use Area)
EucJp
EUC-JP: Japanese on Unix (JIS X 0208, JIS X 0212 after 0x8F, half-width katakana after 0x8E)
Iso2022Jp
ISO-2022-JP: Japanese in mail and news, 7 bits with escape sequences (ASCII, JIS X 0201 Roman and katakana, JIS X 0208)
Gbk
GBK: simplified Chinese (code page 936; also what the labels gb2312 and chinese name). It reads gb18030; it writes only its two-byte characters and the euro sign as 0x80.
Gb18030
gb18030: simplified Chinese with all of Unicode but U+E5E5, which it does not write (GB18030-2022; code page 54936)
Big5
Big5: traditional Chinese with the Hong Kong Supplementary Character Set (HKSCS-2008; code page 950)
EucKr
EUC-KR: Korean as Windows writes it (code page 949, the Unified Hangul Code: all 11 172 syllables)
Implementations§
Source§impl MultiByte
impl MultiByte
Sourcepub const fn name(self) -> &'static str
pub const fn name(self) -> &'static str
its name in the WHATWG Encoding Standard (“Shift_JIS”, “EUC-JP”, “ISO-2022-JP”, “GBK”, “gb18030”, “Big5”, “EUC-KR”)
Sourcepub const fn code_page(self) -> u16
pub const fn code_page(self) -> u16
its Windows code page number: 932, 20932, 50220, 936, 54936, 950, 949
Sourcepub const fn from_code_page(cp: u16) -> Option<MultiByte>
pub const fn from_code_page(cp: u16) -> Option<MultiByte>
the encoding of a Windows code page number: 932, 936, 949, 950, 20932 and 51932 (EUC-JP), 50220 and 50221 (ISO-2022-JP), 51949 (EUC-KR), 54936. None for the others: Johab (1361) is none of the standard’s, and 50222 writes half-width katakana between SO and SI, which the standard’s ISO-2022-JP does not read.
Sourcepub fn from_label(name: &str) -> Option<MultiByte>
pub fn from_label(name: &str) -> Option<MultiByte>
the encoding a WHATWG label names (“shift_jis”, “sjis”, “windows-31j”, “gb2312”, “big5-hkscs”,
“ks_c_5601-1987” …; encoding::label), multi-byte encodings only
Sourcepub fn decode(self, bytes: &[u8]) -> String
pub fn decode(self, bytes: &[u8]) -> String
The text of these bytes, as the standard decodes them: malformed or unassigned sequences become
U+FFFD, ASCII bytes after a broken lead byte are kept. For input in pieces: Decoder.
Sourcepub fn encode(self, text: &str) -> Result<Vec<u8>, Error>
pub fn encode(self, text: &str) -> Result<Vec<u8>, Error>
The bytes of a text; Unmappable: the first character this encoding does not have (ISO-2022-JP ends in ASCII, with ESC ( B where needed).
Sourcepub fn encode_html(self, text: &str) -> Vec<u8> ⓘ
pub fn encode_html(self, text: &str) -> Vec<u8> ⓘ
The bytes of a text, a character this encoding does not have as a decimal character reference (“😀”), as browsers submit forms (the standard’s “html” error mode).