1Unicode::UCD(3pm) Perl Programmers Reference Guide Unicode::UCD(3pm)
2
3
4
6 Unicode::UCD - Unicode character database
7
9 use Unicode::UCD 'charinfo';
10 my $charinfo = charinfo($codepoint);
11
12 use Unicode::UCD 'casefold';
13 my $casefold = casefold(0xFB00);
14
15 use Unicode::UCD 'casespec';
16 my $casespec = casespec(0xFB00);
17
18 use Unicode::UCD 'charblock';
19 my $charblock = charblock($codepoint);
20
21 use Unicode::UCD 'charscript';
22 my $charscript = charscript($codepoint);
23
24 use Unicode::UCD 'charblocks';
25 my $charblocks = charblocks();
26
27 use Unicode::UCD 'charscripts';
28 my $charscripts = charscripts();
29
30 use Unicode::UCD qw(charscript charinrange);
31 my $range = charscript($script);
32 print "looks like $script\n" if charinrange($range, $codepoint);
33
34 use Unicode::UCD qw(general_categories bidi_types);
35 my $categories = general_categories();
36 my $types = bidi_types();
37
38 use Unicode::UCD 'prop_aliases';
39 my @space_names = prop_aliases("space");
40
41 use Unicode::UCD 'prop_value_aliases';
42 my @gc_punct_names = prop_value_aliases("Gc", "Punct");
43
44 use Unicode::UCD 'prop_invlist';
45 my @puncts = prop_invlist("gc=punctuation");
46
47 use Unicode::UCD 'prop_invmap';
48 my ($list_ref, $map_ref, $format, $missing)
49 = prop_invmap("General Category");
50
51 use Unicode::UCD 'compexcl';
52 my $compexcl = compexcl($codepoint);
53
54 use Unicode::UCD 'namedseq';
55 my $namedseq = namedseq($named_sequence_name);
56
57 my $unicode_version = Unicode::UCD::UnicodeVersion();
58
59 my $convert_to_numeric =
60 Unicode::UCD::num("\N{RUMI DIGIT ONE}\N{RUMI DIGIT TWO}");
61
63 The Unicode::UCD module offers a series of functions that provide a
64 simple interface to the Unicode Character Database.
65
66 code point argument
67 Some of the functions are called with a code point argument, which is
68 either a decimal or a hexadecimal scalar designating a Unicode code
69 point, or "U+" followed by hexadecimals designating a Unicode code
70 point. In other words, if you want a code point to be interpreted as a
71 hexadecimal number, you must prefix it with either "0x" or "U+",
72 because a string like e.g. 123 will be interpreted as a decimal code
73 point. Note that the largest code point in Unicode is U+10FFFF.
74
75 charinfo()
76 use Unicode::UCD 'charinfo';
77
78 my $charinfo = charinfo(0x41);
79
80 This returns information about the input "code point argument" as a
81 reference to a hash of fields as defined by the Unicode standard. If
82 the "code point argument" is not assigned in the standard (i.e., has
83 the general category "Cn" meaning "Unassigned") or is a non-character
84 (meaning it is guaranteed to never be assigned in the standard),
85 "undef" is returned.
86
87 Fields that aren't applicable to the particular code point argument
88 exist in the returned hash, and are empty.
89
90 The keys in the hash with the meanings of their values are:
91
92 code
93 the input "code point argument" expressed in hexadecimal, with
94 leading zeros added if necessary to make it contain at least four
95 hexdigits
96
97 name
98 name of code, all IN UPPER CASE. Some control-type code points do
99 not have names. This field will be empty for "Surrogate" and
100 "Private Use" code points, and for the others without a name, it
101 will contain a description enclosed in angle brackets, like
102 "<control>".
103
104 category
105 The short name of the general category of code. This will match
106 one of the keys in the hash returned by "general_categories()".
107
108 The "prop_value_aliases()" function can be used to get all the
109 synonyms of the category name.
110
111 combining
112 the combining class number for code used in the Canonical Ordering
113 Algorithm. For Unicode 5.1, this is described in Section 3.11
114 "Canonical Ordering Behavior" available at
115 <http://www.unicode.org/versions/Unicode5.1.0/>
116
117 The "prop_value_aliases()" function can be used to get all the
118 synonyms of the combining class number.
119
120 bidi
121 bidirectional type of code. This will match one of the keys in the
122 hash returned by "bidi_types()".
123
124 The "prop_value_aliases()" function can be used to get all the
125 synonyms of the bidi type name.
126
127 decomposition
128 is empty if code has no decomposition; or is one or more codes
129 (separated by spaces) that, taken in order, represent a
130 decomposition for code. Each has at least four hexdigits. The
131 codes may be preceded by a word enclosed in angle brackets then a
132 space, like "<compat> ", giving the type of decomposition
133
134 This decomposition may be an intermediate one whose components are
135 also decomposable. Use Unicode::Normalize to get the final
136 decomposition.
137
138 decimal
139 if code is a decimal digit this is its integer numeric value
140
141 digit
142 if code represents some other digit-like number, this is its
143 integer numeric value
144
145 numeric
146 if code represents a whole or rational number, this is its numeric
147 value. Rational values are expressed as a string like "1/4".
148
149 mirrored
150 "Y" or "N" designating if code is mirrored in bidirectional text
151
152 unicode10
153 name of code in the Unicode 1.0 standard if one existed for this
154 code point and is different from the current name
155
156 comment
157 As of Unicode 6.0, this is always empty.
158
159 upper
160 is empty if there is no single code point uppercase mapping for
161 code (its uppercase mapping is itself); otherwise it is that
162 mapping expressed as at least four hexdigits. ("casespec()" should
163 be used in addition to charinfo() for case mappings when the
164 calling program can cope with multiple code point mappings.)
165
166 lower
167 is empty if there is no single code point lowercase mapping for
168 code (its lowercase mapping is itself); otherwise it is that
169 mapping expressed as at least four hexdigits. ("casespec()" should
170 be used in addition to charinfo() for case mappings when the
171 calling program can cope with multiple code point mappings.)
172
173 title
174 is empty if there is no single code point titlecase mapping for
175 code (its titlecase mapping is itself); otherwise it is that
176 mapping expressed as at least four hexdigits. ("casespec()" should
177 be used in addition to charinfo() for case mappings when the
178 calling program can cope with multiple code point mappings.)
179
180 block
181 the block code belongs to (used in "\p{Blk=...}"). See "Blocks
182 versus Scripts".
183
184 script
185 the script code belongs to. See "Blocks versus Scripts".
186
187 Note that you cannot do (de)composition and casing based solely on the
188 decomposition, combining, lower, upper, and title fields; you will need
189 also the "compexcl()", and "casespec()" functions.
190
191 charblock()
192 use Unicode::UCD 'charblock';
193
194 my $charblock = charblock(0x41);
195 my $charblock = charblock(1234);
196 my $charblock = charblock(0x263a);
197 my $charblock = charblock("U+263a");
198
199 my $range = charblock('Armenian');
200
201 With a "code point argument" charblock() returns the block the code
202 point belongs to, e.g. "Basic Latin". The old-style block name is
203 returned (see "Old-style versus new-style block names"). If the code
204 point is unassigned, this returns the block it would belong to if it
205 were assigned.
206
207 See also "Blocks versus Scripts".
208
209 If supplied with an argument that can't be a code point, charblock()
210 tries to do the opposite and interpret the argument as an old-style
211 block name. The return value is a range set with one range: an
212 anonymous list with a single element that consists of another anonymous
213 list whose first element is the first code point in the block, and
214 whose second (and final) element is the final code point in the block.
215 (The extra list consisting of just one element is so that the same
216 program logic can be used to handle both this return, and the return
217 from "charscript()" which can have multiple ranges.) You can test
218 whether a code point is in a range using the "charinrange()" function.
219 If the argument is not a known block, "undef" is returned.
220
221 charscript()
222 use Unicode::UCD 'charscript';
223
224 my $charscript = charscript(0x41);
225 my $charscript = charscript(1234);
226 my $charscript = charscript("U+263a");
227
228 my $range = charscript('Thai');
229
230 With a "code point argument" charscript() returns the script the code
231 point belongs to, e.g. "Latin", "Greek", "Han". If the code point is
232 unassigned, it returns "Unknown".
233
234 If supplied with an argument that can't be a code point, charscript()
235 tries to do the opposite and interpret the argument as a script name.
236 The return value is a range set: an anonymous list of lists that
237 contain start-of-range, end-of-range code point pairs. You can test
238 whether a code point is in a range set using the "charinrange()"
239 function. If the argument is not a known script, "undef" is returned.
240
241 See also "Blocks versus Scripts".
242
243 charblocks()
244 use Unicode::UCD 'charblocks';
245
246 my $charblocks = charblocks();
247
248 charblocks() returns a reference to a hash with the known block names
249 as the keys, and the code point ranges (see "charblock()") as the
250 values.
251
252 The names are in the old-style (see "Old-style versus new-style block
253 names").
254
255 prop_invmap("block") can be used to get this same data in a different
256 type of data structure.
257
258 See also "Blocks versus Scripts".
259
260 charscripts()
261 use Unicode::UCD 'charscripts';
262
263 my $charscripts = charscripts();
264
265 charscripts() returns a reference to a hash with the known script names
266 as the keys, and the code point ranges (see "charscript()") as the
267 values.
268
269 prop_invmap("script") can be used to get this same data in a different
270 type of data structure.
271
272 See also "Blocks versus Scripts".
273
274 charinrange()
275 In addition to using the "\p{Blk=...}" and "\P{Blk=...}" constructs,
276 you can also test whether a code point is in the range as returned by
277 "charblock()" and "charscript()" or as the values of the hash returned
278 by "charblocks()" and "charscripts()" by using charinrange():
279
280 use Unicode::UCD qw(charscript charinrange);
281
282 $range = charscript('Hiragana');
283 print "looks like hiragana\n" if charinrange($range, $codepoint);
284
285 general_categories()
286 use Unicode::UCD 'general_categories';
287
288 my $categories = general_categories();
289
290 This returns a reference to a hash which has short general category
291 names (such as "Lu", "Nd", "Zs", "S") as keys and long names (such as
292 "UppercaseLetter", "DecimalNumber", "SpaceSeparator", "Symbol") as
293 values. The hash is reversible in case you need to go from the long
294 names to the short names. The general category is the one returned
295 from "charinfo()" under the "category" key.
296
297 The "prop_value_aliases()" function can be used to get all the synonyms
298 of the category name.
299
300 bidi_types()
301 use Unicode::UCD 'bidi_types';
302
303 my $categories = bidi_types();
304
305 This returns a reference to a hash which has the short bidi
306 (bidirectional) type names (such as "L", "R") as keys and long names
307 (such as "Left-to-Right", "Right-to-Left") as values. The hash is
308 reversible in case you need to go from the long names to the short
309 names. The bidi type is the one returned from "charinfo()" under the
310 "bidi" key. For the exact meaning of the various bidi classes the
311 Unicode TR9 is recommended reading:
312 <http://www.unicode.org/reports/tr9/> (as of Unicode 5.0.0)
313
314 The "prop_value_aliases()" function can be used to get all the synonyms
315 of the bidi type name.
316
317 compexcl()
318 use Unicode::UCD 'compexcl';
319
320 my $compexcl = compexcl(0x09dc);
321
322 This routine is included for backwards compatibility, but as of Perl
323 5.12, for most purposes it is probably more convenient to use one of
324 the following instead:
325
326 my $compexcl = chr(0x09dc) =~ /\p{Comp_Ex};
327 my $compexcl = chr(0x09dc) =~ /\p{Full_Composition_Exclusion};
328
329 or even
330
331 my $compexcl = chr(0x09dc) =~ /\p{CE};
332 my $compexcl = chr(0x09dc) =~ /\p{Composition_Exclusion};
333
334 The first two forms return true if the "code point argument" should not
335 be produced by composition normalization. For the final two forms to
336 return true, it is additionally required that this fact not otherwise
337 be determinable from the Unicode data base.
338
339 This routine behaves identically to the final two forms. That is, it
340 does not return true if the code point has a decomposition consisting
341 of another single code point, nor if its decomposition starts with a
342 code point whose combining class is non-zero. Code points that meet
343 either of these conditions should also not be produced by composition
344 normalization, which is probably why you should use the
345 "Full_Composition_Exclusion" property instead, as shown above.
346
347 The routine returns false otherwise.
348
349 casefold()
350 use Unicode::UCD 'casefold';
351
352 my $casefold = casefold(0xDF);
353 if (defined $casefold) {
354 my @full_fold_hex = split / /, $casefold->{'full'};
355 my $full_fold_string =
356 join "", map {chr(hex($_))} @full_fold_hex;
357 my @turkic_fold_hex =
358 split / /, ($casefold->{'turkic'} ne "")
359 ? $casefold->{'turkic'}
360 : $casefold->{'full'};
361 my $turkic_fold_string =
362 join "", map {chr(hex($_))} @turkic_fold_hex;
363 }
364 if (defined $casefold && $casefold->{'simple'} ne "") {
365 my $simple_fold_hex = $casefold->{'simple'};
366 my $simple_fold_string = chr(hex($simple_fold_hex));
367 }
368
369 This returns the (almost) locale-independent case folding of the
370 character specified by the "code point argument". (Starting in Perl
371 v5.16, the core function "fc()" returns the "full" mapping (described
372 below) faster than this does, and for entire strings.)
373
374 If there is no case folding for the input code point, "undef" is
375 returned.
376
377 If there is a case folding for that code point, a reference to a hash
378 with the following fields is returned:
379
380 code
381 the input "code point argument" expressed in hexadecimal, with
382 leading zeros added if necessary to make it contain at least four
383 hexdigits
384
385 full
386 one or more codes (separated by spaces) that, taken in order, give
387 the code points for the case folding for code. Each has at least
388 four hexdigits.
389
390 simple
391 is empty, or is exactly one code with at least four hexdigits which
392 can be used as an alternative case folding when the calling program
393 cannot cope with the fold being a sequence of multiple code points.
394 If full is just one code point, then simple equals full. If there
395 is no single code point folding defined for code, then simple is
396 the empty string. Otherwise, it is an inferior, but still better-
397 than-nothing alternative folding to full.
398
399 mapping
400 is the same as simple if simple is not empty, and it is the same as
401 full otherwise. It can be considered to be the simplest possible
402 folding for code. It is defined primarily for backwards
403 compatibility.
404
405 status
406 is "C" (for "common") if the best possible fold is a single code
407 point (simple equals full equals mapping). It is "S" if there are
408 distinct folds, simple and full (mapping equals simple). And it is
409 "F" if there is only a full fold (mapping equals full; simple is
410 empty). Note that this describes the contents of mapping. It is
411 defined primarily for backwards compatibility.
412
413 For Unicode versions between 3.1 and 3.1.1 inclusive, status can
414 also be "I" which is the same as "C" but is a special case for
415 dotted uppercase I and dotless lowercase i:
416
417 * If you use this "I" mapping
418 the result is case-insensitive, but dotless and dotted I's are
419 not distinguished
420
421 * If you exclude this "I" mapping
422 the result is not fully case-insensitive, but dotless and
423 dotted I's are distinguished
424
425 turkic
426 contains any special folding for Turkic languages. For versions of
427 Unicode starting with 3.2, this field is empty unless code has a
428 different folding in Turkic languages, in which case it is one or
429 more codes (separated by spaces) that, taken in order, give the
430 code points for the case folding for code in those languages. Each
431 code has at least four hexdigits. Note that this folding does not
432 maintain canonical equivalence without additional processing.
433
434 For Unicode versions between 3.1 and 3.1.1 inclusive, this field is
435 empty unless there is a special folding for Turkic languages, in
436 which case status is "I", and mapping, full, simple, and turkic are
437 all equal.
438
439 Programs that want complete generality and the best folding results
440 should use the folding contained in the full field. But note that the
441 fold for some code points will be a sequence of multiple code points.
442
443 Programs that can't cope with the fold mapping being multiple code
444 points can use the folding contained in the simple field, with the loss
445 of some generality. In Unicode 5.1, about 7% of the defined foldings
446 have no single code point folding.
447
448 The mapping and status fields are provided for backwards compatibility
449 for existing programs. They contain the same values as in previous
450 versions of this function.
451
452 Locale is not completely independent. The turkic field contains
453 results to use when the locale is a Turkic language.
454
455 For more information about case mappings see
456 <http://www.unicode.org/unicode/reports/tr21>
457
458 casespec()
459 use Unicode::UCD 'casespec';
460
461 my $casespec = casespec(0xFB00);
462
463 This returns the potentially locale-dependent case mappings of the
464 "code point argument". The mappings may be longer than a single code
465 point (which the basic Unicode case mappings as returned by
466 "charinfo()" never are).
467
468 If there are no case mappings for the "code point argument", or if all
469 three possible mappings (lower, title and upper) result in single code
470 points and are locale independent and unconditional, "undef" is
471 returned (which means that the case mappings, if any, for the code
472 point are those returned by "charinfo()").
473
474 Otherwise, a reference to a hash giving the mappings (or a reference to
475 a hash of such hashes, explained below) is returned with the following
476 keys and their meanings:
477
478 The keys in the bottom layer hash with the meanings of their values
479 are:
480
481 code
482 the input "code point argument" expressed in hexadecimal, with
483 leading zeros added if necessary to make it contain at least four
484 hexdigits
485
486 lower
487 one or more codes (separated by spaces) that, taken in order, give
488 the code points for the lower case of code. Each has at least four
489 hexdigits.
490
491 title
492 one or more codes (separated by spaces) that, taken in order, give
493 the code points for the title case of code. Each has at least four
494 hexdigits.
495
496 upper
497 one or more codes (separated by spaces) that, taken in order, give
498 the code points for the upper case of code. Each has at least four
499 hexdigits.
500
501 condition
502 the conditions for the mappings to be valid. If "undef", the
503 mappings are always valid. When defined, this field is a list of
504 conditions, all of which must be true for the mappings to be valid.
505 The list consists of one or more locales (see below) and/or
506 contexts (explained in the next paragraph), separated by spaces.
507 (Other than as used to separate elements, spaces are to be
508 ignored.) Case distinctions in the condition list are not
509 significant. Conditions preceded by "NON_" represent the negation
510 of the condition.
511
512 A context is one of those defined in the Unicode standard. For
513 Unicode 5.1, they are defined in Section 3.13 "Default Case
514 Operations" available at
515 <http://www.unicode.org/versions/Unicode5.1.0/>. These are for
516 context-sensitive casing.
517
518 The hash described above is returned for locale-independent casing,
519 where at least one of the mappings has length longer than one. If
520 "undef" is returned, the code point may have mappings, but if so, all
521 are length one, and are returned by "charinfo()". Note that when this
522 function does return a value, it will be for the complete set of
523 mappings for a code point, even those whose length is one.
524
525 If there are additional casing rules that apply only in certain
526 locales, an additional key for each will be defined in the returned
527 hash. Each such key will be its locale name, defined as a 2-letter ISO
528 3166 country code, possibly followed by a "_" and a 2-letter ISO
529 language code (possibly followed by a "_" and a variant code). You can
530 find the lists of all possible locales, see Locale::Country and
531 Locale::Language. (In Unicode 6.0, the only locales returned by this
532 function are "lt", "tr", and "az".)
533
534 Each locale key is a reference to a hash that has the form above, and
535 gives the casing rules for that particular locale, which take
536 precedence over the locale-independent ones when in that locale.
537
538 If the only casing for a code point is locale-dependent, then the
539 returned hash will not have any of the base keys, like "code", "upper",
540 etc., but will contain only locale keys.
541
542 For more information about case mappings see
543 <http://www.unicode.org/unicode/reports/tr21/>
544
545 namedseq()
546 use Unicode::UCD 'namedseq';
547
548 my $namedseq = namedseq("KATAKANA LETTER AINU P");
549 my @namedseq = namedseq("KATAKANA LETTER AINU P");
550 my %namedseq = namedseq();
551
552 If used with a single argument in a scalar context, returns the string
553 consisting of the code points of the named sequence, or "undef" if no
554 named sequence by that name exists. If used with a single argument in
555 a list context, it returns the list of the ordinals of the code points.
556 If used with no arguments in a list context, returns a hash with the
557 names of the named sequences as the keys and the named sequences as
558 strings as the values. Otherwise, it returns "undef" or an empty list
559 depending on the context.
560
561 This function only operates on officially approved (not provisional)
562 named sequences.
563
564 Note that as of Perl 5.14, "\N{KATAKANA LETTER AINU P}" will insert the
565 named sequence into double-quoted strings, and
566 "charnames::string_vianame("KATAKANA LETTER AINU P")" will return the
567 same string this function does, but will also operate on character
568 names that aren't named sequences, without you having to know which are
569 which. See charnames.
570
571 num()
572 use Unicode::UCD 'num';
573
574 my $val = num("123");
575 my $one_quarter = num("\N{VULGAR FRACTION 1/4}");
576
577 "num" returns the numeric value of the input Unicode string; or "undef"
578 if it doesn't think the entire string has a completely valid, safe
579 numeric value.
580
581 If the string is just one character in length, the Unicode numeric
582 value is returned if it has one, or "undef" otherwise. Note that this
583 need not be a whole number. "num("\N{TIBETAN DIGIT HALF ZERO}")", for
584 example returns -0.5.
585
586 If the string is more than one character, "undef" is returned unless
587 all its characters are decimal digits (that is, they would match
588 "\d+"), from the same script. For example if you have an ASCII '0' and
589 a Bengali '3', mixed together, they aren't considered a valid number,
590 and "undef" is returned. A further restriction is that the digits all
591 have to be of the same form. A half-width digit mixed with a full-
592 width one will return "undef". The Arabic script has two sets of
593 digits; "num" will return "undef" unless all the digits in the string
594 come from the same set.
595
596 "num" errs on the side of safety, and there may be valid strings of
597 decimal digits that it doesn't recognize. Note that Unicode defines a
598 number of "digit" characters that aren't "decimal digit" characters.
599 "Decimal digits" have the property that they have a positional value,
600 i.e., there is a units position, a 10's position, a 100's, etc, AND
601 they are arranged in Unicode in blocks of 10 contiguous code points.
602 The Chinese digits, for example, are not in such a contiguous block,
603 and so Unicode doesn't view them as decimal digits, but merely digits,
604 and so "\d" will not match them. A single-character string containing
605 one of these digits will have its decimal value returned by "num", but
606 any longer string containing only these digits will return "undef".
607
608 Strings of multiple sub- and superscripts are not recognized as
609 numbers. You can use either of the compatibility decompositions in
610 Unicode::Normalize to change these into digits, and then call "num" on
611 the result.
612
613 prop_aliases()
614 use Unicode::UCD 'prop_aliases';
615
616 my ($short_name, $full_name, @other_names) = prop_aliases("space");
617 my $same_full_name = prop_aliases("Space"); # Scalar context
618 my ($same_short_name) = prop_aliases("Space"); # gets 0th element
619 print "The full name is $full_name\n";
620 print "The short name is $short_name\n";
621 print "The other aliases are: ", join(", ", @other_names), "\n";
622
623 prints:
624 The full name is White_Space
625 The short name is WSpace
626 The other aliases are: Space
627
628 Most Unicode properties have several synonymous names. Typically,
629 there is at least a short name, convenient to type, and a long name
630 that more fully describes the property, and hence is more easily
631 understood.
632
633 If you know one name for a Unicode property, you can use "prop_aliases"
634 to find either the long name (when called in scalar context), or a list
635 of all of the names, somewhat ordered so that the short name is in the
636 0th element, the long name in the next element, and any other synonyms
637 are in the remaining elements, in no particular order.
638
639 The long name is returned in a form nicely capitalized, suitable for
640 printing.
641
642 The input parameter name is loosely matched, which means that white
643 space, hyphens, and underscores are ignored (except for the trailing
644 underscore in the old_form grandfathered-in "L_", which is better
645 written as "LC", and both of which mean "General_Category=Cased
646 Letter").
647
648 If the name is unknown, "undef" is returned (or an empty list in list
649 context). Note that Perl typically recognizes property names in
650 regular expressions with an optional ""Is_"" (with or without the
651 underscore) prefixed to them, such as "\p{isgc=punct}". This function
652 does not recognize those in the input, returning "undef". Nor are they
653 included in the output as possible synonyms.
654
655 "prop_aliases" does know about the Perl extensions to Unicode
656 properties, such as "Any" and "XPosixAlpha", and the single form
657 equivalents to Unicode properties such as "XDigit", "Greek",
658 "In_Greek", and "Is_Greek". The final example demonstrates that the
659 "Is_" prefix is recognized for these extensions; it is needed to
660 resolve ambiguities. For example, "prop_aliases('lc')" returns the
661 list "(lc, Lowercase_Mapping)", but "prop_aliases('islc')" returns
662 "(Is_LC, Cased_Letter)". This is because "islc" is a Perl extension
663 which is short for "General_Category=Cased Letter". The lists returned
664 for the Perl extensions will not include the "Is_" prefix (whether or
665 not the input had it) unless needed to resolve ambiguities, as shown in
666 the "islc" example, where the returned list had one element containing
667 "Is_", and the other without.
668
669 It is also possible for the reverse to happen: "prop_aliases('isc')"
670 returns the list "(isc, ISO_Comment)"; whereas "prop_aliases('c')"
671 returns "(C, Other)" (the latter being a Perl extension meaning
672 "General_Category=Other". "Properties accessible through Unicode::UCD"
673 in perluniprops lists the available forms, including which ones are
674 discouraged from use.
675
676 Those discouraged forms are accepted as input to "prop_aliases", but
677 are not returned in the lists. "prop_aliases('isL&')" and
678 "prop_aliases('isL_')", which are old synonyms for "Is_LC" and should
679 not be used in new code, are examples of this. These both return
680 "(Is_LC, Cased_Letter)". Thus this function allows you to take a
681 discourarged form, and find its acceptable alternatives. The same goes
682 with single-form Block property equivalences. Only the forms that
683 begin with "In_" are not discouraged; if you pass "prop_aliases" a
684 discouraged form, you will get back the equivalent ones that begin with
685 "In_". It will otherwise look like a new-style block name (see. "Old-
686 style versus new-style block names").
687
688 "prop_aliases" does not know about any user-defined properties, and
689 will return "undef" if called with one of those. Likewise for Perl
690 internal properties, with the exception of "Perl_Decimal_Digit" which
691 it does know about (and which is documented below in "prop_invmap()").
692
693 prop_value_aliases()
694 use Unicode::UCD 'prop_value_aliases';
695
696 my ($short_name, $full_name, @other_names)
697 = prop_value_aliases("Gc", "Punct");
698 my $same_full_name = prop_value_aliases("Gc", "P"); # Scalar cntxt
699 my ($same_short_name) = prop_value_aliases("Gc", "P"); # gets 0th
700 # element
701 print "The full name is $full_name\n";
702 print "The short name is $short_name\n";
703 print "The other aliases are: ", join(", ", @other_names), "\n";
704
705 prints:
706 The full name is Punctuation
707 The short name is P
708 The other aliases are: Punct
709
710 Some Unicode properties have a restricted set of legal values. For
711 example, all binary properties are restricted to just "true" or
712 "false"; and there are only a few dozen possible General Categories.
713
714 For such properties, there are usually several synonyms for each
715 possible value. For example, in binary properties, truth can be
716 represented by any of the strings "Y", "Yes", "T", or "True"; and the
717 General Category "Punctuation" by that string, or "Punct", or simply
718 "P".
719
720 Like property names, there is typically at least a short name for each
721 such property-value, and a long name. If you know any name of the
722 property-value, you can use "prop_value_aliases"() to get the long name
723 (when called in scalar context), or a list of all the names, with the
724 short name in the 0th element, the long name in the next element, and
725 any other synonyms in the remaining elements, in no particular order,
726 except that any all-numeric synonyms will be last.
727
728 The long name is returned in a form nicely capitalized, suitable for
729 printing.
730
731 Case, white space, hyphens, and underscores are ignored in the input
732 parameters (except for the trailing underscore in the old-form
733 grandfathered-in general category property value "L_", which is better
734 written as "LC").
735
736 If either name is unknown, "undef" is returned. Note that Perl
737 typically recognizes property names in regular expressions with an
738 optional ""Is_"" (with or without the underscore) prefixed to them,
739 such as "\p{isgc=punct}". This function does not recognize those in
740 the property parameter, returning "undef".
741
742 If called with a property that doesn't have synonyms for its values, it
743 returns the input value, possibly normalized with capitalization and
744 underscores.
745
746 For the block property, new-style block names are returned (see "Old-
747 style versus new-style block names").
748
749 To find the synonyms for single-forms, such as "\p{Any}", use
750 "prop_aliases()" instead.
751
752 "prop_value_aliases" does not know about any user-defined properties,
753 and will return "undef" if called with one of those.
754
755 prop_invlist()
756 "prop_invlist" returns an inversion list (described below) that defines
757 all the code points for the binary Unicode property (or
758 "property=value" pair) given by the input parameter string:
759
760 use feature 'say';
761 use Unicode::UCD 'prop_invlist';
762 say join ", ", prop_invlist("Any");
763
764 prints:
765 0, 1114112
766
767 An empty list is returned if the input is unknown; the number of
768 elements in the list is returned if called in scalar context.
769
770 perluniprops gives the list of properties that this function accepts,
771 as well as all the possible forms for them (including with the optional
772 "Is_" prefixes). (Except this function doesn't accept any Perl-
773 internal properties, some of which are listed there.) This function
774 uses the same loose or tighter matching rules for resolving the input
775 property's name as is done for regular expressions. These are also
776 specified in perluniprops. Examples of using the "property=value" form
777 are:
778
779 say join ", ", prop_invlist("Script=Shavian");
780
781 prints:
782 66640, 66688
783
784 say join ", ", prop_invlist("ASCII_Hex_Digit=No");
785
786 prints:
787 0, 48, 58, 65, 71, 97, 103
788
789 say join ", ", prop_invlist("ASCII_Hex_Digit=Yes");
790
791 prints:
792 48, 58, 65, 71, 97, 103
793
794 Inversion lists are a compact way of specifying Unicode property-value
795 definitions. The 0th item in the list is the lowest code point that
796 has the property-value. The next item (item [1]) is the lowest code
797 point beyond that one that does NOT have the property-value. And the
798 next item beyond that ([2]) is the lowest code point beyond that one
799 that does have the property-value, and so on. Put another way, each
800 element in the list gives the beginning of a range that has the
801 property-value (for even numbered elements), or doesn't have the
802 property-value (for odd numbered elements). The name for this data
803 structure stems from the fact that each element in the list toggles (or
804 inverts) whether the corresponding range is or isn't on the list.
805
806 In the final example above, the first ASCII Hex digit is code point 48,
807 the character "0", and all code points from it through 57 (a "9") are
808 ASCII hex digits. Code points 58 through 64 aren't, but 65 (an "A")
809 through 70 (an "F") are, as are 97 ("a") through 102 ("f"). 103 starts
810 a range of code points that aren't ASCII hex digits. That range
811 extends to infinity, which on your computer can be found in the
812 variable $Unicode::UCD::MAX_CP. (This variable is as close to infinity
813 as Perl can get on your platform, and may be too high for some
814 operations to work; you may wish to use a smaller number for your
815 purposes.)
816
817 Note that the inversion lists returned by this function can possibly
818 include non-Unicode code points, that is anything above 0x10FFFF. This
819 is in contrast to Perl regular expression matches on those code points,
820 in which a non-Unicode code point always fails to match. For example,
821 both of these have the same result:
822
823 chr(0x110000) =~ \p{ASCII_Hex_Digit=True} # Fails.
824 chr(0x110000) =~ \p{ASCII_Hex_Digit=False} # Fails!
825
826 And both raise a warning that a Unicode property is being used on a
827 non-Unicode code point. It is arguable as to which is the correct
828 thing to do here. This function has chosen the way opposite to the
829 Perl regular expression behavior. This allows you to easily flip to to
830 the Perl regular expression way (for you to go in the other direction
831 would be far harder). Simply add 0x110000 at the end of the non-empty
832 returned list if it isn't already that value; and pop that value if it
833 is; like:
834
835 my @list = prop_invlist("foo");
836 if (@list) {
837 if ($list[-1] == 0x110000) {
838 pop @list; # Defeat the turning on for above Unicode
839 }
840 else {
841 push @list, 0x110000; # Turn off for above Unicode
842 }
843 }
844
845 It is a simple matter to expand out an inversion list to a full list of
846 all code points that have the property-value:
847
848 my @invlist = prop_invlist($property_name);
849 die "empty" unless @invlist;
850 my @full_list;
851 for (my $i = 0; $i < @invlist; $i += 2) {
852 my $upper = ($i + 1) < @invlist
853 ? $invlist[$i+1] - 1 # In range
854 : $Unicode::UCD::MAX_CP; # To infinity. You may want
855 # to stop much much earlier;
856 # going this high may expose
857 # perl deficiencies with very
858 # large numbers.
859 for my $j ($invlist[$i] .. $upper) {
860 push @full_list, $j;
861 }
862 }
863
864 "prop_invlist" does not know about any user-defined nor Perl internal-
865 only properties, and will return "undef" if called with one of those.
866
867 prop_invmap()
868 use Unicode::UCD 'prop_invmap';
869 my ($list_ref, $map_ref, $format, $missing)
870 = prop_invmap("General Category");
871
872 "prop_invmap" is used to get the complete mapping definition for a
873 property, in the form of an inversion map. An inversion map consists
874 of two parallel arrays. One is an ordered list of code points that
875 mark range beginnings, and the other gives the value (or mapping) that
876 all code points in the corresponding range have.
877
878 "prop_invmap" is called with the name of the desired property. The
879 name is loosely matched, meaning that differences in case, white-space,
880 hyphens, and underscores are not meaningful (except for the trailing
881 underscore in the old-form grandfathered-in property "L_", which is
882 better written as "LC", or even better, "Gc=LC").
883
884 Many Unicode properties have more than one name (or alias).
885 "prop_invmap" understands all of these, including Perl extensions to
886 them. Ambiguities are resolved as described above for
887 "prop_aliases()". The Perl internal property "Perl_Decimal_Digit,
888 described below, is also accepted. "undef" is returned if the property
889 name is unknown. See "Properties accessible through Unicode::UCD" in
890 perluniprops for the properties acceptable as inputs to this function.
891
892 It is a fatal error to call this function except in list context.
893
894 In addition to the the two arrays that form the inversion map,
895 "prop_invmap" returns two other values; one is a scalar that gives some
896 details as to the format of the entries of the map array; the other is
897 used for specialized purposes, described at the end of this section.
898
899 This means that "prop_invmap" returns a 4 element list. For example,
900
901 my ($blocks_ranges_ref, $blocks_maps_ref, $format, $default)
902 = prop_invmap("Block");
903
904 In this call, the two arrays will be populated as shown below (for
905 Unicode 6.0):
906
907 Index @blocks_ranges @blocks_maps
908 0 0x0000 Basic Latin
909 1 0x0080 Latin-1 Supplement
910 2 0x0100 Latin Extended-A
911 3 0x0180 Latin Extended-B
912 4 0x0250 IPA Extensions
913 5 0x02B0 Spacing Modifier Letters
914 6 0x0300 Combining Diacritical Marks
915 7 0x0370 Greek and Coptic
916 8 0x0400 Cyrillic
917 ...
918 233 0x2B820 No_Block
919 234 0x2F800 CJK Compatibility Ideographs Supplement
920 235 0x2FA20 No_Block
921 236 0xE0000 Tags
922 237 0xE0080 No_Block
923 238 0xE0100 Variation Selectors Supplement
924 239 0xE01F0 No_Block
925 240 0xF0000 Supplementary Private Use Area-A
926 241 0x100000 Supplementary Private Use Area-B
927 242 0x110000 No_Block
928
929 The first line (with Index [0]) means that the value for code point 0
930 is "Basic Latin". The entry "0x0080" in the @blocks_ranges column in
931 the second line means that the value from the first line, "Basic
932 Latin", extends to all code points in the range from 0 up to but not
933 including 0x0080, that is, through 127. In other words, the code
934 points from 0 to 127 are all in the "Basic Latin" block. Similarly,
935 all code points in the range from 0x0080 up to (but not including)
936 0x0100 are in the block named "Latin-1 Supplement", etc. (Notice that
937 the return is the old-style block names; see "Old-style versus new-
938 style block names").
939
940 The final line (with Index [242]) means that the value for all code
941 points above the legal Unicode maximum code point have the value
942 "No_Block", which is the term Unicode uses for a non-existing block.
943
944 The arrays completely specify the mappings for all possible code
945 points. The final element in an inversion map returned by this
946 function will always be for the range that consists of all the code
947 points that aren't legal Unicode, but that are expressible on the
948 platform. (That is, it starts with code point 0x110000, the first code
949 point above the legal Unicode maximum, and extends to infinity.) The
950 value for that range will be the same that any typical unassigned code
951 point has for the specified property. (Certain unassigned code points
952 are not "typical"; for example the non-character code points, or those
953 in blocks that are to be written right-to-left. The above-Unicode
954 range's value is not based on these atypical code points.) It could be
955 argued that, instead of treating these as unassigned Unicode code
956 points, the value for this range should be "undef". If you wish, you
957 can change the returned arrays accordingly.
958
959 The maps are almost always simple scalars that should be interpreted
960 as-is. These values are those given in the Unicode-supplied data
961 files, which may be inconsistent as to capitalization and as to which
962 synonym for a property-value is given. The results may be normalized
963 by using the "prop_value_aliases()" function.
964
965 There are exceptions to the simple scalar maps. Some properties have
966 some elements in their map list that are themselves lists of scalars;
967 and some special strings are returned that are not to be interpreted
968 as-is. Element [2] (placed into $format in the example above) of the
969 returned four element list tells you if the map has any of these
970 special elements or not, as follows:
971
972 "s" means all the elements of the map array are simple scalars, with no
973 special elements. Almost all properties are like this, like the
974 "block" example above.
975
976 "sl"
977 means that some of the map array elements have the form given by
978 "s", and the rest are lists of scalars. For example, here is a
979 portion of the output of calling "prop_invmap"() with the "Script
980 Extensions" property:
981
982 @scripts_ranges @scripts_maps
983 ...
984 0x0953 Devanagari
985 0x0964 [ Bengali, Devanagari, Gurumukhi, Oriya ]
986 0x0966 Devanagari
987 0x0970 Common
988
989 Here, the code points 0x964 and 0x965 are both used in Bengali,
990 Devanagari, Gurmukhi, and Oriya, but no other scripts.
991
992 The Name_Alias property is also of this form. But each scalar
993 consists of two components: 1) the name, and 2) the type of alias
994 this is. They are separated by a colon and a space. In Unicode
995 6.1, there are several alias types:
996
997 "correction"
998 indicates that the name is a corrected form for the original
999 name (which remains valid) for the same code point.
1000
1001 "control"
1002 adds a new name for a control character.
1003
1004 "alternate"
1005 is an alternate name for a character
1006
1007 "figment"
1008 is a name for a character that has been documented but was
1009 never in any actual standard.
1010
1011 "abbreviation"
1012 is a common abbreviation for a character
1013
1014 The lists are ordered (roughly) so the most preferred names come
1015 before less preferred ones.
1016
1017 For example,
1018
1019 @aliases_ranges @alias_maps
1020 ...
1021 0x009E [ 'PRIVACY MESSAGE: control', 'PM: abbreviation' ]
1022 0x009F [ 'APPLICATION PROGRAM COMMAND: control',
1023 'APC: abbreviation'
1024 ]
1025 0x00A0 'NBSP: abbreviation'
1026 0x00A1 ""
1027 0x00AD 'SHY: abbreviation'
1028 0x00AE ""
1029 0x01A2 'LATIN CAPITAL LETTER GHA: correction'
1030 0x01A3 'LATIN SMALL LETTER GHA: correction'
1031 0x01A4 ""
1032 ...
1033
1034 A map to the empty string means that there is no alias defined for
1035 the code point.
1036
1037 "a" is like "s" in that all the map array elements are scalars, but
1038 here they are restricted to all being integers, and some have to be
1039 adjusted (hence the name "a") to get the correct result. For
1040 example, in:
1041
1042 my ($uppers_ranges_ref, $uppers_maps_ref, $format)
1043 = prop_invmap("Simple_Uppercase_Mapping");
1044
1045 the returned arrays look like this:
1046
1047 @$uppers_ranges_ref @$uppers_maps_ref Note
1048 0 0
1049 97 65 'a' maps to 'A', b => B ...
1050 123 0
1051 181 924 MICRO SIGN => Greek Cap MU
1052 182 0
1053 ...
1054
1055 Let's start with the second line. It says that the uppercase of
1056 code point 97 is 65; or "uc("a")" == "A". But the line is for the
1057 entire range of code points 97 through 122. To get the mapping for
1058 any code point in a range, you take the offset it has from the
1059 beginning code point of the range, and add that to the mapping for
1060 that first code point. So, the mapping for 122 ("z") is derived by
1061 taking the offset of 122 from 97 (=25) and adding that to 65,
1062 yielding 90 ("z"). Likewise for everything in between.
1063
1064 The first line works the same way. The first map in a range is
1065 always the correct value for its code point (because the adjustment
1066 is 0). Thus the "uc(chr(0))" is just itself. Also, "uc(chr(1))"
1067 is also itself, as the adjustment is 0+1-0 .. "uc(chr(96))" is 96.
1068
1069 Requiring this simple adjustment allows the returned arrays to be
1070 significantly smaller than otherwise, up to a factor of 10,
1071 speeding up searching through them.
1072
1073 "al"
1074 means that some of the map array elements have the form given by
1075 "a", and the rest are ordered lists of code points. For example,
1076 in:
1077
1078 my ($uppers_ranges_ref, $uppers_maps_ref, $format)
1079 = prop_invmap("Uppercase_Mapping");
1080
1081 the returned arrays look like this:
1082
1083 @$uppers_ranges_ref @$uppers_maps_ref
1084 0 0
1085 97 65
1086 123 0
1087 181 924
1088 182 0
1089 ...
1090 0x0149 [ 0x02BC 0x004E ]
1091 0x014A 0
1092 0x014B 330
1093 ...
1094
1095 This is the full Uppercase_Mapping property (as opposed to the
1096 Simple_Uppercase_Mapping given in the example for format "a"). The
1097 only difference between the two in the ranges shown is that the
1098 code point at 0x0149 (LATIN SMALL LETTER N PRECEDED BY APOSTROPHE)
1099 maps to a string of two characters, 0x02BC (MODIFIER LETTER
1100 APOSTROPHE) followed by 0x004E (LATIN CAPITAL LETTER N).
1101
1102 No adjustments are needed to entries that are references to arrays;
1103 each such entry will have exactly one element in its range, so the
1104 offset is always 0.
1105
1106 "ae"
1107 This is like "a", but some elements are the empty string, and
1108 should not be adjusted. The one internal Perl property accessible
1109 by "prop_invmap" is of this type: "Perl_Decimal_Digit" returns an
1110 inversion map which gives the numeric values that are represented
1111 by the Unicode decimal digit characters. Characters that don't
1112 represent decimal digits map to the empty string, like so:
1113
1114 @digits @values
1115 0x0000 ""
1116 0x0030 0
1117 0x003A: ""
1118 0x0660: 0
1119 0x066A: ""
1120 0x06F0: 0
1121 0x06FA: ""
1122 0x07C0: 0
1123 0x07CA: ""
1124 0x0966: 0
1125 ...
1126
1127 This means that the code points from 0 to 0x2F do not represent
1128 decimal digits; the code point 0x30 (DIGIT ZERO) represents 0;
1129 code point 0x31, (DIGIT ONE), represents 0+1-0 = 1; ... code point
1130 0x39, (DIGIT NINE), represents 0+9-0 = 9; ... code points 0x3A
1131 through 0x65F do not represent decimal digits; 0x660 (ARABIC-INDIC
1132 DIGIT ZERO), represents 0; ... 0x07C1 (NKO DIGIT ONE), represents
1133 0+1-0 = 1 ...
1134
1135 "ale"
1136 is a combination of the "al" type and the "ae" type. Some of the
1137 map array elements have the forms given by "al", and the rest are
1138 the empty string. The property "NFKC_Casefold" has this form. An
1139 example slice is:
1140
1141 @$ranges_ref @$maps_ref Note
1142 ...
1143 0x00AA 97 FEMININE ORDINAL INDICATOR => 'a'
1144 0x00AB 0
1145 0x00AD SOFT HYPHEN => ""
1146 0x00AE 0
1147 0x00AF [ 0x0020, 0x0304 ] MACRON => SPACE . COMBINING MACRON
1148 0x00B0 0
1149 ...
1150
1151 "ar"
1152 means that all the elements of the map array are either rational
1153 numbers or the string "NaN", meaning "Not a Number". A rational
1154 number is either an integer, or two integers separated by a solidus
1155 ("/"). The second integer represents the denominator of the
1156 division implied by the solidus, and is actually always positive,
1157 so it is guaranteed not to be 0 and to not to be signed. When the
1158 element is a plain integer (without the solidus), it may need to be
1159 adjusted to get the correct value by adding the offset, just as
1160 other "a" properties. No adjustment is needed for fractions, as
1161 the range is guaranteed to have just a single element, and so the
1162 offset is always 0.
1163
1164 If you want to convert the returned map to entirely scalar numbers,
1165 you can use something like this:
1166
1167 my ($invlist_ref, $invmap_ref, $format) = prop_invmap($property);
1168 if ($format && $format eq "ar") {
1169 map { $_ = eval $_ } @$invmap_ref;
1170 }
1171
1172 Here's some entries from the output of the property "Nv", which has
1173 format "ar".
1174
1175 @numerics_ranges @numerics_maps Note
1176 0x00 "NaN"
1177 0x30 0 DIGIT 0 .. DIGIT 9
1178 0x3A "NaN"
1179 0xB2 2 SUPERSCRIPTs 2 and 3
1180 0xB4 "NaN"
1181 0xB9 1 SUPERSCRIPT 1
1182 0xBA "NaN"
1183 0xBC 1/4 VULGAR FRACTION 1/4
1184 0xBD 1/2 VULGAR FRACTION 1/2
1185 0xBE 3/4 VULGAR FRACTION 3/4
1186 0xBF "NaN"
1187 0x660 0 ARABIC-INDIC DIGIT ZERO .. NINE
1188 0x66A "NaN"
1189
1190 "n" means the Name property. All the elements of the map array are
1191 simple scalars, but some of them contain special strings that
1192 require more work to get the actual name.
1193
1194 Entries such as:
1195
1196 CJK UNIFIED IDEOGRAPH-<code point>
1197
1198 mean that the name for the code point is "CJK UNIFIED IDEOGRAPH-"
1199 with the code point (expressed in hexadecimal) appended to it, like
1200 "CJK UNIFIED IDEOGRAPH-3403" (similarly for
1201 "CJK COMPATIBILITY IDEOGRAPH-<code point>").
1202
1203 Also, entries like
1204
1205 <hangul syllable>
1206
1207 means that the name is algorithmically calculated. This is easily
1208 done by the function "charnames::viacode(code)" in charnames.
1209
1210 Note that for control characters ("Gc=cc"), Unicode's data files
1211 have the string ""<control>"", but the real name of each of these
1212 characters is the empty string. This function returns that real
1213 name, the empty string. (There are names for these characters, but
1214 they are considered aliases, not the Name property name, and are
1215 contained in the "Name_Alias" property.)
1216
1217 "ad"
1218 means the Decomposition_Mapping property. This property is like
1219 "al" properties, except that one of the scalar elements is of the
1220 form:
1221
1222 <hangul syllable>
1223
1224 This signifies that this entry should be replaced by the
1225 decompositions for all the code points whose decomposition is
1226 algorithmically calculated. (All of them are currently in one
1227 range and no others outisde the range are likely to ever be added
1228 to Unicode; the "n" format has this same entry.) These can be
1229 generated via the function Unicode::Normalize::NFD().
1230
1231 Note that the mapping is the one that is specified in the Unicode
1232 data files, and to get the final decomposition, it may need to be
1233 applied recursively.
1234
1235 Note that a format begins with the letter "a" if and only the property
1236 it is for requires adjustments by adding the offsets in multi-element
1237 ranges. For all these properties, an entry should be adjusted only if
1238 the map is a scalar which is an integer. That is, it must match the
1239 regular expression:
1240
1241 / ^ -? \d+ $ /xa
1242
1243 Further, the first element in a range never needs adjustment, as the
1244 adjustment would be just adding 0.
1245
1246 A binary search can be used to quickly find a code point in the
1247 inversion list, and hence its corresponding mapping.
1248
1249 The final element (index [3], assigned to $default in the "block"
1250 example) in the four element list returned by this function may be
1251 useful for applications that wish to convert the returned inversion map
1252 data structure into some other, such as a hash. It gives the mapping
1253 that most code points map to under the property. If you establish the
1254 convention that any code point not explicitly listed in your data
1255 structure maps to this value, you can potentially make your data
1256 structure much smaller. As you construct your data structure from the
1257 one returned by this function, simply ignore those ranges that map to
1258 this value, generally called the "default" value. For example, to
1259 convert to the data structure searchable by "charinrange()", you can
1260 follow this recipe for properties that don't require adjustments:
1261
1262 my ($list_ref, $map_ref, $format, $missing) = prop_invmap($property);
1263 my @range_list;
1264
1265 # Look at each element in the list, but the -2 is needed because we
1266 # look at $i+1 in the loop, and the final element is guaranteed to map
1267 # to $missing by prop_invmap(), so we would skip it anyway.
1268 for my $i (0 .. @$list_ref - 2) {
1269 next if $map_ref->[$i] eq $missing;
1270 push @range_list, [ $list_ref->[$i],
1271 $list_ref->[$i+1],
1272 $map_ref->[$i]
1273 ];
1274 }
1275
1276 print charinrange(\@range_list, $code_point), "\n";
1277
1278 With this, "charinrange()" will return "undef" if its input code point
1279 maps to $missing. You can avoid this by omitting the "next" statement,
1280 and adding a line after the loop to handle the final element of the
1281 inversion map.
1282
1283 Similarly, this recipe can be used for properties that do require
1284 adjustments:
1285
1286 for my $i (0 .. @$list_ref - 2) {
1287 next if $map_ref->[$i] eq $missing;
1288
1289 # prop_invmap() guarantees that if the mapping is to an array, the
1290 # range has just one element, so no need to worry about adjustments.
1291 if (ref $map_ref->[$i]) {
1292 push @range_list,
1293 [ $list_ref->[$i], $list_ref->[$i], $map_ref->[$i] ];
1294 }
1295 else { # Otherwise each element is actually mapped to a separate
1296 # value, so the range has to be split into single code point
1297 # ranges.
1298
1299 my $adjustment = 0;
1300
1301 # For each code point that gets mapped to something...
1302 for my $j ($list_ref->[$i] .. $list_ref->[$i+1] -1 ) {
1303
1304 # ... add a range consisting of just it mapping to the
1305 # original plus the adjustment, which is incremented for the
1306 # next time through the loop, as the offset increases by 1
1307 # for each element in the range
1308 push @range_list,
1309 [ $j, $j, $map_ref->[$i] + $adjustment++ ];
1310 }
1311 }
1312 }
1313
1314 Note that the inversion maps returned for the "Case_Folding" and
1315 "Simple_Case_Folding" properties do not include the Turkic-locale
1316 mappings. Use "casefold()" for these.
1317
1318 "prop_invmap" does not know about any user-defined properties, and will
1319 return "undef" if called with one of those.
1320
1321 Unicode::UCD::UnicodeVersion
1322 This returns the version of the Unicode Character Database, in other
1323 words, the version of the Unicode standard the database implements.
1324 The version is a string of numbers delimited by dots ('.').
1325
1326 Blocks versus Scripts
1327 The difference between a block and a script is that scripts are closer
1328 to the linguistic notion of a set of code points required to present
1329 languages, while block is more of an artifact of the Unicode code point
1330 numbering and separation into blocks of (mostly) 256 code points.
1331
1332 For example the Latin script is spread over several blocks, such as
1333 "Basic Latin", "Latin 1 Supplement", "Latin Extended-A", and "Latin
1334 Extended-B". On the other hand, the Latin script does not contain all
1335 the characters of the "Basic Latin" block (also known as ASCII): it
1336 includes only the letters, and not, for example, the digits or the
1337 punctuation.
1338
1339 For blocks see <http://www.unicode.org/Public/UNIDATA/Blocks.txt>
1340
1341 For scripts see UTR #24: <http://www.unicode.org/unicode/reports/tr24/>
1342
1343 Matching Scripts and Blocks
1344 Scripts are matched with the regular-expression construct "\p{...}"
1345 (e.g. "\p{Tibetan}" matches characters of the Tibetan script), while
1346 "\p{Blk=...}" is used for blocks (e.g. "\p{Blk=Tibetan}" matches any of
1347 the 256 code points in the Tibetan block).
1348
1349 Old-style versus new-style block names
1350 Unicode publishes the names of blocks in two different styles, though
1351 the two are equivalent under Unicode's loose matching rules.
1352
1353 The original style uses blanks and hyphens in the block names (except
1354 for "No_Block"), like so:
1355
1356 Miscellaneous Mathematical Symbols-B
1357
1358 The newer style replaces these with underscores, like this:
1359
1360 Miscellaneous_Mathematical_Symbols_B
1361
1362 This newer style is consistent with the values of other Unicode
1363 properties. To preserve backward compatibility, all the functions in
1364 Unicode::UCD that return block names (except one) return the old-style
1365 ones. That one function, "prop_value_aliases()" can be used to convert
1366 from old-style to new-style:
1367
1368 my $new_style = prop_values_aliases("block", $old_style);
1369
1370 Perl also has single-form extensions that refer to blocks,
1371 "In_Cyrillic", meaning "Block=Cyrillic". These have always been
1372 written in the new style.
1373
1374 To convert from new-style to old-style, follow this recipe:
1375
1376 $old_style = charblock((prop_invlist("block=$new_style"))[0]);
1377
1378 (which finds the range of code points in the block using
1379 "prop_invlist", gets the lower end of the range (0th element) and then
1380 looks up the old name for its block using "charblock").
1381
1382 Note that starting in Unicode 6.1, many of the block names have shorter
1383 synonyms. These are always given in the new style.
1384
1386 Does not yet support EBCDIC platforms.
1387
1389 Jarkko Hietaniemi. Now maintained by perl5 porters.
1390
1391
1392
1393perl v5.16.3 2013-03-04 Unicode::UCD(3pm)