Diff two texts line by line by reducing each line to a character, diffing the reduced texts and expanding the result back to lines.
()
| 53 | // Diff two texts line by line by reducing each line to a character, |
| 54 | // diffing the reduced texts and expanding the result back to lines. |
| 55 | func ExampleDiffMatchPatch_DiffLinesToChars() { |
| 56 | dmp := diffmatchpatch.New() |
| 57 | |
| 58 | text1 := "foo\nbar\nbaz\n" |
| 59 | text2 := "foo\nbaz\nqux\n" |
| 60 | |
| 61 | chars1, chars2, lines := dmp.DiffLinesToChars(text1, text2) |
| 62 | diffs := dmp.DiffMain(chars1, chars2, false) |
| 63 | diffs = dmp.DiffCharsToLines(diffs, lines) |
| 64 | |
| 65 | for _, diff := range diffs { |
| 66 | fmt.Printf("%s %q\n", diff.Type, diff.Text) |
| 67 | } |
| 68 | |
| 69 | // Output: |
| 70 | // Equal "foo\n" |
| 71 | // Delete "bar\n" |
| 72 | // Equal "baz\n" |
| 73 | // Insert "qux\n" |
| 74 | } |
| 75 | |
| 76 | // Make a patch, convert it to text, and apply that text to the |
| 77 | // original later, possibly elsewhere. |
nothing calls this directly
no test coverage detected