blib/lib/Lingua/Cyrillic/Translit/ICAO.pm

filter: Statementstmt 100% 60 / 60 Branchbran 55.0% 22 / 40 Conditioncond 35.0% 21 / 60 MC/DCmcdc 2.6% 1 / 38 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 54.3% 112 / 206 CC 42 SCAR 51.2
CC
42
Cov
64%
cyr2icao
190.7
BEGIN
1.0
BEGIN
1.0
CRAP 167.0
↑ Summary
1 # Lingua/Cyrillic/Translit/ICAO.pm
2 #
3 # $Id: ICAO.pm 7 2009-09-16 15:41:34Z stro $
4 #
5 # Copyright (c) 2007-2009 Serguei Trouchelle. All rights reserved.
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the same terms as Perl itself.
9  
10 # History:
11 # 1.05 2009/09/16 Changed 5.8.0 to 5.008
12 # 1.04 2007/07/07 use Encode in preference of Text::Iconv (thanks to Nikita Dedik)
13 # Rate Text::Iconv Encode
14 # Text::Iconv 13243/s -- -41%
15 # Encode 22386/s 69% --
16 # 1.03 2007/07/05 use 5.8.0 added
17 # 1.02 2007/07/04 POD fixes
18 # 1.01 2007/07/02 Initial revision
19  
20 =head1 NAME
21  
22 Lingua::Cyrillic::Translit::ICAO -- Cyrillic characters transliteration into ICAO Doc 9303
23  
24 =head1 SYNOPSIS
25  
26 use Lingua::Cyrillic::Translit::ICAO qw/ cyr2icao /;
27  
28 print cyr2icao('ukrainian', 'koi8-r');
29  
30 =head1 DESCRIPTION
31  
32 Lingua::Cyrillic::Translit::ICAO can be used for transliteration of Cyrillic
33 characters in conformance with ICAO Doc 9303 Recommendations.
34  
35 =head1 METHODS
36  
37 =cut
38  
39 package Lingua::Cyrillic::Translit::ICAO;
40  
41 4 require Exporter;
42 4 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 4 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 4 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 4 our @EXPORT = qw/ /;
52 4 our @EXPORT_OK = qw/ cyr2icao /;
53 4 our %EXPORT_TAGS = qw / /;
54 4 our @ISA = qw/Exporter/;
55  
56 4 our $VERSION = '1.05';
57  
58 4 my $table = q!1 1
59 А A
60 Б B
61 В V
62 Г G
63 Д D
64 Е E
65 Ё E
66 Ж ZH
67 З Z
68 И I
69 І I
70 Й I
71 К K
72 Л L
73 М M
74 Н N
75 О O
76 П P
77 Р R
78 С S
79 Т T
80 У U
81 Ф F
82 Х KH
83 Ц TS
84 Ч CH
85 Ш SH
86 Щ SHCH
87 Ы Y
88 Ѣ IE
89 Э E
90 Ю IU
91 Я IA
92 Ѵ Y
93 Ґ G
94 Ў U
95 Ѫ U
96 Ѓ G
97 Ђ D
98 Ѕ DZ
99 Ј J
100 Ќ K
101 Љ LJ
102 Њ NJ
103 Һ C
104 Џ DZ
105 Є IE
106 Ї I
107 а a
108 б b
109 в v
110 г g
111 д d
112 е e
113 ё e
114 ж zh
115 з z
116 и i
117 і i
118 й i
119 к k
120 л l
121 м m
122 н n
123 о o
124 п p
125 р r
126 с s
127 т t
128 у u
129 ф f
130 х kh
131 ц ts
132 ч ch
133 ш sh
134 щ shch
135 ы y
136 ѣ ie
137 э e
138 ю iu
139 я ia
140 ѵ y
141 ґ g
142 ў u
143 ѫ u
144 ѓ g
145 ђ d
146 ѕ dz
147 ј j
148 ќ k
149 љ lj
150 њ nj
151 һ c
152 џ dz
153 є ie
154 ї i
155 2 2!;
156  
157 4 our %cyr2icao = split /\s+/, $table;
158  
159 # skip hard and soft signs
160 4 $cyr2icao{'Ъ'} = '';
161 4 $cyr2icao{'ъ'} = '';
162 4 $cyr2icao{'Ь'} = '';
163 4 $cyr2icao{'ь'} = '';
164  
165 =head2 cyr2icao ( $string, [$language], [ $encoding ])
166  
167 This method converts $string from Cyrillic character set to ICAO transliteration.
168  
169 Optional $language parameter allow to specify $string's language. Valid values are:
170  
171 =over 1
172  
173 =item 'by' - Belorussian
174  
175 =item 'bu' - Bulgarian
176  
177 =item 'mk' - Macedonian
178  
179 =item 'uk' - Ukrainian
180  
181 =back
182  
183 Other values are accepted but do not affect anything.
184  
185 Optional $encoding parameter allows to specify $string's encoding (default is 'utf-8')
186  
187 =cut
188  
189 6 ▶sub cyr2icao {
Subroutine cyr2icao: called CC=42 SCAR=52.5
Pod documented
190 6 my $val = shift;
191 6 my $lang = shift;
192 6 my $enc = shift;
193 6 ▶ if ($enc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enc) 6 0 6
194 6 $val = Encode::decode($enc, $val);
195 } # else think of utf-8
196 6 utf8::decode($val);
197 6 my $res = '';
198 6 foreach (0 .. length $val) {
199 42 $_ = substr($val, $_, 1);
200 42 ▶ $_ = 'H' if $_ eq 'Г' and ($lang eq 'by' or $lang eq 'mk');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{413}" and $lang eq "by" || $lang eq "mk" 0 42 42
Condition16%1/6
$_ eq "\x{413}" and $lang eq "by" || $lang eq "mk"
!ll&&!rl&&r
4200
$lang eq "by" or $lang eq "mk"
l!l&&r!l&&!r
000
MC/DC0%0/3
$_ eq "\x{413}" and $lang eq "by" || $lang eq "mk"
$_ eq "\x{413}" $lang eq "by" $lang eq "mk"
Truth table25%1/4
A and B or C
A= $_ eq "\x{413}"B= $lang eq "by"C= $lang eq "mk"
ABCresult
0XX0
1000
11X1
1011
201 42 ▶ $_ = 'h' if $_ eq 'г' and ($lang eq 'by' or $lang eq 'mk');
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{433}" and $lang eq "by" || $lang eq "mk" 0 42 42
Condition16%1/6
$_ eq "\x{433}" and $lang eq "by" || $lang eq "mk"
!ll&&!rl&&r
4200
$lang eq "by" or $lang eq "mk"
l!l&&r!l&&!r
000
MC/DC0%0/3
$_ eq "\x{433}" and $lang eq "by" || $lang eq "mk"
$_ eq "\x{433}" $lang eq "by" $lang eq "mk"
Truth table25%1/4
A and B or C
A= $_ eq "\x{433}"B= $lang eq "by"C= $lang eq "mk"
ABCresult
0XX0
1000
11X1
1011
202 42 ▶ $_ = 'IO' if $_ eq 'Ё' and $lang eq 'by';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{401}" and $lang eq "by" 0 42 42
Condition33%1/3
$_ eq "\x{401}" and $lang eq "by"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{401}" and $lang eq "by"
$_ eq "\x{401}" $lang eq "by"
Truth table33%1/3
A and B
A= $_ eq "\x{401}"B= $lang eq "by"
ABresult
0X0
100
111
203 42 ▶ $_ = 'io' if $_ eq 'ё' and $lang eq 'by';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{451}" and $lang eq "by" 0 42 42
Condition33%1/3
$_ eq "\x{451}" and $lang eq "by"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{451}" and $lang eq "by"
$_ eq "\x{451}" $lang eq "by"
Truth table33%1/3
A and B
A= $_ eq "\x{451}"B= $lang eq "by"
ABresult
0X0
100
111
204 42 ▶ $_ = 'Z' if $_ eq 'Ж' and $lang eq 'mk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{416}" and $lang eq "mk" 0 42 42
Condition33%1/3
$_ eq "\x{416}" and $lang eq "mk"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{416}" and $lang eq "mk"
$_ eq "\x{416}" $lang eq "mk"
Truth table33%1/3
A and B
A= $_ eq "\x{416}"B= $lang eq "mk"
ABresult
0X0
100
111
205 42 ▶ $_ = 'z' if $_ eq 'ж' and $lang eq 'mk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{436}" and $lang eq "mk" 0 42 42
Condition33%1/3
$_ eq "\x{436}" and $lang eq "mk"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{436}" and $lang eq "mk"
$_ eq "\x{436}" $lang eq "mk"
Truth table33%1/3
A and B
A= $_ eq "\x{436}"B= $lang eq "mk"
ABresult
0X0
100
111
206 42 ▶ $_ = 'Y' if $_ eq 'И' and $lang eq 'uk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{418}" and $lang eq "uk" 0 42 42
Condition33%1/3
$_ eq "\x{418}" and $lang eq "uk"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{418}" and $lang eq "uk"
$_ eq "\x{418}" $lang eq "uk"
Truth table33%1/3
A and B
A= $_ eq "\x{418}"B= $lang eq "uk"
ABresult
0X0
100
111
207 42 ▶ $_ = 'y' if $_ eq 'и' and $lang eq 'uk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{438}" and $lang eq "uk" 1 41 42
Condition66%2/3
$_ eq "\x{438}" and $lang eq "uk"
!ll&&!rl&&r
4101
MC/DC50%1/2
$_ eq "\x{438}" and $lang eq "uk"
$_ eq "\x{438}" $lang eq "uk"
Truth table66%2/3
A and B
A= $_ eq "\x{438}"B= $lang eq "uk"
ABresult
0X0
100
111
208 42 ▶ $_ = 'H' if $_ eq 'Х' and $lang eq 'mk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{425}" and $lang eq "mk" 0 42 42
Condition33%1/3
$_ eq "\x{425}" and $lang eq "mk"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{425}" and $lang eq "mk"
$_ eq "\x{425}" $lang eq "mk"
Truth table33%1/3
A and B
A= $_ eq "\x{425}"B= $lang eq "mk"
ABresult
0X0
100
111
209 42 ▶ $_ = 'h' if $_ eq 'х' and $lang eq 'mk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{445}" and $lang eq "mk" 0 42 42
Condition33%1/3
$_ eq "\x{445}" and $lang eq "mk"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{445}" and $lang eq "mk"
$_ eq "\x{445}" $lang eq "mk"
Truth table33%1/3
A and B
A= $_ eq "\x{445}"B= $lang eq "mk"
ABresult
0X0
100
111
210 42 ▶ $_ = 'C' if $_ eq 'Ц' and $lang eq 'mk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{426}" and $lang eq "mk" 0 42 42
Condition33%1/3
$_ eq "\x{426}" and $lang eq "mk"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{426}" and $lang eq "mk"
$_ eq "\x{426}" $lang eq "mk"
Truth table33%1/3
A and B
A= $_ eq "\x{426}"B= $lang eq "mk"
ABresult
0X0
100
111
211 42 ▶ $_ = 'c' if $_ eq 'ц' and $lang eq 'mk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{446}" and $lang eq "mk" 0 42 42
Condition66%2/3
$_ eq "\x{446}" and $lang eq "mk"
!ll&&!rl&&r
4110
MC/DC0%0/2
$_ eq "\x{446}" and $lang eq "mk"
$_ eq "\x{446}" $lang eq "mk"
Truth table66%2/3
A and B
A= $_ eq "\x{446}"B= $lang eq "mk"
ABresult
0X0
100
111
212 42 ▶ $_ = 'C' if $_ eq 'Ч' and $lang eq 'mk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{427}" and $lang eq "mk" 0 42 42
Condition33%1/3
$_ eq "\x{427}" and $lang eq "mk"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{427}" and $lang eq "mk"
$_ eq "\x{427}" $lang eq "mk"
Truth table33%1/3
A and B
A= $_ eq "\x{427}"B= $lang eq "mk"
ABresult
0X0
100
111
213 42 ▶ $_ = 'c' if $_ eq 'ч' and $lang eq 'mk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{447}" and $lang eq "mk" 0 42 42
Condition33%1/3
$_ eq "\x{447}" and $lang eq "mk"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{447}" and $lang eq "mk"
$_ eq "\x{447}" $lang eq "mk"
Truth table33%1/3
A and B
A= $_ eq "\x{447}"B= $lang eq "mk"
ABresult
0X0
100
111
214 42 ▶ $_ = 'S' if $_ eq 'Ш' and $lang eq 'mk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{428}" and $lang eq "mk" 0 42 42
Condition33%1/3
$_ eq "\x{428}" and $lang eq "mk"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{428}" and $lang eq "mk"
$_ eq "\x{428}" $lang eq "mk"
Truth table33%1/3
A and B
A= $_ eq "\x{428}"B= $lang eq "mk"
ABresult
0X0
100
111
215 42 ▶ $_ = 's' if $_ eq 'ш' and $lang eq 'mk';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{448}" and $lang eq "mk" 0 42 42
Condition66%2/3
$_ eq "\x{448}" and $lang eq "mk"
!ll&&!rl&&r
4020
MC/DC0%0/2
$_ eq "\x{448}" and $lang eq "mk"
$_ eq "\x{448}" $lang eq "mk"
Truth table66%2/3
A and B
A= $_ eq "\x{448}"B= $lang eq "mk"
ABresult
0X0
100
111
216 42 ▶ $_ = 'SHT' if $_ eq 'Щ' and $lang eq 'bg';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{429}" and $lang eq "bg" 0 42 42
Condition33%1/3
$_ eq "\x{429}" and $lang eq "bg"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{429}" and $lang eq "bg"
$_ eq "\x{429}" $lang eq "bg"
Truth table33%1/3
A and B
A= $_ eq "\x{429}"B= $lang eq "bg"
ABresult
0X0
100
111
217 42 ▶ $_ = 'sht' if $_ eq 'щ' and $lang eq 'bg';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "\x{449}" and $lang eq "bg" 0 42 42
Condition33%1/3
$_ eq "\x{449}" and $lang eq "bg"
!ll&&!rl&&r
4200
MC/DC0%0/2
$_ eq "\x{449}" and $lang eq "bg"
$_ eq "\x{449}" $lang eq "bg"
Truth table33%1/3
A and B
A= $_ eq "\x{449}"B= $lang eq "bg"
ABresult
0X0
100
111
218  
219 42 ▶ $_ = $cyr2icao{$_} if defined $cyr2icao{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Lingua::Cyrillic::Translit::ICAO::cyr2icao{$_} 29 13 42
220 42 $res .= $_;
221 }
222 6 return $res;
223 }
224  
225 4 1;
226  
227 =head1 AUTHORS
228  
229 Serguei Trouchelle E<lt>F<stro@railways.dp.ua>E<gt>
230  
231 =head1 COPYRIGHT
232  
233 Copyright (c) 2007 Serguei Trouchelle. All rights reserved.
234  
235 This program is free software; you can redistribute it and/or modify it
236 under the same terms as Perl itself.
237  
238 =head1 SEE ALSO
239  
240 Lingua::RU::Translit - Transliteration of Russian text to Latin symbols.
241  
242 Lingua::UK::Translit - Transliteration of Ukrainian text to Latin symbols.
243  
244 =cut
↑ Summary