MCPcopy Create free account
hub / github.com/cogentcore/core / ToPatch

Method ToPatch

texteditor/text/diff.go:126–140  ·  view source on GitHub ↗

ToPatch creates a Patch list from given Diffs output from DiffLines and the b strings from which the needed lines of source are copied. ApplyPatch with this on the a strings will result in the b strings. The resulting Patch is independent of bstr slice.

(bstr []string)

Source from the content-addressed store, hash-verified

124// ApplyPatch with this on the a strings will result in the b strings.
125// The resulting Patch is independent of bstr slice.
126func (dif Diffs) ToPatch(bstr []string) Patch {
127 pt := make(Patch, len(dif))
128 for pi, op := range dif {
129 pr := &PatchRec{Op: op}
130 if op.Tag == 'r' || op.Tag == 'i' {
131 nl := (op.J2 - op.J1)
132 pr.Blines = make([]string, nl)
133 for i := 0; i < nl; i++ {
134 pr.Blines[i] = bstr[op.J1+i]
135 }
136 }
137 pt[pi] = pr
138 }
139 return pt
140}
141
142// Apply applies given Patch to given file as list of strings
143// this does no checking except range checking so it won't crash

Callers 2

SaveStateMethod · 0.80
TestDiffFunction · 0.80

Calls

no outgoing calls

Tested by 1

TestDiffFunction · 0.64