Skip to content

Instantly share code, notes, and snippets.

@lujjjh
Created August 30, 2017 13:25
Show Gist options
  • Save lujjjh/ef10d03bc589367920842dfa5305abd8 to your computer and use it in GitHub Desktop.
Save lujjjh/ef10d03bc589367920842dfa5305abd8 to your computer and use it in GitHub Desktop.
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