Skip to main content

transcode_detected

Function transcode_detected 

Source
pub fn transcode_detected(
    bytes: &[u8],
    detected: DetectedEncoding,
    target: TargetEncoding,
) -> Result<TranscodeOutcome, ForgeError>
Expand description

Transcode with a pre-computed detection verdict.

Fast path: Utf8 → utf-8 returns TranscodeOutcome::Unchanged with zero allocation. Otherwise strict-decode, encode, and compare: a byte-identical result is reported as Unchanged so callers skip the write and a second pass over the same tree touches no file. Encoding refusals (ForgeError::EncodeError — the UTF-16LE NUL guard and the GB18030 unmappable scalar) come from encode and never write mojibake.