changeset 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 87bb975a1844
files mercurial/encoding.py
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/encoding.py	Wed Sep 21 13:00:41 2011 -0500
+++ b/mercurial/encoding.py	Wed Sep 21 13:00:46 2011 -0500
@@ -149,6 +149,14 @@
         return sum([eaw(c) in wide and 2 or 1 for c in d])
     return len(d)
 
+def getcols(s, start, c):
+    '''Use colwidth to find a c-column substring of s starting at byte
+    index start'''
+    for x in xrange(start + c, len(s)):
+        t = s[start:x]
+        if colwidth(t) == c:
+            return t
+
 def lower(s):
     "best-effort encoding-aware case-folding of local string s"
     try: