perl
view release on metacpan or search on metacpan
lib/Unicode/UCD.pm view on Meta::CPAN
no warnings;
eval { kill 0 * $prop };
$tainted = 1 if $@ =~ /^Insecure/;
}
die "Insecure user-defined property \\p{$prop}\n"
if $tainted;
no strict 'refs';
$list = &{$prop}($caseless);
$user_defined = 1;
last GETFILE;
}
}
require "$unicore_dir/UCD.pl";
# All property names are matched caselessly
my $property_and_table = CORE::lc $type;
print STDERR __LINE__, ": $property_and_table\n" if DEBUG;
# See if is of the compound form 'property=value', where the
# value indicates the table we should use.
my ($property, $table, @remainder) =
split /\s*[:=]\s*/, $property_and_table, -1;
if (@remainder) {
pop @recursed if @recursed;
return $type;
}
my $prefix;
if (! defined $table) {
# Here, is the single form. The property becomes empty, and
# the whole value is the table.
$table = $property;
$prefix = $property = "";
} else {
print STDERR __LINE__, ": $property\n" if DEBUG;
# Here it is the compound property=table form. The property
# name is always loosely matched, and always can have an
# optional 'is' prefix (which isn't true in the single
# form).
$property = loose_name($property) =~ s/^is//r;
# And convert to canonical form. Quit if not valid.
$property = $loose_property_name_of{$property};
if (! defined $property) {
pop @recursed if @recursed;
return $type;
}
$prefix = "$property=";
# If the rhs looks like it is a number...
print STDERR __LINE__, ": table=$table\n" if DEBUG;
if ($table =~ $number) {
print STDERR __LINE__, ": table=$table\n" if DEBUG;
# Split on slash, in case it is a rational, like \p{1/5}
my @parts = split m{ \s* / \s* }x, $table, -1;
print __LINE__, ": $type\n" if @parts > 2 && DEBUG;
foreach my $part (@parts) {
print __LINE__, ": part=$part\n" if DEBUG;
$part =~ s/^\+\s*//; # Remove leading plus
$part =~ s/^-\s*/-/; # Remove blanks after unary
# minus
# Remove underscores between digits.
$part =~ s/(?<= [0-9] ) _ (?= [0-9] ) //xg;
# No leading zeros (but don't make a single '0'
# into a null string)
$part =~ s/ ^ ( -? ) 0+ /$1/x;
$part .= '0' if $part eq '-' || $part eq "";
# No trailing zeros after a decimal point
$part =~ s/ ( \. [0-9]*? ) 0+ $ /$1/x;
# Begin with a 0 if a leading decimal point
$part =~ s/ ^ ( -? ) \. /${1}0./x;
# Ensure not a trailing decimal point: turn into an
# integer
$part =~ s/ \. $ //x;
print STDERR __LINE__, ": part=$part\n" if DEBUG;
#return $type if $part eq "";
}
# If a rational...
if (@parts == 2) {
# If denominator is negative, get rid of it, and ...
if ($parts[1] =~ s/^-//) {
# If numerator is also negative, convert the
# whole thing to positive, else move the minus
# to the numerator
if ($parts[0] !~ s/^-//) {
$parts[0] = '-' . $parts[0];
}
}
$table = join '/', @parts;
}
elsif ($property ne 'nv' || $parts[0] !~ /\./) {
# Here is not numeric value, or doesn't have a
# decimal point. No further manipulation is
# necessary. (Note the hard-coded property name.
# This could fail if other properties eventually
# had fractions as well; perhaps the cjk ones
# could evolve to do that. This hard-coding could
# be fixed by mktables generating a list of
# properties that could have fractions.)
$table = $parts[0];
} else {
# Here is a floating point numeric_value. Convert
( run in 1.314 second using v1.01-cache-2.11-cpan-71847e10f99 )