| 1 | package Convert::Braille; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | BEGIN | ||||||||||||||||||||||||||||
| 5 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 6 | 1 | require 5.006; | |||||||||||||||||||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use vars qw( @EXPORT @EXPORT_OK $VERSION %BrailleAscii_To_Unicode %BrailleUnicode_To_Ascii $dot_separator ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | @EXPORT = qw( | |||||||||||||||||||||||||||
| 16 | brailleDotNumbers_To_Unicode | ||||||||||||||||||||||||||||
| 17 | brailleUnicode_To_DotNumbers | ||||||||||||||||||||||||||||
| 18 | brailleUnicode_To_Ascii | ||||||||||||||||||||||||||||
| 19 | brailleAscii_To_Unicode | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | brailleAscii_To_DotNumbers | ||||||||||||||||||||||||||||
| 22 | brailleDotNumbers_To_Ascii | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | 1 | @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 25 | brailleDotNumbers_To_Unicode | ||||||||||||||||||||||||||||
| 26 | brailleUnicode_To_DotNumbers | ||||||||||||||||||||||||||||
| 27 | brailleUnicode_To_Ascii | ||||||||||||||||||||||||||||
| 28 | brailleAscii_To_Unicode | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | brailleAscii_To_DotNumbers | ||||||||||||||||||||||||||||
| 31 | brailleDotNumbers_To_Ascii | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | %BrailleAscii_To_Unicode | ||||||||||||||||||||||||||||
| 34 | %Unicode_To_BrailleAscii | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | %BrailleAscii_To_Unicode =( | |||||||||||||||||||||||||||
| 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 | foreach ( keys %BrailleAscii_To_Unicode ) { | |||||||||||||||||||||||||||
| 107 | 63 | $BrailleUnicode_To_Ascii{$BrailleAscii_To_Unicode{$_}} = $_; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 1 | $dot_separator = ""; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | sub _convert | ||||||||||||||||||||||||||||
| 115 | 25 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_convert: called CC=3 SCAR=11.7
| |||||||||||||||||||||||||||||
| 116 | 25 | ▶ | return unless ( defined($_[0]) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 25 | my ( $token, $hash ) = @_; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 25 | ▶ | ( exists($hash->{$token}) ) ? $hash->{$token} : $token ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub brailleAscii_To_Unicode | ||||||||||||||||||||||||||||
| 125 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
brailleAscii_To_Unicode: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 3 | ▶ | return unless ( defined($_[0]) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 3 | my $ascii = uc($_[0]); | |||||||||||||||||||||||||||
| 130 | 3 | $ascii =~ s/(.)/_convert ( $1, \%BrailleAscii_To_Unicode )/ge; | |||||||||||||||||||||||||||
| 131 | 3 | $ascii; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | sub brailleUnicode_To_Ascii | ||||||||||||||||||||||||||||
| 136 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
brailleUnicode_To_Ascii: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 2 | ▶ | return unless ( defined($_[0]) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 2 | my $unicode = $_[0]; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | # | ||||||||||||||||||||||||||||
| 143 | # first strip off dots 7 and 8: | ||||||||||||||||||||||||||||
| 144 | # | ||||||||||||||||||||||||||||
| 145 | 2 | ▶ | if ( $unicode =~ /⡀-⣿/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 0 | $unicode =~ tr/⢀-⣿/⠀-⡿/; # fold upper half | |||||||||||||||||||||||||||
| 147 | 0 | $unicode =~ tr/⡀-⡿/⠀-⠿/; # fold upper quarter | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 2 | $unicode =~ s/(.)/_convert ( $1, \%BrailleUnicode_To_Ascii )/ge; | |||||||||||||||||||||||||||
| 150 | 2 | $unicode; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | sub brailleUnicode_To_DotNumbers | ||||||||||||||||||||||||||||
| 155 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
brailleUnicode_To_DotNumbers: called CC=16 SCAR=30.1
Pod
documented
| |||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 2 | my $string = shift; # no || "" because fail for '0' | |||||||||||||||||||||||||||
| 158 | 2 | ▶ | return "" if !defined $string || $string eq ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $string or $string eq ""
MC/DC0%0/2
not defined $string or $string eq ""
not defined $string
$string eq ""
Truth table33%1/3
not(A) or B
A= not defined $stringB= $string eq ""
| |||||||||||||||||||||||||||||
| 159 | 2 | ▶ | my $braced = ( @_ ) ? shift : 0 ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 2 | my @chars = split ( //, $string ); | |||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 2 | my ($trans, $dots); | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 2 | foreach ( @chars ) { | |||||||||||||||||||||||||||
| 166 | 10 | ▶ | if ( /[⠀-⣿]/ ) { # assume UTF8 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | 10 | my $char = ord ( $_ ) - 0x2800; | |||||||||||||||||||||||||||
| 168 | 10 | ▶ | $trans .= $dot_separator if ( $dots ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 10 | $dots = undef; | |||||||||||||||||||||||||||
| 170 | 10 | ▶ | $dots = "1" if ( $char & 0x1 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 10 | ▶ | $dots .= "2" if ( $char & 0x2 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 10 | ▶ | $dots .= "3" if ( $char & 0x4 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 10 | ▶ | $dots .= "4" if ( $char & 0x8 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 10 | ▶ | $dots .= "5" if ( $char & 0x10 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 10 | ▶ | $dots .= "6" if ( $char & 0x20 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 10 | ▶ | $dots .= "7" if ( $char & 0x40 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 10 | ▶ | $dots .= "8" if ( $char & 0x80 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 10 | ▶ | $trans .= ($braced) ? "[$dots]" : $dots; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | else { | ||||||||||||||||||||||||||||
| 181 | 0 | $trans .= "$_"; | |||||||||||||||||||||||||||
| 182 | 0 | $dots = undef; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 2 | $trans; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | sub brailleDotNumbers_To_Unicode | ||||||||||||||||||||||||||||
| 191 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
brailleDotNumbers_To_Unicode: called CC=10 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 2 | my $string = shift; | |||||||||||||||||||||||||||
| 194 | 2 | ▶ | return "" if !defined $string || $string eq ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $string or $string eq ""
MC/DC0%0/2
not defined $string or $string eq ""
not defined $string
$string eq ""
Truth table33%1/3
not(A) or B
A= not defined $stringB= $string eq ""
| |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 2 | ▶ | $string =~ s/$dot_separator//g if( $dot_separator ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 2 | my @bits = split ( //, $string ); | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 2 | my ($char, $lastBit, $trans) = (0,0,""); | |||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | 2 | foreach ( @bits ) { | |||||||||||||||||||||||||||
| 204 | 28 | my $bit = $_; | |||||||||||||||||||||||||||
| 205 | 28 | ▶ | if ( $bit =~ /[1-8]/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 206 | 28 | ▶ | if ( $bit > $lastBit ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | # bit continues sequence | ||||||||||||||||||||||||||||
| 208 | 20 | $char += 2**($bit-1); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | else { | ||||||||||||||||||||||||||||
| 211 | # bit starts new sequence | ||||||||||||||||||||||||||||
| 212 | 8 | ▶ | $trans .= chr ( 0x2800+$char ) if ( $char ); # first time problem | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | 8 | $lastBit = $char = 0; | |||||||||||||||||||||||||||
| 214 | 8 | $char = 2**($bit-1); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | 28 | $lastBit = $bit; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | else { # end of sequence | ||||||||||||||||||||||||||||
| 219 | 0 | ▶ | $trans .= chr ( 0x2800+$char ) if ( $char ); # first time problem | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 0 | $trans .= $bit; | |||||||||||||||||||||||||||
| 221 | 0 | $lastBit = $char = 0; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | 2 | ▶ | $trans .= chr ( 0x2800+$char ) if ( $char ); # last time problem | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 2 | $trans; | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | sub brailleAscii_To_DotNumbers | ||||||||||||||||||||||||||||
| 231 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
brailleAscii_To_DotNumbers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 232 | 1 | brailleUnicode_To_DotNumbers ( brailleAscii_To_Unicode ( @_ ) ); | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | sub brailleDotNumbers_To_Ascii | ||||||||||||||||||||||||||||
| 237 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
brailleDotNumbers_To_Ascii: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 238 | 1 | brailleUnicode_To_Ascii ( brailleDotNumbers_To_Unicode ( @_ ) ); | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | ######################################################### | ||||||||||||||||||||||||||||
| 243 | # Do not change this, Do not put anything below this. | ||||||||||||||||||||||||||||
| 244 | # File must return "true" value at termination | ||||||||||||||||||||||||||||
| 245 | 1 | 1; | |||||||||||||||||||||||||||
| 246 | ########################################################## | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | __END__ | ||||||||||||||||||||||||||||