Skip to content

Commit d544696

Browse files
committed
Merge branch 'jk/colors' into maint
"diff-highlight" (in contrib/) used to show byte-by-byte differences, which meant that multi-byte characters can be chopped in the middle. It learned to pay attention to character boundaries (assuming the UTF-8 payload). * jk/colors: diff-highlight: do not split multibyte characters
2 parents d3115a3 + 8d00662 commit d544696

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

contrib/diff-highlight/diff-highlight

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/perl
22

3+
use 5.008;
34
use warnings FATAL => 'all';
45
use strict;
56

@@ -164,8 +165,12 @@ sub highlight_pair {
164165

165166
sub split_line {
166167
local $_ = shift;
167-
return map { /$COLOR/ ? $_ : (split //) }
168-
split /($COLOR*)/;
168+
return utf8::decode($_) ?
169+
map { utf8::encode($_); $_ }
170+
map { /$COLOR/ ? $_ : (split //) }
171+
split /($COLOR+)/ :
172+
map { /$COLOR/ ? $_ : (split //) }
173+
split /($COLOR+)/;
169174
}
170175

171176
sub highlight_line {

0 commit comments

Comments
 (0)