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

Function ExampleDiffMatchPatch_PatchMake

diffmatchpatch/example_test.go:78–103  ·  view source on GitHub ↗

Make a patch, convert it to text, and apply that text to the original later, possibly elsewhere.

()

Source from the content-addressed store, hash-verified

76// Make a patch, convert it to text, and apply that text to the
77// original later, possibly elsewhere.
78func ExampleDiffMatchPatch_PatchMake() {
79 dmp := diffmatchpatch.New()
80
81 text1 := "hello world"
82 text2 := "goodbye world"
83
84 patchText := dmp.PatchToText(dmp.PatchMake(text1, text2))
85 fmt.Print(patchText)
86
87 patches, err := dmp.PatchFromText(patchText)
88 if err != nil {
89 log.Fatal(err)
90 }
91 result, applied := dmp.PatchApply(patches, text1)
92
93 fmt.Println(applied)
94 fmt.Println(result)
95
96 // Output:
97 // @@ -1,9 +1,11 @@
98 // -hello
99 // +goodbye
100 // wor
101 // [true]
102 // goodbye world
103}
104
105// Locate a pattern in the text, exactly or fuzzily.
106func ExampleDiffMatchPatch_MatchMain() {

Callers

nothing calls this directly

Calls 5

NewFunction · 0.92
PatchToTextMethod · 0.80
PatchMakeMethod · 0.80
PatchFromTextMethod · 0.80
PatchApplyMethod · 0.80

Tested by

no test coverage detected