use super::regex::Regex;
use std::collections::HashMap;
pub fn strip_irrelevant_content(s: &str) -> String {
let mut retn = "";
match s.find(r#"
"#) {
Some(pos) => retn = &s[pos..],
None => (),
};
match s.find(r#""#) {
Some(pos) => retn = &s[..pos],
None => (),
};
return retn.into();
}
pub struct Section {
pub name: String,
pub re: Regex,
pub keys: Vec,
pub data: HashMap,
}
impl Section {
pub fn new(name: &str, re: &str, groups: Vec) -> Self {
Section {
name: name.into(),
re: Regex::new(re).unwrap(),
keys: groups,
data: HashMap::new(),
}
}
}
pub fn split_sections(d: &str, s: &mut HashMap) {
for (_, section) in s {
for m in section.re.captures_iter(d) {
assert!(m.len() >= section.keys.len() + 1);
let mut idx = 0;
for key in §ion.keys {
section.data.insert(key.clone(), m.at(idx + 1).unwrap().into());
idx += 1;
}
}
}
}