#ifndef CST_UTIL_H #define CST_UTIL_H #include #include #ifdef __cplusplus extern "C" { #endif typedef struct { char *buf; size_t len; size_t cap; } cst_buf_t; int cst_buf_append(cst_buf_t *b, const char *s, size_t n); int cst_buf_puts(cst_buf_t *b, const char *s); int cst_buf_printf(cst_buf_t *b, const char *fmt, ...); void cst_buf_free(cst_buf_t *b); /* Take ownership of the NUL-terminated buffer (never NULL on success). */ char *cst_buf_steal(cst_buf_t *b); /* Largest n' <= n that does not split a UTF-8 sequence of s. */ size_t cst_utf8_floor(const char *s, size_t n); /* Copy s[0..n) replacing invalid UTF-8 with '?'. malloc'd, NUL-terminated. */ char *cst_utf8_sanitize(const char *s, size_t n, size_t *out_len); uint64_t cst_fnv1a64(uint64_t h, const void *data, size_t n); #define CST_FNV_INIT 1469598103934665603ULL #ifdef __cplusplus } #endif #endif