1Unicode::UCD(3pm)      Perl Programmers Reference Guide      Unicode::UCD(3pm)
2
3
4

NAME

6       Unicode::UCD - Unicode character database
7

SYNOPSIS

9           use Unicode::UCD 'charinfo';
10           my $charinfo   = charinfo($codepoint);
11
12           use Unicode::UCD 'charprop';
13           my $value  = charprop($codepoint, $property);
14
15           use Unicode::UCD 'charprops_all';
16           my $all_values_hash_ref = charprops_all($codepoint);
17
18           use Unicode::UCD 'casefold';
19           my $casefold = casefold($codepoint);
20
21           use Unicode::UCD 'all_casefolds';
22           my $all_casefolds_ref = all_casefolds();
23
24           use Unicode::UCD 'casespec';
25           my $casespec = casespec($codepoint);
26
27           use Unicode::UCD 'charblock';
28           my $charblock  = charblock($codepoint);
29
30           use Unicode::UCD 'charscript';
31           my $charscript = charscript($codepoint);
32
33           use Unicode::UCD 'charblocks';
34           my $charblocks = charblocks();
35
36           use Unicode::UCD 'charscripts';
37           my $charscripts = charscripts();
38
39           use Unicode::UCD qw(charscript charinrange);
40           my $range = charscript($script);
41           print "looks like $script\n" if charinrange($range, $codepoint);
42
43           use Unicode::UCD qw(general_categories bidi_types);
44           my $categories = general_categories();
45           my $types = bidi_types();
46
47           use Unicode::UCD 'prop_aliases';
48           my @space_names = prop_aliases("space");
49
50           use Unicode::UCD 'prop_value_aliases';
51           my @gc_punct_names = prop_value_aliases("Gc", "Punct");
52
53           use Unicode::UCD 'prop_values';
54           my @all_EA_short_names = prop_values("East_Asian_Width");
55
56           use Unicode::UCD 'prop_invlist';
57           my @puncts = prop_invlist("gc=punctuation");
58
59           use Unicode::UCD 'prop_invmap';
60           my ($list_ref, $map_ref, $format, $missing)
61                                             = prop_invmap("General Category");
62
63           use Unicode::UCD 'search_invlist';
64           my $index = search_invlist(\@invlist, $code_point);
65
66           # The following function should be used only internally in
67           # implementations of the Unicode Normalization Algorithm, and there
68           # are better choices than it.
69           use Unicode::UCD 'compexcl';
70           my $compexcl = compexcl($codepoint);
71
72           use Unicode::UCD 'namedseq';
73           my $namedseq = namedseq($named_sequence_name);
74
75           my $unicode_version = Unicode::UCD::UnicodeVersion();
76
77           my $convert_to_numeric =
78                     Unicode::UCD::num("\N{RUMI DIGIT ONE}\N{RUMI DIGIT TWO}");
79

DESCRIPTION

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

AUTHOR

1745       Jarkko Hietaniemi.  Now maintained by perl5 porters.
1746
1747
1748
1749perl v5.32.1                      2021-03-31                 Unicode::UCD(3pm)
Impressum