1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn sliceTo(comptime T: type, haystack: []const T, needle: T) []const T {
6 if (std.mem.indexOfScalar(T, haystack, needle)) |index| {
7 return haystack[0..index];
8 }
9 return haystack;
10}
11
12test {
13 try std.testing.expect(std.mem.eql(u8, sliceTo(u8, "abcdefgh", 'd'), "abc"));
14}
15test {
16 try std.testing.expect(std.mem.eql(u8, sliceTo(u8, "abcdefgh", 'r'), "abcdefgh"));
17}
18test {
19 try std.testing.expect(std.mem.eql(u8, sliceTo(u8, "abcdefgh", 'a'), ""));
20}