From b1b2a198e54da4cdee65f9db5f0dff1d0c8075cd Mon Sep 17 00:00:00 2001 From: mattsu Date: Thu, 22 Jan 2026 13:45:26 +0900 Subject: [PATCH] i18n: treat C locale as no grouping separator --- src/uucore/src/lib/features/i18n/decimal.rs | 12 ++++++++-- .../mixed_floats_ints_chars_numeric.expected | 4 ++-- ...d_floats_ints_chars_numeric.expected.debug | 12 +++++----- ..._floats_ints_chars_numeric_stable.expected | 4 ++-- ...s_ints_chars_numeric_stable.expected.debug | 8 +++---- ..._floats_ints_chars_numeric_unique.expected | 3 +-- ...s_ints_chars_numeric_unique.expected.debug | 6 ++--- ...ints_chars_numeric_unique_reverse.expected | 3 +-- ...hars_numeric_unique_reverse.expected.debug | 6 ++--- .../sort/multiple_groupings_numeric.expected | 8 +++---- .../multiple_groupings_numeric.expected.debug | 24 +++++++++---------- 11 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/uucore/src/lib/features/i18n/decimal.rs b/src/uucore/src/lib/features/i18n/decimal.rs index 0a901143c..a7ceca2ef 100644 --- a/src/uucore/src/lib/features/i18n/decimal.rs +++ b/src/uucore/src/lib/features/i18n/decimal.rs @@ -6,7 +6,7 @@ use std::sync::OnceLock; use icu_decimal::provider::DecimalSymbolsV1; -use icu_locale::Locale; +use icu_locale::{Locale, locale}; use icu_provider::prelude::*; use crate::i18n::get_numeric_locale; @@ -60,7 +60,15 @@ fn get_grouping_separator(loc: Locale) -> String { pub fn locale_grouping_separator() -> &'static str { static GROUPING_SEP: OnceLock = OnceLock::new(); - GROUPING_SEP.get_or_init(|| get_grouping_separator(get_numeric_locale().0.clone())) + GROUPING_SEP.get_or_init(|| { + let loc = get_numeric_locale().0.clone(); + // C/POSIX locale (represented as "und") has no grouping separator. + if loc == locale!("und") { + String::new() + } else { + get_grouping_separator(loc) + } + }) } #[cfg(test)] diff --git a/tests/fixtures/sort/mixed_floats_ints_chars_numeric.expected b/tests/fixtures/sort/mixed_floats_ints_chars_numeric.expected index a781a36bb..59541af32 100644 --- a/tests/fixtures/sort/mixed_floats_ints_chars_numeric.expected +++ b/tests/fixtures/sort/mixed_floats_ints_chars_numeric.expected @@ -21,10 +21,10 @@ CARAvan 8.013 45 46.89 - 4567. - 37800 576,446.88800000 576,446.890 + 4567. + 37800 4798908.340000000000 4798908.45 4798908.8909800 diff --git a/tests/fixtures/sort/mixed_floats_ints_chars_numeric.expected.debug b/tests/fixtures/sort/mixed_floats_ints_chars_numeric.expected.debug index a00067b1e..b7b76e589 100644 --- a/tests/fixtures/sort/mixed_floats_ints_chars_numeric.expected.debug +++ b/tests/fixtures/sort/mixed_floats_ints_chars_numeric.expected.debug @@ -67,18 +67,18 @@ __ 46.89 _____ _____ - 4567. - _____ -____________________ ->>>>37800 - _____ -_________ 576,446.88800000 ___ ________________ 576,446.890 ___ ___________ + 4567. + _____ +____________________ +>>>>37800 + _____ +_________ 4798908.340000000000 ____________________ ____________________ diff --git a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_stable.expected b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_stable.expected index 36eeda637..0ccdd84c0 100644 --- a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_stable.expected +++ b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_stable.expected @@ -24,10 +24,10 @@ CARAvan 8.013 45 46.89 +576,446.890 +576,446.88800000 4567. 37800 -576,446.88800000 -576,446.890 4798908.340000000000 4798908.45 4798908.8909800 diff --git a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_stable.expected.debug b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_stable.expected.debug index 3fba89030..66a98b208 100644 --- a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_stable.expected.debug +++ b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_stable.expected.debug @@ -50,14 +50,14 @@ _____ __ 46.89 _____ +576,446.890 +___ +576,446.88800000 +___ 4567. _____ >>>>37800 _____ -576,446.88800000 -___ -576,446.890 -___ 4798908.340000000000 ____________________ 4798908.45 diff --git a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique.expected b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique.expected index cb27c6664..cd4256c5f 100644 --- a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique.expected +++ b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique.expected @@ -11,10 +11,9 @@ 8.013 45 46.89 +576,446.890 4567. 37800 -576,446.88800000 -576,446.890 4798908.340000000000 4798908.45 4798908.8909800 diff --git a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique.expected.debug b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique.expected.debug index dd6e8dfcc..663a4b3a9 100644 --- a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique.expected.debug +++ b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique.expected.debug @@ -24,14 +24,12 @@ _____ __ 46.89 _____ +576,446.890 +___ 4567. _____ >>>>37800 _____ -576,446.88800000 -___ -576,446.890 -___ 4798908.340000000000 ____________________ 4798908.45 diff --git a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique_reverse.expected b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique_reverse.expected index bbce16934..97e261f14 100644 --- a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique_reverse.expected +++ b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique_reverse.expected @@ -1,10 +1,9 @@ 4798908.8909800 4798908.45 4798908.340000000000 -576,446.890 -576,446.88800000 37800 4567. +576,446.890 46.89 45 8.013 diff --git a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique_reverse.expected.debug b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique_reverse.expected.debug index 4b01a8406..01f7abf5b 100644 --- a/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique_reverse.expected.debug +++ b/tests/fixtures/sort/mixed_floats_ints_chars_numeric_unique_reverse.expected.debug @@ -4,14 +4,12 @@ _______________ __________ 4798908.340000000000 ____________________ -576,446.890 -___ -576,446.88800000 -___ >>>>37800 _____ 4567. _____ +576,446.890 +___ 46.89 _____ 45 diff --git a/tests/fixtures/sort/multiple_groupings_numeric.expected b/tests/fixtures/sort/multiple_groupings_numeric.expected index a6daab836..9dd5b5f65 100644 --- a/tests/fixtures/sort/multiple_groupings_numeric.expected +++ b/tests/fixtures/sort/multiple_groupings_numeric.expected @@ -2,14 +2,14 @@ CARAvan + 1,999.99 +1,234 1.234 + 2,000 2.000 2.000,50 +12,34 22 23,. 111 210 -1,234 -12,34 - 1,999.99 - 2,000 diff --git a/tests/fixtures/sort/multiple_groupings_numeric.expected.debug b/tests/fixtures/sort/multiple_groupings_numeric.expected.debug index 57a4ae01b..62e98a46a 100644 --- a/tests/fixtures/sort/multiple_groupings_numeric.expected.debug +++ b/tests/fixtures/sort/multiple_groupings_numeric.expected.debug @@ -10,15 +10,27 @@ CARAvan ^ no match for key _______ +>>1,999.99 + _ +__________ +1,234 +_ +_____ >1.234 _____ ______ +>>>2,000 + _ +________ 2.000 _____ _____ 2.000,50 _____ ________ +12,34 +__ +_____ 22 __ __ @@ -31,15 +43,3 @@ ___ >210 ___ ____ -1,234 -_ -_____ -12,34 -__ -_____ ->>1,999.99 - _ -__________ ->>>2,000 - _ -________