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

printf: Ignore thousand seperator flag

This commit is contained in:
Joseph Jon Booker 2025-04-06 22:27:12 -05:00
parent ef7a8c300e
commit 7df22051ea
2 changed files with 17 additions and 1 deletions

View file

@ -95,6 +95,7 @@ struct Flags {
space: bool, space: bool,
hash: bool, hash: bool,
zero: bool, zero: bool,
quote: bool,
} }
impl Flags { impl Flags {
@ -108,6 +109,11 @@ impl Flags {
b' ' => flags.space = true, b' ' => flags.space = true,
b'#' => flags.hash = true, b'#' => flags.hash = true,
b'0' => flags.zero = true, b'0' => flags.zero = true,
b'\'' => {
// the thousands separator is printed with numbers using the ' flag, but
// this is a no-op in the "C" locale. We only save this flag for reporting errors
flags.quote = true;
}
_ => break, _ => break,
} }
*index += 1; *index += 1;
@ -181,7 +187,7 @@ impl Spec {
} }
} }
b's' => { b's' => {
if flags.zero || flags.hash { if flags.zero || flags.hash || flags.quote {
return Err(&start[..index]); return Err(&start[..index]);
} }
Self::String { Self::String {

View file

@ -337,6 +337,16 @@ fn sub_num_int_char_const_in() {
.stdout_only("emoji is 128579"); .stdout_only("emoji is 128579");
} }
#[test]
fn sub_num_thousands() {
// For "C" locale, the thousands separator is ignored but should
// not result in an error
new_ucmd!()
.args(&["%'i", "123456"])
.succeeds()
.stdout_only("123456");
}
#[test] #[test]
fn sub_num_uint() { fn sub_num_uint() {
new_ucmd!() new_ucmd!()