Make a patch, convert it to text, and apply that text to the original later, possibly elsewhere.
()
| 76 | // Make a patch, convert it to text, and apply that text to the |
| 77 | // original later, possibly elsewhere. |
| 78 | func 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. |
| 106 | func ExampleDiffMatchPatch_MatchMain() { |
nothing calls this directly
no test coverage detected