#line-ending #newline #text #eol

detect-newline-style

确定字符串的首选换行字符

3个版本

0.1.2 2023年10月25日
0.1.1 2023年10月16日
0.1.0 2023年10月3日

698文本处理

Download history 2/week @ 2024-05-13 128/week @ 2024-05-20 55/week @ 2024-05-27 45/week @ 2024-06-03 64/week @ 2024-06-10 30/week @ 2024-06-17 38/week @ 2024-06-24 96/week @ 2024-07-01 49/week @ 2024-07-08 27/week @ 2024-07-15 29/week @ 2024-07-22

每月 208 下载
用于 catppuccin-whiskers

MIT/Apache

12KB
172

detect-newline-style

Latest Version Documentation CI Status

确定字符串的首选换行字符

安装

cargo add detect-newline-style

示例

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");
}

依赖

~2–3MB
~53K SLoC