StringRef

Module

Implements the StringRef class.

StringRef

Represent a constant reference to a string, i.e. a sequence of characters and a length, which need not be null terminated.

Fields:

data

A pointer to the beginning of the string data being referenced.

length

The length of the string being referenced.

Functions:

__init__

__init__(str: StringLiteral) -> Self

Construct a StringRef value given a constant string.

Args:

  • str (StringLiteral): The input constant string.

Returns:

Constructed StringRef object.

__init__(ptr: pointer<scalar<si8>>, len: Int) -> Self

Construct a StringRef value given a (potentially non-0 terminated string).

The constructor takes a raw pointer and a length.

Args:

  • ptr (pointer<scalar<si8>>): Pointer to the string.
  • len (Int): The length of the string.

Returns:

Constructed StringRef object.

__init__(ptr: pointer<scalar<si8>>) -> Self

Construct a StringRef value given a 0-terminated string.

The constructor takes a raw pointer and deduced the length of the string automatically by scanning for 0.

Args:

  • ptr (pointer<scalar<si8>>): Pointer to the string.

Returns:

Constructed StringRef object.

__getitem__

__getitem__(self: Self, idx: Int) -> Self

Get the string value at the specified position.

Args:

  • idx (Int): The index position.

Returns:

The character at the specified position.

__eq__

__eq__(self: Self, rhs: Self) -> Bool

Compares two strings are equal.

Args:

  • rhs (Self): The other string.

Returns:

True if the strings match and False otherwise.

__ne__

__ne__(self: Self, rhs: Self) -> Bool

Compares two strings are not equal.

Args:

  • rhs (Self): The other string.

Returns:

True if the strings do not match and False otherwise.

__len__

__len__(self: Self) -> Int