Skip to content

Commit 3ab68ba

Browse files
committed
uucore: format: Fix hexadecimal uppercase print (again)
When '%A' format is specified, we also need to capitalize the `0x`, i.e. `0XEP-3`, not `0xEP-3`.
1 parent 17d81bb commit 3ab68ba

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,9 @@ fn format_float_hexadecimal(
509509
) -> String {
510510
debug_assert!(!bd.is_negative());
511511

512-
let exp_char = match case {
513-
Case::Lowercase => 'p',
514-
Case::Uppercase => 'P',
512+
let (prefix, exp_char) = match case {
513+
Case::Lowercase => ("0x", 'p'),
514+
Case::Uppercase => ("0X", 'P'),
515515
};
516516

517517
if BigDecimal::zero().eq(bd) {
@@ -607,7 +607,7 @@ fn format_float_hexadecimal(
607607
""
608608
};
609609

610-
format!("0x{first_digit}{dot}{remaining_digits}{exp_char}{exponent:+}")
610+
format!("{prefix}{first_digit}{dot}{remaining_digits}{exp_char}{exponent:+}")
611611
}
612612

613613
fn strip_fractional_zeroes_and_dot(s: &mut String) {
@@ -964,8 +964,8 @@ mod test {
964964
ForceDecimal::No,
965965
)
966966
};
967-
assert_eq!(f("0.00001"), "0xA.7C5AC4P-20");
968-
assert_eq!(f("0.125"), "0x8.000000P-6");
967+
assert_eq!(f("0.00001"), "0XA.7C5AC4P-20");
968+
assert_eq!(f("0.125"), "0X8.000000P-6");
969969

970970
// Test "0e10"/"0e-10". From cppreference.com: "If the value is ​0​, the exponent is also ​0​."
971971
let f = |digits, scale| {
@@ -1178,7 +1178,7 @@ mod test {
11781178
assert_eq!(f("%e", &(-123.0).into()), "-1.230000e+02");
11791179
assert_eq!(f("%#09.e", &(-100.0).into()), "-001.e+02");
11801180
assert_eq!(f("%# 9.E", &100.0.into()), " 1.E+02");
1181-
assert_eq!(f("% 12.2A", &(-100.0).into()), " -0xC.80P+3");
1181+
assert_eq!(f("% 12.2A", &(-100.0).into()), " -0XC.80P+3");
11821182
}
11831183

11841184
#[test]

0 commit comments

Comments
 (0)