Commit | Line | Data |
393fec97 |
1 | =head1 NAME |
2 | |
3 | perlunicode - Unicode support in Perl |
4 | |
5 | =head1 DESCRIPTION |
6 | |
0a1f2d14 |
7 | =head2 Important Caveats |
21bad921 |
8 | |
776f8809 |
9 | WARNING: While the implementation of Unicode support in Perl is now |
10 | fairly complete it is still evolving to some extent. |
21bad921 |
11 | |
75daf61c |
12 | In particular the way Unicode is handled on EBCDIC platforms is still |
13 | rather experimental. On such a platform references to UTF-8 encoding |
14 | in this document and elsewhere should be read as meaning UTF-EBCDIC as |
15 | specified in Unicode Technical Report 16 unless ASCII vs EBCDIC issues |
16 | are specifically discussed. There is no C<utfebcdic> pragma or |
17 | ":utfebcdic" layer, rather "utf8" and ":utf8" are re-used to mean |
18 | platform's "natural" 8-bit encoding of Unicode. See L<perlebcdic> for |
19 | more discussion of the issues. |
0a1f2d14 |
20 | |
21 | The following areas are still under development. |
21bad921 |
22 | |
13a2d996 |
23 | =over 4 |
21bad921 |
24 | |
25 | =item Input and Output Disciplines |
26 | |
75daf61c |
27 | A filehandle can be marked as containing perl's internal Unicode |
28 | encoding (UTF-8 or UTF-EBCDIC) by opening it with the ":utf8" layer. |
0a1f2d14 |
29 | Other encodings can be converted to perl's encoding on input, or from |
75daf61c |
30 | perl's encoding on output by use of the ":encoding()" layer. There is |
31 | not yet a clean way to mark the Perl source itself as being in an |
32 | particular encoding. |
21bad921 |
33 | |
34 | =item Regular Expressions |
35 | |
e6739005 |
36 | The regular expression compiler does now attempt to produce |
37 | polymorphic opcodes. That is the pattern should now adapt to the data |
75daf61c |
38 | and automatically switch to the Unicode character scheme when |
39 | presented with Unicode data, or a traditional byte scheme when |
40 | presented with byte data. The implementation is still new and |
41 | (particularly on EBCDIC platforms) may need further work. |
21bad921 |
42 | |
ad0029c4 |
43 | =item C<use utf8> still needed to enable UTF-8/UTF-EBCDIC in scripts |
21bad921 |
44 | |
75daf61c |
45 | The C<utf8> pragma implements the tables used for Unicode support. |
46 | These tables are automatically loaded on demand, so the C<utf8> pragma |
47 | need not normally be used. |
21bad921 |
48 | |
75daf61c |
49 | However, as a compatibility measure, this pragma must be explicitly |
ad0029c4 |
50 | used to enable recognition of UTF-8 in the Perl scripts themselves on |
51 | ASCII based machines or recognize UTF-EBCDIC on EBCDIC based machines. |
7dedd01f |
52 | B<NOTE: this should be the only place where an explicit C<use utf8> is |
53 | needed>. |
21bad921 |
54 | |
1768d7eb |
55 | You can also use the C<encoding> pragma to change the default encoding |
d521382b |
56 | of the data in your script; see L<encoding>. Currently this cannot |
57 | be combined with C<use utf8>. |
1768d7eb |
58 | |
21bad921 |
59 | =back |
60 | |
61 | =head2 Byte and Character semantics |
393fec97 |
62 | |
63 | Beginning with version 5.6, Perl uses logically wide characters to |
64 | represent strings internally. This internal representation of strings |
b3419ed8 |
65 | uses either the UTF-8 or the UTF-EBCDIC encoding. |
393fec97 |
66 | |
75daf61c |
67 | In future, Perl-level operations can be expected to work with |
68 | characters rather than bytes, in general. |
393fec97 |
69 | |
75daf61c |
70 | However, as strictly an interim compatibility measure, Perl aims to |
71 | provide a safe migration path from byte semantics to character |
72 | semantics for programs. For operations where Perl can unambiguously |
73 | decide that the input data is characters, Perl now switches to |
74 | character semantics. For operations where this determination cannot |
75 | be made without additional information from the user, Perl decides in |
76 | favor of compatibility, and chooses to use byte semantics. |
8cbd9a7a |
77 | |
78 | This behavior preserves compatibility with earlier versions of Perl, |
79 | which allowed byte semantics in Perl operations, but only as long as |
80 | none of the program's inputs are marked as being as source of Unicode |
81 | character data. Such data may come from filehandles, from calls to |
82 | external programs, from information provided by the system (such as %ENV), |
21bad921 |
83 | or from literals and constants in the source text. |
8cbd9a7a |
84 | |
75daf61c |
85 | If the C<-C> command line switch is used, (or the |
86 | ${^WIDE_SYSTEM_CALLS} global flag is set to C<1>), all system calls |
87 | will use the corresponding wide character APIs. Note that this is |
88 | currently only implemented on Windows since other platforms API |
89 | standard on this area. |
8cbd9a7a |
90 | |
75daf61c |
91 | Regardless of the above, the C<bytes> pragma can always be used to |
92 | force byte semantics in a particular lexical scope. See L<bytes>. |
8cbd9a7a |
93 | |
94 | The C<utf8> pragma is primarily a compatibility device that enables |
75daf61c |
95 | recognition of UTF-(8|EBCDIC) in literals encountered by the parser. |
7dedd01f |
96 | Note that this pragma is only required until a future version of Perl |
97 | in which character semantics will become the default. This pragma may |
98 | then become a no-op. See L<utf8>. |
8cbd9a7a |
99 | |
100 | Unless mentioned otherwise, Perl operators will use character semantics |
101 | when they are dealing with Unicode data, and byte semantics otherwise. |
102 | Thus, character semantics for these operations apply transparently; if |
103 | the input data came from a Unicode source (for example, by adding a |
104 | character encoding discipline to the filehandle whence it came, or a |
105 | literal UTF-8 string constant in the program), character semantics |
106 | apply; otherwise, byte semantics are in effect. To force byte semantics |
8058d7ab |
107 | on Unicode data, the C<bytes> pragma should be used. |
393fec97 |
108 | |
0a378802 |
109 | Notice that if you concatenate strings with byte semantics and strings |
110 | with Unicode character data, the bytes will by default be upgraded |
111 | I<as if they were ISO 8859-1 (Latin-1)> (or if in EBCDIC, after a |
112 | translation to ISO 8859-1). To change this, use the C<encoding> |
113 | pragma, see L<encoding>. |
7dedd01f |
114 | |
393fec97 |
115 | Under character semantics, many operations that formerly operated on |
75daf61c |
116 | bytes change to operating on characters. For ASCII data this makes no |
117 | difference, because UTF-8 stores ASCII in single bytes, but for any |
118 | character greater than C<chr(127)>, the character B<may> be stored in |
393fec97 |
119 | a sequence of two or more bytes, all of which have the high bit set. |
2796c109 |
120 | |
121 | For C1 controls or Latin 1 characters on an EBCDIC platform the |
122 | character may be stored in a UTF-EBCDIC multi byte sequence. But by |
123 | and large, the user need not worry about this, because Perl hides it |
124 | from the user. A character in Perl is logically just a number ranging |
125 | from 0 to 2**32 or so. Larger characters encode to longer sequences |
126 | of bytes internally, but again, this is just an internal detail which |
127 | is hidden at the Perl level. |
393fec97 |
128 | |
8cbd9a7a |
129 | =head2 Effects of character semantics |
393fec97 |
130 | |
131 | Character semantics have the following effects: |
132 | |
133 | =over 4 |
134 | |
135 | =item * |
136 | |
137 | Strings and patterns may contain characters that have an ordinal value |
21bad921 |
138 | larger than 255. |
393fec97 |
139 | |
75daf61c |
140 | Presuming you use a Unicode editor to edit your program, such |
141 | characters will typically occur directly within the literal strings as |
142 | UTF-8 (or UTF-EBCDIC on EBCDIC platforms) characters, but you can also |
143 | specify a particular character with an extension of the C<\x> |
144 | notation. UTF-X characters are specified by putting the hexadecimal |
145 | code within curlies after the C<\x>. For instance, a Unicode smiley |
146 | face is C<\x{263A}>. |
393fec97 |
147 | |
148 | =item * |
149 | |
150 | Identifiers within the Perl script may contain Unicode alphanumeric |
151 | characters, including ideographs. (You are currently on your own when |
75daf61c |
152 | it comes to using the canonical forms of characters--Perl doesn't |
153 | (yet) attempt to canonicalize variable names for you.) |
393fec97 |
154 | |
393fec97 |
155 | =item * |
156 | |
157 | Regular expressions match characters instead of bytes. For instance, |
158 | "." matches a character instead of a byte. (However, the C<\C> pattern |
75daf61c |
159 | is provided to force a match a single byte ("C<char>" in C, hence C<\C>).) |
393fec97 |
160 | |
393fec97 |
161 | =item * |
162 | |
163 | Character classes in regular expressions match characters instead of |
164 | bytes, and match against the character properties specified in the |
75daf61c |
165 | Unicode properties database. So C<\w> can be used to match an |
166 | ideograph, for instance. |
393fec97 |
167 | |
393fec97 |
168 | =item * |
169 | |
170 | Named Unicode properties and block ranges make be used as character |
171 | classes via the new C<\p{}> (matches property) and C<\P{}> (doesn't |
172 | match property) constructs. For instance, C<\p{Lu}> matches any |
173 | character with the Unicode uppercase property, while C<\p{M}> matches |
9fdf68be |
174 | any mark character. Single letter properties may omit the brackets, |
175 | so that can be written C<\pM> also. Many predefined character classes |
a1cc1cb1 |
176 | are available, such as C<\p{IsMirrored}> and C<\p{InTibetan}>. |
4193bef7 |
177 | |
178 | The C<\p{Is...}> test for "general properties" such as "letter", |
179 | "digit", while the C<\p{In...}> test for Unicode scripts and blocks. |
180 | |
e150c829 |
181 | The official Unicode script and block names have spaces and dashes and |
182 | separators, but for convenience you can have dashes, spaces, and |
183 | underbars at every word division, and you need not care about correct |
184 | casing. It is recommended, however, that for consistency you use the |
185 | following naming: the official Unicode script, block, or property name |
186 | (see below for the additional rules that apply to block names), |
187 | with whitespace and dashes replaced with underbar, and the words |
188 | "uppercase-first-lowercase-rest". That is, "Latin-1 Supplement" |
189 | becomes "Latin_1_Supplement". |
4193bef7 |
190 | |
a1cc1cb1 |
191 | You can also negate both C<\p{}> and C<\P{}> by introducing a caret |
e150c829 |
192 | (^) between the first curly and the property name: C<\p{^In_Tamil}> is |
193 | equal to C<\P{In_Tamil}>. |
4193bef7 |
194 | |
61247495 |
195 | The C<In> and C<Is> can be left out: C<\p{Greek}> is equal to |
e150c829 |
196 | C<\p{In_Greek}>, C<\P{Pd}> is equal to C<\P{Pd}>. |
393fec97 |
197 | |
d73e5302 |
198 | Short Long |
199 | |
200 | L Letter |
e150c829 |
201 | Lu Uppercase_Letter |
202 | Ll Lowercase_Letter |
203 | Lt Titlecase_Letter |
204 | Lm Modifier_Letter |
205 | Lo Other_Letter |
d73e5302 |
206 | |
207 | M Mark |
e150c829 |
208 | Mn Nonspacing_Mark |
209 | Mc Spacing_Mark |
210 | Me Enclosing_Mark |
d73e5302 |
211 | |
212 | N Number |
e150c829 |
213 | Nd Decimal_Number |
214 | Nl Letter_Number |
215 | No Other_Number |
d73e5302 |
216 | |
217 | P Punctuation |
e150c829 |
218 | Pc Connector_Punctuation |
219 | Pd Dash_Punctuation |
220 | Ps Open_Punctuation |
221 | Pe Close_Punctuation |
222 | Pi Initial_Punctuation |
d73e5302 |
223 | (may behave like Ps or Pe depending on usage) |
e150c829 |
224 | Pf Final_Punctuation |
d73e5302 |
225 | (may behave like Ps or Pe depending on usage) |
e150c829 |
226 | Po Other_Punctuation |
d73e5302 |
227 | |
228 | S Symbol |
e150c829 |
229 | Sm Math_Symbol |
230 | Sc Currency_Symbol |
231 | Sk Modifier_Symbol |
232 | So Other_Symbol |
d73e5302 |
233 | |
234 | Z Separator |
e150c829 |
235 | Zs Space_Separator |
236 | Zl Line_Separator |
237 | Zp Paragraph_Separator |
d73e5302 |
238 | |
239 | C Other |
e150c829 |
240 | Cc Control |
241 | Cf Format |
242 | Cs Surrogate |
243 | Co Private_Use |
244 | Cn Unassigned |
1ac13f9a |
245 | |
246 | There's also C<L&> which is an alias for C<Ll>, C<Lu>, and C<Lt>. |
32293815 |
247 | |
d73e5302 |
248 | The following reserved ranges have C<In> tests: |
249 | |
e150c829 |
250 | CJK_Ideograph_Extension_A |
251 | CJK_Ideograph |
252 | Hangul_Syllable |
253 | Non_Private_Use_High_Surrogate |
254 | Private_Use_High_Surrogate |
255 | Low_Surrogate |
256 | Private_Surrogate |
257 | CJK_Ideograph_Extension_B |
258 | Plane_15_Private_Use |
259 | Plane_16_Private_Use |
d73e5302 |
260 | |
261 | For example C<"\x{AC00}" =~ \p{HangulSyllable}> will test true. |
e9ad1727 |
262 | (Handling of surrogates is not implemented yet, because Perl |
263 | uses UTF-8 and not UTF-16 internally to represent Unicode.) |
d73e5302 |
264 | |
32293815 |
265 | Additionally, because scripts differ in their directionality |
266 | (for example Hebrew is written right to left), all characters |
267 | have their directionality defined: |
268 | |
d73e5302 |
269 | BidiL Left-to-Right |
270 | BidiLRE Left-to-Right Embedding |
271 | BidiLRO Left-to-Right Override |
272 | BidiR Right-to-Left |
273 | BidiAL Right-to-Left Arabic |
274 | BidiRLE Right-to-Left Embedding |
275 | BidiRLO Right-to-Left Override |
276 | BidiPDF Pop Directional Format |
277 | BidiEN European Number |
278 | BidiES European Number Separator |
279 | BidiET European Number Terminator |
280 | BidiAN Arabic Number |
281 | BidiCS Common Number Separator |
282 | BidiNSM Non-Spacing Mark |
283 | BidiBN Boundary Neutral |
284 | BidiB Paragraph Separator |
285 | BidiS Segment Separator |
286 | BidiWS Whitespace |
287 | BidiON Other Neutrals |
32293815 |
288 | |
2796c109 |
289 | =head2 Scripts |
290 | |
75daf61c |
291 | The scripts available for C<\p{In...}> and C<\P{In...}>, for example |
292 | \p{InCyrillic>, are as follows, for example C<\p{InLatin}> or C<\P{InHan}>: |
2796c109 |
293 | |
1ac13f9a |
294 | Arabic |
e9ad1727 |
295 | Armenian |
1ac13f9a |
296 | Bengali |
e9ad1727 |
297 | Bopomofo |
298 | Canadian-Aboriginal |
299 | Cherokee |
300 | Cyrillic |
301 | Deseret |
302 | Devanagari |
303 | Ethiopic |
304 | Georgian |
305 | Gothic |
306 | Greek |
1ac13f9a |
307 | Gujarati |
e9ad1727 |
308 | Gurmukhi |
309 | Han |
310 | Hangul |
311 | Hebrew |
312 | Hiragana |
313 | Inherited |
1ac13f9a |
314 | Kannada |
e9ad1727 |
315 | Katakana |
316 | Khmer |
1ac13f9a |
317 | Lao |
e9ad1727 |
318 | Latin |
319 | Malayalam |
320 | Mongolian |
1ac13f9a |
321 | Myanmar |
1ac13f9a |
322 | Ogham |
e9ad1727 |
323 | Old-Italic |
324 | Oriya |
1ac13f9a |
325 | Runic |
e9ad1727 |
326 | Sinhala |
327 | Syriac |
328 | Tamil |
329 | Telugu |
330 | Thaana |
331 | Thai |
332 | Tibetan |
1ac13f9a |
333 | Yi |
1ac13f9a |
334 | |
335 | There are also extended property classes that supplement the basic |
336 | properties, defined by the F<PropList> Unicode database: |
337 | |
e9ad1727 |
338 | ASCII_Hex_Digit |
1ac13f9a |
339 | Bidi_Control |
1ac13f9a |
340 | Dash |
1ac13f9a |
341 | Diacritic |
342 | Extender |
e9ad1727 |
343 | Hex_Digit |
344 | Hyphen |
345 | Ideographic |
346 | Join_Control |
347 | Noncharacter_Code_Point |
348 | Other_Alphabetic |
1ac13f9a |
349 | Other_Lowercase |
e9ad1727 |
350 | Other_Math |
1ac13f9a |
351 | Other_Uppercase |
e9ad1727 |
352 | Quotation_Mark |
e150c829 |
353 | White_Space |
1ac13f9a |
354 | |
355 | and further derived properties: |
356 | |
357 | Alphabetic Lu + Ll + Lt + Lm + Lo + Other_Alphabetic |
358 | Lowercase Ll + Other_Lowercase |
359 | Uppercase Lu + Other_Uppercase |
360 | Math Sm + Other_Math |
361 | |
362 | ID_Start Lu + Ll + Lt + Lm + Lo + Nl |
363 | ID_Continue ID_Start + Mn + Mc + Nd + Pc |
364 | |
365 | Any Any character |
366 | Assigned Any non-Cn character |
367 | Common Any character (or unassigned code point) |
e150c829 |
368 | not explicitly assigned to a script |
2796c109 |
369 | |
370 | =head2 Blocks |
371 | |
372 | In addition to B<scripts>, Unicode also defines B<blocks> of |
373 | characters. The difference between scripts and blocks is that the |
e9ad1727 |
374 | scripts concept is closer to natural languages, while the blocks |
2796c109 |
375 | concept is more an artificial grouping based on groups of 256 Unicode |
376 | characters. For example, the C<Latin> script contains letters from |
e9ad1727 |
377 | many blocks. On the other hand, the C<Latin> script does not contain |
378 | all the characters from those blocks, it does not for example contain |
379 | digits because digits are shared across many scripts. Digits and |
380 | other similar groups, like punctuation, are in a category called |
381 | C<Common>. |
2796c109 |
382 | |
383 | For more about scripts see the UTR #24: |
384 | http://www.unicode.org/unicode/reports/tr24/ |
385 | For more about blocks see |
386 | http://www.unicode.org/Public/UNIDATA/Blocks.txt |
387 | |
388 | Because there are overlaps in naming (there are, for example, both |
389 | a script called C<Katakana> and a block called C<Katakana>, the block |
390 | version has C<Block> appended to its name, C<\p{InKatakanaBlock}>. |
391 | |
392 | Notice that this definition was introduced in Perl 5.8.0: in Perl |
e150c829 |
393 | 5.6 only the blocks were used; in Perl 5.8.0 scripts became the |
61247495 |
394 | preferential Unicode character class definition; this meant that |
395 | the definitions of some character classes changed (the ones in the |
2796c109 |
396 | below list that have the C<Block> appended). |
397 | |
e9ad1727 |
398 | Alphabetic Presentation Forms |
399 | Arabic Block |
400 | Arabic Presentation Forms-A |
401 | Arabic Presentation Forms-B |
402 | Armenian Block |
403 | Arrows |
71d929cb |
404 | Basic Latin |
e9ad1727 |
405 | Bengali Block |
406 | Block Elements |
407 | Bopomofo Block |
408 | Bopomofo Extended |
409 | Box Drawing |
410 | Braille Patterns |
411 | Byzantine Musical Symbols |
412 | CJK Compatibility |
413 | CJK Compatibility Forms |
414 | CJK Compatibility Ideographs |
415 | CJK Compatibility Ideographs Supplement |
416 | CJK Radicals Supplement |
417 | CJK Symbols and Punctuation |
418 | CJK Unified Ideographs |
419 | CJK Unified Ideographs Extension A |
420 | CJK Unified Ideographs Extension B |
421 | Cherokee Block |
71d929cb |
422 | Combining Diacritical Marks |
e9ad1727 |
423 | Combining Half Marks |
424 | Combining Marks for Symbols |
425 | Control Pictures |
426 | Currency Symbols |
71d929cb |
427 | Cyrillic Block |
e9ad1727 |
428 | Deseret Block |
71d929cb |
429 | Devanagari Block |
e9ad1727 |
430 | Dingbats |
431 | Enclosed Alphanumerics |
432 | Enclosed CJK Letters and Months |
433 | Ethiopic Block |
434 | General Punctuation |
435 | Geometric Shapes |
71d929cb |
436 | Georgian Block |
e9ad1727 |
437 | Gothic Block |
438 | Greek Block |
439 | Greek Extended |
440 | Gujarati Block |
441 | Gurmukhi Block |
442 | Halfwidth and Fullwidth Forms |
443 | Hangul Compatibility Jamo |
71d929cb |
444 | Hangul Jamo |
e9ad1727 |
445 | Hangul Syllables |
446 | Hebrew Block |
447 | High Private Use Surrogates |
448 | High Surrogates |
449 | Hiragana Block |
450 | IPA Extensions |
451 | Ideographic Description Characters |
452 | Kanbun |
453 | Kangxi Radicals |
454 | Kannada Block |
455 | Katakana Block |
71d929cb |
456 | Khmer Block |
e9ad1727 |
457 | Lao Block |
458 | Latin 1 Supplement |
71d929cb |
459 | Latin Extended Additional |
e9ad1727 |
460 | Latin Extended-A |
461 | Latin Extended-B |
71d929cb |
462 | Letterlike Symbols |
e9ad1727 |
463 | Low Surrogates |
464 | Malayalam Block |
465 | Mathematical Alphanumeric Symbols |
71d929cb |
466 | Mathematical Operators |
e9ad1727 |
467 | Miscellaneous Symbols |
71d929cb |
468 | Miscellaneous Technical |
e9ad1727 |
469 | Mongolian Block |
470 | Musical Symbols |
471 | Myanmar Block |
472 | Number Forms |
473 | Ogham Block |
474 | Old Italic Block |
71d929cb |
475 | Optical Character Recognition |
e9ad1727 |
476 | Oriya Block |
71d929cb |
477 | Private Use |
e9ad1727 |
478 | Runic Block |
479 | Sinhala Block |
71d929cb |
480 | Small Form Variants |
e9ad1727 |
481 | Spacing Modifier Letters |
2796c109 |
482 | Specials |
e9ad1727 |
483 | Superscripts and Subscripts |
484 | Syriac Block |
2796c109 |
485 | Tags |
e9ad1727 |
486 | Tamil Block |
487 | Telugu Block |
488 | Thaana Block |
489 | Thai Block |
490 | Tibetan Block |
491 | Unified Canadian Aboriginal Syllabics |
492 | Yi Radicals |
493 | Yi Syllables |
32293815 |
494 | |
393fec97 |
495 | =item * |
496 | |
497 | The special pattern C<\X> match matches any extended Unicode sequence |
498 | (a "combining character sequence" in Standardese), where the first |
499 | character is a base character and subsequent characters are mark |
500 | characters that apply to the base character. It is equivalent to |
501 | C<(?:\PM\pM*)>. |
502 | |
393fec97 |
503 | =item * |
504 | |
383e7cdd |
505 | The C<tr///> operator translates characters instead of bytes. Note |
506 | that the C<tr///CU> functionality has been removed, as the interface |
507 | was a mistake. For similar functionality see pack('U0', ...) and |
508 | pack('C0', ...). |
393fec97 |
509 | |
393fec97 |
510 | =item * |
511 | |
512 | Case translation operators use the Unicode case translation tables |
44bc797b |
513 | when provided character input. Note that C<uc()> (also known as C<\U> |
514 | in doublequoted strings) translates to uppercase, while C<ucfirst> |
515 | (also known as C<\u> in doublequoted strings) translates to titlecase |
516 | (for languages that make the distinction). Naturally the |
517 | corresponding backslash sequences have the same semantics. |
393fec97 |
518 | |
519 | =item * |
520 | |
521 | Most operators that deal with positions or lengths in the string will |
75daf61c |
522 | automatically switch to using character positions, including |
523 | C<chop()>, C<substr()>, C<pos()>, C<index()>, C<rindex()>, |
524 | C<sprintf()>, C<write()>, and C<length()>. Operators that |
525 | specifically don't switch include C<vec()>, C<pack()>, and |
526 | C<unpack()>. Operators that really don't care include C<chomp()>, as |
527 | well as any other operator that treats a string as a bucket of bits, |
528 | such as C<sort()>, and the operators dealing with filenames. |
393fec97 |
529 | |
530 | =item * |
531 | |
532 | The C<pack()>/C<unpack()> letters "C<c>" and "C<C>" do I<not> change, |
533 | since they're often used for byte-oriented formats. (Again, think |
534 | "C<char>" in the C language.) However, there is a new "C<U>" specifier |
535 | that will convert between UTF-8 characters and integers. (It works |
536 | outside of the utf8 pragma too.) |
537 | |
538 | =item * |
539 | |
540 | The C<chr()> and C<ord()> functions work on characters. This is like |
541 | C<pack("U")> and C<unpack("U")>, not like C<pack("C")> and |
542 | C<unpack("C")>. In fact, the latter are how you now emulate |
35bcd338 |
543 | byte-oriented C<chr()> and C<ord()> for Unicode strings. |
544 | (Note that this reveals the internal UTF-8 encoding of strings and |
545 | you are not supposed to do that unless you know what you are doing.) |
393fec97 |
546 | |
547 | =item * |
548 | |
a1ca4561 |
549 | The bit string operators C<& | ^ ~> can operate on character data. |
550 | However, for backward compatibility reasons (bit string operations |
75daf61c |
551 | when the characters all are less than 256 in ordinal value) one should |
552 | not mix C<~> (the bit complement) and characters both less than 256 and |
a1ca4561 |
553 | equal or greater than 256. Most importantly, the DeMorgan's laws |
554 | (C<~($x|$y) eq ~$x&~$y>, C<~($x&$y) eq ~$x|~$y>) won't hold. |
555 | Another way to look at this is that the complement cannot return |
75daf61c |
556 | B<both> the 8-bit (byte) wide bit complement B<and> the full character |
a1ca4561 |
557 | wide bit complement. |
558 | |
559 | =item * |
560 | |
983ffd37 |
561 | lc(), uc(), lcfirst(), and ucfirst() work for the following cases: |
562 | |
563 | =over 8 |
564 | |
565 | =item * |
566 | |
567 | the case mapping is from a single Unicode character to another |
568 | single Unicode character |
569 | |
570 | =item * |
571 | |
572 | the case mapping is from a single Unicode character to more |
573 | than one Unicode character |
574 | |
575 | =back |
576 | |
577 | What doesn't yet work are the followng cases: |
578 | |
579 | =over 8 |
580 | |
581 | =item * |
582 | |
583 | the "final sigma" (Greek) |
584 | |
585 | =item * |
586 | |
587 | anything to with locales (Lithuanian, Turkish, Azeri) |
588 | |
589 | =back |
590 | |
591 | See the Unicode Technical Report #21, Case Mappings, for more details. |
ac1256e8 |
592 | |
593 | =item * |
594 | |
393fec97 |
595 | And finally, C<scalar reverse()> reverses by character rather than by byte. |
596 | |
597 | =back |
598 | |
8cbd9a7a |
599 | =head2 Character encodings for input and output |
600 | |
7221edc9 |
601 | See L<Encode>. |
8cbd9a7a |
602 | |
393fec97 |
603 | =head1 CAVEATS |
604 | |
605 | As of yet, there is no method for automatically coercing input and |
b3419ed8 |
606 | output to some encoding other than UTF-8 or UTF-EBCDIC. This is planned |
607 | in the near future, however. |
393fec97 |
608 | |
8cbd9a7a |
609 | Whether an arbitrary piece of data will be treated as "characters" or |
610 | "bytes" by internal operations cannot be divined at the current time. |
393fec97 |
611 | |
612 | Use of locales with utf8 may lead to odd results. Currently there is |
613 | some attempt to apply 8-bit locale info to characters in the range |
614 | 0..255, but this is demonstrably incorrect for locales that use |
615 | characters above that range (when mapped into Unicode). It will also |
616 | tend to run slower. Avoidance of locales is strongly encouraged. |
617 | |
776f8809 |
618 | =head1 UNICODE REGULAR EXPRESSION SUPPORT LEVEL |
619 | |
620 | The following list of Unicode regular expression support describes |
621 | feature by feature the Unicode support implemented in Perl as of Perl |
622 | 5.8.0. The "Level N" and the section numbers refer to the Unicode |
623 | Technical Report 18, "Unicode Regular Expression Guidelines". |
624 | |
625 | =over 4 |
626 | |
627 | =item * |
628 | |
629 | Level 1 - Basic Unicode Support |
630 | |
631 | 2.1 Hex Notation - done [1] |
632 | Named Notation - done [2] |
633 | 2.2 Categories - done [3][4] |
634 | 2.3 Subtraction - MISSING [5][6] |
635 | 2.4 Simple Word Boundaries - done [7] |
636 | 2.5 Simple Loose Matches - MISSING [8] |
637 | 2.6 End of Line - MISSING [9][10] |
638 | |
639 | [ 1] \x{...} |
640 | [ 2] \N{...} |
641 | [ 3] . \p{Is...} \P{Is...} |
642 | [ 4] now scripts (see UTR#24 Script Names) in addition to blocks |
643 | [ 5] have negation |
644 | [ 6] can use look-ahead to emulate subtracion |
645 | [ 7] include Letters in word characters |
646 | [ 8] see UTR#21 Case Mappings |
647 | [ 9] see UTR#13 Unicode Newline Guidelines |
648 | [10] should do ^ and $ also on \x{2028} and \x{2029} |
649 | |
650 | =item * |
651 | |
652 | Level 2 - Extended Unicode Support |
653 | |
654 | 3.1 Surrogates - MISSING |
655 | 3.2 Canonical Equivalents - MISSING [11][12] |
656 | 3.3 Locale-Independent Graphemes - MISSING [13] |
657 | 3.4 Locale-Independent Words - MISSING [14] |
658 | 3.5 Locale-Independent Loose Matches - MISSING [15] |
659 | |
660 | [11] see UTR#15 Unicode Normalization |
661 | [12] have Unicode::Normalize but not integrated to regexes |
662 | [13] have \X but at this level . should equal that |
663 | [14] need three classes, not just \w and \W |
664 | [15] see UTR#21 Case Mappings |
665 | |
666 | =item * |
667 | |
668 | Level 3 - Locale-Sensitive Support |
669 | |
670 | 4.1 Locale-Dependent Categories - MISSING |
671 | 4.2 Locale-Dependent Graphemes - MISSING [16][17] |
672 | 4.3 Locale-Dependent Words - MISSING |
673 | 4.4 Locale-Dependent Loose Matches - MISSING |
674 | 4.5 Locale-Dependent Ranges - MISSING |
675 | |
676 | [16] see UTR#10 Unicode Collation Algorithms |
677 | [17] have Unicode::Collate but not integrated to regexes |
678 | |
679 | =back |
680 | |
393fec97 |
681 | =head1 SEE ALSO |
682 | |
32293815 |
683 | L<bytes>, L<utf8>, L<perlretut>, L<perlvar/"${^WIDE_SYSTEM_CALLS}"> |
393fec97 |
684 | |
685 | =cut |