diff options
-rw-r--r-- | charclass_invlists.h | 2 | ||||
-rw-r--r-- | lib/unicore/mktables | 52 | ||||
-rw-r--r-- | regcharclass.h | 2 |
3 files changed, 52 insertions, 4 deletions
diff --git a/charclass_invlists.h b/charclass_invlists.h index 2ee1e38d46..26f7632cd9 100644 --- a/charclass_invlists.h +++ b/charclass_invlists.h @@ -97321,7 +97321,7 @@ static const UV XPosixXDigit_invlist[] = { /* for EBCDIC POSIX-BC */ * a9791f08281d7b0a417e4ad882cf64463f6815db8156932acd85228ac717fd94 lib/unicore/extracted/DLineBreak.txt * a17a0330e57d774343a53c019f1bc69827c2676982a1bf48e0898a76710e8877 lib/unicore/extracted/DNumType.txt * c2cb810a67cc5fb4a8d236b6c1bc6dd4d89733d8603881997e8aae2c816a3db1 lib/unicore/extracted/DNumValues.txt - * 868dbf83a2c62170b63a1fc4f52e11d0a32c8af0f7833dd7823c6ca496cc0d9c lib/unicore/mktables + * 23509f3190e5de421bea70bc351fe6f853b750bf418d62d967331ee3ba11a1ec lib/unicore/mktables * 746472de66b936ac885ca6d6e68058242b4e909e3260c6317f3ec719f78f76cc lib/unicore/version * 4360c31f23eb368e0f3bfd045a44d3bc37ff0889e216f686ebea02543ac188d9 regen/mk_invlists.pl * ex: set ro: */ diff --git a/lib/unicore/mktables b/lib/unicore/mktables index 8a4100c69f..bd312c4cdd 100644 --- a/lib/unicore/mktables +++ b/lib/unicore/mktables @@ -11162,8 +11162,10 @@ END $fields[$NUMERIC_TYPE_OTHER_DIGIT] = 'Numeric'; # Rationals require extra effort. - register_fraction($fields[$NUMERIC]) - if $fields[$NUMERIC] =~ qr{/}; + if ($fields[$NUMERIC] =~ qr{/}) { + reduce_fraction(\$fields[$NUMERIC]); + register_fraction($fields[$NUMERIC]) + } } } @@ -12201,6 +12203,50 @@ sub register_fraction($) { return; } +sub gcd($$) { # Greatest-common-divisor; from + # http://en.wikipedia.org/wiki/Euclidean_algorithm + my ($a, $b) = @_; + + use integer; + + while ($b != 0) { + my $temp = $b; + $b = $a % $b; + $a = $temp; + } + return $a; +} + +sub reduce_fraction($) { + my $fraction_ref = shift; + + # Reduce a fraction to lowest terms. The Unicode data may be reducible, + # hence this is needed. The argument is a reference to the + # string denoting the fraction, which must be of the form: + if ($$fraction_ref !~ / ^ (-?) (\d+) \/ (\d+) $ /ax) { + Carp::my_carp_bug("Non-fraction input '$$fraction_ref'. Unchanged"); + return; + } + + my $sign = $1; + my $numerator = $2; + my $denominator = $3; + + use integer; + + # Find greatest common divisor + my $gcd = gcd($numerator, $denominator); + + # And reduce using the gcd. + if ($gcd != 1) { + $numerator /= $gcd; + $denominator /= $gcd; + $$fraction_ref = "$sign$numerator/$denominator"; + } + + return; +} + sub filter_numeric_value_line { # DNumValues contains lines of a different syntax than the typical # property file: @@ -12225,7 +12271,9 @@ sub filter_numeric_value_line { $_ = ""; return; } + reduce_fraction(\$fields[3]) if $fields[3] =~ qr{/}; $rational = $fields[3]; + $_ = join '; ', @fields[ 0, 3 ]; } else { diff --git a/regcharclass.h b/regcharclass.h index 00e451576d..a93b66460b 100644 --- a/regcharclass.h +++ b/regcharclass.h @@ -2514,7 +2514,7 @@ * a9791f08281d7b0a417e4ad882cf64463f6815db8156932acd85228ac717fd94 lib/unicore/extracted/DLineBreak.txt * a17a0330e57d774343a53c019f1bc69827c2676982a1bf48e0898a76710e8877 lib/unicore/extracted/DNumType.txt * c2cb810a67cc5fb4a8d236b6c1bc6dd4d89733d8603881997e8aae2c816a3db1 lib/unicore/extracted/DNumValues.txt - * 868dbf83a2c62170b63a1fc4f52e11d0a32c8af0f7833dd7823c6ca496cc0d9c lib/unicore/mktables + * 23509f3190e5de421bea70bc351fe6f853b750bf418d62d967331ee3ba11a1ec lib/unicore/mktables * 746472de66b936ac885ca6d6e68058242b4e909e3260c6317f3ec719f78f76cc lib/unicore/version * 3eaedce3745bef6219cff3b5f63e5f8622c58dc66736281a82df991636d54451 regen/regcharclass.pl * ex: set ro: */ |