Integrate perlio:
[p5sagit/p5-mst-13.2.git] / lib / utf8.pm
CommitLineData
a0ed51b3 1package utf8;
2
663b9db3 3if (ord('A') != 193) { # make things more pragmatic for EBCDIC folk
4
d5448623 5$utf8::hint_bits = 0x00800000;
6
a0ed51b3 7sub import {
d5448623 8 $^H |= $utf8::hint_bits;
a0ed51b3 9 $enc{caller()} = $_[1] if $_[1];
10}
11
12sub unimport {
d5448623 13 $^H &= ~$utf8::hint_bits;
a0ed51b3 14}
15
16sub AUTOLOAD {
17 require "utf8_heavy.pl";
daf4d4ea 18 goto &$AUTOLOAD if defined &$AUTOLOAD;
19 Carp::croak("Undefined subroutine $AUTOLOAD called");
a0ed51b3 20}
21
663b9db3 22}
23
a0ed51b3 241;
25__END__
26
27=head1 NAME
28
393fec97 29utf8 - Perl pragma to enable/disable UTF-8 in source code
a0ed51b3 30
31=head1 SYNOPSIS
32
33 use utf8;
34 no utf8;
35
36=head1 DESCRIPTION
37
393fec97 38WARNING: The implementation of Unicode support in Perl is incomplete.
21bad921 39See L<perlunicode> for the exact details.
a0ed51b3 40
393fec97 41The C<use utf8> pragma tells the Perl parser to allow UTF-8 in the
42program text in the current lexical scope. The C<no utf8> pragma
43tells Perl to switch back to treating the source text as literal
44bytes in the current lexical scope.
a0ed51b3 45
393fec97 46This pragma is primarily a compatibility device. Perl versions
47earlier than 5.6 allowed arbitrary bytes in source code, whereas
48in future we would like to standardize on the UTF-8 encoding for
49source text. Until UTF-8 becomes the default format for source
50text, this pragma should be used to recognize UTF-8 in the source.
51When UTF-8 becomes the standard source format, this pragma will
663b9db3 52effectively become a no-op. This pragma already is a no-op on
53EBCDIC platforms (where it is alright to code perl in EBCDIC
54rather than UTF-8).
a0ed51b3 55
393fec97 56Enabling the C<utf8> pragma has the following effects:
a0ed51b3 57
393fec97 58=over
a0ed51b3 59
60=item *
61
393fec97 62Bytes in the source text that have their high-bit set will be treated
63as being part of a literal UTF-8 character. This includes most literals
64such as identifiers, string constants, constant regular expression patterns
65and package names.
a0ed51b3 66
67=item *
68
393fec97 69In the absence of inputs marked as UTF-8, regular expressions within the
70scope of this pragma will default to using character semantics instead
71of byte semantics.
a0ed51b3 72
393fec97 73 @bytes_or_chars = split //, $data; # may split to bytes if data
74 # $data isn't UTF-8
75 {
76 use utf8; # force char semantics
77 @chars = split //, $data; # splits characters
a0ed51b3 78 }
79
393fec97 80=head1 SEE ALSO
a0ed51b3 81
8058d7ab 82L<perlunicode>, L<bytes>
a0ed51b3 83
84=cut