class Sthx::Cursor

Defined in:

synthax/cursor.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(source : String, char_index : Int32, byte_index : Int32) #

[View source]
def self.new(source : String, char_index : Int32) #

Computes byte index from char index for you, otherwise the same as the other overload of .new.

Raises IndexError if char index is out of bounds.


[View source]

Instance Method Detail

def byte_index : Int32 #

Returns the index of the byte pointed at by this cursor, within the source string.


[View source]
def capture(byte_start : Int, byte_end : Int) : Bytes #

Returns a byteslice between byte_start and byte_end byte indices.

  • The byte at byte_start is included in the returned slice.
  • The byte at byte_end is excluded from the returned slice.

[View source]
def char_index : Int32 #

Returns the index of the character pointed at by this cursor, within the source string.


[View source]
def max_err_byte_index : Int32 #

Returns the byte index of the error with most progress into the source string.


[View source]
def thru?(& : Char -> Bool) : Bool #

Advances this cursor to the next character if the block returns true for the current one.

Returns true if advanced, false if the position did not change.


[View source]
def thru?(bytes : Bytes) : Bool #

Attempts to advance the cursor past bytes matching those in bytes.

Returns true if advanced, false if the position did not change.


[View source]