1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
use super::regex::Regex;
use std::collections::HashMap;
pub fn strip_irrelevant_content(s: &str) -> String {
let mut retn = "";
match s.find(r#"<div class=profile id=profile>"#) {
Some(pos) => retn = &s[pos..],
None => (),
};
match s.find(r#"<INPUT style="font-size: 2em;" TYPE=SUBMIT NAME="votes" VALUE="Cast Votes">"#) {
Some(pos) => retn = &s[..pos],
None => (),
};
return retn.into();
}
pub struct Section {
pub name: String,
pub re: Regex,
pub keys: Vec<String>,
pub data: HashMap<String, String>,
}
impl Section {
pub fn new(name: &str, re: &str, groups: Vec<String>) -> Self {
Section {
name: name.into(),
re: Regex::new(re).unwrap(),
keys: groups,
data: HashMap::new(),
}
}
}
pub fn split_sections(d: &str, s: &mut Vec<Section>) {
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;
}
}
}
}
|