Rockbox mail archive
Subject: Re: how is strnatcmp aka "Interpret numbers while sorting" supposed to sort?
Re: how is strnatcmp aka "Interpret numbers while sorting" supposed to sort?
Mike Holden wrote:
> Thomas Martitz wrote:
>> After this discussion and the ones in IRC, it seems to me that the
>> majority is in favor of ignoring leading zeros. This would also match
>> with Nautilus' and Windows Explorer's sorting.
>> And we can do that. Give that the usual browsers do it that way, it's
>> also what the user expects, so it can't be bad. FS#10031 needs changing
>> the algorithm anyway.
>> So, should we do that? It at least seems to be the opinion of most people.
> Just had a quick look in My Computer on an XP box to see how this does it.
> 1. 001 sorts before 01 and 01 sorts before 1, giving the conclusion that
> more leading zeroes sorts before less leading zeroes, where the underlying
> number is the same (i.e. 000x < 00x for any number x).
> 2. 1 sorts before 2, 2 before 10, 10 befoer 11 etc, as expected giving
> numeric sorting.
> 3. 001 sorts before 10 and 010, again giving expected sorting for the
> numeric part.
> 4. Introducing letters into the equation, we can see that 00A sorts before
> 00aa, 001 and 1. This satisfies my expectation that leading zeroes before
> letters should sort first in the list, and not be sorted among the letter
> part only.
> All of these individual items line up to give a file listing that doesn't
> produce any surpries for me, so I would be happy with this set of rules.
This is what we'll be doing too. comparing 001 and 1, will yield 001 <
1, because if strnatcmp sorts the same, strcmp is asked.
Received on 2009-03-19
Page was last modified "Jan 10 2012" The Rockbox Crew