Text
Source: std/text.mw.
Text utilities on NUL-terminated byte strings (*u8) and on String.
Functions
Section titled “Functions”is_upper
Section titled “is_upper”fn is_upper(c: u8) -> boolis_lower
Section titled “is_lower”fn is_lower(c: u8) -> boolis_alnum
Section titled “is_alnum”fn is_alnum(c: u8) -> boolis_hex_digit
Section titled “is_hex_digit”fn is_hex_digit(c: u8) -> boolto_lower
Section titled “to_lower”fn to_lower(c: u8) -> u8to_upper
Section titled “to_upper”fn to_upper(c: u8) -> u8hex_value
Section titled “hex_value”fn hex_value(c: u8) -> i64Value of a hexadecimal digit, or -1.
str_cmp
Section titled “str_cmp”fn str_cmp(a: *u8, b: *u8) -> i32Lexicographic comparison on bytes: negative, zero or positive.
str_starts_with
Section titled “str_starts_with”fn str_starts_with(s: *u8, prefix: *u8) -> boolstr_ends_with
Section titled “str_ends_with”fn str_ends_with(s: *u8, suffix: *u8) -> boolstr_find_char
Section titled “str_find_char”fn str_find_char(s: *u8, c: u8) -> i64Index of the first occurrence of c, or -1.
str_rfind_char
Section titled “str_rfind_char”fn str_rfind_char(s: *u8, c: u8) -> i64str_find
Section titled “str_find”fn str_find(hay: *u8, needle: *u8) -> i64Index of the first occurrence of needle in hay, or -1.
str_dup
Section titled “str_dup”fn str_dup(s: *u8) -> *u8Copy into freshly allocated memory (free it with dealloc).
str_dup_n
Section titled “str_dup_n”fn str_dup_n(s: *u8, n: i64) -> *u8str_concat
Section titled “str_concat”fn str_concat(a: *u8, b: *u8) -> *u8str_to_lower_in_place
Section titled “str_to_lower_in_place”fn str_to_lower_in_place(s: *u8)str_to_upper_in_place
Section titled “str_to_upper_in_place”fn str_to_upper_in_place(s: *u8)str_eq_nocase
Section titled “str_eq_nocase”fn str_eq_nocase(a: *u8, b: *u8) -> boolCase-insensitive (ASCII) equality.
parse_i64
Section titled “parse_i64”fn parse_i64(s: *u8, out: *i64) -> boolParses an optionally signed decimal integer; the whole string must be used.
parse_u64
Section titled “parse_u64”fn parse_u64(s: *u8, base: i64, out: *u64) -> boolparse_f64
Section titled “parse_f64”fn parse_f64(s: *u8, out: *f64) -> boolParses decimal floats such as -12.5, .5, 3., 1e-9, 2.5E+3. The whole string must be used. Correctly rounded for ordinary inputs (up to 19 significant digits and exponents within +-22), a few ulps off beyond that.
str_split
Section titled “str_split”fn str_split(s: *u8, sep: u8) -> *VecPtrSplits on a separator byte. Returns a vector of freshly allocated C strings (free each with dealloc, then the vector with vec_ptr_free).
str_trim
Section titled “str_trim”fn str_trim(s: *u8) -> *u8Trims ASCII whitespace from both ends; returns a new C string.
string_push_i64
Section titled “string_push_i64”fn string_push_i64(s: *String, n: i64)string_push_u64
Section titled “string_push_u64”fn string_push_u64(s: *String, n: u64)string_push_hex
Section titled “string_push_hex”fn string_push_hex(s: *String, n: u64)string_push_f64
Section titled “string_push_f64”fn string_push_f64(s: *String, x: f64, decimals: i64)string_push_bytes
Section titled “string_push_bytes”fn string_push_bytes(s: *String, data: *u8, len: i64)Appends len raw bytes (which may contain NULs).
string_clear
Section titled “string_clear”fn string_clear(s: *String)string_dup_cstr
Section titled “string_dup_cstr”fn string_dup_cstr(s: *String) -> *u8