| author | |
| committer | |
| log | 4d76a93f5ec7c354beb7ed237a94d17bc0c8581a |
| tree | c5241400d5d002782617343b788f7e06b16b4b21 |
| parent | 7f5f1857e06fa23123d566cc4468133b57ed532e |
2 files changed, 20 insertions(+), 0 deletions(-)
src/indexOfSlice.zig created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 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 | } |
src/lib.zig+1| ... | ... | @@ -99,3 +99,4 @@ pub usingnamespace @import("./isZigString.zig"); |
| 99 | 99 | pub usingnamespace @import("./isIndexable.zig"); |
| 100 | 100 | pub usingnamespace @import("./isSlice.zig"); |
| 101 | 101 | pub usingnamespace @import("./matchesNone.zig"); |
| 102 | pub usingnamespace @import("./indexOfSlice.zig"); |