Repository navigation
Sort a base name before its numbered siblings [patch] - #70
Merged
Merged
Conversation
When one text chunk was a strict prefix of the other, CompareTextChunks put the shorter first without looking at what followed it. "file.txt" against "file" + "1" + ".txt" never compared the '.' with the '1', so "report.pdf" sorted after "report2.pdf". Compare the longer chunk's next character with the first digit (as ASCII) of the number that follows the shorter one, which is the order the class remarks promise. Fixes #61 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011XTgJFveY9S4CJX3Bzeyej
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #61
What changed
When one text chunk was a strict prefix of the other,
CompareTextChunksput the shorter chunk first without looking at what came after it. Comparing"file.txt"with"file"+1+".txt"never compared the.against the1, soreport.pdfsorted afterreport2.pdf.Now, when the shared prefix matches and the lengths differ:
This is the order the class remarks promise: "a number compared with text orders exactly as the equivalent ASCII digits would". It also matches the existing mixed text/number branch in
Compare. A text chunk never contains a digit, so the two characters always differ. The comparer still allocates nothing.Tests
Compare_TextThatExtendsTheOtherSidesText_ComparesItsNextCharacterWithTheNumbercovers the acceptance cases (file.txt/file1.txt,file-1/file1,file 2/file10), plusa!against ASCII and Arabic-Indic five, plus guards showing thatfileastill sorts afterfile1and thatfilestill comes beforefile.txt.Sort_PutsABaseNameBeforeItsNumberedSiblingschecks thatreport.pdfsorts beforereport1/2/10.pdf.Compare_IsTransitiveOverMixedScriptDigitsAndText(NaturalStringComparer is intransitive for non-ASCII digits (٥ < 10 < z < ٥), so sort output depends on input order #55) now also includes prefix-shaped values (a!,a.b,a.5,a٥.b,a~,az,a 2,a-1) and stays antisymmetric and transitive.The two new tests fail on
mainand pass with the fix. The full suite passes: 27/27.🤖 Generated with Claude Code
https://claude.ai/code/session_011XTgJFveY9S4CJX3Bzeyej
Generated by Claude Code