diff options
| author | jan <jan@ruken.pw> | 2016-10-01 10:45:55 (UTC) | 
|---|---|---|
| committer | jan <jan@ruken.pw> | 2016-10-01 10:45:55 (UTC) | 
| commit | ad63b49b94bf4b4596e6420e37d265a57b77d731 (patch) | |
| tree | 73234b1a5f4d34e6b1771e4309374fd05bebd881 /src/pre_process.rs | |
| parent | a6b37fa5e1bd505adfae4888896be2a3aa49ec3a (diff) | |
config entfernt, extra details parsen
Diffstat (limited to 'src/pre_process.rs')
| -rw-r--r-- | src/pre_process.rs | 34 | 
1 files changed, 0 insertions, 34 deletions
| diff --git a/src/pre_process.rs b/src/pre_process.rs index 273562d..877ddc3 100644 --- a/src/pre_process.rs +++ b/src/pre_process.rs | |||
| @@ -1,7 +1,3 @@ | |||
| 1 | use super::regex::Regex; | ||
| 2 | |||
| 3 | use std::collections::HashMap; | ||
| 4 | |||
| 5 | pub fn strip_irrelevant_content(s: &str) -> String { | 1 | pub fn strip_irrelevant_content(s: &str) -> String { | 
| 6 | let mut retn = ""; | 2 | let mut retn = ""; | 
| 7 | match s.find(r#"<div class=profile id=profile>"#) { | 3 | match s.find(r#"<div class=profile id=profile>"#) { | 
| @@ -16,34 +12,4 @@ pub fn strip_irrelevant_content(s: &str) -> String { | |||
| 16 | return retn.into(); | 12 | return retn.into(); | 
| 17 | } | 13 | } | 
| 18 | 14 | ||
| 19 | pub struct Section { | ||
| 20 | pub name: String, | ||
| 21 | pub re: Regex, | ||
| 22 | pub keys: Vec<String>, | ||
| 23 | pub data: HashMap<String, String>, | ||
| 24 | } | ||
| 25 | 15 | ||
| 26 | impl Section { | ||
| 27 | pub fn new(name: &str, re: &str, groups: Vec<String>) -> Self { | ||
| 28 | Section { | ||
| 29 | name: name.into(), | ||
| 30 | re: Regex::new(re).unwrap(), | ||
| 31 | keys: groups, | ||
| 32 | data: HashMap::new(), | ||
| 33 | } | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | pub fn split_sections(d: &str, s: &mut HashMap<String, Section>) { | ||
| 38 | for (_, section) in s { | ||
| 39 | for m in section.re.captures_iter(d) { | ||
| 40 | assert!(m.len() >= section.keys.len() + 1); | ||
| 41 | |||
| 42 | let mut idx = 0; | ||
| 43 | for key in §ion.keys { | ||
| 44 | section.data.insert(key.clone(), m.at(idx + 1).unwrap().into()); | ||
| 45 | idx += 1; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
