Skip to content

StrDup

Description

Clone a Str, inheriting the source allocator configuration.

Parameters

Name Direction Description
str in Source string.

Success

Returns a fully initialized Str that is a deep copy of str, inheriting its allocator binding. Same state effects as StrInitFromStr(str).

Failure

Returns an empty Str (length 0, capacity 0, data NULL, allocator bound) when allocation fails.

Usage example (Cross-references)

Usage examples (Cross-references)
            case STR_DUP : {
                if (VecLen(str) > 0) {
                    Str temp = StrDup(str);
                    StrDeinit(str);
                    *str = temp;
    // Test StrDup function (alias for StrInitFromStr)
    bool test_str_dup(void) {
        WriteFmt("Testing StrDup\n");
    
        Str src = StrInitFromZstr("Hello, World!");
    
        Str src = StrInitFromZstr("Hello, World!");
        Str dst = StrDup(&src);
    
        // Validate both strings
Last updated on