1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

uucore/format: cast signedint to unsignedint if possible

This commit is contained in:
Terts Diepraam 2024-02-08 13:19:13 +01:00
parent da139c9524
commit a30dce0b7c

View file

@ -168,6 +168,24 @@ impl Formatter for UnsignedInt {
}
fn try_from_spec(s: Spec) -> Result<Self, FormatError> {
// A signed int spec might be mapped to an unsigned int spec if no sign is specified
let s = if let Spec::SignedInt {
width,
precision,
positive_sign: PositiveSign::None,
alignment,
} = s
{
Spec::UnsignedInt {
variant: UnsignedIntVariant::Decimal,
width,
precision,
alignment,
}
} else {
s
};
let Spec::UnsignedInt {
variant,
width,