Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use String#byteindex instead of String#index #286

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib/net/imap/response_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2023,21 +2023,21 @@ def nil_atom
# This advances @pos directly so it's safe before changing @lex_state.
def accept_spaces
return false unless SP?
@str.index(SPACES_REGEXP, @pos) and
@pos = $~.end(0)
@str.byteindex(SPACES_REGEXP, @pos) and
@pos = $~.byteoffset(0)[1]
true
end

def next_token
case @lex_state
when EXPR_BEG
if @str.index(BEG_REGEXP, @pos)
@pos = $~.end(0)
if @str.byteindex(BEG_REGEXP, @pos)
@pos = $~.byteoffset(0)[1]
if $1
return Token.new(T_SPACE, $+)
elsif $2
len = $+.to_i
val = @str[@pos, len]
val = @str.byteslice(@pos, len)
@pos += len
return Token.new(T_LITERAL8, val)
elsif $3 && $7
Expand Down Expand Up @@ -2068,7 +2068,7 @@ def next_token
return Token.new(T_RBRA, $+)
elsif $16
len = $+.to_i
val = @str[@pos, len]
val = @str.byteslice(@pos, len)
@pos += len
return Token.new(T_LITERAL, val)
elsif $17
Expand All @@ -2081,12 +2081,12 @@ def next_token
parse_error("[Net::IMAP BUG] BEG_REGEXP is invalid")
end
else
@str.index(/\S*/n, @pos)
@str.byteindex(/\S*/n, @pos)
parse_error("unknown token - %s", $&.dump)
end
when EXPR_DATA
if @str.index(DATA_REGEXP, @pos)
@pos = $~.end(0)
if @str.byteindex(DATA_REGEXP, @pos)
@pos = $~.byteoffset(0)[1]
if $1
return Token.new(T_SPACE, $+)
elsif $2
Expand All @@ -2097,7 +2097,7 @@ def next_token
return Token.new(T_QUOTED, Patterns.unescape_quoted($+))
elsif $5
len = $+.to_i
val = @str[@pos, len]
val = @str.byteslice(@pos, len)
@pos += len
return Token.new(T_LITERAL, val)
elsif $6
Expand All @@ -2108,7 +2108,7 @@ def next_token
parse_error("[Net::IMAP BUG] DATA_REGEXP is invalid")
end
else
@str.index(/\S*/n, @pos)
@str.byteindex(/\S*/n, @pos)
parse_error("unknown token - %s", $&.dump)
end
else
Expand Down
Loading