Last active
January 23, 2020 10:46
-
-
Save dmundt/d0d47892942e9975112df995362cdd28 to your computer and use it in GitHub Desktop.
Go: diffpatchmerge example usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module example.com/m | |
go 1.13 | |
require github.com/sergi/go-diff v1.1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/sergi/go-diff/diffmatchpatch" | |
) | |
const ( | |
text1 = "Lorem ipsum dolor." | |
text2 = "Lorem dolor sit amet." | |
) | |
func main() { | |
dmp := diffmatchpatch.New() | |
diff := dmp.DiffMain(text1, text2, true) | |
dmp.DiffCleanupSemantic(diff) | |
patch := dmp.PatchMake(text1, text2, diff) | |
s := dmp.PatchToText(patch) | |
fmt.Println(s) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment