Change 13912 by jhi@alpha on 2001/12/27 23:56:20

        Fast Latin1<->UTF-8 conversion for older Perls.

Affected files ...

.... //depot/perl/pod/perluniintro.pod#14 edit

Differences ...

==== //depot/perl/pod/perluniintro.pod#14 (text) ====
Index: perl/pod/perluniintro.pod
--- perl/pod/perluniintro.pod.~1~       Thu Dec 27 17:00:05 2001
+++ perl/pod/perluniintro.pod   Thu Dec 27 17:00:05 2001
@@ -790,6 +790,15 @@
 If you have the GNU recode installed, you can also use the
 Perl frontend C<Convert::Recode> for character conversions.
 
+The following are fast conversions from ISO 8859-1 (Latin-1) bytes
+to UTF-8 bytes, the code works even with older Perl 5 versions.
+
+    # ISO 8859-1 to UTF-8
+    s/([\x80-\xFF])/chr(0xC0|ord($1)>>6).chr(0x80|ord($1)&0x3F)/eg;
+
+    # UTF-8 to ISO 8859-1
+    s/([\xC2\xC3])([\x80-\xBF])/chr(ord($1)<<6&0xC0|ord($2)&0x3F)/eg;
+
 =head1 SEE ALSO
 
 L<perlunicode>, L<Encode>, L<encoding>, L<open>, L<utf8>, L<bytes>,
End of Patch.

Reply via email to