From c8dc582fd122372c62e7b3bbb3bbf20465b37372 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Mon, 3 Nov 2014 02:30:58 -0500 Subject: [PATCH] Fixed bug with message parsing, and updated example. --- examples/simple.rs | 2 +- src/data/message.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/simple.rs b/examples/simple.rs index bf2de9f..09cf6b8 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -21,6 +21,6 @@ fn main() { let server = IrcServer::from_config(config).unwrap(); identify(&server).unwrap(); for message in server.iter() { - println!("RCV: {}", message); + println!("{}", message) } } diff --git a/src/data/message.rs b/src/data/message.rs index ce1680c..bce8057 100644 --- a/src/data/message.rs +++ b/src/data/message.rs @@ -57,27 +57,27 @@ impl FromStr for Message { let mut state = s.clone(); if s.len() == 0 { return None } let prefix = if state.starts_with(":") { - let prefix = state.find(' ').map(|i| s[1..i]); - state = state.find(' ').map_or("", |i| s[i..]); + let prefix = state.find(' ').map(|i| state[1..i]); + state = state.find(' ').map_or("", |i| state[i+1..]); prefix } else { None }; let suffix = if state.contains(":") { - let suffix = state.find(':').map(|i| s[i..]); - state = state.find(':').map_or("", |i| s[..i]); + let suffix = state.find(':').map(|i| state[i..state.len()-1]); + state = state.find(':').map_or("", |i| state[..i]); suffix } else { None }; - let command = match state.find(' ').map(|i| s[..i]) { + let command = match state.find(' ').map(|i| state[..i]) { Some(cmd) => { - state = state.find(' ').map_or("", |i| s[i..]); + state = state.find(' ').map_or("", |i| state[i+1..]); cmd } _ => return None }; - let args: Vec<_> = state.splitn(14, ' ').collect(); + let args: Vec<_> = state.splitn(14, ' ').filter(|s| s.len() != 0).collect(); Some(Message::new(prefix, command, if args.len() > 0 { Some(args) } else { None }, suffix)) } }