Mercurial > bins
changeset 6:3021deef1599
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
author | Peter Gervai <grin@grin.hu> |
---|---|
date | Thu, 16 Oct 2008 00:02:14 +0200 |
parents | e8a9408780ff |
children | 69923c621cfe |
files | bins_edit |
diffstat | 1 files changed, 13 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- 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' => {