StrMerge

Table of Contents

StrMerge

Description

Merge two strings and store the result in first string. By default, this uses R-value semantics (preserves source string). Data is copied from str2 into str. If a copy_init method is provided in str, each element from str2 will be copied using that method. Otherwise, a raw memory copy is performed.

Note

This preserves the source string. If you want to transfer ownership and reset the source string, use StrMergeL instead.

Parameters

NameDirectionDescription
strin,outStr to insert array chars into.
str2inStr to be inserted.

Success

str

Failure

NULL

Usage example (Cross-references)

    }
    StrPushBackZstr(o, "0x");
    StrMerge(o, &hex);
    StrDeinit(&hex);
    });
    }
    StrPushBackZstr(o, "0x");
    StrMerge(o, &hex);
    StrDeinit(&hex);
    i++;
    
    // Merge the formatted number into output
    StrMerge(o, &temp);
    StrDeinit(&temp);
    
    // Merge the formatted number into output
    StrMerge(o, &temp);
    StrDeinit(&temp);
    
    // Merge the formatted number into output
    StrMerge(o, &temp);
    StrDeinit(&temp);
    }
    } else {
    Str bit_str = BitVecToStr(bv);
    StrMerge(o, &bit_str);
    StrDeinit(&bit_str);
    }
    // keep track of current path we're exploring
    Str current_path = StrInit();
    StrMerge(&current_path, &dir_name);
    
    SysDirContents dir_contents = SysGetDirContents(dir_name.data);
    // create new directory path relative to current directory search path
    Str path = StrInit();
    StrMerge(&path, &current_path);
    StrPushBack(&path, '/');
    StrMerge(&path, &dir_entry.name);
    StrMerge(&path, &current_path);
    StrPushBack(&path, '/');
    StrMerge(&path, &dir_entry.name);
    
    // store the directory name, ownersip transferred
    // create complete relative file path
    Str path = StrInit();
    StrMerge(&path, &current_path);
    StrPushBack(&path, '/');
    StrMerge(&path, &dir_entry.name);
    StrMerge(&path, &current_path);
    StrPushBack(&path, '/');
    StrMerge(&path, &dir_entry.name);
    
    // store discovered file name, ownersip transferred
    Str output_path = StrInit();
    Scope(&output_path, StrDeinit, {
    StrMerge(&output_path, &file_path);
    LOG_INFO("{}", output_path);
    StrReplaceZstr(&output_path, "/", "-", -1);
    
    StrWriteFmt(&md_code, mdHeader, output_path.data, output_path.data, output_path.data);
    StrMerge(&md_code, &file_contents);
    StrWriteFmt(&md_code, "\n```");
    // Test StrMerge function (alias for StrMergeR)
    bool test_str_merge(void) {
    printf("Testing StrMerge\n");
    
    Str s1 = StrInitFromZstr("Hello");
    
    // Merge s2 into s1
    StrMerge(&s1, &s2);
    
    // Check that the strings were merged correctly

Share :