Indent inserts prefix at the beginning of each non-empty line of s. The end-of-line marker is NL.
(s, prefix string)
| 74 | // Indent inserts prefix at the beginning of each non-empty line of s. The |
| 75 | // end-of-line marker is NL. |
| 76 | func Indent(s, prefix string) string { |
| 77 | var ( |
| 78 | b = []byte(s) |
| 79 | p = []byte(prefix) |
| 80 | res = make([]byte, 0, len(b)+len(b)/4*len(p)) // preallocate with estimated size |
| 81 | bol = true |
| 82 | ) |
| 83 | for _, c := range b { |
| 84 | if bol && c != '\n' { |
| 85 | res = append(res, p...) |
| 86 | } |
| 87 | res = append(res, c) |
| 88 | bol = c == '\n' |
| 89 | } |
| 90 | return string(res) |
| 91 | } |
| 92 | |
| 93 | // Casing exceptions |
| 94 | var toLower = map[string]string{"OAuth": "oauth"} |