Skip to main content

Module encoding

Module encoding 

Source
Expand description

Unicode text encodings: formats::encoding (here until 0.3.0)

Structs§

Decoder
A decoder for input in pieces: decode(piece, last, out) appends the text of each piece to out; a sequence cut between two pieces is finished by the next one. The output is the same as decoding the whole input at once with decode_label (without its byte-order mark rule; see Decoder::sniffing). Shift_JIS’s “あ” in two pieces, 0x82 and then 0xA0 with last, gives “あ”.

Enums§

Charset
a single-byte character set: the bytes below 0x80 are ASCII, the others come from its table. The single-byte encodings of the WHATWG Encoding Standard (what browsers, HTML and mail use; whatwg()) and the DOS code pages of old files (by from_code_page or by name here; no web label names them)
Encoding
Explicit text encodings; unmarked input is interpreted as UTF-8.
Error
Invalid Unicode, an encoding this crate does not decode (UTF-32, an unknown label), a caller-specified byte limit, or a character the encoding cannot encode.
Label
What a label of the WHATWG Encoding Standard names (label).
MultiByte
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).

Functions§

decode
Decode without replacement characters or guessed legacy code pages.
decode_label
Decode as the WHATWG Encoding Standard’s “decode”: a UTF-8 or UTF-16 byte-order mark wins over the label (and is dropped), else the label’s encoding; malformed input becomes U+FFFD, never an error. Limit: more than limit bytes in or out; Unsupported: no label of the standard (and no byte-order mark).
encode
Encode Unicode; UTF-16 output always includes its byte-order mark.
from_code_page
The encoding of a Windows code page number: 65001 (UTF-8), 1200 and 1201 (UTF-16), the single-byte sets (Charset::from_code_page) and the multi-byte encodings (MultiByte::from_code_page); None for the others. What RTF’s \ansicpg, DXF’s $DWGCODEPAGE or a DBF’s language driver name.
label
The encoding a label names, as the WHATWG Encoding Standard reads it (“get an encoding”): leading and trailing ASCII white space ignored, ASCII case ignored, the standard’s labels only (“latin1”, “iso-8859-1” and “ascii” are windows-1252, “utf-16” is UTF-16LE). None: no label of the standard.