| author | |
| committer | |
| log | a6e8db462de2eab7636ee26ed4c1f8b238c55f96 |
| tree | 9878afdf823d6f890d740b4f838e889af8fc5018 |
| parent | f2c237f7944dfcd72492a1123f5860088c64726c |
see zig/pull/241041 files changed, 4 insertions(+), 6 deletions(-)
src/countScalar.zig+4-6| ... | ... | @@ -3,14 +3,12 @@ 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; | |
| 7 | 6 | var found: usize = 0; |
| 8 | ||
| 9 | while (std.mem.indexOfScalarPos(T, haystack, i, needle)) |idx| { | |
| 10 | i = idx + 1; | |
| 11 | found += 1; | |
| 7 | for (haystack) |item| { | |
| 8 | if (item == needle) { | |
| 9 | found += 1; | |
| 10 | } | |
| 12 | 11 | } |
| 13 | ||
| 14 | 12 | return found; |
| 15 | 13 | } |
| 16 | 14 |