line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; mode:folding; coding:utf-8; -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Lingua::POR::Nums2Words; |
4
|
|
|
|
|
|
|
# ABSTRACT: Number 2 word conversion in POR. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# {{{ use block |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
63147
|
use 5.10.1; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
128
|
|
9
|
3
|
|
|
3
|
|
14
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
89
|
|
10
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
82
|
|
11
|
3
|
|
|
3
|
|
13
|
use utf8; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
16
|
|
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
2430
|
use Perl6::Export::Attrs; |
|
3
|
|
|
|
|
29413
|
|
|
3
|
|
|
|
|
18
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# }}} |
16
|
|
|
|
|
|
|
# {{{ variables declaration |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = 0.0682; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# }}} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# {{{ num2word |
23
|
|
|
|
|
|
|
sub num2word :Export { |
24
|
701
|
|
|
701
|
1
|
3069
|
my @a = @_; |
25
|
701
|
100
|
|
|
|
1342
|
@a || return (); |
26
|
699
|
100
|
|
|
|
1350
|
my @numbers = wantarray ? @a : shift @a; |
27
|
710
|
50
|
|
|
|
1283
|
my @results = map { ## no critic |
28
|
699
|
|
|
|
|
868
|
$_ < 0 && return $_; |
29
|
|
|
|
|
|
|
#$_ > 999999999999999999 && return $_; |
30
|
710
|
50
|
|
|
|
1094
|
$_ > 999999999999999 && return $_; |
31
|
710
|
100
|
|
|
|
1510
|
if ( $_ > 999999999999 ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
32
|
27
|
|
|
|
|
158
|
my ($bil,$mil) = /(.*)(\d{12})$/; |
33
|
27
|
|
|
|
|
51
|
my $a = num2word($bil); |
34
|
27
|
|
|
|
|
49
|
my $b = num2word($mil); |
35
|
27
|
|
|
|
|
35
|
my $e = ""; |
36
|
27
|
100
|
100
|
|
|
109
|
if ($b && $mil =~ /^0{9}/) { |
37
|
3
|
|
|
|
|
3
|
$e = " e"; |
38
|
|
|
|
|
|
|
} |
39
|
27
|
100
|
|
|
|
44
|
my $s = $b ? ' ' : ''; |
40
|
27
|
100
|
|
|
|
175
|
return $a . ($bil == 1 ? ' biliăo' : ' biliőes') . $e . $s . $b; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
elsif ( $_ > 999999 ) { |
43
|
79
|
|
|
|
|
382
|
my ($mil,$uni) = /(.*)(\d{6})$/; |
44
|
79
|
|
|
|
|
141
|
my $a = num2word($mil); |
45
|
79
|
|
|
|
|
134
|
my $b = num2word($uni); |
46
|
79
|
|
|
|
|
105
|
my $e = ""; |
47
|
79
|
100
|
|
|
|
121
|
my $s = $b ? ' ' : ''; |
48
|
79
|
100
|
|
|
|
301
|
if ($uni =~ /^000\d{0,2}[1-9]\d{0,2}|0\d?[1-9]\d?000|[1-9]0{5}/) { |
49
|
13
|
|
|
|
|
16
|
$e = " e"; |
50
|
|
|
|
|
|
|
} |
51
|
79
|
100
|
|
|
|
579
|
return $a . ($mil == 1 ? ' milhăo' : ' milhőes') . $e . $s . $b; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ( $_ > 9999 ) { |
54
|
138
|
|
|
|
|
314
|
$_ =~ /\d\d\d$/; |
55
|
138
|
|
|
|
|
240
|
my $a = num2word($`); |
56
|
138
|
|
|
|
|
374
|
my $b = num2word( 1000 + $& ); |
57
|
138
|
|
|
|
|
520
|
return "$a $b"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
else { |
60
|
466
|
|
|
|
|
678
|
s!^00+!!; |
61
|
466
|
|
|
|
|
487
|
s!^0+(?=[1-9])!!; |
62
|
466
|
|
|
|
|
547
|
s!9(?=\d\d\d)!nove mil e !; |
63
|
466
|
|
|
|
|
533
|
s!8(?=\d\d\d)!oito mil e !; |
64
|
466
|
|
|
|
|
484
|
s!7(?=\d\d\d)!sete mil e !; |
65
|
466
|
|
|
|
|
499
|
s!6(?=\d\d\d)!seis mil e !; |
66
|
466
|
|
|
|
|
473
|
s!5(?=\d\d\d)!cinco mil e !; |
67
|
466
|
|
|
|
|
490
|
s!4(?=\d\d\d)!quatro mil e !; |
68
|
466
|
|
|
|
|
495
|
s!3(?=\d\d\d)!tręs mil e !; |
69
|
466
|
|
|
|
|
501
|
s!2(?=\d\d\d)!dois mil e !; |
70
|
466
|
|
|
|
|
790
|
s!1(?=\d\d\d)!mil e !; |
71
|
466
|
|
|
|
|
595
|
s!9(?=\d\d)!novecentos e !; |
72
|
466
|
|
|
|
|
515
|
s!8(?=\d\d)!oitocentos e !; |
73
|
466
|
|
|
|
|
475
|
s!7(?=\d\d)!setecentos e !; |
74
|
466
|
|
|
|
|
524
|
s!6(?=\d\d)!seiscentos e !; |
75
|
466
|
|
|
|
|
485
|
s!5(?=\d\d)!quinhentos e !; |
76
|
466
|
|
|
|
|
531
|
s!4(?=\d\d)!quatrocentos e !; |
77
|
466
|
|
|
|
|
570
|
s!3(?=\d\d)!trezentos e !; |
78
|
466
|
|
|
|
|
518
|
s!2(?=\d\d)!duzentos e !; |
79
|
466
|
|
|
|
|
494
|
s!100!cem!; |
80
|
466
|
|
|
|
|
571
|
s!mil e 0+(?=[1-9])!mil e !; |
81
|
466
|
|
|
|
|
1106
|
s!1(?=\d\d)!cento e !; |
82
|
466
|
|
|
|
|
572
|
s!9(?=\d)!noventa e !; |
83
|
466
|
|
|
|
|
1046
|
s!8(?=\d)!oitenta e !; |
84
|
466
|
|
|
|
|
464
|
s!7(?=\d)!setenta e !; |
85
|
466
|
|
|
|
|
478
|
s!6(?=\d)!sessenta e !; |
86
|
466
|
|
|
|
|
488
|
s!5(?=\d)!cinquenta e !; |
87
|
466
|
|
|
|
|
516
|
s!4(?=\d)!quarenta e !; |
88
|
466
|
|
|
|
|
510
|
s!3(?=\d)!trinta e !; |
89
|
466
|
|
|
|
|
544
|
s!2(?=\d)!vinte e !; |
90
|
466
|
|
|
|
|
673
|
s/ e 0+(?=[1-9])/ e /; |
91
|
466
|
|
|
|
|
650
|
s/ e 0+//; |
92
|
466
|
|
|
|
|
516
|
s/19/dezanove/; |
93
|
466
|
|
|
|
|
444
|
s/18/dezoito/; |
94
|
466
|
|
|
|
|
442
|
s/17/dezassete/; |
95
|
466
|
|
|
|
|
429
|
s/16/dezasseis/; |
96
|
466
|
|
|
|
|
412
|
s/15/quinze/; |
97
|
466
|
|
|
|
|
438
|
s/14/catorze/; |
98
|
466
|
|
|
|
|
464
|
s/13/treze/; |
99
|
466
|
|
|
|
|
469
|
s/12/doze/; |
100
|
466
|
|
|
|
|
464
|
s/11/onze/; |
101
|
466
|
|
|
|
|
462
|
s/10/dez/; |
102
|
466
|
|
|
|
|
522
|
s/9/nove/; |
103
|
466
|
|
|
|
|
472
|
s/8/oito/; |
104
|
466
|
|
|
|
|
516
|
s/7/sete/; |
105
|
466
|
|
|
|
|
982
|
s/6/seis/; |
106
|
466
|
|
|
|
|
502
|
s/5/cinco/; |
107
|
466
|
|
|
|
|
461
|
s/4/quatro/; |
108
|
466
|
|
|
|
|
461
|
s/3/tręs/; |
109
|
466
|
|
|
|
|
483
|
s/2/dois/; |
110
|
466
|
|
|
|
|
471
|
s/1/um/; |
111
|
466
|
|
|
|
|
451
|
s/0/zero/; |
112
|
|
|
|
|
|
|
|
113
|
466
|
|
|
|
|
732
|
s!mil e (novecentos|oitocentos|setecentos|seiscentos) e!mil $1 e!; |
114
|
466
|
|
|
|
|
761
|
s!mil e (quinhentos|quatrocentos|trezentos|duzentos) e!mil $1 e!; |
115
|
466
|
|
|
|
|
487
|
s!mil e cento!mil cento!; |
116
|
|
|
|
|
|
|
|
117
|
466
|
|
|
|
|
1137
|
$_; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} @numbers; |
120
|
|
|
|
|
|
|
|
121
|
455
|
100
|
|
|
|
1464
|
return wantarray ? @results : $results[0]; |
122
|
3
|
|
|
3
|
|
4152
|
} |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
16
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# }}} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
__END__ |