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

Function ExampleDiffMatchPatch_DiffCleanupSemantic

diffmatchpatch/example_test.go:121–145  ·  view source on GitHub ↗

Cleanup shifts edits to word boundaries: the raw diff on the left splits words, the cleaned up diff on the right edits whole words.

()

Source from the content-addressed store, hash-verified

119// Cleanup shifts edits to word boundaries: the raw diff on the left
120// splits words, the cleaned up diff on the right edits whole words.
121func ExampleDiffMatchPatch_DiffCleanupSemantic() {
122 dmp := diffmatchpatch.New()
123
124 diffs := dmp.DiffMain("and one two.", "and one one.", false)
125
126 for _, diff := range diffs {
127 fmt.Printf("%s %q\n", diff.Type, diff.Text)
128 }
129 fmt.Println("---")
130 for _, diff := range dmp.DiffCleanupSemantic(diffs) {
131 fmt.Printf("%s %q\n", diff.Type, diff.Text)
132 }
133
134 // Output:
135 // Equal "and one "
136 // Delete "tw"
137 // Equal "o"
138 // Insert "ne"
139 // Equal "."
140 // ---
141 // Equal "and one "
142 // Delete "two"
143 // Insert "one"
144 // Equal "."
145}

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
DiffMainMethod · 0.80
DiffCleanupSemanticMethod · 0.80

Tested by

no test coverage detected