In Perl_apply, the name of the op can be found from PL_op_name, instead
[p5sagit/p5-mst-13.2.git] / lib / charnames.pm
index 3457b8b..54f5179 100644 (file)
@@ -1,9 +1,8 @@
 package charnames;
 use strict;
 use warnings;
-use Carp;
 use File::Spec;
-our $VERSION = '1.02';
+our $VERSION = '1.05';
 
 use bytes ();          # for $bytes::hint_bits
 $charnames::hint_bits = 0x20000; # HINT_LOCALIZE_HH
@@ -44,6 +43,16 @@ my %alias3 = (
            );
 my $txt;
 
+sub croak
+{
+  require Carp; goto &Carp::croak;
+} # croak
+
+sub carp
+{
+  require Carp; goto &Carp::carp;
+} # carp
+
 sub alias (@)
 {
   @_ or return %alias3;
@@ -190,8 +199,8 @@ sub import
   ## fill %h keys with our @_ args.
   ##
   my ($promote, %h, @args) = (0);
-  while (@_ and $_ = shift) {
-    if ($_ eq ":alias") {
+  while (my $arg = shift) {
+    if ($arg eq ":alias") {
       @_ or
        croak ":alias needs an argument in charnames";
       my $alias = shift;
@@ -210,11 +219,11 @@ sub import
       alias_file ($alias);
       next;
     }
-    if (m/^:/ and ! ($_ eq ":full" || $_ eq ":short")) {
-      warn "unsupported special '$_' in charnames";
+    if (substr($arg, 0, 1) eq ':' and ! ($arg eq ":full" || $arg eq ":short")) {
+      warn "unsupported special '$arg' in charnames";
       next;
     }
-    push @args, $_;
+    push @args, $arg;
   }
   @args == 0 && $promote and @args = (":full");
   @h{@args} = (1) x @args;
@@ -238,30 +247,31 @@ sub import
   }
 } # import
 
-require Unicode::UCD; # for Unicode::UCD::_getcode()
-
 my %viacode;
 
 sub viacode
 {
   if (@_ != 1) {
     carp "charnames::viacode() expects one argument";
-    return ()
+    return;
   }
 
   my $arg = shift;
-  my $code = Unicode::UCD::_getcode($arg);
 
+  # this comes actually from Unicode::UCD, where it is the named
+  # function _getcode (), but it avoids the overhead of loading it
   my $hex;
-
-  if (defined $code) {
+  if ($arg =~ /^[1-9]\d*$/) {
     $hex = sprintf "%04X", $arg;
+  } elsif ($arg =~ /^(?:[Uu]\+|0[xX])?([[:xdigit:]]+)$/) {
+    $hex = $1;
   } else {
     carp("unexpected arg \"$arg\" to charnames::viacode()");
     return;
   }
 
-  if ($code > 0x10FFFF) {
+  # checking the length first is slightly faster
+  if (length($hex) > 5 && hex($hex) > 0x10FFFF) {
     carp sprintf "Unicode characters only allocated up to U+10FFFF (you asked for U+%X)", $hex;
     return;
   }
@@ -270,11 +280,9 @@ sub viacode
 
   $txt = do "unicore/Name.pl" unless $txt;
 
-  if ($txt =~ m/^$hex\t\t(.+)/m) {
-    return $viacode{$hex} = $1;
-  } else {
-    return;
-  }
+  return unless $txt =~ m/^$hex\t\t(.+)/m;
+
+  $viacode{$hex} = $1;
 } # viacode
 
 my %vianame;