Skip to content

StrCapacity

Description

Capacity in characters: the most the string can hold before the next reallocation. Always >= StrLen(str).

Parameters

Name Direction Description
str in String to query.

Usage example (Cross-references)

Usage examples (Cross-references)
    
            // Check capacity is as expected
            if (StrCapacity(&stack_str) != 20) {
                result = false;
            }
    
        // After the scope, stack_str should be zeroed out
        if (StrBegin(&stack_str) != NULL || StrLen(&stack_str) != 0 || StrCapacity(&stack_str) != 0) {
            result = false;
        }
    
        // Original capacity should be at least 100
        bool result = (StrCapacity(&s) >= 100);
    
        // Try to reduce space
    
        // Capacity should now be closer to the actual length
        result = result && (StrCapacity(&s) < 100) && (StrCapacity(&s) >= StrLen(&s));
    
        StrDeinit(&s);
    
        // Capacity should now be at least 100
        bool result = (StrCapacity(&s) >= 100);
    
        // Length should still be 0
    
        // Capacity should still be at least 100
        result = result && (StrCapacity(&s) >= 100);
    
        StrDeinit(&s);
    
        // Length should now be 0, but capacity should remain
        result = result && (StrLen(&s) == 0) && (StrCapacity(&s) >= 13);
    
        // Data pointer should still be valid
        Zstr expected = "this is longer than the initial buffer";
        bool result   = (got == (i64)ZstrLen(expected)) && (StrLen(&body) == (size)ZstrLen(expected)) &&
                      ZstrCompare(StrBegin(&body), expected) == 0 && StrCapacity(&body) >= StrLen(&body) + 1;
    
        StrDeinit(&body);
Last updated on