-
Notifications
You must be signed in to change notification settings - Fork 3
/
diff.go
65 lines (50 loc) · 961 Bytes
/
diff.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package pitchfork
import (
"github.com/aryann/difflib"
"strings"
)
type PfDiff struct {
Common string
Left string
Right string
}
func diff_do(a string, b string) (diff []difflib.DiffRecord) {
tA := strings.Split(a, "\n")
tB := strings.Split(b, "\n")
return difflib.Diff(tA, tB)
}
func Diff_Out(ctx PfCtx, a string, b string) {
df := diff_do(a, b)
for _, d := range df {
switch d.Delta {
case difflib.Common:
ctx.OutLn(" %s", d.Payload)
break
case difflib.LeftOnly:
ctx.OutLn("-%s", d.Payload)
break
case difflib.RightOnly:
ctx.OutLn("+%s", d.Payload)
break
}
}
}
func DoDiff(a string, b string) (diff []PfDiff) {
df := diff_do(a, b)
for _, d := range df {
var t PfDiff
switch d.Delta {
case difflib.Common:
t.Common = d.Payload
break
case difflib.LeftOnly:
t.Left = d.Payload
break
case difflib.RightOnly:
t.Right = d.Payload
break
}
diff = append(diff, t)
}
return
}