replace changes yaml node value in stream at position, preserving content
(in []byte, line int, column int, value string)
| 124 | |
| 125 | // replace changes yaml node value in stream at position, preserving content |
| 126 | func replace(in []byte, line int, column int, value string) []byte { |
| 127 | var out []byte |
| 128 | l := 1 |
| 129 | pos := 0 |
| 130 | for _, b := range in { |
| 131 | if b == '\n' { |
| 132 | l++ |
| 133 | if l == line { |
| 134 | break |
| 135 | } |
| 136 | } |
| 137 | pos++ |
| 138 | } |
| 139 | pos += column |
| 140 | out = append(out, in[0:pos]...) |
| 141 | out = append(out, []byte(value)...) |
| 142 | for ; pos < len(in); pos++ { |
| 143 | if in[pos] == '\n' { |
| 144 | break |
| 145 | } |
| 146 | } |
| 147 | out = append(out, in[pos:]...) |
| 148 | return out |
| 149 | } |
no outgoing calls
no test coverage detected