/* is parametrized: no */ #ifndef GUF_CSTR_H #define GUF_CSTR_H #include #include "guf_common.h" #include "guf_assert.h" #include "guf_hash.h" typedef const char* guf_cstr_const; static inline int guf_cstr_const_cmp(const guf_cstr_const *a, const guf_cstr_const *b) { GUF_ASSERT_RELEASE(a && b); GUF_ASSERT_RELEASE(*a && *b); return strcmp(*a, *b); } static inline bool guf_cstr_const_eq(const guf_cstr_const *a, const guf_cstr_const *b) { GUF_ASSERT_RELEASE(a && b); GUF_ASSERT_RELEASE(*a && *b); return 0 == strcmp(*a, *b); } static inline guf_hash_size_t guf_cstr_const_hash(const guf_cstr_const *a) { GUF_ASSERT_RELEASE(a); GUF_ASSERT_RELEASE(*a); return guf_hash(*a, strlen(*a), GUF_HASH_INIT); } typedef char* guf_cstr_heap; static inline guf_cstr_heap *guf_cstr_heap_copy(guf_cstr_heap *dst, const guf_cstr_heap *src, void *ctx) { (void)ctx; GUF_ASSERT_RELEASE(dst && src); if (*src == NULL) { *dst = NULL; return dst; } *dst = strdup(*src); GUF_ASSERT_RELEASE(*dst); return dst; } static inline guf_cstr_heap *guf_cstr_heap_move(guf_cstr_heap *dst, guf_cstr_heap *src, void *ctx) { (void)ctx; GUF_ASSERT_RELEASE(dst && src); *dst = *src; *src = NULL; return dst; } static inline void guf_cstr_heap_free(guf_cstr_heap *a, void *ctx) { (void)ctx; GUF_ASSERT_RELEASE(a); free(*a); } static inline int guf_cstr_heap_cmp(const guf_cstr_heap *a, const guf_cstr_heap *b) { GUF_ASSERT_RELEASE(a && b); GUF_ASSERT_RELEASE(*a && *b); return strcmp(*a, *b); } static inline bool guf_cstr_heap_eq(const guf_cstr_heap *a, const guf_cstr_heap *b) { GUF_ASSERT_RELEASE(a && b); GUF_ASSERT_RELEASE(*a && *b); return 0 == strcmp(*a, *b); } #endif