X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fstr%2Fstr.h;h=bf858f13b69cb1f671a895450004f36a6ad361cd;hp=8cfd7f29a5626cb7ca3a3196e545f35c3a74c0be;hb=1dcd3ad51bbeb4ba8048b08d62278df8e428031a;hpb=1fe7f55b1efc5deefb20815a03b56c8ef0f6dc53 diff --git a/ccan/str/str.h b/ccan/str/str.h index 8cfd7f29..bf858f13 100644 --- a/ccan/str/str.h +++ b/ccan/str/str.h @@ -55,4 +55,18 @@ static inline bool strends(const char *str, const char *postfix) #define stringify(expr) stringify_1(expr) /* Double-indirection required to stringify expansions */ #define stringify_1(expr) #expr + +/** + * strcount - Count number of (non-overlapping) occurrences of a substring. + * @haystack: a C string + * @needle: a substring + * + * Example: + * int i; + * i = strcount("aaa aaa", "a"); // i = 6; + * i = strcount("aaa aaa", "ab"); // i = 0; + * i = strcount("aaa aaa", "aa"); // i = 2; + */ +size_t strcount(const char *haystack, const char *needle); + #endif /* CCAN_STR_H */