diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 5814dd6..c29f780 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -284,24 +284,26 @@ impl Settings { RULESET_CURRENT_VERSION.to_string() } + // TODO make the return type a Result fn update_rules(&self) -> Vec<(Regex, String)> { let mut rules = self.rules.clone(); + // TODO Optimize that shit + // TODO break categories in different rules for (category, content) in &self.categories { let mut temp_rules: Vec<(Regex, String)> = Vec::new(); for (from, to) in &rules { let from = Regex::new( from.to_string() .replace( - category.as_str(), + format!("%{}", category).as_str(), format!("[{}]", content).as_str(), ) - .replace("%", "") .as_str(), ); let to = to.to_string().replace( - category, - format!("[{}]", content).replace("%", "").as_str(), + format!("%{}", category).as_str(), + format!("[{}]", content).as_str(), ); temp_rules.push((from, to)); } @@ -334,8 +336,7 @@ impl Settings { /// // set some input /// let _output = settings.apply(input); /// ``` - pub fn apply(&self, s: String) -> String { - // Replace all `%C`s by their equivalent + pub fn apply(&self, s: String) -> std::result::Result { let rules = self.update_rules(); let mut s = s.clone(); debug!("==============================================="); @@ -345,7 +346,7 @@ impl Settings { s = from.replace_all(&s, to.as_str()).to_string(); debug!("new: {}", s); } - s + Ok(s) } }