Added "keep_chars" argument in translateString function ZTK-1.1
authorThierry Florac <thierry.florac@onf.fr>
Tue, 03 Dec 2013 11:45:25 +0100
branchZTK-1.1
changeset 238 26773e68d3d3
parent 237 fca4a296d89e
child 239 96765451d8d7
Added "keep_chars" argument in translateString function
src/ztfy/utils/unicode.py
--- a/src/ztfy/utils/unicode.py	Tue Dec 03 11:43:33 2013 +0100
+++ b/src/ztfy/utils/unicode.py	Tue Dec 03 11:45:25 2013 +0100
@@ -82,7 +82,7 @@
 _fillUnicodeTransTable()
 
 
-def translateString(s, escapeSlashes=False, forceLower=True, spaces=' ') :
+def translateString(s, escapeSlashes=False, forceLower=True, spaces=' ', keep_chars='_-.'):
     """Remove extended characters from string and replace them with 'basic' ones
     
     @param s: text to be cleaned.
@@ -100,7 +100,8 @@
     if isinstance(s, str):
         s = unicode(s, "utf8", "replace")
     s = s.translate(_unicodeTransTable)
-    s = ''.join([a for a in s.translate(_unicodeTransTable) if a.replace(' ', '-') in (string.ascii_letters + string.digits + '_-.')])
+    s = ''.join([a for a in s.translate(_unicodeTransTable)
+                 if a.replace(' ', '-') in (string.ascii_letters + string.digits + (keep_chars or ''))])
     if forceLower:
         s = s.lower()
     if spaces != ' ':