| ... | @@ -3,13 +3,14 @@ const string = []const u8; | ... | @@ -3,13 +3,14 @@ const string = []const u8; |
| 3 | const extras = @import("./lib.zig"); | 3 | const extras = @import("./lib.zig"); |
| 4 | | 4 | |
| 5 | pub fn countScalar(comptime T: type, haystack: []const T, needle: T) usize { | 5 | pub fn countScalar(comptime T: type, haystack: []const T, needle: T) usize { |
| | 6 | var i: usize = 0; |
| 6 | var found: usize = 0; | 7 | var found: usize = 0; |
| 7 | | 8 | |
| 8 | for (haystack) |item| { | 9 | while (std.mem.indexOfScalarPos(T, haystack, i, needle)) |idx| { |
| 9 | if (item == needle) { | 10 | i = idx + 1; |
| 10 | found += 1; | 11 | found += 1; |
| 11 | } | | |
| 12 | } | 12 | } |
| | 13 | |
| 13 | return found; | 14 | return found; |
| 14 | } | 15 | } |
| 15 | | 16 | |