aboutsummaryrefslogtreecommitdiff
path: root/src/framework
diff options
context:
space:
mode:
authoracdenisSK <[email protected]>2017-12-18 17:19:16 +0100
committeracdenisSK <[email protected]>2017-12-18 17:19:16 +0100
commit08febb0d8d95bbbae9861130a756e842eae40eef (patch)
treefba2cb36c913017ac0204478ff30644615f22b2e /src/framework
parentAdd a special `len` to `Args` (diff)
downloadserenity-08febb0d8d95bbbae9861130a756e842eae40eef.tar.xz
serenity-08febb0d8d95bbbae9861130a756e842eae40eef.zip
Fix multiple char delimiters
Diffstat (limited to 'src/framework')
-rw-r--r--src/framework/standard/args.rs13
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