diff options
| author | Ben Keith <keitwb@gmail.com> | 2018-03-02 20:42:19 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-02 20:42:19 -0500 |
| commit | 73f2ea0d517a20058ba2d31c86036c44052e651d (patch) | |
| tree | e3e72798d3cc744315e78e3c6006a7ae962dd9fa /strings/strings.go | |
| parent | 1ea5214a7153733385f14759e4c80a1e53956f09 (diff) | |
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.
Diffstat (limited to 'strings/strings.go')
| -rw-r--r-- | strings/strings.go | 3 |
1 files changed, 3 insertions, 0 deletions
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) } |
