StringSlice
scoped struct StringSliceimport StringSlice from Wax;A scoped, read-only UTF-8 view that borrows text without copying. Offsets and lengths are bytes
relative to the view. ToString copies into a retainable string. Byte/character access panics
outside the slice, unlike the sentinel-returning accessors on string; check for empty input
before reading its first or last element.
Members
lengthgetter
public get length() : int32The number of UTF-8 bytes, excluding any terminator. This is not a character or grapheme count.
Containsmethod
public fn Contains<T>(T needle) : bool where T is StringLikeTests for an exact, case-sensitive byte sequence. An empty needle is always present. Accepts
strings and other StringLike values.
StartsWithmethod
public fn StartsWith<T>(T prefix) : bool where T is StringLikeTests for an exact, case-sensitive prefix. An empty prefix matches; a prefix longer than this slice does not.
EndsWithmethod
public fn EndsWith<T>(T suffix) : bool where T is StringLikeTests for an exact, case-sensitive suffix. An empty suffix matches; a suffix longer than this slice does not.
IndexOfmethod
public fn IndexOf<T>(T needle) : int32 where T is StringLikeReturns the byte offset of the first exact match, or -1 when absent. An empty needle
returns 0. Matching is case-sensitive and does not normalize Unicode.
LastIndexOfmethod
public fn LastIndexOf<T>(T needle) : int32 where T is StringLikeReturns the byte offset of the last exact match, or -1 when absent. An empty needle
returns length. Matching is case-sensitive and does not normalize Unicode.
Countmethod
public fn Count<T>(T needle) : int32 where T is StringLikeCounts exact, case-sensitive, non-overlapping matches from left to right. An empty needle
returns 0.
ByteAtmethod
public fn ByteAt(int32 index) : uint8Reads an in-range UTF-8 byte relative to the view. Negative indices and indices at or beyond
length panic.
CharAtByteOffsetmethod
public fn CharAtByteOffset(int32 offset) : charDecodes at an in-range byte offset relative to the view. An offset inside a multibyte sequence produces U+FFFD; an out-of-range offset panics.
FirstBytemethod
public fn FirstByte() : uint8Returns the first byte. Panics on an empty slice.
LastBytemethod
public fn LastByte() : uint8Returns the last byte, which may be a UTF-8 continuation byte. Panics on an empty slice.
FirstCharmethod
public fn FirstChar() : charReturns the first code point. Panics on an empty slice.
LastCharmethod
public fn LastChar() : charReturns the last code point. Panics on an empty slice.
IsEmptymethod
public fn IsEmpty() : boolReturns true when length is zero.
Slicemethod
public fn Slice(int32 sliceStart, int32 len) : StringSliceBorrows a subrange relative to this view. Arguments must be nonnegative, the range must fit, and both endpoints must be code-point boundaries, otherwise it panics.
Trimmethod
public fn Trim() : StringSliceBorrows a narrower view with leading and trailing Unicode whitespace removed. All-whitespace input produces an empty slice.
TrimStartmethod
public fn TrimStart() : StringSliceBorrows a view with leading Unicode whitespace removed, without copying.
TrimEndmethod
public fn TrimEnd() : StringSliceBorrows a view with trailing Unicode whitespace removed, without copying.
ToStringmethod
public fn ToString() : stringCopies the viewed bytes into an independent string that can outlive the slice.
ToStringSlicemethod
public fn ToStringSlice() : StringSliceReturns this view unchanged.
ToReadOnlySpanmethod
public fn ToReadOnlySpan() : ReadOnlySpan<uint8>Borrows the raw UTF-8 bytes of this view without a copy or terminator.
Bytesmethod
public fn Bytes() : ByteIteratorIterates UTF-8 bytes from first to last. An empty string yields no elements.
Charsmethod
public fn Chars() : CharIteratorIterates Unicode code points from first to last. Code points are not necessarily whole
displayed characters; use Graphemes for those boundaries.
CharsReversemethod
public fn CharsReverse() : ReverseCharIteratorIterates Unicode code points from last to first, preserving each code point. This does not reverse grapheme clusters as units.
Graphemesmethod
public fn Graphemes() : GraphemeIteratorIterates extended grapheme clusters as borrowed StringSlice views. A cluster may contain
several code points, such as a letter plus combining marks. Empty input yields no clusters.
GraphemeCountmethod
public fn GraphemeCount() : int32Counts extended grapheme clusters by scanning the string. Returns zero for an empty string;
this differs from the UTF-8 byte count in length.
ToStringBuffermethod
public fn ToStringBuffer(StringBuilder builder) : int32Provided by the compiler.