Skip to content

Commit 9ceafda

Browse files
committed
In parsing hexadecimal strings space has to be ignored.
improved _error to print the characters currently being used for better debugging.
1 parent 98c217a commit 9ceafda

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/CosReader.jl

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ get_pdfcontentops
44
import Base: peek
55

66
_error(msg, io) = error(msg*" at $(position(io)) found $(_peekb(io))")
7+
_error(msg, io, cs...) = error(msg*" at $(position(io)) next: $(_peekb(io)) curr: $cs")
78

89
#This function is for testing only
910
function parse_data(filename)
@@ -66,7 +67,7 @@ function parse_name(ps::IO)
6667
if ispdfxdigit(c1) && ispdfxdigit(c2)
6768
c = UInt8(gethexval(c1)*16+gethexval(c2))
6869
else
69-
_error(E_UNEXPECTED_CHAR, ps)
70+
_error(E_UNEXPECTED_CHAR, ps, c1, c2)
7071
end
7172
end
7273
skip(ps,1)
@@ -183,26 +184,22 @@ end
183184

184185
function parse_xstring(ps::IO)
185186
b = UInt8[]
186-
skip(ps,1) # skip open LT
187+
skip(ps, 1) # skip open LT
187188

188-
count = 0
189189
while true
190190
c = advance!(ps)
191-
if c == LESS_THAN
192-
return parse_dict(ps)
191+
c == LESS_THAN && return parse_dict(ps)
192+
# As per section 7.3.4.3 space must be ignored
193+
ispdfspace(c) && continue
194+
if ispdfxdigit(c)
195+
push!(b, c)
193196
elseif c == GREATER_THAN
194-
if count % 2 !=0
195-
count +=1
196-
push!(b, NULL)
197-
end
197+
length(b) % 2 != 0 && push!(b, NULL)
198198
chomp_space!(ps)
199199
return CosXString(b)
200-
elseif !ispdfxdigit(c)
201-
_error(E_UNEXPECTED_CHAR, ps)
202200
else
203-
count +=1
201+
_error(E_UNEXPECTED_CHAR, ps, c)
204202
end
205-
push!(b, c)
206203
end
207204
end
208205

@@ -245,7 +242,7 @@ function ensure_line_feed_eol(ps::IO)
245242
elseif (c == LINE_FEED)
246243
return c
247244
else
248-
_error(E_UNEXPECTED_CHAR, ps)
245+
_error(E_UNEXPECTED_CHAR, ps, c)
249246
end
250247
end
251248

0 commit comments

Comments
 (0)