comparison mercurial/encoding.py @ 15143:16c129b0f465

encoding: add getcols to extract substrings based on column width
author Matt Mackall <mpm@selenic.com>
date Wed, 21 Sep 2011 13:00:46 -0500
parents 176882876780
children 2ebe3d0ce91d
comparison
equal deleted inserted replaced
15142:176882876780 15143:16c129b0f465
147 eaw = getattr(unicodedata, 'east_asian_width', None) 147 eaw = getattr(unicodedata, 'east_asian_width', None)
148 if eaw is not None: 148 if eaw is not None:
149 return sum([eaw(c) in wide and 2 or 1 for c in d]) 149 return sum([eaw(c) in wide and 2 or 1 for c in d])
150 return len(d) 150 return len(d)
151 151
152 def getcols(s, start, c):
153 '''Use colwidth to find a c-column substring of s starting at byte
154 index start'''
155 for x in xrange(start + c, len(s)):
156 t = s[start:x]
157 if colwidth(t) == c:
158 return t
159
152 def lower(s): 160 def lower(s):
153 "best-effort encoding-aware case-folding of local string s" 161 "best-effort encoding-aware case-folding of local string s"
154 try: 162 try:
155 if isinstance(s, localstr): 163 if isinstance(s, localstr):
156 u = s._utf8.decode("utf-8") 164 u = s._utf8.decode("utf-8")