perl-unicode

Re: UTF-8 encoding & decoding

2016-05-06 09:24:33
* Pali Rohár <pali(_dot_)rohar(_at_)gmail(_dot_)com> [2016-05-06 14:50]:
1. What is difference between those two calls?

 utf8::encode($str);

and

 $str = Encode::encode('utf8', $str);

2. What is difference between those?

 utf8::decode($str);
 $str = Encode::decode_utf8($str);

They do the same thing with different interfaces. utf8::encode/decode
modify a string in-place and return a boolean to signal success or not.
Encode.pm returns a copy and can be configured to do a range of things
with invalid input, from converting invalid bytes to replacement marks
to throwing an exception.

3. Where is implementation of utf8::encode/decode functions? It is not
in utf8.pm, nor in utf8_heavy.pl and also not in unicore/Heavy.pl. And
what those functions doing?

They are part of the perl interpreter and defined in universal.c as thin
wrappers around code ultimately from sv.c.

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

<Prev in Thread] Current Thread [Next in Thread>