Crates.io | detect-newline-style |
lib.rs | detect-newline-style |
version | 0.1.2 |
source | src |
created_at | 2023-10-03 21:03:55.406483 |
updated_at | 2023-10-25 18:46:17.958595 |
description | Determine a string's preferred newline character |
homepage | |
repository | https://github.com/busticated/rusty |
max_upload_size | |
id | 991549 |
size | 13,510 |
Determine a string's preferred newline character
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");
}