[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Issue with ls -v / sort -V and strverscmp() usage

From: Eric Blake
Subject: Re: Issue with ls -v / sort -V and strverscmp() usage
Date: Mon, 22 Sep 2008 06:36:02 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20080708 Thunderbird/ Mnenhy/

Hash: SHA1

According to Jim Meyering on 9/22/2008 6:21 AM:
> Kamil, you may expect to use the new function in ls, too.
> The more I think of this, the more I'm convinced producing
> sensible results is what matters here.  Being completely
> compatible with older versions of ls -v is not important.

How does the proposed filevercmp function compare with m4sugar's
m4_version_compare function?  That one behaves a bit differently than
glibc's strverscmp; for example, strverscmp says "00" is less than "0",
whereas m4_version_compare says they are equal.  m4_version_compare does
not currently handle all bytes, but could possibly be generalized to do
so, if its algorithm is deemed desirable.  The m4 algorithm is:

separate the candidate strings into fields at all ',', '.', and '-'
separators.  Then, for each field, any alphabetic strings are taken as the
insertion of two new fields, a -1 and then the base-36 value of the
alphabetic string.  The comparison then visits one field at a time,
treating blank fields as 0; leading zeros are ignored.  Thus, "1" compares
less than "1a" ("1.-1.10"), which in turn is less than "2".

On the other hand, the fact that strverscmp provides a distinction based
on leading zeros is nice, as it guarantees a stable sort (no two strings
that differ on strcmp will compare equal with strverscmp).

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]