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