package text

import (
	
)

// Indent inserts prefix at the beginning of each non-empty line of s. The
// end-of-line marker is NL.
func (,  string) string {
	return string(IndentBytes([]byte(), []byte()))
}

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

// Writer indents each line of its input.
type indentWriter struct {
	w   io.Writer
	bol bool
	pre [][]byte
	sel int
	off int
}

// NewIndentWriter makes a new write filter that indents the input
// lines. Each line is prefixed in order with the corresponding
// element of pre. If there are more lines than elements, the last
// element of pre is repeated for each subsequent line.
func ( io.Writer,  ...[]byte) io.Writer {
	return &indentWriter{
		w:   ,
		pre: ,
		bol: true,
	}
}

// The only errors returned are from the underlying indentWriter.
func ( *indentWriter) ( []byte) ( int,  error) {
	for ,  := range  {
		if .bol {
			var  int
			,  = .w.Write(.pre[.sel][.off:])
			.off += 
			if  != nil {
				return , 
			}
		}
		_,  = .w.Write([]byte{})
		if  != nil {
			return , 
		}
		++
		.bol =  == '\n'
		if .bol {
			.off = 0
			if .sel < len(.pre)-1 {
				.sel++
			}
		}
	}
	return , nil
}