lib/hexapdf/content/parser.rb in hexapdf-0.2.0 vs lib/hexapdf/content/parser.rb in hexapdf-0.3.0
- old
+ new
@@ -2,11 +2,11 @@
#
#--
# This file is part of HexaPDF.
#
# HexaPDF - A Versatile PDF Creation and Manipulation Library For Ruby
-# Copyright (C) 2016 Thomas Leitner
+# Copyright (C) 2014-2017 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):
@@ -46,10 +46,11 @@
class Tokenizer < HexaPDF::Tokenizer #:nodoc:
# Creates a new tokenizer.
def initialize(string)
@ss = StringScanner.new(string)
+ @string = string
end
# See: HexaPDF::Tokenizer#pos
def pos
@ss.pos
@@ -66,43 +67,43 @@
end
# See: HexaPDF::Tokenizer#next_token
def next_token
@ss.skip(WHITESPACE_MULTI_RE)
- case (@ss.eos? ? -1 : @ss.string.getbyte(@ss.pos))
- when 43, 45, 46, 48..57 # + - . 0..9
+ byte = @string.getbyte(@ss.pos) || -1
+ if (48 <= byte && byte <= 57) || byte == 45 || byte == 43 || byte == 46 # 0..9 - + .
parse_number
- when 65..90, 96..121
+ elsif (65 <= byte && byte <= 90) || (96 <= byte && byte <= 121)
parse_keyword
- when 47 # /
+ elsif byte == 47 # /
parse_name
- when 40 # (
+ elsif byte == 40 # (
parse_literal_string
- when 60 # <
- if @ss.string.getbyte(@ss.pos + 1) != 60
+ elsif byte == 60 # <
+ if @string.getbyte(@ss.pos + 1) != 60
parse_hex_string
else
@ss.pos += 2
TOKEN_DICT_START
end
- when 62 # >
- unless @ss.string.getbyte(@ss.pos + 1) == 62
+ elsif byte == 62 # >
+ unless @string.getbyte(@ss.pos + 1) == 62
raise HexaPDF::MalformedPDFError.new("Delimiter '>' found at invalid position", pos: pos)
end
@ss.pos += 2
TOKEN_DICT_END
- when 91 # [
+ elsif byte == 91 # [
@ss.pos += 1
TOKEN_ARRAY_START
- when 93 # ]
+ elsif byte == 93 # ]
@ss.pos += 1
TOKEN_ARRAY_END
- when 123, 125 # { }
+ elsif byte == 123 || byte == 125 # { }
Token.new(@ss.get_byte)
- when 37 # %
+ elsif byte == 37 # %
return NO_MORE_TOKENS unless @ss.skip_until(/(?=[\r\n])/)
next_token
- when -1
+ elsif byte == -1
NO_MORE_TOKENS
else
parse_keyword
end
end