Add builtin header check: Field is empty
This commit is contained in:
parent
780410f29d
commit
bcf8cf0447
1 changed files with 45 additions and 0 deletions
45
libimagentryfilter/src/builtin/header/field_isempty.rs
Normal file
45
libimagentryfilter/src/builtin/header/field_isempty.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
use libimagstore::store::Entry;
|
||||
|
||||
use builtin::header::field_path::FieldPath;
|
||||
use filter::Filter;
|
||||
|
||||
use toml::Value;
|
||||
|
||||
pub struct FieldIsEmpty {
|
||||
header_field_path: FieldPath,
|
||||
}
|
||||
|
||||
impl FieldIsEmpty {
|
||||
|
||||
pub fn new(path: FieldPath) -> FieldIsEmpty {
|
||||
FieldIsEmpty {
|
||||
header_field_path: path,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl Filter for FieldIsEmpty {
|
||||
|
||||
fn filter(&self, e: &Entry) -> bool {
|
||||
let header = e.get_header();
|
||||
self.header_field_path
|
||||
.walk(header)
|
||||
.map(|v| {
|
||||
match v {
|
||||
Value::Array(a) => a.is_empty(),
|
||||
Value::Boolean(_) => false,
|
||||
Value::Float(_) => false,
|
||||
Value::Integer(_) => false,
|
||||
Value::String(_) => false,
|
||||
Value::Table(t) => t.is_empty(),
|
||||
_ => true,
|
||||
}
|
||||
})
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in a new issue