Overloaded function creating new dynamic string instance. Created string is guaranteed to be zero terminated.
Warning
Every new string must be deleted by string_delete call.
fn () string
Create new empty string object.
New empty string.
main :: fn () s32 { str :: string_new(); defer string_delete(str); string_append(&str, "Hello"); print("str = %\n", str); return 0; }
fn (size: usize) string
Create new string with preallocated space. This type of string initialization can reduce count of allocations made later by extending string content. String with length up to size require only one memory allocation.
Hint
This initialization should be preferred if string length can be predicted.
size Preallocation size in characters.
New string.
main :: fn () s32 { str :: string_new(256); defer string_delete(str); string_append(&str, "Hello"); print("str = %\n", str); return 0; }
fn (v: string) string
Create copy of v string. Allocates memory to hold exactly size of v string data.
v String to be copied.
New duplicate string.
fn (cstr: *u8) string
Create copy of C zero terminated string.
v Pointer to C string.
Declared in: string.bl