-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff_iterator.go
54 lines (44 loc) · 1.01 KB
/
diff_iterator.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
package go_three_way_merge
import (
"github.com/sergi/go-diff/diffmatchpatch"
)
type diffIterator struct {
diffs []diffmatchpatch.Diff
diffOffset int
runeOffset int
currentRunes []rune
}
func newDiffIterator(diffs []diffmatchpatch.Diff) diffIterator {
var currentRunes []rune
if len(diffs) != 0 {
currentRunes = []rune(diffs[0].Text)
}
return diffIterator{
diffs: diffs,
diffOffset: 0,
runeOffset: 0,
currentRunes: currentRunes,
}
}
func (i *diffIterator) next() {
i.runeOffset++
if i.runeOffset == len(i.currentRunes) {
i.runeOffset = 0
i.diffOffset++
if i.diffOffset < len(i.diffs) {
i.currentRunes = []rune(i.diffs[i.diffOffset].Text)
}
}
}
func (i diffIterator) diffType() int {
return int(i.diffs[i.diffOffset].Type)
}
func (i diffIterator) value() string {
return string(i.currentRunes[i.runeOffset])
}
func (i diffIterator) valueRune() rune {
return i.currentRunes[i.runeOffset]
}
func (i diffIterator) isFinished() bool {
return i.diffOffset >= len(i.diffs)
}