comparison mercurial/utils/stringutil.py @ 49086:51aed118f9dc

templates: extract function to `stringutil` for getting first line of text It's surprisingly hard to get the first line from a string, so let's have our own function in `stringutil` for it. Differential Revision: https://phab.mercurial-scm.org/D12404
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 24 Mar 2022 16:09:12 -0700
parents 642e31cb55f0
children 75794847ef62
comparison
equal deleted inserted replaced
49085:1138674ecdb8 49086:51aed118f9dc
683 False 683 False
684 """ 684 """
685 return _correctauthorformat.match(author) is not None 685 return _correctauthorformat.match(author) is not None
686 686
687 687
688 def firstline(text):
689 """Return the first line of the input"""
690 try:
691 return text.splitlines()[0]
692 except IndexError:
693 return b''
694
695
688 def ellipsis(text, maxlength=400): 696 def ellipsis(text, maxlength=400):
689 """Trim string to at most maxlength (default: 400) columns in display.""" 697 """Trim string to at most maxlength (default: 400) columns in display."""
690 return encoding.trim(text, maxlength, ellipsis=b'...') 698 return encoding.trim(text, maxlength, ellipsis=b'...')
691 699
692 700