summaryrefslogtreecommitdiffstats
path: root/upstream/debian-bookworm/man3/charnames.3perl
blob: 7784889a037b347dfd0072de731c4982e6311610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  \*(C+ will
.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and
.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,
.\" nothing in troff, for use with C<>.
.tr \(*W-
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
.    ds C`
.    ds C'
'br\}
.\"
.\" Escape single quotes in literal strings from groff's Unicode transform.
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\"
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{\
.    if \nF \{\
.        de IX
.        tm Index:\\$1\t\\n%\t"\\$2"
..
.        if !\nF==2 \{\
.            nr % 0
.            nr F 2
.        \}
.    \}
.\}
.rr rF
.\" ========================================================================
.\"
.IX Title "charnames 3perl"
.TH charnames 3perl "2023-11-25" "perl v5.36.0" "Perl Programmers Reference Guide"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
.nh
.SH "NAME"
charnames \- access to Unicode character names and named character sequences; also define character names
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 4
\& use charnames \*(Aq:full\*(Aq;
\& print "\eN{GREEK SMALL LETTER SIGMA} is called sigma.\en";
\& print "\eN{LATIN CAPITAL LETTER E WITH VERTICAL LINE BELOW}",
\&       " is an officially named sequence of two Unicode characters\en";
\&
\& use charnames \*(Aq:loose\*(Aq;
\& print "\eN{Greek small\-letter  sigma}",
\&        "can be used to ignore case, underscores, most blanks,"
\&        "and when you aren\*(Aqt sure if the official name has hyphens\en";
\&
\& use charnames \*(Aq:short\*(Aq;
\& print "\eN{greek:Sigma} is an upper\-case sigma.\en";
\&
\& use charnames qw(cyrillic greek);
\& print "\eN{sigma} is Greek sigma, and \eN{be} is Cyrillic b.\en";
\&
\& use utf8;
\& use charnames ":full", ":alias" => {
\&   e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE",
\&   mychar => 0xE8000,  # Private use area
\&   "自転車に乗る人" => "BICYCLIST"
\& };
\& print "\eN{e_ACUTE} is a small letter e with an acute.\en";
\& print "\eN{mychar} allows me to name private use characters.\en";
\& print "And I can create synonyms in other languages,",
\&       " such as \eN{自転車に乗る人} for "BICYCLIST (U+1F6B4)\en";
\&
\& use charnames ();
\& print charnames::viacode(0x1234); # prints "ETHIOPIC SYLLABLE SEE"
\& printf "%04X", charnames::vianame("GOTHIC LETTER AHSA"); # prints
\&                                                          # "10330"
\& print charnames::vianame("LATIN CAPITAL LETTER A"); # prints 65 on
\&                                                     # ASCII platforms;
\&                                                     # 193 on EBCDIC
\& print charnames::string_vianame("LATIN CAPITAL LETTER A"); # prints "A"
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Pragma \f(CW\*(C`use charnames\*(C'\fR is used to gain access to the names of the
Unicode characters and named character sequences, and to allow you to define
your own character and character sequence names.
.PP
All forms of the pragma enable use of the following 3 functions:
.IP "\(bu" 4
"charnames::string_vianame(\fIname\fR)" for run-time lookup of a
either a character name or a named character sequence, returning its string
representation
.IP "\(bu" 4
"charnames::vianame(\fIname\fR)" for run-time lookup of a
character name (but not a named character sequence) to get its ordinal value
(code point)
.IP "\(bu" 4
"charnames::viacode(\fIcode\fR)" for run-time lookup of a code point to get its
Unicode name.
.PP
Starting in Perl v5.16, any occurrence of \f(CW\*(C`\eN{\f(CICHARNAME\f(CW}\*(C'\fR sequences
in a double-quotish string automatically loads this module with arguments
\&\f(CW\*(C`:full\*(C'\fR and \f(CW\*(C`:short\*(C'\fR (described below) if it hasn't already been loaded with
different arguments, in order to compile the named Unicode character into
position in the string.  Prior to v5.16, an explicit \f(CW\*(C`use charnames\*(C'\fR was
required to enable this usage.  (However, prior to v5.16, the form \f(CW"use charnames ();"\fR did not enable \f(CW\*(C`\eN{\f(CICHARNAME\f(CW}\*(C'\fR.)
.PP
Note that \f(CW\*(C`\eN{U+\f(CI...\f(CW}\*(C'\fR, where the \fI...\fR is a hexadecimal number,
also inserts a character into a string.
The character it inserts is the one whose Unicode code point
(ordinal value) is equal to the number.  For example, \f(CW"\eN{U+263a}"\fR is
the Unicode (white background, black foreground) smiley face
equivalent to \f(CW"\eN{WHITE SMILING FACE}"\fR.
Also note, \f(CW\*(C`\eN{\f(CI...\f(CW}\*(C'\fR can mean a regex quantifier instead of a character
name, when the \fI...\fR is a number (or comma separated pair of numbers
(see \*(L"\s-1QUANTIFIERS\*(R"\s0 in perlreref), and is not related to this pragma.
.PP
The \f(CW\*(C`charnames\*(C'\fR pragma supports arguments \f(CW\*(C`:full\*(C'\fR, \f(CW\*(C`:loose\*(C'\fR, \f(CW\*(C`:short\*(C'\fR,
script names and customized aliases.
.PP
If \f(CW\*(C`:full\*(C'\fR is present, for expansion of
\&\f(CW\*(C`\eN{\f(CICHARNAME\f(CW}\*(C'\fR, the string \fI\s-1CHARNAME\s0\fR is first looked up in the list of
standard Unicode character names.
.PP
\&\f(CW\*(C`:loose\*(C'\fR is a variant of \f(CW\*(C`:full\*(C'\fR which allows \fI\s-1CHARNAME\s0\fR to be less
precisely specified.  Details are in \*(L"\s-1LOOSE MATCHES\*(R"\s0.
.PP
If \f(CW\*(C`:short\*(C'\fR is present, and
\&\fI\s-1CHARNAME\s0\fR has the form \f(CW\*(C`\f(CISCRIPT\f(CW:\f(CICNAME\f(CW\*(C'\fR, then \fI\s-1CNAME\s0\fR is looked up
as a letter in script \fI\s-1SCRIPT\s0\fR, as described in the next paragraph.
Or, if \f(CW\*(C`use charnames\*(C'\fR is used
with script name arguments, then for \f(CW\*(C`\eN{\f(CICHARNAME\f(CW}\*(C'\fR the name
\&\fI\s-1CHARNAME\s0\fR is looked up as a letter in the given scripts (in the
specified order). Customized aliases can override these, and are explained in
\&\*(L"\s-1CUSTOM ALIASES\*(R"\s0.
.PP
For lookup of \fI\s-1CHARNAME\s0\fR inside a given script \fI\s-1SCRIPTNAME\s0\fR,
this pragma looks in the table of standard Unicode names for the names
.PP
.Vb 3
\&  SCRIPTNAME CAPITAL LETTER CHARNAME
\&  SCRIPTNAME SMALL LETTER CHARNAME
\&  SCRIPTNAME LETTER CHARNAME
.Ve
.PP
If \fI\s-1CHARNAME\s0\fR is all lowercase,
then the \f(CW\*(C`CAPITAL\*(C'\fR variant is ignored, otherwise the \f(CW\*(C`SMALL\*(C'\fR variant
is ignored, and both \fI\s-1CHARNAME\s0\fR and \fI\s-1SCRIPTNAME\s0\fR are converted to all
uppercase for look-up.  Other than that, both of them follow loose rules if \f(CW\*(C`:loose\*(C'\fR is also specified; strict otherwise.
.PP
Note that \f(CW\*(C`\eN{...}\*(C'\fR is compile-time; it's a special form of string
constant used inside double-quotish strings; this means that you cannot
use variables inside the \f(CW\*(C`\eN{...}\*(C'\fR.  If you want similar run-time
functionality, use
\&\fBcharnames::string_vianame()\fR.
.PP
Note, starting in Perl 5.18, the name \f(CW\*(C`BELL\*(C'\fR refers to the Unicode character
U+1F514, instead of the traditional U+0007.  For the latter, use \f(CW\*(C`ALERT\*(C'\fR
or \f(CW\*(C`BEL\*(C'\fR.
.PP
It is a syntax error to use \f(CW\*(C`\eN{NAME}\*(C'\fR where \f(CW\*(C`NAME\*(C'\fR is unknown.
.PP
For \f(CW\*(C`\eN{NAME}\*(C'\fR, it is a fatal error if \f(CW\*(C`use bytes\*(C'\fR is in effect and the
input name is that of a character that won't fit into a byte (i.e., whose
ordinal is above 255).
.PP
Otherwise, any string that includes a \f(CW\*(C`\eN{\f(CIcharname\f(CW}\*(C'\fR or
\&\f(CW\*(C`\eN{U+\f(CIcode point\f(CW}\*(C'\fR will automatically have Unicode rules (see
\&\*(L"Byte and Character Semantics\*(R" in perlunicode).
.SH "LOOSE MATCHES"
.IX Header "LOOSE MATCHES"
By specifying \f(CW\*(C`:loose\*(C'\fR, Unicode's loose character name
matching <http://www.unicode.org/reports/tr44#Matching_Rules> rules are
selected instead of the strict exact match used otherwise.
That means that \fI\s-1CHARNAME\s0\fR doesn't have to be so precisely specified.
Upper/lower case doesn't matter (except with scripts as mentioned above), nor
do any underscores, and the only hyphens that matter are those at the
beginning or end of a word in the name (with one exception:  the hyphen in
U+1180 \f(CW\*(C`HANGUL JUNGSEONG O\-E\*(C'\fR does matter).
Also, blanks not adjacent to hyphens don't matter.
The official Unicode names are quite variable as to where they use hyphens
versus spaces to separate word-like units, and this option allows you to not
have to care as much.
The reason non-medial hyphens matter is because of cases like
U+0F60 \f(CW\*(C`TIBETAN LETTER \-A\*(C'\fR versus U+0F68 \f(CW\*(C`TIBETAN LETTER A\*(C'\fR.
The hyphen here is significant, as is the space before it, and so both must be
included.
.PP
\&\f(CW\*(C`:loose\*(C'\fR slows down look-ups by a factor of 2 to 3 versus
\&\f(CW\*(C`:full\*(C'\fR, but the trade-off may be worth it to you.  Each individual look-up
takes very little time, and the results are cached, so the speed difference
would become a factor only in programs that do look-ups of many different
spellings, and probably only when those look-ups are through \f(CW\*(C`vianame()\*(C'\fR and
\&\f(CW\*(C`string_vianame()\*(C'\fR, since \f(CW\*(C`\eN{...}\*(C'\fR look-ups are done at compile time.
.SH "ALIASES"
.IX Header "ALIASES"
Starting in Unicode 6.1 and Perl v5.16, Unicode defines many abbreviations and
names that were formerly Perl extensions, and some additional ones that Perl
did not previously accept.  The list is getting too long to reproduce here,
but you can get the complete list from the Unicode web site:
<http://www.unicode.org/Public/UNIDATA/NameAliases.txt>.
.PP
Earlier versions of Perl accepted almost all the 6.1 names.  These were most
extensively documented in the v5.14 version of this pod:
<http://perldoc.perl.org/5.14.0/charnames.html#ALIASES>.
.SH "CUSTOM ALIASES"
.IX Header "CUSTOM ALIASES"
You can add customized aliases to standard (\f(CW\*(C`:full\*(C'\fR) Unicode naming
conventions.  The aliases override any standard definitions, so, if
you're twisted enough, you can change \f(CW"\eN{LATIN CAPITAL LETTER A}"\fR to
mean \f(CW"B"\fR, etc.
.PP
Aliases must begin with a character that is alphabetic.  After that, each may
contain any combination of word (\f(CW\*(C`\ew\*(C'\fR) characters, \s-1SPACE\s0 (U+0020),
HYPHEN-MINUS (U+002D), \s-1LEFT PARENTHESIS\s0 (U+0028), and \s-1RIGHT PARENTHESIS\s0
(U+0029).  These last two should never have been allowed
in names, and are retained for backwards compatibility only, and may be
deprecated and removed in future releases of Perl, so don't use them for new
names.  (More precisely, the first character of a name you specify must be
something that matches all of \f(CW\*(C`\ep{ID_Start}\*(C'\fR, \f(CW\*(C`\ep{Alphabetic}\*(C'\fR, and
\&\f(CW\*(C`\ep{Gc=Letter}\*(C'\fR.  This makes sure it is what any reasonable person would view
as an alphabetic character.  And, the continuation characters that match \f(CW\*(C`\ew\*(C'\fR
must also match \f(CW\*(C`\ep{ID_Continue}\*(C'\fR.)  Starting with Perl v5.18, any Unicode
characters meeting the above criteria may be used; prior to that only
Latin1\-range characters were acceptable.
.PP
An alias can map to either an official Unicode character name (not a loose
matched name) or to a
numeric code point (ordinal).  The latter is useful for assigning names
to code points in Unicode private use areas such as U+E800 through
U+F8FF.
A numeric code point must be a non-negative integer, or a string beginning
with \f(CW"U+"\fR or \f(CW"0x"\fR with the remainder considered to be a
hexadecimal integer.  A literal numeric constant must be unsigned; it
will be interpreted as hex if it has a leading zero or contains
non-decimal hex digits; otherwise it will be interpreted as decimal.
If it begins with \f(CW"U+"\fR, it is interpreted as the Unicode code point;
otherwise it is interpreted as native.  (Only code points below 256 can
differ between Unicode and native.)  Thus \f(CW\*(C`U+41\*(C'\fR is always the Latin letter
\&\*(L"A\*(R"; but \f(CW0x41\fR can be \*(L"NO-BREAK \s-1SPACE\*(R"\s0 on \s-1EBCDIC\s0 platforms.
.PP
Aliases are added either by the use of anonymous hashes:
.PP
.Vb 5
\&    use charnames ":alias" => {
\&        e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE",
\&        mychar1 => 0xE8000,
\&        };
\&    my $str = "\eN{e_ACUTE}";
.Ve
.PP
or by using a file containing aliases:
.PP
.Vb 1
\&    use charnames ":alias" => "pro";
.Ve
.PP
This will try to read \f(CW"unicore/pro_alias.pl"\fR from the \f(CW@INC\fR path. This
file should return a list in plain perl:
.PP
.Vb 10
\&    (
\&    A_GRAVE         => "LATIN CAPITAL LETTER A WITH GRAVE",
\&    A_CIRCUM        => "LATIN CAPITAL LETTER A WITH CIRCUMFLEX",
\&    A_DIAERES       => "LATIN CAPITAL LETTER A WITH DIAERESIS",
\&    A_TILDE         => "LATIN CAPITAL LETTER A WITH TILDE",
\&    A_BREVE         => "LATIN CAPITAL LETTER A WITH BREVE",
\&    A_RING          => "LATIN CAPITAL LETTER A WITH RING ABOVE",
\&    A_MACRON        => "LATIN CAPITAL LETTER A WITH MACRON",
\&    mychar2         => "U+E8001",
\&    );
.Ve
.PP
Both these methods insert \f(CW":full"\fR automatically as the first argument (if no
other argument is given), and you can give the \f(CW":full"\fR explicitly as
well, like
.PP
.Vb 1
\&    use charnames ":full", ":alias" => "pro";
.Ve
.PP
\&\f(CW":loose"\fR has no effect with these.  Input names must match exactly, using
\&\f(CW":full"\fR rules.
.PP
Also, both these methods currently allow only single characters to be named.
To name a sequence of characters, use a
custom translator (described below).
.SH "charnames::string_vianame(\fIname\fP)"
.IX Header "charnames::string_vianame(name)"
This is a runtime equivalent to \f(CW\*(C`\eN{...}\*(C'\fR.  \fIname\fR can be any expression
that evaluates to a name accepted by \f(CW\*(C`\eN{...}\*(C'\fR under the \f(CW\*(C`:full\*(C'\fR
option to \f(CW\*(C`charnames\*(C'\fR.  In addition, any other options for the
controlling \f(CW"use charnames"\fR in the same scope apply, like \f(CW\*(C`:loose\*(C'\fR or any
script list, \f(CW\*(C`:short\*(C'\fR option, or custom aliases you may have defined.
.PP
The only differences are due to the fact that \f(CW\*(C`string_vianame\*(C'\fR is run-time
and \f(CW\*(C`\eN{}\*(C'\fR is compile time.  You can't interpolate inside a \f(CW\*(C`\eN{}\*(C'\fR, (so
\&\f(CW\*(C`\eN{$variable}\*(C'\fR doesn't work); and if the input name is unknown,
\&\f(CW\*(C`string_vianame\*(C'\fR returns \f(CW\*(C`undef\*(C'\fR instead of it being a syntax error.
.SH "charnames::vianame(\fIname\fP)"
.IX Header "charnames::vianame(name)"
This is similar to \f(CW\*(C`string_vianame\*(C'\fR.  The main difference is that under most
circumstances, \f(CW\*(C`vianame\*(C'\fR returns an ordinal code
point, whereas \f(CW\*(C`string_vianame\*(C'\fR returns a string.  For example,
.PP
.Vb 1
\&   printf "U+%04X", charnames::vianame("FOUR TEARDROP\-SPOKED ASTERISK");
.Ve
.PP
prints \*(L"U+2722\*(R".
.PP
This leads to the other two differences.  Since a single code point is
returned, the function can't handle named character sequences, as these are
composed of multiple characters (it returns \f(CW\*(C`undef\*(C'\fR for these.  And, the code
point can be that of any
character, even ones that aren't legal under the \f(CW\*(C`use bytes\*(C'\fR pragma,
.PP
See \*(L"\s-1BUGS\*(R"\s0 for the circumstances in which the behavior differs
from  that described above.
.SH "charnames::viacode(\fIcode\fP)"
.IX Header "charnames::viacode(code)"
Returns the full name of the character indicated by the numeric code.
For example,
.PP
.Vb 1
\&    print charnames::viacode(0x2722);
.Ve
.PP
prints \*(L"\s-1FOUR\s0 TEARDROP-SPOKED \s-1ASTERISK\*(R".\s0
.PP
The name returned is the \*(L"best\*(R" (defined below) official name or alias
for the code point, if
available; otherwise your custom alias for it, if defined; otherwise \f(CW\*(C`undef\*(C'\fR.
This means that your alias will only be returned for code points that don't
have an official Unicode name (nor alias) such as private use code points.
.PP
If you define more than one name for the code point, it is indeterminate
which one will be returned.
.PP
As mentioned, the function returns \f(CW\*(C`undef\*(C'\fR if no name is known for the code
point.  In Unicode the proper name for these is the empty string, which
\&\f(CW\*(C`undef\*(C'\fR stringifies to.  (If you ask for a code point past the legal
Unicode maximum of U+10FFFF that you haven't assigned an alias to, you
get \f(CW\*(C`undef\*(C'\fR plus a warning.)
.PP
The input number must be a non-negative integer, or a string beginning
with \f(CW"U+"\fR or \f(CW"0x"\fR with the remainder considered to be a
hexadecimal integer.  A literal numeric constant must be unsigned; it
will be interpreted as hex if it has a leading zero or contains
non-decimal hex digits; otherwise it will be interpreted as decimal.
If it begins with \f(CW"U+"\fR, it is interpreted as the Unicode code point;
otherwise it is interpreted as native.  (Only code points below 256 can
differ between Unicode and native.)  Thus \f(CW\*(C`U+41\*(C'\fR is always the Latin letter
\&\*(L"A\*(R"; but \f(CW0x41\fR can be \*(L"NO-BREAK \s-1SPACE\*(R"\s0 on \s-1EBCDIC\s0 platforms.
.PP
As mentioned above under \*(L"\s-1ALIASES\*(R"\s0, Unicode 6.1 defines extra names
(synonyms or aliases) for some code points, most of which were already
available as Perl extensions.  All these are accepted by \f(CW\*(C`\eN{...}\*(C'\fR and the
other functions in this module, but \f(CW\*(C`viacode\*(C'\fR has to choose which one
name to return for a given input code point, so it returns the \*(L"best\*(R" name.
To understand how this works, it is helpful to know more about the Unicode
name properties.  All code points actually have only a single name, which
(starting in Unicode 2.0) can never change once a character has been assigned
to the code point.  But mistakes have been made in assigning names, for
example sometimes a clerical error was made during the publishing of the
Standard which caused words to be misspelled, and there was no way to correct
those.  The Name_Alias property was eventually created to handle these
situations.  If a name was wrong, a corrected synonym would be published for
it, using Name_Alias.  \f(CW\*(C`viacode\*(C'\fR will return that corrected synonym as the
\&\*(L"best\*(R" name for a code point.  (It is even possible, though it hasn't happened
yet, that the correction itself will need to be corrected, and so another
Name_Alias can be created for that code point; \f(CW\*(C`viacode\*(C'\fR will return the
most recent correction.)
.PP
The Unicode name for each of the control characters (such as \s-1LINE FEED\s0) is the
empty string.  However almost all had names assigned by other standards, such
as the \s-1ASCII\s0 Standard, or were in common use.  \f(CW\*(C`viacode\*(C'\fR returns these names
as the \*(L"best\*(R" ones available.  Unicode 6.1 has created Name_Aliases for each
of them, including alternate names, like \s-1NEW LINE.\s0  \f(CW\*(C`viacode\*(C'\fR uses the
original name, \*(L"\s-1LINE FEED\*(R"\s0 in preference to the alternate.  Similarly the
name returned for U+FEFF is \*(L"\s-1ZERO WIDTH\s0 NO-BREAK \s-1SPACE\*(R",\s0 not \*(L"\s-1BYTE ORDER
MARK\*(R".\s0
.PP
Until Unicode 6.1, the 4 control characters U+0080, U+0081, U+0084, and U+0099
did not have names nor aliases.
To preserve backwards compatibility, any alias you define for these code
points will be returned by this function, in preference to the official name.
.PP
Some code points also have abbreviated names, such as \*(L"\s-1LF\*(R"\s0 or \*(L"\s-1NL\*(R".\s0
\&\f(CW\*(C`viacode\*(C'\fR never returns these.
.PP
Because a name correction may be added in future Unicode releases, the name
that \f(CW\*(C`viacode\*(C'\fR returns may change as a result.  This is a rare event, but it
does happen.
.SH "CUSTOM TRANSLATORS"
.IX Header "CUSTOM TRANSLATORS"
The mechanism of translation of \f(CW\*(C`\eN{...}\*(C'\fR escapes is general and not
hardwired into \fIcharnames.pm\fR.  A module can install custom
translations (inside the scope which \f(CW\*(C`use\*(C'\fRs the module) with the
following magic incantation:
.PP
.Vb 4
\&    sub import {
\&        shift;
\&        $^H{charnames} = \e&translator;
\&    }
.Ve
.PP
Here \fBtranslator()\fR is a subroutine which takes \fI\s-1CHARNAME\s0\fR as an
argument, and returns text to insert into the string instead of the
\&\f(CW\*(C`\eN{\f(CICHARNAME\f(CW}\*(C'\fR escape.
.PP
This is the only way you can create a custom named sequence of code points.
.PP
Since the text to insert should be different
in \f(CW\*(C`bytes\*(C'\fR mode and out of it, the function should check the current
state of \f(CW\*(C`bytes\*(C'\fR\-flag as in:
.PP
.Vb 9
\&    use bytes ();                      # for $bytes::hint_bits
\&    sub translator {
\&        if ($^H & $bytes::hint_bits) {
\&            return bytes_translator(@_);
\&        }
\&        else {
\&            return utf8_translator(@_);
\&        }
\&    }
.Ve
.PP
See \*(L"\s-1CUSTOM ALIASES\*(R"\s0 above for restrictions on \fI\s-1CHARNAME\s0\fR.
.PP
Of course, \f(CW\*(C`vianame\*(C'\fR, \f(CW\*(C`viacode\*(C'\fR, and \f(CW\*(C`string_vianame\*(C'\fR would need to be
overridden as well.
.SH "BUGS"
.IX Header "BUGS"
\&\fBvianame()\fR normally returns an ordinal code point, but when the input name is of
the form \f(CW\*(C`U+...\*(C'\fR, it returns a chr instead.  In this case, if \f(CW\*(C`use bytes\*(C'\fR is
in effect and the character won't fit into a byte, it returns \f(CW\*(C`undef\*(C'\fR and
raises a warning.
.PP
Since evaluation of the translation function (see \*(L"\s-1CUSTOM
TRANSLATORS\*(R"\s0) happens in the middle of compilation (of a string
literal), the translation function should not do any \f(CW\*(C`eval\*(C'\fRs or
\&\f(CW\*(C`require\*(C'\fRs.  This restriction should be lifted (but is low priority) in
a future version of Perl.