API2/Basic/PDF/Filter/ASCIIHexDecode.pm

filter: Statementstmt 100% 29 / 29 Branchbran 100% 8 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 2 / 2 totaltotal 100% 49 / 49 SCAR 17.9
CC
6
Cov
100%
infilt
5.0
outfilt
2.0
BEGIN
1.0
CRAP 6.0
« API2/Resource.pm ↑ Summary API2/Basic/PDF/Page.pm »
1 package PDF::API2::Basic::PDF::Filter::ASCIIHexDecode;
2  
3 43 ▶use base 'PDF::API2::Basic::PDF::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 43 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 43 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 43 our $VERSION = '2.044'; # VERSION
9  
10 # Maintainer's Note: ASCIIHexDecode is described in the PDF 1.7 spec
11 # in section 7.4.2.
12  
13 sub outfilt {
14 4 ▶ my ($self, $string, $include_eod) = @_;
Subroutine outfilt: called CC=2 SCAR=6.9
Pod documented
15  
16 # Each byte of the input string gets encoded as two hexadecimal
17 # characters.
18 4 $string =~ s/(.)/sprintf('%02x', ord($1))/ges;
19  
20 # Wrap after 72 characters
21 4 $string =~ s/(.{72})/$1\n/g;
22  
23 # The EOD (end-of-document) marker is a greater-than sign
24 4 ▶ $string .= '>' if $include_eod;
Branch: 1 branch
BranchTrueFalseTotal
if $include_eod 3 1 4
25  
26 4 return $string;
27 }
28  
29 sub infilt {
30 8 ▶ my ($self, $string) = @_;
Subroutine infilt: called CC=5 SCAR=16.1
Pod documented
31  
32 # "All white-space characters shall be ignored."
33 8 $string =~ s/\s//og;
34  
35 # "A GREATER-THAN SIGN (3Eh) indicates EOD."
36 8 my $has_eod_marker = 0;
37 8 ▶ if (substr($string, -1, 1) eq '>') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($string, -1, 1) eq ">") 3 5 8
38 3 $has_eod_marker = 1;
39 3 chop $string;
40 }
41  
42 # "Any other characters [than 0-9, A-F, or a-f] shall cause an
43 # error."
44 8 ▶ die "Illegal character found in ASCII hex-encoded stream"
Branch: 1 branch
BranchTrueFalseTotal
if $string =~ /[^0-9A-Fa-f]/ 1 7 8
45 if $string =~ /[^0-9A-Fa-f]/;
46  
47 # "If the filter encounters the EOD marker after reading an odd
48 # number of hexadecimal digits, it shall behave as if a 0 (zero)
49 # followed the last digit."
50 7 ▶ if ($has_eod_marker and length($string) % 2 == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_eod_marker and length($string) % 2 == 1) 1 6 7
Condition100%3/3
$has_eod_marker and length($string) % 2 == 1
!ll&&!rl&&r
421
MC/DC100%2/2
$has_eod_marker and length($string) % 2 == 1
$has_eod_marker length($string) % 2 == 1
Truth table100%3/3
A and B
A= $has_eod_markerB= length($string) % 2 == 1
ABresult
0X0
100
111
51 1 $string .= '0';
52 }
53  
54 # "The ASCIIHexDecode filter shall produce one byte of binary data
55 # for each pair of ASCII hexadecimal digits."
56 7 $string =~ s/([0-9A-Fa-f]{2})/pack("C", hex($1))/oge;
57  
58 7 return $string;
59 }
60  
61 43 1;
« API2/Resource.pm ↑ Summary API2/Basic/PDF/Page.pm »