line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# For Emacs: -*- mode:cperl; mode:folding; coding:utf-8 -*- |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Lingua::DEU::Num2Word; |
4
|
|
|
|
|
|
|
# ABSTRACT: Number 2 word conversion in DEU. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# {{{ use block |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
30896
|
use 5.10.1; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
47
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
11
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
35
|
|
12
|
1
|
|
|
1
|
|
6
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
23
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
113
|
|
15
|
1
|
|
|
1
|
|
879
|
use Readonly; |
|
1
|
|
|
|
|
2724
|
|
|
1
|
|
|
|
|
47
|
|
16
|
1
|
|
|
1
|
|
866
|
use Perl6::Export::Attrs; |
|
1
|
|
|
|
|
9845
|
|
|
1
|
|
|
|
|
6
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# }}} |
19
|
|
|
|
|
|
|
# {{{ variable declarations |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my Readonly::Scalar $COPY = 'Copyright (C) PetaMem, s.r.o. 2002-present'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = 0.1106; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# }}} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# {{{ num2deu_cardinal convert number to text |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub num2deu_cardinal :Export { |
30
|
7
|
|
|
7
|
1
|
2122
|
my $positive = shift; |
31
|
|
|
|
|
|
|
|
32
|
7
|
100
|
66
|
|
|
111
|
croak 'You should specify a number from interval [0, 999_999_999]' |
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
33
|
|
|
|
|
|
|
if !defined $positive |
34
|
|
|
|
|
|
|
|| $positive !~ m{\A\d+\z}xms |
35
|
|
|
|
|
|
|
|| $positive < 0 |
36
|
|
|
|
|
|
|
|| $positive > 999_999_999; |
37
|
|
|
|
|
|
|
|
38
|
5
|
|
|
|
|
19
|
my @tokens1 = qw(null ein zwei drei vier fünf sechs sieben acht neun zehn elf zwölf); |
39
|
5
|
|
|
|
|
14
|
my @tokens2 = qw(zwanzig dreissig vierzig fünfzig sechzig siebzig achtzig neunzig hundert); |
40
|
|
|
|
|
|
|
|
41
|
5
|
100
|
66
|
|
|
29
|
return $tokens1[$positive] if ($positive >= 0 && $positive < 13); # 0 .. 12 |
42
|
3
|
50
|
|
|
|
7
|
return 'sechzehn' if ($positive == 16); # 16 exception |
43
|
3
|
50
|
|
|
|
9
|
return 'siebzehn' if ($positive == 17); # 17 exception |
44
|
3
|
50
|
33
|
|
|
15
|
return $tokens1[$positive-10] . 'zehn' if ($positive > 12 && $positive < 20); # 13 .. 19 |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
5
|
my $out; # string for return value construction |
47
|
|
|
|
|
|
|
my $one_idx; # index for tokens1 array |
48
|
0
|
|
|
|
|
0
|
my $remain; # remainder |
49
|
|
|
|
|
|
|
|
50
|
3
|
100
|
66
|
|
|
32
|
if ($positive > 19 && $positive < 101) { # 20 .. 100 |
|
|
100
|
66
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
51
|
1
|
|
|
|
|
3
|
$one_idx = int ($positive / 10); |
52
|
1
|
|
|
|
|
3
|
$remain = $positive % 10; |
53
|
|
|
|
|
|
|
|
54
|
1
|
50
|
|
|
|
4
|
$out = "$tokens1[$remain]und" if ($remain); |
55
|
1
|
|
|
|
|
3
|
$out .= $tokens2[$one_idx - 2]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ($positive > 100 && $positive < 1000) { # 101 .. 999 |
58
|
1
|
|
|
|
|
4
|
$one_idx = int ($positive / 100); |
59
|
1
|
|
|
|
|
3
|
$remain = $positive % 100; |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
4
|
$out = "$tokens1[$one_idx]hundert"; |
62
|
1
|
50
|
|
|
|
9
|
$out .= $remain ? num2deu_cardinal($remain) : ''; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif ($positive > 999 && $positive < 1_000_000) { # 1000 .. 999_999 |
65
|
1
|
|
|
|
|
3
|
$one_idx = int ($positive / 1000); |
66
|
1
|
|
|
|
|
2
|
$remain = $positive % 1000; |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
3
|
$out = num2deu_cardinal($one_idx).'tausend'; |
69
|
1
|
50
|
|
|
|
5
|
$out .= $remain ? num2deu_cardinal($remain) : ''; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
elsif ( $positive > 999_999 |
72
|
|
|
|
|
|
|
&& $positive < 1_000_000_000) { # 1_000_000 .. 999_999_999 |
73
|
0
|
|
|
|
|
0
|
$one_idx = int ($positive / 1000000); |
74
|
0
|
|
|
|
|
0
|
$remain = $positive % 1000000; |
75
|
0
|
0
|
|
|
|
0
|
my $one = $one_idx == 1 ? 'e' : ''; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
$out = num2deu_cardinal($one_idx) . "$one million"; |
78
|
0
|
0
|
|
|
|
0
|
$out .= 'en' if ($one_idx > 1); |
79
|
0
|
0
|
|
|
|
0
|
$out .= $remain ? ' ' . num2deu_cardinal($remain) : ''; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
|
|
12
|
return $out; |
83
|
1
|
|
|
1
|
|
466
|
} |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# }}} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |