Skip to content

String

Source: std/string.mw.

C strings are plain *u8 values ending in a zero byte. String is the growable owned variant.

struct String {
data: *u8;
len: i64;
cap: i64;
}
fn str_len(s: *u8) -> i64
fn str_eq(s1: *u8, s2: *u8) -> i8
fn is_digit(c: u8) -> i8
fn is_alpha(c: u8) -> i8
fn is_space(c: u8) -> i8
fn string_new(initial_cap: i64) -> ^String
fn string_from(raw_str: *u8) -> *String
fn string_push_char(s: *String, c: u8)
fn string_push_str(s: *String, raw_str: *u8)
fn string_free(s: ^String)
fn string_destroy(s: *String)
fn string_into_data(s: ^String) -> *u8

A ^String frees itself at the end of its scope. string_free drops it at once, string_destroy frees one held by a plain pointer. string_into_data gives the buffer to the caller (free it with dealloc) and frees only the String.

fn string_eq(a: *String, b: *String) -> i32
fn string_cmp(a: *String, b: *String) -> i32