Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed strange behaviour for when the prefix has spaces #215

Merged
merged 2 commits into from
Nov 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/framework/standard/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,16 @@ fn find_mention_end(content: &str, conf: &Configuration) -> Option<usize> {

// Finds the end of the first continuous block of whitespace after the prefix
fn find_end_of_prefix_with_whitespace(content: &str, position: usize) -> Option<usize> {
let mut ws_split = content.split_whitespace();
if let Some(cmd) = ws_split.nth(1) {
if let Some(index_of_cmd) = content.find(cmd) {
if index_of_cmd > position && index_of_cmd <= content.len() {
let slice = unsafe { content.slice_unchecked(position, index_of_cmd) }.as_bytes();
for byte in slice.iter() {
// 0x20 is ASCII for space
if *byte != 0x20u8 {
return None;
}
}
return Some(index_of_cmd);
}
let content_len = content.len();
if position >= content_len { return None; }

let slice = unsafe { content.slice_unchecked(position, content_len) }.as_bytes();
for i in 0..slice.len() {
match slice[i] {
// \t \n \r [space]
0x09 | 0x0a | 0x0d | 0x20 => {}
_ => return if i == 0 { None } else { Some(position + i) }
}
}
None
Some(content.len())
}