Skip to main content

cr_outside_strings_present

Function cr_outside_strings_present 

Source
pub fn cr_outside_strings_present(src: &str) -> bool
Expand description

true iff src contains at least one \r byte OUTSIDE a string literal — i.e. the byte sequence the canonical formatter would fold to \n via crlf_to_lf_outside_strings.

This is the explicit predicate companion to the Cow return of crlf_to_lf_outside_strings. Tooling that only needs to know whether the fold would change bytes (the CLI --diff “CR-bearing line endings folded” cause line, the LSP did-the-formatter-touch-this guard) should call this instead of matching on Cow::Owned, which conflates allocation with semantic change. A future optimization that pre-allocated the Cow even on a no-op fold would silently invert that match-on-Cow guard; this predicate keeps the question answered by the bytes, not by allocation behavior.