]> git.ozlabs.org Git - ccan/blobdiff - ccan/str/str.h
str: strcount
[ccan] / ccan / str / str.h
index 8cfd7f29a5626cb7ca3a3196e545f35c3a74c0be..770a40fd1f4dca3fe599cfdee109fe9fa581b861 100644 (file)
@@ -55,4 +55,16 @@ 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
 #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:
+ *     #define PRINT_COND_IF_FALSE(cond) \
+ *             ((cond) || printf("%s is false!", stringify(cond)))
+ */
+size_t strcount(const char *haystack, const char *needle);
+
 #endif /* CCAN_STR_H */
 #endif /* CCAN_STR_H */