@@ -670,16 +670,16 @@ func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
670
670
// An insertion or deletion.
671
671
672
672
if diffs [pointer ].Type == DiffInsert {
673
- lengthInsertions2 += len (diffs [pointer ].Text )
673
+ lengthInsertions2 += utf8 . RuneCountInString (diffs [pointer ].Text )
674
674
} else {
675
- lengthDeletions2 += len (diffs [pointer ].Text )
675
+ lengthDeletions2 += utf8 . RuneCountInString (diffs [pointer ].Text )
676
676
}
677
677
// Eliminate an equality that is smaller or equal to the edits on both sides of it.
678
678
difference1 := int (math .Max (float64 (lengthInsertions1 ), float64 (lengthDeletions1 )))
679
679
difference2 := int (math .Max (float64 (lengthInsertions2 ), float64 (lengthDeletions2 )))
680
- if len (lastequality ) > 0 &&
681
- (len (lastequality ) <= difference1 ) &&
682
- (len (lastequality ) <= difference2 ) {
680
+ if utf8 . RuneCountInString (lastequality ) > 0 &&
681
+ (utf8 . RuneCountInString (lastequality ) <= difference1 ) &&
682
+ (utf8 . RuneCountInString (lastequality ) <= difference2 ) {
683
683
// Duplicate record.
684
684
insPoint := equalities [len (equalities )- 1 ]
685
685
diffs = splice (diffs , insPoint , 0 , Diff {DiffDelete , lastequality })
@@ -728,8 +728,8 @@ func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
728
728
overlapLength1 := dmp .DiffCommonOverlap (deletion , insertion )
729
729
overlapLength2 := dmp .DiffCommonOverlap (insertion , deletion )
730
730
if overlapLength1 >= overlapLength2 {
731
- if float64 (overlapLength1 ) >= float64 (len (deletion ))/ 2 ||
732
- float64 (overlapLength1 ) >= float64 (len (insertion ))/ 2 {
731
+ if float64 (overlapLength1 ) >= float64 (utf8 . RuneCountInString (deletion ))/ 2 ||
732
+ float64 (overlapLength1 ) >= float64 (utf8 . RuneCountInString (insertion ))/ 2 {
733
733
734
734
// Overlap found. Insert an equality and trim the surrounding edits.
735
735
diffs = splice (diffs , pointer , 0 , Diff {DiffEqual , insertion [:overlapLength1 ]})
@@ -739,8 +739,8 @@ func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
739
739
pointer ++
740
740
}
741
741
} else {
742
- if float64 (overlapLength2 ) >= float64 (len (deletion ))/ 2 ||
743
- float64 (overlapLength2 ) >= float64 (len (insertion ))/ 2 {
742
+ if float64 (overlapLength2 ) >= float64 (utf8 . RuneCountInString (deletion ))/ 2 ||
743
+ float64 (overlapLength2 ) >= float64 (utf8 . RuneCountInString (insertion ))/ 2 {
744
744
// Reverse overlap found. Insert an equality and swap and trim the surrounding edits.
745
745
overlap := Diff {DiffEqual , deletion [:overlapLength2 ]}
746
746
diffs = splice (diffs , pointer , 0 , overlap )
0 commit comments