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

Macros

#define lparseCreatePull(sb, ...)   _lparseCreatePull(sb, opt_flags(__VA_ARGS__))
 

Functions

bool lparseLine (LineParser *lp, string *out)
 

Detailed Description

Pull-mode line parsing where the consumer explicitly requests each line.

Macro Definition Documentation

◆ lparseCreatePull

#define lparseCreatePull (   sb,
  ... 
)    _lparseCreatePull(sb, opt_flags(__VA_ARGS__))

LineParser *lparseCreatePull(StreamBuffer *sb, [flags])

Creates a line parser that reads on demand.

The parser is the driving consumer, so it registers nothing with the stream buffer; call lparseLine() for each line. Use this on a stream buffer that has a pull producer attached.

Parameters
sbThe stream buffer
...(flags) Configuration flags from LINEPARSER_FLAGS_ENUM
Returns
New line parser (destroy with lparseDestroy)

Example:

StreamBuffer *sb = sbufCreate(4096);
sbufFilePRegisterPull(sb, file, true);
LineParser *lp = lparseCreatePull(sb, LPARSE_Auto);
string line = 0;
while (lparseLine(lp, &line)) {
// Process each line
printf("Line: %s\n", strZ(line));
}
strDestroy(&line);
@ LPARSE_Auto
Auto-detect line ending style from first line found.
Definition lineparse.h:78
bool lparseLine(LineParser *lp, string *out)
#define lparseCreatePull(sb,...)
Definition lineparse.h:143
void lparseDestroy(LineParser **lp)
#define sbufCreate(targetsz,...)
Definition streambuf.h:275
void strDestroy(strhandle ps)

Definition at line 143 of file lineparse.h.

Function Documentation

◆ lparseLine()

bool lparseLine ( LineParser *  lp,
string *  out 
)

Retrieves the next line from the stream buffer.

Call this repeatedly after lparseCreatePull(). It returns false once the input runs out, which happens when the stream ends, when it fails, or when the producer detaches.

Parameters
lpThe line parser
outString to receive the line content (cleared and populated)
Returns
true if a line was read, false when no more lines are available