39 Commits
Author SHA1 Message Date
b3d8706a2c sort: fix inconsistent sort ordering under i18n-collator with equal sorting keys (#12013)
* sort: Fix inconsistent sort orderg under i18n-collator with equal sorting keys.

* Test cases for fix #11980

* Simplyfing fix for #11980

* Fix clippy lint and rename test files.

* Remove old test files

* Update tests/by-util/test_sort.rs

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* Update tests/by-util/test_sort.rs

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>

* Removing redundant test and swapping default order for sort to match sort's ordering.

* Comment for clarification.

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
2026-04-30 10:33:48 +02:00
808865e4ac fix: scientific notation is incorrectly parsed in general numeric sort (#10437)
* fix: scientific notation is incorrectly parsed in general sort

* test(sort): refactor exponents_positive_general test

---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2026-02-12 02:52:22 -08:00
mattsuandSylvestre Ledru ce96a263c8 fix(tests): correct sorting order of decimal values in numeric sort fixture
Update the expected output for the multiple decimals numeric sort test to reflect the proper ascending order. The values "576,446.88800000" and "576,446.890" were misplaced and have been repositioned to their correct locations in the sorted sequence, ensuring the test accurately validates the sorting logic. The debug fixture was updated accordingly.
2026-02-01 22:34:06 +01:00
mattsuandSylvestre Ledru b1b2a198e5 i18n: treat C locale as no grouping separator 2026-02-01 22:34:06 +01:00
Kaua KlassmannandGitHub 1a64417aae fix: numeric sort (-n) does not recognize thousand separators (#10339) 2026-01-21 21:48:50 +01:00
Dorian Peron 27faee711b test(sort): Fix fixtures 2025-07-25 13:51:53 +02:00
Yonatan LinikandDorian Péron bd2e33bb34 sort: Support hexadecimal numbers/floats correctly
Fixes https://github.com/uutils/coreutils/issues/8060
2025-07-23 21:14:14 +02:00
Daniel Hofstetter 2a406d8cbb sort: adapt fixtures to change in unicode-width 2024-12-09 09:20:19 +01:00
Michael Debertol 418f5b7692 sort: handle empty merge inputs 2021-07-31 21:02:20 +02:00
Michael Debertol 233a778963 sort/ls: implement version cmp matching GNU spec
This reimplements version_cmp, which is used in sort and ls to sort
according to versions.
However, it is not bug-for-bug identical with GNU's implementation.
I reported a bug with GNU here:
https://lists.gnu.org/archive/html/bug-coreutils/2021-06/msg00045.html
This implementation does not contain the bugs regarding the handling of
file extensions and null bytes.
2021-06-27 15:29:17 +02:00
Michael Debertol 548a895cd6 sort: compatibility of human-numeric sort
Closes #1985.
This makes human-numeric sort follow the same algorithm as GNU's/FreeBSD's sort.
As documented by GNU in https://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html,
we first compare by sign, then by si unit and finally by the numeric value.
2021-06-25 18:19:00 +02:00
Michael Debertol 66359a0f56 sort: insert line separators after non-empty files
If files don't end witht a line separator we have to insert one,
otherwise the last line will be combined with the first line of the next
file.
2021-06-06 18:01:08 +02:00
Michael Debertol 06b3092f5f sort: fix debug output for zeros / invalid numbers
We were reporting "no match" when sorting something like "0 ". This is
because we don't distinguish between 0 and invalid lines when sorting.
For debug output we have to get this information back.
2021-06-01 18:18:51 +02:00
Michael DebertolandGitHub dc63133f14 sort: correctly inherit global flags for keys (#2302)
Closes #2254. We should only inherit global settings for keys when there
are absolutely no options attached to the key.

The default key (matching the whole line) is implicitly added only if no
keys are supplied.

Improved some error messages by including more context.
2021-05-29 23:25:56 +02:00
Michael DebertolandGitHub e9656a6c32 sort: make GNU test sort-debug-keys pass (#2269)
* sort: disable support for thousand separators

In order to be compatible with GNU, we have to disable thousands
separators. GNU does not enable them for the C locale, either.

Once we add support for locales we can add this feature back.

* sort: delete unused fixtures

* sort: compare -0 and 0 equal

I must have misunderstood this when implementing, but GNU considers
-0, 0, and invalid numbers to be equal.

* sort: strip blanks before applying the char index

* sort: don't crash when key start is after key end

* sort: add "no match" for months at the first non-whitespace char

We should put the "^ no match for key" indicator at the first
non-whitespace character of a field.

* sort: improve support for e notation

* sort: use maches! macros
2021-05-28 22:38:29 +02:00
Michael Debertol e0ebf907a4 sort: make merging stable
When merging files we need to prioritize files that occur earlier in the
command line arguments with -m.

This also makes the extsort merge step (and thus extsort itself) stable again.
2021-05-09 11:43:38 +02:00
electricboogie 4c395146dd Merge branch 'master' of https://github.com/uutils/coreutils 2021-04-25 10:11:27 -05:00
Michael Debertol e6f6b109a5 sort: implement --debug
This adds a --debug flag, which, when activated, will draw lines below
the characters that are actually used for comparisons.

This is not a complete implementation of --debug. It should, quoting the man page
for GNU sort: "annotate the part of the line used to sort, and warn
about questionable usage to stderr". Warning about "questionable usage"
is not part of this patch.

This change required some adjustments to be able to get the range that
is actually used for comparisons. Most notably, general numeric comparisons
were rewritten, fixing some bugs along the lines.

Testing is mostly done by adding fixtures for the expected debug output of
existing tests.
2021-04-23 22:36:15 +02:00
electricboogie 25021f31eb Incorporate overhead of Line struct 2021-04-19 21:24:52 -05:00
Michael DebertolandGitHub 4bbbe3a3f2 sort: implement numeric string comparison (#2070)
* sort: implement numeric string comparison

This implements -n and -h using a string comparison algorithm instead
of parsing each number to a f64 and comparing those.

This should result in a moderate performance increase and eliminate loss
of precision.

* cache parsed f64 numbers

For general numeric comparisons we have to parse numbers as f64,
as this behavior is explicitly documented by GNU coreutils.
We can however cache the parsed value to speed up comparisons.

* fix leading zeroes for negative numbers

* use more appropriate name for exponent

* improvements to the parse function

* move checks into main loop and fix thousands separator condition

* remove unneeded checks

* rustfmt
2021-04-17 13:49:35 +02:00
a76d452f75 Sort: More small fixes (#2065)
* Various fixes and performance improvements

* fix a typo

Co-authored-by: Michael Debertol <michael.debertol@gmail.com>

* Fix month parse for months with leading whitespace

* Implement test for months whitespace fix

* Confirm human numeric works as expected with whitespace with a test

* Correct arg help value name for --parallel

* Fix SemVer non version lines/empty line sorting with a test

Co-authored-by: Sylvestre Ledru <sledru@mozilla.com>
Co-authored-by: Michael Debertol <michael.debertol@gmail.com>
2021-04-17 10:06:19 +02:00
Michael DebertolandGitHub 69f4410a8a sort: dedup using compare_by (#2064)
compare_by is the function used for sorting, we should use it for dedup
as well.
2021-04-10 19:49:10 +02:00
e5113ad00e Sort: Various fixes and performance improvements (#2057)
* Various fixes and performance improvements

* fix a typo

Co-authored-by: Michael Debertol <michael.debertol@gmail.com>

Co-authored-by: Sylvestre Ledru <sledru@mozilla.com>
Co-authored-by: Michael Debertol <michael.debertol@gmail.com>
2021-04-10 11:56:20 +02:00
electricboogieandGitHub 8474249e5f Sort: Implement stable sort, ignore non-printing, month sort dedup, auto parallel sort through rayon, zero terminated sort, check silent (#2008) 2021-04-08 22:07:09 +02:00
elgrisandSylvestre Ledru 71ba8b3fd6 sort: add "dictionary-order" flag.
The flag makes 'sort' command ignore non-dictionary symbols
(non-alphanumeric and non-spaces). The only difference with GNU sort is
that it takes ALL alphanumeric symbols, not only ASCII ones.
2020-05-07 23:08:24 +02:00