blib/lib/Encode/DosHebrew.pm untested

filter: Statementstmt 0.0% 0 / 45 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 68 CC 1 SCAR 6.9
CC
1
Cov
0%
hebChr
2.0
initDos2Uni
2.0
decode_char
2.0
CRAP 2.0
1 =head1 NAME
2
3 Encode::DosHebrew - DOS Hebrew Encoding
4
5 =head1 SYNOPSIS
6
7 use Encode;
8 use Encode::DosHebrew;
9 use File::BOM;
10
11 # Hebrew word for "newspaper"
12 my $dosTxt = "\x92\xA0\xFA\xED\x8F\xA7";
13
14 open $outF, ">:utf8:via(File::BOM)", 'unicode.txt'
15 or die "can't write: $!\n";
16 print $outF decode('DosHebrew', $dosTxt), "\n";
17 close $outF;
18
19 =head1 ABSTRACT
20
21 This module implements a DOS 8-bit encoding of Hebrew, which includes vowels (nikud),
22 as well as pointed (dagesh) consonants, in addition to the standard consonants. It
23 is a superset of Code page 862 (which includes only consonants).
24
25 Although data files exist that use this "DosHebrew" encoding, its origin is unclear,
26 and there are no known standards which describe it.
27
28 =head1 BUGS
29
30 Only the "decode" function is implemented at this time.
31
32 =head1 DESCRIPTION
33
34 To find how to use this module in detail, see Encode.
35
36 =head1 SEE ALSO
37
38 Encode
39
40 =head1 AUTHOR
41
42 Tzadik Vanderhoof, E<lt>tzadikv@cpan.orgE<gt>
43
44 =cut
45
46 package Encode::DosHebrew;
47 use strict;
48 use warnings;
49 use base 'Encode::Encoding';
50 use feature ":5.10";
51 use Carp;
52
53 our $VERSION = '0.5';
54
55 __PACKAGE__->Define('DosHebrew');
56
57 my %dos2uni;
58
59 sub hebChr {
60 my ($c) = @_;
61
62 return chr(0x0500 + $c);
63 }
64
65 sub initDos2Uni {
66 my $data = dos2UniData();
67 open my $dataF, '<', \$data or die "Can't open data";
68 while (<$dataF>) {
69 my @x = m|\b([0-9a-f]{2})\b|ig or next;
70 my $from = chr(hex(shift @x));
71 my $to = join '', map { hebChr hex $_ } @x;
72 $dos2uni{$from} = $to;
73 }
74 close $dataF;
75 }
76
77 sub decode_char {
78 my ($c) = @_;
79
80 my $toC;
81
82 given ($c) {
83 when (m|[\s\x21-\x3F]|) {
84 $toC = $c;
85 }
86 when (m|[\x80-\x9A]|) {
87 $toC = hebChr(ord($c) + 0x50);
88 }
89 default {
90 $toC = $dos2uni{$c};
91 }
92 }
93
94 return $toC;
95 }
96
97 sub decode($$;$) {
98 my ($obj, $s, $chk) = @_;
99
100 return join '', map { decode_char $_ } split //, $s;
101 }
102
103 sub encode {
104 croak "'encode' not yet implemented";
105 }
106
107 initDos2Uni;
108
109 sub dos2UniData {
110 return <<'END_DATA';
111
112 dotted consonants:
113 e1 d1 bc beis
114 e2 d2 bc gimel dagesh
115 e3 d3 bc dalet dagesh
116 e4 d4 bc heh dagesh
117 e5 d5 bc vav shuruk
118 e6 d6 bc zayin dagesh
119 e7 da b0 chof sofit shva
120 e8 ea bc taf
121 e9 d9 bc yood dagesh
122 eb db bc cof
123 ec dc bc lamed dagesh
124 ed d5 b9 vav holam
125 ee de bc mem dagesh
126 ef dc b9 lamed holam
127 f0 e0 bc nun dagesh
128 f1 e1 bc samech dagesh
129 f2 da b8 chof sofit kametz
130 f4 e4 bc peh
131 f5 e9 c1 shin
132 f6 e6 bc tzadi dagesh
133 f7 e7 bc koof dagesh
134 f8 e9 c1 bc shin dagesh
135 f9 e9 c2 bc sin dagesh
136 fa ea bc tof
137 fb e9 c2 sin
138 fc d6 b9 zayin holom
139 ff unknown (ignore)
140
141 vowels:
142 9b b1 segel shva
143 9c b3 qamats shva
144 9d b2 patach shva
145 9e b6 segel
146 9f b5 tzare
147 a0 b4 chirik
148 a1 b0 shva
149 a2 b8 kometz
150 a3 b7 patach
151 a4 bb kubutz
152 a5 b9 holam
153 a7 bottom of nun sofit (ignore)
154
155 END_DATA
156
157 }
158
159 1;