#line-ending #newline #text #eol

detect-newline-style

Determine a string's preferred newline character

3 releases

0.1.2 Oct 25, 2023
0.1.1 Oct 16, 2023
0.1.0 Oct 3, 2023

#916 in Text processing

Download history 64/week @ 2024-11-15 49/week @ 2024-11-22 53/week @ 2024-11-29 73/week @ 2024-12-06 75/week @ 2024-12-13 38/week @ 2024-12-20 198/week @ 2024-12-27 448/week @ 2025-01-03 213/week @ 2025-01-10 196/week @ 2025-01-17 339/week @ 2025-01-24 260/week @ 2025-01-31 343/week @ 2025-02-07 197/week @ 2025-02-14 182/week @ 2025-02-21 185/week @ 2025-02-28

933 downloads per month
Used in catppuccin-whiskers

MIT/Apache

12KB
172 lines

detect-newline-style

Latest Version Documentation CI Status

Determine a string's preferred newline character

Installation

cargo add detect-newline-style

Examples

use detect_newline_style::LineEnding;

fn main() {
    let text = "one\rtwo\r\nthree\nfour\n";
    let eol = LineEnding::find(text, LineEnding::LF);

    assert_eq!(eol, LineEnding::LF);

    let text = "one\rtwo\r\nthree\n";
    let eol = LineEnding::find_or_use_lf(text);

    assert_eq!(eol, LineEnding::LF);

    let text = "one\rtwo\r\nthree\n";
    let eol = LineEnding::find_or_use_crlf(text);

    assert_eq!(eol, LineEnding::CRLF);

    assert_eq!(format!("{}", LineEnding::CR), "\r");
    assert_eq!(format!("{}", LineEnding::LF), "\n");
    assert_eq!(format!("{}", LineEnding::CRLF), "\r\n");
}

Dependencies

~2–3MB
~53K SLoC