CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Byte-at-a-time Access

Functions

bool striChar (striter *i, uint8 *out)
 
bool striPeekChar (striter *i, uint8 *out)
 
bool striAdvance (striter *i, uint32 by)
 

Detailed Description

These functions simplify iteration by handling run boundaries automatically. They are less efficient than processing runs directly, but much simpler for state machine-based parsing (like UTF-8 decoding) where you need to examine one byte at a time without worrying about where runs begin and end.

Function Documentation

◆ striAdvance()

bool striAdvance ( striter i,
uint32  by 
)
inline

bool striAdvance(striter *i, uint32 by)

Advances the cursor by a specified number of bytes

Moves the cursor forward by 'by' bytes, automatically crossing run boundaries as needed. Returns false if advancing would go past the end of the string.

Parameters
iIterator to advance
byNumber of bytes to advance
Returns
true if advanced successfully, false if hit end of string

Example:

// Skip next 10 bytes
if (striAdvance(&it, 10)) {
// Successfully skipped
}
bool striAdvance(striter *i, uint32 by)
Definition striter.h:370

Definition at line 370 of file striter.h.

References striNext().

◆ striChar()

bool striChar ( striter i,
uint8 *  out 
)
inline

bool striChar(striter *i, uint8 *out)

Retrieves the next byte and advances cursor

Gets one byte from the current position and moves the cursor forward. Automatically advances to the next run if needed. Returns false when the end of the string is reached.

Parameters
iIterator to read from
outPointer to store the byte
Returns
true if a byte was read, false if end of string

Example:

striInit(&it, s);
uint8 ch;
while (striChar(&it, &ch)) {
// Process ch
}
bool striChar(striter *i, uint8 *out)
Definition striter.h:307
void striFinish(striter *i)
void striInit(striter *i, strref s)

Definition at line 307 of file striter.h.

References striNext().

◆ striPeekChar()

bool striPeekChar ( striter i,
uint8 *  out 
)
inline

bool striPeekChar(striter *i, uint8 *out)

Retrieves the next byte without advancing cursor

Gets one byte from the current position but doesn't move the cursor. Useful for lookahead in parsers. Automatically advances to the next run if at a boundary.

Parameters
iIterator to read from
outPointer to store the byte
Returns
true if a byte was read, false if end of string

Example:

uint8 ch;
if (striPeekChar(&it, &ch) && ch == '\\') {
// Next char is backslash, decide how to handle
}
bool striPeekChar(striter *i, uint8 *out)
Definition striter.h:339

Definition at line 339 of file striter.h.

References striNext().