- def sortemes(self, string):
- return collate._strings.alnumsplit(string)
+ def str(self, string):
+ """Convert a unicode to a str using the collator encoding."""
+ try:
+ return str(string)
+ except UnicodeError:
+ return string.encode(self.encoding, 'replace')
+
+ def lstripwords(
+ self, string, strip=collate.strings.INITIAL_STOPS, append=u", "):
+ """Strip words and whitespace from the start of a string.
+
+ If append is not empty, it and the words stripped from the
+ front are appended to the end.
+ """
+ string = self.unicode(string)
+ stripped = []
+ words = self.words(string)
+ while words and (words[0].isspace() or words[0].lower() in strip):
+ stripped.append(words.pop(0))
+ while stripped and stripped[-1].isspace():
+ stripped.pop()
+ if append and stripped:
+ if words:
+ words.append(append)
+ words.extend(stripped)
+ return u"".join(words)