diff mercurial/encoding.py @ 15672:2ebe3d0ce91d stable

i18n: use encoding.lower/upper for encoding aware case folding this patch uses encoding.lower/upper for case folding, because ones of str can not fold case of non ascii characters correctly. to avoid cyclic dependency and to encapsulate logic of normcase in each platforms, this patch introduces encodinglower/encodingupper in both posix/windows specific files. this patch does not change implementation of normcase() in posix.py, because we do not know the encoding of filenames on POSIX. some "normcase()" are excluded from function wrap list in hgext/win32mbcs.py, because they become encoding aware by this patch.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 16 Dec 2011 21:09:41 +0900
parents 16c129b0f465
children afdf4f5bac61
line wrap: on
line diff
--- a/mercurial/encoding.py	Fri Dec 16 21:09:40 2011 +0900
+++ b/mercurial/encoding.py	Fri Dec 16 21:09:41 2011 +0900
@@ -171,3 +171,22 @@
         return lu.encode(encoding)
     except UnicodeError:
         return s.lower() # we don't know how to fold this except in ASCII
+    except LookupError, k:
+        raise error.Abort(k, hint="please check your locale settings")
+
+def upper(s):
+    "best-effort encoding-aware case-folding of local string s"
+    try:
+        if isinstance(s, localstr):
+            u = s._utf8.decode("utf-8")
+        else:
+            u = s.decode(encoding, encodingmode)
+
+        uu = u.upper()
+        if u == uu:
+            return s # preserve localstring
+        return uu.encode(encoding)
+    except UnicodeError:
+        return s.upper() # we don't know how to fold this except in ASCII
+    except LookupError, k:
+        raise error.Abort(k, hint="please check your locale settings")