Skip to content
StrIterFromZstr

StrIterFromZstr

Description

Construct a forward-walking StrIter over a NUL-terminated Zstr. Alias-reframe of the IterInitFromVec shape: length is taken from ZstrLen(s), alignment is fixed at 1. See IterInitFromVec for the overall borrowed-data semantics.

Parameters

Name Direction Description
s in NUL-terminated string. Must outlive the iterator.

Success

Returns a compound-literal StrIter covering [s, s + ZstrLen(s)) with pos = 0, dir = 1. The NUL terminator is not part of the iterated range.

Failure

Macro cannot fail. Passing a non-NUL-terminated buffer is a usage error – ZstrLen would run past the end.

Usage example (Cross-references)

Usage examples (Cross-references)
        if (!s || !*s)
            return false;
        StrIter si = StrIterFromZstr(s);
        u64     v  = 0;
        char    c;
        BufIter start     = *iter;
        u64     arg_index = 0;
        StrIter fsi       = StrIterFromZstr(fmtstr);
        char    fc        = 0;
    static bool render_binary_fmt(Str *out, Zstr fmtstr, TypeSpecificIO *argv, u64 argc) {
        u64     arg_index = 0;
        StrIter fsi       = StrIterFromZstr(fmtstr);
        char    fc        = 0;
        while (StrIterPeek(&fsi, &fc)) {
        }
    
        StrIter si = StrIterFromZstr(i);
        char    c  = 0;
        }
    
        StrIter si = StrIterFromZstr(i);
        char    c  = 0;
            }                                                                                                              \
                                                                                                                           \
            StrIter si = StrIterFromZstr(i);                                                                               \
            char    c  = 0;                                                                                                \
                                                                                                                           \
        ValidateBitVec(bv);
    
        StrIter si = StrIterFromZstr(i);
        char    c  = 0;
        ValidateInt(value);
    
        StrIter si = StrIterFromZstr(i);
        char    c  = 0;
        ValidateFloat(value);
    
        StrIter si = StrIterFromZstr(i);
        char    c  = 0;
        }
    
        StrIter si = StrIterFromZstr(i);
        char    c  = 0;
            return false;
        }
        StrIter si          = StrIterFromZstr(name);
        u64     total_bytes = 0;
        char    c;
            size aug_end_pos = IterIndex(body) + aug_len;
    
            StrIter aug_it = StrIterFromZstr(augmentation + 1);
            char    a;
            while (StrIterRead(&aug_it, &a)) {
    // the iterator walks exactly the visible characters, alignment 1, forward.
    bool test_striter_from_zstr_length_and_read(void) {
        StrIter si = StrIterFromZstr("abc");
        if (StrIterRemainingLength(&si) != 3) {
            return false;
    // StrIterPeek reads the current character without advancing the cursor.
    bool test_striter_peek_does_not_advance(void) {
        StrIter si = StrIterFromZstr("xy");
        char    c  = 0;
        if (!StrIterPeek(&si, &c) || c != 'x') {
    // advancing. On a forward iter that is the byte after the cursor.
    bool test_striter_peek_next_forward(void) {
        StrIter si = StrIterFromZstr("abc");
        char    c  = 0;
        if (!StrIterPeekNext(&si, &c) || c != 'b') {
    // StrIterPeekPrev looks one character behind in iteration order.
    bool test_striter_peek_prev_forward(void) {
        StrIter si = StrIterFromZstr("abc");
        StrIterMustNext(&si); // -> 'b'
        char c = 0;
    // *out untouched.
    bool test_striter_peek_next_at_last_fails(void) {
        StrIter si = StrIterFromZstr("ab");
        StrIterMustNext(&si); // -> 'b' (last)
        char c = 0x7F;
    // *out untouched.
    bool test_striter_peek_prev_at_first_fails(void) {
        StrIter si = StrIterFromZstr("ab");
        char    c  = 0x7F;
        if (StrIterPeekPrev(&si, &c)) {
    // advancing the cursor.
    bool test_striter_peek_at_offset(void) {
        StrIter si = StrIterFromZstr("abcd");
        char    c  = 0;
        if (!StrIterPeekAt(&si, 2, &c) || c != 'c') {
    // StrIterDataAt is index-addressed and well-defined one past the end.
    bool test_striter_data_at_bounds(void) {
        StrIter si = StrIterFromZstr("abc");
        if (*StrIterDataAt(&si, 0) != 'a') {
            return false;
Last updated on