X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fbytestring%2Fbytestring.h;h=0d1c929e599564d92984c836b9f434b5195dbd1e;hb=3f60b879d0ca10fed16e6432180c847ad90b8d80;hp=8aa272755caa90b2ad1c18655a8195093d7ec7cf;hpb=cb2d540f764b225a068a3cdd1396df4fc8dc6824;p=ccan diff --git a/ccan/bytestring/bytestring.h b/ccan/bytestring/bytestring.h index 8aa27275..0d1c929e 100644 --- a/ccan/bytestring/bytestring.h +++ b/ccan/bytestring/bytestring.h @@ -246,4 +246,62 @@ struct bytestring bytestring_splitchr_next(struct bytestring whole, (_s).ptr; \ (_s) = bytestring_splitchr_next((_w), (_delim), (_s))) +/** + * bytestring_splitchrs_first - split a bytestring on a set of delimiter + * characters + * @whole: a bytestring + * @delim: delimiter characters + * + * Returns the first substring of @whole delimited by any character in + * @delim. + */ +struct bytestring bytestring_splitchrs_first(struct bytestring whole, + struct bytestring delim); + +/** + * bytestring_splitchr_next - split a bytestring on a set of delimiter + * characters + * @whole: a bytestring + * @delim: delimiter character + * @prev: last substring + * + * Returns the next @delim delimited substring of @whole after @prev. + */ +struct bytestring bytestring_splitchrs_next(struct bytestring whole, + struct bytestring delim, + struct bytestring prev); + +#define bytestring_foreach_splitchrs(_s, _w, _delim) \ + for ((_s) = bytestring_splitchrs_first((_w), (_delim)); \ + (_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_ */