Make Cursor::number
less DRY.
A tiny bit of repetition makes this easier to read, and avoids a test on the "Not a base prefix" match arm.
This commit is contained in:
parent
18bfe5d8a9
commit
19967c5890
1 changed files with 10 additions and 10 deletions
|
@ -582,34 +582,34 @@ impl Cursor<'_> {
|
||||||
let mut base = Base::Decimal;
|
let mut base = Base::Decimal;
|
||||||
if first_digit == '0' {
|
if first_digit == '0' {
|
||||||
// Attempt to parse encoding base.
|
// Attempt to parse encoding base.
|
||||||
let has_digits = match self.first() {
|
match self.first() {
|
||||||
'b' => {
|
'b' => {
|
||||||
base = Base::Binary;
|
base = Base::Binary;
|
||||||
self.bump();
|
self.bump();
|
||||||
self.eat_decimal_digits()
|
if !self.eat_decimal_digits() {
|
||||||
|
return Int { base, empty_int: true };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
'o' => {
|
'o' => {
|
||||||
base = Base::Octal;
|
base = Base::Octal;
|
||||||
self.bump();
|
self.bump();
|
||||||
self.eat_decimal_digits()
|
if !self.eat_decimal_digits() {
|
||||||
|
return Int { base, empty_int: true };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
'x' => {
|
'x' => {
|
||||||
base = Base::Hexadecimal;
|
base = Base::Hexadecimal;
|
||||||
self.bump();
|
self.bump();
|
||||||
self.eat_hexadecimal_digits()
|
if !self.eat_hexadecimal_digits() {
|
||||||
|
return Int { base, empty_int: true };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Not a base prefix.
|
// Not a base prefix.
|
||||||
'0'..='9' | '_' | '.' | 'e' | 'E' => {
|
'0'..='9' | '_' | '.' | 'e' | 'E' => {
|
||||||
self.eat_decimal_digits();
|
self.eat_decimal_digits();
|
||||||
true
|
|
||||||
}
|
}
|
||||||
// Just a 0.
|
// Just a 0.
|
||||||
_ => return Int { base, empty_int: false },
|
_ => return Int { base, empty_int: false },
|
||||||
};
|
|
||||||
// Base prefix was provided, but there were no digits
|
|
||||||
// after it, e.g. "0x".
|
|
||||||
if !has_digits {
|
|
||||||
return Int { base, empty_int: true };
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No base prefix, parse number in the usual way.
|
// No base prefix, parse number in the usual way.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue