3个版本

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

698文本处理

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

每月 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