Skip to content

StrIterPeekAt

Description

Read the character at signed offset n into *out without advancing. Propagating alias for IterPeekAt; see IterPeekAt for the full contract.

Parameters

Name Direction Description
mi in Pointer to the StrIter to peek into.
n in Signed character offset along the iteration direction (scaled by dir); positive looks ahead in iteration order, negative looks behind.
out out Destination char *; receives data[pos + dir * n].

Success

*out is set to the character at pos + dir * n; the cursor is not advanced; returns true.

Failure

pos + dir * n is outside [0, length); *out is not written, returns false.

Usage example (Cross-references)

Usage examples (Cross-references)
        // followed by `i`/`I` enters this branch too.
        char c1 = 0;
        (void)StrIterPeekAt(&si, 1, &c1);
        if ((c == 'i' || c == 'I' || c == 'n' || c == 'N') || (c == '-' && (c1 == 'i' || c1 == 'I'))) {
            StrIter saved = si;
        char c0 = 0;
        char c1 = 0;
        (void)StrIterPeekAt(&si, 0, &c0);
        (void)StrIterPeekAt(&si, 1, &c1);
        char c1 = 0;
        (void)StrIterPeekAt(&si, 0, &c0);
        (void)StrIterPeekAt(&si, 1, &c1);
    
        if (c0 == '0' && (c1 == 'x' || c1 == 'X')) {
        char p0 = 0;
        char p1 = 0;
        (void)StrIterPeekAt(&si, 0, &p0);
        (void)StrIterPeekAt(&si, 1, &p1);
        char p1 = 0;
        (void)StrIterPeekAt(&si, 0, &p0);
        (void)StrIterPeekAt(&si, 1, &p1);
    
        if (radix == 16 && p0 == '0' && (p1 == 'x' || p1 == 'X')) {
        // followed by `i`/`I` enters this branch too.
        char c1 = 0;
        (void)StrIterPeekAt(&si, 1, &c1);
        if ((c == 'i' || c == 'I' || c == 'n' || c == 'N') || (c == '-' && (c1 == 'i' || c1 == 'I'))) {
            StrIter saved = si;
            if (StrIterRemainingLength(&si) > kw_len &&
                MemCompare(StrIterDataAt(&si, StrIterIndex(&si)), NS_KEYWORD, kw_len) == 0 &&
                StrIterPeekAt(&si, (i64)kw_len, &sep) && (sep == ' ' || sep == '\t')) {
                StrIterMustMove(&si, (i64)kw_len);
                skip_hspace_iter(&si);
        StrIter si = StrIterFromZstr("abcd");
        char    c  = 0;
        if (!StrIterPeekAt(&si, 2, &c) || c != 'c') {
            return false;
        }
Last updated on