StrForeachReverseIdx
Description
Walk each character of str backward, binding chr to the character value at index idx from length - 1 down to 0. Both chr and idx are stamped by the macro. See VecForeachReverseIdx for the full SUCCESS/FAILURE contract.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Str.Foreach.c:58:
// Test StrForeachReverseIdx macro
bool test_str_foreach_reverse_idx(void) {
WriteFmt("Testing StrForeachReverseIdx\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Str.Foreach.c:67:
Str result = StrInit(&alloc);
StrForeachReverseIdx(&s, chr, idx) {
// Append the character and its index to the result string
StrAppendFmt(&result, "{c}{}", chr, idx); // Make idx go out of bounds in StrForeachReverseIdx by modifying string during iteration
bool test_str_foreach_reverse_idx_out_of_bounds_access(void) {
WriteFmt("Testing StrForeachReverseIdx where idx goes out of bounds\n");
DefaultAllocator alloc = DefaultAllocatorInit();
// StrForeachReverseIdx (VecForeachReverseIdx) has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
StrForeachReverseIdx(&s, chr, idx) {
WriteFmt("Accessing idx {} (s.length={}): '{c}'\n", idx, StrLen(&s), chr);
Last updated on