X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fcharnames.pm;h=f895d3796731e0e0397ee4fb71473c9f1269d29f;hb=c74ace89800a81a764294e9f6eacc04bbed5a568;hp=7b39cee83c7f4a4a2085398f6056256cde592638;hpb=9cfe5470b44e33f00045a3b9c3128c6ade6e813f;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/charnames.pm b/lib/charnames.pm index 7b39cee..f895d37 100644 --- a/lib/charnames.pm +++ b/lib/charnames.pm @@ -3,7 +3,7 @@ use strict; use warnings; use Carp; use File::Spec; -our $VERSION = '1.02'; +our $VERSION = '1.04'; use bytes (); # for $bytes::hint_bits $charnames::hint_bits = 0x20000; # HINT_LOCALIZE_HH @@ -107,7 +107,7 @@ sub charnames ## @off will hold the index into the code/name string of the start and ## end of the name as we find it. - ## If :full, look for the the name exactly + ## If :full, look for the name exactly if ($^H{charnames_full} and $txt =~ /\t\t\Q$name\E$/m) { @off = ($-[0], $+[0]); } @@ -190,8 +190,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 +210,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,7 +238,19 @@ sub import } } # import -require Unicode::UCD; # for Unicode::UCD::_getcode() +# this comes actually from Unicode::UCD, but it avoids the +# overhead of loading it +sub _getcode { + my $arg = shift; + + if ($arg =~ /^[1-9]\d*$/) { + return $arg; + } elsif ($arg =~ /^(?:[Uu]\+|0[xX])?([[:xdigit:]]+)$/) { + return hex($1); + } + + return; +} my %viacode; @@ -250,7 +262,7 @@ sub viacode } my $arg = shift; - my $code = Unicode::UCD::_getcode($arg); + my $code = _getcode($arg); my $hex; @@ -333,9 +345,10 @@ charnames - define character names for C<\N{named}> string literal escapes use charnames ":full", ":alias" => { e_ACUTE => "LATIN SMALL LETTER E WITH ACUTE", - }; + }; print "\N{e_ACUTE} is a small letter e with an acute.\n"; + use charnames (); print charnames::viacode(0x1234); # prints "ETHIOPIC SYLLABLE SEE" printf "%04X", charnames::vianame("GOTHIC LETTER AHSA"); # prints "10330" @@ -343,8 +356,8 @@ charnames - define character names for C<\N{named}> string literal escapes Pragma C supports arguments C<:full>, C<:short>, script names and customized aliases. If C<:full> is present, for expansion of -C<\N{CHARNAME}> string C is first looked in the list of -standard Unicode names of chars. If C<:short> is present, and +C<\N{CHARNAME}>, the string C is first looked up in the list of +standard Unicode character names. If C<:short> is present, and C has the form C, then C is looked up as a letter in script C