blib/lib/Lingua/KO/Hangul/Util.pm

filter: Statementstmt 100% 209 / 209 Branchbran 97.3% 72 / 74 Conditioncond 92.0% 46 / 50 MC/DCmcdc 83.3% 25 / 30 Subroutinesub 100% 46 / 46 Podpod 100% 13 / 13 totaltotal 97.3% 411 / 422 CC 55 SCAR 14.5
CC
55
Cov
98%
getSyllableType
11.0
composeSyllable
8.0
composeJamo
7.0
CRAP 4.3
↑ Summary
1 package Lingua::KO::Hangul::Util;
2  
3 6 ▶use 5.006001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 require Exporter;
8  
9 6 our $VERSION = '0.28';
10 6 our $PACKAGE = __PACKAGE__;
11  
12 6 our @EXPORT = qw(
13 decomposeHangul
14 composeHangul
15 getHangulName
16 parseHangulName
17 getHangulComposite
18 );
19 6 our @EXPORT_OK = qw(
20 decomposeSyllable
21 composeSyllable
22 decomposeJamo
23 composeJamo
24 decomposeFull
25 getSyllableType
26 isStandardForm
27 insertFiller
28 );
29 6 our %EXPORT_TAGS = (
30 'all' => [ @EXPORT, @EXPORT_OK ],
31 );
32  
33 ##### The above part is common to XS and PP #####
34  
35 6 our @ISA = qw(Exporter);
36 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 #####
39  
40 6 my @JamoL = ( # Initial (HANGUL CHOSEONG)
41 "G", "GG", "N", "D", "DD", "R", "M", "B", "BB",
42 "S", "SS", "", "J", "JJ", "C", "K", "T", "P", "H",
43 );
44  
45 6 my @JamoV = ( # Medial (HANGUL JUNGSEONG)
46 "A", "AE", "YA", "YAE", "EO", "E", "YEO", "YE", "O",
47 "WA", "WAE", "OE", "YO", "U", "WEO", "WE", "WI",
48 "YU", "EU", "YI", "I",
49 );
50  
51 6 my @JamoT = ( # Final (HANGUL JONGSEONG)
52 "", "G", "GG", "GS", "N", "NJ", "NH", "D", "L", "LG", "LM",
53 "LB", "LS", "LT", "LP", "LH", "M", "B", "BS",
54 "S", "SS", "NG", "J", "C", "K", "T", "P", "H",
55 );
56  
57 6 my $BlockName = "HANGUL SYLLABLE ";
58  
59 #####
60  
61 6 ▶use constant SBase => 0xAC00;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 6 ▶use constant SFinal => 0xD7A3; # SBase -1 + SCount
Subroutine BEGIN: called CC=1 SCAR=0.0
63 6 ▶use constant SCount => 11172; # LCount * NCount
Subroutine BEGIN: called CC=1 SCAR=0.0
64 6 ▶use constant NCount => 588; # VCount * TCount
Subroutine BEGIN: called CC=1 SCAR=0.0
65 6 ▶use constant LBase => 0x1100;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 6 ▶use constant LFinal => 0x1112;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 6 ▶use constant LCount => 19; # scalar @JamoL
Subroutine BEGIN: called CC=1 SCAR=0.0
68 6 ▶use constant VBase => 0x1161;
Subroutine BEGIN: called CC=1 SCAR=0.0
69 6 ▶use constant VFinal => 0x1175;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 6 ▶use constant VCount => 21; # scalar @JamoV
Subroutine BEGIN: called CC=1 SCAR=0.0
71 6 ▶use constant TBase => 0x11A7;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 6 ▶use constant TFinal => 0x11C2;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 6 ▶use constant TCount => 28; # scalar @JamoT
Subroutine BEGIN: called CC=1 SCAR=0.0
74 6 ▶use constant JBase => 0x1100;
Subroutine BEGIN: called CC=1 SCAR=0.0
75 6 ▶use constant JFinal => 0x11FF;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 6 ▶use constant JCount => 256;
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 6 ▶use constant JamoLIni => 0x1100;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 6 ▶use constant JamoLFin => 0x1159;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 6 ▶use constant JamoLFill => 0x115F;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 6 ▶use constant JamoVIni => 0x1160;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 6 ▶use constant JamoVFin => 0x11A2;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 6 ▶use constant JamoTIni => 0x11A8;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 6 ▶use constant JamoTFin => 0x11F9;
Subroutine BEGIN: called CC=1 SCAR=0.0
85  
86 6 my(%CodeL, %CodeV, %CodeT);
87 6 @CodeL{@JamoL} = 0 .. LCount-1;
88 6 @CodeV{@JamoV} = 0 .. VCount-1;
89 6 @CodeT{@JamoT} = 0 .. TCount-1;
90  
91 271 ▶my $IsJ = sub { JBase <= $_[0] && $_[0] <= JFinal };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
4352 <= $_[0] and $_[0] <= 4607 267 4 271
92 33567 ▶my $IsS = sub { SBase <= $_[0] && $_[0] <= SFinal };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
44032 <= $_[0] and $_[0] <= 55203 33544 23 33567
93 43956 ▶my $IsL = sub { LBase <= $_[0] && $_[0] <= LFinal };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
4352 <= $_[0] and $_[0] <= 4370 43938 18 43956
94 22361 ▶my $IsV = sub { VBase <= $_[0] && $_[0] <= VFinal };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
4449 <= $_[0] and $_[0] <= 4469 22358 3 22361
95 21567 ▶my $IsT = sub { TBase < $_[0] && $_[0] <= TFinal };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
4519 < $_[0] and $_[0] <= 4546 21557 10 21567
96 # TBase <= $_[0] is false!
97 21599 ▶my $IsLV = sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
98 21599 ▶ SBase <= $_[0] && $_[0] <= SFinal && (($_[0] - SBase ) % TCount) == 0;
Branch: 1 branch
BranchTrueFalseTotal
44032 <= $_[0] and $_[0] <= 55203 and ($_[0] - 44032) % 28 == 0 21570 29 21599
Condition66%2/3
44032 <= $_[0] and $_[0] <= 55203
!ll&&!rl&&r
29021570
MC/DC50%1/2
44032 <= $_[0] and $_[0] <= 55203
44032 <= $_[0] $_[0] <= 55203
Truth table66%2/3
A and B
A= 44032 <= $_[0]B= $_[0] <= 55203
ABresult
0X0
100
111
99 6 };
100  
101 #####
102  
103 # separator is a semicolon, ';'.
104 6 my %Map12; # ("integer;integer" => integer)
105 my %Map123; # ("integer;integer;integer" => integer)
106  
107 6 my %Decomp = (
108 0x1101 => [0x1100, 0x1100],
109 0x1104 => [0x1103, 0x1103],
110 0x1108 => [0x1107, 0x1107],
111 0x110A => [0x1109, 0x1109],
112 0x110D => [0x110C, 0x110C],
113 0x1113 => [0x1102, 0x1100],
114 0x1114 => [0x1102, 0x1102],
115 0x1115 => [0x1102, 0x1103],
116 0x1116 => [0x1102, 0x1107],
117 0x1117 => [0x1103, 0x1100],
118 0x1118 => [0x1105, 0x1102],
119 0x1119 => [0x1105, 0x1105],
120 0x111A => [0x1105, 0x1112],
121 0x111B => [0x1105, 0x110B],
122 0x111C => [0x1106, 0x1107],
123 0x111D => [0x1106, 0x110B],
124 0x111E => [0x1107, 0x1100],
125 0x111F => [0x1107, 0x1102],
126 0x1120 => [0x1107, 0x1103],
127 0x1121 => [0x1107, 0x1109],
128 0x1122 => [0x1107, 0x1109, 0x1100],
129 0x1123 => [0x1107, 0x1109, 0x1103],
130 0x1124 => [0x1107, 0x1109, 0x1107],
131 0x1125 => [0x1107, 0x1109, 0x1109],
132 0x1126 => [0x1107, 0x1109, 0x110C],
133 0x1127 => [0x1107, 0x110C],
134 0x1128 => [0x1107, 0x110E],
135 0x1129 => [0x1107, 0x1110],
136 0x112A => [0x1107, 0x1111],
137 0x112B => [0x1107, 0x110B],
138 0x112C => [0x1107, 0x1107, 0x110B],
139 0x112D => [0x1109, 0x1100],
140 0x112E => [0x1109, 0x1102],
141 0x112F => [0x1109, 0x1103],
142 0x1130 => [0x1109, 0x1105],
143 0x1131 => [0x1109, 0x1106],
144 0x1132 => [0x1109, 0x1107],
145 0x1133 => [0x1109, 0x1107, 0x1100],
146 0x1134 => [0x1109, 0x1109, 0x1109],
147 0x1135 => [0x1109, 0x110B],
148 0x1136 => [0x1109, 0x110C],
149 0x1137 => [0x1109, 0x110E],
150 0x1138 => [0x1109, 0x110F],
151 0x1139 => [0x1109, 0x1110],
152 0x113A => [0x1109, 0x1111],
153 0x113B => [0x1109, 0x1112],
154 0x113D => [0x113C, 0x113C],
155 0x113F => [0x113E, 0x113E],
156 0x1141 => [0x110B, 0x1100],
157 0x1142 => [0x110B, 0x1103],
158 0x1143 => [0x110B, 0x1106],
159 0x1144 => [0x110B, 0x1107],
160 0x1145 => [0x110B, 0x1109],
161 0x1146 => [0x110B, 0x1140],
162 0x1147 => [0x110B, 0x110B],
163 0x1148 => [0x110B, 0x110C],
164 0x1149 => [0x110B, 0x110E],
165 0x114A => [0x110B, 0x1110],
166 0x114B => [0x110B, 0x1111],
167 0x114D => [0x110C, 0x110B],
168 0x114F => [0x114E, 0x114E],
169 0x1151 => [0x1150, 0x1150],
170 0x1152 => [0x110E, 0x110F],
171 0x1153 => [0x110E, 0x1112],
172 0x1156 => [0x1111, 0x1107],
173 0x1157 => [0x1111, 0x110B],
174 0x1158 => [0x1112, 0x1112],
175 0x1162 => [0x1161, 0x1175],
176 0x1164 => [0x1163, 0x1175],
177 0x1166 => [0x1165, 0x1175],
178 0x1168 => [0x1167, 0x1175],
179 0x116A => [0x1169, 0x1161],
180 0x116B => [0x1169, 0x1161, 0x1175],
181 0x116C => [0x1169, 0x1175],
182 0x116F => [0x116E, 0x1165],
183 0x1170 => [0x116E, 0x1165, 0x1175],
184 0x1171 => [0x116E, 0x1175],
185 0x1174 => [0x1173, 0x1175],
186 0x1176 => [0x1161, 0x1169],
187 0x1177 => [0x1161, 0x116E],
188 0x1178 => [0x1163, 0x1169],
189 0x1179 => [0x1163, 0x116D],
190 0x117A => [0x1165, 0x1169],
191 0x117B => [0x1165, 0x116E],
192 0x117C => [0x1165, 0x1173],
193 0x117D => [0x1167, 0x1169],
194 0x117E => [0x1167, 0x116E],
195 0x117F => [0x1169, 0x1165],
196 0x1180 => [0x1169, 0x1165, 0x1175],
197 0x1181 => [0x1169, 0x1167, 0x1175],
198 0x1182 => [0x1169, 0x1169],
199 0x1183 => [0x1169, 0x116E],
200 0x1184 => [0x116D, 0x1163],
201 0x1185 => [0x116D, 0x1163, 0x1175],
202 0x1186 => [0x116D, 0x1167],
203 0x1187 => [0x116D, 0x1169],
204 0x1188 => [0x116D, 0x1175],
205 0x1189 => [0x116E, 0x1161],
206 0x118A => [0x116E, 0x1161, 0x1175],
207 0x118B => [0x116E, 0x1165, 0x1173],
208 0x118C => [0x116E, 0x1167, 0x1175],
209 0x118D => [0x116E, 0x116E],
210 0x118E => [0x1172, 0x1161],
211 0x118F => [0x1172, 0x1165],
212 0x1190 => [0x1172, 0x1165, 0x1175],
213 0x1191 => [0x1172, 0x1167],
214 0x1192 => [0x1172, 0x1167, 0x1175],
215 0x1193 => [0x1172, 0x116E],
216 0x1194 => [0x1172, 0x1175],
217 0x1195 => [0x1173, 0x116E],
218 0x1196 => [0x1173, 0x1173],
219 0x1197 => [0x1173, 0x1175, 0x116E],
220 0x1198 => [0x1175, 0x1161],
221 0x1199 => [0x1175, 0x1163],
222 0x119A => [0x1175, 0x1169],
223 0x119B => [0x1175, 0x116E],
224 0x119C => [0x1175, 0x1173],
225 0x119D => [0x1175, 0x119E],
226 0x119F => [0x119E, 0x1165],
227 0x11A0 => [0x119E, 0x116E],
228 0x11A1 => [0x119E, 0x1175],
229 0x11A2 => [0x119E, 0x119E],
230 0x11A9 => [0x11A8, 0x11A8],
231 0x11AA => [0x11A8, 0x11BA],
232 0x11AC => [0x11AB, 0x11BD],
233 0x11AD => [0x11AB, 0x11C2],
234 0x11B0 => [0x11AF, 0x11A8],
235 0x11B1 => [0x11AF, 0x11B7],
236 0x11B2 => [0x11AF, 0x11B8],
237 0x11B3 => [0x11AF, 0x11BA],
238 0x11B4 => [0x11AF, 0x11C0],
239 0x11B5 => [0x11AF, 0x11C1],
240 0x11B6 => [0x11AF, 0x11C2],
241 0x11B9 => [0x11B8, 0x11BA],
242 0x11BB => [0x11BA, 0x11BA],
243 0x11C3 => [0x11A8, 0x11AF],
244 0x11C4 => [0x11A8, 0x11BA, 0x11A8],
245 0x11C5 => [0x11AB, 0x11A8],
246 0x11C6 => [0x11AB, 0x11AE],
247 0x11C7 => [0x11AB, 0x11BA],
248 0x11C8 => [0x11AB, 0x11EB],
249 0x11C9 => [0x11AB, 0x11C0],
250 0x11CA => [0x11AE, 0x11A8],
251 0x11CB => [0x11AE, 0x11AF],
252 0x11CC => [0x11AF, 0x11A8, 0x11BA],
253 0x11CD => [0x11AF, 0x11AB],
254 0x11CE => [0x11AF, 0x11AE],
255 0x11CF => [0x11AF, 0x11AE, 0x11C2],
256 0x11D0 => [0x11AF, 0x11AF],
257 0x11D1 => [0x11AF, 0x11B7, 0x11A8],
258 0x11D2 => [0x11AF, 0x11B7, 0x11BA],
259 0x11D3 => [0x11AF, 0x11B8, 0x11BA],
260 0x11D4 => [0x11AF, 0x11B8, 0x11C2],
261 0x11D5 => [0x11AF, 0x11B8, 0x11BC],
262 0x11D6 => [0x11AF, 0x11BA, 0x11BA],
263 0x11D7 => [0x11AF, 0x11EB],
264 0x11D8 => [0x11AF, 0x11BF],
265 0x11D9 => [0x11AF, 0x11F9],
266 0x11DA => [0x11B7, 0x11A8],
267 0x11DB => [0x11B7, 0x11AF],
268 0x11DC => [0x11B7, 0x11B8],
269 0x11DD => [0x11B7, 0x11BA],
270 0x11DE => [0x11B7, 0x11BA, 0x11BA],
271 0x11DF => [0x11B7, 0x11EB],
272 0x11E0 => [0x11B7, 0x11BE],
273 0x11E1 => [0x11B7, 0x11C2],
274 0x11E2 => [0x11B7, 0x11BC],
275 0x11E3 => [0x11B8, 0x11AF],
276 0x11E4 => [0x11B8, 0x11C1],
277 0x11E5 => [0x11B8, 0x11C2],
278 0x11E6 => [0x11B8, 0x11BC],
279 0x11E7 => [0x11BA, 0x11A8],
280 0x11E8 => [0x11BA, 0x11AE],
281 0x11E9 => [0x11BA, 0x11AF],
282 0x11EA => [0x11BA, 0x11B8],
283 0x11EC => [0x11BC, 0x11A8],
284 0x11ED => [0x11BC, 0x11A8, 0x11A8],
285 0x11EE => [0x11BC, 0x11BC],
286 0x11EF => [0x11BC, 0x11BF],
287 0x11F1 => [0x11F0, 0x11BA],
288 0x11F2 => [0x11F0, 0x11EB],
289 0x11F3 => [0x11C1, 0x11B8],
290 0x11F4 => [0x11C1, 0x11BC],
291 0x11F5 => [0x11C2, 0x11AB],
292 0x11F6 => [0x11C2, 0x11AF],
293 0x11F7 => [0x11C2, 0x11B7],
294 0x11F8 => [0x11C2, 0x11B8],
295 );
296  
297 6 foreach my $char (sort {$a <=> $b} keys %Decomp) {
298 1122 ▶ $char or croak("$PACKAGE : composition to NULL is not allowed");
Branch: 1 branch
BranchTrueFalseTotal
$char or croak("$Lingua::KO::Hangul::Util::PACKAGE : composition to NULL is not allowed") 1122 0 1122
299 1122 my @dec = @{ $Decomp{$char} };
300 1122 ▶ @dec == 2 || @dec == 3 or
Branch: 1 branch
BranchTrueFalseTotal
@dec == 2 or @dec == 3 or croak(sprintf("$Lingua::KO::Hangul::Util::PACKAGE : weird decomposition [%04X]", $char)) 1122 0 1122
Condition66%2/3
@dec == 2 or @dec == 3
l!l&&r!l&&!r
9421800
MC/DC0%0/2
@dec == 2 or @dec == 3
@dec == 2 @dec == 3
Truth table66%2/3
A or B
A= @dec == 2B= @dec == 3
ABresult
1X1
011
000
301 croak(sprintf("$PACKAGE : weird decomposition [%04X]", $char));
302 1122 ▶ if (@dec == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dec == 2) { } 942 180 1122
303 942 $Map12{"$dec[0];$dec[1]"} = $char;
304 } else {
305 180 $Map123{"$dec[0];$dec[1];$dec[2]"} = $char;
306 }
307 }
308  
309 #####
310  
311 251 ▶sub getSyllableType($) {
Subroutine getSyllableType: called CC=11 SCAR=24.0
Pod documented
312 251 my $u = shift;
313 return
314 251 ▶ JamoLIni <= $u && $u <= JamoLFin || $u == JamoLFill ? "L" :
Branch: 5 branches
BranchTrueFalseTotal
4352 <= $u && $u <= 4441 || $u == 4447 ? : 59 192 251
4448 <= $u && $u <= 4514 ? : 60 132 192
4520 <= $u && $u <= 4601 ? : 34 98 132
44032 <= $u && $u <= 55203 ? : 59 39 98
($u - 44032) % 28 ? : 31 28 59
Condition100%15/15
4352 <= $u and $u <= 4441 or $u == 4447
l!l&&r!l&&!r
3227192
4352 <= $u and $u <= 4441
!ll&&!rl&&r
2819132
4448 <= $u and $u <= 4514
!ll&&!rl&&r
3010260
4520 <= $u and $u <= 4601
!ll&&!rl&&r
336534
44032 <= $u and $u <= 55203
!ll&&!rl&&r
37259
MC/DC100%3/3
4352 <= $u and $u <= 4441 or $u == 4447
4352 <= $u $u <= 4441 $u == 4447
MC/DC100%2/2
4448 <= $u and $u <= 4514
4448 <= $u $u <= 4514
MC/DC100%2/2
4520 <= $u and $u <= 4601
4520 <= $u $u <= 4601
MC/DC100%2/2
44032 <= $u and $u <= 55203
44032 <= $u $u <= 55203
Truth table80%4/5
A and B or C
A= 4352 <= $uB= $u <= 4441C= $u == 4447
ABCresult
11X1
0X11
1011
0X00
1000
Truth table100%3/3
A and B
A= 4448 <= $uB= $u <= 4514
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= 4520 <= $uB= $u <= 4601
ABresult
0X0
100
111
Truth table100%3/3
A and B
A= 44032 <= $uB= $u <= 55203
ABresult
0X0
100
111
315 JamoVIni <= $u && $u <= JamoVFin ? "V" :
316 JamoTIni <= $u && $u <= JamoTFin ? "T" :
317 SBase <= $u && $u <= SFinal ?
318 ($u - SBase) % TCount ? "LVT" : "LV" : "NA";
319 }
320  
321 6 my %Fillers = (
322 "LT" => [ 0x1160, 0x115F, 0x1160 ],
323 "LNA" => [ 0x1160 ],
324 "TV" => [ 0x115F ],
325 "LVTV" => [ 0x115F ],
326 "NAV" => [ 0x115F ],
327 "NAT" => [ 0x115F, 0x1160 ],
328 );
329  
330 50 ▶sub isStandardForm($) {
Subroutine isStandardForm: called CC=4 SCAR=13.9
Pod documented
331 50 my $str = shift(@_).pack('U*');
332  
333 50 my $ptype = 'NA';
334 50 foreach my $ch (unpack('U*', $str)) {
335 109 my $ctype = getSyllableType($ch);
336 109 ▶ return "" if $Fillers{"$ptype$ctype"};
Branch: 1 branch
BranchTrueFalseTotal
if $Fillers{"$ptype$ctype"} 13 96 109
337 96 $ptype = $ctype;
338 }
339 37 ▶ return $ptype eq "L" ? "" : 1;
Branch: 1 branch
BranchTrueFalseTotal
$ptype eq 'L' ? : 3 34 37
340 }
341  
342 51 ▶sub insertFiller($) {
Subroutine insertFiller: called CC=4 SCAR=13.9
Pod documented
343 51 my $str = shift(@_).pack('U*');
344 51 my $ptype = 'NA';
345 51 my(@ret);
346 51 foreach my $ch (unpack('U*', $str)) {
347 110 my $ctype = getSyllableType($ch);
348 $Fillers{"$ptype$ctype"} and
349 110 ▶ push(@ret, @{ $Fillers{"$ptype$ctype"} });
Branch: 1 branch
BranchTrueFalseTotal
$Fillers{"$ptype$ctype"} and push @ret, @{$Fillers{"$ptype$ctype"};} 13 97 110
350 110 push @ret, $ch;
351 110 $ptype = $ctype;
352 }
353 51 ▶ $ptype eq "L" and push(@ret, @{ $Fillers{"LNA"} });
Branch: 1 branch
BranchTrueFalseTotal
$ptype eq "L" and push @ret, @{$Fillers{"LNA"};} 4 47 51
354 51 return pack('U*', @ret);
355 }
356  
357 11184 ▶sub getHangulName ($) {
Subroutine getHangulName: called CC=2 SCAR=6.9
Pod documented
358 11184 my $u = shift;
359 11184 ▶ return undef unless &$IsS($u);
Branch: 1 branch
BranchTrueFalseTotal
unless &$IsS($u) 7 11177 11184
360 11177 my $sindex = $u - SBase;
361 11177 my $lindex = int( $sindex / NCount);
362 11177 my $vindex = int(($sindex % NCount) / TCount);
363 11177 my $tindex = $sindex % TCount;
364 11177 return "$BlockName$JamoL[$lindex]$JamoV[$vindex]$JamoT[$tindex]";
365 }
366  
367 11205 ▶sub parseHangulName ($) {
Subroutine parseHangulName: called CC=6 SCAR=17.9
Pod documented
368 11205 my $arg = shift;
369 11205 ▶ return undef unless $arg =~ s/$BlockName//o;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg =~ s/$BlockName//o 9 11196 11205
370 11196 ▶ return undef unless $arg =~ /^([^AEIOUWY]*)([AEIOUWY]+)([^AEIOUWY]*)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg =~ /^([^AEIOUWY]*)([AEIOUWY]+)([^AEIOUWY]*)$/ 3 11193 11196
371 return undef unless exists $CodeL{$1}
372 11193 ▶ && exists $CodeV{$2} && exists $CodeT{$3};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $CodeL{$1} and exists $CodeV{$2} and exists $CodeT{$3} 16 11177 11193
Condition100%6/6
exists $CodeL{$1} and exists $CodeV{$2} and exists $CodeT{$3}
!ll&&!rl&&r
11511177
exists $CodeL{$1} and exists $CodeV{$2}
!ll&&!rl&&r
5611182
MC/DC100%3/3
exists $CodeL{$1} and exists $CodeV{$2} and exists $CodeT{$3}
exists $CodeL{$1} exists $CodeV{$2} exists $CodeT{$3}
Truth table100%4/4
A and B and C
A= exists $CodeL{$1}B= exists $CodeV{$2}C= exists $CodeT{$3}
ABCresult
0XX0
10X0
1100
1111
373 11177 return SBase + $CodeL{$1} * NCount + $CodeV{$2} * TCount + $CodeT{$3};
374 }
375  
376 13 ▶sub getHangulComposite ($$) {
Subroutine getHangulComposite: called CC=5 SCAR=16.1
Pod documented
377 13 ▶ if (&$IsL($_[0]) && &$IsV($_[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$IsL($_[0]) and &$IsV($_[1])) 2 11 13
Condition100%3/3
&$IsL($_[0]) and &$IsV($_[1])
!ll&&!rl&&r
1012
MC/DC100%2/2
&$IsL($_[0]) and &$IsV($_[1])
&$IsL($_[0]) &$IsV($_[1])
Truth table100%3/3
A and B
A= &$IsL($_[0])B= &$IsV($_[1])
ABresult
0X0
100
111
378 2 my $lindex = $_[0] - LBase;
379 2 my $vindex = $_[1] - VBase;
380 2 return (SBase + ($lindex * VCount + $vindex) * TCount);
381 }
382 11 ▶ if (&$IsLV($_[0]) && &$IsT($_[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$IsLV($_[0]) and &$IsT($_[1])) 2 9 11
Condition100%3/3
&$IsLV($_[0]) and &$IsT($_[1])
!ll&&!rl&&r
812
MC/DC100%2/2
&$IsLV($_[0]) and &$IsT($_[1])
&$IsLV($_[0]) &$IsT($_[1])
Truth table100%3/3
A and B
A= &$IsLV($_[0])B= &$IsT($_[1])
ABresult
0X0
100
111
383 2 return($_[0] + $_[1] - TBase);
384 }
385 9 return undef;
386 }
387  
388 274 ▶sub decomposeJamo ($) {
Subroutine decomposeJamo: called CC=3 SCAR=11.0
Pod documented
389 274 my $str = shift(@_).pack('U*');
390 274 my(@ret);
391 274 foreach my $ch (unpack('U*', $str)) {
392 297 ▶ push @ret, $Decomp{$ch} ? @{ $Decomp{$ch} } : ($ch);
Branch: 1 branch
BranchTrueFalseTotal
$Decomp{$ch} ? : 197 100 297
393 }
394 274 return pack('U*', @ret);
395 }
396  
397 11190 ▶sub decomposeSyllable ($) {
Subroutine decomposeSyllable: called CC=3 SCAR=11.0
Pod documented
398 11190 my $str = shift(@_).pack('U*');
399 11190 my(@ret);
400 11190 foreach my $ch (unpack('U*', $str)) {
401 11202 my @r = decomposeHangul($ch);
402 11202 ▶ push @ret, @r ? @r : ($ch);
Branch: 1 branch
BranchTrueFalseTotal
@r ? : 11186 16 11202
403 }
404 11190 return pack('U*', @ret);
405 }
406  
407 22383 ▶sub decomposeHangul ($) {
Subroutine decomposeHangul: called CC=4 SCAR=13.9
Pod documented
408 22383 my $code = shift;
409 22383 ▶ return unless &$IsS($code);
Branch: 1 branch
BranchTrueFalseTotal
unless &$IsS($code) 19 22364 22383
410 22364 my $sindex = $code - SBase;
411 22364 my $lindex = int( $sindex / NCount);
412 22364 my $vindex = int(($sindex % NCount) / TCount);
413 22364 my $tindex = $sindex % TCount;
414 22364 ▶ my @ret = (
Branch: 1 branch
BranchTrueFalseTotal
$tindex ? : 21557 807 22364
415 LBase + $lindex,
416 VBase + $vindex,
417 $tindex ? (TBase + $tindex) : (),
418 );
419 22364 ▶ wantarray ? @ret : pack('U*', @ret);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 11188 11176 22364
420 }
421  
422 265 ▶sub composeJamo ($) {
Subroutine composeJamo: called CC=7 SCAR=19.5
Pod documented
423 265 my $str = shift(@_).pack('U*');
424 265 my @tmp = unpack('U*', $str);
425 265 ▶ for (my $i = 0; $i < @tmp; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @tmp) 271 265 536
426 271 ▶ next unless &$IsJ($tmp[$i]);
Branch: 1 branch
BranchTrueFalseTotal
unless &$IsJ($tmp[$i]) 7 264 271
427  
428 264 ▶ if ($tmp[$i + 2] && $Map123{"$tmp[$i];$tmp[$i+1];$tmp[$i+2]"}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tmp[$i + 2] and $Map123{"$tmp[$i];$tmp[$i + 1];$tmp[$i + 2]"}) { } 31 233 264
elsif ($tmp[$i + 1] and $Map12{"$tmp[$i];$tmp[$i + 1]"}) { } 162 140 302
Condition100%3/3
$tmp[$i + 2] and $Map123{"$tmp[$i];$tmp[$i + 1];$tmp[$i + 2]"}
!ll&&!rl&&r
229431
MC/DC100%2/2
$tmp[$i + 2] and $Map123{"$tmp[$i];$tmp[$i + 1];$tmp[$i + 2]"}
$tmp[$i + 2] $Map123{"$tmp[$i];$tmp[$i + 1];$tmp[$i + 2]"}
Truth table100%3/3
A and B
A= $tmp[$i + 2]B= $Map123{"$tmp[$i];$tmp[$i + 1];$tmp[$i + 2]"}
ABresult
0X0
100
111
429 31 $tmp[$i] = $Map123{"$tmp[$i];$tmp[$i+1];$tmp[$i+2]"};
430 31 $tmp[$i+1] = $tmp[$i+2] = undef;
431 31 $i += 2;
432 }
433 ▶ elsif ($tmp[$i + 1] && $Map12{"$tmp[$i];$tmp[$i+1]"}) {
Condition100%3/3
$tmp[$i + 1] and $Map12{"$tmp[$i];$tmp[$i + 1]"}
!ll&&!rl&&r
692162
MC/DC100%2/2
$tmp[$i + 1] and $Map12{"$tmp[$i];$tmp[$i + 1]"}
$tmp[$i + 1] $Map12{"$tmp[$i];$tmp[$i + 1]"}
Truth table100%3/3
A and B
A= $tmp[$i + 1]B= $Map12{"$tmp[$i];$tmp[$i + 1]"}
ABresult
0X0
100
111
434 162 $tmp[$i] = $Map12{"$tmp[$i];$tmp[$i+1]"};
435 162 $tmp[$i+1] = undef;
436 162 $i ++;
437 }
438 }
439 265 return pack 'U*', grep defined, @tmp;
440 }
441  
442 22370 ▶sub composeSyllable ($) {
Subroutine composeSyllable: called CC=8 SCAR=20.8
Pod documented
443 22370 my $str = shift(@_).pack('U*');
444 22370 my(@ret);
445 22370 foreach my $ch (unpack('U*', $str)) {
446 66310 ▶ push(@ret, $ch) and next unless @ret;
Branch: 1 branch
BranchTrueFalseTotal
unless @ret 22367 43943 66310
Condition60%3/5
@ret || push(@ret, $ch) && (next)
l!l&&r!l&&!r
43943223670
push @ret, $ch and next
!ll
022367
MC/DC0%0/2
@ret || push(@ret, $ch) && (next)
@ret push @ret, $ch
Truth table66%2/3
A || B
A= @retB= push @ret, $ch
ABresult
1X1
011
000
447  
448 # 1. check to see if $ret[-1] is L and $ch is V.
449  
450 43943 ▶ if (&$IsL($ret[-1]) && &$IsV($ch)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$IsL($ret[-1]) and &$IsV($ch)) 22355 21588 43943
Condition100%3/3
&$IsL($ret[-1]) and &$IsV($ch)
!ll&&!rl&&r
21585322355
MC/DC100%2/2
&$IsL($ret[-1]) and &$IsV($ch)
&$IsL($ret[-1]) &$IsV($ch)
Truth table100%3/3
A and B
A= &$IsL($ret[-1])B= &$IsV($ch)
ABresult
0X0
100
111
451 22355 $ret[-1] -= LBase; # LIndex
452 22355 $ch -= VBase; # VIndex
453 22355 $ret[-1] = SBase + ($ret[-1] * VCount + $ch) * TCount;
454 22355 next; # discard $ch
455 }
456  
457 # 2. check to see if $ret[-1] is LV and $ch is T.
458  
459 21588 ▶ if (&$IsLV($ret[-1]) && &$IsT($ch)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$IsLV($ret[-1]) and &$IsT($ch)) 21555 33 21588
Condition100%3/3
&$IsLV($ret[-1]) and &$IsT($ch)
!ll&&!rl&&r
24921555
MC/DC100%2/2
&$IsLV($ret[-1]) and &$IsT($ch)
&$IsLV($ret[-1]) &$IsT($ch)
Truth table100%3/3
A and B
A= &$IsLV($ret[-1])B= &$IsT($ch)
ABresult
0X0
100
111
460 21555 $ret[-1] += $ch - TBase; # + TIndex
461 21555 next; # discard $ch
462 }
463  
464 # 3. just append $ch
465 33 push(@ret, $ch);
466 }
467 22370 return pack('U*', @ret);
468 }
469  
470 ##### The below part is common to XS and PP #####
471  
472 9 ▶sub decomposeFull ($) { decomposeJamo(decomposeSyllable(shift)) }
Subroutine decomposeFull: called CC=1 SCAR=0.0
Pod documented
473  
474 11189 ▶sub composeHangul ($) {
Subroutine composeHangul: called CC=2 SCAR=6.9
Pod documented
475 11189 my $ret = composeSyllable(shift);
476 11189 ▶ wantarray ? unpack('U*', $ret) : $ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 11180 9 11189
477 }
478  
479 6 1;
480 __END__
↑ Summary