diff options
author | Seo Sanghyeon <sanxiyn@gmail.com> | 2018-12-19 23:38:14 +0900 |
---|---|---|
committer | Seo Sanghyeon <sanxiyn@gmail.com> | 2018-12-19 23:38:14 +0900 |
commit | 7b3038e8bdf5435d2dd56ce2115f06966f59b225 (patch) | |
tree | e4c52730c394552cf17dda16e31d453348d7842e | |
parent | 371e744e4158f23e75adb296433fc684076964ad (diff) |
Store original strings in RegexSet
-rw-r--r-- | src/lib.rs | 90 | ||||
-rw-r--r-- | src/regex_set.rs | 5 |
2 files changed, 18 insertions, 77 deletions
@@ -233,11 +233,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--bitfield-enum".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -247,11 +243,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--rustified-enum".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -261,11 +253,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--constified-enum-module".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -275,11 +263,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--constified-enum".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -289,11 +273,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--blacklist-type".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -303,11 +283,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--blacklist-function".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -317,11 +293,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--blacklist-item".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -472,11 +444,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--opaque-type".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -485,11 +453,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--raw-line".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -507,11 +471,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--whitelist-function".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -521,11 +481,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--whitelist-type".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -535,11 +491,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--whitelist-var".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -576,11 +528,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--no-partialeq".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -590,11 +538,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--no-copy".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); @@ -604,11 +548,7 @@ impl Builder { .iter() .map(|item| { output_vector.push("--no-hash".into()); - output_vector.push( - item.trim_left_matches("^") - .trim_right_matches("$") - .into(), - ); + output_vector.push(item.to_owned()); }) .count(); diff --git a/src/regex_set.rs b/src/regex_set.rs index ce8714d4..6e2ca662 100644 --- a/src/regex_set.rs +++ b/src/regex_set.rs @@ -20,7 +20,7 @@ impl RegexSet { where S: AsRef<str>, { - self.items.push(format!("^{}$", string.as_ref())); + self.items.push(string.as_ref().to_owned()); self.set = None; } @@ -34,7 +34,8 @@ impl RegexSet { /// Must be called before calling `matches()`, or it will always return /// false. pub fn build(&mut self) { - self.set = match RxSet::new(&self.items) { + let items = self.items.iter().map(|item| format!("^{}$", item)); + self.set = match RxSet::new(items) { Ok(x) => Some(x), Err(e) => { error!("Invalid regex in {:?}: {:?}", self.items, e); |