Mercurial > public > mercurial-scm > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
15671:3c5e818ac679 | 15672:2ebe3d0ce91d |
---|---|
169 if u == lu: | 169 if u == lu: |
170 return s # preserve localstring | 170 return s # preserve localstring |
171 return lu.encode(encoding) | 171 return lu.encode(encoding) |
172 except UnicodeError: | 172 except UnicodeError: |
173 return s.lower() # we don't know how to fold this except in ASCII | 173 return s.lower() # we don't know how to fold this except in ASCII |
174 except LookupError, k: | |
175 raise error.Abort(k, hint="please check your locale settings") | |
176 | |
177 def upper(s): | |
178 "best-effort encoding-aware case-folding of local string s" | |
179 try: | |
180 if isinstance(s, localstr): | |
181 u = s._utf8.decode("utf-8") | |
182 else: | |
183 u = s.decode(encoding, encodingmode) | |
184 | |
185 uu = u.upper() | |
186 if u == uu: | |
187 return s # preserve localstring | |
188 return uu.encode(encoding) | |
189 except UnicodeError: | |
190 return s.upper() # we don't know how to fold this except in ASCII | |
191 except LookupError, k: | |
192 raise error.Abort(k, hint="please check your locale settings") |