[Zope-dev] case insensitive sorts

Tres Seaver tseaver@digicool.com
Thu, 04 Jan 2001 07:36:40 -0500


Chris Withers <chrisw@nipltd.com> wrote:
 
> Andy McKay wrote:
> > 
> > They want information fast and most users expect case insensitive sorts. Its
> > simpler and easy. I think having the ignore_case option for a -tree and -in
> > helps Zope by increasing the ease of development and friendliness to the
> > user.
> 
> And my point was that this is so universally true that the _pthyon_ sort
> function (which is at fault here) should be fixed :-)

Python's sort already allows you to pass an alternate comparison
function::

 [/var/home/tres] $ python
 Python 1.5.2 (#1, Feb  1 2000, 16:32:16)  [GCC egcs-2.91.66
19990314/Linux (egcs- on linux-i386
 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
 >>> foo = [ 'z', 'y', 'x' ]
 >>> foo.sort()
 >>> foo
 ['x', 'y', 'z']
 >>> foo.sort( lambda x, y: cmp(y,x) )
 >>> foo
 ['z', 'y', 'x']

I believe Andy's patch makes use of this feature.  You are missing
a couple of points if you *require* a case-insensitive sort:

 * collation (which letters belong together) is highly locale
   sensitive (e.g., does a-accent-grave sort with a? etc.)

 * Should strings which differ only in case be equal (*NOT*!)

Tres.
-- 
===============================================================
Tres Seaver                                tseaver@digicool.com
Digital Creations     "Zope Dealers"       http://www.zope.org