line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::TR::ASCII; |
2
|
1
|
|
|
1
|
|
13633
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
3
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
4
|
1
|
|
|
1
|
|
4
|
use utf8; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
21
|
use base qw( Exporter ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
85
|
|
6
|
1
|
|
|
1
|
|
1070
|
use Lingua::TR::ASCII::Data; |
|
1
|
|
|
|
|
150
|
|
|
1
|
|
|
|
|
244
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.14'; |
9
|
|
|
|
|
|
|
our @EXPORT = qw( ascii_to_turkish turkish_to_ascii ); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub ascii_to_turkish { |
12
|
12
|
|
|
12
|
1
|
16670
|
my($str) = @_; |
13
|
12
|
100
|
|
|
|
44
|
return $str if ! $str; |
14
|
9
|
|
|
|
|
44
|
return __PACKAGE__->_new( $str )->_deasciify; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub turkish_to_ascii { |
18
|
9
|
|
|
9
|
1
|
78
|
my($str, $encoding) = @_; |
19
|
9
|
|
|
|
|
703
|
require Text::Unidecode; |
20
|
1
|
|
|
1
|
|
8
|
use utf8; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
21
|
9
|
|
|
|
|
1461
|
return Text::Unidecode::unidecode( $str ); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _new { |
25
|
9
|
|
|
9
|
|
13
|
my($class, $input) = @_; |
26
|
9
|
|
|
|
|
39
|
my $self = { |
27
|
|
|
|
|
|
|
input => $input, |
28
|
|
|
|
|
|
|
length => length $input, |
29
|
|
|
|
|
|
|
turkish => $input, |
30
|
|
|
|
|
|
|
}; |
31
|
9
|
|
|
|
|
14
|
bless $self, $class; |
32
|
9
|
|
|
|
|
30
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Convert a string with ASCII-only letters into one with Turkish letters. |
36
|
|
|
|
|
|
|
sub _deasciify { |
37
|
9
|
|
|
9
|
|
8
|
my($self) = @_; |
38
|
9
|
|
|
|
|
19
|
my $s = \$self->{turkish}; |
39
|
9
|
|
|
|
|
10
|
my @chars = split m{}xms, ${$s}; |
|
9
|
|
|
|
|
147
|
|
40
|
|
|
|
|
|
|
|
41
|
9
|
|
|
|
|
26
|
for my $i ( 0 .. $#chars ) { |
42
|
1598
|
|
|
|
|
1433
|
my $c = $chars[$i]; |
43
|
1598
|
100
|
|
|
|
1671
|
next if ! $self->_needs_correction( $c, $i ); |
44
|
163
|
|
33
|
|
|
132
|
substr ${$s}, $i, 1, $TOGGLE_ACCENT->{ $c } || $c; |
|
163
|
|
|
|
|
577
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
9
|
|
|
|
|
9
|
return ${$s}; |
|
9
|
|
|
|
|
195
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Determine if char at cursor needs correction. |
51
|
|
|
|
|
|
|
sub _needs_correction { |
52
|
1598
|
|
|
1598
|
|
1231
|
my($self, $ch, $point) = @_; |
53
|
1598
|
|
66
|
|
|
3385
|
my $tr = $ASCIIFY->{ $ch } || $ch; |
54
|
1598
|
|
|
|
|
1372
|
my $pl = $PATTERN->{ lc $tr }; |
55
|
1598
|
100
|
100
|
|
|
1913
|
my $m = $pl ? $self->_matches( $pl, $point || 0 ) : 0; |
56
|
|
|
|
|
|
|
|
57
|
1598
|
50
|
|
|
|
3834
|
return $tr eq 'I' ? ( $ch eq $tr ? ! $m : $m ) |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
58
|
|
|
|
|
|
|
: ( $ch eq $tr ? $m : ! $m ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Check if the pattern is in the pattern table. |
62
|
|
|
|
|
|
|
sub _matches { |
63
|
422
|
|
|
422
|
|
304
|
my($self, $dlist, $point) = @_; |
64
|
422
|
|
100
|
|
|
661
|
my $str = $self->_get_context( $point || 0 ); |
65
|
422
|
|
|
|
|
349
|
my $rank = 2 * keys %{ $dlist }; |
|
422
|
|
|
|
|
492
|
|
66
|
422
|
|
|
|
|
379
|
my $len = length $str; |
67
|
422
|
|
|
|
|
253
|
my($start, $end); |
68
|
|
|
|
|
|
|
|
69
|
422
|
|
|
|
|
593
|
while ( $start++ <= CONTEXT_SIZE ) { |
70
|
4642
|
|
|
|
|
2758
|
$end = CONTEXT_SIZE; |
71
|
4642
|
|
|
|
|
4863
|
while ( ++$end <= $len ) { |
72
|
25399
|
|
|
|
|
19014
|
my $s = substr $str, $start, $end - $start; |
73
|
25399
|
|
100
|
|
|
49997
|
my $r = $dlist->{ $s } || next; |
74
|
815
|
100
|
|
|
|
1470
|
$rank = $r if abs $r < abs $rank; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
422
|
|
|
|
|
633
|
return $rank > 0; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _get_context { |
82
|
422
|
|
|
422
|
|
343
|
my($self, $point, $size) = @_; |
83
|
422
|
|
50
|
|
|
833
|
$size ||= CONTEXT_SIZE; |
84
|
422
|
|
|
|
|
316
|
my($s, $i, $space, $index); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $morph = sub { |
87
|
844
|
|
|
844
|
|
640
|
my($next, $lookup) = @_; |
88
|
844
|
|
|
|
|
551
|
$index = $point; |
89
|
844
|
|
|
|
|
493
|
$space = 0; |
90
|
844
|
|
|
|
|
800
|
while ( $next->() ) { |
91
|
6035
|
|
|
|
|
7128
|
my $char = substr $self->{turkish}, $index, 1; |
92
|
6035
|
|
|
|
|
4788
|
my $x = $lookup->{ $char }; |
93
|
6035
|
100
|
|
|
|
6551
|
if ( $x ) { |
94
|
4926
|
|
|
|
|
4107
|
substr $s, abs $i, 1, $x; |
95
|
4926
|
|
|
|
|
2790
|
$space = 0; |
96
|
4926
|
|
|
|
|
2782
|
$i++; |
97
|
4926
|
|
|
|
|
4578
|
next; |
98
|
|
|
|
|
|
|
} |
99
|
1109
|
100
|
|
|
|
1245
|
next if $space; |
100
|
974
|
|
|
|
|
565
|
$space = 1; |
101
|
974
|
|
|
|
|
874
|
$i++; |
102
|
|
|
|
|
|
|
} |
103
|
422
|
|
|
|
|
1090
|
}; |
104
|
|
|
|
|
|
|
|
105
|
422
|
|
|
|
|
572
|
$s = q{ } x ( 1 + ( 2 * $size ) ); |
106
|
422
|
|
|
|
|
279
|
$i = 1 + $size; |
107
|
422
|
|
|
|
|
430
|
substr $s, $size, 1, 'X'; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$morph->( |
110
|
2309
|
100
|
100
|
2309
|
|
9548
|
sub { $i < length $s && ! $space && ++$index < $self->{length} }, |
111
|
422
|
|
|
|
|
858
|
$DOWNCASE_ASCIIFY |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
422
|
|
|
|
|
771
|
$s = substr $s, 0, $i; |
115
|
422
|
|
|
|
|
352
|
$i = 0 - --$size; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
$morph->( |
118
|
4570
|
100
|
|
4570
|
|
12588
|
sub { $i <= 0 && --$index >= 0 }, |
119
|
422
|
|
|
|
|
842
|
$UPCASE_ACCENTS |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
|
122
|
422
|
|
|
|
|
1432
|
return $s; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
__END__ |