[Bug] Wrong 'underscore' sorting

Questions, glitches, bugs and crashes
Post Reply
User avatar
swoop
Posts: 54
Joined: Thu Mar 02, 2017 2:40 pm
Location: Brussels, Belgium

[Bug] Wrong 'underscore' sorting

Post by swoop » Fri Apr 14, 2017 3:18 pm

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 5335 times
Total Commander (Windows 95 - Windows 7) (retired for Mac)
Nimble Commander (retired Crax, Commander One, DCommander)
Macbook 12" 2016 - macOS High Sierra

User avatar
mike
Posts: 808
Joined: Thu Jul 16, 2015 5:35 am
Location: Exeter, UK

Re: [Bug] Wrong 'underscore' sorting

Post by mike » 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].

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

User avatar
swoop
Posts: 54
Joined: Thu Mar 02, 2017 2:40 pm
Location: Brussels, Belgium

Re: [Bug] Wrong 'underscore' sorting

Post by swoop » Sun Apr 23, 2017 3:45 pm

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). ;)
Total Commander (Windows 95 - Windows 7) (retired for Mac)
Nimble Commander (retired Crax, Commander One, DCommander)
Macbook 12" 2016 - macOS High Sierra

User avatar
darek
Posts: 168
Joined: Thu Jul 16, 2015 4:50 pm
Location: Warsaw, Poland
Contact:

Re: [Bug] Wrong 'underscore' sorting

Post by darek » Tue Apr 25, 2017 2:08 pm

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 5300 times
Total Commander:
sorting_tc.png
sorting_tc.png (2.77 KiB) Viewed 5300 times
Windows CMD shell (command: dir /ON)
sorting_dos.png
sorting_dos.png (6.89 KiB) Viewed 5300 times

JayB
Posts: 142
Joined: Sun Jan 08, 2017 4:38 pm

Re: [Bug] Wrong 'underscore' sorting

Post by JayB » Thu May 04, 2017 10:50 am

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.

User avatar
swoop
Posts: 54
Joined: Thu Mar 02, 2017 2:40 pm
Location: Brussels, Belgium

Re: [Bug] Wrong 'underscore' sorting

Post by swoop » Sun Sep 17, 2017 3:02 pm

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...)
Total Commander (Windows 95 - Windows 7) (retired for Mac)
Nimble Commander (retired Crax, Commander One, DCommander)
Macbook 12" 2016 - macOS High Sierra

User avatar
mike
Posts: 808
Joined: Thu Jul 16, 2015 5:35 am
Location: Exeter, UK

Re: [Bug] Wrong 'underscore' sorting

Post by mike » Mon Sep 18, 2017 2:26 am

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.

Post Reply