Fixed bug with message parsing, and updated example.
This commit is contained in:
parent
c20038951e
commit
c8dc582fd1
2 changed files with 8 additions and 8 deletions
|
@ -21,6 +21,6 @@ fn main() {
|
||||||
let server = IrcServer::from_config(config).unwrap();
|
let server = IrcServer::from_config(config).unwrap();
|
||||||
identify(&server).unwrap();
|
identify(&server).unwrap();
|
||||||
for message in server.iter() {
|
for message in server.iter() {
|
||||||
println!("RCV: {}", message);
|
println!("{}", message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,27 +57,27 @@ impl FromStr for Message {
|
||||||
let mut state = s.clone();
|
let mut state = s.clone();
|
||||||
if s.len() == 0 { return None }
|
if s.len() == 0 { return None }
|
||||||
let prefix = if state.starts_with(":") {
|
let prefix = if state.starts_with(":") {
|
||||||
let prefix = state.find(' ').map(|i| s[1..i]);
|
let prefix = state.find(' ').map(|i| state[1..i]);
|
||||||
state = state.find(' ').map_or("", |i| s[i..]);
|
state = state.find(' ').map_or("", |i| state[i+1..]);
|
||||||
prefix
|
prefix
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let suffix = if state.contains(":") {
|
let suffix = if state.contains(":") {
|
||||||
let suffix = state.find(':').map(|i| s[i..]);
|
let suffix = state.find(':').map(|i| state[i..state.len()-1]);
|
||||||
state = state.find(':').map_or("", |i| s[..i]);
|
state = state.find(':').map_or("", |i| state[..i]);
|
||||||
suffix
|
suffix
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let command = match state.find(' ').map(|i| s[..i]) {
|
let command = match state.find(' ').map(|i| state[..i]) {
|
||||||
Some(cmd) => {
|
Some(cmd) => {
|
||||||
state = state.find(' ').map_or("", |i| s[i..]);
|
state = state.find(' ').map_or("", |i| state[i+1..]);
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
_ => return None
|
_ => 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))
|
Some(Message::new(prefix, command, if args.len() > 0 { Some(args) } else { None }, suffix))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue