Page 1 of 1

[Bug] Wrong 'underscore' sorting

Posted: Fri Apr 14, 2017 3:18 pm
by swoop
When an underscore is used as first character of a filename, it is incorrectly sorted after files that start with a numeric character. It is correctly sorted before alpha characters. See attached image.
wrong.underscore.sorting.png
wrong.underscore.sorting.png (23.2 KiB) Viewed 12302 times

Re: [Bug] Wrong 'underscore' sorting

Posted: Mon Apr 17, 2017 6:55 am
by mike
Well, if something behaves not as Finder - that doesn't immediately mean a wrong behavior.
The Underscore symbol has a code point 95:
https://en.wikipedia.org/wiki/ASCII#Character_set
Numerics have, on the other hand, the range of [48,57].

PS remembered about this topic: http://magnumbytes.com/forum/viewtopic.php?f=5&t=64

Re: [Bug] Wrong 'underscore' sorting

Posted: Sun Apr 23, 2017 3:45 pm
by swoop
Oops, it seems I coughed up just half (surface part) of the story. Sorry about that! Here we go.
mike wrote:
Mon Apr 17, 2017 6:55 am
Well, if something behaves not as Finder - that doesn't immediately mean a wrong behavior.
The Underscore symbol has a code point 95:
https://en.wikipedia.org/wiki/ASCII#Character_set
Numerics have, on the other hand, the range of [48,57].
You are right about the codes. What I meant to say was that, it seems it is an unwritten agreement (Finder, TC, many other file managers) that underscores are used to place files at the beginning (end) of ordered lists.

Bottom line, I wanted to suggest that this unwritten rule would be introduced in NC. I myself manipulate a lot of files and using underscores for files that I need to process later on is common practices for me (and I believe I'm not the only one). ;)

Re: [Bug] Wrong 'underscore' sorting

Posted: Tue Apr 25, 2017 2:08 pm
by darek
I'd also expect underscores to sort on top. This is something I got used to on DOS/Windows and I always thought it's a general convention for sorting files (haven't checked on Linux though). Anyway, here's how it behaves on Windows:

Explorer:
sorting_explorer.png
sorting_explorer.png (1.38 KiB) Viewed 12267 times
Total Commander:
sorting_tc.png
sorting_tc.png (2.77 KiB) Viewed 12267 times
Windows CMD shell (command: dir /ON)
sorting_dos.png
sorting_dos.png (6.89 KiB) Viewed 12267 times

Re: [Bug] Wrong 'underscore' sorting

Posted: Thu May 04, 2017 10:50 am
by JayB
As far as I can see, NC does not sort based on ASCII value, as e.g. ls in the shell does, unless you enable "case-sensitive comparison", right? If you disable case-sensitive, NC output seems to be unsorted, as with ls -f.

Re: [Bug] Wrong 'underscore' sorting

Posted: Sun Sep 17, 2017 3:02 pm
by swoop
Hello, Mike! Any "owner" opinion on this? This is (right after the legacy copy/move queueing) my biggest issue with NC. Thanks in advance for letting us know. (I know you will aim for a proper / configurable / maintainable solution - no hardcoded hack. And that takes time...)

Re: [Bug] Wrong 'underscore' sorting

Posted: Mon Sep 18, 2017 2:26 am
by mike
Hi, swoop!
Well, the situation is quite simple - I don't know the right solution to the problem.
NC uses a string comparison routine provided by CoreFoundation framework to perform sorting. Two available comparison options (case sensitivity and numeric treatment) are mapped directly to flags of this routine. I don't know any options to "tune" this lexicographical order to include exceptions for various symbols like "_".
Foundation framework, on the other hand, has a black-box comparison routine to perform an undefined "Finder-like" sorting, which apparently treats underscores accordingly, but there's no way to tune it regarding case sensitivity and numeric treatment.
A solution might be a custom comparison routine built directly atop of ICU, but it's quite serious R&D task.

Of course I'm not speaking about some hacky ways like

Code: Select all

    if( c1 == '_' )
    	return c2 != '_';
since it will destroy the sorting performance.