use util_str::read_str_to_lines

This commit is contained in:
2020-05-05 13:30:06 +08:00
parent 9587124132
commit d2e01d450f
3 changed files with 4 additions and 35 deletions

View File

@@ -9,6 +9,7 @@ use std::{
use chrono::prelude::*;
use serde::{ Deserialize, Serialize, };
use rust_util::{
util_str::read_str_to_lines,
util_file::locate_file,
util_msg::{ print_info, print_error, print_debug, }
};
@@ -139,35 +140,3 @@ fn ps_aux() -> Option<String> {
},
}
}
/// Split string to lines, splited by '\r', '\n' or "\r\n"
fn read_str_to_lines(s: &str) -> Vec<String> {
let mut r = vec![];
let mut line = String::new();
let mut cs = s.chars();
while let Some(c) = cs.next() {
if c == '\n' || c == '\r' {
r.push(line.clone());
line.clear();
if c == '\r' {
if let Some(nc) = cs.next() {
if nc == '\n' {
// IGNORE
} else if nc == '\r' {
r.push("".to_owned());
} else {
line.push(nc);
}
} else {
break;
}
}
} else {
line.push(c);
}
}
if !line.is_empty() {
r.push(line);
}
r
}