StrForeachPtr
- Macro
- August 22, 2025
Table of Contents
StrForeachPtr
StrForeachPtr
Description
Iterate over each character pointer chrptr
of the given Str str
. This is a convenience macro that iterates forward using an internally managed index and provides a pointer to each character. The variable chrptr
is declared and defined by the underlying VecForeachPtr
macro as a pointer to the character type.
Parameters
Name | Direction | Description |
---|---|---|
str | in,out | Str to iterate over. |
chrptr | in | Name of the pointer variable to be used which will point to the current character during iteration. The type of chrptr will likely be a pointer to the character type used by the Str implementation (e.g., char* ). |
Usage example (Cross-references)
// Test StrForeachPtr macro
bool test_str_foreach_ptr(void) {
printf("Testing StrForeachPtr\n");
Str s = StrInitFromZstr("Hello");
// Build a new string by iterating through each character pointer
Str result = StrInit();
StrForeachPtr(&s, chrptr, {
// Append the character (via pointer) to the result string
StrPushBack(&result, *chrptr);