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

Macros

#define lparseCreatePush(sb, pline, ...)   _lparseCreatePush(sb, pline, opt_flags(__VA_ARGS__))
 

Typedefs

typedef bool(* lparseLineCB) (stvlist *cvars, strref line)
 

Detailed Description

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

Macro Definition Documentation

◆ lparseCreatePush

#define lparseCreatePush (   sb,
  pline,
  ... 
)    _lparseCreatePush(sb, pline, opt_flags(__VA_ARGS__))

LineParser *lparseCreatePush(StreamBuffer *sb, closure pline, [flags])

Creates a line parser that is called as data arrives.

The parser registers as the stream buffer's consumer, so the producer drives: the closure runs for each line as soon as enough data is there. A last line with no EOL is delivered when the producer calls sbufClose().

Takes ownership of the closure whether or not the parser is created. It is destroyed along with the parser.

Parameters
sbThe stream buffer
plineClosure created with closureCreateAs(lparseLineCB, ...)
...(flags) Configuration flags from LINEPARSER_FLAGS_ENUM
Returns
New line parser, or NULL if a consumer is already attached to the stream buffer

Example:

bool handleLine(stvlist *cvars, strref line) {
int *count = stvlAtPtr(cvars, 0);
(*count)++;
printf("Line %d: %s\n", *count, strC(line));
return true; // continue processing
}
int lineCount = 0;
StreamBuffer *sb = sbufCreate(4096);
LineParser *lp = lparseCreatePush(sb,
closureCreateAs(lparseLineCB, handleLine, stvar(ptr, &lineCount)), LPARSE_LF);
sbufFileIn(sb, file, true); // triggers callbacks automatically
#define closureCreateAs(sigtype, func,...)
Definition closure.h:168
@ LPARSE_LF
Expect LF (Unix-style) line endings.
Definition lineparse.h:82
#define lparseCreatePush(sb, pline,...)
Definition lineparse.h:210
bool(* lparseLineCB)(stvlist *cvars, strref line)
Definition lineparse.h:171
void lparseDestroy(LineParser **lp)
#define sbufCreate(targetsz,...)
Definition streambuf.h:275
void sbufClose(StreamBuffer *sb)
const char * strC(strref s)
#define stvar(typen, val)
Definition stvar.h:162
#define stvlAtPtr(list, idx)
Definition stvar.h:874

Definition at line 210 of file lineparse.h.

Typedef Documentation

◆ lparseLineCB

typedef bool(* lparseLineCB) (stvlist *cvars, strref line)

Line callback, for a parser created with lparseCreatePush()

Create it with closureCreateAs(lparseLineCB, func, ...). Runs for each line found in the stream buffer. The line is only valid during the call; copy it to keep it.

Parameters
cvarsCaptured variables of the closure
lineThe parsed line (valid only during the call)
Returns
true to continue parsing, false to stop

Definition at line 171 of file lineparse.h.