x-lang

← Index

x/type/str

String library: the Str8 / StrUtf8 protocol classes and the byte accessors.

The string library is the protocol classes Str8 / StrUtf8, with Str naming the active protocol (StrUtf8 by default). Use (Str append a b), (Str length s), etc.; (help Str8 method) for per-method docs.

Byte accessors str-length, str-ref, substring, str=? are always byte-level.

str-length

Byte length (raw octets). For element count in the active protocol use (Str length s).

Parameters:

Returns: INT — Byte length of s

Examples:

(%str-length "$¢€") => 6

str-ref

Byte at offset i, UNCHECKED: an out-of-range offset reads out of bounds – use (Str8 ref i s) for the checked byte view. For the i-th code point use (StrUtf8 ref i s) or the bare (s i) – equivalent, including negative i counting from the end.

Parameters:

Returns: CHAR — The byte at offset i, as a CHARACTER (0-255)

Examples:

(%str-ref "$¢€" 1) => #\Â

substring

Byte substring [start, end) – the byte-level slice-convention primitive. Always byte-level.

Parameters:

Returns: STRING — The bytes [start, end) of s

Examples:

(%substring "abcdef" 1 4) => "bcd"

str=?

String equality (byte-level; the same result as code-point equality).

Parameters:

Returns: BOOL — #t if a and b are equal

Examples:

(str=? "ab" "ab") => #t