Mercurial > hg > documentViewer
diff SrvTxtUtils.py @ 514:c55e376be01b
search works even with unicode...
author | casties |
---|---|
date | Tue, 28 Feb 2012 19:46:37 +0100 |
parents | 6f116b86a226 |
children | f8a5f63eafc0 |
line wrap: on
line diff
--- a/SrvTxtUtils.py Tue Feb 28 19:10:08 2012 +0100 +++ b/SrvTxtUtils.py Tue Feb 28 19:46:37 2012 +0100 @@ -11,7 +11,7 @@ import logging -srvTxtUtilsVersion = "1.3" +srvTxtUtilsVersion = "1.4" def getInt(number, default=0): """returns always an int (0 in case of problems)""" @@ -27,6 +27,28 @@ except: return default +def unicodify(s): + """decode str (utf-8 or latin-1 representation) into unicode object""" + if not s: + return u"" + if isinstance(s, str): + try: + return s.decode('utf-8') + except: + return s.decode('latin-1') + else: + return s + +def utf8ify(s): + """encode unicode object or string into byte string in utf-8 representation. + assumes string objects to be utf-8""" + if not s: + return "" + if isinstance(s, str): + return s + else: + return s.encode('utf-8') + def getText(node, recursive=0): """returns all text content of a node and its subnodes""" if node is None: