line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::AF::Numbers; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '1.2'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
8065
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1648
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my $numbers = { |
8
|
|
|
|
|
|
|
0 => 'nul', |
9
|
|
|
|
|
|
|
1 => 'een', |
10
|
|
|
|
|
|
|
2 => 'twee', |
11
|
|
|
|
|
|
|
3 => 'drie', |
12
|
|
|
|
|
|
|
4 => 'vier', |
13
|
|
|
|
|
|
|
5 => 'vyf', |
14
|
|
|
|
|
|
|
6 => 'ses', |
15
|
|
|
|
|
|
|
7 => 'sewe', |
16
|
|
|
|
|
|
|
8 => 'agt', |
17
|
|
|
|
|
|
|
9 => 'nege', |
18
|
|
|
|
|
|
|
10 => 'tien', |
19
|
|
|
|
|
|
|
11 => 'elf', |
20
|
|
|
|
|
|
|
12 => 'twaalf', |
21
|
|
|
|
|
|
|
13 => 'dertien', |
22
|
|
|
|
|
|
|
14 => 'viertien', |
23
|
|
|
|
|
|
|
15 => 'vyftien', |
24
|
|
|
|
|
|
|
16 => 'sestien', |
25
|
|
|
|
|
|
|
17 => 'sewentien', |
26
|
|
|
|
|
|
|
18 => 'agtien', |
27
|
|
|
|
|
|
|
19 => 'negentien', |
28
|
|
|
|
|
|
|
20 => 'twintig', |
29
|
|
|
|
|
|
|
30 => 'dertig', |
30
|
|
|
|
|
|
|
40 => 'viertig', |
31
|
|
|
|
|
|
|
50 => 'vyftig', |
32
|
|
|
|
|
|
|
60 => 'sestig', |
33
|
|
|
|
|
|
|
70 => 'sewentig', |
34
|
|
|
|
|
|
|
80 => 'tagtig', |
35
|
|
|
|
|
|
|
90 => 'negentig', |
36
|
|
|
|
|
|
|
}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
41
|
0
|
|
0
|
|
|
|
my $number = shift || ''; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $self = {}; |
44
|
0
|
|
|
|
|
|
bless $self, $class; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if( $number =~ /\d+/ ) { |
47
|
0
|
|
|
|
|
|
return( $self->parse($number) ); |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
return( $self ); |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub parse |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
my $number = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $digits; |
60
|
0
|
|
|
|
|
|
my $ret = ''; |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if( defined($numbers->{$number}) ) { |
63
|
0
|
|
|
|
|
|
$ret = $numbers->{$number}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
0
|
|
|
|
|
|
my $ret_array = []; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
@{$digits} = reverse( split('', $number) ); |
|
0
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# tens of billions |
71
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[10]) && ($digits->[10] != 0) ) { |
|
|
0
|
0
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $temp = $self->_formatTens( $digits->[9], $digits->[10] ); |
73
|
0
|
|
|
|
|
|
unshift @{$ret_array}, "$temp biljoen"; |
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif( defined($digits->[9]) && ($digits->[9] != 0) ) { |
76
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[9], 'biljoen' ); |
|
0
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# hundreds of millions |
80
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[8]) && ($digits->[8] != 0) ) { |
81
|
0
|
0
|
0
|
|
|
|
if( ($digits->[7] == 0) && ($digits->[6] == 0) ) { |
82
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[8], 'honderd miljoen' ); |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[8], 'honderd' ); |
|
0
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# tens of millions |
90
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[7]) && ($digits->[7] != 0) ) { |
|
|
0
|
0
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $temp = $self->_formatTens( $digits->[6], $digits->[7] ); |
92
|
0
|
|
|
|
|
|
unshift @{$ret_array}, "$temp miljoen"; |
|
0
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif( defined($digits->[6]) && ($digits->[6] != 0) ) { |
95
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[6], 'miljoen' ); |
|
0
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# hundreds of thousands |
99
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[5]) && ($digits->[5] != 0) ) { |
100
|
0
|
0
|
0
|
|
|
|
if( ($digits->[4] == 0) && ($digits->[3] == 0) ) { |
101
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[5], 'honderd duisend' ); |
|
0
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
else { |
104
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[5], 'honderd' ); |
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
}; |
106
|
|
|
|
|
|
|
}; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# tens of thousands |
109
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[4]) && ($digits->[4] != 0) ) { |
|
|
0
|
0
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $temp = $self->_formatTens( $digits->[3], $digits->[4] ); |
111
|
0
|
|
|
|
|
|
unshift @{$ret_array}, "$temp duisend"; |
|
0
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
elsif( defined($digits->[3]) && ($digits->[3] != 0) ) { |
114
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[3], 'duisend' ); |
|
0
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
}; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# hundreds |
118
|
0
|
0
|
0
|
|
|
|
if( defined($digits->[2]) && ($digits->[2] != 0) ) { |
119
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatLarge( $digits->[2], 'honderd' ); |
|
0
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
}; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# tens |
123
|
0
|
|
|
|
|
|
unshift @{$ret_array}, $self->_formatTens( $digits->[0], $digits->[1] ); |
|
0
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
$ret = $self->_sortReturn( $ret_array, $digits ); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
}; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
return( $ret ); |
130
|
|
|
|
|
|
|
}; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _sortReturn |
134
|
|
|
|
|
|
|
{ |
135
|
0
|
|
|
0
|
|
|
my $self = shift; |
136
|
0
|
|
|
|
|
|
my $ret_array = shift; |
137
|
0
|
|
|
|
|
|
my $digits = shift; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my $large_nums = 0; |
140
|
0
|
|
|
|
|
|
my $ret = ''; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $size = @{$ret_array}; |
|
0
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
if( $size == 1 ) { |
|
|
0
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
return( $ret_array->[0] ); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
elsif( $size > 1 ) { |
148
|
0
|
|
|
|
|
|
$large_nums = 1; |
149
|
|
|
|
|
|
|
}; |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
for( my $i = $size; $i > 0; $i-- ) { |
152
|
0
|
0
|
|
|
|
|
if( defined($ret_array->[$i]) ) { |
153
|
0
|
0
|
|
|
|
|
if( $ret_array->[$i] =~ /(miljoen|duisend)/ ) { |
154
|
0
|
|
|
|
|
|
$ret .= $ret_array->[$i] .', '; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
else { |
157
|
0
|
|
|
|
|
|
$ret .= $ret_array->[$i] .' '; |
158
|
|
|
|
|
|
|
}; |
159
|
|
|
|
|
|
|
}; |
160
|
|
|
|
|
|
|
}; |
161
|
|
|
|
|
|
|
|
162
|
0
|
0
|
0
|
|
|
|
if( ($digits->[0] == 0) && ($digits->[1] == 0) ) { |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
163
|
|
|
|
|
|
|
# do nothing |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
elsif( ($digits->[0] == 0) || ($digits->[1] == 0) || ($digits->[1] == 1) ) { |
166
|
0
|
0
|
|
|
|
|
if( $large_nums ) { |
167
|
0
|
|
|
|
|
|
$ret .= ' en '; |
168
|
|
|
|
|
|
|
}; |
169
|
0
|
|
|
|
|
|
$ret .= $ret_array->[0]; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
else { |
172
|
0
|
|
|
|
|
|
$ret .= ' '. $ret_array->[0]; |
173
|
|
|
|
|
|
|
}; |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
$ret =~ s/(^ |\s{2,}| $)/ /g; |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
|
return( $ret ); |
178
|
|
|
|
|
|
|
}; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub _formatTens |
182
|
|
|
|
|
|
|
{ |
183
|
0
|
|
|
0
|
|
|
my $self = shift; |
184
|
0
|
|
|
|
|
|
my $units = shift; |
185
|
0
|
|
|
|
|
|
my $tens = shift; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# Both digits are zero |
188
|
0
|
0
|
0
|
|
|
|
unless( $units || $tens ) { |
189
|
0
|
|
|
|
|
|
return; |
190
|
|
|
|
|
|
|
}; |
191
|
|
|
|
|
|
|
|
192
|
0
|
0
|
0
|
|
|
|
if( $tens == 0 ) { |
|
|
0
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
return( $numbers->{$units} ); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
elsif( ($tens == 1) || ($units == 0) ) { |
196
|
0
|
|
|
|
|
|
my $temp = $tens . $units; |
197
|
0
|
|
|
|
|
|
return( $numbers->{$temp} ); |
198
|
|
|
|
|
|
|
}; |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
my $temp = $tens . 0; |
201
|
0
|
|
|
|
|
|
return( "$numbers->{$units} en $numbers->{$temp}" ); |
202
|
|
|
|
|
|
|
}; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub _formatLarge |
206
|
|
|
|
|
|
|
{ |
207
|
0
|
|
|
0
|
|
|
my $self = shift; |
208
|
0
|
|
|
|
|
|
my $digit = shift; |
209
|
0
|
|
|
|
|
|
my $word = shift; |
210
|
|
|
|
|
|
|
|
211
|
0
|
|
|
|
|
|
my $ret = "$numbers->{$digit} $word"; |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
return( $ret ); |
214
|
|
|
|
|
|
|
}; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
1; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=pod |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 NAME |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Lingua::AF::Numbers - Perl module for converting numeric values into their Afrikaans equivalents |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 DESCRIPTION |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Initial release, documentation and updates will follow. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head1 SYNOPSIS |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
use Lingua::AF::Numbers; |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
my $numbers = Lingua::AF::Numbers->new; |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
my $text = $numbers->parse( 123 ); |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
# prints 'een honderd, drie en twintig' |
241
|
|
|
|
|
|
|
print $text; |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 KNOWN BUGS |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
None, but that does not mean there are not any. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 AUTHOR |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Alistair Francis, http://search.cpan.org/~friffin/ |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=cut |
253
|
|
|
|
|
|
|
|