numfmt: treat multibyte chars as a single character (#11992)

* treat multibyte chars as a single character

* add test for issue 11937
This commit is contained in:
Devel08
2026-04-25 18:51:57 +02:00
committed by GitHub
parent 020124b5a6
commit c5bdff1816
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -620,7 +620,7 @@ fn transform_to(
/// Right-aligns when `right_align` is true, left-aligns otherwise.
/// Unlike `format!("{:>width$}")`, this handles widths larger than 65535.
fn pad_string(s: &str, width: usize, fill: char, right_align: bool) -> String {
let len = s.len();
let len = s.chars().count();
if len >= width {
return s.to_string();
}
+10
View File
@@ -1549,3 +1549,13 @@ fn test_si_format_precision_no_cap() {
.succeeds()
.stdout_is("1.23457M\n");
}
// https://github.com/uutils/coreutils/issues/11937
// numfmt: --format width accounting diverges from GNU for multi-byte --suffix
#[test]
fn test_multibyte_suffix_issue11937() {
new_ucmd!()
.args(&["--suffix=€", "--format=%10.2f", "692"])
.succeeds()
.stdout_is(" 692.00€\n");
}