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