StrForeachPtrInRange
- Macro
- August 22, 2025
Table of Contents
StrForeachPtrInRange
StrForeachPtrInRange
Description
Iterate over characters in a specific range of the given Str str
(as pointers). This is a convenience macro that iterates over a range using an internally managed index and provides a pointer to each character. The variable chrptr
is declared and defined by the underlying VecForeachPtrInRange
macro as a pointer to the character type.
Parameters
Name | Direction | Description |
---|---|---|
str | in,out | Str to iterate over. |
chrptr | in | Name of pointer variable to be used which’ll point to the current character. |
start | in | Starting index (inclusive). |
end | in | Ending index (exclusive). |
Success
The body
is executed for each character of the Str str
from the start
index to the end-1
index, with chrptr
pointing to each character.
Failure
If the Str str
is NULL, its length is zero, or the range is invalid, the loop body will not be executed. Any failures within the VecForeachPtrInRangeIdx
macro will result in a fatal log message and program termination.
Usage example (Cross-references)
// Test StrForeachPtrInRange macro
bool test_str_foreach_ptr_in_range(void) {
printf("Testing StrForeachPtrInRange\n");
Str s = StrInitFromZstr("Hello World");
// Build a new string by iterating through a range of character pointers
Str result = StrInit();
StrForeachPtrInRange(&s, chrptr, 0, 5, {
// Append the character to the result string
StrPushBack(&result, *chrptr);