summaryrefslogtreecommitdiff
path: root/lib/charnames.pm
diff options
context:
space:
mode:
authorKarl Williamson <khw@khw-desktop.(none)>2010-07-13 13:15:10 -0600
committerKarl Williamson <khw@khw-desktop.(none)>2010-07-13 17:15:54 -0600
commitdc023ef4ba9dbad8f45a2001a409b7f4b7371f6b (patch)
tree1fc4d42736b460d628ba9342bbf694f79991be56 /lib/charnames.pm
parent8a684a5bc8fbe6717bed6db3793eea95bd53d41d (diff)
downloadperl-dc023ef4ba9dbad8f45a2001a409b7f4b7371f6b.tar.gz
charnames.pm: refactor so complex re is used once
The :short option which looks like "greek:letter" is just a special case of the option where a list of possible scripts is set up in the pragma call. In this case, greek is the single script to look up. It also turns out that, contrary to the prior code, :short is effectively mutually exclusive of checking through that list of scripts. That is, "greek:letter" didn't match in the :short option, it won't match any script option either because ':' is not a legal character in a name. So there is no need to execute both. I refactored the code to do an if then else because of this. And they both use the same complicated regex that I may have to change in future patches. So I refactored the code to use the same re Finally, I added a goto to eliminate a test.
Diffstat (limited to 'lib/charnames.pm')
-rw-r--r--lib/charnames.pm51
1 files changed, 27 insertions, 24 deletions
diff --git a/lib/charnames.pm b/lib/charnames.pm
index 426775dd49..dfe4ab4e90 100644
--- a/lib/charnames.pm
+++ b/lib/charnames.pm
@@ -2,7 +2,7 @@ package charnames;
use strict;
use warnings;
use File::Spec;
-our $VERSION = '1.12';
+our $VERSION = '1.13';
use bytes (); # for $bytes::hint_bits
@@ -576,35 +576,38 @@ sub lookup_name ($;$) {
# If we didn't get it above keep looking
if (! $found_full_in_table) {
- # If :short is allowed, look for the short name, which is like
- # "greek:Sigma"
+ # If :short is allowed, see if input is like "greek:Sigma".
+ my $scripts_ref;
+ my $name_ref;
if (($^H{charnames_short})
- && $name =~ /^ \s* (.+?) \s* : \s* (.+?) \s* $ /xs) {
- my ($script, $cname) = ($1, $2);
- my $case = $cname =~ /[[:upper:]]/ ? "CAPITAL" : "SMALL";
- if ($txt =~ m/\t\t\U$script\E (?:$case )?LETTER \U\Q$cname\E$/m) {
+ && $name =~ /^ \s* (.+?) \s* : \s* (.+?) \s* $ /xs)
+ {
+ my @script = uc $1;
+ my $character_name = $2;
+ $scripts_ref = \@script;
+ $name_ref = \$character_name;
+ }
+ else {
+ $scripts_ref = $^H{charnames_scripts};
+ $name_ref = \$name;
+ }
+
+ my $case = $$name_ref =~ /[[:upper:]]/ ? "CAPITAL" : "SMALL";
+ for my $script (@{$scripts_ref}) {
+ if ($txt =~
+ m/\t\t \Q$script\E \ (?:$case\ )? LETTER \ \U\Q$$name_ref\E $/xm)
+ {
@off = ($-[0] + 2, $+[0]);
+ goto found_one;
}
}
- ## If we still don't have it, check for the name among the loaded
- ## scripts.
- unless (@off) {
- my $case = $name =~ /[[:upper:]]/ ? "CAPITAL" : "SMALL";
- for my $script (@{$^H{charnames_scripts}}) {
- if ($txt =~ m/\t\t$script (?:$case )?LETTER \U\Q$name\E$/m) {
- @off = ($-[0] + 2, $+[0]);
- last;
- }
- }
+ # Here we still don't have it, give up.
+ return if $runtime;
+ carp "Unknown charname '$name'";
+ return 0xFFFD;
- ## If we don't have it by now, give up.
- unless (@off) {
- return if $runtime;
- carp "Unknown charname '$name'";
- return 0xFFFD;
- }
- }
+found_one:
}
##