StrForeachInRange
Description
Walk characters of str in the half-open range [start, end), binding chr to the current character value. Convenience wrapper around StrForeachInRangeIdx with an internally-managed index. See VecForeachInRange for the full SUCCESS/FAILURE contract.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Io.c:1677:
}
} else {
StrForeachInRange(s, c, 0, len) {
if (IS_PRINTABLE(c)) {
if (!StrPushBackR(o, c)) { // Test StrForeachInRange macro
bool test_str_foreach_in_range(void) {
WriteFmt("Testing StrForeachInRange\n");
DefaultAllocator alloc = DefaultAllocatorInit(); // Build a new string by iterating through a range of characters
Str result = StrInit(&alloc);
StrForeachInRange(&s, chr, 0, 5) {
// Append the character to the result string
StrPushBackR(&result, chr); // Test with range at the end of the string
Str end_result = StrInit(&alloc);
StrForeachInRange(&s, chr, 6, 11) {
// Append the character to the result string
StrPushBackR(&end_result, chr);
Last updated on