ekristen/libnuke

View on GitHub
pkg/utils/indent.go

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
package utils

func Indent(s, prefix string) string {
    return string(IndentBytes([]byte(s), []byte(prefix)))
}

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
}