Skip to content

IterMove

Description

Propagating move by n positions in the iteration direction. n may be negative to step backward. The new position must land in [0, length] for forward iteration, or in [-1, length) for reverse iteration (where -1 is the past-start sentinel).

Success

Position is updated, returns true.

Failure

The new position would be out of range. Position is unchanged, returns false.

Usage example (Cross-references)

Usage examples (Cross-references)
                if (!BufReadU8(cur, &n))
                    return false;
                return IterMove(cur, (i64)(n));
            }
            case DW_FORM_block2 : {
                if (!BufReadU16LE(cur, &n))
                    return false;
                return IterMove(cur, (i64)(n));
            }
            case DW_FORM_block4 : {
                if (!BufReadU32LE(cur, &n))
                    return false;
                return IterMove(cur, (i64)(n));
            }
            case DW_FORM_block :
                if (!BufReadULeb128(cur, &n))
                    return false;
                return IterMove(cur, (i64)(n));
            }
            case DW_FORM_indirect : {
            return true;
        }
        if (!IterMove(&c, (i64)(DIR_INDEX_DEBUG * 8u)))
            return false;
        // Read into a local u32, then widen -- aliasing a u64* through a
        const u8 buf[4] = {5, 6, 7, 8};
        BufIter  it     = BufIterFromMemory(buf, 4);
        IterMove(&it, 2);
        u8 v;
        if (!IterPeekAt(&it, 0, &v) || v != 7) {
        const u8 buf[5] = {0};
        BufIter  it     = BufIterFromMemory(buf, 5);
        if (!IterMove(&it, 3) || IterIndex(&it) != 3) {
            return false;
        }
            return false;
        }
        if (!IterMove(&it, -2) || IterIndex(&it) != 1) {
            return false;
        }
        const u8 buf[3] = {0};
        BufIter  it     = BufIterFromMemory(buf, 3);
        if (!IterMove(&it, 3) || IterIndex(&it) != 3) {
            return false;
        }
        BufIter  it     = BufIterFromMemory(buf, 3);
        size     before = IterIndex(&it);
        if (IterMove(&it, 4)) {
            return false;
        }
        const u8 buf[3] = {0};
        BufIter  it     = BufIterFromMemory(buf, 3);
        if (IterMove(&it, -1)) {
            return false;
        }
        BufIter  it     = from_rev(buf, 5);
        // start at pos=4
        if (!IterMove(&it, 2) || IterIndex(&it) != 2) {
            return false;
        }
        }
        // step backward in reverse direction (n=-1, effective +1)
        if (!IterMove(&it, -1) || IterIndex(&it) != 3) {
            return false;
        }
        BufIter  it     = from_rev(buf, 3);
        // pos=2, dir=-1, move by 3 lands on sentinel pos=-1
        if (!IterMove(&it, 3) || IterIndex(&it) != (size)-1) {
            return false;
        }
        // pos=2, dir=-1, move by 4 would land at pos=-2 — invalid
        size before = IterIndex(&it);
        if (IterMove(&it, 4)) {
            return false;
        }
    /// TAGS: StrIter, Move, Position, Alias
    ///
    #define StrIterMove(si, n) IterMove((si), (n))
    
    ///
    #define IterMustMove(mi, n)                                                                                            \
        do {                                                                                                               \
            if (!IterMove((mi), (n))) {                                                                                    \
                LOG_FATAL("IterMustMove: target position out of range");                                                   \
            }                                                                                                              \
    /// TAGS: Iter, Memory, Position
    ///
    #define IterNext(mi) IterMove((mi), 1)
    
    ///
    /// TAGS: Iter, Memory, Position
    ///
    #define IterPrev(mi) IterMove((mi), -1)
    
    ///
Last updated on