Created
August 30, 2017 13:25
-
-
Save lujjjh/ef10d03bc589367920842dfa5305abd8 to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
src = "Hello world!" | |
dst = "Hello Config Hub!" | |
src2 = "Foo.\nHello world!.\nBar." | |
src3 = "Foo.\nGoodbye world!.\nBar." | |
) | |
func main() { | |
dmp := diffmatchpatch.New() | |
srcChars, dstChars, lineArray := dmp.DiffLinesToChars(src, dst) | |
diffs := dmp.DiffMain(srcChars, dstChars, false) | |
diffs = dmp.DiffCharsToLines(diffs, lineArray) | |
patches := dmp.PatchMake(src, diffs) | |
fmt.Println(dmp.PatchApply(patches, src2)) | |
fmt.Println(dmp.PatchApply(patches, src3)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment