Add cfw_string_set_nocopy().
This commit is contained in:
parent
69adb323ad
commit
7ad3af0b3d
2 changed files with 22 additions and 3 deletions
24
src/string.c
24
src/string.c
|
@ -180,19 +180,37 @@ bool
|
|||
cfw_string_set(CFWString *str, const char *cstr)
|
||||
{
|
||||
char *copy;
|
||||
size_t len;
|
||||
|
||||
if ((copy = cfw_strdup(cstr)) == NULL)
|
||||
return false;
|
||||
if (str != NULL) {
|
||||
if ((copy = cfw_strdup(cstr)) == NULL)
|
||||
return false;
|
||||
|
||||
len = strlen(copy);
|
||||
} else {
|
||||
copy = NULL;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
if (str->data != NULL)
|
||||
free(str->data);
|
||||
|
||||
str->data = copy;
|
||||
str->len = strlen(copy);
|
||||
str->len = len;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
cfw_string_set_nocopy(CFWString *str, char *cstr, size_t len)
|
||||
{
|
||||
if (str->data != NULL)
|
||||
free(str->data);
|
||||
|
||||
str->data = cstr;
|
||||
str->len = len;
|
||||
}
|
||||
|
||||
bool
|
||||
cfw_string_append(CFWString *str, CFWString *append)
|
||||
{
|
||||
|
|
|
@ -37,6 +37,7 @@ extern char* cfw_strndup(const char*, size_t);
|
|||
extern const char* cfw_string_c(CFWString*);
|
||||
extern size_t cfw_string_length(CFWString*);
|
||||
extern bool cfw_string_set(CFWString*, const char*);
|
||||
extern void cfw_string_set_nocopy(CFWString*, char*, size_t);
|
||||
extern bool cfw_string_append(CFWString*, CFWString*);
|
||||
extern size_t cfw_string_find(CFWString*, CFWString*, cfw_range_t);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue