Compare two texts and print the differences.
()
| 17 | |
| 18 | // Compare two texts and print the differences. |
| 19 | func 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. |