Skip to content

Commit dbf098b

Browse files
authored
Fix DiffLevenshtein counting single runes as multiple edits
1 parent 217d392 commit dbf098b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

diffmatchpatch/diff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,9 +1236,9 @@ func (dmp *DiffMatchPatch) DiffLevenshtein(diffs []Diff) int {
12361236
for _, aDiff := range diffs {
12371237
switch aDiff.Type {
12381238
case DiffInsert:
1239-
insertions += len(aDiff.Text)
1239+
insertions += utf8.RuneCountInString(aDiff.Text)
12401240
case DiffDelete:
1241-
deletions += len(aDiff.Text)
1241+
deletions += utf8.RuneCountInString(aDiff.Text)
12421242
case DiffEqual:
12431243
// A deletion and an insertion is one substitution.
12441244
levenshtein += max(insertions, deletions)

0 commit comments

Comments
 (0)