Rust Line Endings
| OS | Status |
|---|---|
| Ubuntu-latest | |
| macOS-latest | |
| Windows-latest |
A Rust crate to detect, normalize, and convert line endings across platforms. Ensures consistent handling of LF, CRLF, and CR line endings in text processing.
Install
Usage
Split into lines
Split a string into lines using the detected line ending.
use LineEnding;
let crlf_lines = split_into_lines;
let cr_lines = split_into_lines;
let lf_lines = split_into_lines;
let expected = vec!;
assert_eq!;
assert_eq!;
assert_eq!;
Apply to lines
Join a vector of strings with the specified line ending.
use LineEnding;
let lines = vec!;
assert_eq!;
assert_eq!;
assert_eq!;
Convert to type
Convert a string from any line ending type to a specified one.
use LineEnding;
let mixed_text = "first line\r\nsecond line\rthird line\nfourth line\n";
assert_eq!;
assert_eq!;
assert_eq!;
From string slice
Detect the predominant line ending style used in the input string.
use LineEnding;
let sample = "first line\nsecond line\nthird line";
assert_eq!;
use LineEnding;
let sample = "first line\r\nsecond line\r\nthird line";
assert_eq!;
use LineEnding;
let sample = "first line\rsecond line\rthird line";
assert_eq!;
Normalize
Convert all line endings in a string to LF (\n) for consistent processing.
use LineEnding;
let crlf = "first\r\nsecond\r\nthird";
let cr = "first\rsecond\rthird";
let lf = "first\nsecond\nthird";
assert_eq!;
assert_eq!;
assert_eq!;
Denormalize
Restore line endings in a string to the specified type.
use LineEnding;
let text = "first\nsecond\nthird";
let crlf_restored = CRLF.denormalize;
let cr_restored = CR.denormalize;
let lf_restored = LF.denormalize;
assert_eq!;
assert_eq!;
assert_eq!;
License
Licensed under MIT. See LICENSE for details.