Subject: | Will unicode check ever run? |
I've been having problems with XML::Smart reading my xml-files, and always saving them as iso-8859-1 files.
Then I read the source of XML/Smart/Data.pm and found the following pice of code:
###############
# _IS_UNICODE #
###############
sub _is_unicode {
if ($] >= 5.8) {
eval(q`
if ( $data =~ /[\x{100}-\x{10FFFF}]/s) { return 1 ;}}
`);
}
else {
## No Perl internal support for UTF-8! ;-/
## Is better to handle as Latin1.
return undef ;
}
return undef ;
}
------------------------------
Now I'm not an expert but, I guess the $data variable should be shifted, since it's passed as a parameter, and the $] never returns 5.8 but 5.008xxx, so anyways the $data variable is never used, and therefor the unicode check is nevere run (ergo never fails).
My suggestion to a fix is as follows:
-------------------------------
sub _is_unicode {
my $data = shift;
if ($] >= 5.008) {
## If we're using >5.008, we got utf8 so we should be able
## to use the utf8::_is_utf8 function.
use utf8;
if ( utf8::is_utf8($data)) { return 1 ;}
}
else {
## No Perl internal support for UTF-8! ;-/
## Is better to handle as Latin1.
return undef ;
}
return undef ;
}
------------------------------------
Ole Øyvind Hove <oleo@trenger.ro>