use super::regex::Regex; use std::collections::HashMap; 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<&'static str>) -> Self { Section { name: name.into(), re: Regex::new(re).unwrap(), keys: groups.into_iter().map(|s| s.into()).collect(), data: HashMap::new(), } } } pub fn process(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; } } } }