aboutsummaryrefslogtreecommitdiff
path: root/src/ident.rs
blob: 19756ca38ef17107cb8d402b17bad7fa69d96bed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use regex::Regex;

static PATTERN: Regex = regex!(":(.*)!(.*)@(.*)");

#[deriving(Show, Clone)]
pub struct Ident {
    pub nickname: String,
    pub user: String,
    pub host: String
}

impl Ident {
    pub fn parse(s: &str) -> Option<Ident> {
        let c = match PATTERN.captures(s) {
            Some(c) => c,
            None => return None
        };
        Some(Ident {
            nickname: c.at(1).unwrap().into_string(),
            user: c.at(2).unwrap().into_string(),
            host: c.at(3).unwrap().into_string()
        })
    }
}