Function containsAtLeastScalar [src]

Returns true if the haystack contains expected_count or more needles See also: containsAtLeast

Prototype

pub fn containsAtLeastScalar(comptime T: type, haystack: []const T, expected_count: usize, needle: T) bool

Parameters

T: typehaystack: []const Texpected_count: usizeneedle: T

Example

test containsAtLeastScalar { try testing.expect(containsAtLeastScalar(u8, "aa", 0, 'a')); try testing.expect(containsAtLeastScalar(u8, "aa", 1, 'a')); try testing.expect(containsAtLeastScalar(u8, "aa", 2, 'a')); try testing.expect(!containsAtLeastScalar(u8, "aa", 3, 'a')); try testing.expect(containsAtLeastScalar(u8, "adadda", 3, 'd')); try testing.expect(!containsAtLeastScalar(u8, "adadda", 4, 'd')); }

Source

pub fn containsAtLeastScalar(comptime T: type, haystack: []const T, expected_count: usize, needle: T) bool { if (expected_count == 0) return true; var found: usize = 0; for (haystack) |item| { if (item == needle) { found += 1; if (found == expected_count) return true; } } return false; }