Skip to content

StrForeachPtr

StrForeachPtr

Description

Iterate over each character pointer chrptr of the given Str str. This is a convenience macro that iterates forward using an internally managed index and provides a pointer to each character. The variable chrptr is declared and defined by the underlying VecForeachPtr macro as a pointer to the character type.

Parameters

Name Direction Description
str in,out Str to iterate over.
chrptr in Name of the pointer variable to be used which will point to the current character during iteration. The type of chrptr will likely be a pointer to the character type used by the Str implementation (e.g., char*).

Usage example (Cross-references)

Usage examples (Cross-references)
                if (VecLen(str) > 0) {
                    size_t total_len = 0;
                    StrForeachPtr(str, ch_ptr) {
                        total_len += 1;
                    }
    // Test StrForeachPtr macro
    bool test_str_foreach_ptr(void) {
        WriteFmt("Testing StrForeachPtr\n");
    
        Str s = StrInitFromZstr("Hello");
        // Build a new string by iterating through each character pointer
        Str result = StrInit();
        StrForeachPtr(&s, chrptr) {
            // Append the character (via pointer) to the result string
            StrPushBack(&result, *chrptr);
Last updated on