[kupfer] kupferstring: Doctests
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] kupferstring: Doctests
- Date: Fri, 11 Sep 2009 16:10:39 +0000 (UTC)
commit 7a266209c16b23d96e79de0df06255811becb87f
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Fri Sep 11 17:47:18 2009 +0200
kupferstring: Doctests
kupfer/kupferstring.py | 18 ++++++++++++++----
1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/kupfer/kupferstring.py b/kupfer/kupferstring.py
index de15130..1159db2 100644
--- a/kupfer/kupferstring.py
+++ b/kupfer/kupferstring.py
@@ -36,10 +36,20 @@ def toutf8(ustr):
return ustr.encode("UTF-8", "replace")
def tofolded(ustr):
- """Return a search-folded string"""
- # Replace characters with folding_table, then
- # decompose the string into combining chars representation,
- # strip those and join up the result
+ u"""`Fold' @ustr
+
+ Return a unicode str where composed characters are replaced by
+ their base, and extended latin characters are replaced by
+ similar basic latin characters.
+
+ >>> tofolded(u"WyÅ?Ä?cz")
+ u'Wylacz'
+ >>> tofolded(u"naïveté")
+ u'naivete'
+ """
srcstr = normalize("NFKD", ustr.translate(folding_table))
return u"".join(c for c in srcstr if category(c) != 'Mn')
+if __name__ == '__main__':
+ import doctest
+ doctest.testmod()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]