| changeset 149 | 0f2c5744b39b |
| parent 119 | 5e8dda1b7631 |
| child 175 | 4f072edc51a1 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cm/utils/string_utils.py Fri Feb 05 16:01:32 2010 +0100 @@ -0,0 +1,15 @@ +import chardet + +def to_unicode(input): + if type(input) == str: + res = None + for encoding in [chardet.detect(input)['encoding'], 'utf8', 'latin1']: + try: + res = unicode(input, encoding) + break; + except UnicodeDecodeError: + pass + if not res: + raise Exception('UnicodeDecodeError: could not decode') + return res + return input \ No newline at end of file