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: Wed, 18 Mar 2009 22:55:55 +0100

On Wed, Mar 18, 2009 at 10:22 PM, Paul Louden <paulthenerd_at_gmail.com> wrote:
> 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, so it should be. This
> sounds like a case of  "let's make the unimportant case work one way, while
> choosing to break the case where people make intentional changes."

You have a point, but if we assume people to add leading zeros
*intentionally* can't we assume those people to number their files
correctly in the first place, thus not having any need for this
"natural" sorting anyway? I'm pretty confident that there are users
careless enough to name files "3", "05", "7" and expecting them to get
sorted as "3", "05", "7". If we consider leading zeros as intentional
do we need this strnatcmp at all? If we not skip leading zeros are we
treating digits as numbers at all? I wouldn't say so.
Besides, couldn't that also create a sorting like "10", "13", "02",
"04" as 0 is a character here and thus sorted separately? Such a
sorting would be wrong if one names his files always using leading
zeros, especially if numbers are always sorted first.

> ignore leading zeros. I don't think we should ever assume any part of a
> filename is unintentional. I think assuming numbers are written as a human

in that case why do we need to add additional "brain" to the naming
the user chose?

> normally does is fine (1, 2, 3, 10, 11, 12) but if someone chooses to add
> something to alter sorting we should still respect it. You don't

Does "alter the sorting" require you to use digits? At least I usually
prepend character if I want something to get sorted at the top or
bottom or indexes like "a", "b" after the leading number.

> accidentally add a 0, and if there are random zeros in a mix folder the
> order of playback almost certainly isn't meant to be 2, 03, 4, but rather
> "whatever order" if they just chose to haphazardly mix them.

Ok, that was a bad example :)

> Also, which comes first: 001 or 01? If we're going to recognize that 001 has
> one more zero than 01, why don't we recognize that 00number has more zeros
> than 0number, even if the two numbers are different?

well, in that case (as both strings will evaluate to the number 1) a
strcmp would be in place to break the tie. It's a corner-case as both
numbers are identical (and 00 isn't "worth" more than "0", is it?).
Thus I don't think this is much of an issue as long as it is
deterministic.

> I expect people will number disks 1.01 - 1.12 rather than 1.1, 1.2, 1.10,
> 1.12. This is only my personal assumption, but if that's the case, our
> current method works for it.

I'd expect the same too, but I'm among the people that don't need
strnatcmp anyway as I properly name my files ;-)

> Maybe we should just see if various FLOSS file browsers have a common
> "natural" sort, and use it, so that our files are likely to show up in the
> host's browser the same order as they show up in ours?

Good point. Though if we only address the naming issue we kinda create
our own sorting, don't we?

 - Dominik
Received on 2009-03-18


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