object: string: add b_string_duplicate()
This commit is contained in:
@@ -170,6 +170,23 @@ struct b_string *b_string_create_from_c(char c, size_t count)
|
||||
return str;
|
||||
}
|
||||
|
||||
struct b_string *b_string_duplicate(const struct b_string *str)
|
||||
{
|
||||
struct b_string *new_str = b_string_create();
|
||||
if (!str) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
string_change_capacity(new_str, str->s_len);
|
||||
const char *src = b_string_ptr(str);
|
||||
char *dst = string_ptr(new_str);
|
||||
|
||||
memcpy(dst, src, str->s_len);
|
||||
new_str->s_len = str->s_len;
|
||||
|
||||
return new_str;
|
||||
}
|
||||
|
||||
char *b_string_steal(struct b_string *str)
|
||||
{
|
||||
char *dest = NULL;
|
||||
|
||||
Reference in New Issue
Block a user