Skip to content

i18n: distinguish locale codesets from modifiers - #15508

Open
limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/i18n-parse-posix-locale-components-12291
Open

limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/i18n-parse-posix-locale-components-12291

Conversation

@limadog9

Copy link
Copy Markdown
Contributor

Factor POSIX locale parsing into a shared helper and recognize encoding only before the modifier. This fixes en_US@utf-8.dict being treated as UTF-8 and adds an expr regression.

Refs #12291.

/// C and POSIX use the default collation. Only a codeset following `.` can
/// select UTF-8; a modifier following `@` is never an encoding.
/// Unrecognized locale names use the default locale; unrecognized codesets use ASCII.
pub fn parse_posix_locale(value: &str) -> (Locale, UEncoding) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why pub? if it's meant to be shared, is_c_locale in uniq could use it, no?

Comment thread src/uucore/src/lib/features/i18n/mod.rs Outdated
/// select UTF-8; a modifier following `@` is never an encoding.
/// Unrecognized locale names use the default locale; unrecognized codesets use ASCII.
pub fn parse_posix_locale(value: &str) -> (Locale, UEncoding) {
let name_and_codeset = value.split('@').next().unwrap_or_default();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value.split_once('@').map_or(value, |(n, _)| n) would avoid the unwrap_or_default()

let (name, codeset) = name_and_codeset
.split_once('.')
.unwrap_or((name_and_codeset, ""));
let locale = if matches!(name, "C" | "POSIX") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POSIX used to parse as a real "posix" locale, so this is a second fix. please mention it in the commit message

Comment thread src/uucore/src/lib/features/i18n/mod.rs Outdated
}

#[cfg(test)]
mod posix_locale_tests {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please move these into the existing mod tests? no need for a second test module

@limadog9
limadog9 force-pushed the fix/i18n-parse-posix-locale-components-12291 branch 3 times, most recently from 97c083b to d077d2a Compare October 19, 2026 11:40
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/tail/follow-symlink is no longer failing!

@codspeed

codspeed Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 19.94%

⚠️ 121 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

❌ 2 regressed benchmarks
✅ 399 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory cp_recursive_deep_tree[(120, 4)] 532.6 KB 699.2 KB -23.82%
❌ Simulation true_consecutive_calls 294.7 ns 350.2 ns -15.86%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing limadog9:fix/i18n-parse-posix-locale-components-12291 (c48bc70) with main (6f60c70)2

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (48f2a33) during the generation of this report, so 6f60c70 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for the PR!
the tail test fix is unrelated to this change, please split it into its own pr, the rest looks good.

Comment thread tests/by-util/test_tail.rs Outdated

at.truncate(source, "x\n");
p.delay(delay);
// Wait for tail to observe the write before terminating it on slow CI hosts.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to the locale parsing, could you please move this tail fix into a separate pr?

Parse locale names, codesets and modifiers separately. Treat POSIX as
the default C locale rather than a language named posix. Reuse the parser
in uniq when choosing the C-locale comparison path.

Closes uutils#12291.
@limadog9
limadog9 force-pushed the fix/i18n-parse-posix-locale-components-12291 branch from d077d2a to c48bc70 Compare October 19, 2026 19:39

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants