string_new
Initialize new dynamic string. Created string is guaranteed to be zero terminated.
Warning
Every new string must be deleted by string_delete call.
Declaration
fn () string
Description
Create new empty string object.
Result
New empty string.
Example
main :: fn () s32 {
str :: string_new();
defer string_delete(str);
string_append(&str, "Hello");
print("str = %\n", str);
return 0;
}
Declaration
fn (size: usize) string
Description
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.
Arguments
sizePreallocation size in characters.
Result
New string.
Example
main :: fn () s32 {
str :: string_new(256);
defer string_delete(str);
string_append(&str, "Hello");
print("str = %\n", str);
return 0;
}
Declaration
fn (v: string) string
Description
Create copy of v string.
Arguments
vString to be copied.
Result
New duplicate string.
Declaration
fn (cstr: *u8) string
Description
Create copy of C zero terminated string.
Arguments
vPointer to C string.
Result
New duplicate string.
Declared in: string.bl