| ... | ... | @@ -1691,7 +1691,7 @@ test countScalar { |
| 1691 | 1691 | // |
| 1692 | 1692 | /// See also: `containsAtLeastScalar` |
| 1693 | 1693 | pub fn containsAtLeast(comptime T: type, haystack: []const T, expected_count: usize, needle: []const T) bool { |
| 1694 | | if (needle.len == 1) return containsAtLeastScalar(T, haystack, expected_count, needle[0]); |
| 1694 | if (needle.len == 1) return containsAtLeastScalar(T, haystack, needle[0], expected_count); |
| 1695 | 1695 | assert(needle.len > 0); |
| 1696 | 1696 | if (expected_count == 0) return true; |
| 1697 | 1697 | |
| ... | ... | @@ -1722,17 +1722,12 @@ test containsAtLeast { |
| 1722 | 1722 | try testing.expect(!containsAtLeast(u8, " radar radar ", 3, "radar")); |
| 1723 | 1723 | } |
| 1724 | 1724 | |
| 1725 | | /// Deprecated in favor of `containsAtLeastScalar2`. |
| 1726 | | pub fn containsAtLeastScalar(comptime T: type, list: []const T, minimum: usize, element: T) bool { |
| 1727 | | return containsAtLeastScalar2(T, list, element, minimum); |
| 1728 | | } |
| 1729 | | |
| 1730 | 1725 | /// Returns true if `element` appears at least `minimum` number of times in `list`. |
| 1731 | 1726 | // |
| 1732 | 1727 | /// Related: |
| 1733 | 1728 | /// * `containsAtLeast` |
| 1734 | 1729 | /// * `countScalar` |
| 1735 | | pub fn containsAtLeastScalar2(comptime T: type, list: []const T, element: T, minimum: usize) bool { |
| 1730 | pub fn containsAtLeastScalar(comptime T: type, list: []const T, element: T, minimum: usize) bool { |
| 1736 | 1731 | const n = list.len; |
| 1737 | 1732 | var i: usize = 0; |
| 1738 | 1733 | var found: usize = 0; |
| ... | ... | @@ -1760,14 +1755,14 @@ pub fn containsAtLeastScalar2(comptime T: type, list: []const T, element: T, min |
| 1760 | 1755 | return false; |
| 1761 | 1756 | } |
| 1762 | 1757 | |
| 1763 | | test containsAtLeastScalar2 { |
| 1764 | | try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 0)); |
| 1765 | | try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 1)); |
| 1766 | | try testing.expect(containsAtLeastScalar2(u8, "aa", 'a', 2)); |
| 1767 | | try testing.expect(!containsAtLeastScalar2(u8, "aa", 'a', 3)); |
| 1758 | test containsAtLeastScalar { |
| 1759 | try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 0)); |
| 1760 | try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 1)); |
| 1761 | try testing.expect(containsAtLeastScalar(u8, "aa", 'a', 2)); |
| 1762 | try testing.expect(!containsAtLeastScalar(u8, "aa", 'a', 3)); |
| 1768 | 1763 | |
| 1769 | | try testing.expect(containsAtLeastScalar2(u8, "adadda", 'd', 3)); |
| 1770 | | try testing.expect(!containsAtLeastScalar2(u8, "adadda", 'd', 4)); |
| 1764 | try testing.expect(containsAtLeastScalar(u8, "adadda", 'd', 3)); |
| 1765 | try testing.expect(!containsAtLeastScalar(u8, "adadda", 'd', 4)); |
| 1771 | 1766 | } |
| 1772 | 1767 | |
| 1773 | 1768 | /// Reads an integer from memory with size equal to bytes.len. |