-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9b0b59
commit f8953d3
Showing
4 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
use regex::Regex; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::StringMatcher; | ||
|
||
use super::EnumLoader; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct Entry { | ||
#[serde(rename = "match", with = "serde_regex")] | ||
pub match_regex: Regex, | ||
#[serde(rename = "match")] | ||
pub match_regex: StringMatcher, | ||
#[serde(rename = "with")] | ||
pub type_: EnumLoader, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use regex::Regex; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
#[serde(tag = "type")] | ||
pub enum StringMatcher { | ||
Regex { | ||
#[serde(with = "serde_regex")] | ||
regex: Regex, | ||
}, | ||
Not { | ||
matcher: Box<StringMatcher>, | ||
}, | ||
All { | ||
matchers: Vec<StringMatcher>, | ||
}, | ||
Any { | ||
matchers: Vec<StringMatcher>, | ||
}, | ||
} | ||
|
||
impl StringMatcher { | ||
pub fn is_match(&self, string: &str) -> bool { | ||
match self { | ||
StringMatcher::Regex { regex } => regex.is_match(string), | ||
StringMatcher::Not { matcher } => !matcher.is_match(string), | ||
StringMatcher::All { matchers } => { | ||
matchers.iter().all(|matcher| matcher.is_match(string)) | ||
} | ||
StringMatcher::Any { matchers } => { | ||
matchers.iter().any(|matcher| matcher.is_match(string)) | ||
} | ||
} | ||
} | ||
} |