Mercurial > public > mercurial-scm > hg
comparison mercurial/utils/stringutil.py @ 38261:f3033692ccef
stringutil: promote smartset.prettyformat() to utility function
It will be used by debugwalk.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 10 Jun 2018 11:50:09 +0900 |
parents | 32bc3815efae |
children | fbb2eddea4d2 |
comparison
equal
deleted
inserted
replaced
38260:15a1e37f80bd | 38261:f3033692ccef |
---|---|
42 for k, v in sorted(o.items()))) | 42 for k, v in sorted(o.items()))) |
43 elif isinstance(o, tuple): | 43 elif isinstance(o, tuple): |
44 return '(%s)' % (b', '.join(pprint(a, bprefix=bprefix) for a in o)) | 44 return '(%s)' % (b', '.join(pprint(a, bprefix=bprefix) for a in o)) |
45 else: | 45 else: |
46 return pycompat.byterepr(o) | 46 return pycompat.byterepr(o) |
47 | |
48 def prettyrepr(o): | |
49 """Pretty print a representation of a possibly-nested object""" | |
50 lines = [] | |
51 rs = pycompat.byterepr(o) | |
52 p = 0 | |
53 while p < len(rs): | |
54 q = rs.find('<', p + 1) | |
55 if q < 0: | |
56 q = len(rs) | |
57 l = rs.count('<', 0, p) - rs.count('>', 0, p) | |
58 assert l >= 0 | |
59 lines.append((l, rs[p:q].rstrip())) | |
60 p = q | |
61 return '\n'.join(' ' * l + s for l, s in lines) | |
47 | 62 |
48 def binary(s): | 63 def binary(s): |
49 """return true if a string is binary data""" | 64 """return true if a string is binary data""" |
50 return bool(s and '\0' in s) | 65 return bool(s and '\0' in s) |
51 | 66 |