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: Al Le <>
Date: Wed, 18 Mar 2009 22:57:59 +0100

On 18.03.2009 22:22, Paul Louden wrote:
> Dominik Riebeling wrote:
>> A situation
>> where a folder can contain files starting with "02" and "4" the same
>> time is something that could happen and still not being intentional
>> (just think of copying files from various albums to a mix folder).
> I agree that it could be unintentional, but disagree that "numeric
> sorting" matters in this case - if you have a mix of random songs, why
> does 03 need to be between 2 and 4? Meanwhile, if someone intentionally
> prefixes something with a 0, they intend for it to be first

I think we can't tell for sure what's intentional and what's not. All we
have is a bunch of files, and it's not our task to infer how it has come
to it. Guessing what the intention was is an intelligence of a higher
degree than the natsort!

>> Either treat digits as number or don't treat them as numbers at all.

I'm absolutely with you, Dominik. This way the thing the algorithm does
can be captured in few words, which we accurately did in the setting
names ("Interpret numbers as ..."). Special treatment of leading zeroes,
spaces and dots is too much for a usual human being to understand.

> Also, which comes first: 001 or 01?

If strnatcmp tells two strings are equal then strcmp is called which
always delivers a perfectly predictable result.

> Well, we're currently using an "existing" algorithm. One that *may* be
> used in other FLOSS (I don't know, and haven't investigated). To me, the
> two sides of the argument are basically "do we want to use it as-is,
> such that our sorted lists look the same as lists in other applications,
> or do we want to define our own rules for 'natural' list sorting?"

I'd opt for the latter, because it's easy to understand.
Received on 2009-03-18

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy