#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

#851 in Text processing

Download history 29/week @ 2024-07-22 62/week @ 2024-07-29 65/week @ 2024-08-05 19/week @ 2024-08-12 69/week @ 2024-08-19 39/week @ 2024-08-26 72/week @ 2024-09-02 34/week @ 2024-09-09 16/week @ 2024-09-16 47/week @ 2024-09-23 25/week @ 2024-09-30 58/week @ 2024-10-07 61/week @ 2024-10-14 24/week @ 2024-10-21 26/week @ 2024-10-28 31/week @ 2024-11-04

147 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
~54K SLoC