mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-23 08:39:37 +08:00
wcstoi: remove the consume_all / consumed_all machinery
Nothing sets these, so they can be removed. Also remove CharsLeft for the same reason.
This commit is contained in:
parent
60d439ab22
commit
dec3976a1f
|
@ -218,7 +218,7 @@ impl<'a> builtin_printf_state_t<'a> {
|
|||
Error::Empty => {
|
||||
self.fatal_error(sprintf!("%ls: %ls", s, wgettext!("Number was empty")));
|
||||
}
|
||||
Error::InvalidChar | Error::CharsLeft => {
|
||||
Error::InvalidChar => {
|
||||
panic!("Unreachable");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,4 @@ pub enum Error {
|
|||
// The input string contained an invalid char.
|
||||
// Note this may not be returned for conversions which stop at invalid chars.
|
||||
InvalidChar,
|
||||
|
||||
// There were chars remaining in the input.
|
||||
CharsLeft,
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ use std::result::Result;
|
|||
struct ParseResult {
|
||||
result: u64,
|
||||
negative: bool,
|
||||
consumed_all: bool,
|
||||
consumed: usize,
|
||||
}
|
||||
|
||||
|
@ -20,9 +19,6 @@ pub struct Options {
|
|||
/// For example, strtoul("-2") returns ULONG_MAX - 1.
|
||||
pub wrap_negatives: bool,
|
||||
|
||||
/// If set, it is an error to have unconsumed characters.
|
||||
pub consume_all: bool,
|
||||
|
||||
/// The radix, or None to infer it.
|
||||
pub mradix: Option<u32>,
|
||||
}
|
||||
|
@ -109,7 +105,6 @@ fn parse_radix<Iter: Iterator<Item = char>>(
|
|||
leading_zero_result = Some(ParseResult {
|
||||
result: 0,
|
||||
negative: false,
|
||||
consumed_all: chars.peek().is_none(),
|
||||
consumed: chars.consumed,
|
||||
});
|
||||
match chars.current() {
|
||||
|
@ -152,11 +147,9 @@ fn parse_radix<Iter: Iterator<Item = char>>(
|
|||
if result == 0 {
|
||||
negative = false;
|
||||
}
|
||||
let consumed_all = chars.peek().is_none();
|
||||
Ok(ParseResult {
|
||||
result,
|
||||
negative,
|
||||
consumed_all,
|
||||
consumed,
|
||||
})
|
||||
}
|
||||
|
@ -177,23 +170,19 @@ where
|
|||
|
||||
let Options {
|
||||
wrap_negatives,
|
||||
consume_all,
|
||||
mradix,
|
||||
} = options;
|
||||
|
||||
let ParseResult {
|
||||
result,
|
||||
negative,
|
||||
consumed_all,
|
||||
consumed,
|
||||
} = parse_radix(src, mradix, !signed && !wrap_negatives)?;
|
||||
*out_consumed = consumed;
|
||||
|
||||
assert!(!negative || result > 0, "Should never get negative zero");
|
||||
|
||||
if consume_all && !consumed_all {
|
||||
Err(Error::CharsLeft)
|
||||
} else if !negative {
|
||||
if !negative {
|
||||
match Int::from(result) {
|
||||
Some(r) => Ok(r),
|
||||
None => Err(Error::Overflow),
|
||||
|
@ -410,7 +399,7 @@ mod tests {
|
|||
s.chars(),
|
||||
Options {
|
||||
wrap_negatives: true,
|
||||
..Default::default()
|
||||
mradix: None,
|
||||
},
|
||||
)
|
||||
};
|
||||
|
@ -420,7 +409,6 @@ mod tests {
|
|||
Options {
|
||||
wrap_negatives: true,
|
||||
mradix: Some(radix),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user