mercurial/utils/stringutil.py
changeset 38576 a3130208db1c
parent 38477 de275ab362cb
child 38783 e7aa113b14f7
equal deleted inserted replaced
38575:152f4822d210 38576: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):