Functions
fn alignAllocLen(full_len: usize, alloc_len: usize, len_align: u29) usize
An allocator helper function. Adjusts an allocation length satisfy
len_align
….An allocator helper function. Adjusts an allocation length satisfy
len_align
.full_len
should be the full capacity of the allocation which may be greater than thelen
that was requested. This function should only be used by allocators that are unaffected bylen_align
.fn alignBackward(comptime T: type, addr: T, alignment: T) T
Round an address down to the previous (or current) aligned address. The alignme…
Round an address down to the previous (or current) aligned address. The alignment must be a power of 2 and greater than 0.
fn alignBackwardAnyAlign(i: usize, alignment: usize) usize
Round an address down to the previous (or current) aligned address. Unlike `ali…
Round an address down to the previous (or current) aligned address. Unlike
alignBackward
,alignment
can be any positive number, not just a power of 2.fn alignForward(comptime T: type, addr: T, alignment: T) T
Round an address up to the next (or current) aligned address. The alignment mus…
Round an address up to the next (or current) aligned address. The alignment must be a power of 2 and greater than 0. Asserts that rounding up the address does not cause integer overflow.
fn alignInBytes(bytes: []u8, comptime new_alignment: usize) ?[]align(new_alignment) u8
Returns the largest slice in the given bytes that conforms to the new alignment,…
Returns the largest slice in the given bytes that conforms to the new alignment, or
null
if the given bytes contain no conforming address.fn alignInSlice(slice: anytype, comptime new_alignment: usize) ?AlignedSlice(@TypeOf(slice), new_alignment)
Returns the largest sub-slice within the given slice that conforms to the new al…
Returns the largest sub-slice within the given slice that conforms to the new alignment, or
null
if the given slice contains no conforming address.fn alignPointer(ptr: anytype, align_to: usize) ?@TypeOf(ptr)
Aligns a given pointer value to a specified alignment factor. Returns an aligne…
Aligns a given pointer value to a specified alignment factor. Returns an aligned pointer or null if one of the following conditions is met:
- The aligned pointer would not fit the address space,
- The delta required to align the pointer is not a multiple of the pointee’s type.
fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize
Returns the number of elements that, if added to the given pointer, align it to…
Returns the number of elements that, if added to the given pointer, align it to a multiple of the given quantity, or
null
if one of the following conditions is met:- The aligned pointer would not fit the address space,
- The delta required to align the pointer is not a multiple of the pointee’s type.
fn allEqual(comptime T: type, slice: []const T, scalar: T) bool
Returns true if all elements in a slice are equal to the scalar value provided
fn asBytes(ptr: anytype) AsBytesReturnType(@TypeOf(ptr))
Given a pointer to a single item, returns a slice of the underlying bytes, prese…
Given a pointer to a single item, returns a slice of the underlying bytes, preserving pointer attributes.
fn byteSwapAllFields(comptime S: type, ptr: *S) void
Swap the byte order of all the members of the fields of a struct (Changing thei…
Swap the byte order of all the members of the fields of a struct (Changing their endianness)
fn bytesAsSlice(comptime T: type, bytes: anytype) BytesAsSliceReturnType(T, @TypeOf(bytes))
Given a slice of bytes, returns a slice of the specified type backed by those b…
Given a slice of bytes, returns a slice of the specified type backed by those bytes, preserving pointer attributes.
fn bytesAsValue(comptime T: type, bytes: anytype) BytesAsValueReturnType(T, @TypeOf(bytes))
Given a pointer to an array of bytes, returns a pointer to a value of the specif…
Given a pointer to an array of bytes, returns a pointer to a value of the specified type backed by those bytes, preserving pointer attributes.
fn bytesToValue(comptime T: type, bytes: anytype) T
Given a pointer to an array of bytes, returns a value of the specified type back…
Given a pointer to an array of bytes, returns a value of the specified type backed by a copy of those bytes.
fn collapseRepeats(comptime T: type, slice: []T, elem: T) []T
Collapse consecutive duplicate elements into one entry.
fn collapseRepeatsLen(comptime T: type, slice: []T, elem: T) usize
Collapse consecutive duplicate elements into one entry.
fn concat(allocator: Allocator, comptime T: type, slices: []const []const T) ![]T
Copies each T from slices into a new slice that exactly holds all the elements.
fn concatMaybeSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: ?T) ![]T
Copies each T from slices into a new slice that exactly holds all the elements a…
Copies each T from slices into a new slice that exactly holds all the elements as well as the sentinel.
fn concatWithSentinel(allocator: Allocator, comptime T: type, slices: []const []const T, comptime s: T) ![:s]T
Copies each T from slices into a new slice that exactly holds all the elements.
fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: usize, needle: []const T) bool
Returns true if the haystack contains expected_count or more needles needle.len…
Returns true if the haystack contains expected_count or more needles needle.len must be > 0 does not count overlapping needles
fn copy(comptime T: type, dest: []T, source: []const T) void
Deprecated: use
@memcpy
if the arguments do not overlap, orcopyForwards
if…Deprecated: use
@memcpy
if the arguments do not overlap, orcopyForwards
if they do.fn copyBackwards(comptime T: type, dest: []T, source: []const T) void
Copy all of source into dest at position 0. dest.len must be >= source.len. If…
Copy all of source into dest at position 0. dest.len must be >= source.len. If the slices overlap, dest.ptr must be >= src.ptr.
fn copyForwards(comptime T: type, dest: []T, source: []const T) void
Copy all of source into dest at position 0. dest.len must be >= source.len. If…
Copy all of source into dest at position 0. dest.len must be >= source.len. If the slices overlap, dest.ptr must be <= src.ptr.
fn count(comptime T: type, haystack: []const T, needle: []const T) usize
Returns the number of needles inside the haystack needle.len must be > 0 does …
Returns the number of needles inside the haystack needle.len must be > 0 does not count overlapping needles
fn doNotOptimizeAway(val: anytype) void
Force an evaluation of the expression; this tries to prevent the compiler from …
Force an evaluation of the expression; this tries to prevent the compiler from optimizing the computation away even if the result eventually gets discarded.
fn endsWith(comptime T: type, haystack: []const T, needle: []const T) bool
No documentation provided.
fn eql(comptime T: type, a: []const T, b: []const T) bool
Compares two slices and returns whether they are equal.
fn indexOf(comptime T: type, haystack: []const T, needle: []const T) ?usize
No documentation provided.
fn indexOfAny(comptime T: type, slice: []const T, values: []const T) ?usize
No documentation provided.
fn indexOfAnyPos(comptime T: type, slice: []const T, start_index: usize, values: []const T) ?usize
No documentation provided.
fn indexOfDiff(comptime T: type, a: []const T, b: []const T) ?usize
Compares two slices and returns the index of the first inequality. Returns null…
Compares two slices and returns the index of the first inequality. Returns null if the slices are equal.
fn indexOfMax(comptime T: type, slice: []const T) usize
Returns the index of the largest number in a slice. O(n).
slice
must not be e…Returns the index of the largest number in a slice. O(n).
slice
must not be empty.fn indexOfMin(comptime T: type, slice: []const T) usize
Returns the index of the smallest number in a slice. O(n).
slice
must not be …Returns the index of the smallest number in a slice. O(n).
slice
must not be empty.fn indexOfMinMax(comptime T: type, slice: []const T) struct { index_min: usize, index_max: usize, }
Finds the indices of the smallest and largest number in a slice. O(n). Returns …
Finds the indices of the smallest and largest number in a slice. O(n). Returns an anonymous struct with the fields
index_min
andindex_max
.slice
must not be empty.fn indexOfNone(comptime T: type, slice: []const T, values: []const T) ?usize
Find the first item in
slice
which is not contained invalues
.Find the first item in
slice
which is not contained invalues
.Comparable to
strspn
in the C standard library.fn indexOfNonePos(comptime T: type, slice: []const T, start_index: usize, values: []const T) ?usize
Find the first item in
slice[start_index..]
which is not contained invalues
…Find the first item in
slice[start_index..]
which is not contained invalues
. The returned index will be relative to the start ofslice
, and never less thanstart_index
.Comparable to
strspn
in the C standard library.fn indexOfPos(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize
Uses Boyer-Moore-Horspool algorithm on large inputs;
indexOfPosLinear
on small…Uses Boyer-Moore-Horspool algorithm on large inputs;
indexOfPosLinear
on small inputs.fn indexOfPosLinear(comptime T: type, haystack: []const T, start_index: usize, needle: []const T) ?usize
Consider using
indexOfPos
instead of this, which will automatically use a mor…Consider using
indexOfPos
instead of this, which will automatically use a more sophisticated algorithm on larger inputs.fn indexOfScalar(comptime T: type, slice: []const T, value: T) ?usize
Linear search for the index of a scalar value inside a slice.
fn indexOfScalarPos(comptime T: type, slice: []const T, start_index: usize, value: T) ?usize
No documentation provided.
fn indexOfSentinel(comptime Elem: type, comptime sentinel: Elem, ptr: [*:sentinel]const Elem) usize
No documentation provided.
fn isAligned(addr: usize, alignment: usize) bool
Given an address and an alignment, return true if the address is a multiple of t…
Given an address and an alignment, return true if the address is a multiple of the alignment The alignment must be a power of 2 and greater than 0.
fn isValidAlign(alignment: usize) bool
Returns whether
alignment
is a valid alignment, meaning it is a positive powe…Returns whether
alignment
is a valid alignment, meaning it is a positive power of 2.fn isValidAlignGeneric(comptime T: type, alignment: T) bool
Returns whether
alignment
is a valid alignment, meaning it is a positive powe…Returns whether
alignment
is a valid alignment, meaning it is a positive power of 2.fn join(allocator: Allocator, separator: []const u8, slices: []const []const u8) ![]u8
Naively combines a series of slices with a separator. Allocates memory for the …
Naively combines a series of slices with a separator. Allocates memory for the result, which must be freed by the caller.
fn joinZ(allocator: Allocator, separator: []const u8, slices: []const []const u8) ![:0]u8
Naively combines a series of slices with a separator and null terminator. Alloc…
Naively combines a series of slices with a separator and null terminator. Allocates memory for the result, which must be freed by the caller.
fn lastIndexOf(comptime T: type, haystack: []const T, needle: []const T) ?usize
Find the index in a slice of a sub-slice, searching from the end backwards. To …
Find the index in a slice of a sub-slice, searching from the end backwards. To start looking at a different index, slice the haystack first. Uses the Reverse Boyer-Moore-Horspool algorithm on large inputs;
lastIndexOfLinear
on small inputs.fn lastIndexOfAny(comptime T: type, slice: []const T, values: []const T) ?usize
No documentation provided.
fn lastIndexOfLinear(comptime T: type, haystack: []const T, needle: []const T) ?usize
Find the index in a slice of a sub-slice, searching from the end backwards. To …
Find the index in a slice of a sub-slice, searching from the end backwards. To start looking at a different index, slice the haystack first. Consider using
lastIndexOf
instead of this, which will automatically use a more sophisticated algorithm on larger inputs.fn lastIndexOfNone(comptime T: type, slice: []const T, values: []const T) ?usize
Find the last item in
slice
which is not contained invalues
.Find the last item in
slice
which is not contained invalues
.Like
strspn
in the C standard library, but searches from the end.fn lastIndexOfScalar(comptime T: type, slice: []const T, value: T) ?usize
Linear search for the last index of a scalar value inside a slice.
fn len(value: anytype) usize
Takes a sentinel-terminated pointer and iterates over the memory to find the se…
Takes a sentinel-terminated pointer and iterates over the memory to find the sentinel and determine the length.
[*c]
pointers are assumed to be non-null and 0-terminated.fn lessThan(comptime T: type, lhs: []const T, rhs: []const T) bool
Returns true if lhs < rhs, false otherwise
fn max(comptime T: type, slice: []const T) T
Returns the largest number in a slice. O(n).
slice
must not be empty.fn min(comptime T: type, slice: []const T) T
Returns the smallest number in a slice. O(n).
slice
must not be empty.fn nativeTo(comptime T: type, x: T, desired_endianness: Endian) T
Converts an integer which has host endianness to the desired endianness.
fn nativeToBig(comptime T: type, x: T) T
Converts an integer which has host endianness to big endian.
fn nativeToLittle(comptime T: type, x: T) T
Converts an integer which has host endianness to little endian.
fn order(comptime T: type, lhs: []const T, rhs: []const T) math.Order
Compares two slices of numbers lexicographically. O(n).
fn orderZ(comptime T: type, lhs: [*:0]const T, rhs: [*:0]const T) math.Order
Compares two many-item pointers with NUL-termination lexicographically.
fn readInt(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8, endian: Endian) T
Reads an integer from memory with bit count specified by T. The bit count of T …
Reads an integer from memory with bit count specified by T. The bit count of T must be evenly divisible by 8. This function cannot fail and cannot cause undefined behavior.
fn readIntForeign(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T
Reads an integer from memory with bit count specified by T. The bit count of T …
Reads an integer from memory with bit count specified by T. The bit count of T must be evenly divisible by 8. This function cannot fail and cannot cause undefined behavior. Assumes the endianness of memory is foreign, so it must byte-swap.
fn readIntNative(comptime T: type, bytes: *const [@divExact(@typeInfo(T).Int.bits, 8)]u8) T
Reads an integer from memory with bit count specified by T. The bit count of T …
Reads an integer from memory with bit count specified by T. The bit count of T must be evenly divisible by 8. This function cannot fail and cannot cause undefined behavior. Assumes the endianness of memory is native. This means the function can simply pointer cast memory.
fn readIntSlice(comptime T: type, bytes: []const u8, endian: Endian) T
Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting …
Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0 and ignores extra bytes. The bit count of T must be evenly divisible by 8.
fn readIntSliceForeign(comptime T: type, bytes: []const u8) T
Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting …
Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0 and ignores extra bytes. The bit count of T must be evenly divisible by 8. Assumes the endianness of memory is foreign, so it must byte-swap.
fn readIntSliceNative(comptime T: type, bytes: []const u8) T
Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting …
Asserts that bytes.len >= @typeInfo(T).Int.bits / 8. Reads the integer starting from index 0 and ignores extra bytes. The bit count of T must be evenly divisible by 8. Assumes the endianness of memory is native. This means the function can simply pointer cast memory.
fn readPackedInt(comptime T: type, bytes: []const u8, bit_offset: usize, endian: Endian) T
Loads an integer from packed memory. Asserts that buffer contains at least bit_…
Loads an integer from packed memory. Asserts that buffer contains at least bit_offset + @bitSizeOf(T) bits.
Example: const T = packed struct(u16){ a: u3, b: u7, c: u6 }; var st = T{ .a = 1, .b = 2, .c = 4 }; const b_field = readPackedInt(u7, std.mem.asBytes(&st), @bitOffsetOf(T, “b”), builtin.cpu.arch.endian());
fn readVarInt(comptime ReturnType: type, bytes: []const u8, endian: Endian) ReturnType
Reads an integer from memory with size equal to bytes.len. T specifies the retu…
Reads an integer from memory with size equal to bytes.len. T specifies the return type, which must be large enough to store the result.
fn readVarPackedInt(comptime T: type, bytes: []const u8, bit_offset: usize, bit_count: usize, endian: std.builtin.Endian, signedness: std.builtin.Signedness) T
Loads an integer from packed memory with provided bit_count, bit_offset, and sig…
Loads an integer from packed memory with provided bit_count, bit_offset, and signedness. Asserts that T is large enough to store the read value.
Example: const T = packed struct(u16){ a: u3, b: u7, c: u6 }; var st = T{ .a = 1, .b = 2, .c = 4 }; const b_field = readVarPackedInt(u64, std.mem.asBytes(&st), @bitOffsetOf(T, “b”), 7, builtin.cpu.arch.endian(), .unsigned);
fn replace(comptime T: type, input: []const T, needle: []const T, replacement: []const T, output: []T) usize
Replace needle with replacement as many times as possible, writing to an output …
Replace needle with replacement as many times as possible, writing to an output buffer which is assumed to be of appropriate size. Use replacementSize to calculate an appropriate buffer size. The needle must not be empty. Returns the number of replacements made.
fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, needle: []const T, replacement: []const T) Allocator.Error![]T
Perform a replacement on an allocated buffer of pre-determined size. Caller must…
Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory.
fn replaceScalar(comptime T: type, slice: []T, needle: T, replacement: T) void
Replace all occurrences of
needle
withreplacement
.fn replacementSize(comptime T: type, input: []const T, needle: []const T, replacement: []const T) usize
Calculate the size needed in an output buffer to perform a replacement. The nee…
Calculate the size needed in an output buffer to perform a replacement. The needle must not be empty.
fn rotate(comptime T: type, items: []T, amount: usize) void
In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we r…
In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1) Assumes 0 <= amount <= items.len
fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice))
Given a slice, returns a slice of the underlying bytes, preserving pointer attri…
Given a slice, returns a slice of the underlying bytes, preserving pointer attributes.
fn sliceTo(ptr: anytype, comptime end: field_call) SliceTo(@TypeOf(ptr), end)
Takes an array, a pointer to an array, a sentinel-terminated pointer, or a slice…
Takes an array, a pointer to an array, a sentinel-terminated pointer, or a slice and iterates searching for the first occurrence of
end
, returning the scanned slice. Ifend
is not found, the full length of the array/slice/sentinel terminated pointer is returned. If the pointer type is sentinel terminated andend
matches that terminator, the resulting slice is also sentinel terminated. Pointer properties such as mutability and alignment are preserved. C pointers are assumed to be non-null.fn sort(comptime T: type, items: []T, context: anytype, comptime lessThanFn: fn (@TypeOf(context), T, T) bool) void
No documentation provided.
fn sortContext(a: usize, b: usize, context: anytype) void
TODO: currently this just calls
insertionSortContext
. The block sort implement…TODO: currently this just calls
insertionSortContext
. The block sort implementation in this file needs to be adapted to use the sort context.fn sortUnstable(comptime T: type, items: []T, context: anytype, comptime lessThanFn: fn (@TypeOf(context), T, T) bool) void
No documentation provided.
fn span(ptr: anytype) Span(@TypeOf(ptr))
Takes a sentinel-terminated pointer and returns a slice, iterating over the mem…
Takes a sentinel-terminated pointer and returns a slice, iterating over the memory to find the sentinel and determine the length. Pointer attributes such as const are preserved.
[*c]
pointers are assumed to be non-null and 0-terminated.fn split(comptime T: type, buffer: []const T, delimiter: []const T) SplitIterator(T, .sequence)
Deprecated: use
splitSequence
,splitAny
, orsplitScalar
fn splitAny(comptime T: type, buffer: []const T, delimiters: []const T) SplitIterator(T, .any)
Returns an iterator that iterates over the slices of
buffer
that are separate…Returns an iterator that iterates over the slices of
buffer
that are separated by any item indelimiters
.splitAny(u8, "abc,def||ghi", "|,")
will return slices for “abc”, “def”, “”, “ghi”, null, in that order.If none of
delimiters
exist in buffer, the iterator will returnbuffer
, null, in that order.See also:
splitSequence
,splitScalar
,splitBackwardsSequence
,splitBackwardsAny
,splitBackwardsScalar
,tokenizeAny
,tokenizeSequence
, andtokenizeScalar
.fn splitBackwards(comptime T: type, buffer: []const T, delimiter: []const T) SplitBackwardsIterator(T, .sequence)
Deprecated: use
splitBackwardsSequence
,splitBackwardsAny
, or `splitBackward…Deprecated: use
splitBackwardsSequence
,splitBackwardsAny
, orsplitBackwardsScalar
fn splitBackwardsAny(comptime T: type, buffer: []const T, delimiters: []const T) SplitBackwardsIterator(T, .any)
Returns an iterator that iterates backwards over the slices of
buffer
that ar…Returns an iterator that iterates backwards over the slices of
buffer
that are separated by any item indelimiters
.splitBackwardsAny(u8, "abc,def||ghi", "|,")
will return slices for “ghi”, “”, “def”, “abc”, null, in that order.If none of
delimiters
exist in buffer, the iterator will returnbuffer
, null, in that order.See also:
splitBackwardsSequence
,splitBackwardsScalar
,splitSequence
,splitAny
,splitScalar
,tokenizeAny
,tokenizeSequence
, andtokenizeScalar
.fn splitBackwardsScalar(comptime T: type, buffer: []const T, delimiter: T) SplitBackwardsIterator(T, .scalar)
Returns an iterator that iterates backwards over the slices of
buffer
that ar…Returns an iterator that iterates backwards over the slices of
buffer
that are separated bydelimiter
.splitBackwardsScalar(u8, "abc|def||ghi", '|')
will return slices for “ghi”, “”, “def”, “abc”, null, in that order.If
delimiter
does not exist in buffer, the iterator will returnbuffer
, null, in that order.See also:
splitBackwardsSequence
,splitBackwardsAny
,splitSequence
,splitAny
,splitScalar
,tokenizeAny
,tokenizeSequence
, andtokenizeScalar
.fn splitBackwardsSequence(comptime T: type, buffer: []const T, delimiter: []const T) SplitBackwardsIterator(T, .sequence)
Returns an iterator that iterates backwards over the slices of
buffer
that ar…Returns an iterator that iterates backwards over the slices of
buffer
that are separated by the sequence indelimiter
.splitBackwardsSequence(u8, "abc||def||||ghi", "||")
will return slices for “ghi”, “”, “def”, “abc”, null, in that order.If
delimiter
does not exist in buffer, the iterator will returnbuffer
, null, in that order. The delimiter length must not be zero.See also:
splitBackwardsAny
,splitBackwardsScalar
,splitSequence
,splitAny
,splitScalar
,tokenizeAny
,tokenizeSequence
, andtokenizeScalar
.fn splitScalar(comptime T: type, buffer: []const T, delimiter: T) SplitIterator(T, .scalar)
Returns an iterator that iterates over the slices of
buffer
that are separate…Returns an iterator that iterates over the slices of
buffer
that are separated bydelimiter
.splitScalar(u8, "abc|def||ghi", '|')
will return slices for “abc”, “def”, “”, “ghi”, null, in that order.If
delimiter
does not exist in buffer, the iterator will returnbuffer
, null, in that order.See also:
splitSequence
,splitAny
,splitBackwardsSequence
,splitBackwardsAny
,splitBackwardsScalar
,tokenizeAny
,tokenizeSequence
, andtokenizeScalar
.fn splitSequence(comptime T: type, buffer: []const T, delimiter: []const T) SplitIterator(T, .sequence)
Returns an iterator that iterates over the slices of
buffer
that are separate…Returns an iterator that iterates over the slices of
buffer
that are separated by the byte sequence indelimiter
.splitSequence(u8, "abc||def||||ghi", "||")
will return slices for “abc”, “def”, “”, “ghi”, null, in that order.If
delimiter
does not exist in buffer, the iterator will returnbuffer
, null, in that order. The delimiter length must not be zero.See also:
splitAny
,splitScalar
,splitBackwardsSequence
,splitBackwardsAny
,splitBackwardsScalar
,tokenizeAny
,tokenizeSequence
, andtokenizeScalar
.fn startsWith(comptime T: type, haystack: []const T, needle: []const T) bool
No documentation provided.
fn toBytes(value: anytype) [@sizeOf(@TypeOf(value))]u8
Given any value, returns a copy of its bytes in an array.
fn toNative(comptime T: type, x: T, endianness_of_x: Endian) T
Converts an integer from specified endianness to host endianness.
fn tokenize(comptime T: type, buffer: []const T, delimiters: []const T) TokenIterator(T, .any)
Deprecated: use
tokenizeAny
,tokenizeSequence
, ortokenizeScalar
fn tokenizeAny(comptime T: type, buffer: []const T, delimiters: []const T) TokenIterator(T, .any)
Returns an iterator that iterates over the slices of
buffer
that are not any …Returns an iterator that iterates over the slices of
buffer
that are not any of the items indelimiters
.tokenizeAny(u8, " abc|def || ghi ", " |")
will return slices for “abc”, “def”, “ghi”, null, in that order.If
buffer
is empty, the iterator will return null. If none ofdelimiters
exist in buffer, the iterator will returnbuffer
, null, in that order.See also:
tokenizeSequence
,tokenizeScalar
,splitSequence
,splitAny
,splitScalar
,splitBackwardsSequence
,splitBackwardsAny
, andsplitBackwardsScalar
fn tokenizeScalar(comptime T: type, buffer: []const T, delimiter: T) TokenIterator(T, .scalar)
Returns an iterator that iterates over the slices of
buffer
that are not `del…Returns an iterator that iterates over the slices of
buffer
that are notdelimiter
.tokenizeScalar(u8, " abc def ghi ", ' ')
will return slices for “abc”, “def”, “ghi”, null, in that order.If
buffer
is empty, the iterator will return null. Ifdelimiter
does not exist in buffer, the iterator will returnbuffer
, null, in that order.See also:
tokenizeAny
,tokenizeSequence
,splitSequence
,splitAny
, andsplitScalar
splitBackwardsSequence
,splitBackwardsAny
, andsplitBackwardsScalar
fn tokenizeSequence(comptime T: type, buffer: []const T, delimiter: []const T) TokenIterator(T, .sequence)
Returns an iterator that iterates over the slices of
buffer
that are not the …Returns an iterator that iterates over the slices of
buffer
that are not the sequence indelimiter
.tokenizeSequence(u8, "<>abc><def<><>ghi", "<>")
will return slices for “abc><def”, “ghi”, null, in that order.If
buffer
is empty, the iterator will return null. Ifdelimiter
does not exist in buffer, the iterator will returnbuffer
, null, in that order. The delimiter length must not be zero.See also:
tokenizeAny
,tokenizeScalar
,splitSequence
,splitAny
, andsplitScalar
splitBackwardsSequence
,splitBackwardsAny
, andsplitBackwardsScalar
fn trim(comptime T: type, slice: []const T, values_to_strip: []const T) []const T
Remove a set of values from the beginning and end of a slice.
fn trimLeft(comptime T: type, slice: []const T, values_to_strip: []const T) []const T
Remove a set of values from the beginning of a slice.
fn trimRight(comptime T: type, slice: []const T, values_to_strip: []const T) []const T
Remove a set of values from the end of a slice.
fn validationWrap(allocator: anytype) ValidationAllocator(@TypeOf(allocator))
No documentation provided.
fn window(comptime T: type, buffer: []const T, size: usize, advance: usize) WindowIterator(T)
Returns an iterator with a sliding window of slices for
buffer
. The sliding w…Returns an iterator with a sliding window of slices for
buffer
. The sliding window has lengthsize
and on every iteration moves forward byadvance
.Extract data for moving average with:
window(u8, "abcdefg", 3, 1)
will return slices “abc”, “bcd”, “cde”, “def”, “efg”, null, in that order.Chunk or split every N items with:
window(u8, "abcdefg", 3, 3)
will return slices “abc”, “def”, “g”, null, in that order.Pick every even index with:
window(u8, "abcdefg", 1, 2)
will return slices “a”, “c”, “e”, “g” null, in that order.The
size
andadvance
must be not be zero.fn writeInt(comptime T: type, buffer: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T, endian: Endian) void
Writes an integer to memory, storing it in twos-complement. This function alway…
Writes an integer to memory, storing it in twos-complement. This function always succeeds, has defined behavior for all inputs, but the integer bit width must be divisible by 8.
fn writeIntForeign(comptime T: type, buf: *[@divExact(@typeInfo(T).Int.bits, 8)]u8, value: T) void
Writes an integer to memory, storing it in twos-complement. This function alway…
Writes an integer to memory, storing it in twos-complement. This function always succeeds, has defined behavior for all inputs, but the integer bit width must be divisible by 8. This function stores in foreign endian, which means it does a @byteSwap first.
fn writeIntNative(comptime T: type, buf: *[@intCast(u16, (@typeInfo(T).Int.bits + 7) / 8)]u8, value: T) void
Writes an integer to memory, storing it in twos-complement. This function alway…
Writes an integer to memory, storing it in twos-complement. This function always succeeds, has defined behavior for all inputs, and accepts any integer bit width. This function stores in native endian, which means it is implemented as a simple memory store.
fn writeIntSlice(comptime T: type, buffer: []u8, value: T, endian: Endian) void
Writes a twos-complement integer to memory, with the specified endianness. Asse…
Writes a twos-complement integer to memory, with the specified endianness. Asserts that buf.len >= @typeInfo(T).Int.bits / 8. The bit count of T must be evenly divisible by 8. Any extra bytes in buffer not part of the integer are set to zero, with respect to endianness. To avoid the branch to check for extra buffer bytes, use writeInt instead.
fn writeIntSliceBig(comptime T: type, buffer: []u8, value: T) void
Writes a twos-complement big-endian integer to memory. Asserts that buffer.len …
Writes a twos-complement big-endian integer to memory. Asserts that buffer.len >= @typeInfo(T).Int.bits / 8. The bit count of T must be divisible by 8. Any extra bytes in buffer before writing the integer are set to zero. To avoid the branch to check for extra buffer bytes, use writeIntBig instead.
fn writeIntSliceLittle(comptime T: type, buffer: []u8, value: T) void
Writes a twos-complement little-endian integer to memory. Asserts that buf.len …
Writes a twos-complement little-endian integer to memory. Asserts that buf.len >= @typeInfo(T).Int.bits / 8. The bit count of T must be divisible by 8. Any extra bytes in buffer after writing the integer are set to zero. To avoid the branch to check for extra buffer bytes, use writeIntLittle instead.
fn writePackedInt(comptime T: type, bytes: []u8, bit_offset: usize, value: T, endian: Endian) void
Stores an integer to packed memory. Asserts that buffer contains at least bit_o…
Stores an integer to packed memory. Asserts that buffer contains at least bit_offset + @bitSizeOf(T) bits.
Example: const T = packed struct(u16){ a: u3, b: u7, c: u6 }; var st = T{ .a = 1, .b = 2, .c = 4 }; // st.b = 0x7f; writePackedInt(u7, std.mem.asBytes(&st), @bitOffsetOf(T, “b”), 0x7f, builtin.cpu.arch.endian());
fn writeVarPackedInt(bytes: []u8, bit_offset: usize, bit_count: usize, value: anytype, endian: std.builtin.Endian) void
Stores an integer to packed memory with provided bit_count, bit_offset, and sign…
Stores an integer to packed memory with provided bit_count, bit_offset, and signedness. If negative, the written value is sign-extended.
Example: const T = packed struct(u16){ a: u3, b: u7, c: u6 }; var st = T{ .a = 1, .b = 2, .c = 4 }; // st.b = 0x7f; var value: u64 = 0x7f; writeVarPackedInt(std.mem.asBytes(&st), @bitOffsetOf(T, “b”), 7, value, builtin.cpu.arch.endian());
fn zeroInit(comptime T: type, init: anytype) T
Initializes all fields of the struct with their default value, or zero values if…
Initializes all fields of the struct with their default value, or zero values if no default value is present. If the field is present in the provided initial values, it will have that value instead. Structs are initialized recursively.
fn zeroes(comptime T: type) T
Generally, Zig users are encouraged to explicitly initialize all fields of a str…
Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function. However, it is recognized that there are sometimes use cases for initializing all fields to a “zero” value. For example, when interfacing with a C API where this practice is more common and relied upon. If you are performing code review and see this function used, examine closely - it may be a code smell. Zero initializes the type. This can be used to zero-initialize any type for which it makes sense. Structs will be initialized recursively.
Values
alignBackwardGeneric | undefined | |
alignForwardGeneric | undefined | |
byte_size_in_bits | comptime_int | The standard library currently thoroughly depends on byte size being 8 bits. (… |
page_size | type | Compile time known minimum page size. https://github.com/ziglang/zig/issues/408… |
readIntBig | type | |
readIntLittle | type | |
readIntSliceBig | type | |
readIntSliceLittle | type | |
readPackedIntForeign | type | |
readPackedIntNative | type | |
set | undefined | |
writeIntBig | type | |
writeIntLittle | type | |
writeIntSliceForeign | type | |
writeIntSliceNative | type | |
writePackedIntForeign | type | |
writePackedIntNative | type |