.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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" '' '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 turned on, 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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "charnames 3perl" .TH charnames 3perl "2011-09-26" "perl v5.14.2" "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: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 charnames ":full", ":alias" => { \& e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE", \& mychar => 0xE8000, # Private use area \& }; \& print "\eN{e_ACUTE} is a small letter e with an acute.\en"; \& print "\e\eN{mychar} allows me to name private use characters.\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 All forms other than \f(CW"use\ charnames\ ();"\fR also enable the use of \&\f(CW\*(C`\eN{\f(CICHARNAME\f(CW}\*(C'\fR sequences to compile a Unicode character into a string, based on its name. .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, but doesn't require the use of this pragma. The character it inserts is the one whose 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; it doesn't require this pragma, whereas the equivalent, \f(CW"\eN{WHITE SMILING FACE}"\fR does. Also, \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\s0\*(R" 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`:short\*(C'\fR, script names and customized aliases. 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. 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. 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\s0 \s-1ALIASES\s0\*(R". .PP For lookup of \fI\s-1CHARNAME\s0\fR inside a given script \fI\s-1SCRIPTNAME\s0\fR this pragma looks for the names .PP .Vb 3 \& SCRIPTNAME CAPITAL LETTER CHARNAME \& SCRIPTNAME SMALL LETTER CHARNAME \& SCRIPTNAME LETTER CHARNAME .Ve .PP in the table of standard Unicode names. If \fI\s-1CHARNAME\s0\fR is lowercase, then the \f(CW\*(C`CAPITAL\*(C'\fR variant is ignored, otherwise the \f(CW\*(C`SMALL\*(C'\fR variant is ignored. .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 \&\fIcharnames::string_vianame()\fR. .PP For the C0 and C1 control characters (U+0000..U+001F, U+0080..U+009F) there are no official Unicode names but you can use instead the \s-1ISO\s0 6429 names (\s-1LINE\s0 \s-1FEED\s0, \s-1ESCAPE\s0, and so forth, and their abbreviations, \s-1LF\s0, \&\s-1ESC\s0, ...). In Unicode 3.2 (as of Perl 5.8) some naming changes took place, and \s-1ISO\s0 6429 was updated, see \*(L"\s-1ALIASES\s0\*(R". .PP If the input name is unknown, \f(CW\*(C`\eN{NAME}\*(C'\fR raises a warning and substitutes the Unicode \s-1REPLACEMENT\s0 \s-1CHARACTER\s0 (U+FFFD). .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 semantics (see \&\*(L"Byte and Character Semantics\*(R" in perlunicode). .SH "ALIASES" .IX Header "ALIASES" A few aliases have been defined for convenience: instead of having to use the official names .PP .Vb 4 \& LINE FEED (LF) \& FORM FEED (FF) \& CARRIAGE RETURN (CR) \& NEXT LINE (NEL) .Ve .PP (yes, with parentheses), one can use .PP .Vb 8 \& LINE FEED \& FORM FEED \& CARRIAGE RETURN \& NEXT LINE \& LF \& FF \& CR \& NEL .Ve .PP All the other standard abbreviations for the controls, such as \f(CW\*(C`ACK\*(C'\fR for \&\f(CW\*(C`ACKNOWLEDGE\*(C'\fR also can be used. .PP One can also use .PP .Vb 2 \& BYTE ORDER MARK \& BOM .Ve .PP and these abbreviations .PP .Vb 1 \& Abbreviation Full Name \& \& CGJ COMBINING GRAPHEME JOINER \& FVS1 MONGOLIAN FREE VARIATION SELECTOR ONE \& FVS2 MONGOLIAN FREE VARIATION SELECTOR TWO \& FVS3 MONGOLIAN FREE VARIATION SELECTOR THREE \& LRE LEFT\-TO\-RIGHT EMBEDDING \& LRM LEFT\-TO\-RIGHT MARK \& LRO LEFT\-TO\-RIGHT OVERRIDE \& MMSP MEDIUM MATHEMATICAL SPACE \& MVS MONGOLIAN VOWEL SEPARATOR \& NBSP NO\-BREAK SPACE \& NNBSP NARROW NO\-BREAK SPACE \& PDF POP DIRECTIONAL FORMATTING \& RLE RIGHT\-TO\-LEFT EMBEDDING \& RLM RIGHT\-TO\-LEFT MARK \& RLO RIGHT\-TO\-LEFT OVERRIDE \& SHY SOFT HYPHEN \& VS1 VARIATION SELECTOR\-1 \& . \& . \& . \& VS256 VARIATION SELECTOR\-256 \& WJ WORD JOINER \& ZWJ ZERO WIDTH JOINER \& ZWNJ ZERO WIDTH NON\-JOINER \& ZWSP ZERO WIDTH SPACE .Ve .PP For backward compatibility one can use the old names for certain C0 and C1 controls .PP .Vb 1 \& old new \& \& FILE SEPARATOR INFORMATION SEPARATOR FOUR \& GROUP SEPARATOR INFORMATION SEPARATOR THREE \& HORIZONTAL TABULATION CHARACTER TABULATION \& HORIZONTAL TABULATION SET CHARACTER TABULATION SET \& HORIZONTAL TABULATION WITH JUSTIFICATION CHARACTER TABULATION \& WITH JUSTIFICATION \& PARTIAL LINE DOWN PARTIAL LINE FORWARD \& PARTIAL LINE UP PARTIAL LINE BACKWARD \& RECORD SEPARATOR INFORMATION SEPARATOR TWO \& REVERSE INDEX REVERSE LINE FEED \& UNIT SEPARATOR INFORMATION SEPARATOR ONE \& VERTICAL TABULATION LINE TABULATION \& VERTICAL TABULATION SET LINE TABULATION SET .Ve .PP but the old names in addition to giving the character will also give a warning about being deprecated. .PP And finally, certain published variants are usable, including some for controls that have no Unicode names: .PP .Vb 1 \& name character \& \& END OF PROTECTED AREA END OF GUARDED AREA, U+0097 \& HIGH OCTET PRESET U+0081 \& HOP U+0081 \& IND U+0084 \& INDEX U+0084 \& PAD U+0080 \& PADDING CHARACTER U+0080 \& PRIVATE USE 1 PRIVATE USE ONE, U+0091 \& PRIVATE USE 2 PRIVATE USE TWO, U+0092 \& SGC U+0099 \& SINGLE GRAPHIC CHARACTER INTRODUCER U+0099 \& SINGLE\-SHIFT 2 SINGLE SHIFT TWO, U+008E \& SINGLE\-SHIFT 3 SINGLE SHIFT THREE, U+008F \& START OF PROTECTED AREA START OF GUARDED AREA, U+0096 .Ve .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 Note that an alias should not be something that is a legal curly brace-enclosed quantifier (see \*(L"\s-1QUANTIFIERS\s0\*(R" in perlreref). For example \&\f(CW\*(C`\eN{123}\*(C'\fR means to match 123 non-newline characters, and is not treated as a charnames alias. Aliases are discouraged from beginning with anything other than an alphabetic character and from containing anything other than alphanumerics, spaces, dashes, parentheses, and underscores. Currently they must be \s-1ASCII\s0. .PP An alias can map to either an official Unicode character 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. .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 Also, both these methods currently allow only a single character to be named. To name a sequence of characters, use a custom translator (described below). .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\s0\*(R". .PP The name returned is the official name for the code point, if available; otherwise your custom alias for it. This means that your alias will only be returned for code points that don't have an official Unicode name (nor Unicode version 1 name), such as private use code points, and the 4 control characters U+0080, U+0081, U+0084, and U+0099. If you define more than one name for the code point, it is indeterminate which one will be returned. .PP The function returns \f(CW\*(C`undef\*(C'\fR if no name is known for the code point. In Unicode the proper name of 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. .PP Notice that the name returned for of U+FEFF is \*(L"\s-1ZERO\s0 \s-1WIDTH\s0 NO-BREAK \&\s-1SPACE\s0\*(R", not \*(L"\s-1BYTE\s0 \s-1ORDER\s0 \s-1MARK\s0\*(R". .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 any script list, \f(CW\*(C`:short\*(C'\fR option, or custom aliases you may have defined. .PP The only difference is that if the input name is unknown, \f(CW\*(C`string_vianame\*(C'\fR returns \f(CW\*(C`undef\*(C'\fR instead of the \s-1REPLACEMENT\s0 \s-1CHARACTER\s0 and does not raise a warning message. .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 (see \*(L"\s-1BUGS\s0\*(R" for the others), vianame 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. 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, .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 \fItranslator()\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. 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\s0 \s-1ALIASES\s0\*(R" above for restrictions on \fI\s-1CHARNAME\s0\fR. .PP Of course, \f(CW\*(C`vianame\*(C'\fR and \f(CW\*(C`viacode\*(C'\fR would need to be overridden as well. .SH "BUGS" .IX Header "BUGS" vianame 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 Names must be \s-1ASCII\s0 characters only, which means that you are out of luck if you want to create aliases in a language where some or all the characters of the desired aliases are non-ASCII. .PP Since evaluation of the translation function (see \*(L"\s-1CUSTOM\s0 \&\s-1TRANSLATORS\s0\*(R") 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.