StrForeachPtrInRange
- Macro
- October 8, 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). |
Usage example (Cross-references)
// Test StrForeachPtrInRange macro
bool test_str_foreach_ptr_in_range(void) {
WriteFmt("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);
- In
Str.c:583
:
if (start < end) {
size_t total_len = 0;
StrForeachPtrInRange(str, ch_ptr, start, end) {
total_len += 1;
}