Skip to content

uniq: skip characters, not bytes, for -s in a UTF-8 locale - #16684

Open
Xnadir wants to merge 2 commits into
uutils:mainfrom
Xnadir:uniq-skip-chars-utf8
Open

Xnadir wants to merge 2 commits into
uutils:mainfrom
Xnadir:uniq-skip-chars-utf8

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

In a UTF-8 locale, -s N skipped N bytes instead of N characters, so printf 'éxy\nABxy\n' | uniq -s 2 -c compared xy with xy and merged the two lines. GNU skips two characters and compares y with xy.

-s now counts characters the same way -w already does: characters for valid UTF-8 outside the C locale, bytes otherwise. The new test covers both locales and fails on main.

Closes #16661

AI disclosure: written with help from Claude Code.

Copilot AI balanced review requested due to automatic review settings November 18, 2026 14:39

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for this PR!
Mostly duplication: char_offset repeats the logic key_end_index already has (see inline).

Comment thread src/uu/uniq/src/uniq.rs

/// The index `count` characters after `start`: bytes in the C locale or
/// for invalid UTF-8, characters otherwise, as for `-w`.
fn char_offset(&self, line: &[u8], start: usize, count: usize) -> usize {

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.

key_end_index does the same C / utf-8 / invalid dance, could it just call char_offset(line, key_start, limit)? almost the same code twice


#[uutests::wasi_ignore(NoLocaleData)]
#[test]
fn test_skip_chars_multibyte() {

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 also add a case with -s and -w together, and one with invalid utf-8 (bytes fallback)?

@github-actions

Copy link
Copy Markdown

Binary size comparison:

Individual binary size comparison VS main (threshold: >=5% AND >=4 KB).

Total size of compared binaries: 155.48 MB (+100 KB, +0.06%)

Significant per-binary changes:
  env     1.20 MB ->    1.28 MB  (+80 KB, +6.51%)

Copilot AI balanced review requested due to automatic review settings November 19, 2026 22:55

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

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.

uniq: --skip-chars merges distinct lines in a UTF-8 locale

3 participants