File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -1250,6 +1250,26 @@ func (dmp *DiffMatchPatch) DiffLevenshtein(diffs []Diff) int {
1250
1250
return levenshtein
1251
1251
}
1252
1252
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
+
1253
1273
// DiffToDelta crushes the diff into an encoded string which describes the operations required to transform text1 into text2.
1254
1274
// 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.
1255
1275
func (dmp * DiffMatchPatch ) DiffToDelta (diffs []Diff ) string {
You can’t perform that action at this time.
0 commit comments