Re: Fix UTF Encoding issue
- From
- Martin Koegler <mkoegler@auto.tuwien.ac.at>
- Date
- Dec 4, 2007, 08:16 UTC
- Message-ID
- <20071204081634.GD31042@auto.tuwien.ac.at>
- In-Reply-To
- <200712040955.04655.ismail@pardus.org.tr>
On Tue, Dec 04, 2007 at 09:55:04AM +0200, Ismail Dönmez wrote:
Show 6 quoted lines
> Tuesday 04 December 2007 Tarihinde 09:50:28 yazm????t??: > > The bug affects old versions of perl (Debian sarge = oldstable). > > As it works on the newer Debian etch, do you really think, that it is > > a good idea to report issue? > > Same problem here with v5.8.8 which is latest stable perl5 release.
I have put together a small perl script, which tests the various ways of decoding, which have been posted on the list. The first test is wrong by design. A working decoding method should result in "#öäü#äöü".
Debian sarge: #öäü#ÀöÌ ##äöü ##äöü ##äöü
Debian etch, OpenSuSE 10.2, Fedora 7: #öäü#ÀöÌ #öäü#äöü #öäü#äöü #öäü#äöü
mfg Martin Kögler
#!/usr/bin/perl use Encode;
sub t { my $str = shift; my ($res); eval { return ($res = decode_utf8($str, Encode::FB_CROAK)); }; return decode("latin1", $str, Encode::FB_DEFAULT); } sub t1 { my $str = shift; my ($res); eval { ($res = decode_utf8($str, Encode::FB_CROAK)); }; if ($@) { return decode("latin1", $str, Encode::FB_DEFAULT); } else { return $res; } }
sub t2 { my $str = shift; my ($res);
eval { $res = decode_utf8($str, Encode::FB_CROAK); };
if (defined $res) {
return $res;
} else {
return decode("latin1", $str, Encode::FB_DEFAULT);
}
}sub t3 {
my $str = shift;
my $res;
eval { $res = decode_utf8 ($str, 1); };
return $res || decode('latin1', $str);
}print t("#öäü"); print t("#ÀöÌ"); print "\n"; print t1("#öäü"); print t1("#ÀöÌ"); print "\n"; print t2("#öäü"); print t2("#ÀöÌ"); print "\n"; print t3("#öäü"); print t3("#ÀöÌ"); print "\n";