lib/net/imap/response_parser/parser_utils.rb in net-imap-0.4.3 vs lib/net/imap/response_parser/parser_utils.rb in net-imap-0.4.4
- old
+ new
@@ -13,10 +13,11 @@
LOOKAHEAD = "(@token ||= next_token)"
SHIFT_TOKEN = "(@token = nil)"
# we can skip lexer for single character matches, as a shortcut
def def_char_matchers(name, char, token)
+ byte = char.ord
match_name = name.match(/\A[A-Z]/) ? "#{name}!" : name
char = char.dump
class_eval <<~RUBY, __FILE__, __LINE__ + 1
# frozen_string_literal: true
@@ -25,30 +26,30 @@
#{LOOKAHEAD}&.symbol == #{token}
end
# use token or string peek
def peek_#{name}?
- @token ? @token.symbol == #{token} : @str[@pos] == #{char}
+ @token ? @token.symbol == #{token} : @str.getbyte(@pos) == #{byte}
end
# like accept(token_symbols); returns token or nil
def #{name}?
if @token&.symbol == #{token}
#{SHIFT_TOKEN}
#{char}
- elsif !@token && @str[@pos] == #{char}
+ elsif !@token && @str.getbyte(@pos) == #{byte}
@pos += 1
#{char}
end
end
# like match(token_symbols); returns token or raises parse_error
def #{match_name}
if @token&.symbol == #{token}
#{SHIFT_TOKEN}
#{char}
- elsif !@token && @str[@pos] == #{char}
+ elsif !@token && @str.getbyte(@pos) == #{byte}
@pos += 1
#{char}
else
parse_error("unexpected %s (expected %p)",
@token&.symbol || @str[@pos].inspect, #{char})
@@ -107,10 +108,9 @@
else
#{raise_parse_error}
end
end
RUBY
-
end
end
private