method
move
v8.1.1 -
Show latest stable
- Class:
ActionDispatch::Journey::GTG::TransitionTable
move(t, full_string, token, start_index, token_matches_default)public
No documentation available.
# File actionpack/lib/action_dispatch/journey/gtg/transition_table.rb, line 49
def move(t, full_string, token, start_index, token_matches_default)
return [] if t.empty?
next_states = []
transitions_count = t.size
i = 0
while i < transitions_count
s = t[i]
previous_start = t[i + 1]
if previous_start.nil?
# In the simple case of a "default" param regex do this fast-path and add all
# next states.
if token_matches_default && std_state = @stdparam_states[s]
next_states << std_state << nil
end
# When we have a literal string, we can just pull the next state
if states = @string_states[s]
state = states[token]
next_states << state << nil unless state.nil?
end
end
# For regexes that aren't the "default" style, they may potentially not be
# terminated by the first "token" [./?], so we need to continue to attempt to
# match this regexp as well as any successful paths that continue out of it.
# both paths could be valid.
if states = @regexp_states[s]
slice_start = if previous_start.nil?
start_index
else
previous_start
end
slice_length = start_index + token.length - slice_start
curr_slice = full_string.slice(slice_start, slice_length)
states.each { |re, v|
# if we match, we can try moving past this
next_states << v << nil if !v.nil? && re.match?(curr_slice)
}
# and regardless, we must continue accepting tokens and retrying this regexp. we
# need to remember where we started as well so we can take bigger slices.
next_states << s << slice_start
end
i += 2
end
next_states
end