String
pub type String = { ptr: ref u8, len: i64, cap: i64 }This is the classic string type.
An owned heap string: ptr, len, cap - each 8 bytes.
Fields
| Name | Type |
|---|---|
ptr | ref u8 |
len | i64 |
cap | i64 |
pub type String = { ptr: ref u8, len: i64, cap: i64 }This is the classic string type.
An owned heap string: ptr, len, cap - each 8 bytes.
| Name | Type |
|---|---|
ptr | ref u8 |
len | i64 |
cap | i64 |
pub type StringView = { ptr: ref u8, len: i64 }A borrowed, non-owning view over a byte range.
A view does not own ptr and is not required to be null-terminated. The caller must ensure the underlying bytes outlive the view.
| Name | Type |
|---|---|
ptr | ref u8 |
len | i64 |
fn alloc_in[T: allocators.Allocator](ac: T, size: i64) ref voidfn alloc_string_in[T: allocators.Allocator](ac: T, len: i64) Stringpub fn as_cstr[T](x: T) ref u8Extract ref u8 from supported types.
pub fn view(ptr: ref u8, len: i64) StringViewBuild a borrowed view over len bytes starting at ptr.
fn from_cstr_impl(s: ref u8) StringView = trust { ... }Build a view over an existing null-terminated C str.
pub fn from_cstr(s: ref u8) StringViewBuild a view over an existing null-terminated C str.
pub fn as_view[T](x: T) StringViewExtract a borrowed view from a String, StringView, or raw C str.
pub fn len(v: StringView) i64pub fn ptr(v: StringView) ref u8pub fn is_empty(v: StringView) boolpub fn cmp(a: StringView, b: StringView) i64 = trust { ... }Compare two views byte-for-byte using their lengths.
pub fn eql(a: StringView, b: StringView) bool = trust { ... }pub fn eql_cstr(v: StringView, s: ref u8) bool = trust { ... }Compare a view with a null-terminated string literal.
pub fn slice(v: StringView, start: i64, end: i64) StringView = trust { ... }Return a sub-view clamped to the bounds of v.
pub fn starts_with(v: StringView, prefix: StringView) bool = trust { ... }pub fn ends_with(v: StringView, suffix: StringView) bool = trust { ... }pub fn find(v: StringView, needle: StringView) option[i64] = trust { ... }pub fn contains(v: StringView, needle: StringView) bool = trust { ... }pub fn trim_left(v: StringView) StringView = trust { ... }pub fn trim_right(v: StringView) StringView = trust { ... }pub fn trim(v: StringView) StringView = trust { ... }pub type ZString = { ptr: ref u8 }An owned, NUL-terminated C str.
Construct with zstr_from; release with zstr_free using the same allocator.
| Name | Type |
|---|---|
ptr | ref u8 |
pub fn zstr_from[T: allocators.GeneralAllocator](ac: T, v: StringView) ZStringAllocate a NUL-terminated copy of a view with an explicit allocator.
pub fn zstr_from_cstr[T: allocators.GeneralAllocator](ac: T, s: ref u8) ZStringpub fn zstr_ptr(s: ZString) ref u8pub fn zstr(s: ZString) StringViewpub fn zstr_free[T: allocators.GeneralAllocator](ac: T, s: ZString) voidpub fn to_string[T: allocators.Allocator](ac: T, v: StringView) StringCopy a view into a newly allocated owning String.
pub fn to_lower[T: allocators.Allocator](ac: T, v: StringView) StringCopy a view into a new owned string with ASCII letters lowercased.
pub fn to_upper[T: allocators.Allocator](ac: T, v: StringView) StringCopy a view into a new owned string with ASCII letters uppercased.
pub fn compare[A, B](a: A, b: B) i64Compare supported string-like values using their lengths.
pub fn is_alpha(c: u8) boolReturns true when c is an ASCII letter (A-Z or a-z).