# HG changeset patch # User Matt Mackall # Date 1316628046 18000 # Node ID 16c129b0f465d2d32d8a0cfb5374a6db649b6c51 # Parent 17688287678051a35f386e4c27fabab8490b0cf1 encoding: add getcols to extract substrings based on column width diff -r 176882876780 -r 16c129b0f465 mercurial/encoding.py --- 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: