line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
################################################## |
2
|
|
|
|
|
|
|
# Lingua::JA::Number |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Mike Schilli, 2001 (m@perlmeister.com) |
5
|
|
|
|
|
|
|
################################################## |
6
|
|
|
|
|
|
|
package Lingua::JA::Number; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1080
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
318
|
|
9
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
54
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
9
|
use Exporter (); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1042
|
|
12
|
|
|
|
|
|
|
our $VERSION = 0.01; |
13
|
|
|
|
|
|
|
our @ISA = qw (Exporter); |
14
|
|
|
|
|
|
|
our @EXPORT = qw (); |
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw ( to_string ); |
16
|
|
|
|
|
|
|
our %EXPORT_TAGS = (); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my %N2J = qw( |
19
|
|
|
|
|
|
|
1 ichi 2 ni 3 san 4 yon 5 go 6 roku 7 nana |
20
|
|
|
|
|
|
|
8 hachi 9 kyu 10 ju 100 hyaku 1000 sen); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my %N2J_EXCP = qw( |
23
|
|
|
|
|
|
|
300 san-byaku 600 ro-p-pyaku 800 ha-p-pyaku |
24
|
|
|
|
|
|
|
3000 san-zen 8000 ha-s-sen); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my @N2J_BLOCK = ("", "man", "oku", "cho"); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my %N2J_BLOCK_EXCP = qw( 1 i-t-cho 8 ha-t-cho |
29
|
|
|
|
|
|
|
0 ju-t-cho); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
################################################## |
32
|
|
|
|
|
|
|
sub to_string { |
33
|
|
|
|
|
|
|
################################################## |
34
|
4
|
|
|
4
|
0
|
109
|
my $n = shift; |
35
|
|
|
|
|
|
|
|
36
|
4
|
50
|
33
|
|
|
24
|
if($n < 1 || $n >= 1E16) { |
37
|
0
|
|
|
|
|
0
|
warn "$n needs to be >=1 and <1E16.\n"; |
38
|
0
|
|
|
|
|
0
|
return undef; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
4
|
|
|
|
|
8
|
my @result = (); |
42
|
4
|
|
|
|
|
9
|
$n = reverse $n; |
43
|
4
|
|
|
|
|
6
|
my $bix = 0; |
44
|
|
|
|
|
|
|
|
45
|
4
|
|
|
|
|
20
|
while($n =~ /(\d{1,4})/g) { |
46
|
8
|
|
|
|
|
15
|
my $b = scalar reverse($1); |
47
|
8
|
|
|
|
|
18
|
my @r = blockof4_to_string($b); |
48
|
|
|
|
|
|
|
|
49
|
8
|
100
|
100
|
|
|
24
|
if($bix && @r) { |
50
|
2
|
100
|
66
|
|
|
15
|
if($bix == 3 && |
51
|
|
|
|
|
|
|
$b =~ /[1-9]0$|[18]$/) { |
52
|
1
|
|
|
|
|
5
|
$r[$#r] = $N2J_BLOCK_EXCP{$b%10}; |
53
|
|
|
|
|
|
|
} else { |
54
|
1
|
|
|
|
|
3
|
push @r, $N2J_BLOCK[$bix]; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
8
|
|
|
|
|
13
|
unshift @result, @r; |
58
|
8
|
|
|
|
|
23
|
$bix++; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
4
|
|
|
|
|
17
|
return @result; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
################################################## |
65
|
|
|
|
|
|
|
sub blockof4_to_string { |
66
|
|
|
|
|
|
|
################################################## |
67
|
8
|
|
|
8
|
0
|
9
|
my $n = shift; |
68
|
|
|
|
|
|
|
|
69
|
8
|
50
|
33
|
|
|
33
|
return undef if $n > 9999 or $n < 0; |
70
|
8
|
50
|
|
|
|
20
|
return "" unless $n; |
71
|
|
|
|
|
|
|
|
72
|
8
|
|
|
|
|
10
|
my @result = (); |
73
|
8
|
|
|
|
|
30
|
my @digits = split //, sprintf("%04d", $n); |
74
|
8
|
|
|
|
|
14
|
my @weights = (1000, 100, 10, 1); |
75
|
|
|
|
|
|
|
|
76
|
8
|
|
|
|
|
13
|
for my $i (0..3) { |
77
|
32
|
100
|
|
|
|
58
|
next unless $digits[$i]; |
78
|
9
|
|
|
|
|
14
|
my $v = $digits[$i] * $weights[$i]; |
79
|
9
|
|
66
|
|
|
61
|
push @result, $N2J_EXCP{$v} || |
80
|
|
|
|
|
|
|
$N2J{$v} || |
81
|
|
|
|
|
|
|
($N2J{$digits[$i]}, |
82
|
|
|
|
|
|
|
$N2J{$weights[$i]}); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
8
|
|
|
|
|
24
|
return @result; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |