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