Skip to content

std.mem

slice helpers; generics take the element type first: copy(u8, dst, src)

pub eql :: fn($T: type, self: []const T, b: []const T) -> bool
pub starts_with :: fn($T: type, self: []const T, prefix: []const T) -> bool
pub ends_with :: fn($T: type, self: []const T, suffix: []const T) -> bool
pub copy :: fn($T: type, self: []T, source: []const T) -> usize

copies min(len) elements, returns the count; must not overlap

pub fill :: fn($T: type, self: []T, value: T)
pub swap :: fn($T: type, self: []T, i: usize, j: usize)
pub reverse :: fn($T: type, self: []T)
pub index_of :: fn($T: type, self: []const T, needle: T) -> ?usize
pub contains :: fn($T: type, self: []const T, needle: T) -> bool
pub eql_bytes :: fn(self: []const u8, b: []const u8) -> bool
pub compare_bytes :: fn(self: []const u8, b: []const u8) -> i32

byte order: -1, 0 or 1; a prefix sorts first

pub less_bytes :: fn(self: []const u8, b: []const u8) -> bool

byte-order less-than; for sort::by

pub copy_bytes :: fn(self: []u8, source: []const u8) -> usize
pub zero :: fn(self: []u8)
pub index_of_slice :: fn($T: type, self: []const T, needle: []const T) -> ?usize

first start of needle in self, or null; empty needle -> 0

pub last_index_of :: fn($T: type, self: []const T, needle: T) -> ?usize
pub last_index_of_slice :: fn($T: type, self: []const T, needle: []const T) -> ?usize
pub count :: fn($T: type, self: []const T, needle: []const T) -> usize

non-overlapping occurrences; empty needle -> 0

pub trim_left :: fn($T: type, self: []const T, set: []const T) -> []const T

drops leading elements in set

pub trim_right :: fn($T: type, self: []const T, set: []const T) -> []const T

drops trailing elements in set

pub trim :: fn($T: type, self: []const T, set: []const T) -> []const T

both ends

pub Split :: struct($T: type) {
rest: []const T,
sep: []const T,
done: bool,
}

parts between separators, empty ones kept: “a,,b” -> “a”, “”, “b”

pub next :: fn(self: *Self) -> ?[]const T
pub remaining :: fn(self: *Self) -> []const T

the unsplit rest

pub split :: fn($T: type, self: []const T, sep: []const T) -> Split(T)

empty sep gives self as one part

pub Tokens :: struct($T: type) {
rest: []const T,
delims: []const T,
}

parts between runs of delimiters, empty ones skipped

pub next :: fn(self: *Self) -> ?[]const T
pub tokenize :: fn($T: type, self: []const T, delims: []const T) -> Tokens(T)

any element of delims splits

pub Halves :: struct($T: type) {
before: []const T,
after: []const T,
}

result of split_once

pub split_once :: fn($T: type, self: []const T, sep: []const T) -> ?Halves(T)

before and after the first sep, or null if absent