From 8ab06c512ba0cfbb9ccce9376de4c3f5647b8576 Mon Sep 17 00:00:00 2001 From: curly Date: Thu, 5 Jan 2023 10:24:21 -0700 Subject: bugfix/cleanup line parsing --- src/lib.rs | 61 +++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index bb60fca..542d39f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -231,42 +231,47 @@ impl S3G { if line.contains(&self.config.file_delim) || line.contains(&self.config.command_delim) { + // Setup the line for parsing + let mut v = line.trim().split(':'); + // make sure to push the first string + match v.next() { + None => (), + Some(n) => file_string.push_str(n), + }; + let v: Vec = v.map(|x| (String::from(':') + x)).collect(); + // Parse lines for prefixes - let v: Vec<&str> = line.trim().split(':').collect(); - for s in v { - let s = match s { - "" => String::from(""), - n => { - let mut string = String::new(); - // Commands - for c in &self.config.commands { - let delim = String::new() + &self.config.command_delim.get(1..2).unwrap() + &c.0; - if n.contains(&delim) { - let n = n.replace(&delim, &c.1); - string.push_str(&n); - } + for n in v { + let n = { + let mut string = String::new(); + // Commands + for c in &self.config.commands { + let delim = String::new() + &self.config.command_delim + &c.0; + if n.contains(&delim) { + let n = n.replace(&delim, &c.1); + string.push_str(&n); } + } - // Files - if n.contains(&self.config.file_delim.get(1..2).unwrap()) { - let n: Vec<&str> = n.split(&self.config.file_delim.get(1..2).unwrap()).collect(); - for s in n { - let s = match s { - "" => String::from(""), - // Scan the file from the path - n => self.file_scan(&path::PathBuf::from(n)).unwrap_or(String::from("")), - }; + // Files + if n.contains(&self.config.file_delim) { + let n: Vec<&str> = n.split(&self.config.file_delim).collect(); + for s in n { + let s = match s { + "" => String::from(""), + // Scan the file from the path + n => self.file_scan(&path::PathBuf::from(n)).unwrap_or(String::from("")), + }; - string.push_str(&s); - } - + string.push_str(&s); } - string - }, + + } + string }; // Push matching and scanned string - file_string.push_str(&s); + file_string.push_str(&n); file_string.push('\n'); } -- cgit v1.2.3