aboutsummaryrefslogtreecommitdiff
path: root/src/section.rs
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2016-10-01 10:45:55 (UTC)
committerjan <jan@ruken.pw>2016-10-01 10:45:55 (UTC)
commitad63b49b94bf4b4596e6420e37d265a57b77d731 (patch)
tree73234b1a5f4d34e6b1771e4309374fd05bebd881 /src/section.rs
parenta6b37fa5e1bd505adfae4888896be2a3aa49ec3a (diff)
config entfernt, extra details parsen
Diffstat (limited to 'src/section.rs')
-rw-r--r--src/section.rs34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/section.rs b/src/section.rs
new file mode 100644
index 0000000..7e492b1
--- /dev/null
+++ b/src/section.rs
@@ -0,0 +1,34 @@
1use super::regex::Regex;
2use std::collections::HashMap;
3
4pub struct Section {
5 pub name: String,
6 pub re: Regex,
7 pub keys: Vec<String>,
8 pub data: HashMap<String, String>,
9}
10
11impl Section {
12 pub fn new(name: &str, re: &str, groups: Vec<&'static str>) -> Self {
13 Section {
14 name: name.into(),
15 re: Regex::new(re).unwrap(),
16 keys: groups.into_iter().map(|s| s.into()).collect(),
17 data: HashMap::new(),
18 }
19 }
20}
21
22pub fn process(d: &str, s: &mut HashMap<String, Section>) {
23 for (_, section) in s {
24 for m in section.re.captures_iter(d) {
25 assert!(m.len() >= section.keys.len() + 1);
26
27 let mut idx = 0;
28 for key in &section.keys {
29 section.data.insert(key.clone(), m.at(idx + 1).unwrap().into());
30 idx += 1;
31 }
32 }
33 }
34}