docs/Writerside/topics/string.h.md

changeset 1304
57e062a4bb05
parent 1297
0811fb9a8dba
equal deleted inserted replaced
1303:4022e403de60 1304:57e062a4bb05
37 37
38 cxmutstr cx_strdup(AnyStr string); 38 cxmutstr cx_strdup(AnyStr string);
39 39
40 cxmutstr cx_strdup_a(const CxAllocator *allocator, AnyStr string); 40 cxmutstr cx_strdup_a(const CxAllocator *allocator, AnyStr string);
41 41
42 int cx_strcpy(cxmutstr *dest, cxstring source);
43
44 int cx_strcpy_a(const CxAllocator *allocator,
45 cxmutstr *dest, cxstring source);
46
42 void cx_strfree(cxmutstr *str); 47 void cx_strfree(cxmutstr *str);
43 48
44 void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str); 49 void cx_strfree_a(const CxAllocator *alloc, cxmutstr *str);
45 50
46 51
53 In case you already know the length, or the string is not zero-terminated, you can use `cx_strn()` or `cx_mutstrn()`. 58 In case you already know the length, or the string is not zero-terminated, you can use `cx_strn()` or `cx_mutstrn()`.
54 59
55 The function `cx_strdup_a()` allocates new memory with the given `allocator` and copies the given `string` 60 The function `cx_strdup_a()` allocates new memory with the given `allocator` and copies the given `string`
56 and guarantees that the result string is zero-terminated. 61 and guarantees that the result string is zero-terminated.
57 The function `cx_strdup()` is equivalent to `cx_strdup_a()`, except that it uses the default stdlib allocator. 62 The function `cx_strdup()` is equivalent to `cx_strdup_a()`, except that it uses the default stdlib allocator.
63
64 The functions `cx_strcpy_a()` and `cx_strcpy()` copy the contents of the `source` string to the `dest` string,
65 and also guarantee zero-termination of the resulting string.
66 The memory in `dest` is either freshly allocated or re-allocated to fit the size of the string plus the terminator.
58 67
59 Allocated strings are always of type `cxmutstr` and can be deallocated by a call to `cx_strfree()` or `cx_strfree_a()`. 68 Allocated strings are always of type `cxmutstr` and can be deallocated by a call to `cx_strfree()` or `cx_strfree_a()`.
60 The caller must make sure to use the correct allocator for deallocating a string. 69 The caller must make sure to use the correct allocator for deallocating a string.
61 It is safe to call these functions multiple times on a given string, as the pointer will be nulled and the length set to zero. 70 It is safe to call these functions multiple times on a given string, as the pointer will be nulled and the length set to zero.
62 It is also safe to call the functions with a `NULL`-pointer, just like any other `free()`-like function. 71 It is also safe to call the functions with a `NULL`-pointer, just like any other `free()`-like function.

mercurial