StrForeachPtrInRange

Table of Contents

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

NameDirectionDescription
strin,outStr to iterate over.
chrptrinName of pointer variable to be used which’ll point to the current character.
startinStarting index (inclusive).
endinEnding 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);
    if (start < end) {
    size_t total_len = 0;
    StrForeachPtrInRange(str, ch_ptr, start, end) {
    total_len += 1;
    }

Share :