mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
uucore/format: ignore the 0
flag if a precision is specified
This commit is contained in:
parent
5fbbfc75de
commit
3a21d27c1e
2 changed files with 26 additions and 6 deletions
|
@ -115,12 +115,6 @@ impl Spec {
|
|||
index += 1;
|
||||
}
|
||||
|
||||
let alignment = match (minus, zero) {
|
||||
(true, _) => NumberAlignment::Left,
|
||||
(false, true) => NumberAlignment::RightZero,
|
||||
(false, false) => NumberAlignment::RightSpace,
|
||||
};
|
||||
|
||||
let positive_sign = match (plus, space) {
|
||||
(true, _) => PositiveSign::Plus,
|
||||
(false, true) => PositiveSign::Space,
|
||||
|
@ -136,6 +130,17 @@ impl Spec {
|
|||
None
|
||||
};
|
||||
|
||||
// The `0` flag is ignored if `-` is given or a precision is specified.
|
||||
// So the only case for RightZero, is when `-` is not given and the
|
||||
// precision is none.
|
||||
let alignment = if minus {
|
||||
NumberAlignment::Left
|
||||
} else if zero && precision.is_none() {
|
||||
NumberAlignment::RightZero
|
||||
} else {
|
||||
NumberAlignment::RightSpace
|
||||
};
|
||||
|
||||
// We ignore the length. It's not really relevant to printf
|
||||
let _ = Self::parse_length(rest, &mut index);
|
||||
|
||||
|
|
|
@ -1357,3 +1357,18 @@ fn precision_format() {
|
|||
assert_eq!(at.read("xx 000"), generate(1, 10));
|
||||
assert_eq!(at.read("xx 0x001"), generate(10, 51));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn precision_format2() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
ucmd.args(&["numbers50.txt", "10", "--suffix-format", "%0#6.3x"])
|
||||
.succeeds()
|
||||
.stdout_only("18\n123\n");
|
||||
|
||||
let count = glob(&at.plus_as_string("xx*"))
|
||||
.expect("there should be splits created")
|
||||
.count();
|
||||
assert_eq!(count, 2);
|
||||
assert_eq!(at.read("xx 000"), generate(1, 10));
|
||||
assert_eq!(at.read("xx 0x001"), generate(10, 51));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue