# HG changeset patch # User Peter Gervai # Date 1224108134 -7200 # Node ID 3021deef1599f9fbf75e2977e71f4abdd6eec8bd # Parent e8a9408780ffc73f26e2805d2a5dafd8945ba393 Encoding related fixes * chomp encoding string * reformat else (seems someone hacked it in) * debug print encoding * do not use :utf8 binmode ("re-encode") on written file if the input is _already_ UTF-8 diff -r e8a9408780ff -r 3021deef1599 bins_edit --- a/bins_edit Wed Oct 15 23:36:49 2008 +0200 +++ b/bins_edit Thu Oct 16 00:02:14 2008 +0200 @@ -44,18 +44,19 @@ my $localEncoding; $localEncoding = `locale charmap`; +chomp $localEncoding; if ($? != 0 ) { $localEncoding = "LATIN1"; -} -else { -if (! $localEncoding or ($localEncoding eq "ANSI_X3.4-1968")) { - chop($localEncoding); - # ANSI is unspeakably primitive, promote it. - $localEncoding = "LATIN1"; - print "Forcing encoding to $localEncoding\n" if ($verbose >=2); -} +} else { + if (! $localEncoding or ($localEncoding eq "ANSI_X3.4-1968")) { + chop($localEncoding); + # ANSI is unspeakably primitive, promote it. + $localEncoding = "LATIN1"; + print "Forcing encoding to $localEncoding\n" if ($verbose >=2); + } } my $converter = Text::Iconv->new($localEncoding, "UTF-8"); +print "Using $localEncoding encoding on input\n" if ($verbose >=2); # decode HTML entites which doesn't exist in XML sub decodeEntites{ @@ -283,7 +284,10 @@ my $fileHandler = new IO::File; open($fileHandler, '>', $file) or die("Cannot open file $file to write Exif tag ($!)"); - binmode($fileHandler, ":utf8") if $^V ge v5.8.0; + if( $localEncoding !~ /utf-?8/i ) { + # if input is UTF-8 do not re-convert it again + binmode($fileHandler, ":utf8") if $^V ge v5.8.0; + } my $my_handler = new XML::Handler::YAWriter( 'Output' => $fileHandler, # 'Escape' => {