Commit | Line | Data |
a0ed51b3 |
1 | package utf8; |
2 | |
663b9db3 |
3 | |
d5448623 |
4 | $utf8::hint_bits = 0x00800000; |
5 | |
b75c8c73 |
6 | our $VERSION = '1.00'; |
7 | |
a0ed51b3 |
8 | sub import { |
d5448623 |
9 | $^H |= $utf8::hint_bits; |
a0ed51b3 |
10 | $enc{caller()} = $_[1] if $_[1]; |
11 | } |
12 | |
13 | sub unimport { |
d5448623 |
14 | $^H &= ~$utf8::hint_bits; |
a0ed51b3 |
15 | } |
16 | |
17 | sub AUTOLOAD { |
18 | require "utf8_heavy.pl"; |
daf4d4ea |
19 | goto &$AUTOLOAD if defined &$AUTOLOAD; |
20 | Carp::croak("Undefined subroutine $AUTOLOAD called"); |
a0ed51b3 |
21 | } |
22 | |
23 | 1; |
24 | __END__ |
25 | |
26 | =head1 NAME |
27 | |
393fec97 |
28 | utf8 - Perl pragma to enable/disable UTF-8 in source code |
a0ed51b3 |
29 | |
30 | =head1 SYNOPSIS |
31 | |
32 | use utf8; |
33 | no utf8; |
34 | |
35 | =head1 DESCRIPTION |
36 | |
393fec97 |
37 | WARNING: The implementation of Unicode support in Perl is incomplete. |
21bad921 |
38 | See L<perlunicode> for the exact details. |
a0ed51b3 |
39 | |
393fec97 |
40 | The C<use utf8> pragma tells the Perl parser to allow UTF-8 in the |
41 | program text in the current lexical scope. The C<no utf8> pragma |
42 | tells Perl to switch back to treating the source text as literal |
43 | bytes in the current lexical scope. |
a0ed51b3 |
44 | |
393fec97 |
45 | This pragma is primarily a compatibility device. Perl versions |
46 | earlier than 5.6 allowed arbitrary bytes in source code, whereas |
47 | in future we would like to standardize on the UTF-8 encoding for |
48 | source text. Until UTF-8 becomes the default format for source |
49 | text, this pragma should be used to recognize UTF-8 in the source. |
50 | When UTF-8 becomes the standard source format, this pragma will |
663b9db3 |
51 | effectively become a no-op. This pragma already is a no-op on |
1b026014 |
52 | EBCDIC platforms (where it is alright to code perl in EBCDIC |
663b9db3 |
53 | rather than UTF-8). |
a0ed51b3 |
54 | |
393fec97 |
55 | Enabling the C<utf8> pragma has the following effects: |
a0ed51b3 |
56 | |
4ac9195f |
57 | =over 4 |
a0ed51b3 |
58 | |
59 | =item * |
60 | |
393fec97 |
61 | Bytes in the source text that have their high-bit set will be treated |
62 | as being part of a literal UTF-8 character. This includes most literals |
63 | such as identifiers, string constants, constant regular expression patterns |
64 | and package names. |
a0ed51b3 |
65 | |
66 | =item * |
67 | |
393fec97 |
68 | In the absence of inputs marked as UTF-8, regular expressions within the |
69 | scope of this pragma will default to using character semantics instead |
70 | of byte semantics. |
a0ed51b3 |
71 | |
393fec97 |
72 | @bytes_or_chars = split //, $data; # may split to bytes if data |
73 | # $data isn't UTF-8 |
74 | { |
75 | use utf8; # force char semantics |
76 | @chars = split //, $data; # splits characters |
a0ed51b3 |
77 | } |
78 | |
4ac9195f |
79 | =back |
80 | |
1b026014 |
81 | =head2 Utility functions |
82 | |
83 | The following functions are defined in the C<utf8::> package by the perl core. |
84 | |
85 | =over 4 |
86 | |
87 | =item * $num_octets = utf8::upgrade($string); |
88 | |
89 | Converts internal representation of string to the perls internal UTF-X form. |
90 | Returns the number of octets necessary to represent the string as UTF-X. |
91 | |
92 | =item * utf8::downgrade($string[, CHECK]) |
93 | |
94 | Converts internal representation of string to be un-encoded bytes. |
95 | |
96 | =item * utf8::encode($string) |
97 | |
98 | Converts (in-place) I<$string> from logical characters to octet sequence |
99 | representing it in perl's UTF-X encoding. |
100 | |
101 | =item * $flag = utf8::decode($string) |
102 | |
103 | Attempts to converts I<$string> in-place from perl's UTF-X encoding into logical characters. |
104 | |
105 | =back |
106 | |
393fec97 |
107 | =head1 SEE ALSO |
a0ed51b3 |
108 | |
8058d7ab |
109 | L<perlunicode>, L<bytes> |
a0ed51b3 |
110 | |
111 | =cut |