Skip to content

Commit

Permalink
fix escapes in range patterns [#42]
Browse files Browse the repository at this point in the history
this issue was discovered using preliminary CLDR v28 data
  • Loading branch information
patch committed Sep 1, 2015
1 parent a02f951 commit 572d10d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ t/objects.t
t/pattern-coerce.t
t/pattern-trigger.t
t/quoting.t
t/range.t
t/rounding.t
16 changes: 11 additions & 5 deletions bin/generate-cldr-data.pl
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,18 @@ sub quote_key {
sub escape_control {
my ($str) = @_;

return $str =~ /"/ ? qq{qq[$str]} : qq{"$str"}
if $str =~ s{ ( \p{Cf} ) }{
'\\N{' . charinfo(ord $1)->{name} . '}'
}xeg;
for ($str) {
if ($str ne q[']) {
s{ (?<! ' ) ' (?! ' ) }{}xg;
}

return $str =~ /'/ ? qq{q[$str]} : qq{'$str'};
s{''}{'}g;
s{ ( \p{Cf} ) }{ '\\N{' . charinfo(ord $1)->{name} . '}' }xeg;
}

return qq["$str"] if $str =~ /\\/;
return "q[$str]" if $str =~ /'/;
return "'$str'";
}

sub parents {
Expand Down
4 changes: 2 additions & 2 deletions lib/CLDR/Number/Data/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ our $DATA = {
pattern => {
currency => '¤ #,##0.00',
percent => '#,##0%',
range => q['de' {0} 'a' {1}],
range => 'de {0} a {1}',
},
symbol => {
decimal => ',',
Expand Down Expand Up @@ -656,7 +656,7 @@ our $DATA = {
},
'es-GT' => {
pattern => {
range => q[{0} 'al' {1}],
range => '{0} al {1}',
},
},
'es-MX' => {
Expand Down
2 changes: 0 additions & 2 deletions t/inf-nan.t
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use utf8;
use strict;
use warnings;
use charnames qw( :full );
use open qw( :encoding(UTF-8) :std );
use Test::More tests => 25;
use Test::Warn;
use CLDR::Number;

my $inf = 9**9**9;
Expand Down
26 changes: 26 additions & 0 deletions t/range.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use utf8;
use strict;
use warnings;
use open qw( :encoding(UTF-8) :std );
use Test::More tests => 6;
use CLDR::Number;

my ($cldr, $decf, $perf, $curf);

$cldr = CLDR::Number->new(locale => 'en');
$decf = $cldr->decimal_formatter;
$perf = $cldr->percent_formatter;
$curf = $cldr->currency_formatter(currency_code => 'EUR');

is $decf->range(1, 5), '1–5', 'range of numbers (en)';
is $perf->range(0.01, 0.05), '1%–5%', 'range of percents (en)';
is $curf->range(1, 5), '€1.00–€5.00', 'range of prices (en)';

$cldr = CLDR::Number->new(locale => 'es-CO');
$decf = $cldr->decimal_formatter;
$perf = $cldr->percent_formatter;
$curf = $cldr->currency_formatter(currency_code => 'COP');

is $decf->range(1, 5), 'de 1 a 5', 'range of numbers (es-CO)';
is $perf->range(0.01, 0.05), 'de 1% a 5%', 'range of percents (es-CO)';
is $curf->range(1, 5), 'de $ 1,00 a $ 5,00', 'range of prices (es-CO)';

0 comments on commit 572d10d

Please sign in to comment.