Rockbox mail archiveSubject: Re: how is strnatcmp aka "Interpret numbers while sorting" supposed to sort?
Re: how is strnatcmp aka "Interpret numbers while sorting" supposed to sort?
From: Mike Holden <rockbox_at_mikeholden.org>
Date: Thu, 19 Mar 2009 14:53:22 -0000 (UTC)
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
3. 001 sorts before 10 and 010, again giving expected sorting for the
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
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.
-- Mike Holden http://www.by-ang.com - the place to shop for all manner of hand crafted items, including Jewellery, Greetings Cards and GiftsReceived on 2009-03-19