'Advanced' sorteme functions.
[python-collate.git] / collate / _abcollator.py
index 094a5de..bc43dc3 100644 (file)
@@ -1,5 +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