X-Git-Url: https://git.korewanetadesu.com/?p=python-collate.git;a=blobdiff_plain;f=collate%2F_abcollator.py;h=2e6ab9567338e48884c6e46778b112e914d229e5;hp=99866c36cac82698313be7c3237ddc3052a6843c;hb=7c67e10286c784b572703666a980e85b39b858ee;hpb=f73c4c6cd3ed326c5735ab33a6896697227d07e3 diff --git a/collate/_abcollator.py b/collate/_abcollator.py index 99866c3..2e6ab95 100644 --- a/collate/_abcollator.py +++ b/collate/_abcollator.py @@ -1,3 +1,5 @@ +import collate._strings + class Collator(object): def cmp(self, string1, string2): """Return negative if a < b, zero if a == b, positive if a > b.""" @@ -9,3 +11,14 @@ class Collator(object): This split is done using Unicode's definition of whitespace. """ return string.split() + + def sortemes(self, string): + return collate._strings.alnumsplit(string) + + def sortemekey(self, string, invalid=float('inf')): + words = [] + for sorteme in self.sortemes(string): + num, alpha = collate._strings.numeric(sorteme, invalid) + alpha = self.key(collate._strings.strip_punc(alpha)) + words.append((num, alpha)) + return words