X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fbytestring%2Fbytestring.h;h=8aa272755caa90b2ad1c18655a8195093d7ec7cf;hp=34d81af2038e4bc5ea0c481e19f27ffb6620ae2a;hb=cb2d540f764b225a068a3cdd1396df4fc8dc6824;hpb=b529270bf1ce198a310046d83c8e5d9356dcfe15 diff --git a/ccan/bytestring/bytestring.h b/ccan/bytestring/bytestring.h index 34d81af2..8aa27275 100644 --- a/ccan/bytestring/bytestring.h +++ b/ccan/bytestring/bytestring.h @@ -220,4 +220,30 @@ size_t bytestring_spn(struct bytestring s, struct bytestring accept); */ size_t bytestring_cspn(struct bytestring s, struct bytestring reject); +/** + * bytestring_splitchr_first - split a bytestring on a single character delimiter + * @whole: a bytestring + * @delim: delimiter character + * + * Returns the first @delim delimited substring of @whole. + */ +struct bytestring bytestring_splitchr_first(struct bytestring whole, + char delim); + +/** + * bytestring_splitchr_next - split a bytestring on a single character delimiter + * @whole: a bytestring + * @delim: delimiter character + * @prev: last substring + * + * Returns the next @delim delimited substring of @whole after @prev. + */ +struct bytestring bytestring_splitchr_next(struct bytestring whole, + char delim, struct bytestring prev); + +#define bytestring_foreach_splitchr(_s, _w, _delim) \ + for ((_s) = bytestring_splitchr_first((_w), (_delim)); \ + (_s).ptr; \ + (_s) = bytestring_splitchr_next((_w), (_delim), (_s))) + #endif /* CCAN_BYTESTRING_H_ */