dev builds
themes manual
device status forums
mailing lists
IRC bugs
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 <>
Date: Thu, 19 Mar 2009 17:31:25 +0100

On Thu, Mar 19, 2009 at 4:34 PM, Thomas Martitz
<> 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 template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy