StrForeachReversePtrIdx

Table of Contents

StrForeachReversePtrIdx

Description

Iterate over each character pointer chrptr of the given Str str in reverse order at each index idx. This macro is a direct alias for VecForeachPtrReverseIdx specialized for Str. The variables chrptr and idx are declared and defined by the underlying macro.

Parameters

NameDirectionDescription
strin,outStr to iterate over.
chrptrinName of the pointer variable to be used which will point to the character at the iterated index idx. The type of chrptr will likely be a pointer to the character type used by the Str implementation (e.g., char*).
idxinName of the variable to be used for iterating over indices (i64).

Usage example (Cross-references)

    // Deadend test: Make idx go out of bounds in StrForeachReversePtrIdx by modifying string during iteration
    bool test_str_foreach_reverse_ptr_idx_out_of_bounds_access(void) {
    printf("Testing StrForeachReversePtrIdx where idx goes out of bounds (should crash)\n");
    
    Str s = StrInitFromZstr("Excellent Example"); // 17 characters
    
    // StrForeachReversePtrIdx (VecForeachPtrReverseIdx) has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
    StrForeachReversePtrIdx(&s, chr_ptr, idx, {
    printf("Accessing idx %zu (s.length=%zu): '%c'\n", idx, s.length, *chr_ptr);
    // Test StrForeachReversePtrIdx macro
    bool test_str_foreach_reverse_ptr_idx(void) {
    printf("Testing StrForeachReversePtrIdx\n");
    
    Str s = StrInitFromZstr("Hello");
    bool saw_index_zero = false;
    
    StrForeachReversePtrIdx(&s, chrptr, idx, {
    // Check if we see index 0
    if (idx == 0) {

Share :