File tree Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Expand file tree Collapse file tree 2 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -901,16 +901,15 @@ func (dmp *DiffMatchPatch) DiffCleanupSemanticLossless(diffs []Diff) []Diff {
901
901
return 6
902
902
}
903
903
904
- _one := []rune (one )
905
- _two := []rune (two )
906
-
907
904
// Each port of this function behaves slightly differently due to
908
905
// subtle differences in each language's definition of things like
909
906
// 'whitespace'. Since this function's purpose is largely cosmetic,
910
907
// the choice has been made to use each language's native features
911
908
// rather than force total conformity.
912
- char1 := string (_one [len (one )- 1 ])
913
- char2 := string (_two [0 ])
909
+ rune1 , _ := utf8 .DecodeLastRuneInString (one )
910
+ rune2 , _ := utf8 .DecodeRuneInString (two )
911
+ char1 := string (rune1 )
912
+ char2 := string (rune2 )
914
913
915
914
nonAlphaNumeric1 := nonAlphaNumericRegex_ .MatchString (char1 )
916
915
nonAlphaNumeric2 := nonAlphaNumericRegex_ .MatchString (char2 )
Original file line number Diff line number Diff line change @@ -437,6 +437,19 @@ func Test_diffCleanupSemanticLossless(t *testing.T) {
437
437
Diff {DiffEqual , "The xxx." },
438
438
Diff {DiffInsert , " The zzz." },
439
439
Diff {DiffEqual , " The yyy." }}, diffs )
440
+
441
+ // UTF-8 strings.
442
+ diffs = []Diff {
443
+ Diff {DiffEqual , "The ♕. The " },
444
+ Diff {DiffInsert , "♔. The " },
445
+ Diff {DiffEqual , "♖." }}
446
+
447
+ dmp .DiffCleanupSemanticLossless (diffs )
448
+
449
+ assertDiffEqual (t , []Diff {
450
+ Diff {DiffEqual , "The ♕." },
451
+ Diff {DiffInsert , " The ♔." },
452
+ Diff {DiffEqual , " The ♖." }}, diffs )
440
453
}
441
454
442
455
func Test_diffCleanupSemantic (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments