diff options
| author | Jakub Bukaj <jakub@jakub.cc> | 2014-11-18 00:23:55 +0100 |
|---|---|---|
| committer | Jakub Bukaj <jakub@jakub.cc> | 2014-11-18 00:23:55 +0100 |
| commit | db4d60afb0d17c9bff72bb7b6c3754c0e6d3f2b5 (patch) | |
| tree | 075f7946fe635b611e4474e4589229a5833be094 /src/libcore/num | |
| parent | 7137c2cc83526e1f74af472380e625fc7c552826 (diff) | |
| parent | 197a0ac481ae6d154c0966b21849432f1b32c28f (diff) | |
| download | rust-db4d60afb0d17c9bff72bb7b6c3754c0e6d3f2b5.tar.gz rust-db4d60afb0d17c9bff72bb7b6c3754c0e6d3f2b5.zip | |
rollup merge of #18911: canndrew/slice_shift_char
`slice_shift_char` splits a `str` into it's leading `char` and the remainder of the `str`. Currently, it returns a `(Option<char>, &str)` such that:
"bar".slice_shift_char() => (Some('b'), "ar")
"ar".slice_shift_char() => (Some('a'), "r")
"r".slice_shift_char() => (Some('r'), "")
"".slice_shift_char() => (None, "")
This is a little odd. Either a `str` can be split into both a head and a tail or it cannot. So the return type should be `Option<(char, &str)>`. With the current behaviour, in the case of the empty string, the `str` returned is meaningless - it is always the empty string.
This PR changes `slice_shift_char` so that:
"bar".slice_shift_char() => Some(('b', "ar"))
"ar".slice_shift_char() => Some(('a', "r"))
"r".slice_shift_char() => Some(('r', ""))
"".slice_shift_char() => None
Diffstat (limited to 'src/libcore/num')
| -rw-r--r-- | src/libcore/num/mod.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 800b0c1a905..01c9277a20b 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -1457,10 +1457,10 @@ macro_rules! from_str_radix_float_impl { } let (is_positive, src) = match src.slice_shift_char() { - (None, _) => return None, - (Some('-'), "") => return None, - (Some('-'), src) => (false, src), - (Some(_), _) => (true, src), + None => return None, + Some(('-', "")) => return None, + Some(('-', src)) => (false, src), + Some((_, _)) => (true, src), }; // The significand to accumulate @@ -1563,10 +1563,10 @@ macro_rules! from_str_radix_float_impl { // Parse the exponent as decimal integer let src = src[offset..]; let (is_positive, exp) = match src.slice_shift_char() { - (Some('-'), src) => (false, from_str::<uint>(src)), - (Some('+'), src) => (true, from_str::<uint>(src)), - (Some(_), _) => (true, from_str::<uint>(src)), - (None, _) => return None, + Some(('-', src)) => (false, from_str::<uint>(src)), + Some(('+', src)) => (true, from_str::<uint>(src)), + Some((_, _)) => (true, from_str::<uint>(src)), + None => return None, }; match (is_positive, exp) { @@ -1606,7 +1606,7 @@ macro_rules! from_str_radix_int_impl { let is_signed_ty = (0 as $T) > Int::min_value(); match src.slice_shift_char() { - (Some('-'), src) if is_signed_ty => { + Some(('-', src)) if is_signed_ty => { // The number is negative let mut result = 0; for c in src.chars() { @@ -1625,7 +1625,7 @@ macro_rules! from_str_radix_int_impl { } Some(result) }, - (Some(_), _) => { + Some((_, _)) => { // The number is signed let mut result = 0; for c in src.chars() { @@ -1644,7 +1644,7 @@ macro_rules! from_str_radix_int_impl { } Some(result) }, - (None, _) => None, + None => None, } } } |
