aboutsummaryrefslogtreecommitdiff
path: root/src/dl_list.rs
blob: 17d49fc8cd95e82d5d43b6ce2a15da7e22f64550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use super::regex::Regex;

#[derive(Debug, Serialize)]
pub struct DLListItem {
    name: String,
    value: String,
}

pub fn parse(s: &str) -> Vec<DLListItem> {
    let reg_list_item = Regex::new(r#"(?is)<dt.*?>(.*?)</dt>.*?<dd>(.*?)</dd>"#).unwrap();

    reg_list_item.captures_iter(s)
                 .map(|c| {
                     DLListItem {
                         name: c.at(1).unwrap().into(),
                         value: c.at(2).unwrap().into(),
                     }
                 })
                 .collect()
}