Skip to main content

normalize_line_endings

Function normalize_line_endings 

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

#1763: source with every line ending made LF, borrowed when there is nothing to change. The canonical form uses LF, and comparing a file against it modulo line endings is what keeps a Windows checkout (core.autocrlf=true) of a canonical file canonical.

A run of CRs before an LF (\r\n, \r\r\n, …) is one line ending, so this is a fixed point: normalising its own output changes nothing (#1775 review; a single replace turned \r\r\n into a \r\n a second pass would change again). A CR not before an LF is left alone; the lexer treats it as whitespace. Normalising can’t change a program value, since a string literal can’t span a line (bynk.lex.unterminated_string).