@@ -670,16 +670,16 @@ func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
670670 // An insertion or deletion.
671671
672672 if diffs [pointer ].Type == DiffInsert {
673- lengthInsertions2 += len ([] rune ( diffs [pointer ].Text ) )
673+ lengthInsertions2 += utf8 . RuneCountInString ( diffs [pointer ].Text )
674674 } else {
675- lengthDeletions2 += len ([] rune ( diffs [pointer ].Text ) )
675+ lengthDeletions2 += utf8 . RuneCountInString ( diffs [pointer ].Text )
676676 }
677677 // Eliminate an equality that is smaller or equal to the edits on both sides of it.
678678 difference1 := int (math .Max (float64 (lengthInsertions1 ), float64 (lengthDeletions1 )))
679679 difference2 := int (math .Max (float64 (lengthInsertions2 ), float64 (lengthDeletions2 )))
680- if len ([] rune ( lastequality ) ) > 0 &&
681- (len ([] rune ( lastequality ) ) <= difference1 ) &&
682- (len ([] rune ( lastequality ) ) <= difference2 ) {
680+ if utf8 . RuneCountInString ( lastequality ) > 0 &&
681+ (utf8 . RuneCountInString ( lastequality ) <= difference1 ) &&
682+ (utf8 . RuneCountInString ( lastequality ) <= difference2 ) {
683683 // Duplicate record.
684684 insPoint := equalities [len (equalities )- 1 ]
685685 diffs = splice (diffs , insPoint , 0 , Diff {DiffDelete , lastequality })
@@ -728,8 +728,8 @@ func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
728728 overlapLength1 := dmp .DiffCommonOverlap (deletion , insertion )
729729 overlapLength2 := dmp .DiffCommonOverlap (insertion , deletion )
730730 if overlapLength1 >= overlapLength2 {
731- if float64 (overlapLength1 ) >= float64 (len ([] rune ( deletion ) ))/ 2 ||
732- float64 (overlapLength1 ) >= float64 (len ([] rune ( insertion ) ))/ 2 {
731+ if float64 (overlapLength1 ) >= float64 (utf8 . RuneCountInString ( deletion ))/ 2 ||
732+ float64 (overlapLength1 ) >= float64 (utf8 . RuneCountInString ( insertion ))/ 2 {
733733
734734 // Overlap found. Insert an equality and trim the surrounding edits.
735735 diffs = splice (diffs , pointer , 0 , Diff {DiffEqual , insertion [:overlapLength1 ]})
@@ -739,8 +739,8 @@ func (dmp *DiffMatchPatch) DiffCleanupSemantic(diffs []Diff) []Diff {
739739 pointer ++
740740 }
741741 } else {
742- if float64 (overlapLength2 ) >= float64 (len ([] rune ( deletion ) ))/ 2 ||
743- float64 (overlapLength2 ) >= float64 (len ([] rune ( insertion ) ))/ 2 {
742+ if float64 (overlapLength2 ) >= float64 (utf8 . RuneCountInString ( deletion ))/ 2 ||
743+ float64 (overlapLength2 ) >= float64 (utf8 . RuneCountInString ( insertion ))/ 2 {
744744 // Reverse overlap found. Insert an equality and swap and trim the surrounding edits.
745745 overlap := Diff {DiffEqual , deletion [:overlapLength2 ]}
746746 diffs = splice (diffs , pointer , 0 , overlap )
0 commit comments