Can't get #17492 to work with -Uuseperlio otherwise (either
[p5sagit/p5-mst-13.2.git] / lib / charnames.pm
index d9cf7fa..fc3ad8b 100644 (file)
@@ -16,7 +16,7 @@ my %alias1 = (
                # Convenience.
                'LF'                    => 'LINE FEED (LF)',
                'FF'                    => 'FORM FEED (FF)',
-               'CR'                    => 'CARRIAGE RETURN (LF)',
+               'CR'                    => 'CARRIAGE RETURN (CR)',
                'NEL'                   => 'NEXT LINE (NEL)',
                # More convenience.  For futher convencience,
                # it is suggested some way using using the NamesList
@@ -203,7 +203,7 @@ sub viacode
     }
 
     if ($code > 0x10FFFF) {
-       carp "Unicode characters only allocated up to 0x10FFFF (you asked for $hex)";
+       carp sprintf "Unicode characters only allocated up to U+10FFFF (you asked for U+%X)", $hex;
        return;
     }
 
@@ -235,8 +235,19 @@ sub vianame
 
     $txt = do "unicore/Name.pl" unless $txt;
 
-    if ($txt =~ m/^([0-9A-F]+)\t\t($arg)/m) {
-        return $vianame{$arg} = hex $1;
+    my $pos = index $txt, "\t\t$arg\n";
+    if ($[ <= $pos) {
+       my $posLF = rindex $txt, "\n", $pos;
+       (my $code = substr $txt, $posLF + 1, 6) =~ tr/\t//d;
+       return $vianame{$arg} = hex $code;
+
+       # If $pos is at the 1st line, $posLF must be $[ - 1 (not found);
+       # then $posLF + 1 equals to $[ (at the beginning of $txt).
+       # Otherwise $posLF is the position of "\n";
+       # then $posLF + 1 must be the position of the next to "\n"
+       # (the beginning of the line).
+       # substr($txt, $posLF + 1, 6) may be "0000\t\t", "00A1\t\t",
+       # "10300\t", "100000", etc. So we can get the code via removing TAB.
     } else {
         return;
     }
@@ -268,11 +279,11 @@ charnames - define character names for C<\N{named}> string literal escapes
 
 Pragma C<use charnames> supports arguments C<:full>, C<:short> and
 script names.  If C<:full> is present, for expansion of
-C<\N{CHARNAME}}> string C<CHARNAME> is first looked in the list of
+C<\N{CHARNAME}> string C<CHARNAME> is first looked in the list of
 standard Unicode names of chars.  If C<:short> is present, and
 C<CHARNAME> has the form C<SCRIPT:CNAME>, then C<CNAME> is looked up
 as a letter in script C<SCRIPT>.  If pragma C<use charnames> is used
-with script name arguments, then for C<\N{CHARNAME}}> the name
+with script name arguments, then for C<\N{CHARNAME}> the name
 C<CHARNAME> is looked up as a letter in the given scripts (in the
 specified order).
 
@@ -349,7 +360,7 @@ to custom translators.
 Notice that the name returned for of U+FEFF is "ZERO WIDTH NO-BREAK
 SPACE", not "BYTE ORDER MARK".
 
-=head1 charnames::vianame(code)
+=head1 charnames::vianame(name)
 
 Returns the code point indicated by the name.
 The example
@@ -358,9 +369,9 @@ The example
 
 prints "2722".
 
-Returns undef if no name is known for the name.
+Returns undef if the name is unknown.
 
-This works only for the standard names, and does not yet aply 
+This works only for the standard names, and does not yet apply 
 to custom translators.
 
 =head1 ALIASES
@@ -415,8 +426,12 @@ will also give a warning about being deprecated.
 
 =head1 ILLEGAL CHARACTERS
 
-If you ask for a character that does not exist, a warning is given
-and the Unicode I<replacement character> "\x{FFFD}" is returned.
+If you ask by name for a character that does not exist, a warning is
+given and the Unicode I<replacement character> "\x{FFFD}" is returned.
+
+If you ask by code for a character that does not exist, no warning is
+given and C<undef> is returned.  (Though if you ask for a code point
+past U+10FFFF you do get a warning.)
 
 =head1 BUGS