Skip to main content

crlf_to_lf_outside_strings

Function crlf_to_lf_outside_strings 

Source
pub fn crlf_to_lf_outside_strings(src: &str) -> Cow<'_, str>
Expand description

Replace CRLF and bare-CR line terminators with LF, but ONLY outside string literals.

String literals ("…") can contain raw \r and \n per the lexer’s STRING rule; folding CR inside a string would mutate the user’s data. Uses the shared SourceState state machine to track string / comment boundaries.

Cheap fast path: if the input contains no \r, returns the source slice borrowed (no allocation). Used by format_source before parsing so the lexer never has to see legacy line endings. Exposed publicly under crlf_to_lf_outside_strings for tooling (CLI --diff, format-equivalence checks) that needs the same string-aware normalization.