Add filter: header::field_grep::FieldGrep
This commit is contained in:
parent
0dc88877c6
commit
41564a7d8e
2 changed files with 44 additions and 0 deletions
43
libimagentryfilter/src/builtin/header/field_grep.rs
Normal file
43
libimagentryfilter/src/builtin/header/field_grep.rs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
use regex::Regex;
|
||||||
|
use toml::Value;
|
||||||
|
|
||||||
|
use libimagstore::store::Entry;
|
||||||
|
|
||||||
|
use builtin::header::field_path::FieldPath;
|
||||||
|
use filter::Filter;
|
||||||
|
|
||||||
|
/// Check whether certain header field in a entry is equal to a value
|
||||||
|
pub struct FieldGrep {
|
||||||
|
header_field_path: FieldPath,
|
||||||
|
grep: Regex,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FieldGrep {
|
||||||
|
|
||||||
|
pub fn new(path: FieldPath, grep: Regex) -> FieldGrep {
|
||||||
|
FieldGrep {
|
||||||
|
header_field_path: path,
|
||||||
|
grep: grep,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Filter for FieldGrep {
|
||||||
|
|
||||||
|
fn filter(&self, e: &Entry) -> bool {
|
||||||
|
let header = e.get_header();
|
||||||
|
self.header_field_path
|
||||||
|
.walk(header)
|
||||||
|
.map(|v| {
|
||||||
|
match v {
|
||||||
|
Value::String(s) => self.grep.captures(&s[..]).is_some(),
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
pub mod field_eq;
|
pub mod field_eq;
|
||||||
|
pub mod field_grep;
|
||||||
pub mod field_path;
|
pub mod field_path;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue