string/cstr

sourcestring/cstr.sx

alloc_in

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

alloc_substr_in

private
fn alloc_substr_in[T: allocators.Allocator](ac: T, src: ref u8, start: i64, len: i64) ref u8

cmp

pub fn cmp(a: ref u8, b: ref u8) i64

Compare two raw strings.

eql

pub fn eql(a: ref u8, b: ref u8) bool

Compare two null-terminated C strings for equality.

Null is tolerated: two null pointers compare equal, while a null pointer never equals a non-null str.

len

pub fn len(s: ref u8) i64

Length of a raw u8 pointer

starts_with

pub fn starts_with(s: ref u8, prefix: ref u8) bool

Returns true if s starts with prefix

ends_with

pub fn ends_with(s: ref u8, suffix: ref u8) bool

contains

pub fn contains(haystack: ref u8, needle: ref u8) bool = trust { ... }

Returns true when needle occurs anywhere in haystack.

concat

pub fn concat(a: ref u8, b: ref u8) ref u8 = trust { ... }

Concat raw u8 pointers — returns a new heap-allocated ref u8

byte_at

pub fn byte_at(s: ref u8, i: i64) option[u8]

Get byte at index i from raw u8 pointer, returns none if out of bounds

trim_prefix

pub fn trim_prefix[T: allocators.Allocator](ac: T, s: ref u8, prefix: ref u8) ref u8

If s starts with prefix, return a new ref u8 without it, otherwise clone.

trim_suffix

pub fn trim_suffix[T: allocators.Allocator](ac: T, s: ref u8, suffix: ref u8) ref u8

If s ends with suffix, return a new ref u8 without it, otherwise clone.

substr

pub fn substr(src: ref u8, start: i64, len: i64) ref u8 = trust { ... }

Return a new ref u8 containing the substring of src starting at start with length len.

copy

pub fn copy(dst: ref u8, dst_off: i64, src: ref u8) void = trust { ... }

Copy len bytes from src to dst, starting at offset dst_off in dst. The result is NOT null-terminated beyond what was already there.