Function newline_converter::dos2unix
source · pub fn dos2unix<T: AsRef<str> + ?Sized>(input: &T) -> Cow<'_, str>
Expand description
Converts DOS-style line endings (\r\n
) to UNIX-style (\n
).
The input string may already be in correct format, so this function
returns Cow<str>
, to avoid unnecessary allocation and copying.
Examples
assert_eq!(newline_converter::dos2unix("\r\nfoo\r\nbar\r\n"), "\nfoo\nbar\n");
Lone \r
bytes will be preserved:
assert_eq!(
newline_converter::dos2unix("\nfoo\rbar\r\n"),
"\nfoo\rbar\n"
);