pub fn sliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) SliceTo(@TypeOf(ptr), end) 974
975
976
977
978
979
980
981
982
983
984
985
986
987pub fn sliceTo(ptr: anytype, comptime end: std.meta.Elem(@TypeOf(ptr))) SliceTo(@TypeOf(ptr), end) {
if (@typeInfo(@TypeOf(ptr)) == .optional) {
const non_null = ptr orelse return null;
return sliceTo(non_null, end);
}
const Result = SliceTo(@TypeOf(ptr), end);
const length = lenSliceTo(ptr, end);
const ptr_info = @typeInfo(Result).pointer;
if (ptr_info.sentinel()) |s| {
return ptr[0..length :s];
} else {
return ptr[0..length];
}
}
Takes a pointer to an array, a many-item pointer, or a slice, and returns a slice of the items up to the first occurrence of
end. Ifendis not found, the resulting slice will include all items up to the input's length or sentinel. If the pointer type is unbounded (no length or sentinel),endwill be the sentinel for the resulting slice. If the pointer type is sentinel-terminated byend, the resulting slice will also be sentinel-terminated byend. Pointer properties such as mutability and alignment are preserved. C pointers are assumed to be non-null.