Skip to content

Commit a46da8d

Browse files
committed
uucore: format: num_parser: Allow uppercase exponent
1E3 and 0x1P3 are acceptable numbers. Sprinkle uppercase values in the tests.
1 parent 16131b8 commit a46da8d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/uucore/src/lib/features/format/num_parser.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,10 @@ fn parse(
432432
};
433433

434434
// Parse the exponent part, only decimal numbers are allowed.
435-
if chars.peek().is_some_and(|&(_, c)| c == exp_char) {
435+
if chars
436+
.peek()
437+
.is_some_and(|&(_, c)| c.to_ascii_lowercase() == exp_char)
438+
{
436439
chars.next();
437440
let exp_negative = match chars.peek() {
438441
Some((_, '-')) => {
@@ -570,8 +573,8 @@ mod tests {
570573
assert_eq!(Ok(-123.15), f64::extended_parse("-0123.15"));
571574
assert_eq!(Ok(12315000.0), f64::extended_parse("123.15e5"));
572575
assert_eq!(Ok(-12315000.0), f64::extended_parse("-123.15e5"));
573-
assert_eq!(Ok(12315000.0), f64::extended_parse("123.15e+5"));
574-
assert_eq!(Ok(0.0012315), f64::extended_parse("123.15e-5"));
576+
assert_eq!(Ok(12315000.0), f64::extended_parse("123.15E+5"));
577+
assert_eq!(Ok(0.0012315), f64::extended_parse("123.15E-5"));
575578
assert_eq!(
576579
Ok(0.15),
577580
f64::extended_parse(".150000000000000000000000000231313")
@@ -655,7 +658,7 @@ mod tests {
655658
12315.into(),
656659
102
657660
))),
658-
ExtendedBigDecimal::extended_parse("123.15e-100")
661+
ExtendedBigDecimal::extended_parse("123.15E-100")
659662
);
660663
// Very high precision that would not fit in a f64.
661664
assert_eq!(
@@ -724,7 +727,7 @@ mod tests {
724727
assert_eq!(Ok(0.0625), f64::extended_parse("0x.1"));
725728
assert_eq!(Ok(15.007_812_5), f64::extended_parse("0xf.02"));
726729
assert_eq!(Ok(16.0), f64::extended_parse("0x0.8p5"));
727-
assert_eq!(Ok(0.0625), f64::extended_parse("0x1p-4"));
730+
assert_eq!(Ok(0.0625), f64::extended_parse("0x1P-4"));
728731

729732
// We cannot really check that 'e' is not a valid exponent indicator for hex floats...
730733
// but we can check that the number still gets parsed properly: 0x0.8e5 is 0x8e5 / 16**3
@@ -751,7 +754,7 @@ mod tests {
751754
Err(ExtendedParserError::Overflow(ExtendedBigDecimal::Infinity))
752755
));
753756
assert!(matches!(
754-
ExtendedBigDecimal::extended_parse(&format!("-0x100p{}", u32::MAX as u64 + 1)),
757+
ExtendedBigDecimal::extended_parse(&format!("-0x100P{}", u32::MAX as u64 + 1)),
755758
Err(ExtendedParserError::Overflow(
756759
ExtendedBigDecimal::MinusInfinity
757760
))

0 commit comments

Comments
 (0)