lib/hexapdf/parser.rb in hexapdf-0.6.0 vs lib/hexapdf/parser.rb in hexapdf-0.7.0
- old
+ new
@@ -1,12 +1,12 @@
-# -*- encoding: utf-8 -*-
+# -*- encoding: utf-8; frozen_string_literal: true -*-
#
#--
# This file is part of HexaPDF.
#
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
-# Copyright (C) 2014-2017 Thomas Leitner
+# Copyright (C) 2014-2018 Thomas Leitner
#
# HexaPDF is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License version 3 as
# published by the Free Software Foundation with the addition of the
# following permission added to Section 15 as permitted in Section 7(a):
@@ -94,24 +94,24 @@
@tokenizer.pos = offset + @header_offset if offset
oid = @tokenizer.next_token
gen = @tokenizer.next_token
tok = @tokenizer.next_token
unless oid.kind_of?(Integer) && gen.kind_of?(Integer) &&
- tok.kind_of?(Tokenizer::Token) && tok == 'obj'.freeze
+ tok.kind_of?(Tokenizer::Token) && tok == 'obj'
raise_malformed("No valid object found", pos: offset)
end
- if (tok = @tokenizer.peek_token) && tok.kind_of?(Tokenizer::Token) && tok == 'endobj'.freeze
+ if (tok = @tokenizer.peek_token) && tok.kind_of?(Tokenizer::Token) && tok == 'endobj'
maybe_raise("No indirect object value between 'obj' and 'endobj'", pos: @tokenizer.pos)
object = nil
else
object = @tokenizer.next_object
end
tok = @tokenizer.next_token
- if tok.kind_of?(Tokenizer::Token) && tok == 'stream'.freeze
+ if tok.kind_of?(Tokenizer::Token) && tok == 'stream'
unless object.kind_of?(Hash)
raise_malformed("A stream needs a dictionary, not a(n) #{object.class}", pos: offset)
end
tok1 = @tokenizer.next_byte
tok2 = @tokenizer.next_byte if tok1 == 13 # 13=CR, 10=LF
@@ -133,11 +133,11 @@
0
end
@tokenizer.pos = pos + length
tok = @tokenizer.next_token
- unless tok.kind_of?(Tokenizer::Token) && tok == 'endstream'.freeze
+ unless tok.kind_of?(Tokenizer::Token) && tok == 'endstream'
maybe_raise("Invalid stream length, keyword endstream not found", pos: @tokenizer.pos)
@tokenizer.pos = pos
if @tokenizer.scan_until(/(?=\n?endstream)/)
length = @tokenizer.pos - pos
tok = @tokenizer.next_token
@@ -152,11 +152,11 @@
stream = StreamData.new(@tokenizer.io, offset: pos, length: length,
filter: @document.unwrap(object[:Filter]),
decode_parms: @document.unwrap(object[:DecodeParms]))
end
- unless tok.kind_of?(Tokenizer::Token) && tok == 'endobj'.freeze
+ unless tok.kind_of?(Tokenizer::Token) && tok == 'endobj'
maybe_raise("Indirect object must be followed by keyword endobj", pos: @tokenizer.pos)
end
[object, oid, gen, stream]
end
@@ -232,11 +232,11 @@
maybe_raise("Invalid cross-reference subsection entry", pos: @tokenizer.pos,
force: matched_size == 20)
end
if xref.entry?(oid)
next
- elsif type == 'n'.freeze
+ elsif type == 'n'
if pos == 0 || gen > 65535
maybe_raise("Invalid in use cross-reference entry in cross-reference section",
pos: @tokenizer.pos)
xref.add_free_entry(oid, gen)
else
@@ -253,11 +253,11 @@
raise_malformed("Trailer doesn't start with keyword trailer", pos: @tokenizer.pos)
end
trailer = @tokenizer.next_object
unless trailer.kind_of?(Hash)
- raise_malformed("Trailer is a #{trailer.class} instead of a dictionary ", pos: @tokenizer.pos)
+ raise_malformed("Trailer is #{trailer.class} instead of dictionary ", pos: @tokenizer.pos)
end
[xref, trailer]
end
@@ -337,10 +337,10 @@
# Calls the block stored in the config option +parser.on_correctable_error+ with the document,
# the given message and the position. If the returned value is +true+, raises a
# HexaPDF::MalformedPDFError. Otherwise the error is corrected and parsing continues.
#
# If the option +force+ is used, the block is not called and the error is raised immediately.
- def maybe_raise(msg, pos: nil, force: false)
+ def maybe_raise(msg, pos:, force: false)
if force || @document.config['parser.on_correctable_error'].call(@document, msg, pos)
error = HexaPDF::MalformedPDFError.new(msg, pos: pos)
error.set_backtrace(caller(1))
raise error
end