1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use once_cell::sync::Lazy;
use regex::Regex;

pub fn lines_count(content: &str) -> usize {
    let mut line_count: usize = 0;
    for c in content.chars() {
        if c == '\n' {
            line_count += 1;
        }
    }
    line_count
}

pub fn all_to_lf(content: &str) -> String {
    static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\r\n|\r").unwrap());
    RE.replace_all(content, "\n").to_string()
}