#ifndef UC_DSTR_H_ #define UC_DSTR_H_ #include #ifdef __cplusplus extern "C" { #endif /** A dynamic string. * The string might not always be nul terminated, * Normally, use uc_dstr_str() to manipulate the managed string * instead of accessing ->str directly. */ struct DStr { size_t len; size_t allocated; char *str; }; #define UC_DSTR_STATIC_INIT {0, 0, NULL} /** Initialize a DStr. * Note that str->str will be NULL after initialization. * */ void uc_dstr_init(struct DStr *str); /** Destroy/free the string. * (Does not free str itself, only the managed resource of the str) */ void uc_dstr_destroy(struct DStr *str); /** * @return the available/unused tail bytes in the string */ size_t uc_dstr_available(const struct DStr *str); /** Ensure the DStr is of at least 'len' bytes, * allocating room if needed. */ int uc_dstr_ensure(struct DStr *str, size_t len); void uc_dstr_reset(struct DStr *str); void uc_dstr_terminate(struct DStr *str); char *uc_dstr_str(struct DStr *str); char *uc_dstr_put(struct DStr *str, size_t len); size_t uc_dstr_put_str_filter(struct DStr *str, const char *s, int (*is_x)(int c)); int uc_dstr_put_str_sz(struct DStr *str, const char *s, size_t len); int uc_dstr_put_str(struct DStr *str, const char *s); int uc_dstr_put_char(struct DStr *str, char c); void uc_dstr_own(struct DStr *str, char *s); char *uc_dstr_steal(struct DStr *str); void uc_str_swap(struct DStr *a, struct DStr *b); size_t uc_dstr_replace(struct DStr *str, char f, char r); void uc_dstr_trim(struct DStr *str); #ifdef __cplusplus } #endif #endif