diff options
Diffstat (limited to 'common/text/transform.go')
-rw-r--r-- | common/text/transform.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/common/text/transform.go b/common/text/transform.go index b324b54c1..2b05b9b4f 100644 --- a/common/text/transform.go +++ b/common/text/transform.go @@ -61,3 +61,17 @@ func Puts(s string) string { } return s + "\n" } + +// VisitLinesAfter calls the given function for each line, including newlines, in the given string. +func VisitLinesAfter(s string, fn func(line string)) { + high := strings.Index(s, "\n") + for high != -1 { + fn(s[:high+1]) + s = s[high+1:] + high = strings.Index(s, "\n") + } + + if s != "" { + fn(s) + } +} |