Skip to main content

Module transcoder

Module transcoder 

Source
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 — encode prepends it manually.
  • Any decode that reports had_errors is a hard error, never a replacement-char pass-through, so mojibake is never written.
  • No newline normalization — encoding_rs preserves \r\n verbatim.

Enums§

TargetEncoding
Encodings the tool can write.
TranscodeOutcome
Result of transcoding a byte stream.

Functions§

decode_strict
Strictly decode bytes according to a prior detect verdict.
encode
Encode text into target. BOMs for utf-8-bom / utf-16le / utf-16be are prepended manually — encoding_rs never emits them.
transcode
Detect + transcode in one call. Prefer transcode_detected when the detection verdict is already known (avoids a second sniff).
transcode_detected
Transcode with a pre-computed detection verdict.