]> git.ozlabs.org Git - ccan/blobdiff - ccan/bytestring/bytestring.h
bytestring: Split bytestrings by a string delimiter
[ccan] / ccan / bytestring / bytestring.h
index 5a8d3cd896fb003704bada0f535d4e11c5354171..0d1c929e599564d92984c836b9f434b5195dbd1e 100644 (file)
@@ -276,4 +276,32 @@ struct bytestring bytestring_splitchrs_next(struct bytestring whole,
             (_s).ptr;                                         \
             (_s) = bytestring_splitchrs_next((_w), (_delim), (_s)))
 
+/**
+ * bytestring_splitstr_first - split a bytestring on a delimiter string
+ * @whole: a bytestring
+ * @delim: delimiter substring
+ *
+ * Returns the first substring of @whole delimited by the substring in
+ * @delim.
+ */
+struct bytestring bytestring_splitstr_first(struct bytestring whole,
+                                            struct bytestring delim);
+
+/**
+ * bytestring_splitstr_next - split a bytestring on a delimiter string
+ * @whole: a bytestring
+ * @delim: delimiter string
+ * @prev: last substring
+ *
+ * Returns the next @delim delimited substring of @whole after @prev.
+ */
+struct bytestring bytestring_splitstr_next(struct bytestring whole,
+                                          struct bytestring delim,
+                                          struct bytestring prev);
+
+#define bytestring_foreach_splitstr(_s, _w, _delim) \
+       for ((_s) = bytestring_splitstr_first((_w), (_delim)); \
+            (_s).ptr;                                         \
+            (_s) = bytestring_splitstr_next((_w), (_delim), (_s)))
+
 #endif /* CCAN_BYTESTRING_H_ */