Function containsAtLeast [src]
Returns true if the haystack contains expected_count or more needles
needle.len must be > 0
does not count overlapping needles
See also: containsAtLeastScalar
Prototype
pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: usize, needle: []const T) bool
Parameters
T: type
haystack: []const T
expected_count: usize
needle: []const T
Example
test containsAtLeast {
try testing.expect(containsAtLeast(u8, "aa", 0, "a"));
try testing.expect(containsAtLeast(u8, "aa", 1, "a"));
try testing.expect(containsAtLeast(u8, "aa", 2, "a"));
try testing.expect(!containsAtLeast(u8, "aa", 3, "a"));
try testing.expect(containsAtLeast(u8, "radaradar", 1, "radar"));
try testing.expect(!containsAtLeast(u8, "radaradar", 2, "radar"));
try testing.expect(containsAtLeast(u8, "radarradaradarradar", 3, "radar"));
try testing.expect(!containsAtLeast(u8, "radarradaradarradar", 4, "radar"));
try testing.expect(containsAtLeast(u8, " radar radar ", 2, "radar"));
try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar"));
}
Source
pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: usize, needle: []const T) bool {
assert(needle.len > 0);
if (expected_count == 0) return true;
var i: usize = 0;
var found: usize = 0;
while (indexOfPos(T, haystack, i, needle)) |idx| {
i = idx + needle.len;
found += 1;
if (found == expected_count) return true;
}
return false;
}