diff options
author | Jeff Waugh <jdub@bethesignal.org> | 2016-11-15 14:37:20 +1100 |
---|---|---|
committer | Jeff Waugh <jdub@bethesignal.org> | 2016-11-16 05:31:02 +1100 |
commit | 8270a0ca766ea834032daeb67c7f32a1947ab3bd (patch) | |
tree | b3bbdb0f98e5da995f91c89fbf5b10ecb8290bde /src/regex_set.rs | |
parent | 6e78bb8d56d875619d20e343d0f3109e2d6b6841 (diff) |
Transition to libbindgen sub-crate
- The root crate is the `bindgen` binary
- Rust-ify the test suite, no more subprocesses!
- Update Travis config to test both crates
Diffstat (limited to 'src/regex_set.rs')
-rw-r--r-- | src/regex_set.rs | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/src/regex_set.rs b/src/regex_set.rs deleted file mode 100644 index 93130590..00000000 --- a/src/regex_set.rs +++ /dev/null @@ -1,66 +0,0 @@ -//! A type that represents the union of a set of regular expressions. - -use regex::Regex; -use std::borrow::Borrow; - -// Yeah, I'm aware this is sorta crappy, should be cheaper to compile a regex -// ORing all the patterns, I guess... - -/// A dynamic set of regular expressions. -#[derive(Debug)] -pub struct RegexSet { - items: Vec<Regex>, -} - -impl RegexSet { - /// Is this set empty? - pub fn is_empty(&self) -> bool { - self.items.is_empty() - } - - /// Extend this set with every regex in the iterator. - pub fn extend<I>(&mut self, iter: I) - where I: IntoIterator<Item = String>, - { - for s in iter.into_iter() { - self.insert(&s) - } - } - - /// Insert a new regex into this set. - pub fn insert<S>(&mut self, string: &S) - where S: Borrow<str>, - { - let s = string.borrow(); - match Regex::new(&format!("^{}$", s)) { - Ok(r) => { - self.items.push(r); - } - Err(err) => { - error!("Invalid pattern provided: {}, {:?}", s, err); - } - } - } - - /// Does the given `string` match any of the regexes in this set? - pub fn matches<S>(&self, string: &S) -> bool - where S: Borrow<str>, - { - let s = string.borrow(); - for r in &self.items { - if r.is_match(s) { - return true; - } - } - - false - } -} - -impl Default for RegexSet { - fn default() -> Self { - RegexSet { - items: vec![], - } - } -} |