diff options
| author | acdenisSK <[email protected]> | 2017-12-18 17:19:16 +0100 |
|---|---|---|
| committer | acdenisSK <[email protected]> | 2017-12-18 17:19:16 +0100 |
| commit | 08febb0d8d95bbbae9861130a756e842eae40eef (patch) | |
| tree | fba2cb36c913017ac0204478ff30644615f22b2e /src | |
| parent | Add a special `len` to `Args` (diff) | |
| download | serenity-08febb0d8d95bbbae9861130a756e842eae40eef.tar.xz serenity-08febb0d8d95bbbae9861130a756e842eae40eef.zip | |
Fix multiple char delimiters
Diffstat (limited to 'src')
| -rw-r--r-- | src/framework/standard/args.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/framework/standard/args.rs b/src/framework/standard/args.rs index 3c596a0..8c23fd6 100644 --- a/src/framework/standard/args.rs +++ b/src/framework/standard/args.rs @@ -79,11 +79,16 @@ fn parse<T: FromStr>(s: &mut String, delimiter: &str) -> Result<T, T::Err> where T::Err: StdError { let mut pos = s.find(delimiter).unwrap_or_else(|| s.len()); + let res = (&s[..pos]).parse::<T>().map_err(Error::Parse); - // +1 is for the delimiter - if pos < s.len() { - pos += 1; - } + // First find out whether the delimiter is 2 chars or longer, + // if so add those extras to the position. + // Otherwise just add `1` for 1 char delimiters. + pos += if delimiter.len() > 1 { + delimiter.len() + } else { + 1 + }; s.drain(..pos); res |