pub struct Decoder { /* private fields */ }Expand description
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 “あ”.
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn sniffing(label: Label) -> Decoder
pub fn sniffing(label: Label) -> Decoder
A decoder with the standard’s byte-order mark rule (its “decode”): a UTF-8, UTF-16LE or UTF-16BE byte-order mark at the start wins over the label and is dropped.
Sourcepub fn label(&self) -> Label
pub fn label(&self) -> Label
The encoding decoded: the label’s, or the byte-order mark’s once one was found.
Sourcepub fn malformed(&self) -> bool
pub fn malformed(&self) -> bool
Whether some input was malformed (a U+FFFD in the output came from an error, not from the input).
Sourcepub fn decode(&mut self, input: &[u8], last: bool, out: &mut String)
pub fn decode(&mut self, input: &[u8], last: bool, out: &mut String)
Append the text of input to out. last: no more input follows; an open sequence becomes U+FFFD,
and a following call starts a new input in the encoding label names (a byte-order mark is not looked
for again). The output grows by at most three bytes per input byte, and by six for what an earlier
piece left open.