Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

count

Public Function
std.mem.count
pub fn count(comptime T: type, haystack: []const T, needle: []const T) usize

Returns the number of needles inside the haystack needle.len must be > 0 does not count overlapping needles

Params

  • T: type
  • haystack: []const T
  • needle: []const T

File

mem.zig:1646
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
pub 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;
}