Add init method to dstr for initializing directyl from a string
Change the api so _put_ functions that copy in data are named "_append_" instead.
This commit is contained in:
+16
-4
@@ -35,6 +35,18 @@ struct DStr {
|
||||
*/
|
||||
void uc_dstr_init(struct DStr *str);
|
||||
|
||||
/** Initialize a DStr from an existing string
|
||||
*
|
||||
* @return 0 on success (!= 0 if an allocation fail)
|
||||
*/
|
||||
int uc_dstr_init_str(struct DStr *str, const char *init);
|
||||
|
||||
/** Initialize a DStr from an existing string with a given length
|
||||
*
|
||||
* @return 0 on success (!= 0 if an allocation fail)
|
||||
*/
|
||||
int uc_dstr_init_str_sz(struct DStr *str, const char *init, size_t len);
|
||||
|
||||
/** Destroy/free the string.
|
||||
* (Frees str->str, not str itself)
|
||||
*/
|
||||
@@ -95,7 +107,7 @@ char *uc_dstr_put(struct DStr *str, size_t len);
|
||||
* @param is_x ctype.h compatible function to use as a filter.
|
||||
* @return number of chars appended
|
||||
*/
|
||||
size_t uc_dstr_put_str_filter(struct DStr *str, const char *restrict s, int (*is_x)(int c));
|
||||
size_t uc_dstr_append_str_filter(struct DStr *str, const char *restrict s, int (*is_x)(int c));
|
||||
|
||||
/* Append a string of the give size.
|
||||
* (The nul terminator is not appended)
|
||||
@@ -104,20 +116,20 @@ size_t uc_dstr_put_str_filter(struct DStr *str, const char *restrict s, int (*is
|
||||
* @param len bytes to append (not including the nul terminator)
|
||||
* @return 0 on success (!= 0 if an allocation fail)
|
||||
*/
|
||||
int uc_dstr_put_str_sz(struct DStr *str, const char *restrict s, size_t len);
|
||||
int uc_dstr_append_str_sz(struct DStr *str, const char *restrict s, size_t len);
|
||||
|
||||
/* Append a string.
|
||||
* (The nul terminator is not appended)
|
||||
*
|
||||
* @return 0 on success (!= 0 if an allocation fail)
|
||||
*/
|
||||
int uc_dstr_put_str(struct DStr *str, const char *restrict s);
|
||||
int uc_dstr_append_str(struct DStr *str, const char *restrict s);
|
||||
|
||||
/* Append a single char.
|
||||
*
|
||||
* @return 0 on success (!= 0 if an allocation fail)
|
||||
*/
|
||||
int uc_dstr_put_char(struct DStr *str, char c);
|
||||
int uc_dstr_append_char(struct DStr *str, char c);
|
||||
|
||||
/* Make the DStr take ownership of the given dynamically allocated string.
|
||||
* Any existing string in the DStr is freed.
|
||||
|
||||
Reference in New Issue
Block a user