##// END OF EJS Templates
templatefilters: indent: do not compute text.endswith('\n') in each iteration
Nicolas Dumazet -
r9387:20ed9909 default
parent child Browse files
Show More
@@ -105,13 +105,14 b' def indent(text, prefix):'
105 105 '''indent each non-empty line of text after first with prefix.'''
106 106 lines = text.splitlines()
107 107 num_lines = len(lines)
108 endswithnewline = text[-1:] == '\n'
108 109 def indenter():
109 110 for i in xrange(num_lines):
110 111 l = lines[i]
111 112 if i and l.strip():
112 113 yield prefix
113 114 yield l
114 if i < num_lines - 1 or text.endswith('\n'):
115 if i < num_lines - 1 or endswithnewline:
115 116 yield '\n'
116 117 return "".join(indenter())
117 118
General Comments 0
You need to be logged in to leave comments. Login now