Indent prepends each line of a string with a tab
(str string)
| 7 | |
| 8 | // Indent prepends each line of a string with a tab |
| 9 | func Indent(str string) string { |
| 10 | |
| 11 | // trim superfluous whitespace |
| 12 | str = strings.TrimSpace(str) |
| 13 | |
| 14 | // prepend each line with a tab character |
| 15 | out := "" |
| 16 | for _, line := range strings.Split(str, "\n") { |
| 17 | out += fmt.Sprintf("\t%s\n", line) |
| 18 | } |
| 19 | |
| 20 | return out |
| 21 | } |
no outgoing calls