line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Convert::Braille; |
2
|
1
|
|
|
1
|
|
27846
|
use utf8; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
BEGIN |
5
|
|
|
|
|
|
|
{ |
6
|
1
|
|
|
1
|
|
25
|
require 5.006; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
49
|
use base qw(Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
165
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
54
|
|
11
|
1
|
|
|
1
|
|
5
|
use vars qw( @EXPORT @EXPORT_OK $VERSION %BrailleAsciiToUnicode %BrailleUnicodeToAscii $dot_separator ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
346
|
|
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
4
|
$VERSION = '0.05'; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
3
|
@EXPORT = qw( |
16
|
|
|
|
|
|
|
brailleDotsToUnicode |
17
|
|
|
|
|
|
|
brailleUnicodeToDots |
18
|
|
|
|
|
|
|
brailleUnicodeToAscii |
19
|
|
|
|
|
|
|
brailleAsciiToUnicode |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
brailleAsciiToDots |
22
|
|
|
|
|
|
|
brailleDotsToAscii |
23
|
|
|
|
|
|
|
); |
24
|
1
|
|
|
|
|
3
|
@EXPORT_OK = qw( |
25
|
|
|
|
|
|
|
brailleDotsToUnicode |
26
|
|
|
|
|
|
|
brailleUnicodeToDots |
27
|
|
|
|
|
|
|
brailleUnicodeToAscii |
28
|
|
|
|
|
|
|
brailleAsciiToUnicode |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
brailleAsciiToDots |
31
|
|
|
|
|
|
|
brailleDotsToAscii |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
%BrailleAsciiToUnicode |
34
|
|
|
|
|
|
|
%UnicodeToBrailleAscii |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
68
|
%BrailleAsciiToUnicode =( |
38
|
|
|
|
|
|
|
A => '⠁', |
39
|
|
|
|
|
|
|
B => '⠃', |
40
|
|
|
|
|
|
|
C => '⠉', |
41
|
|
|
|
|
|
|
D => '⠙', |
42
|
|
|
|
|
|
|
E => '⠑', |
43
|
|
|
|
|
|
|
F => '⠋', |
44
|
|
|
|
|
|
|
G => '⠛', |
45
|
|
|
|
|
|
|
H => '⠓', |
46
|
|
|
|
|
|
|
I => '⠊', |
47
|
|
|
|
|
|
|
J => '⠚', |
48
|
|
|
|
|
|
|
K => '⠅', |
49
|
|
|
|
|
|
|
L => '⠇', |
50
|
|
|
|
|
|
|
M => '⠍', |
51
|
|
|
|
|
|
|
N => '⠝', |
52
|
|
|
|
|
|
|
O => '⠕', |
53
|
|
|
|
|
|
|
P => '⠏', |
54
|
|
|
|
|
|
|
Q => '⠟', |
55
|
|
|
|
|
|
|
R => '⠗', |
56
|
|
|
|
|
|
|
S => '⠎', |
57
|
|
|
|
|
|
|
T => '⠞', |
58
|
|
|
|
|
|
|
U => '⠥', |
59
|
|
|
|
|
|
|
V => '⠧', |
60
|
|
|
|
|
|
|
W => '⠺', |
61
|
|
|
|
|
|
|
X => '⠭', |
62
|
|
|
|
|
|
|
Y => '⠽', |
63
|
|
|
|
|
|
|
Z => '⠵', |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1 => '⠂', |
66
|
|
|
|
|
|
|
2 => '⠆', |
67
|
|
|
|
|
|
|
3 => '⠒', |
68
|
|
|
|
|
|
|
4 => '⠲', |
69
|
|
|
|
|
|
|
5 => '⠢', |
70
|
|
|
|
|
|
|
6 => '⠖', |
71
|
|
|
|
|
|
|
7 => '⠶', |
72
|
|
|
|
|
|
|
8 => '⠦', |
73
|
|
|
|
|
|
|
9 => '⠔', |
74
|
|
|
|
|
|
|
0 => '⠴', |
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
|
1
|
|
|
|
|
9
|
foreach ( keys %BrailleAsciiToUnicode ) { |
107
|
63
|
|
|
|
|
138
|
$BrailleUnicodeToAscii{$BrailleAsciiToUnicode{$_}} = $_; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
345
|
$dot_separator = ""; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _convert |
115
|
|
|
|
|
|
|
{ |
116
|
20
|
50
|
|
20
|
|
53
|
return unless ( defined($_[0]) ); |
117
|
|
|
|
|
|
|
|
118
|
20
|
|
|
|
|
37
|
my ( $token, $hash ) = @_; |
119
|
|
|
|
|
|
|
|
120
|
20
|
50
|
|
|
|
656
|
( exists($hash->{$token}) ) ? $hash->{$token} : $token ; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub brailleAsciiToUnicode |
125
|
|
|
|
|
|
|
{ |
126
|
|
|
|
|
|
|
|
127
|
2
|
50
|
|
2
|
1
|
731
|
return unless ( defined($_[0]) ); |
128
|
|
|
|
|
|
|
|
129
|
2
|
|
|
|
|
4
|
my $ascii = $_[0]; |
130
|
2
|
|
|
|
|
12
|
$ascii =~ s/(.)/_convert ( $1, \%BrailleAsciiToUnicode )/ge; |
|
10
|
|
|
|
|
28
|
|
131
|
2
|
|
|
|
|
19
|
$ascii; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub brailleUnicodeToAscii |
136
|
|
|
|
|
|
|
{ |
137
|
|
|
|
|
|
|
|
138
|
2
|
50
|
|
2
|
1
|
365
|
return unless ( defined($_[0]) ); |
139
|
|
|
|
|
|
|
|
140
|
2
|
|
|
|
|
4
|
my $unicode = $_[0]; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# |
143
|
|
|
|
|
|
|
# first strip off dots 7 and 8: |
144
|
|
|
|
|
|
|
# |
145
|
2
|
50
|
|
|
|
54
|
if ( $unicode =~ /⡀-⣿/ ) { |
146
|
1
|
|
|
1
|
|
5
|
$unicode =~ tr/⢀-⣿/⠀-⡿/; # fold upper half |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
14
|
|
|
0
|
|
|
|
|
0
|
|
147
|
0
|
|
|
|
|
0
|
$unicode =~ tr/⡀-⡿/⠀-⠿/; # fold upper quarter |
148
|
|
|
|
|
|
|
} |
149
|
2
|
|
|
|
|
12
|
$unicode =~ s/(.)/_convert ( $1, \%BrailleUnicodeToAscii )/ge; |
|
10
|
|
|
|
|
20
|
|
150
|
2
|
|
|
|
|
18
|
$unicode; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub brailleUnicodeToDots |
155
|
|
|
|
|
|
|
{ |
156
|
|
|
|
|
|
|
|
157
|
2
|
|
|
2
|
1
|
275
|
my $string = shift; # no || "" because fail for '0' |
158
|
2
|
50
|
33
|
|
|
18
|
return "" if !defined $string || $string eq ""; |
159
|
|
|
|
|
|
|
|
160
|
2
|
|
|
|
|
12
|
my @chars = split ( //, $string ); |
161
|
|
|
|
|
|
|
|
162
|
2
|
|
|
|
|
5
|
my ($trans, $dots); |
163
|
|
|
|
|
|
|
|
164
|
2
|
|
|
|
|
5
|
foreach ( @chars ) { |
165
|
10
|
50
|
|
|
|
48
|
if ( /[⠀-⣿]/ ) { # assume UTF8 |
166
|
10
|
|
|
|
|
22
|
my $char = ord ( $_ ) - 0x2800; |
167
|
10
|
100
|
|
|
|
22
|
$trans .= $dot_separator if ( $dots ); |
168
|
10
|
|
|
|
|
14
|
$dots = undef; |
169
|
10
|
50
|
|
|
|
24
|
$dots = "1" if ( $char & 0x1 ); |
170
|
10
|
100
|
|
|
|
21
|
$dots .= "2" if ( $char & 0x2 ); |
171
|
10
|
100
|
|
|
|
42
|
$dots .= "3" if ( $char & 0x4 ); |
172
|
10
|
50
|
|
|
|
887
|
$dots .= "4" if ( $char & 0x8 ); |
173
|
10
|
100
|
|
|
|
28
|
$dots .= "5" if ( $char & 0x10 ); |
174
|
10
|
50
|
|
|
|
18
|
$dots .= "6" if ( $char & 0x20 ); |
175
|
10
|
50
|
|
|
|
21
|
$dots .= "7" if ( $char & 0x40 ); |
176
|
10
|
50
|
|
|
|
18
|
$dots .= "8" if ( $char & 0x80 ); |
177
|
10
|
|
|
|
|
23
|
$trans .= $dots; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
else { |
180
|
0
|
|
|
|
|
0
|
$trans .= $_; |
181
|
0
|
|
|
|
|
0
|
$dots = undef; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
2
|
|
|
|
|
27
|
$trans; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub brailleDotsToUnicode |
190
|
|
|
|
|
|
|
{ |
191
|
|
|
|
|
|
|
|
192
|
2
|
|
|
2
|
1
|
289
|
my $string = shift; |
193
|
2
|
50
|
33
|
|
|
47
|
return "" if !defined $string || $string eq ""; |
194
|
|
|
|
|
|
|
|
195
|
2
|
|
|
|
|
15
|
my @bits = split ( //, $string ); |
196
|
|
|
|
|
|
|
|
197
|
2
|
|
|
|
|
8
|
my ($char, $lastBit, $trans) = (0,0,""); |
198
|
|
|
|
|
|
|
|
199
|
2
|
|
|
|
|
4
|
foreach ( @bits ) { |
200
|
28
|
|
|
|
|
41
|
my $bit = $_; |
201
|
28
|
50
|
|
|
|
79
|
if ( $bit =~ /[1-8]/ ) { |
202
|
28
|
100
|
|
|
|
56
|
if ( $bit > $lastBit ) { |
203
|
|
|
|
|
|
|
# bit continues sequence |
204
|
20
|
|
|
|
|
89
|
$char += 2**($bit-1); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
else { |
207
|
|
|
|
|
|
|
# bit starts new sequence |
208
|
8
|
50
|
|
|
|
27
|
$trans .= chr ( 0x2800+$char ) if ( $char ); # first time problem |
209
|
8
|
|
|
|
|
11
|
$lastBit = $char = 0; |
210
|
8
|
|
|
|
|
12
|
$char = 2**($bit-1); |
211
|
|
|
|
|
|
|
} |
212
|
28
|
|
|
|
|
46
|
$lastBit = $bit; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
else { # end of sequence |
215
|
0
|
0
|
|
|
|
0
|
$trans .= chr ( 0x2800+$char ) if ( $char ); # first time problem |
216
|
0
|
|
|
|
|
0
|
$trans .= $bit; |
217
|
0
|
|
|
|
|
0
|
$lastBit = $char = 0; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
} |
220
|
2
|
50
|
|
|
|
11
|
$trans .= chr ( 0x2800+$char ) if ( $char ); # last time problem |
221
|
|
|
|
|
|
|
|
222
|
2
|
|
|
|
|
17
|
$trans; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub brailleAsciiToDots |
227
|
|
|
|
|
|
|
{ |
228
|
1
|
|
|
1
|
1
|
326
|
brailleUnicodeToDots ( brailleAsciiToUnicode ( @_ ) ); |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
sub brailleDotsToAscii |
233
|
|
|
|
|
|
|
{ |
234
|
1
|
|
|
1
|
1
|
344
|
brailleUnicodeToAscii ( brailleDotsToUnicode ( @_ ) ); |
235
|
|
|
|
|
|
|
} |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
######################################################### |
239
|
|
|
|
|
|
|
# Do not change this, Do not put anything below this. |
240
|
|
|
|
|
|
|
# File must return "true" value at termination |
241
|
|
|
|
|
|
|
1; |
242
|
|
|
|
|
|
|
########################################################## |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
__END__ |