Changeset bc932ef74a9c…
Parent fc48fdac0213…
by
Changes to one file · Browse files at bc932ef74a9c Showing diff from parent fc48fdac0213 Diff from another changeset...
@@ -38,6 +38,24 @@ pass
return s.decode(_fallbackencoding, 'replace')
+def fromunicode(s, errors='strict'):
+ """
+ Convert the encoding of string from Unicode to MBCS.
+
+ Return 'str' type string.
+
+ If you don't want an exception for conversion failure,
+ specify errors='replace'.
+ """
+ s = unicode(s) # s can be QtCore.QString
+ for enc in (_encoding, _fallbackencoding):
+ try:
+ return s.encode(enc)
+ except UnicodeEncodeError:
+ pass
+
+ return s.encode(_encoding, errors) # last ditch
+
def toutf(s):
"""
Convert the encoding of string from MBCS to UTF-8.
|
Loading...