Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



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?

From: Dominik Riebeling <dominik.riebeling_at_gmail.com>
Date: Thu, 19 Mar 2009 17:31:25 +0100

On Thu, Mar 19, 2009 at 4:34 PM, Thomas Martitz
<thomas.martitz_at_fhtw-berlin.de> wrote:
>> I've found a simpler solution for this. Trying the code raises the
>> following problem:
>>
>> 00 < 0b < 01 < 1
[...]
> Nautilus has this problem too. I don't know what windows does in this case.

I don't see any problem here. You just need to distinguish between
strings and values on sorting:
a. 00 -> value 0
b. 0b -> value 0, followed by string "b"
c. 01 -> value 1
d. 1 -> value 1

so while the strcmp() is the tie-breaker between c. and d., sorting
of a. and b. is also rather simple -- you sort by the leading numbers
first. This makes a. and b. come before the others. Then, as a. and b.
are a "starting with zero"-group you have to resort that again as
there is a tie with the numbers. Thus b. comes after a. That's how
ASCII-sorting would do it (and also how windows explorer does it).

You can't simply sort by leading numbers and ignore that the string
has other characters in it too.

 - Dominik
Received on 2009-03-19


Page was last modified "Jan 10 2012" The Rockbox Crew
aaa