line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Locale::CLDR::NumberFormatter; |
2
|
|
|
|
|
|
|
|
3
|
20
|
|
|
20
|
|
14714
|
use version; |
|
20
|
|
|
|
|
45
|
|
|
20
|
|
|
|
|
141
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = version->declare('v0.28.1'); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
20
|
|
|
20
|
|
2037
|
use v5.10.1; |
|
20
|
|
|
|
|
73
|
|
9
|
20
|
|
|
20
|
|
111
|
use mro 'c3'; |
|
20
|
|
|
|
|
38
|
|
|
20
|
|
|
|
|
139
|
|
10
|
20
|
|
|
20
|
|
727
|
use utf8; |
|
20
|
|
|
|
|
45
|
|
|
20
|
|
|
|
|
131
|
|
11
|
20
|
|
|
20
|
|
684
|
use if $^V ge v5.12.0, feature => 'unicode_strings'; |
|
20
|
|
|
|
|
41
|
|
|
20
|
|
|
|
|
270
|
|
12
|
|
|
|
|
|
|
|
13
|
20
|
|
|
20
|
|
2213
|
use Moose::Role; |
|
20
|
|
|
|
|
44
|
|
|
20
|
|
|
|
|
384
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub format_number { |
16
|
761
|
|
|
761
|
0
|
1467
|
my ($self, $number, $format, $currency, $for_cash) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Check if the locales numbering system is algorithmic. If so ignore the format |
19
|
761
|
|
|
|
|
2677
|
my $numbering_system = $self->default_numbering_system(); |
20
|
761
|
50
|
|
|
|
29153
|
if ($self->numbering_system->{$numbering_system}{type} eq 'algorithmic') { |
21
|
0
|
|
|
|
|
0
|
$format = $self->numbering_system->{$numbering_system}{data}; |
22
|
0
|
|
|
|
|
0
|
return $self->_algorithmic_number_format($number, $format); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
761
|
|
100
|
|
|
3068
|
$format //= '0'; |
26
|
|
|
|
|
|
|
|
27
|
761
|
|
|
|
|
1947
|
return $self->_format_number($number, $format, $currency, $for_cash); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub format_currency { |
31
|
8
|
|
|
8
|
0
|
25
|
my ($self, $number, $for_cash) = @_; |
32
|
|
|
|
|
|
|
|
33
|
8
|
|
|
|
|
37
|
my $format = $self->currency_format; |
34
|
8
|
|
|
|
|
34
|
return $self->format_number($number, $format, undef(), $for_cash); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _format_number { |
38
|
763
|
|
|
763
|
|
1585
|
my ($self, $number, $format, $currency, $for_cash) = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# First check to see if this is an algorithmic format |
41
|
763
|
|
|
|
|
1860
|
my @valid_formats = $self->_get_valid_algorithmic_formats(); |
42
|
|
|
|
|
|
|
|
43
|
763
|
100
|
|
|
|
1972
|
if (grep {$_ eq $format} @valid_formats) { |
|
15260
|
|
|
|
|
28087
|
|
44
|
5
|
|
|
|
|
17
|
return $self->_algorithmic_number_format($number, $format); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Some of these algorithmic formats are in locale/type/name format |
48
|
758
|
50
|
|
|
|
2163
|
if (my ($locale_id, $type, $format) = $format =~ m(^(.*?)/(.*?)/(.*?)$)) { |
49
|
0
|
|
|
|
|
0
|
my $locale = Locale::CLDR->new($locale_id); |
50
|
0
|
|
|
|
|
0
|
return $locale->format_number($number, $format); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
758
|
|
|
|
|
785
|
my $currency_data; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Check if we need a currency and have not been given one. |
56
|
|
|
|
|
|
|
# In that case we look up the default currency for the locale |
57
|
758
|
100
|
|
|
|
2555
|
if ($format =~ tr/¤/¤/) { |
58
|
|
|
|
|
|
|
|
59
|
9
|
|
100
|
|
|
35
|
$for_cash //=0; |
60
|
|
|
|
|
|
|
|
61
|
9
|
50
|
|
|
|
53
|
$currency = $self->default_currency() |
62
|
|
|
|
|
|
|
if ! defined $currency; |
63
|
|
|
|
|
|
|
|
64
|
9
|
|
|
|
|
37
|
$currency_data = $self->_get_currency_data($currency); |
65
|
|
|
|
|
|
|
|
66
|
9
|
|
|
|
|
38
|
$currency = $self->currency_symbol($currency); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
758
|
|
|
|
|
2075
|
$format = $self->parse_number_format($format, $currency, $currency_data, $for_cash); |
70
|
|
|
|
|
|
|
|
71
|
758
|
|
|
|
|
2378
|
$number = $self->get_formatted_number($number, $format, $currency_data, $for_cash); |
72
|
|
|
|
|
|
|
|
73
|
758
|
|
|
|
|
4199
|
return $number; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub add_currency_symbol { |
77
|
9
|
|
|
9
|
0
|
18
|
my ($self, $format, $symbol) = @_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
9
|
|
|
|
|
69
|
$format =~ s/¤/'$symbol'/g; |
81
|
|
|
|
|
|
|
|
82
|
9
|
|
|
|
|
33
|
return $format; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _get_currency_data { |
86
|
9
|
|
|
9
|
|
18
|
my ($self, $currency) = @_; |
87
|
|
|
|
|
|
|
|
88
|
9
|
|
|
|
|
39
|
my $currency_data = $self->currency_fractions($currency); |
89
|
|
|
|
|
|
|
|
90
|
9
|
|
|
|
|
22
|
return $currency_data; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _get_currency_rounding { |
94
|
|
|
|
|
|
|
|
95
|
18
|
|
|
18
|
|
32
|
my ($self, $currency_data, $for_cash) = @_; |
96
|
|
|
|
|
|
|
|
97
|
18
|
100
|
|
|
|
47
|
my $rounder = $for_cash ? 'cashrounding' : 'rounding' ; |
98
|
|
|
|
|
|
|
|
99
|
18
|
|
|
|
|
43
|
return $currency_data->{$rounder}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub _get_currency_digits { |
103
|
9
|
|
|
9
|
|
20
|
my ($self, $currency_data, $for_cash) = @_; |
104
|
|
|
|
|
|
|
|
105
|
9
|
100
|
|
|
|
27
|
my $digits = $for_cash ? 'cashdigits' : 'digits' ; |
106
|
|
|
|
|
|
|
|
107
|
9
|
|
|
|
|
28
|
return $currency_data->{$digits}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub parse_number_format { |
111
|
760
|
|
|
760
|
0
|
1458
|
my ($self, $format, $currency, $currency_data, $for_cash) = @_; |
112
|
|
|
|
|
|
|
|
113
|
20
|
|
|
20
|
|
128406
|
use feature 'state'; |
|
20
|
|
|
|
|
54
|
|
|
20
|
|
|
|
|
11352
|
|
114
|
|
|
|
|
|
|
|
115
|
760
|
|
|
|
|
798
|
state %cache; |
116
|
|
|
|
|
|
|
|
117
|
760
|
100
|
|
|
|
2754
|
return $cache{$format} if exists $cache{$format}; |
118
|
|
|
|
|
|
|
|
119
|
18
|
100
|
|
|
|
72
|
$format = $self->add_currency_symbol($format, $currency) |
120
|
|
|
|
|
|
|
if defined $currency; |
121
|
|
|
|
|
|
|
|
122
|
18
|
|
|
|
|
155
|
my ($positive, $negative) = $format =~ /^( (?: (?: ' [^']* ' )*+ | [^';]+ )+ ) (?: ; (.+) )? $/x; |
123
|
|
|
|
|
|
|
|
124
|
18
|
|
66
|
|
|
104
|
$negative //= "-$positive"; |
125
|
|
|
|
|
|
|
|
126
|
18
|
|
|
|
|
35
|
my $type = 'positive'; |
127
|
18
|
|
|
|
|
35
|
foreach my $to_parse ( $positive, $negative ) { |
128
|
36
|
|
|
|
|
60
|
my ($prefix, $suffix); |
129
|
36
|
100
|
|
|
|
229
|
if (($prefix) = $to_parse =~ /^ ( (?: [^0-9@#.,E'*] | (?: ' [^']* ' )++ )+ ) /x) { |
130
|
26
|
|
|
|
|
131
|
$to_parse =~ s/^ ( (?: [^0-9@#.,E'*] | (?: ' [^']* ' )++ )+ ) //x; |
131
|
|
|
|
|
|
|
} |
132
|
36
|
100
|
|
|
|
268
|
if( ($suffix) = $to_parse =~ / ( (?: [^0-9@#.,E'] | (?: ' [^']* ' )++ )+ ) $ /x) { |
133
|
11
|
|
|
|
|
88
|
$to_parse =~ s/( (?:[^0-9@#.,E'] | (?: ' [^']* ' )++ )+ ) $//x; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Fix escaped ', - and + |
137
|
36
|
|
|
|
|
69
|
foreach my $str ($prefix, $suffix) { |
138
|
72
|
|
100
|
|
|
197
|
$str //= ''; |
139
|
72
|
|
|
|
|
230
|
$str =~ s/(?: ' (?: (?: '' )++ | [^']+ ) ' )*? \K ( [-+\\] ) /\\$1/gx; |
140
|
72
|
|
|
|
|
177
|
$str =~ s/ ' ( (?: '' )++ | [^']++ ) ' /$1/gx; |
141
|
72
|
|
|
|
|
141
|
$str =~ s/''/'/g; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# Look for padding |
145
|
36
|
|
|
|
|
50
|
my ($pad_character, $pad_location); |
146
|
36
|
50
|
|
|
|
238
|
if (($pad_character) = $prefix =~ /^\*(\p{Any})/ ) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
147
|
0
|
|
|
|
|
0
|
$prefix =~ s/^\*(\p{Any})//; |
148
|
0
|
|
|
|
|
0
|
$pad_location = 'before prefix'; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
elsif ( ($pad_character) = $prefix =~ /\*(\p{Any})$/ ) { |
151
|
0
|
|
|
|
|
0
|
$prefix =~ s/\*(\p{Any})$//; |
152
|
0
|
|
|
|
|
0
|
$pad_location = 'after prefix'; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
elsif (($pad_character) = $suffix =~ /^\*(\p{Any})/ ) { |
155
|
0
|
|
|
|
|
0
|
$suffix =~ s/^\*(\p{Any})//; |
156
|
0
|
|
|
|
|
0
|
$pad_location = 'before suffix'; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
elsif (($pad_character) = $suffix =~ /\*(\p{Any})$/ ) { |
159
|
1
|
|
|
|
|
5
|
$suffix =~ s/\*(\p{Any})$//; |
160
|
1
|
|
|
|
|
2
|
$pad_location = 'after suffix'; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
36
|
100
|
|
|
|
86
|
my $pad_length = defined $pad_character |
164
|
|
|
|
|
|
|
? length($prefix) + length($to_parse) + length($suffix) + 2 |
165
|
|
|
|
|
|
|
: 0; |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# Check for a multiplier |
168
|
36
|
|
|
|
|
51
|
my $multiplier = 1; |
169
|
36
|
100
|
66
|
|
|
190
|
$multiplier = 100 if $prefix =~ tr/%/%/ || $suffix =~ tr/%/%/; |
170
|
36
|
100
|
66
|
|
|
243
|
$multiplier = 1000 if $prefix =~ tr/â°/â°/ || $suffix =~ tr/â°/â°/; |
171
|
|
|
|
|
|
|
|
172
|
36
|
|
|
|
|
93
|
my $rounding = $to_parse =~ / ( [1-9] [0-9]* (?: \. [0-9]+ )? ) /x; |
173
|
36
|
|
50
|
|
|
142
|
$rounding ||= 0; |
174
|
|
|
|
|
|
|
|
175
|
36
|
100
|
|
|
|
109
|
$rounding = $self->_get_currency_rounding($currency_data, $for_cash) |
176
|
|
|
|
|
|
|
if defined $currency; |
177
|
|
|
|
|
|
|
|
178
|
36
|
|
|
|
|
136
|
my ($integer, $decimal) = split /\./, $to_parse; |
179
|
|
|
|
|
|
|
|
180
|
36
|
|
|
|
|
65
|
my ($minimum_significant_digits, $maximum_significant_digits, $minimum_digits); |
181
|
36
|
50
|
|
|
|
102
|
if (my ($digits) = $to_parse =~ /(\@+)/) { |
182
|
0
|
|
|
|
|
0
|
$minimum_significant_digits = length $digits; |
183
|
0
|
|
|
|
|
0
|
($digits ) = $to_parse =~ /\@(#+)/; |
184
|
0
|
|
0
|
|
|
0
|
$maximum_significant_digits = $minimum_significant_digits + length ($digits // ''); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
else { |
187
|
36
|
|
|
|
|
74
|
$minimum_digits = $integer =~ tr/0-9/0-9/; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# Check for exponent |
191
|
36
|
|
|
|
|
52
|
my $exponent_digits = 0; |
192
|
36
|
|
|
|
|
43
|
my $need_plus = 0; |
193
|
36
|
|
|
|
|
54
|
my $exponent; |
194
|
|
|
|
|
|
|
my $major_group; |
195
|
0
|
|
|
|
|
0
|
my $minor_group; |
196
|
36
|
50
|
|
|
|
75
|
if ($to_parse =~ tr/E/E/) { |
197
|
0
|
|
|
|
|
0
|
($need_plus, $exponent) = $to_parse =~ m/ E ( \+? ) ( [0-9]+ ) /x; |
198
|
0
|
|
|
|
|
0
|
$exponent_digits = length $exponent; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
else { |
201
|
|
|
|
|
|
|
# Check for grouping |
202
|
36
|
|
|
|
|
118
|
my ($grouping) = split /\./, $to_parse; |
203
|
36
|
|
|
|
|
119
|
my @groups = split /,/, $grouping; |
204
|
36
|
|
|
|
|
79
|
shift @groups; |
205
|
36
|
|
|
|
|
65
|
($major_group, $minor_group) = map {length} @groups; |
|
32
|
|
|
|
|
97
|
|
206
|
36
|
|
100
|
|
|
167
|
$minor_group //= $major_group; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
36
|
|
50
|
|
|
654
|
$cache{$format}{$type} = { |
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
210
|
|
|
|
|
|
|
prefix => $prefix // '', |
211
|
|
|
|
|
|
|
suffix => $suffix // '', |
212
|
|
|
|
|
|
|
pad_character => $pad_character, |
213
|
|
|
|
|
|
|
pad_location => $pad_location // 'none', |
214
|
|
|
|
|
|
|
pad_length => $pad_length, |
215
|
|
|
|
|
|
|
multiplier => $multiplier, |
216
|
|
|
|
|
|
|
rounding => $rounding, |
217
|
|
|
|
|
|
|
minimum_significant_digits => $minimum_significant_digits, |
218
|
|
|
|
|
|
|
maximum_significant_digits => $maximum_significant_digits, |
219
|
|
|
|
|
|
|
minimum_digits => $minimum_digits // 0, |
220
|
|
|
|
|
|
|
exponent_digits => $exponent_digits, |
221
|
|
|
|
|
|
|
exponent_needs_plus => $need_plus, |
222
|
|
|
|
|
|
|
major_group => $major_group, |
223
|
|
|
|
|
|
|
minor_group => $minor_group, |
224
|
|
|
|
|
|
|
}; |
225
|
|
|
|
|
|
|
|
226
|
36
|
|
|
|
|
134
|
$type = 'negative'; |
227
|
|
|
|
|
|
|
} |
228
|
|
|
|
|
|
|
|
229
|
18
|
|
|
|
|
64
|
return $cache{$format}; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
# Rounding function |
233
|
|
|
|
|
|
|
sub round { |
234
|
9
|
|
|
9
|
0
|
21
|
my ($self, $number, $increment, $decimal_digits) = @_; |
235
|
|
|
|
|
|
|
|
236
|
9
|
50
|
|
|
|
23
|
if ($increment ) { |
237
|
0
|
|
|
|
|
0
|
$number /= $increment; |
238
|
0
|
|
|
|
|
0
|
$number = int ($number + .5 ); |
239
|
0
|
|
|
|
|
0
|
$number *= $increment; |
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
9
|
50
|
|
|
|
20
|
if ( $decimal_digits ) { |
243
|
9
|
|
|
|
|
20
|
$number *= 10 ** $decimal_digits; |
244
|
9
|
|
|
|
|
18
|
$number = int $number; |
245
|
9
|
|
|
|
|
20
|
$number /= 10 ** $decimal_digits; |
246
|
|
|
|
|
|
|
|
247
|
9
|
|
|
|
|
78
|
my ($decimal) = $number =~ /(\..*)/; |
248
|
9
|
|
100
|
|
|
28
|
$decimal //= '.'; # No fraction so add a decimal point |
249
|
|
|
|
|
|
|
|
250
|
9
|
|
|
|
|
42
|
$number = int ($number) . $decimal . ('0' x ( $decimal_digits - length( $decimal ) +1 )); |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
else { |
253
|
|
|
|
|
|
|
# No decimal digits wanted |
254
|
0
|
|
|
|
|
0
|
$number = int $number; |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
9
|
|
|
|
|
21
|
return $number; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub get_formatted_number { |
261
|
758
|
|
|
758
|
0
|
1237
|
my ($self, $number, $format, $currency_data, $for_cash) = @_; |
262
|
|
|
|
|
|
|
|
263
|
758
|
|
|
|
|
2203
|
my @digits = $self->get_digits; |
264
|
758
|
|
|
|
|
3017
|
my @number_symbols_bundles = reverse $self->_find_bundle('number_symbols'); |
265
|
758
|
|
|
|
|
1357
|
my %symbols; |
266
|
758
|
|
|
|
|
1330
|
foreach my $bundle (@number_symbols_bundles) { |
267
|
1516
|
|
|
|
|
61559
|
my $current_symbols = $bundle->number_symbols; |
268
|
1516
|
|
|
|
|
7594
|
foreach my $type (keys %$current_symbols) { |
269
|
32594
|
|
|
|
|
34537
|
foreach my $symbol (keys %{$current_symbols->{$type}}) { |
|
32594
|
|
|
|
|
71531
|
|
270
|
65188
|
|
|
|
|
158143
|
$symbols{$type}{$symbol} = $current_symbols->{$type}{$symbol}; |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
758
|
|
|
|
|
2745
|
my $symbols_type = $self->default_numbering_system; |
276
|
|
|
|
|
|
|
|
277
|
758
|
50
|
|
|
|
2504
|
$symbols_type = $symbols{$symbols_type}{alias} if exists $symbols{$symbols_type}{alias}; |
278
|
|
|
|
|
|
|
|
279
|
758
|
100
|
|
|
|
2245
|
my $type = $number=~ s/^-// ? 'negative' : 'positive'; |
280
|
|
|
|
|
|
|
|
281
|
758
|
|
|
|
|
1768
|
$number *= $format->{$type}{multiplier}; |
282
|
|
|
|
|
|
|
|
283
|
758
|
100
|
66
|
|
|
3791
|
if ($format->{rounding} || defined $for_cash) { |
284
|
9
|
|
|
|
|
14
|
my $decimal_digits = 0; |
285
|
|
|
|
|
|
|
|
286
|
9
|
50
|
|
|
|
27
|
if (defined $for_cash) { |
287
|
9
|
|
|
|
|
32
|
$decimal_digits = $self->_get_currency_digits($currency_data, $for_cash) |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
9
|
|
|
|
|
39
|
$number = $self->round($number, $format->{$type}{rounding}, $decimal_digits); |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
758
|
|
|
|
|
1793
|
my $pad_zero = $format->{$type}{minimum_digits} - length "$number"; |
294
|
758
|
100
|
|
|
|
1484
|
if ($pad_zero > 0) { |
295
|
4
|
|
|
|
|
17
|
$number = ('0' x $pad_zero) . $number; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
# Handle grouping |
299
|
758
|
|
|
|
|
2229
|
my ($integer, $decimal) = split /\./, $number; |
300
|
|
|
|
|
|
|
|
301
|
758
|
|
|
|
|
2946
|
my $minimum_grouping_digits = $self->_find_bundle('minimum_grouping_digits'); |
302
|
758
|
50
|
|
|
|
32481
|
$minimum_grouping_digits = $minimum_grouping_digits |
303
|
|
|
|
|
|
|
? $minimum_grouping_digits->minimum_grouping_digits() |
304
|
|
|
|
|
|
|
: 0; |
305
|
|
|
|
|
|
|
|
306
|
758
|
|
|
|
|
2251
|
my ($separator, $decimal_point) = ($symbols{$symbols_type}{group}, $symbols{$symbols_type}{decimal}); |
307
|
758
|
50
|
33
|
|
|
4321
|
if (($minimum_grouping_digits && length $integer >= $minimum_grouping_digits) || ! $minimum_grouping_digits) { |
|
|
|
33
|
|
|
|
|
308
|
758
|
|
|
|
|
1755
|
my ($minor_group, $major_group) = ($format->{$type}{minor_group}, $format->{$type}{major_group}); |
309
|
|
|
|
|
|
|
|
310
|
758
|
100
|
66
|
|
|
2223
|
if (defined $minor_group && $separator) { |
311
|
|
|
|
|
|
|
# Fast commify using unpack |
312
|
19
|
|
|
|
|
54
|
my $pattern = "(A$minor_group)(A$major_group)*"; |
313
|
19
|
|
|
|
|
122
|
$number = reverse join $separator, grep {length} unpack $pattern, reverse $integer; |
|
45
|
|
|
|
|
108
|
|
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
} |
316
|
|
|
|
|
|
|
else { |
317
|
0
|
|
|
|
|
0
|
$number = $integer; |
318
|
|
|
|
|
|
|
} |
319
|
|
|
|
|
|
|
|
320
|
758
|
100
|
|
|
|
1732
|
$number.= "$decimal_point$decimal" if defined $decimal; |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
# Fix digits |
323
|
758
|
|
|
|
|
3114
|
$number =~ s/([0-9])/$digits[$1]/eg; |
|
888
|
|
|
|
|
3249
|
|
324
|
|
|
|
|
|
|
|
325
|
758
|
|
|
|
|
2015
|
my ($prefix, $suffix) = ( $format->{$type}{prefix}, $format->{$type}{suffix}); |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
# This needs fixing for escaped symbols |
328
|
758
|
|
|
|
|
1218
|
foreach my $string ($prefix, $suffix) { |
329
|
1516
|
|
|
|
|
1877
|
$string =~ s/%/$symbols{$symbols_type}{percentSign}/; |
330
|
1516
|
|
|
|
|
1815
|
$string =~ s/â°/$symbols{$symbols_type}{perMille}/; |
331
|
1516
|
100
|
|
|
|
3020
|
if ($type eq 'negative') { |
332
|
16
|
|
|
|
|
53
|
$string =~ s/(?: \\ \\ )*+ \K \\ - /$symbols{$symbols_type}{minusSign}/x; |
333
|
16
|
|
|
|
|
33
|
$string =~ s/(?: \\ \\)*+ \K \\ + /$symbols{$symbols_type}{minusSign}/x; |
334
|
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
else { |
336
|
1500
|
|
|
|
|
1772
|
$string =~ s/(?: \\ \\ )*+ \K \\ - //x; |
337
|
1500
|
|
|
|
|
1900
|
$string =~ s/(?: \\ \\ )*+ \K \\ + /$symbols{$symbols_type}{plusSign}/x; |
338
|
|
|
|
|
|
|
} |
339
|
1516
|
|
|
|
|
2265
|
$string =~ s/ \\ \\ /\\/gx; |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
|
342
|
758
|
|
|
|
|
1527
|
$number = $prefix . $number . $suffix; |
343
|
|
|
|
|
|
|
|
344
|
758
|
|
|
|
|
15402
|
return $number; |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
# Get the digits for the locale. Assumes a numeric numbering system |
348
|
|
|
|
|
|
|
sub get_digits { |
349
|
759
|
|
|
759
|
0
|
1041
|
my $self = shift; |
350
|
|
|
|
|
|
|
|
351
|
759
|
|
|
|
|
2405
|
my $numbering_system = $self->default_numbering_system(); |
352
|
|
|
|
|
|
|
|
353
|
759
|
50
|
|
|
|
28541
|
$numbering_system = 'latn' unless $self->numbering_system->{$numbering_system}{type} eq 'numeric'; # Fall back to latn if the numbering system is not numeric |
354
|
|
|
|
|
|
|
|
355
|
759
|
|
|
|
|
28191
|
my $digits = $self->numbering_system->{$numbering_system}{data}; |
356
|
|
|
|
|
|
|
|
357
|
759
|
|
|
|
|
3603
|
return @$digits; |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
# RBNF |
361
|
|
|
|
|
|
|
# Note that there are a couple of assumptions with the way |
362
|
|
|
|
|
|
|
# I handle Rule Base Number Formats. |
363
|
|
|
|
|
|
|
# 1) The number is treated as a string for as long as possible |
364
|
|
|
|
|
|
|
# This allows things like -0.0 to be correctly formatted |
365
|
|
|
|
|
|
|
# 2) There is no fall back. All the rule sets are self contained |
366
|
|
|
|
|
|
|
# in a bundle. Fall back is used to find a bundle but once a |
367
|
|
|
|
|
|
|
# bundle is found no further processing of the bundle chain |
368
|
|
|
|
|
|
|
# is done. This was found by trial and error when attempting |
369
|
|
|
|
|
|
|
# to process -0.0 correctly into English. |
370
|
|
|
|
|
|
|
sub _get_valid_algorithmic_formats { |
371
|
763
|
|
|
763
|
|
953
|
my $self = shift; |
372
|
|
|
|
|
|
|
|
373
|
763
|
|
|
|
|
2418
|
my @formats = map { @{$_->valid_algorithmic_formats()} } $self->_find_bundle('valid_algorithmic_formats'); |
|
1526
|
|
|
|
|
1783
|
|
|
1526
|
|
|
|
|
63562
|
|
374
|
|
|
|
|
|
|
|
375
|
763
|
|
|
|
|
2190
|
my %seen; |
376
|
763
|
|
|
|
|
1286
|
return sort grep { ! $seen{$_}++ } @formats; |
|
19075
|
|
|
|
|
51472
|
|
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
# Main entry point to RBNF |
380
|
|
|
|
|
|
|
sub _algorithmic_number_format { |
381
|
8
|
|
|
8
|
|
24
|
my ($self, $number, $format_name, $type) = @_; |
382
|
|
|
|
|
|
|
|
383
|
8
|
|
|
|
|
3808
|
my $format_data = $self->_get_algorithmic_number_format_data_by_name($format_name, $type); |
384
|
|
|
|
|
|
|
|
385
|
8
|
50
|
|
|
|
18
|
return $number unless $format_data; |
386
|
|
|
|
|
|
|
|
387
|
8
|
|
|
|
|
42
|
return $self->_process_algorithmic_number_data($number, $format_data); |
388
|
|
|
|
|
|
|
} |
389
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
sub _get_algorithmic_number_format_data_by_name { |
391
|
8
|
|
|
8
|
|
16
|
my ($self, $format_name, $type) = @_; |
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
# Some of these algorithmic formats are in locale/type/name format |
394
|
8
|
50
|
|
|
|
32
|
if (my ($locale_id, undef, $format) = $format_name =~ m(^(.*?)/(.*?)/(.*?)$)) { |
395
|
0
|
|
|
|
|
0
|
my $locale = Locale::CLDR->new($locale_id); |
396
|
0
|
0
|
|
|
|
0
|
return $locale->_get_algorithmic_number_format_data_by_name($format, $type) |
397
|
|
|
|
|
|
|
if $locale; |
398
|
|
|
|
|
|
|
|
399
|
0
|
|
|
|
|
0
|
return undef; |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
|
402
|
8
|
|
100
|
|
|
29
|
$type //= 'public'; |
403
|
|
|
|
|
|
|
|
404
|
8
|
|
|
|
|
17
|
my %data = (); |
405
|
|
|
|
|
|
|
|
406
|
8
|
|
|
|
|
30
|
my @data_bundles = $self->_find_bundle('algorithmic_number_format_data'); |
407
|
8
|
|
|
|
|
19
|
foreach my $data_bundle (@data_bundles) { |
408
|
10
|
|
|
|
|
421
|
my $data = $data_bundle->algorithmic_number_format_data(); |
409
|
10
|
100
|
|
|
|
36
|
next unless $data->{$format_name}; |
410
|
8
|
50
|
|
|
|
26
|
next unless $data->{$format_name}{$type}; |
411
|
|
|
|
|
|
|
|
412
|
8
|
|
|
|
|
10
|
foreach my $rule (keys %{$data->{$format_name}{$type}}) { |
|
8
|
|
|
|
|
58
|
|
413
|
186
|
|
|
|
|
424
|
$data{$rule} = $data->{$format_name}{$type}{$rule}; |
414
|
|
|
|
|
|
|
} |
415
|
|
|
|
|
|
|
|
416
|
8
|
|
|
|
|
24
|
last; |
417
|
|
|
|
|
|
|
} |
418
|
|
|
|
|
|
|
|
419
|
8
|
50
|
|
|
|
33
|
return keys %data ? \%data : undef; |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
sub _get_plural_form { |
423
|
1
|
|
|
1
|
|
4
|
my ($self, $plural, $from) = @_; |
424
|
|
|
|
|
|
|
|
425
|
1
|
|
|
|
|
16
|
my ($result) = $from =~ /$plural\{(.+?)\}/; |
426
|
1
|
50
|
|
|
|
4
|
($result) = $from =~ /other\{(.+?)\}/ unless defined $result; |
427
|
|
|
|
|
|
|
|
428
|
1
|
|
|
|
|
5
|
return $result; |
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
sub _process_algorithmic_number_data { |
432
|
14
|
|
|
14
|
|
31
|
my ($self, $number, $format_data, $plural, $in_fraction_rule_set) = @_; |
433
|
|
|
|
|
|
|
|
434
|
14
|
|
100
|
|
|
51
|
$in_fraction_rule_set //= 0; |
435
|
|
|
|
|
|
|
|
436
|
14
|
|
|
|
|
37
|
my $format = $self->_get_algorithmic_number_format($number, $format_data); |
437
|
|
|
|
|
|
|
|
438
|
14
|
|
|
|
|
1194
|
my $format_rule = $format->{rule}; |
439
|
14
|
100
|
66
|
|
|
91
|
if (! $plural && $format_rule =~ /(cardinal|ordinal)/) { |
440
|
3
|
|
|
|
|
9
|
my $type = $1; |
441
|
3
|
|
|
|
|
17
|
$plural = $self->plural($number, $type); |
442
|
3
|
|
|
|
|
8
|
$plural = [$type, $plural]; |
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
# Sort out plural forms |
446
|
14
|
100
|
|
|
|
32
|
if ($plural) { |
447
|
3
|
|
|
|
|
70
|
$format_rule =~ s/\$\($plural->[0],(.+)\)\$/$self->_get_plural_form($plural->[1],$1)/eg; |
|
1
|
|
|
|
|
5
|
|
448
|
|
|
|
|
|
|
} |
449
|
|
|
|
|
|
|
|
450
|
14
|
|
|
|
|
27
|
my $divisor = $format->{divisor}; |
451
|
14
|
|
100
|
|
|
43
|
my $base_value = $format->{base_value} // ''; |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
# Negative numbers |
454
|
14
|
100
|
|
|
|
60
|
if ($number =~ /^-/) { |
|
|
100
|
|
|
|
|
|
455
|
2
|
|
|
|
|
4
|
my $positive_number = $number; |
456
|
2
|
|
|
|
|
7
|
$positive_number =~ s/^-//; |
457
|
|
|
|
|
|
|
|
458
|
2
|
100
|
|
|
|
20
|
if ($format_rule =~ /ââ/) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
459
|
1
|
|
|
|
|
4
|
$format_rule =~ s/ââ/$self->_process_algorithmic_number_data($positive_number, $format_data, $plural)/e; |
|
1
|
|
|
|
|
4
|
|
460
|
|
|
|
|
|
|
} |
461
|
|
|
|
|
|
|
elsif((my $rule_name) = $format_rule =~ /â(.+)â/) { |
462
|
0
|
|
|
|
|
0
|
my $type = 'public'; |
463
|
0
|
0
|
|
|
|
0
|
if ($rule_name =~ s/^%%/%/) { |
464
|
0
|
|
|
|
|
0
|
$type = 'private'; |
465
|
|
|
|
|
|
|
} |
466
|
0
|
|
|
|
|
0
|
my $format_data = $self->_get_algorithmic_number_format_data_by_name($rule_name, $type); |
467
|
0
|
0
|
|
|
|
0
|
if($format_data) { |
468
|
|
|
|
|
|
|
# was a valid name |
469
|
0
|
|
|
|
|
0
|
$format_rule =~ s/â(.+)â/$self->_process_algorithmic_number_data($positive_number, $format_data, $plural)/e; |
|
0
|
|
|
|
|
0
|
|
470
|
|
|
|
|
|
|
} |
471
|
|
|
|
|
|
|
else { |
472
|
|
|
|
|
|
|
# Assume a format |
473
|
0
|
|
|
|
|
0
|
$format_rule =~ s/â(.+)â/$self->_format_number($positive_number, $1)/e; |
|
0
|
|
|
|
|
0
|
|
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
elsif($format_rule =~ /=%%.*=/) { |
477
|
0
|
|
|
|
|
0
|
$format_rule =~ s/=%%(.*?)=/$self->_algorithmic_number_format($number, $1, 'private')/eg; |
|
0
|
|
|
|
|
0
|
|
478
|
|
|
|
|
|
|
} |
479
|
|
|
|
|
|
|
elsif($format_rule =~ /=%.*=/) { |
480
|
1
|
|
|
|
|
6
|
$format_rule =~ s/=%(.*?)=/$self->_algorithmic_number_format($number, $1, 'public')/eg; |
|
1
|
|
|
|
|
3
|
|
481
|
|
|
|
|
|
|
} |
482
|
|
|
|
|
|
|
elsif($format_rule =~ /=.*=/) { |
483
|
0
|
|
|
|
|
0
|
$format_rule =~ s/=(.*?)=/$self->_format_number($number, $1)/eg; |
|
0
|
|
|
|
|
0
|
|
484
|
|
|
|
|
|
|
} |
485
|
|
|
|
|
|
|
} |
486
|
|
|
|
|
|
|
# Fractions |
487
|
|
|
|
|
|
|
elsif( $number =~ /\./ ) { |
488
|
1
|
|
|
|
|
3
|
my $in_fraction_rule_set = 1; |
489
|
1
|
|
|
|
|
7
|
my ($integer, $fraction) = $number =~ /^([^.]*)\.(.*)$/; |
490
|
|
|
|
|
|
|
|
491
|
1
|
50
|
33
|
|
|
10
|
if ($number >= 0 && $number < 1) { |
492
|
1
|
|
|
|
|
13
|
$format_rule =~ s/\[.*\]//; |
493
|
|
|
|
|
|
|
} |
494
|
|
|
|
|
|
|
else { |
495
|
0
|
|
|
|
|
0
|
$format_rule =~ s/[\[\]]//g; |
496
|
|
|
|
|
|
|
} |
497
|
|
|
|
|
|
|
|
498
|
1
|
50
|
|
|
|
5
|
if ($format_rule =~ /ââ/) { |
|
|
0
|
|
|
|
|
|
499
|
1
|
|
|
|
|
4
|
$format_rule =~ s/ââ/$self->_process_algorithmic_number_data_fractions($fraction, $format_data, $plural)/e; |
|
1
|
|
|
|
|
6
|
|
500
|
|
|
|
|
|
|
} |
501
|
|
|
|
|
|
|
elsif((my $rule_name) = $format_rule =~ /â(.*)â/) { |
502
|
0
|
|
|
|
|
0
|
my $type = 'public'; |
503
|
0
|
0
|
|
|
|
0
|
if ($rule_name =~ s/^%%/%/) { |
504
|
0
|
|
|
|
|
0
|
$type = 'private'; |
505
|
|
|
|
|
|
|
} |
506
|
0
|
|
|
|
|
0
|
my $format_data = $self->_get_algorithmic_number_format_data_by_name($rule_name, $type); |
507
|
0
|
0
|
|
|
|
0
|
if ($format_data) { |
508
|
0
|
|
|
|
|
0
|
$format_rule =~ s/â(.*)â/$self->_process_algorithmic_number_data_fractions($fraction, $format_data, $plural)/e; |
|
0
|
|
|
|
|
0
|
|
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
else { |
511
|
0
|
|
|
|
|
0
|
$format_rule =~ s/â(.*)â/$self->_format_number($fraction, $1)/e; |
|
0
|
|
|
|
|
0
|
|
512
|
|
|
|
|
|
|
} |
513
|
|
|
|
|
|
|
} |
514
|
|
|
|
|
|
|
|
515
|
1
|
50
|
|
|
|
15
|
if ($format_rule =~ /ââ/) { |
|
|
0
|
|
|
|
|
|
516
|
1
|
|
|
|
|
5
|
$format_rule =~ s/ââ/$self->_process_algorithmic_number_data($integer, $format_data, $plural, $in_fraction_rule_set)/e; |
|
1
|
|
|
|
|
4
|
|
517
|
|
|
|
|
|
|
} |
518
|
|
|
|
|
|
|
elsif((my $rule_name) = $format_rule =~ /â(.+)â/) { |
519
|
0
|
|
|
|
|
0
|
my $type = 'public'; |
520
|
0
|
0
|
|
|
|
0
|
if ($rule_name =~ s/^%%/%/) { |
521
|
0
|
|
|
|
|
0
|
$type = 'private'; |
522
|
|
|
|
|
|
|
} |
523
|
0
|
|
|
|
|
0
|
my $format_data = $self->_get_algorithmic_number_format_data_by_name($rule_name, $type); |
524
|
0
|
0
|
|
|
|
0
|
if ($format_data) { |
525
|
0
|
|
|
|
|
0
|
$format_rule =~ s/â(.*)â/$self->_process_algorithmic_number_data($integer, $format_data, $plural, $in_fraction_rule_set)/e; |
|
0
|
|
|
|
|
0
|
|
526
|
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
else { |
528
|
0
|
|
|
|
|
0
|
$format_rule =~ s/â(.*)â/$self->_format_number($integer, $1)/e; |
|
0
|
|
|
|
|
0
|
|
529
|
|
|
|
|
|
|
} |
530
|
|
|
|
|
|
|
} |
531
|
|
|
|
|
|
|
|
532
|
1
|
50
|
|
|
|
8
|
if($format_rule =~ /=.*=/) { |
533
|
0
|
0
|
|
|
|
0
|
if($format_rule =~ /=%%.*=/) { |
|
|
0
|
|
|
|
|
|
534
|
0
|
|
|
|
|
0
|
$format_rule =~ s/=%%(.*?)=/$self->_algorithmic_number_format($number, $1, 'private')/eg; |
|
0
|
|
|
|
|
0
|
|
535
|
|
|
|
|
|
|
} |
536
|
|
|
|
|
|
|
elsif($format_rule =~ /=%.*=/) { |
537
|
0
|
|
|
|
|
0
|
$format_rule =~ s/=%(.*?)=/$self->_algorithmic_number_format($number, $1, 'public')/eg; |
|
0
|
|
|
|
|
0
|
|
538
|
|
|
|
|
|
|
} |
539
|
|
|
|
|
|
|
else { |
540
|
0
|
|
|
|
|
0
|
$format_rule =~ s/=(.*?)=/$self->_format_number($integer, $1)/eg; |
|
0
|
|
|
|
|
0
|
|
541
|
|
|
|
|
|
|
} |
542
|
|
|
|
|
|
|
} |
543
|
|
|
|
|
|
|
} |
544
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
# Everything else |
546
|
|
|
|
|
|
|
else { |
547
|
|
|
|
|
|
|
# At this stage we have a non negative integer |
548
|
11
|
100
|
|
|
|
36
|
if ($format_rule =~ /\[.*\]/) { |
549
|
3
|
50
|
33
|
|
|
25
|
if ($in_fraction_rule_set && $number * $base_value == 1) { |
|
|
50
|
33
|
|
|
|
|
550
|
0
|
|
|
|
|
0
|
$format_rule =~ s/\[.*\]//; |
551
|
|
|
|
|
|
|
} |
552
|
|
|
|
|
|
|
# Not fractional rule set Number is a multiple of $divisor and the multiple is even |
553
|
|
|
|
|
|
|
elsif (! $in_fraction_rule_set && ! ($number % $divisor) ) { |
554
|
0
|
|
|
|
|
0
|
$format_rule =~ s/\[.*\]//; |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
else { |
557
|
3
|
|
|
|
|
16
|
$format_rule =~ s/[\[\]]//g; |
558
|
|
|
|
|
|
|
} |
559
|
|
|
|
|
|
|
} |
560
|
|
|
|
|
|
|
|
561
|
11
|
100
|
|
|
|
23
|
if ($in_fraction_rule_set) { |
562
|
2
|
50
|
|
|
|
13
|
if (my ($rule_name) = $format_rule =~ /â(.*)â/) { |
|
|
50
|
|
|
|
|
|
563
|
0
|
0
|
|
|
|
0
|
if (length $rule_name) { |
564
|
0
|
|
|
|
|
0
|
my $type = 'public'; |
565
|
0
|
0
|
|
|
|
0
|
if ($rule_name =~ s/^%%/%/) { |
566
|
0
|
|
|
|
|
0
|
$type = 'private'; |
567
|
|
|
|
|
|
|
} |
568
|
0
|
|
|
|
|
0
|
my $format_data = $self->_get_algorithmic_number_format_data_by_name($rule_name, $type); |
569
|
0
|
0
|
|
|
|
0
|
if ($format_data) { |
570
|
0
|
|
|
|
|
0
|
$format_rule =~ s/â(.*)â/$self->_process_algorithmic_number_data($number * $base_value, $format_data, $plural, $in_fraction_rule_set)/e; |
|
0
|
|
|
|
|
0
|
|
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
else { |
573
|
0
|
|
|
|
|
0
|
$format_rule =~ s/â(.*)â/$self->_format_number($number * $base_value, $1)/e; |
|
0
|
|
|
|
|
0
|
|
574
|
|
|
|
|
|
|
} |
575
|
|
|
|
|
|
|
} |
576
|
|
|
|
|
|
|
else { |
577
|
0
|
|
|
|
|
0
|
$format_rule =~ s/ââ/$self->_process_algorithmic_number_data($number * $base_value, $format_data, $plural, $in_fraction_rule_set)/e; |
|
0
|
|
|
|
|
0
|
|
578
|
|
|
|
|
|
|
} |
579
|
|
|
|
|
|
|
} |
580
|
|
|
|
|
|
|
elsif($format_rule =~ /=.*=/) { |
581
|
0
|
|
|
|
|
0
|
$format_rule =~ s/=(.*?)=/$self->_format_number($number, $1)/eg; |
|
0
|
|
|
|
|
0
|
|
582
|
|
|
|
|
|
|
} |
583
|
|
|
|
|
|
|
} |
584
|
|
|
|
|
|
|
else { |
585
|
9
|
100
|
|
|
|
41
|
if (my ($rule_name) = $format_rule =~ /â(.*)â/) { |
586
|
3
|
50
|
|
|
|
10
|
if (length $rule_name) { |
587
|
0
|
|
|
|
|
0
|
my $type = 'public'; |
588
|
0
|
0
|
|
|
|
0
|
if ($rule_name =~ s/^%%/%/) { |
589
|
0
|
|
|
|
|
0
|
$type = 'private'; |
590
|
|
|
|
|
|
|
} |
591
|
0
|
|
|
|
|
0
|
my $format_data = $self->_get_algorithmic_number_format_data_by_name($rule_name, $type); |
592
|
0
|
0
|
|
|
|
0
|
if ($format_data) { |
593
|
0
|
|
|
|
|
0
|
$format_rule =~ s/â(.+)â/$self->_process_algorithmic_number_data($number % $divisor, $format_data, $plural)/e; |
|
0
|
|
|
|
|
0
|
|
594
|
|
|
|
|
|
|
} |
595
|
|
|
|
|
|
|
else { |
596
|
0
|
|
|
|
|
0
|
$format_rule =~ s/â(.*)â/$self->_format_number($number % $divisor, $1)/e; |
|
0
|
|
|
|
|
0
|
|
597
|
|
|
|
|
|
|
} |
598
|
|
|
|
|
|
|
} |
599
|
|
|
|
|
|
|
else { |
600
|
3
|
|
|
|
|
11
|
$format_rule =~ s/ââ/$self->_process_algorithmic_number_data($number % $divisor, $format_data, $plural)/e; |
|
3
|
|
|
|
|
10
|
|
601
|
|
|
|
|
|
|
} |
602
|
|
|
|
|
|
|
} |
603
|
|
|
|
|
|
|
|
604
|
9
|
50
|
|
|
|
30
|
if (my ($rule_name) = $format_rule =~ /â(.*)â/) { |
605
|
0
|
0
|
|
|
|
0
|
if (length $rule_name) { |
606
|
0
|
|
|
|
|
0
|
my $type = 'public'; |
607
|
0
|
0
|
|
|
|
0
|
if ($rule_name =~ s/^%%/%/) { |
608
|
0
|
|
|
|
|
0
|
$type = 'private'; |
609
|
|
|
|
|
|
|
} |
610
|
0
|
|
|
|
|
0
|
my $format_data = $self->_get_algorithmic_number_format_data_by_name($rule_name, $type); |
611
|
0
|
0
|
|
|
|
0
|
if ($format_data) { |
612
|
0
|
|
|
|
|
0
|
$format_rule =~ s|â(.*)â|$self->_process_algorithmic_number_data(int ($number / $divisor), $format_data, $plural)|e; |
|
0
|
|
|
|
|
0
|
|
613
|
|
|
|
|
|
|
} |
614
|
|
|
|
|
|
|
else { |
615
|
0
|
|
|
|
|
0
|
$format_rule =~ s|â(.*)â|$self->_format_number(int($number / $divisor), $1)|e; |
|
0
|
|
|
|
|
0
|
|
616
|
|
|
|
|
|
|
} |
617
|
|
|
|
|
|
|
} |
618
|
|
|
|
|
|
|
else { |
619
|
0
|
|
|
|
|
0
|
$format_rule =~ s|ââ|$self->_process_algorithmic_number_data(int($number / $divisor), $format_data, $plural)|e; |
|
0
|
|
|
|
|
0
|
|
620
|
|
|
|
|
|
|
} |
621
|
|
|
|
|
|
|
} |
622
|
|
|
|
|
|
|
|
623
|
9
|
100
|
|
|
|
34
|
if($format_rule =~ /=.*=/) { |
624
|
4
|
50
|
|
|
|
20
|
if($format_rule =~ /=%%.*=/) { |
|
|
100
|
|
|
|
|
|
625
|
0
|
|
|
|
|
0
|
$format_rule =~ s/=%%(.*?)=/$self->_algorithmic_number_format($number, $1, 'private')/eg; |
|
0
|
|
|
|
|
0
|
|
626
|
|
|
|
|
|
|
} |
627
|
|
|
|
|
|
|
elsif($format_rule =~ /=%.*=/) { |
628
|
2
|
|
|
|
|
14
|
$format_rule =~ s/=%(.*?)=/$self->_algorithmic_number_format($number, $1, 'public')/eg; |
|
2
|
|
|
|
|
13
|
|
629
|
|
|
|
|
|
|
} |
630
|
|
|
|
|
|
|
else { |
631
|
2
|
|
|
|
|
10
|
$format_rule =~ s/=(.*?)=/$self->_format_number($number, $1)/eg; |
|
2
|
|
|
|
|
11
|
|
632
|
|
|
|
|
|
|
} |
633
|
|
|
|
|
|
|
} |
634
|
|
|
|
|
|
|
} |
635
|
|
|
|
|
|
|
} |
636
|
|
|
|
|
|
|
|
637
|
14
|
|
|
|
|
115
|
return $format_rule; |
638
|
|
|
|
|
|
|
} |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
sub _process_algorithmic_number_data_fractions { |
641
|
1
|
|
|
1
|
|
4
|
my ($self, $fraction, $format_data, $plural) = @_; |
642
|
|
|
|
|
|
|
|
643
|
1
|
|
|
|
|
2
|
my $result = ''; |
644
|
1
|
|
|
|
|
4
|
foreach my $digit (split //, $fraction) { |
645
|
1
|
|
|
|
|
8
|
$result .= $self->_process_algorithmic_number_data($digit, $format_data, $plural, 1); |
646
|
|
|
|
|
|
|
} |
647
|
|
|
|
|
|
|
|
648
|
1
|
|
|
|
|
6
|
return $result; |
649
|
|
|
|
|
|
|
} |
650
|
|
|
|
|
|
|
|
651
|
|
|
|
|
|
|
sub _get_algorithmic_number_format { |
652
|
14
|
|
|
14
|
|
24
|
my ($self, $number, $format_data) = @_; |
653
|
|
|
|
|
|
|
|
654
|
20
|
|
|
20
|
|
159432
|
use bignum; |
|
20
|
|
|
|
|
116009
|
|
|
20
|
|
|
|
|
153
|
|
655
|
14
|
100
|
66
|
|
|
48
|
return $format_data->{'-x'} if $number =~ /^-/ && exists $format_data->{'-x'}; |
656
|
13
|
100
|
66
|
|
|
36
|
return $format_data->{'x.x'} if $number =~ /\./ && exists $format_data->{'x.x'}; |
657
|
12
|
100
|
66
|
|
|
108
|
return $format_data->{0} if $number == 0 || $number =~ /^-/; |
658
|
6
|
100
|
|
|
|
616
|
return $format_data->{max} if $number >= $format_data->{max}{base_value}; |
659
|
|
|
|
|
|
|
|
660
|
4
|
|
|
|
|
8
|
my $previous = 0; |
661
|
4
|
|
|
|
|
103
|
foreach my $key (sort { $a <=> $b } grep /^[0-9]+$/, keys %$format_data) { |
|
520
|
|
|
|
|
659
|
|
662
|
71
|
100
|
|
|
|
679
|
next if $key == 0; |
663
|
67
|
100
|
|
|
|
5362
|
return $format_data->{$key} if $number == $key; |
664
|
66
|
100
|
|
|
|
123
|
return $format_data->{$previous} if $number < $key; |
665
|
63
|
|
|
|
|
92
|
$previous = $key; |
666
|
|
|
|
|
|
|
} |
667
|
|
|
|
|
|
|
} |
668
|
|
|
|
|
|
|
|
669
|
20
|
|
|
20
|
|
1347636
|
no Moose::Role; |
|
20
|
|
|
|
|
56
|
|
|
20
|
|
|
|
|
272
|
|
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
1; |
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
# vim: tabstop=4 |