Date: Wed, 15 Feb 2006 10:05:24 -0600 From: Dan Nelson <dnelson@allantgroup.com> To: Peter Jeremy <peterjeremy@optushome.com.au>, hackers@freebsd.org Subject: Re: Naive implementation of strverscmp(3) Message-ID: <20060215160524.GA70956@dan.emsphone.com> In-Reply-To: <20060215150237.GA1123@galgenberg.net> References: <20060214212503.GE1107@galgenberg.net> <20060215080532.GB684@turion.vk2pj.dyndns.org> <20060215150237.GA1123@galgenberg.net>
next in thread | previous in thread | raw e-mail | index | archive | help
In the last episode (Feb 15), Ulrich Spoerlein said:
> Peter Jeremy wrote:
> >>Is there a chance this might get included into libc? Or is it
> >>considered bloat?
> >I don't think it belongs in libc. Maybe libutil.
>
> This would require patching the gqview configure script, but I can live
> with that.
>
> >For the first point, consider
> > strverscmp("jan25", "janx25");
>
> This fell victim to a rearranging of the while loop. Thanks for
> pointing that out!
>
> Attached is an updated version, which now also takes leading zeros
> into account. It still differs from the GNU version, because
> strverscmp("foo.009", "foo.0") > 0 In my book, '009' is just greater
> than zero, no matter what. If someone could explain to me, why the
> GNU folks do it the other way round, I could try implementing that
> too.
This looks a lot like strnatcmp, which is "natural sort" or "do what I
mean" sort :)
http://sourcefrog.net/projects/natsort/
Your function is simpler than the C implementation on that site, but
falls over when a run of numbers exceeds 2^31 (raise it to 2^64 if you
use strtoull, but that's as high as you can yet).
--
Dan Nelson
dnelson@allantgroup.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060215160524.GA70956>
