diff options
author | curly <curlybryce@protonmail.com> | 2023-01-05 10:24:21 -0700 |
---|---|---|
committer | curly <curlybryce@protonmail.com> | 2023-01-05 10:24:21 -0700 |
commit | 8ab06c512ba0cfbb9ccce9376de4c3f5647b8576 (patch) | |
tree | 698f26df75845de123430d084f54b5ac2405b799 /src/lib.rs | |
parent | 8475fb499f114a3c8062c1067b9dd00514f8dcd4 (diff) | |
download | s3g-8ab06c512ba0cfbb9ccce9376de4c3f5647b8576.tar.gz s3g-8ab06c512ba0cfbb9ccce9376de4c3f5647b8576.tar.bz2 s3g-8ab06c512ba0cfbb9ccce9376de4c3f5647b8576.zip |
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 61 |
1 files changed, 33 insertions, 28 deletions
@@ -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'); } |