1 import collate
._strings
3 class Collator(object):
4 def cmp(self
, string1
, string2
):
5 """Return negative if a < b, zero if a == b, positive if a > b."""
6 return cmp(self
.key(string1
), self
.key(string2
))
8 def words(self
, string
):
9 """Split the string into separate words.
11 This split is done using Unicode's definition of whitespace.
15 def sortemes(self
, string
):
17 for word
in self
.words(string
):
18 words
.extend(collate
._strings
.alnumsplit(word
))
19 return filter(collate
._strings
.wordlike
, words
)
21 def sortemekey(self
, string
):
22 words
= map(collate
._strings
.numeric
, self
.sortemes(string
))
23 words
= [(i
, self
.key(word
)) for (i
, word
) in words
]