Skip to content

StrInsertCstr

StrInsertCstr

Description

Insert a string of given length into given Str at given index.

Parameters

Name Direction Description
str in,out Str object to insert into.
zstr in Zero-terminated string to be inserted.
idx in Index to insert the string at.
len in Length of string or number of bytes to insert.

Success

return

Failure

Does not return

Usage example (Cross-references)

Usage examples (Cross-references)
                    char  *cstr = generate_cstring(data, offset, size, 20);
                    if (cstr) {
                        StrInsertCstr(str, cstr, idx, strlen(cstr));
                        free(cstr);
                    }
            if (MemCompare(s->data + i, match, match_len) == 0) {
                StrDeleteRange(s, i, match_len);
                StrInsertCstr(s, replacement, i, replacement_len);
                i        += replacement_len;
                replaced += 1;
    // Test StrInsertCstr function
    bool test_str_insert_cstr(void) {
        WriteFmt("Testing StrInsertCstr\n");
    
        Str s = StrInitFromZstr("Hello");
    
        // Insert a string in the middle
        StrInsertCstr(&s, " World", 2, 6);
    
        // Check that the string was inserted correctly
    /// FAILURE : Does not return
    ///
    #define StrInsertZstr(str, zstr, idx) StrInsertCstr((str), (zstr), (idx), strlen(zstr))
    
    ///
    /// FAILURE : Does not return
    ///
    #define StrInsert(str, str2, idx) StrInsertCstr((str), (str2)->data, (idx), (str2)->length)
    
    ///
Last updated on