diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/lib.rs | 61 |
3 files changed, 35 insertions, 30 deletions
@@ -4,7 +4,7 @@ version = 3 [[package]] name = "s3g" -version = "1.0.1" +version = "1.0.2" dependencies = [ "toml", ] @@ -1,6 +1,6 @@ [package] name = "s3g" -version = "1.0.1" +version = "1.0.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -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<String> = 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'); } |