mercurial/encoding.py
branchstable
changeset 15066 24efa83d81cb
parent 15064 1f581a8b1948
child 15142 176882876780
--- a/mercurial/encoding.py	Sat Aug 06 23:52:20 2011 +0200
+++ b/mercurial/encoding.py	Sat Aug 27 04:56:12 2011 +0900
@@ -135,16 +135,17 @@
         raise error.Abort("%s, please check your locale settings" % k)
 
 # How to treat ambiguous-width characters. Set to 'wide' to treat as wide.
-ambiguous = os.environ.get("HGENCODINGAMBIGUOUS", "narrow")
+wide = (os.environ.get("HGENCODINGAMBIGUOUS", "narrow") == "wide"
+        and "WFA" or "WF")
 
 def colwidth(s):
     "Find the column width of a UTF-8 string for display"
-    d = s.decode(encoding, 'replace')
+    return ucolwidth(s.decode(encoding, 'replace'))
+
+def ucolwidth(d):
+    "Find the column width of a Unicode string for display"
     eaw = getattr(unicodedata, 'east_asian_width', None)
     if eaw is not None:
-        wide = "WF"
-        if ambiguous == "wide":
-            wide = "WFA"
         return sum([eaw(c) in wide and 2 or 1 for c in d])
     return len(d)