From 73f2ea0d517a20058ba2d31c86036c44052e651d Mon Sep 17 00:00:00 2001 From: Ben Keith Date: Fri, 2 Mar 2018 20:42:19 -0500 Subject: Allow no indentation in strings.Indent When recursively generating YAML, it is useful to have a simple generic template definition that starts with an indent of 0 and increments at each level YAML. If you pass `width` of 0 to the function as it was before this change, it would indent it one level without complaining, which was a great source of confusion to me. --- strings/strings.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'strings/strings.go') diff --git a/strings/strings.go b/strings/strings.go index d7d2c504..1ca3146a 100644 --- a/strings/strings.go +++ b/strings/strings.go @@ -4,6 +4,9 @@ import "strings" // Indent - indent each line of the string with the given indent string func Indent(width int, indent, s string) string { + if width == 0 { + return s + } if width > 1 { indent = strings.Repeat(indent, width) } -- cgit v1.2.3