pub fn absorbSentinel(slice: anytype) AbsorbSentinel(@TypeOf(slice)) slice4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766pub 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,
}
}
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.