pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize T: typehaystack: []const Tneedle: []const T1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize {
if (needle.len == 1) return countScalar(T, haystack, needle[0]);
assert(needle.len > 0);
var i: usize = 0;
var found: usize = 0;
while (findPos(T, haystack, i, needle)) |idx| {
i = idx + needle.len;
found += 1;
}
return found;
}
Returns the number of needles inside the haystack needle.len must be > 0 does not count overlapping needles