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: Bryan VanDyke <bryan.vandyke_at_gmail.com>
Date: Thu, 19 Mar 2009 10:48:44 -0400

Thomas Martitz wrote:
> Linus Nielsen Feltzing wrote:
>> Mike Holden wrote:
>>> Maybe leading zeros should only be stripped if another digit follows
>>> them?
>>>
>>> I use names like 00RockFaves.m3u, 00ClassicRock.m3u for playlists that I
>>> have created (as opposed to original artist albums), and the leading
>>> zerozero is deliberately there to sort them at the top.
>>
>> That's an interesting observation. I believe leading zeroes are
>> treated like whitespace in the current code, but in this case I think
>> that the final zero should be kept.
>>
>> Linus
> That's not trivial, and adds complexity. You basically need to look at
> the current, the next, and one more for this, instead of just the
> current char.
>

Actually it not that bad.

Pseudo code:

get current
get next
while (current != null && next != null && current == '0' && next is a
number)
{
        current = next
        next = get next
}
Received on 2009-03-19


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