Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/utils/stringutil.py @ 38577:a3130208db1c
stringutil: move _formatsetrepr() from smartset
I'll add a matcher subclass wrapping a boolean function, which will use
buildrepr() to provide debugging information in a similar way to
smartset.filteredset.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 10 Jun 2018 17:19:31 +0900 |
parents | de275ab362cb |
children | e7aa113b14f7 |
comparison
equal
deleted
inserted
replaced
38576:152f4822d210 | 38577:a3130208db1c |
---|---|
88 assert l >= 0 | 88 assert l >= 0 |
89 lines.append((l, rs[p0:q0].rstrip())) | 89 lines.append((l, rs[p0:q0].rstrip())) |
90 p0, p1 = q0, q1 | 90 p0, p1 = q0, q1 |
91 return '\n'.join(' ' * l + s for l, s in lines) | 91 return '\n'.join(' ' * l + s for l, s in lines) |
92 | 92 |
93 def buildrepr(r): | |
94 """Format an optional printable representation from unexpanded bits | |
95 | |
96 ======== ================================= | |
97 type(r) example | |
98 ======== ================================= | |
99 tuple ('<not %r>', other) | |
100 bytes '<branch closed>' | |
101 callable lambda: '<branch %r>' % sorted(b) | |
102 object other | |
103 ======== ================================= | |
104 """ | |
105 if r is None: | |
106 return '' | |
107 elif isinstance(r, tuple): | |
108 return r[0] % pycompat.rapply(pycompat.maybebytestr, r[1:]) | |
109 elif isinstance(r, bytes): | |
110 return r | |
111 elif callable(r): | |
112 return r() | |
113 else: | |
114 return pycompat.byterepr(r) | |
115 | |
93 def binary(s): | 116 def binary(s): |
94 """return true if a string is binary data""" | 117 """return true if a string is binary data""" |
95 return bool(s and '\0' in s) | 118 return bool(s and '\0' in s) |
96 | 119 |
97 def stringmatcher(pattern, casesensitive=True): | 120 def stringmatcher(pattern, casesensitive=True): |