feat(df): add thousands separator support#9090
Conversation
3ce60cf to
48f4bc1
Compare
|
GNU testsuite comparison: |
a8966af to
ae09fec
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
could you please split this per program in different pr ? thanks |
| /// - `','` for other locales (default, en_US style) | ||
| fn get_thousands_separator() -> char { | ||
| // Try to read LC_NUMERIC or LANG environment variable | ||
| if let Ok(locale) = std::env::var("LC_NUMERIC") |
There was a problem hiding this comment.
Environment variable reads on every call is inefficient - consider caching the locale information
|
|
||
| // Simple heuristic: European locales use period, others use comma | ||
| // This covers common cases like de_DE, fr_FR, it_IT, es_ES, nl_NL, etc. | ||
| if locale.starts_with("de_") |
There was a problem hiding this comment.
is it?
i don't like this hardcoded list. isn't something in icu to do that?
There was a problem hiding this comment.
oki, replace with ICU's FixedDecimalFormatter
|
GNU testsuite comparison: |
8b92113 to
fb15063
Compare
fb15063 to
13225ab
Compare
|
GNU testsuite comparison: |
Merging this PR will not alter performance
Comparing Footnotes
|
|
GNU testsuite comparison: |
8aa4f8c to
c6cb13e
Compare
|
GNU testsuite comparison: |
1 similar comment
|
GNU testsuite comparison: |
29d396b to
e85ae66
Compare
|
GNU testsuite comparison: |
e85ae66 to
714a5a2
Compare
|
GNU testsuite comparison: |
714a5a2 to
3be82c4
Compare
Implement thousands separator support for df using GNU coreutils-compatible leading single quote syntax (--block-size='1K). Changes: - Add extract_thousands_separator_flag() to parse_size.rs - Add format_with_thousands_separator() to human.rs with locale support - Add BlockSizeConfig struct to df/blocks.rs to hold separator flag - Update df to use new block size configuration - Add 4 integration tests for thousands separator functionality - Fix clippy warnings (inlined format args, unnecessary qualifications) Fixes PR uutils#9090
97ff706 to
f34a0cc
Compare
Implement thousands separator support for df using GNU coreutils-compatible leading single quote syntax (--block-size='1K). Changes: - Add extract_thousands_separator_flag() to parse_size.rs - Add format_with_thousands_separator() to human.rs with locale support - Add BlockSizeConfig struct to df/blocks.rs to hold separator flag - Update df to use new block size configuration - Add 4 integration tests for thousands separator functionality - Fix clippy warnings (inlined format args, unnecessary qualifications) Fixes PR uutils#9090
f34a0cc to
ca4b994
Compare
Implement thousands separator support for df using GNU coreutils-compatible leading single quote syntax (--block-size='1K). Changes: - Add extract_thousands_separator_flag() to parse_size.rs - Add format_with_thousands_separator() to human.rs with locale support - Add BlockSizeConfig struct to df/blocks.rs to hold separator flag - Update df to use new block size configuration - Add 4 integration tests for thousands separator functionality - Fix clippy warnings (inlined format args, unnecessary qualifications) Fixes PR uutils#9090
ca4b994 to
66195aa
Compare
Implement thousands separator support for df using GNU coreutils-compatible leading single quote syntax (--block-size='1K). Changes: - Add extract_thousands_separator_flag() to parse_size.rs - Add format_with_thousands_separator() to human.rs with locale support - Add BlockSizeConfig struct to df/blocks.rs to hold separator flag - Update df to use new block size configuration - Add 4 integration tests for thousands separator functionality - Fix clippy warnings (inlined format args, unnecessary qualifications) Fixes PR uutils#9090
66195aa to
7a559c7
Compare
Implement thousands separator support for df using GNU coreutils-compatible leading single quote syntax (--block-size='1K). Includes: - extract_thousands_separator_flag() in parse_size.rs - format_with_thousands_separator() in human.rs with locale support - BlockSizeConfig struct in df/blocks.rs - 4 integration tests Also includes ParserBuilderError for better block size validation (restored from PR uutils#9090).
7a559c7 to
e99e193
Compare
Implement thousands separator support for df using GNU coreutils-compatible leading single quote syntax (--block-size='1K). Includes: - extract_thousands_separator_flag() in parse_size.rs - format_with_thousands_separator() in human.rs with locale support - BlockSizeConfig struct in df/blocks.rs - 4 integration tests Also includes ParserBuilderError for better block size validation (restored from PR uutils#9090).
4a4f79d to
7a559c7
Compare
Implement thousands separator support for df using GNU coreutils-compatible leading single quote syntax (--block-size='1K). Includes: - extract_thousands_separator_flag() in parse_size.rs - format_with_thousands_separator() in human.rs with locale support - BlockSizeConfig struct in df/blocks.rs - 4 integration tests Also includes ParserBuilderError for better block size validation (restored from PR uutils#9090).
7a559c7 to
f4aa95f
Compare
Implement thousands separator support for df using GNU coreutils-compatible leading single quote syntax (--block-size='1K). Includes: - extract_thousands_separator_flag() in parse_size.rs - format_with_thousands_separator() in human.rs with locale support - BlockSizeConfig struct in df/blocks.rs - 4 integration tests Also includes ParserBuilderError for better block size validation (restored from PR uutils#9090).
f4aa95f to
efd45e8
Compare
|
GNU testsuite comparison: |
Implement thousands separator support for df using GNU coreutils-compatible leading single quote syntax (--block-size='1K). Includes: - extract_thousands_separator_flag() in parse_size.rs - format_with_thousands_separator() in human.rs with locale support - BlockSizeConfig struct in df/blocks.rs - 4 integration tests Also includes ParserBuilderError for better block size validation (restored from PR uutils#9090).
| /// // assert_eq!(format_with_thousands_separator(1234567), "1.234.567"); | ||
| /// ``` | ||
| pub fn format_with_thousands_separator(number: u64) -> String { |
There was a problem hiding this comment.
please write unit test for this function
|
GNU testsuite comparison: |
|
hmm, was hardcoded to 3 now uses ICU locale data: (3,3) for westernor (3,2) for indian locales |
|
GNU testsuite comparison: |
Implement thousands separator support for df using GNU coreutils-compatible leading single quote syntax (--block-size='1K). Includes: - extract_thousands_separator_flag() in parse_size.rs - format_with_thousands_separator() in human.rs with ICU locale support - BlockSizeConfig struct in df/blocks.rs - 4 integration tests Also includes ParserBuilderError for better block size validation (restored from PR uutils#9090).
Fix build error when i18n-decimal feature is not enabled by: - Wrapping ICU imports in #[cfg(feature = "i18n-decimal")] - Providing fallback implementation that returns comma separator
Add support for Indian numbering system (hi_IN) and other locales with non-standard grouping: - Add locale_grouping_sizes() to decimal.rs returning (primary, secondary) - Update format_with_thousands_separator() to use locale-aware groups - Most locales: (3, 3) -> 1,234,567 - Indian locales: (3, 2) -> 12,34,567 - Add conditional compilation for i18n-decimal feature
Add tests for: - test_format_with_thousands_separator: basic functionality - test_format_with_grouping_sizes: tests (3,3) and (3,2) grouping Tests verify both Western format (1,234,567) and Indian format (12,34,567)
|
GNU testsuite comparison: |
Adds GNU-compatible thousands separator formatting to ls, du, and df. Use a leading quote in --block-size to get readable output: --block-size="'1" shows 1,024,000 instead of 1024000.
Respects LC_NUMERIC locale (comma for en_US, period for European locales, none for C/POSIX). Works with environment variables too (LS_BLOCK_SIZE, DU_BLOCK_SIZE, DF_BLOCK_SIZE, etc.).
Core changes in uucore (parse_size.rs, human.rs) handle the parsing and formatting. Each utility integrates it with minimal changes. 12 new integration tests, all existing tests pass.
Closes #9084