X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fbytestring%2Fbytestring.h;fp=ccan%2Fbytestring%2Fbytestring.h;h=042b1843220192bd1c4d2614cdd75df303812bc0;hp=54e9fa8735122a70f7d7b032b8c776ead3096297;hb=d584928758cb995a60e8264b73da46bcd8c410ca;hpb=4a234682efc2a968564b86821435930d221a8218 diff --git a/ccan/bytestring/bytestring.h b/ccan/bytestring/bytestring.h index 54e9fa87..042b1843 100644 --- a/ccan/bytestring/bytestring.h +++ b/ccan/bytestring/bytestring.h @@ -2,12 +2,15 @@ #ifndef CCAN_BYTESTRING_H_ #define CCAN_BYTESTRING_H_ +#include "config.h" + #include #include #include #include #include +#include struct bytestring { const char *ptr; @@ -150,4 +153,32 @@ static inline bool bytestring_ends(struct bytestring s, suffix.ptr, suffix.len) == 0); } +/** + * bytestring_index - locate character in bytestring + * @haystack: a bytestring + * @needle: a character or byte value + * + * Returns a pointer to the first occurrence of @needle within + * @haystack, or NULL if @needle does not appear in @haystack. + */ +static inline const char *bytestring_index(struct bytestring haystack, + char needle) +{ + return memchr(haystack.ptr, needle, haystack.len); +} + +/** + * bytestring_rindex - locate character in bytestring + * @haystack: a bytestring + * @needle: a character or byte value + * + * Returns a pointer to the last occurrence of @needle within + * @haystack, or NULL if @needle does not appear in @haystack. + */ +static inline const char *bytestring_rindex(struct bytestring haystack, + char needle) +{ + return memrchr(haystack.ptr, needle, haystack.len); +} + #endif /* CCAN_BYTESTRING_H_ */