line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::JA::Dakuon; |
2
|
7
|
|
|
7
|
|
366901
|
use 5.008005; |
|
7
|
|
|
|
|
28
|
|
|
7
|
|
|
|
|
355
|
|
3
|
7
|
|
|
7
|
|
44
|
use strict; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
235
|
|
4
|
7
|
|
|
7
|
|
49
|
use warnings; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
177
|
|
5
|
7
|
|
|
7
|
|
1113
|
use utf8; |
|
7
|
|
|
|
|
23
|
|
|
7
|
|
|
|
|
43
|
|
6
|
7
|
|
|
7
|
|
283
|
use Exporter 'import'; |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
12338
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw{ |
11
|
|
|
|
|
|
|
dakuon handakuon seion |
12
|
|
|
|
|
|
|
dakuon_normalize |
13
|
|
|
|
|
|
|
handakuon_normalize |
14
|
|
|
|
|
|
|
all_dakuon_normalize |
15
|
|
|
|
|
|
|
}; |
16
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
17
|
|
|
|
|
|
|
all => \@EXPORT_OK, |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $EnableCombining = 0; |
21
|
|
|
|
|
|
|
our $PreferCombining = 0; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my %Dakuon = map { split // } qw{ |
24
|
|
|
|
|
|
|
かが きぎ くぐ けげ こご |
25
|
|
|
|
|
|
|
さざ しじ すず せぜ そぞ |
26
|
|
|
|
|
|
|
ただ ちぢ つづ てで とど |
27
|
|
|
|
|
|
|
はば ひび ふぶ へべ ほぼ |
28
|
|
|
|
|
|
|
うゔ ゝゞ |
29
|
|
|
|
|
|
|
カガ キギ クグ ケゲ コゴ |
30
|
|
|
|
|
|
|
サザ シジ スズ セゼ ソゾ |
31
|
|
|
|
|
|
|
タダ チヂ ツヅ テデ トド |
32
|
|
|
|
|
|
|
ハバ ヒビ フブ ヘベ ホボ |
33
|
|
|
|
|
|
|
ウヴ ワヷ ヰヸ ヱヹ ヲヺ |
34
|
|
|
|
|
|
|
ヽヾ |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
my %DakuonRev = reverse %Dakuon; |
37
|
|
|
|
|
|
|
my $DakuonRE = '[' . join('', keys %DakuonRev) . ']'; |
38
|
|
|
|
|
|
|
my %Handakuon = map { split // } qw{ |
39
|
|
|
|
|
|
|
はぱ ひぴ ふぷ へぺ ほぽ |
40
|
|
|
|
|
|
|
ハパ ヒピ フプ ヘペ ホポ |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
my %HandakuonRev = reverse %Handakuon; |
43
|
|
|
|
|
|
|
my $HandakuonRE = '[' . join('', keys %HandakuonRev) . ']'; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $HankakuKatakanaRE = '[ヲ-ン]'; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
our $AllDakuonRE = "(?:$DakuonRE|.[゛\x{3099}]|$HankakuKatakanaRE\゙)"; |
48
|
|
|
|
|
|
|
our $AllHandakuonRE = "(?:$HandakuonRE|.[゜\x{309a}]|$HankakuKatakanaRE\゚)"; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub dakuon { |
51
|
77
|
|
|
77
|
1
|
32598
|
my ($c) = @_; |
52
|
77
|
100
|
|
|
|
274
|
return if length($c) != 1; # Expected argument is a single char |
53
|
|
|
|
|
|
|
|
54
|
75
|
100
|
|
|
|
648
|
my $dc = $PreferCombining ? undef : $Dakuon{$c}; |
55
|
75
|
100
|
|
|
|
155
|
if (!$dc) { |
56
|
15
|
100
|
|
|
|
174
|
if ($c =~ /^$HankakuKatakanaRE$/) { |
57
|
8
|
|
|
|
|
19
|
$dc = "$c\゙"; |
58
|
|
|
|
|
|
|
} else { |
59
|
7
|
100
|
66
|
|
|
53
|
$dc = ($EnableCombining || $PreferCombining) ? "$c\x{3099}" : $c; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
75
|
|
|
|
|
429
|
$dc; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub handakuon { |
66
|
35
|
|
|
35
|
1
|
23685
|
my ($c) = @_; |
67
|
35
|
100
|
|
|
|
557
|
return if length($c) != 1; # Expected argument is a single char |
68
|
|
|
|
|
|
|
|
69
|
33
|
100
|
|
|
|
119
|
my $dc = $PreferCombining ? undef : $Handakuon{$c}; |
70
|
33
|
100
|
|
|
|
82
|
if (!$dc) { |
71
|
15
|
100
|
|
|
|
185
|
if ($c =~ /^$HankakuKatakanaRE$/) { |
72
|
8
|
|
|
|
|
60
|
$dc = "$c\゚"; |
73
|
|
|
|
|
|
|
} else { |
74
|
7
|
100
|
66
|
|
|
54
|
$dc = ($EnableCombining || $PreferCombining) ? "$c\x{309a}" : $c; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
33
|
|
|
|
|
223
|
$dc; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub seion { |
81
|
87
|
|
|
87
|
1
|
9563
|
my ($c) = @_; |
82
|
87
|
|
|
|
|
454
|
my $len = length($c); |
83
|
|
|
|
|
|
|
# Expected argument is a single char or single char followed by combining char |
84
|
87
|
100
|
100
|
|
|
395
|
return unless $len == 1 || |
|
|
|
66
|
|
|
|
|
85
|
|
|
|
|
|
|
$len == 2 && $c =~ /[゛゜\x{3099}\x{309a}゙゚]$/; |
86
|
|
|
|
|
|
|
|
87
|
85
|
100
|
100
|
|
|
1143
|
$DakuonRev{$c} || $HandakuonRev{$c} || substr($c, 0, 1); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub dakuon_normalize { |
91
|
5
|
|
|
5
|
1
|
9926
|
my ($s) = @_; |
92
|
|
|
|
|
|
|
|
93
|
5
|
100
|
|
|
|
19
|
if ($PreferCombining) { |
94
|
2
|
|
|
|
|
76
|
$s =~ s{($DakuonRE)}{"$DakuonRev{$1}\x{3099}"}ge; |
|
4
|
|
|
|
|
27
|
|
95
|
2
|
|
|
|
|
15
|
$s =~ s{゛}{\x{3099}}g; |
96
|
|
|
|
|
|
|
} else { |
97
|
3
|
|
|
|
|
54
|
$s =~ s{(.)[゛\x{3099}]}{dakuon($1)}ge; |
|
12
|
|
|
|
|
29
|
|
98
|
|
|
|
|
|
|
} |
99
|
5
|
|
|
|
|
222
|
$s =~ s{($HankakuKatakanaRE)[゛\x{3099}]}{$1゙}g; |
100
|
5
|
|
|
|
|
30
|
$s; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub handakuon_normalize { |
104
|
5
|
|
|
5
|
1
|
10033
|
my ($s) = @_; |
105
|
|
|
|
|
|
|
|
106
|
5
|
100
|
|
|
|
20
|
if ($PreferCombining) { |
107
|
2
|
|
|
|
|
53
|
$s =~ s{($HandakuonRE)}{"$HandakuonRev{$1}\x{309a}"}ge; |
|
2
|
|
|
|
|
19
|
|
108
|
2
|
|
|
|
|
14
|
$s =~ s{゜}{\x{309a}}g; |
109
|
|
|
|
|
|
|
} else { |
110
|
3
|
|
|
|
|
44
|
$s =~ s{(.)[゜\x{309a}]}{handakuon($1)}ge; |
|
12
|
|
|
|
|
28
|
|
111
|
|
|
|
|
|
|
} |
112
|
5
|
|
|
|
|
80
|
$s =~ s{($HankakuKatakanaRE)[゜\x{309a}]}{$1゚}g; |
113
|
5
|
|
|
|
|
34
|
$s; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub all_dakuon_normalize { |
117
|
1
|
|
|
1
|
1
|
13
|
handakuon_normalize dakuon_normalize @_; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
__END__ |