Implement FileHeaderData::matches_with(&Regex)
This commit is contained in:
parent
8f8badebb3
commit
58bd36599f
1 changed files with 24 additions and 0 deletions
|
@ -5,6 +5,8 @@ use std::fmt;
|
|||
use super::parser::FileHeaderParser;
|
||||
use storage::file_id::*;
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FileHeaderSpec {
|
||||
Null,
|
||||
|
@ -56,6 +58,28 @@ impl Display for FileHeaderSpec {
|
|||
|
||||
}
|
||||
|
||||
impl FileHeaderData {
|
||||
|
||||
pub fn matches_with(&self, r: &Regex) -> bool {
|
||||
match self {
|
||||
&FileHeaderData::Text(ref t) => r.is_match(&t[..]),
|
||||
&FileHeaderData::Key{name: ref n, value: ref val} => {
|
||||
r.is_match(n) || val.matches_with(r)
|
||||
},
|
||||
|
||||
&FileHeaderData::Map{keys: ref dks} => {
|
||||
dks.iter().any(|x| x.matches_with(r))
|
||||
},
|
||||
|
||||
&FileHeaderData::Array{values: ref vs} => {
|
||||
vs.iter().any(|x| x.matches_with(r))
|
||||
}
|
||||
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MatchError<'a> {
|
||||
summary: String,
|
||||
expected: &'a FileHeaderSpec,
|
||||
|
|
Loading…
Reference in a new issue