| package text |
| |
| // Indent inserts prefix at the beginning of each non-empty line of s. The |
| // end-of-line marker is NL. |
| func Indent(s, prefix string) string { |
| return string(IndentBytes([]byte(s), []byte(prefix))) |
| } |
| |
| // IndentBytes inserts prefix at the beginning of each non-empty line of b. |
| // The end-of-line marker is NL. |
| func IndentBytes(b, prefix []byte) []byte { |
| var res []byte |
| bol := true |
| for _, c := range b { |
| if bol && c != '\n' { |
| res = append(res, prefix...) |
| } |
| res = append(res, c) |
| bol = c == '\n' |
| } |
| return res |
| } |