Method: Parslet::Source#chars_until

Defined in:
lib/parslet/source.rb

#chars_until(str) ⇒ Fixnum

Returns how many chars there are between current position and the string given. If the string given doesn’t occur in the source, then the remaining chars (#chars_left) are returned.

Returns:

  • (Fixnum)

    count of chars until str or #chars_left



64
65
66
67
68
# File 'lib/parslet/source.rb', line 64

def chars_until str
  slice_str = @str.check_until(Regexp.new(Regexp.escape(str)))
  return chars_left unless slice_str
  return slice_str.size - str.size
end