This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.pm: Add decoding example to pod
authorKarl Williamson <khw@cpan.org>
Sun, 27 Sep 2020 21:47:53 +0000 (15:47 -0600)
committerKarl Williamson <khw@cpan.org>
Sun, 27 Sep 2020 21:54:31 +0000 (15:54 -0600)
Thanks to Dagfinn Ilmari MannsÃ¥ker and H.Merijn Brand

lib/utf8.pm

index 607c59d..522f7d8 100644 (file)
@@ -2,7 +2,7 @@ package utf8;
 
 $utf8::hint_bits = 0x00800000;
 
-our $VERSION = '1.22';
+our $VERSION = '1.23';
 
 sub import {
     $^H |= $utf8::hint_bits;
@@ -199,6 +199,11 @@ otherwise returns true.
                      # with ord 0x100.   Since these bytes aren't
                      # legal UTF-EBCDIC, on EBCDIC platforms, $x is
                      # unchanged and the function returns FALSE.
+ my $y = "\xc3\x83\xc2\xab"; This has been encoded twice; this
+                     # example is only for ASCII platforms
+ utf8::decode($y);   # Converts $y to \xc3\xab, returns TRUE;
+ utf8::decode($y);   # Further converts to \xeb, returns TRUE;
+ utf8::decode($y);   # Returns FALSE, leaves $y unchanged
 
 B<Note that this function does not handle arbitrary encodings>;
 use L<Encode> instead.