mirror of
https://github.com/pkgconf/pkgconf.git
synced 2026-01-26 16:09:27 +00:00
libpkgconf: buffer: add pkgconf_buffer_contains and pkgconf_buffer_match
Signed-off-by: Ariadne Conill <ariadne@ariadne.space>
This commit is contained in:
parent
a0933c8b1b
commit
db6bcbdcbe
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user