line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::Parity; |
2
|
|
|
|
|
|
|
$String::Parity::VERSION = '1.34'; |
3
|
1
|
|
|
1
|
|
635
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
851
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw( |
12
|
|
|
|
|
|
|
setEvenParity setOddParity |
13
|
|
|
|
|
|
|
setMarkParity setSpaceParity |
14
|
|
|
|
|
|
|
EvenBytes OddBytes |
15
|
|
|
|
|
|
|
MarkBytes SpaceBytes |
16
|
|
|
|
|
|
|
isEvenParity isOddParity |
17
|
|
|
|
|
|
|
isMarkParity isSpaceParity |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
21
|
|
|
|
|
|
|
showParity showMarkSpace |
22
|
|
|
|
|
|
|
$even_parity $odd_parity |
23
|
|
|
|
|
|
|
$show_parity $even_codes |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
our ($even_parity, $odd_parity, $show_parity); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $even_bits = "\0"; |
28
|
|
|
|
|
|
|
my $odd_bits = "\200"; |
29
|
|
|
|
|
|
|
foreach (0 .. 7) { |
30
|
|
|
|
|
|
|
$even_bits .= $odd_bits; |
31
|
|
|
|
|
|
|
($odd_bits = $even_bits) =~ tr/\0\200/\200\0/; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $codes = pack('C*', (0 .. 255)); |
35
|
|
|
|
|
|
|
($even_parity = $codes ^ $even_bits) =~ s/(\W)/sprintf('\%o', ord $1)/eg; |
36
|
|
|
|
|
|
|
($odd_parity = $codes ^ $odd_bits) =~ s/(\W)/sprintf('\%o', ord $1)/eg; |
37
|
|
|
|
|
|
|
($show_parity = $even_bits) =~ tr /\0\200/eo/; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $even_codes = ''; |
40
|
|
|
|
|
|
|
while ($even_bits =~ /\0/g) { |
41
|
|
|
|
|
|
|
$even_codes .= sprintf '\%o', (pos $even_bits) - 1; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
4
|
100
|
|
4
|
1
|
67
|
eval <
|
|
4
|
100
|
|
4
|
1
|
10
|
|
|
4
|
50
|
|
2
|
1
|
9
|
|
|
4
|
|
|
2
|
1
|
12
|
|
|
4
|
|
|
2
|
1
|
6
|
|
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
106
|
|
|
2
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
78
|
|
|
2
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
66
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub setEvenParity { |
47
|
|
|
|
|
|
|
my(\@s) = \@_; |
48
|
|
|
|
|
|
|
foreach (\@s) { |
49
|
|
|
|
|
|
|
tr/\\0-\\377/$even_parity/; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
wantarray ? \@s : join '', \@s; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub setOddParity { |
55
|
|
|
|
|
|
|
my(\@s) = \@_; |
56
|
|
|
|
|
|
|
foreach (\@s) { |
57
|
|
|
|
|
|
|
tr/\\0-\\377/$odd_parity/; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
wantarray ? \@s : join '', \@s; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub showParity { |
63
|
|
|
|
|
|
|
my(\@s) = \@_; |
64
|
|
|
|
|
|
|
foreach (\@s) { |
65
|
|
|
|
|
|
|
tr/\\0-\\377/$show_parity/; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
wantarray ? \@s : join '', \@s; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub EvenBytes { |
71
|
|
|
|
|
|
|
my \$count = 0; |
72
|
|
|
|
|
|
|
foreach (\@_) { |
73
|
|
|
|
|
|
|
\$count += tr/$even_codes//; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
\$count; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub OddBytes { |
79
|
|
|
|
|
|
|
my \$count = 0; |
80
|
|
|
|
|
|
|
foreach (\@_) { |
81
|
|
|
|
|
|
|
\$count += tr/$even_codes//c; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
\$count; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
EDQ |
87
|
|
|
|
|
|
|
die $@ if $@; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub isEvenParity { |
90
|
2
|
|
|
2
|
1
|
64
|
! &OddBytes; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub isOddParity { |
94
|
2
|
|
|
2
|
1
|
61
|
! &EvenBytes; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub setSpaceParity { |
98
|
2
|
|
|
2
|
1
|
31
|
my(@s) = @_; |
99
|
2
|
|
|
|
|
26
|
foreach (@s) { |
100
|
4
|
|
|
|
|
8
|
tr/\200-\377/\0-\177/; |
101
|
|
|
|
|
|
|
} |
102
|
2
|
100
|
|
|
|
10
|
wantarray ? @s : join '', @s; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub setMarkParity { |
106
|
2
|
|
|
2
|
1
|
16
|
my(@s) = @_; |
107
|
2
|
|
|
|
|
4
|
foreach (@s) { |
108
|
4
|
|
|
|
|
8
|
tr/\0-\177/\200-\377/; |
109
|
|
|
|
|
|
|
} |
110
|
2
|
100
|
|
|
|
14
|
wantarray ? @s : join '', @s; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub showMarkSpace { |
114
|
2
|
|
|
2
|
1
|
19
|
my(@s) = @_; |
115
|
2
|
|
|
|
|
5
|
foreach (@s) { |
116
|
2
|
|
|
|
|
5
|
tr/\0-\177/s/; |
117
|
2
|
|
|
|
|
3
|
tr/\200-\377/m/; |
118
|
|
|
|
|
|
|
} |
119
|
2
|
50
|
|
|
|
11
|
wantarray ? @s : join '', @s; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub SpaceBytes { |
123
|
6
|
|
|
6
|
1
|
10
|
my $count = 0; |
124
|
6
|
|
|
|
|
10
|
foreach (@_) { |
125
|
6
|
|
|
|
|
14
|
$count += tr/\0-\177//; |
126
|
|
|
|
|
|
|
} |
127
|
6
|
|
|
|
|
15
|
$count; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub MarkBytes { |
131
|
6
|
|
|
6
|
1
|
7
|
my $count = 0; |
132
|
6
|
|
|
|
|
10
|
foreach (@_) { |
133
|
6
|
|
|
|
|
12
|
$count += tr/\200-\377//; |
134
|
|
|
|
|
|
|
} |
135
|
6
|
|
|
|
|
18
|
$count; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub isSpaceParity { |
139
|
4
|
|
|
4
|
1
|
31
|
! &MarkBytes; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub isMarkParity { |
143
|
4
|
|
|
4
|
1
|
34
|
! &SpaceBytes; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |