Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / charnames.html
blob4bbc5d1483221679f674387dade1f51603f09840
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>charnames - define character names for C&lt;\N{named}&gt; string literal escapes</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;charnames - define character names for C&lt;\N{named}&gt; string literal escapes</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <li><a href="#custom_translators">CUSTOM TRANSLATORS</a></li>
26 <li><a href="#custom_aliases">CUSTOM ALIASES</a></li>
27 <ul>
29 <li><a href="#anonymous_hashes">Anonymous hashes</a></li>
30 <li><a href="#alias_file">Alias file</a></li>
31 <li><a href="#alias_shortcut">Alias shortcut</a></li>
32 </ul>
34 <li><a href="#charnames__viacode_code_">charnames::viacode(code)</a></li>
35 <li><a href="#charnames__vianame_name_">charnames::vianame(name)</a></li>
36 <li><a href="#aliases">ALIASES</a></li>
37 <li><a href="#illegal_characters">ILLEGAL CHARACTERS</a></li>
38 <li><a href="#bugs">BUGS</a></li>
39 </ul>
40 <!-- INDEX END -->
42 <hr />
43 <p>
44 </p>
45 <h1><a name="name">NAME</a></h1>
46 <p>charnames - define character names for <code>\N{named}</code> string literal escapes</p>
47 <p>
48 </p>
49 <hr />
50 <h1><a name="synopsis">SYNOPSIS</a></h1>
51 <pre>
52 use charnames ':full';
53 print &quot;\N{GREEK SMALL LETTER SIGMA} is called sigma.\n&quot;;</pre>
54 <pre>
55 use charnames ':short';
56 print &quot;\N{greek:Sigma} is an upper-case sigma.\n&quot;;</pre>
57 <pre>
58 use charnames qw(cyrillic greek);
59 print &quot;\N{sigma} is Greek sigma, and \N{be} is Cyrillic b.\n&quot;;</pre>
60 <pre>
61 use charnames &quot;:full&quot;, &quot;:alias&quot; =&gt; {
62 e_ACUTE =&gt; &quot;LATIN SMALL LETTER E WITH ACUTE&quot;,
64 print &quot;\N{e_ACUTE} is a small letter e with an acute.\n&quot;;</pre>
65 <pre>
66 use charnames ();
67 print charnames::viacode(0x1234); # prints &quot;ETHIOPIC SYLLABLE SEE&quot;
68 printf &quot;%04X&quot;, charnames::vianame(&quot;GOTHIC LETTER AHSA&quot;); # prints &quot;10330&quot;</pre>
69 <p>
70 </p>
71 <hr />
72 <h1><a name="description">DESCRIPTION</a></h1>
73 <p>Pragma <code>use charnames</code> supports arguments <code>:full</code>, <code>:short</code>, script
74 names and customized aliases. If <code>:full</code> is present, for expansion of
75 <code>\N{CHARNAME}</code>, the string <code>CHARNAME</code> is first looked up in the list of
76 standard Unicode character names. If <code>:short</code> is present, and
77 <code>CHARNAME</code> has the form <code>SCRIPT:CNAME</code>, then <code>CNAME</code> is looked up
78 as a letter in script <code>SCRIPT</code>. If pragma <code>use charnames</code> is used
79 with script name arguments, then for <code>\N{CHARNAME}</code> the name
80 <code>CHARNAME</code> is looked up as a letter in the given scripts (in the
81 specified order). Customized aliases are explained in <a href="#custom_aliases">CUSTOM ALIASES</a>.</p>
82 <p>For lookup of <code>CHARNAME</code> inside a given script <code>SCRIPTNAME</code>
83 this pragma looks for the names</p>
84 <pre>
85 SCRIPTNAME CAPITAL LETTER CHARNAME
86 SCRIPTNAME SMALL LETTER CHARNAME
87 SCRIPTNAME LETTER CHARNAME</pre>
88 <p>in the table of standard Unicode names. If <code>CHARNAME</code> is lowercase,
89 then the <code>CAPITAL</code> variant is ignored, otherwise the <code>SMALL</code> variant
90 is ignored.</p>
91 <p>Note that <code>\N{...}</code> is compile-time, it's a special form of string
92 constant used inside double-quoted strings: in other words, you cannot
93 use variables inside the <code>\N{...}</code>. If you want similar run-time
94 functionality, use charnames::vianame().</p>
95 <p>For the C0 and C1 control characters (U+0000..U+001F, U+0080..U+009F)
96 as of Unicode 3.1, there are no official Unicode names but you can use
97 instead the ISO 6429 names (LINE FEED, ESCAPE, and so forth). In
98 Unicode 3.2 (as of Perl 5.8) some naming changes take place ISO 6429
99 has been updated, see <a href="#aliases">ALIASES</a>. Also note that the U+UU80, U+0081,
100 U+0084, and U+0099 do not have names even in ISO 6429.</p>
101 <p>Since the Unicode standard uses ``U+HHHH'', so can you: ``\N{U+263a}''
102 is the Unicode smiley face, or ``\N{WHITE SMILING FACE}''.</p>
104 </p>
105 <hr />
106 <h1><a name="custom_translators">CUSTOM TRANSLATORS</a></h1>
107 <p>The mechanism of translation of <code>\N{...}</code> escapes is general and not
108 hardwired into <em>charnames.pm</em>. A module can install custom
109 translations (inside the scope which <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_use"><code>use</code></a>s the module) with the
110 following magic incantation:</p>
111 <pre>
112 use charnames (); # for $charnames::hint_bits
113 sub import {
114 shift;
115 $^H |= $charnames::hint_bits;
116 $^H{charnames} = \&amp;translator;
117 }</pre>
118 <p>Here <code>translator()</code> is a subroutine which takes <code>CHARNAME</code> as an
119 argument, and returns text to insert into the string instead of the
120 <code>\N{CHARNAME}</code> escape. Since the text to insert should be different
121 in <code>bytes</code> mode and out of it, the function should check the current
122 state of <code>bytes</code>-flag as in:</p>
123 <pre>
124 use bytes (); # for $bytes::hint_bits
125 sub translator {
126 if ($^H &amp; $bytes::hint_bits) {
127 return bytes_translator(@_);
129 else {
130 return utf8_translator(@_);
132 }</pre>
134 </p>
135 <hr />
136 <h1><a name="custom_aliases">CUSTOM ALIASES</a></h1>
137 <p>This version of charnames supports three mechanisms of adding local
138 or customized aliases to standard Unicode naming conventions (:full)</p>
140 </p>
141 <h2><a name="anonymous_hashes">Anonymous hashes</a></h2>
142 <pre>
143 use charnames &quot;:full&quot;, &quot;:alias&quot; =&gt; {
144 e_ACUTE =&gt; &quot;LATIN SMALL LETTER E WITH ACUTE&quot;,
146 my $str = &quot;\N{e_ACUTE}&quot;;</pre>
148 </p>
149 <h2><a name="alias_file">Alias file</a></h2>
150 <pre>
151 use charnames &quot;:full&quot;, &quot;:alias&quot; =&gt; &quot;pro&quot;;</pre>
152 <pre>
153 will try to read &quot;unicore/pro_alias.pl&quot; from the @INC path. This
154 file should return a list in plain perl:</pre>
155 <pre>
157 A_GRAVE =&gt; &quot;LATIN CAPITAL LETTER A WITH GRAVE&quot;,
158 A_CIRCUM =&gt; &quot;LATIN CAPITAL LETTER A WITH CIRCUMFLEX&quot;,
159 A_DIAERES =&gt; &quot;LATIN CAPITAL LETTER A WITH DIAERESIS&quot;,
160 A_TILDE =&gt; &quot;LATIN CAPITAL LETTER A WITH TILDE&quot;,
161 A_BREVE =&gt; &quot;LATIN CAPITAL LETTER A WITH BREVE&quot;,
162 A_RING =&gt; &quot;LATIN CAPITAL LETTER A WITH RING ABOVE&quot;,
163 A_MACRON =&gt; &quot;LATIN CAPITAL LETTER A WITH MACRON&quot;,
164 );</pre>
166 </p>
167 <h2><a name="alias_shortcut">Alias shortcut</a></h2>
168 <pre>
169 use charnames &quot;:alias&quot; =&gt; &quot;:pro&quot;;</pre>
170 <pre>
171 works exactly the same as the alias pairs, only this time,
172 &quot;:full&quot; is inserted automatically as first argument (if no
173 other argument is given).</pre>
175 </p>
176 <hr />
177 <h1><a name="charnames__viacode_code_">charnames::viacode(code)</a></h1>
178 <p>Returns the full name of the character indicated by the numeric code.
179 The example</p>
180 <pre>
181 print charnames::viacode(0x2722);</pre>
182 <p>prints ``FOUR TEARDROP-SPOKED ASTERISK''.</p>
183 <p>Returns undef if no name is known for the code.</p>
184 <p>This works only for the standard names, and does not yet apply
185 to custom translators.</p>
186 <p>Notice that the name returned for of U+FEFF is ``ZERO WIDTH NO-BREAK
187 SPACE'', not ``BYTE ORDER MARK''.</p>
189 </p>
190 <hr />
191 <h1><a name="charnames__vianame_name_">charnames::vianame(name)</a></h1>
192 <p>Returns the code point indicated by the name.
193 The example</p>
194 <pre>
195 printf &quot;%04X&quot;, charnames::vianame(&quot;FOUR TEARDROP-SPOKED ASTERISK&quot;);</pre>
196 <p>prints ``2722''.</p>
197 <p>Returns undef if the name is unknown.</p>
198 <p>This works only for the standard names, and does not yet apply
199 to custom translators.</p>
201 </p>
202 <hr />
203 <h1><a name="aliases">ALIASES</a></h1>
204 <p>A few aliases have been defined for convenience: instead of having
205 to use the official names</p>
206 <pre>
207 LINE FEED (LF)
208 FORM FEED (FF)
209 CARRIAGE RETURN (CR)
210 NEXT LINE (NEL)</pre>
211 <p>(yes, with parentheses) one can use</p>
212 <pre>
213 LINE FEED
214 FORM FEED
215 CARRIAGE RETURN
216 NEXT LINE
220 NEL</pre>
221 <p>One can also use</p>
222 <pre>
223 BYTE ORDER MARK
224 BOM</pre>
225 <p>and</p>
226 <pre>
227 ZWNJ
228 ZWJ</pre>
229 <p>for ZERO WIDTH NON-JOINER and ZERO WIDTH JOINER.</p>
230 <p>For backward compatibility one can use the old names for
231 certain C0 and C1 controls</p>
232 <pre>
233 old new</pre>
234 <pre>
235 HORIZONTAL TABULATION CHARACTER TABULATION
236 VERTICAL TABULATION LINE TABULATION
237 FILE SEPARATOR INFORMATION SEPARATOR FOUR
238 GROUP SEPARATOR INFORMATION SEPARATOR THREE
239 RECORD SEPARATOR INFORMATION SEPARATOR TWO
240 UNIT SEPARATOR INFORMATION SEPARATOR ONE
241 PARTIAL LINE DOWN PARTIAL LINE FORWARD
242 PARTIAL LINE UP PARTIAL LINE BACKWARD</pre>
243 <p>but the old names in addition to giving the character
244 will also give a warning about being deprecated.</p>
246 </p>
247 <hr />
248 <h1><a name="illegal_characters">ILLEGAL CHARACTERS</a></h1>
249 <p>If you ask by name for a character that does not exist, a warning is
250 given and the Unicode <em>replacement character</em> ``\x{FFFD}'' is returned.</p>
251 <p>If you ask by code for a character that does not exist, no warning is
252 given and <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_undef"><code>undef</code></a> is returned. (Though if you ask for a code point
253 past U+10FFFF you do get a warning.)</p>
255 </p>
256 <hr />
257 <h1><a name="bugs">BUGS</a></h1>
258 <p>Since evaluation of the translation function happens in a middle of
259 compilation (of a string literal), the translation function should not
260 do any <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_eval"><code>eval</code></a>s or <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_require"><code>require</code></a>s. This restriction should be lifted in
261 a future version of Perl.</p>
262 <table border="0" width="100%" cellspacing="0" cellpadding="3">
263 <tr><td class="block" style="background-color: #cccccc" valign="middle">
264 <big><strong><span class="block">&nbsp;charnames - define character names for C&lt;\N{named}&gt; string literal escapes</span></strong></big>
265 </td></tr>
266 </table>
268 </body>
270 </html>