Skip to content

Make NumericSort use InvariantCulture for text comparison #1724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

goran-w
Copy link
Contributor

@goran-w goran-w commented Aug 12, 2025

Changed the comparison method used in NumericSort.Compare() :

  • Ordinal comparison sorts non-alphanumeric chars (like underscore etc) differently than expected (i.e compared to filesystem sorting etc).
  • InvariantCulture comparison corrects this, without imposing cultural differences.
  • (A possible alternative would be CurrentCulture comparison.)

Additionally:

  • When comparing a single digit-char against a single non-digit-char, the earlier code used char.CompareTo() where the comparison method can not be specified.
  • To fix this, we now use the same consistent Comparer object for all the string comparisons which are NOT "digits vs digits".

Ordinal comparison sorts non-alphanumeric chars (like underscore etc) differently than expected (i.e compared to filesystem sorting etc).
InvariantCulture comparison corrects this, without imposing cultural differences. (A possible alternative would be CurrentCulture comparison.)
The earlier code, when comparing a single digit-char against non-digit-char, used char.CompareTo() where the comparison method can not be specified.
To fix this, we now use the same Comparer for all non-all-digits string comparisons.
@goran-w goran-w changed the title Make NumericSort use InvariantCulture instead of Ordinal comparison Make NumericSort use InvariantCulture for text comparison Aug 13, 2025
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.

1 participant