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

Fix #7221: Unit::SI uses lowercase k for kilos

Other units remain untouched and use uppercase `K`, as well as all other suffixes

Signed-off-by: Alex Snaps <alex@wcgw.dev>
This commit is contained in:
Alex Snaps 2025-02-18 15:30:26 -05:00
parent bc995283c4
commit 1250195bce
No known key found for this signature in database
GPG key ID: D95FB9EFA518E173
2 changed files with 15 additions and 14 deletions

View file

@ -281,12 +281,12 @@ fn transform_to(
format!( format!(
"{:.precision$}{}", "{:.precision$}{}",
i2, i2,
DisplayableSuffix(s), DisplayableSuffix(s, opts.to),
precision = precision precision = precision
) )
} }
Some(s) if i2.abs() < 10.0 => format!("{:.1}{}", i2, DisplayableSuffix(s)), Some(s) if i2.abs() < 10.0 => format!("{:.1}{}", i2, DisplayableSuffix(s, opts.to)),
Some(s) => format!("{:.0}{}", i2, DisplayableSuffix(s)), Some(s) => format!("{:.0}{}", i2, DisplayableSuffix(s, opts.to)),
}) })
} }

View file

@ -45,20 +45,21 @@ pub enum RawSuffix {
pub type Suffix = (RawSuffix, WithI); pub type Suffix = (RawSuffix, WithI);
pub struct DisplayableSuffix(pub Suffix); pub struct DisplayableSuffix(pub Suffix, pub Unit);
impl fmt::Display for DisplayableSuffix { impl fmt::Display for DisplayableSuffix {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let Self((ref raw_suffix, ref with_i)) = *self; let Self((ref raw_suffix, ref with_i), unit) = *self;
match raw_suffix { match (raw_suffix, unit) {
RawSuffix::K => write!(f, "K"), (RawSuffix::K, Unit::Si) => write!(f, "k"),
RawSuffix::M => write!(f, "M"), (RawSuffix::K, _) => write!(f, "K"),
RawSuffix::G => write!(f, "G"), (RawSuffix::M, _) => write!(f, "M"),
RawSuffix::T => write!(f, "T"), (RawSuffix::G, _) => write!(f, "G"),
RawSuffix::P => write!(f, "P"), (RawSuffix::T, _) => write!(f, "T"),
RawSuffix::E => write!(f, "E"), (RawSuffix::P, _) => write!(f, "P"),
RawSuffix::Z => write!(f, "Z"), (RawSuffix::E, _) => write!(f, "E"),
RawSuffix::Y => write!(f, "Y"), (RawSuffix::Z, _) => write!(f, "Z"),
(RawSuffix::Y, _) => write!(f, "Y"),
} }
.and_then(|()| match with_i { .and_then(|()| match with_i {
true => write!(f, "i"), true => write!(f, "i"),