-
Notifications
You must be signed in to change notification settings - Fork 5
/
strpatch.go
42 lines (36 loc) · 924 Bytes
/
strpatch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"log"
"os"
"unicode/utf8"
"github.com/cubicdaiya/gonp"
)
func main() {
if len(os.Args) < 3 {
log.Fatal("./strdiff arg1 arg2")
}
if !utf8.ValidString(os.Args[1]) {
log.Fatal("arg1 contains invalid rune")
}
if !utf8.ValidString(os.Args[2]) {
log.Fatal("arg2 contains invalid rune")
}
a := []rune(os.Args[1])
b := []rune(os.Args[2])
diff := gonp.New(a, b)
diff.Compose()
patchedSeq := diff.Patch(a)
fmt.Printf("success:%v, applying SES between '%s' and '%s' to '%s' is '%s'\n",
string(b) == string(patchedSeq),
string(a), string(b),
string(a), string(patchedSeq))
uniPatchedSeq, err := diff.UniPatch(a, diff.UnifiedHunks())
if err != nil {
log.Fatal(err)
}
fmt.Printf("success:%v, applying unified format difference between '%s' and '%s' to '%s' is '%s'\n",
string(b) == string(uniPatchedSeq),
string(a), string(b),
string(a), string(uniPatchedSeq))
}