Expand description
Strict decode / encode / transcode.
use utf8_forge::transcoder::{decode_strict, encode, TargetEncoding};
let text = decode_strict(&[0xFF, 0xFE, b'h', 0], utf8_forge::detector::detect(&[0xFF, 0xFE, b'h', 0])).unwrap();
assert_eq!(&*text, "h");
assert_eq!(encode(&text, TargetEncoding::Utf8).unwrap(), b"h");Rules enforced here:
- UTF-16 encoders never emit a BOM by themselves —
encodeprepends it manually. - Any decode that reports
had_errorsis a hard error, never a replacement-char pass-through, so mojibake is never written. - No newline normalization —
encoding_rspreserves\r\nverbatim.
Enums§
- Target
Encoding - Encodings the tool can write.
- Transcode
Outcome - Result of transcoding a byte stream.
Functions§
- decode_
strict - Strictly decode
bytesaccording to a priordetectverdict. - encode
- Encode
textintotarget. BOMs forutf-8-bom/utf-16le/utf-16beare prepended manually —encoding_rsnever emits them. - transcode
- Detect + transcode in one call. Prefer
transcode_detectedwhen the detection verdict is already known (avoids a second sniff). - transcode_
detected - Transcode with a pre-computed detection verdict.