Commit 27cd0ac
committed
ls: add --quoting-style=locale support
Implement locale-aware quoting for the ls command, allowing filenames
to be quoted using locale-specific quotation marks based on the
current LC_CTYPE setting.
Features:
- Add Quotes::Locale variant for locale-aware quoting
- Create locale_quotes module with comprehensive locale mappings
- Support 20+ languages with appropriate quote characters:
* Romance languages (French, Spanish, etc.): guillemets
* Germanic languages (German, Czech, etc.): low-9 and high quotes
* Japanese: corner brackets
* Chinese/Korean: CJK curly quotes
* English/default: ASCII double quotes
- Proper UTF-8 handling for multi-byte quote characters
- Environment variable precedence: LC_ALL > LC_CTYPE > LANG
- Localized help text in English and French
Implementation:
- Enhanced CQuoter to dynamically detect and apply locale quotes
- Added --quoting-style=locale CLI option
- Follows C-style quoting semantics (always-quote behavior)
- Safe fallback to ASCII double quotes for unknown locales
- Added spell-checker:ignore comments for technical terms
Testing:
- Verified with multiple locales (en_US, fr_FR, de_DE, ja_JP, zh_CN)
- All existing tests pass
- Help text properly localized
test(ls): add comprehensive tests for --quoting-style=locale
Add test coverage for locale-aware quoting functionality:
- Tests 10 different locales with appropriate quotation marks
- Verifies English, French, German, Japanese, Chinese, Russian, Spanish, Polish, C, and POSIX locales
- Tests escape sequence handling with locale quoting (newline character)
- Validates UTF-8 encoding of multi-byte quote characters
test(ls): use only CI-available locales in locale quoting test
Fix test failures by limiting locale tests to those available in the CI environment.
CI only generates en_US.UTF-8, fr_FR.UTF-8, es_ES.UTF-8, and sv_SE.UTF-8.
Removed tests for: de_DE, ja_JP, zh_CN, pl_PL, ru_RU.UTF-8
- These locales are not generated in .github/workflows/GnuTests.yml
- The locale_quotes module unit tests still validate these quote types
- This keeps the integration test CI-friendly while maintaining comprehensive coverage
test(ls): add missing tests for locale quoting feature
Add missing Quotes::Locale test case in test_quotes_display() to ensure
the Display trait implementation is tested for all quote variants.
Add comprehensive unit tests for locale_quotes module:
- Test locale environment variable precedence (LC_ALL > LC_CTYPE > LANG)
- Validate quote character mappings for all supported locales
- Ensure Romance, Germanic, Slavic, and Asian language quotes work correctly
- Test locale string parsing with encoding and modifiers
- Verify fallback behavior for unknown locales
This adds 17 unit tests covering the locale detection and quote mapping
functionality that was previously untested.
test(ls): add integration tests for locale quoting with environment variables
Add test_ls_quoting_style_locale_env_vars to verify that --quoting-style=locale
correctly responds to different locale environment variables (LC_ALL).
Tests verify:
- French locale (fr_FR.UTF-8) uses guillemets (« »)
- Spanish locale (es_ES.UTF-8) uses guillemets (« »)
- Swedish locale (sv_SE.UTF-8) uses ASCII quotes
- C locale uses ASCII quotes
Note: Environment variable precedence testing (LC_ALL > LC_CTYPE > LANG) is
already comprehensively covered in unit tests (locale_quotes.rs). These
integration tests focus on end-to-end functionality.
fix: address CI failures in locale quoting tests
- Add locale/typography terms (CTYPE, Guillemets, guillemets) to spell checker dictionary
- Skip newline filename test on Windows where such filenames are invalid
optimize locale quoting and clean up code
- Optimize locale parsing to avoid multiple string splits and allocations
- Use efficient find() operations instead of split() for locale parsing
- Remove redundant comments and GNU-specific references for MIT compliance
- Clean up documentation to include only essential API documentation
- Maintain all functionality while improving performance to fix CodSpeed regression1 parent f43602d commit 27cd0ac
8 files changed
Lines changed: 517 additions & 6 deletions
File tree
- .vscode/cspell.dictionaries
- src
- uucore/src/lib/features/quoting_style
- uu/ls
- locales
- src
- tests/by-util
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
664 | 664 | | |
665 | 665 | | |
666 | 666 | | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
667 | 670 | | |
668 | 671 | | |
669 | 672 | | |
| |||
1364 | 1367 | | |
1365 | 1368 | | |
1366 | 1369 | | |
| 1370 | + | |
1367 | 1371 | | |
1368 | 1372 | | |
1369 | 1373 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| |||
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
20 | 32 | | |
21 | 33 | | |
22 | | - | |
23 | | - | |
| 34 | + | |
| 35 | + | |
24 | 36 | | |
25 | 37 | | |
26 | 38 | | |
27 | 39 | | |
| 40 | + | |
28 | 41 | | |
29 | 42 | | |
30 | 43 | | |
31 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
32 | 54 | | |
33 | 55 | | |
34 | 56 | | |
| |||
47 | 69 | | |
48 | 70 | | |
49 | 71 | | |
| 72 | + | |
50 | 73 | | |
51 | 74 | | |
52 | | - | |
53 | | - | |
| 75 | + | |
| 76 | + | |
54 | 77 | | |
55 | 78 | | |
56 | 79 | | |
| |||
0 commit comments