package textimport ()// Indent inserts prefix at the beginning of each non-empty line of s. The// end-of-line marker is NL.func (, string) string {returnstring(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 := truefor , := range {if && != '\n' { = append(, ...) } = append(, ) = == '\n' }return}// Writer indents each line of its input.typeindentWriterstruct {wio.Writerbolboolpre [][]byteselintoffint}// 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 {varint , = .w.Write(.pre[.sel][.off:]) .off += if != nil {return , } } _, = .w.Write([]byte{})if != nil {return , } ++ .bol = == '\n'if .bol { .off = 0if .sel < len(.pre)-1 { .sel++ } } }return , nil}
The pages are generated with Goldsv0.4.9. (GOOS=linux GOARCH=amd64)