X-Git-Url: https://git.korewanetadesu.com/?p=python-collate.git;a=blobdiff_plain;f=collate%2F_abcollator.py;h=bc43dc384d75e926ba1636356f931a44f3b81096;hp=71f5f54631a42e8c33ac1945b57ff92066bc0496;hb=53e1676b8d68cccd2b0692654d3871e44e0ba6b6;hpb=c519e411927761939a0461bdf8d0a12b26d965e9 diff --git a/collate/_abcollator.py b/collate/_abcollator.py index 71f5f54..bc43dc3 100644 --- a/collate/_abcollator.py +++ b/collate/_abcollator.py @@ -1,4 +1,24 @@ +import collate._strings + class Collator(object): def cmp(self, string1, string2): """Return negative if a < b, zero if a == b, positive if a > b.""" return cmp(self.key(string1), self.key(string2)) + + def words(self, string): + """Split the string into separate words. + + This split is done using Unicode's definition of whitespace. + """ + return string.split() + + def sortemes(self, string): + words = [] + for word in self.words(string): + words.extend(collate._strings.alnumsplit(word)) + return filter(collate._strings.wordlike, words) + + def sortemekey(self, string): + words = map(collate._strings.numeric, self.sortemes(string)) + words = [(i, self.key(word)) for (i, word) in words] + return words