String.new

new :: fn { new_default; new_reserved; new_copy; new_cstr; }

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.


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.

Example

main :: fn () s32 {
    str :: String.new();
    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.


fn (cstr: *u8) string

Create copy of C zero terminated string.

Declared in: string.bl