Skip to content

Commit 2ed258d

Browse files
committed
updating functionality
1 parent 1744e29 commit 2ed258d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

diffmatchpatch/diff.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,26 @@ func (dmp *DiffMatchPatch) DiffLevenshtein(diffs []Diff) int {
12501250
return levenshtein
12511251
}
12521252

1253+
// DiffLevenshtein computes the Levenshtein distance that is the number of inserted, deleted or substituted characters.
1254+
func (dmp *DiffMatchPatch) DiffAdditionsDeletions(diffs []Diff) (int, int) {
1255+
insertions := 0
1256+
deletions := 0
1257+
1258+
for _, aDiff := range diffs {
1259+
switch aDiff.Type {
1260+
case DiffInsert:
1261+
insertions += len(aDiff.Text)
1262+
case DiffDelete:
1263+
deletions += len(aDiff.Text)
1264+
case DiffEqual:
1265+
// Do nothing we don't care
1266+
1267+
}
1268+
}
1269+
1270+
return insertions, deletions
1271+
}
1272+
12531273
// DiffToDelta crushes the diff into an encoded string which describes the operations required to transform text1 into text2.
12541274
// E.g. =3\t-2\t+ing -> Keep 3 chars, delete 2 chars, insert 'ing'. Operations are tab-separated. Inserted text is escaped using %xx notation.
12551275
func (dmp *DiffMatchPatch) DiffToDelta(diffs []Diff) string {

0 commit comments

Comments
 (0)