From: Karl Williamson Date: Tue, 1 Mar 2011 14:50:11 +0000 (-0700) Subject: UCD.pm: Convert num() to use new fcn X-Git-Tag: accepted/trunk/20130322.191538~5234 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=98025745287774eee2205646801176660f6268b6;p=platform%2Fupstream%2Fperl.git UCD.pm: Convert num() to use new fcn A new function that reads mktables files has been created. Switch to use this. A test is added to make sure it's working right --- diff --git a/lib/Unicode/UCD.pm b/lib/Unicode/UCD.pm index de60ce3..4404881 100644 --- a/lib/Unicode/UCD.pm +++ b/lib/Unicode/UCD.pm @@ -1230,27 +1230,32 @@ sub _numeric { if ((pack "C*", split /\./, UnicodeVersion()) lt 6.0.0) { croak __PACKAGE__, "::num requires Unicode 6.0 or greater" } - my @temp = split /^/m, do "unicore/To/Nv.pl"; - foreach my $line (@temp) { - chomp $line; - my @value = split /\t\t/, $line; - if ((my @rational = split /\//, $value[1]) == 2) { - $value[1] = $rational[0] / $rational[1]; + my @numbers = _read_table("unicore/To/Nv.pl"); + foreach my $entry (@numbers) { + my ($start, $end, $value) = @$entry; + + # If value contains a slash, convert to decimal + if ((my @rational = split /\//, $value) == 2) { + my $real = $rational[0] / $rational[1]; + $value = $real; + } + + for my $i ($start .. $end) { + $NUMERIC{$i} = $value; } - $NUMERIC{$value[0]} = $value[1]; } # Decided unsafe to use these that aren't officially part of the Unicode # standard. #use Math::Trig; #my $pi = acos(-1.0); - #$NUMERIC{"03C0"} = $pi; + #$NUMERIC{0x03C0} = $pi; # Euler's constant, not to be confused with Euler's number - #$NUMERIC{"2107"} = 0.57721566490153286060651209008240243104215933593992; + #$NUMERIC{0x2107} = 0.57721566490153286060651209008240243104215933593992; # Euler's number - #$NUMERIC{"212F"} = 2.7182818284590452353602874713526624977572; + #$NUMERIC{0x212F} = 2.7182818284590452353602874713526624977572; return; } @@ -1317,10 +1322,10 @@ sub num { _numeric unless %NUMERIC; my $length = length($string); - return $NUMERIC{sprintf("%04X", ord($string))} if $length == 1; + return $NUMERIC{ord($string)} if $length == 1; return if $string =~ /\D/; my $first_ord = ord(substr($string, 0, 1)); - my $value = $NUMERIC{sprintf("%04X", $first_ord)}; + my $value = $NUMERIC{$first_ord}; my $zero_ord = $first_ord - $value; for my $i (1 .. $length -1) { diff --git a/lib/Unicode/UCD.t b/lib/Unicode/UCD.t index 01276f2..63d0aad 100644 --- a/lib/Unicode/UCD.t +++ b/lib/Unicode/UCD.t @@ -17,7 +17,7 @@ use strict; use Unicode::UCD; use Test::More; -BEGIN { plan tests => 268 }; +BEGIN { plan tests => 269 }; use Unicode::UCD 'charinfo'; @@ -461,3 +461,4 @@ ok(! defined num("\N{CHAM DIGIT ZERO}\N{JAVANESE DIGIT NINE}"), 'Verify num("\N{ is(num("\N{SUPERSCRIPT TWO}"), 2, 'Verify num("\N{SUPERSCRIPT TWO} == 2'); is(num("\N{ETHIOPIC NUMBER TEN THOUSAND}"), 10000, 'Verify num("\N{ETHIOPIC NUMBER TEN THOUSAND}") == 10000'); is(num("\N{NORTH INDIC FRACTION ONE HALF}"), .5, 'Verify num("\N{NORTH INDIC FRACTION ONE HALF}") == .5'); +is(num("\N{U+12448}"), 9, 'Verify num("\N{U+12448}") == 9');