libpkgconf: buffer: add pkgconf_buffer_contains and pkgconf_buffer_match

Signed-off-by: Ariadne Conill <ariadne@ariadne.space>
This commit is contained in:
Ariadne Conill 2025-12-27 15:07:50 -08:00
parent a0933c8b1b
commit db6bcbdcbe
2 changed files with 23 additions and 0 deletions

View File

@ -170,3 +170,24 @@ pkgconf_buffer_join(pkgconf_buffer_t *buffer, char delim, ...)
pkgconf_buffer_vjoin(buffer, delim, va);
va_end(va);
}
bool
pkgconf_buffer_contains(const pkgconf_buffer_t *haystack, const pkgconf_buffer_t *needle)
{
const char *haystack_str = pkgconf_buffer_str_or_empty(haystack);
const char *needle_str = pkgconf_buffer_str_or_empty(needle);
return strstr(haystack_str, needle_str) != NULL;
}
bool
pkgconf_buffer_match(const pkgconf_buffer_t *haystack, const pkgconf_buffer_t *needle)
{
const char *haystack_str = pkgconf_buffer_str_or_empty(haystack);
const char *needle_str = pkgconf_buffer_str_or_empty(needle);
if (pkgconf_buffer_len(haystack) != pkgconf_buffer_len(needle))
return false;
return memcmp(haystack_str, needle_str, pkgconf_buffer_len(haystack)) == 0;
}

View File

@ -459,6 +459,8 @@ PKGCONF_API void pkgconf_buffer_finalize(pkgconf_buffer_t *buffer);
PKGCONF_API void pkgconf_buffer_fputs(pkgconf_buffer_t *buffer, FILE *out);
PKGCONF_API void pkgconf_buffer_vjoin(pkgconf_buffer_t *buffer, char delim, va_list va);
PKGCONF_API void pkgconf_buffer_join(pkgconf_buffer_t *buffer, char delim, ...);
PKGCONF_API bool pkgconf_buffer_contains(const pkgconf_buffer_t *haystack, const pkgconf_buffer_t *needle);
PKGCONF_API bool pkgconf_buffer_match(const pkgconf_buffer_t *haystack, const pkgconf_buffer_t *needle);
static inline const char *pkgconf_buffer_str(const pkgconf_buffer_t *buffer) {
return buffer->base;
}