7
// Indent inserts prefix at the beginning of each non-empty line of s. The
8
// end-of-line marker is NL.
9
func Indent(s, prefix string) string {
10
return string(IndentBytes([]byte(s), []byte(prefix)))
13
// IndentBytes inserts prefix at the beginning of each non-empty line of b.
14
// The end-of-line marker is NL.
15
func IndentBytes(b, prefix []byte) []byte {
20
res = append(res, prefix...)
28
// Writer indents each line of its input.
29
type indentWriter struct {
37
// NewIndentWriter makes a new write filter that indents the input
38
// lines. Each line is prefixed in order with the corresponding
39
// element of pre. If there are more lines than elements, the last
40
// element of pre is repeated for each subsequent line.
41
func NewIndentWriter(w io.Writer, pre ...[]byte) io.Writer {
49
// The only errors returned are from the underlying indentWriter.
50
func (w *indentWriter) Write(p []byte) (n int, err error) {
54
i, err = w.w.Write(w.pre[w.sel][w.off:])
60
_, err = w.w.Write([]byte{c})
68
if w.sel < len(w.pre)-1 {