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

Function ExampleDiffMatchPatch_DiffMain

diffmatchpatch/example_test.go:19–36  ·  view source on GitHub ↗

Compare two texts and print the differences.

()

Source from the content-addressed store, hash-verified

17
18// Compare two texts and print the differences.
19func ExampleDiffMatchPatch_DiffMain() {
20 dmp := diffmatchpatch.New()
21
22 diffs := dmp.DiffMain("Lorem ipsum dolor.", "Lorem dolor sit amet.", false)
23
24 for _, diff := range diffs {
25 switch diff.Type {
26 case diffmatchpatch.DiffInsert:
27 fmt.Print("[+]", diff.Text)
28 case diffmatchpatch.DiffDelete:
29 fmt.Print("[-]", diff.Text)
30 case diffmatchpatch.DiffEqual:
31 fmt.Print("[=]", diff.Text)
32 }
33 }
34
35 // Output: [=]Lorem [-]ipsum [=]dolor[+] sit amet[=].
36}
37
38// The diffs are plain data; the source and target texts can be
39// reconstructed from them without any pretty printing.

Callers

nothing calls this directly

Calls 2

NewFunction · 0.92
DiffMainMethod · 0.80

Tested by

no test coverage detected