Skip to content

diff: add -i/--ignore-case - #413

Open
Xnadir wants to merge 1 commit into
uutils:mainfrom
Xnadir:diff-ignore-case
Open

Xnadir wants to merge 1 commit into
uutils:mainfrom
Xnadir:diff-ignore-case

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 17, 2026

Copy link
Copy Markdown

Closes #406

diff -i / --ignore-case failed with unrecognized option. It now compares lines with their case folded and prints the original lines.

A diff_lines helper in utils.rs replaces the direct diff::slice calls in the normal, context, unified, ed and side-by-side formats. Without -i it is diff::slice as before. With -i it diffs folded copies of the lines and maps the results back to the original lines by position. Folding uses to_lowercase for UTF-8 lines, except in the C/POSIX locale (checked with the existing is_posix_locale("LC_CTYPE")), where only ASCII letters fold, as in GNU diff. -q and the exit status come from the same result, so case-only differences count as identical.

Tests: the issue's Funky Stuff / fUNKy stuFf with -i and --ignore-case in the normal, -u, -c, -e and -q formats (and still different without -i). Also a file that differs in more than case, and the non-ASCII case (AĀΑ-Δ vs aāα-δ), equal under LC_ALL=C.UTF-8 and different under LC_ALL=C. All of them fail on main. I checked the same cases against GNU diff 3.12.

AI disclosure: written with help from Claude Code.

🤖 Generated with Claude Code

Closes uutils#406

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 16:11

Copilot AI left a comment

Copy link
Copy Markdown

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.

@github-actions

Copy link
Copy Markdown

GNU diffutils testsuite comparison:

Test results comparison:
  Current:   TOTAL: 33 / PASSED: 20 / FAILED: 9 / SKIPPED: 4
  Reference: TOTAL: 33 / PASSED: 19 / FAILED: 10 / SKIPPED: 4

Changes from main branch:
  TOTAL: +0
  PASSED: +1
  FAILED: -1

Test improvements (1):
  + ignore-case

Comment thread src/utils.rs
ignore_case: bool,
) -> Vec<diff::Result<&'a [u8]>> {
if !ignore_case {
return diff::slice(left, right)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

do we need to copy the whole result vector when -i isn't passed?
if diff_lines returned diff::Result<&'b &'a [u8]> (&left[i - 1] in the -i branch), this could just be return diff::slice(left, right); and the default path stays as cheap as before


#[rstest]
fn ignore_case(
#[values(&[][..], &["-u"], &["-c"], &["-e"], &["-q"])] format: &[&str],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

please add -y too, side_diff.rs is changed as well

Comment thread src/utils.rs
let posix = is_posix_locale("LC_CTYPE");
let fold = |line: &&[u8]| -> Vec<u8> {
match std::str::from_utf8(line) {
Ok(text) if !posix => text.to_lowercase().into_bytes(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

str::to_lowercase applies the final sigma rule (Σ at the end of a word becomes ς), so ΟΔΟΣ and οδοσ differ with -i.
should it fold char by char instead (chars().flat_map(char::to_lowercase))?

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.

diff - -i / --ignore-case is not implemented

3 participants