unicode - Perl UTF8 to UTF16 conversion error - wide characters -
can tell me why snippet fails following error? have tried utf8::downgrade()
before calling from_to()
no success. using perl 5.14.2.
any ideas??
code:
use encode qw(from_to); use html::entities; $s = "มหัศ"; $foo = decode_entities($s); print "is foo utf8? ", utf8::is_utf8($foo), "\n"; from_to($foo, 'utf-8', 'utf-16');
output:
is foo utf8? 1 cannot decode string wide characters @ /usr/lib/perl/5.14/encode.pm line 194.
first of all, utf8::is_utf8
not think does. provides details internal storage of string, nothing should ever need check.
the problem string not encoded using utf-8. it's not encoded @ all. decode_entities
both takes , returns decoded string, string of unicode code points.
you use
encode('utf-16', decode_entities(decode('utf-8', $foo)))
Comments
Post a Comment