detect-newline-style

Crates.iodetect-newline-style
lib.rsdetect-newline-style
version0.1.2
sourcesrc
created_at2023-10-03 21:03:55.406483
updated_at2023-10-25 18:46:17.958595
descriptionDetermine a string's preferred newline character
homepage
repositoryhttps://github.com/busticated/rusty
max_upload_size
id991549
size13,510
Busticated (busticated)

documentation

README

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");
}
Commit count: 126

cargo fmt