| 86 | type edits []edit |
| 87 | |
| 88 | func (edits edits) apply(contents []byte) []byte { |
| 89 | // Apply the edits with the highest offset first, so that earlier edits |
| 90 | // don't affect the offsets of later edits. |
| 91 | sort.Slice(edits, func(i, j int) bool { |
| 92 | return edits[i].begin > edits[j].begin |
| 93 | }) |
| 94 | |
| 95 | for _, edit := range edits { |
| 96 | prefix := contents[:edit.begin] |
| 97 | suffix := contents[edit.end:] |
| 98 | contents = append(prefix, append(edit.replacement, suffix...)...) |
| 99 | } |
| 100 | |
| 101 | return contents |
| 102 | } |
| 103 | |
| 104 | // formatFuncDoc reformats the comment lines in commentList, and appends any |
| 105 | // changes to the edit list. |