| author | |
| committer | |
| log | 27da3db4b150bbd563d800e369b394c5650dd4f2 |
| tree | 8f768fafed1a765a3f4e4b86f29d6a41db4e5db4 |
| parent | 4f8933255778838a5f9a34cade2942e9aeae8415 |
2 files changed, 31 insertions(+), 0 deletions(-)
src/lib.zig+1| ... | @@ -98,3 +98,4 @@ pub usingnamespace @import("./FlippedInt.zig"); | ... | @@ -98,3 +98,4 @@ pub usingnamespace @import("./FlippedInt.zig"); |
| 98 | pub usingnamespace @import("./isZigString.zig"); | 98 | pub usingnamespace @import("./isZigString.zig"); |
| 99 | pub usingnamespace @import("./isIndexable.zig"); | 99 | pub usingnamespace @import("./isIndexable.zig"); |
| 100 | pub usingnamespace @import("./isSlice.zig"); | 100 | pub usingnamespace @import("./isSlice.zig"); |
| 101 | pub usingnamespace @import("./matchesNone.zig"); |
src/matchesNone.zig created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const string = []const u8; | ||
| 3 | const extras = @import("./lib.zig"); | ||
| 4 | |||
| 5 | pub fn matchesNone(comptime T: type, haystack: []const T, comptime needle: fn (T) bool) bool { | ||
| 6 | for (haystack) |c| { | ||
| 7 | if (needle(c)) { | ||
| 8 | return false; | ||
| 9 | } | ||
| 10 | } | ||
| 11 | return true; | ||
| 12 | } | ||
| 13 | |||
| 14 | test { | ||
| 15 | const S = struct { | ||
| 16 | fn needle(item: u8) bool { | ||
| 17 | return item > 8; | ||
| 18 | } | ||
| 19 | }; | ||
| 20 | try std.testing.expect(matchesNone(u8, &.{ 0, 1, 2, 3, 4, 5 }, S.needle)); | ||
| 21 | } | ||
| 22 | |||
| 23 | test { | ||
| 24 | const S = struct { | ||
| 25 | fn needle(item: u8) bool { | ||
| 26 | return item == 4; | ||
| 27 | } | ||
| 28 | }; | ||
| 29 | try std.testing.expect(!matchesNone(u8, &.{ 0, 1, 2, 3, 4, 5 }, S.needle)); | ||
| 30 | } | ||