Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

absorbSentinel

Public Function
std.mem.absorbSentinel
pub fn absorbSentinel(slice: anytype) AbsorbSentinel(@TypeOf(slice))

If the provided slice is not sentinel terminated, do nothing and return that slice. If it is sentinel-terminated, return a non-sentinel-terminated slice with the length increased by one to include the absorbed sentinel element.

Params

  • slice

File

mem.zig:4746
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
pub fn absorbSentinel(slice: anytype) AbsorbSentinel(@TypeOf(slice)) {
    const info = @typeInfo(@TypeOf(slice)).pointer;
    switch (info.size) {
        .slice => {
            if (info.sentinel_ptr == null) {
                return slice;
            } else {
                return slice.ptr[0 .. slice.len + 1];
            }
        },
        .one => {
            const child_info = @typeInfo(info.child).array;
            if (child_info.sentinel_ptr == null) {
                return slice;
            } else {
                return slice[0 .. child_info.len + 1];
            }
        },
        else => unreachable,
    }
}