string/owned

sourcestring/owned.sx

alloc_in

private
fn alloc_in[T: allocators.Allocator](ac: T, size: i64) ref void

alloc_string_in

private
fn alloc_string_in[T: allocators.Allocator](ac: T, len: i64) str.String

alloc_in_general

private
fn alloc_in_general[T: allocators.GeneralAllocator](ac: T, size: i64) ref void

alloc_string_in_general

private
fn alloc_string_in_general[T: allocators.GeneralAllocator](ac: T, len: i64) str.String

new

pub fn new() str.String = trust { ... }

Create empty string

from_cstr

pub fn from_cstr[T: allocators.Allocator](ac: T, cstr: ref u8) str.String

Create from raw C string using the provided allocator.

free

pub fn free(s: str.String) void = trust { ... }

Free string

len

pub fn len(s: str.String) i64

Length of a str.String

as_cstr

pub fn as_cstr(s: str.String) ref u8 = trust { ... }

Raw pointer

ensure_cap

private
fn ensure_cap(ptr: ref void, needed: i64) void = trust { ... }

Ensure capacity (private helper)

push_cstr

pub fn push_cstr(s: str.String, other: ref u8) void = trust { ... }

Append a C string in place

push

pub fn push(s: str.String, other: str.String) void = trust { ... }

Append another str.String in place

clone

pub fn clone(s: str.String) str.String = trust { ... }

Clone — returns a new heap-allocated str.String

reverse

pub fn reverse(s: str.String) void = trust { ... }

Reverse in place

concat

pub fn concat(a: str.String, b: str.String) str.String = trust { ... }

Concat — returns a new heap-allocated str.String

reserve

pub fn reserve(s: str.String, cap: i64) void = trust { ... }

Reserve at least cap bytes of capacity

clear

pub fn clear(s: str.String) void = trust { ... }

Clear contents (set length to 0, keep allocation)

push_char

pub fn push_char(s: str.String, c: u8) void = trust { ... }

Append a single byte character

get

pub fn get(s: str.String, i: i64) option[u8]

Get byte at index i, returns none if out of bounds

set

pub fn set(s: str.String, i: i64, c: u8) void = trust { ... }

Set byte at index i (no-op if out of bounds)

slice

pub fn slice(s: str.String, start: i64, end: i64) str.String = trust { ... }

Return a new heap str.String containing bytes [start, end)

slice_general

private
fn slice_general[T: allocators.GeneralAllocator](ac: T, s: str.String, start: i64, end: i64) str.String

find

pub fn find(s: str.String, sub: str.String) option[i64]

Find first occurrence of sub in s — returns some(index) or none

contains

pub fn contains(s: str.String, sub: str.String) bool

Returns true if sub appears anywhere in s

to_upper

pub fn to_upper(s: str.String) void = trust { ... }

Convert to uppercase in place

to_lower

pub fn to_lower(s: str.String) void = trust { ... }

Convert to lowercase in place

trim_left

pub fn trim_left(s: str.String) void = trust { ... }

Trim leading whitespace in place

trim_right

pub fn trim_right(s: str.String) void = trust { ... }

Trim trailing whitespace in place

trim

pub fn trim(s: str.String) void = trust { ... }

Trim leading and trailing whitespace in place

replace

pub fn replace(s: str.String, from: str.String, to: str.String) str.String = trust { ... }

Return a new str.String with all occurrences of from replaced by to

split

pub fn split[T: allocators.GeneralAllocator](ac: T, s: str.String, delim: str.String) result[ref void, ListAllocError]

Split s by delim, returns an opaque list of Strings allocated with the provided general allocator.

equals

pub fn equals(x: str.String, y: str.String) bool

Check if two strings are equal

trim_prefix

pub fn trim_prefix(s: str.String, prefix: str.String) str.String = trust { ... }

If s starts with prefix, return s without it, otherwise clone

trim_suffix

pub fn trim_suffix(s: str.String, suffix: str.String) str.String = trust { ... }

If s ends with suffix, return s without it, otherwise clone

starts_with

pub fn starts_with(s: str.String, prefix: str.String) bool

Check if s starts with prefix

ends_with

pub fn ends_with(s: str.String, suffix: str.String) bool

Check if s ends with suffix