| 1 | const std = @import("std"); |
| 2 | const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); |
| 4 | |
| 5 | pub fn indexOfSlice(comptime T: type, haystack: []const []const T, needle: []const T) ?usize { |
| 6 | for (haystack, 0..) |item, i| { |
| 7 | if (std.mem.eql(u8, item, needle)) { |
| 8 | return i; |
| 9 | } |
| 10 | } |
| 11 | return null; |
| 12 | } |
| 13 | |
| 14 | test { |
| 15 | try std.testing.expect(indexOfSlice(u8, &.{ "a", "b", "c", "d" }, "b") == 1); |
| 16 | } |
| 17 | test { |
| 18 | try std.testing.expect(indexOfSlice(u8, &.{}, "b") == null); |
| 19 | } |