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
#[macro_use]
extern crate lazy_static;

extern crate regex;

use std::collections::HashMap;

mod util;

pub fn matcher<'a>(pattern: &'a str, url: &'a str) -> Option<HashMap<String, &'a str>> {

    let mut map = HashMap::new();

    let expr = util::expression(pattern);
    let re = util::regexp(&expr);

    let caps = re.captures(url)?;

    for (index, key) in re.capture_names().enumerate() {
        if let (Some(k), Some(c)) = (key, caps.get(index)) {
            map.insert(k.to_owned(), c.as_str());
        }
    }

    Some(map)

}