[enh] Add prependlines method to text formatting utils

This commit is contained in:
Jérôme Lebleu 2015-01-11 15:49:27 +01:00
parent df5cd5ad7f
commit f8f8bfca79

View file

@ -2,7 +2,7 @@ import re
import mmap
# Searching helpers ----------------------------------------------------
# Pattern searching ----------------------------------------------------
def search(pattern, text, count=0, flags=0):
"""Search for pattern in a text
@ -48,3 +48,11 @@ def searchf(pattern, path, count=0, flags=re.MULTILINE):
match = search(pattern, data, count, flags)
data.close()
return match
# Text formatting ------------------------------------------------------
def prependlines(text, prepend):
"""Prepend a string to each line of a text"""
lines = text.splitlines(True)
return "%s%s" % (prepend, prepend.join(lines))