Index: t/unicode.t
===================================================================
--- t/unicode.t (revision 0)
+++ t/unicode.t (revision 0)
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+
+use strict;
+
+BEGIN
+{
+ $ENV{'DIFF_OUTPUT_UNICODE'} = 1;
+}
+
+use Test::More;
+use Text::Diff;
+
+eval "use Encode;";
+
+if ($@)
+{
+ plan skip_all => "No utf8.";
+}
+else
+{
+ plan tests => 3;
+}
+
+sub u
+{
+ return decode("utf-8", shift);
+}
+
+sub ind
+{
+ my $s = u(shift(@_));
+ return index( diff( \(u("ש×××"), u("ש××ש")), { STYLE => "Table" } ), $s );
+}
+
+# TEST
+ok (
+ (ind("ש") >= 0),
+ "Output in unicode."
+);
+
+{
+ local $Text::Diff::Config::Output_Unicode = 0;
+ # To settle use warnings;
+ $Text::Diff::Config::Output_Unicode = 0+0;
+
+ # TEST
+ ok (
+ (ind ("\\x{05e9}" ) >= 0),
+ "Output not in unicode."
+ );
+
+ # TEST
+ ok (
+ (ind( "ש" ) < 0 ),
+ "Output not in unicode - no unicode char found."
+ );
+}
+
Index: lib/Text/Diff/Config.pm
===================================================================
--- lib/Text/Diff/Config.pm (revision 0)
+++ lib/Text/Diff/Config.pm (revision 0)
@@ -0,0 +1,70 @@
+package Text::Diff::Config;
+
+use strict;
+use warnings;
+
+use vars qw($Output_Unicode);
+
+BEGIN
+{
+ $Output_Unicode = $ENV{'DIFF_OUTPUT_UNICODE'};
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Text::Diff::Config - global configuration for Text::Diff (as a
+separate module).
+
+=head1 SYNOPSIS
+
+ use Text::Diff::Config;
+
+ $Text::Diff::Config::Output_Unicode = 1;
+
+=head1 DESCRIPTION
+
+This module configures Text::Diff and its related modules. Currently it contains
+only one global variable $Text::Diff::Config::Output_Unicode which is a boolean
+flag, that if set outputs unicode characters as themselves without escaping them
+as C< \x{HHHH} > first.
+
+It is initialized to the value of C< $ENV{DIFF_OUTPUT_UNICODE} >, but can be
+set to a different value at run-time, including using local.
+
+=head1 AUTHOR
+
+Shlomi Fish, L<
http://www.shlomifish.org/> .
+
+=head1 LICENSE
+
+Copyright 2010, Shlomi Fish.
+
+This file is licensed under the MIT/X11 License:
+L<
http://www.opensource.org/licenses/mit-license.php>.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
+=cut
+
Property changes on: lib/Text/Diff/Config.pm
___________________________________________________________________
Added: svn:eol-style
+ native
Index: lib/Text/Diff/Table.pm
===================================================================
--- lib/Text/Diff/Table.pm (revision 11778)
+++ lib/Text/Diff/Table.pm (working copy)
@@ -3,6 +3,8 @@
use 5.00503;
use strict;
use Carp;
+use Text::Diff::Config;
+
use vars qw{$VERSION @ISA @EXPORT_OK};
BEGIN {
$VERSION = '1.37';
@@ -59,10 +61,13 @@
sub escape($) {
use utf8;
join "", map {
+ my $c = $_;
$_ = ord;
exists $escapes{$_}
? $escapes{$_}
- : sprintf( "\\x{%04x}", $_ );
+ : $Text::Diff::Config::Output_Unicode
+ ? $c
+ : sprintf( "\\x{%04x}", $_ );
} split //, shift;
}
@@ -378,6 +383,13 @@
Whether or not line 3 should have that tab character escaped is a judgement
call; so far I'm choosing not to.
+=head1 UNICODE
+
+To output the raw unicode chracters consult the documentation of
+L<Text::Diff::Config>. You can set the C<DIFF_OUTPUT_UNICODE> environment
+variable to 1 to output it from the command line. For more information,
+consult this bug: L<
https://rt.cpan.org/Ticket/Display.html?id=54214> .
+
=head1 LIMITATIONS
Table formatting requires buffering the entire diff in memory in order to