Skip to content

Commit ff42fa1

Browse files
committed
Made diff operation its own type.
1 parent c23354f commit ff42fa1

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

diffmatchpatch/dmp.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ import (
3232
// The data structure representing a diff is an array of tuples:
3333
// [[DiffDelete, 'Hello'], [DiffInsert, 'Goodbye'], [DiffEqual, ' world.']]
3434
// which means: delete 'Hello', add 'Goodbye' and keep ' world.'
35+
36+
type Operation int8
37+
3538
const (
36-
DiffDelete = -1
37-
DiffInsert = 1
38-
DiffEqual = 0
39+
DiffDelete Operation = -1
40+
DiffInsert Operation = 1
41+
DiffEqual Operation = 0
3942
)
4043

4144
// unescaper unescapes selected chars for compatability with JavaScript's encodeURI.
@@ -103,7 +106,7 @@ func max(x, y int) int {
103106

104107
// Diff represents one diff operation
105108
type Diff struct {
106-
Type int8
109+
Type Operation
107110
Text string
108111
}
109112

@@ -264,7 +267,7 @@ func (dmp *DiffMatchPatch) diffCompute(text1, text2 string, checklines bool, dea
264267
}
265268

266269
if i := strings.Index(longtext, shorttext); i != -1 {
267-
var op int8 = DiffInsert
270+
op := DiffInsert
268271
// Swap insertions for deletions if diff is reversed.
269272
if len(text1) > len(text2) {
270273
op = DiffDelete

0 commit comments

Comments
 (0)