← Standard library

StringSlice

scoped struct StringSlice
import 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.

String.wax:1300

Members

lengthgetter

public get length() : int32

The number of UTF-8 bytes, excluding any terminator. This is not a character or grapheme count.

String.wax:1311

Containsmethod

public fn Contains<T>(T needle) : bool where T is StringLike

Tests for an exact, case-sensitive byte sequence. An empty needle is always present. Accepts strings and other StringLike values.

String.wax:1318

StartsWithmethod

public fn StartsWith<T>(T prefix) : bool where T is StringLike

Tests for an exact, case-sensitive prefix. An empty prefix matches; a prefix longer than this slice does not.

String.wax:1326

EndsWithmethod

public fn EndsWith<T>(T suffix) : bool where T is StringLike

Tests for an exact, case-sensitive suffix. An empty suffix matches; a suffix longer than this slice does not.

String.wax:1335

IndexOfmethod

public fn IndexOf<T>(T needle) : int32 where T is StringLike

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

String.wax:1344

LastIndexOfmethod

public fn LastIndexOf<T>(T needle) : int32 where T is StringLike

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

String.wax:1352

Countmethod

public fn Count<T>(T needle) : int32 where T is StringLike

Counts exact, case-sensitive, non-overlapping matches from left to right. An empty needle returns 0.

String.wax:1368

ByteAtmethod

public fn ByteAt(int32 index) : uint8

Reads an in-range UTF-8 byte relative to the view. Negative indices and indices at or beyond length panic.

String.wax:1390

CharAtByteOffsetmethod

public fn CharAtByteOffset(int32 offset) : char

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

String.wax:1397

FirstBytemethod

public fn FirstByte() : uint8

Returns the first byte. Panics on an empty slice.

String.wax:1403

LastBytemethod

public fn LastByte() : uint8

Returns the last byte, which may be a UTF-8 continuation byte. Panics on an empty slice.

String.wax:1407

FirstCharmethod

public fn FirstChar() : char

Returns the first code point. Panics on an empty slice.

String.wax:1411

LastCharmethod

public fn LastChar() : char

Returns the last code point. Panics on an empty slice.

String.wax:1415

IsEmptymethod

public fn IsEmpty() : bool

Returns true when length is zero.

String.wax:1425

Slicemethod

public fn Slice(int32 sliceStart, int32 len) : StringSlice

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

String.wax:1432

Trimmethod

public fn Trim() : StringSlice

Borrows a narrower view with leading and trailing Unicode whitespace removed. All-whitespace input produces an empty slice.

String.wax:1442

TrimStartmethod

public fn TrimStart() : StringSlice

Borrows a view with leading Unicode whitespace removed, without copying.

String.wax:1450

TrimEndmethod

public fn TrimEnd() : StringSlice

Borrows a view with trailing Unicode whitespace removed, without copying.

String.wax:1457

ToStringmethod

public fn ToString() : string

Copies the viewed bytes into an independent string that can outlive the slice.

String.wax:1466

ToStringSlicemethod

public fn ToStringSlice() : StringSlice

Returns this view unchanged.

String.wax:1470

ToReadOnlySpanmethod

public fn ToReadOnlySpan() : ReadOnlySpan<uint8>

Borrows the raw UTF-8 bytes of this view without a copy or terminator.

String.wax:1476

Bytesmethod

public fn Bytes() : ByteIterator

Iterates UTF-8 bytes from first to last. An empty string yields no elements.

String.wax:1482

Charsmethod

public fn Chars() : CharIterator

Iterates Unicode code points from first to last. Code points are not necessarily whole displayed characters; use Graphemes for those boundaries.

String.wax:1489

CharsReversemethod

public fn CharsReverse() : ReverseCharIterator

Iterates Unicode code points from last to first, preserving each code point. This does not reverse grapheme clusters as units.

String.wax:1496

Graphemesmethod

public fn Graphemes() : GraphemeIterator

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

String.wax:1503

GraphemeCountmethod

public fn GraphemeCount() : int32

Counts extended grapheme clusters by scanning the string. Returns zero for an empty string; this differs from the UTF-8 byte count in length.

String.wax:1510

ToStringBuffermethod

public fn ToStringBuffer(StringBuilder builder) : int32

Provided by the compiler.