bc43dc384d75e926ba1636356f931a44f3b81096
[python-collate.git] / collate / _abcollator.py
1 import collate._strings
2
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))
7
8 def words(self, string):
9 """Split the string into separate words.
10
11 This split is done using Unicode's definition of whitespace.
12 """
13 return string.split()
14
15 def sortemes(self, string):
16 words = []
17 for word in self.words(string):
18 words.extend(collate._strings.alnumsplit(word))
19 return filter(collate._strings.wordlike, words)
20
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]
24 return words