@@ -4,6 +4,7 @@ get_pdfcontentops
4
4
import Base: peek
5
5
6
6
_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 " )
7
8
8
9
# This function is for testing only
9
10
function parse_data (filename)
@@ -66,7 +67,7 @@ function parse_name(ps::IO)
66
67
if ispdfxdigit (c1) && ispdfxdigit (c2)
67
68
c = UInt8 (gethexval (c1)* 16 + gethexval (c2))
68
69
else
69
- _error (E_UNEXPECTED_CHAR, ps)
70
+ _error (E_UNEXPECTED_CHAR, ps, c1, c2 )
70
71
end
71
72
end
72
73
skip (ps,1 )
@@ -183,26 +184,22 @@ end
183
184
184
185
function parse_xstring (ps:: IO )
185
186
b = UInt8[]
186
- skip (ps,1 ) # skip open LT
187
+ skip (ps, 1 ) # skip open LT
187
188
188
- count = 0
189
189
while true
190
190
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)
193
196
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)
198
198
chomp_space! (ps)
199
199
return CosXString (b)
200
- elseif ! ispdfxdigit (c)
201
- _error (E_UNEXPECTED_CHAR, ps)
202
200
else
203
- count += 1
201
+ _error (E_UNEXPECTED_CHAR, ps, c)
204
202
end
205
- push! (b, c)
206
203
end
207
204
end
208
205
@@ -245,7 +242,7 @@ function ensure_line_feed_eol(ps::IO)
245
242
elseif (c == LINE_FEED)
246
243
return c
247
244
else
248
- _error (E_UNEXPECTED_CHAR, ps)
245
+ _error (E_UNEXPECTED_CHAR, ps, c )
249
246
end
250
247
end
251
248
0 commit comments