MCPcopy Create free account
hub / github.com/sergi/go-diff / PatchDeepCopy

Method PatchDeepCopy

diffmatchpatch/patch.go:265–282  ·  view source on GitHub ↗

PatchDeepCopy returns an array that is identical to a given an array of patches.

(patches []Patch)

Source from the content-addressed store, hash-verified

263
264// PatchDeepCopy returns an array that is identical to a given an array of patches.
265func (dmp *DiffMatchPatch) PatchDeepCopy(patches []Patch) []Patch {
266 patchesCopy := []Patch{}
267 for _, aPatch := range patches {
268 patchCopy := Patch{}
269 for _, aDiff := range aPatch.diffs {
270 patchCopy.diffs = append(patchCopy.diffs, Diff{
271 aDiff.Type,
272 aDiff.Text,
273 })
274 }
275 patchCopy.Start1 = aPatch.Start1
276 patchCopy.Start2 = aPatch.Start2
277 patchCopy.Length1 = aPatch.Length1
278 patchCopy.Length2 = aPatch.Length2
279 patchesCopy = append(patchesCopy, patchCopy)
280 }
281 return patchesCopy
282}
283
284// PatchApply merges a set of patches onto the text. Returns a patched text, as well as an array of true/false values indicating which patches were applied.
285func (dmp *DiffMatchPatch) PatchApply(patches []Patch, text string) (string, []bool) {

Callers 2

PatchApplyMethod · 0.95
BenchmarkPatchSplitMaxFunction · 0.80

Calls

no outgoing calls

Tested by 1

BenchmarkPatchSplitMaxFunction · 0.64