mercurial/util.py
changeset 21857 86c2d792a4b7
parent 21813 c2262004c2e2
child 21907 7e5dfa00e3c2
equal deleted inserted replaced
21856:d24969ee272f 21857:86c2d792a4b7
  1316     r = author.find('>')
  1316     r = author.find('>')
  1317     if r == -1:
  1317     if r == -1:
  1318         r = None
  1318         r = None
  1319     return author[author.find('<') + 1:r]
  1319     return author[author.find('<') + 1:r]
  1320 
  1320 
  1321 def _ellipsis(text, maxlength):
       
  1322     if len(text) <= maxlength:
       
  1323         return text, False
       
  1324     else:
       
  1325         return "%s..." % (text[:maxlength - 3]), True
       
  1326 
       
  1327 def ellipsis(text, maxlength=400):
  1321 def ellipsis(text, maxlength=400):
  1328     """Trim string to at most maxlength (default: 400) characters."""
  1322     """Trim string to at most maxlength (default: 400) columns in display."""
  1329     try:
  1323     return encoding.trim(text, maxlength, ellipsis='...')
  1330         # use unicode not to split at intermediate multi-byte sequence
       
  1331         utext, truncated = _ellipsis(text.decode(encoding.encoding),
       
  1332                                      maxlength)
       
  1333         if not truncated:
       
  1334             return text
       
  1335         return utext.encode(encoding.encoding)
       
  1336     except (UnicodeDecodeError, UnicodeEncodeError):
       
  1337         return _ellipsis(text, maxlength)[0]
       
  1338 
  1324 
  1339 def unitcountfn(*unittable):
  1325 def unitcountfn(*unittable):
  1340     '''return a function that renders a readable count of some quantity'''
  1326     '''return a function that renders a readable count of some quantity'''
  1341 
  1327 
  1342     def go(count):
  1328     def go(count):