Skip to content

Commit 7df2205

Browse files
committed
printf: Ignore thousand seperator flag
1 parent ef7a8c3 commit 7df2205

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct Flags {
9595
space: bool,
9696
hash: bool,
9797
zero: bool,
98+
quote: bool,
9899
}
99100

100101
impl Flags {
@@ -108,6 +109,11 @@ impl Flags {
108109
b' ' => flags.space = true,
109110
b'#' => flags.hash = true,
110111
b'0' => flags.zero = true,
112+
b'\'' => {
113+
// the thousands separator is printed with numbers using the ' flag, but
114+
// this is a no-op in the "C" locale. We only save this flag for reporting errors
115+
flags.quote = true;
116+
}
111117
_ => break,
112118
}
113119
*index += 1;
@@ -181,7 +187,7 @@ impl Spec {
181187
}
182188
}
183189
b's' => {
184-
if flags.zero || flags.hash {
190+
if flags.zero || flags.hash || flags.quote {
185191
return Err(&start[..index]);
186192
}
187193
Self::String {

tests/by-util/test_printf.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,16 @@ fn sub_num_int_char_const_in() {
337337
.stdout_only("emoji is 128579");
338338
}
339339

340+
#[test]
341+
fn sub_num_thousands() {
342+
// For "C" locale, the thousands separator is ignored but should
343+
// not result in an error
344+
new_ucmd!()
345+
.args(&["%'i", "123456"])
346+
.succeeds()
347+
.stdout_only("123456");
348+
}
349+
340350
#[test]
341351
fn sub_num_uint() {
342352
new_ucmd!()

0 commit comments

Comments
 (0)