CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches

Typedefs

typedef bool(* lparseLineCB) (strref line, void *ctx)
 

Functions

bool lparseRegisterPush (StreamBuffer *sb, lparseLineCB pline, sbufCleanupCB pcleanup, void *ctx, uint32 flags)
 

Detailed Description

Push-mode line parsing where a callback is invoked for each line automatically.

Typedef Documentation

◆ lparseLineCB

typedef bool(* lparseLineCB) (strref line, void *ctx)

bool (*lparseLineCB)(strref line, void *ctx)

Callback function type for push-mode line parsing.

This callback is invoked for each line found in the stream buffer. The callback should return true to continue parsing or false to stop.

IMPORTANT: The line string reference is only valid during the callback. If you need to retain the line data, copy it.

Parameters
lineThe parsed line (valid only during callback)
ctxUser context pointer passed to lparseRegisterPush()
Returns
true to continue parsing, false to stop

Definition at line 158 of file lineparse.h.

Function Documentation

◆ lparseRegisterPush()

bool lparseRegisterPush ( StreamBuffer *  sb,
lparseLineCB  pline,
sbufCleanupCB  pcleanup,
void *  ctx,
uint32  flags 
)

bool lparseRegisterPush(StreamBuffer *sb, lparseLineCB pline, sbufCleanupCB pcleanup, void *ctx, uint32 flags)

Registers the line parser as a consumer with the stream buffer in push mode.

In push mode, the provided callback is automatically invoked for each line as data becomes available from the producer. This is useful for asynchronous processing or when you want lines to be handled as soon as they're ready.

Parameters
sbThe stream buffer
plineCallback function invoked for each line
pcleanupOptional cleanup callback invoked when parsing completes
ctxUser context pointer passed to callbacks
flagsConfiguration flags from LINEPARSER_FLAGS_ENUM
Returns
true on success, false if registration failed

Example:

bool handleLine(strref line, void *ctx) {
int *count = (int *)ctx;
(*count)++;
printf("Line %d: %s\n", *count, strC(line));
return true; // continue processing
}
int lineCount = 0;
StreamBuffer *sb = sbufCreate(4096);
lparseRegisterPush(sb, handleLine, NULL, &lineCount, LPARSE_LF);
sbufFileIn(sb, file, true); // triggers callbacks automatically
bool sbufFileIn(StreamBuffer *sb, VFSFile *file, bool close)
@ LPARSE_LF
Expect LF (Unix-style) line endings.
Definition lineparse.h:70
bool lparseRegisterPush(StreamBuffer *sb, lparseLineCB pline, sbufCleanupCB pcleanup, void *ctx, uint32 flags)
StreamBuffer * sbufCreate(size_t targetsz)
const char * strC(strref s)