This file is indexed.

/usr/share/perl5/NetSDS/Util/Translit.pm is in libnetsds-util-perl 1.044-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#===============================================================================
#
#         FILE:  Translit.pm
#
#  DESCRIPTION:  Cyrillic transliteration routines
#
#         NOTE:  This module ported from Wono framework "as is"
#       AUTHOR:  Michael Bochkaryov (Rattler), <misha@rattler.kiev.ua>
#      COMPANY:  Net.Style
#      VERSION:  1.044
#      CREATED:  03.08.2008 15:04:22 EEST
#===============================================================================

=head1 NAME

NetSDS::Util::Translit - transliteration routines

=head1 SYNOPSIS

	use NetSDS::Const;
	use NetSDS::Util::Translit;

	# Transliterate cyrillic string
	$trans_string = trans_cyr_lat($cyr_string);

	# Reverse transliteration to russian language
	$rus_string = trans_lat_cyr("Vsem privet", LANG_RU);

=head1 DESCRIPTION

C<NetSDS::Util::Translit> module contains routines for bidirectional
cyrillic text transliteration. Now it supports russian and ukrainian
languages processing.

=cut

package NetSDS::Util::Translit;

use 5.8.0;
use warnings 'all';
use strict;

use base 'Exporter';

use version; our $VERSION = '1.044';

use NetSDS::Util::String;

our @EXPORT = qw(
  trans_cyr_lat
  trans_lat_cyr
);

use constant LANG_BE => 'be';
use constant LANG_EN => 'en';
use constant LANG_RU => 'ru';
use constant LANG_UK => 'uk';

use constant DEFAULT_LANG     => LANG_RU;

my %PREP = (
	LANG_RU() => {
		'а'   => 'a',
		'б'   => 'b',
		'в'   => 'v',
		'г'   => 'g',
		'д'   => 'd',
		'е'   => 'e',
		'ё'   => 'yo',
		'ж'   => 'zh',
		'з'   => 'z',
		'и'   => 'i',
		'й'   => 'j',
		'к'   => 'k',
		'л'   => 'l',
		'м'   => 'm',
		'н'   => 'n',
		'о'   => 'o',
		'п'   => 'p',
		'р'   => 'r',
		'с'   => 's',
		'т'   => 't',
		'у'   => 'u',
		'ф'   => 'f',
		'х'   => 'kh',
		'ц'   => 'tc',
		'ч'   => 'ch',
		'ш'   => 'sh',
		'щ'   => 'sch',
		'ъ'   => '"',
		'ы'   => 'y',
		'ые' => 'yje',
		'ыё' => 'yjo',
		'ыу' => 'yiu',
		'ыю' => 'yju',
		'ыя' => 'yja',
		'ь'   => "'",
		'ье' => 'jie',
		'ьё' => 'jio',
		'ью' => 'jiu',
		'ья' => 'jia',
		'э'   => 'ye',
		'ю'   => 'yu',
		'я'   => 'ya',
	},

	LANG_UK() => {
		"'"  => '"',
		'а' => 'a',
		'б' => 'b',
		'в' => 'v',
		'ґ' => 'g',
		'г' => 'h',
		'д' => 'd',
		'е' => 'e',
		'є' => 'ye',
		'ж' => 'zh',
		'з' => 'z',
		'і' => 'i',
		'и' => 'y',
		'ї' => 'yi',
		'й' => 'j',
		'к' => 'k',
		'л' => 'l',
		'м' => 'm',
		'н' => 'n',
		'о' => 'o',
		'п' => 'p',
		'р' => 'r',
		'с' => 's',
		'т' => 't',
		'у' => 'u',
		'ф' => 'f',
		'х' => 'kh',
		'ц' => 'tc',
		'ч' => 'ch',
		'ш' => 'sh',
		'щ' => 'sch',
		'ь' => "'",
		'ю' => 'yu',
		'я' => 'ya',
	},

	LANG_BE() => {
		"'"    => '"',
		'а'   => 'a',
		'б'   => 'b',
		'в'   => 'v',
		'ґ'   => 'g',
		'г'   => 'h',
		'д'   => 'd',
		'е'   => 'ye',
		'ё'   => 'yo',
		'ж'   => 'zh',
		'з'   => 'z',
		'і'   => 'i',
		'и'   => 'i',
		'ї'   => 'yi',
		'й'   => 'j',
		'к'   => 'k',
		'л'   => 'l',
		'м'   => 'm',
		'н'   => 'n',
		'о'   => 'o',
		'п'   => 'p',
		'р'   => 'r',
		'с'   => 's',
		'т'   => 't',
		'у'   => 'u',
		'ў'   => 'w',
		'ф'   => 'f',
		'х'   => 'kh',
		'ц'   => 'tc',
		'ч'   => 'ch',
		'ш'   => 'sh',
		'щ'   => 'sch',
		'ы'   => 'y',
		'ые' => 'yje',
		'ыё' => 'yjo',
		'ыу' => 'yiu',
		'ыю' => 'yju',
		'ыя' => 'yja',
		'ь'   => "'",
		'ье' => 'jie',
		'ьё' => 'jio',
		'ью' => 'jiu',
		'ья' => 'jia',
		'э'   => 'e',
		'ю'   => 'yu',
		'я'   => 'ya',
	},
);

my %TO_LAT = ();

my %TO_CYR = ();

#*********************************************************************************************
sub _prep_translit {
	my ($lang) = @_;

	return if ( $PREP{prepared}->{$lang} );

	my $rfw = {};
	my $rbw = {};
	while ( my ( $fw, $bw ) = each %{ $PREP{$lang} } ) {
		$fw = str_encode($fw);
		$bw = str_encode($bw);
		my $lf = length($fw);
		my $lb = length($bw);
		if ( ( $lf == 1 ) and ( $lb == 1 ) ) {
			$rfw->{0}->{ uc($fw) }      = uc($bw);
			$rfw->{0}->{ ucfirst($fw) } = ucfirst($bw);
			$rfw->{0}->{$fw}            = $bw;

			$rbw->{0}->{ uc($bw) }      = uc($fw);
			$rbw->{0}->{ ucfirst($bw) } = ucfirst($fw);
			$rbw->{0}->{$bw}            = $fw;
		} else {
			$rfw->{$lf}->{ uc($fw) }      = uc($bw);
			$rfw->{$lf}->{ ucfirst($fw) } = ucfirst($bw);
			$rfw->{$lf}->{$fw}            = $bw;

			$rbw->{$lb}->{ uc($bw) }      = uc($fw);
			$rbw->{$lb}->{ ucfirst($bw) } = ucfirst($fw);
			$rbw->{$lb}->{$bw}            = $fw;
		}
	} ## end while ( my ( $fw, $bw ) =...

	$TO_LAT{$lang} = [];
	foreach my $ord ( reverse sort { $a <=> $b } keys %{$rfw} ) {
		my $tra = $rfw->{$ord};
		my $fnd = join( '|', keys %{$tra} );
		push( @{ $TO_LAT{$lang} }, [ $fnd, $tra ] );
	}

	$TO_CYR{$lang} = [];
	foreach my $ord ( reverse sort { $a <=> $b } keys %{$rbw} ) {
		my $tra = $rbw->{$ord};
		my $fnd = join( '|', keys %{$tra} );
		push( @{ $TO_CYR{$lang} }, [ $fnd, $tra ] );
	}

	$PREP{prepared}->{$lang} = 1;
} ## end sub _prep_translit

#*********************************************************************************************

=head1 EXPORTS

=over

=item B<trans_cyr_lat($text[, $lang])> - transliterate string

Convert text from cyrillic to latin encoding.

Language may be set if not default one.

	$lat = trans_cyr_lat($string);

=cut

#-----------------------------------------------------------------------
sub trans_cyr_lat {
	my ( $text, $lang ) = @_;

	$lang ||= DEFAULT_LANG();

	_prep_translit($lang);

	$text = str_encode($text);

	foreach my $row ( @{ $TO_LAT{$lang} } ) {
		my ( $fnd, $has ) = @{$row};
		$text =~ s/($row->[0])/$row->[1]->{$1}/ge;
	}
	$text =~ s/[^\x{0}-\x{7f}]+/\?/g;

	return str_decode($text);
}

#*********************************************************************************************

=item B<trans_lat_cyr($text[, $lang])> - reverse transliteration

This function transliterate string from latin encoding to cyrillic one.

Target language may be set if not default one.

	$cyr = trans_lat_cyr("Sam baran", "ru");

=cut

#-----------------------------------------------------------------------
sub trans_lat_cyr {
	my ( $text, $lang ) = @_;

	$lang ||= DEFAULT_LANG();

	_prep_translit($lang);

	$text = str_encode($text);

	$text =~ s/[^\x{0}-\x{7f}]+/\?/g;
	foreach my $row ( @{ $TO_CYR{$lang} } ) {
		my ( $fnd, $has ) = @{$row};
		$text =~ s/($row->[0])/$row->[1]->{$1}/sg;
	}

	return str_decode($text);
}

1;
__END__

=back

=head1 EXAMPLES

None yet

=head1 BUGS

Unknown yet

=head1 TODO

Implement examples and tests.

=head1 SEE ALSO

L<Encode>, L<perlunicode>

=head1 AUTHORS

Valentyn Solomko <pere@pere.org.ua>

=cut