Changeset 514:c55e376be01b in documentViewer for SrvTxtUtils.py


Ignore:
Timestamp:
Feb 28, 2012, 6:46:37 PM (12 years ago)
Author:
casties
Branch:
default
Message:

search works even with unicode...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • SrvTxtUtils.py

    r490 r514  
    1212
    1313
    14 srvTxtUtilsVersion = "1.3"
     14srvTxtUtilsVersion = "1.4"
    1515
    1616def getInt(number, default=0):
     
    2727    except:
    2828        return default
     29
     30def unicodify(s):
     31    """decode str (utf-8 or latin-1 representation) into unicode object"""
     32    if not s:
     33        return u""
     34    if isinstance(s, str):
     35        try:
     36            return s.decode('utf-8')
     37        except:
     38            return s.decode('latin-1')
     39    else:
     40        return s
     41
     42def utf8ify(s):
     43    """encode unicode object or string into byte string in utf-8 representation.
     44       assumes string objects to be utf-8"""
     45    if not s:
     46        return ""
     47    if isinstance(s, str):
     48        return s
     49    else:
     50        return s.encode('utf-8')
    2951
    3052def getText(node, recursive=0):
Note: See TracChangeset for help on using the changeset viewer.