From fc27f8cee888acf70683badca9edadb45544822c Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Tue, 21 Oct 2014 15:33:17 +0200 Subject: Initial commit. --- src/ident.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/ident.rs (limited to 'src/ident.rs') diff --git a/src/ident.rs b/src/ident.rs new file mode 100644 index 0000000..069e186 --- /dev/null +++ b/src/ident.rs @@ -0,0 +1,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 { + let c = match PATTERN.captures(s) { + Some(c) => c, + None => return None + }; + Some(Ident { + nickname: c.at(1).into_string(), + user: c.at(2).into_string(), + host: c.at(3).into_string() + }) + } +} -- cgit v1.2.3