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

4
Cargo.lock generated
View File

@@ -944,9 +944,9 @@ dependencies = [
[[package]]
name = "rust_util"
version = "0.2.4"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78e3a554df0a4e66701f3971ab0f55737d6da2bb5511a9b61da9d22dd6581d09"
checksum = "854b942370a20552f9ab927cdc4e88d1d29c59c17f07729930031c26afad16ec"
dependencies = [
"lazy_static",
"libc",

View File

@@ -11,7 +11,7 @@ tokio = { version = "0.2.6", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
argparse = "0.2.2"
rust_util = "0.2.4"
rust_util = "0.2.5"
dingtalk = "1.3.2"
chrono = "0.4.11"
# log = "0.4.8"

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
}