Add cfw_string_append().
This commit is contained in:
parent
d957ec53ea
commit
0915874505
3 changed files with 32 additions and 2 deletions
|
@ -131,6 +131,23 @@ cfw_string_set(CFWString *str, const char *cstr)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
cfw_string_append(CFWString *str, CFWString *append)
|
||||
{
|
||||
char *new;
|
||||
|
||||
if ((new = realloc(str->cstr, str->len + append->len + 1)) == NULL)
|
||||
return false;
|
||||
|
||||
memcpy(new + str->len, append->cstr, append->len);
|
||||
new[str->len + append->len] = 0;
|
||||
|
||||
str->cstr = new;
|
||||
str->len += append->len;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static CFWClass class = {
|
||||
.name = "CFWString",
|
||||
.size = sizeof(CFWString),
|
||||
|
|
|
@ -34,5 +34,6 @@ extern CFWClass *cfw_string;
|
|||
extern const char* cfw_string_c(CFWString*);
|
||||
extern size_t cfw_string_len(CFWString*);
|
||||
extern bool cfw_string_set(CFWString*, const char*);
|
||||
extern bool cfw_string_append(CFWString*, CFWString*);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue