Mercurial > hg-stable
changeset 2559:bf67d0f6531c
templater.firstline should handle empty strings
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Tue, 04 Jul 2006 15:36:05 -0700 |
parents | 1120302009d7 |
children | 2748253b49c2 |
files | mercurial/templater.py |
diffstat | 1 files changed, 8 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templater.py Mon Jul 03 00:33:19 2006 -0300 +++ b/mercurial/templater.py Tue Jul 04 15:36:05 2006 -0700 @@ -221,6 +221,13 @@ fp.write(rest) return fp.getvalue() +def firstline(text): + '''return the first line of text''' + try: + return text.splitlines(1)[0].rstrip('\r\n') + except IndexError: + return '' + def isodate(date): '''turn a (timestamp, tzoff) tuple into an iso 8631 date and time.''' return util.datestr(date, format='%Y-%m-%d %H:%M') @@ -284,7 +291,7 @@ "escape": lambda x: cgi.escape(x, True), "fill68": lambda x: fill(x, width=68), "fill76": lambda x: fill(x, width=76), - "firstline": lambda x: x.splitlines(1)[0].rstrip('\r\n'), + "firstline": firstline, "tabindent": lambda x: indent(x, '\t'), "hgdate": hgdate, "isodate": isodate,