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