class

Sthx::Cursor

Inherits Reference < Object

Constructors

new(source : String, char_index : Int32, byte_index : Int32)
Source
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.

Source

Instance methods

byte_index

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

Source
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.
Source
char_index

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

Source
max_err_byte_index

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

Source
thru?

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.

Source
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.

Source