StrForeachReverseIdx

Table of Contents

StrForeachReverseIdx

Description

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

Parameters

NameDirectionDescription
strin,outStr to iterate over.
chrinName of the variable to be used which will contain the character at the iterated index idx. The type of chr will likely be 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 StrForeachReverseIdx by modifying string during iteration
    bool test_str_foreach_reverse_idx_out_of_bounds_access(void) {
    printf("Testing StrForeachReverseIdx where idx goes out of bounds (should crash)\n");
    
    Str s = StrInitFromZstr("Beautiful Weather"); // 17 characters
    
    // StrForeachReverseIdx (VecForeachReverseIdx) has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
    StrForeachReverseIdx(&s, chr, idx, {
    printf("Accessing idx %zu (s.length=%zu): '%c'\n", idx, s.length, chr);
    // Test StrForeachReverseIdx macro
    bool test_str_foreach_reverse_idx(void) {
    printf("Testing StrForeachReverseIdx\n");
    
    Str s = StrInitFromZstr("Hello");
    bool saw_index_zero = false;
    
    StrForeachReverseIdx(&s, chr, idx, {
    // Check if we see index 0
    if (idx == 0) {

Share :