From 86c82db6780593c4a7a9f52d1afbce29c5e37e8b Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 8 May 2013 16:00:34 +0200 Subject: Fix handle UTF-8 chars. --- localworddiff | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'localworddiff') diff --git a/localworddiff b/localworddiff index 1561684..af29599 100755 --- a/localworddiff +++ b/localworddiff @@ -33,14 +33,18 @@ my ( $infile1, $infile2, $outfile ) = @ARGV; die 'Missing input file arguments' unless ( $infile1 and $infile2 ); +# read infiles using File::Slurp (Text::WordDiff don't handle UTF-8) +my $text1 = read_file( $infile1, binmode => ':utf8' ); +my $text2 = read_file( $infile2, binmode => ':utf8' ); + # use console if no output file provided as third argument unless ($outfile) { - print word_diff $infile1, $infile2, { STYLE => 'ANSIColor' }; + print word_diff $text1, $text2, { STYLE => 'ANSIColor' }; exit 0; } # resolve diff -my $diff = word_diff $infile1, $infile2, { STYLE => 'HTMLTwoLines' }; +my $diff = word_diff $text1, $text2, { STYLE => 'HTMLTwoLines' }; # apply markup to each file div of resolved diff my $d = "
"; @@ -87,6 +91,6 @@ my $page = html( CHUNK( $diffchunk[1] ), ), ); -write_file( $outfile, $page ); +write_file( $outfile, { binmode => ':utf8' }, $page ); 1; -- cgit v1.2.3