StrForeachReversePtrIdx
Description
Walk each character of str backward, binding chrptr to a pointer to the character at index idx from length - 1 down to 0. Both chrptr and idx are stamped by the macro. See VecForeachPtrReverseIdx for the full SUCCESS/FAILURE contract.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Foreach.c:115:
// Test StrForeachReversePtrIdx macro
bool test_str_foreach_reverse_ptr_idx(void) {
WriteFmt("Testing StrForeachReversePtrIdx\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Foreach.c:124:
Str result = StrInit(&alloc);
StrForeachReversePtrIdx(&s, chrptr, idx) {
// Append the character (via pointer) and its index to the result string
StrAppendFmt(&result, "{c}{}", *chrptr, idx);- In
Foreach.c:557:
// 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) {
WriteFmt("Testing StrForeachReversePtrIdx where idx goes out of bounds\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Foreach.c:564:
// StrForeachReversePtrIdx (VecForeachPtrReverseIdx) has explicit bounds checking: if ((idx) >= (v)->length) LOG_FATAL(...)
StrForeachReversePtrIdx(&s, chr_ptr, idx) {
WriteFmt("Accessing idx {} (s.length={}): '{c}'\n", idx, StrLen(&s), *chr_ptr);
Last updated on