aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcurly <curlybryce@protonmail.com>2023-01-05 10:24:21 -0700
committercurly <curlybryce@protonmail.com>2023-01-05 10:24:21 -0700
commit8ab06c512ba0cfbb9ccce9376de4c3f5647b8576 (patch)
tree698f26df75845de123430d084f54b5ac2405b799 /src
parent8475fb499f114a3c8062c1067b9dd00514f8dcd4 (diff)
downloads3g-master.tar.gz
s3g-master.tar.bz2
s3g-master.zip
bugfix/cleanup line parsingHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs61
1 files changed, 33 insertions, 28 deletions
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<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');
}