Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: i18n/utf8 problem, 'utf8 "\xF8" does not map to Unicode'

by Juerd (Abbot)
on Feb 25, 2008 at 15:04 UTC ( #670014=note: print w/ replies, xml ) Need Help??


in reply to Re^2: i18n/utf8 problem, 'utf8 "\xF8" does not map to Unicode'
in thread i18n/utf8 problem, 'utf8 "\xF8" does not map to Unicode'

If you have the raw bytestring, the easiest way to see if it's valid UTF-8 is to decode it to a unicode string. If that fails, it wasn't utf8 enough :)

utf8::decode($string) or die "Input is not valid UTF-8";
or
utf8::decode(my $text = $binary) or die "Input is not valid UTF-8";
If you leave out the "or die" clause, any invalid UTF-8 will just be seen as ISO-8859-1.

Update: changed the examples as per ikegami's sound response.

Juerd # { site => 'juerd.nl', do_not_use => 'spamtrap', perl6_server => 'feather' }


Comment on Re^3: i18n/utf8 problem, 'utf8 "\xF8" does not map to Unicode'
Select or Download Code
Replies are listed 'Best First'.
Re^4: i18n/utf8 problem, 'utf8 "\xF8" does not map to Unicode'
by ikegami (Pope) on Feb 25, 2008 at 17:40 UTC
    That should be
    utf8::decode(my $text = $binary) or die "Input is not valid UTF-8";

    It works in-place.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://670014]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2015-07-31 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (280 votes), past polls