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

Modules

 Line Parser Flags
 
 Pull Mode
 
 Push Mode
 

Detailed Description

Stream buffer consumer that parses line-by-line input.

The line parser is a specialized consumer that processes stream buffer data one line at a time. It automatically handles different line ending conventions (LF, CRLF, or mixed) and provides both pull and push mode operation.

Common Use Cases:

Pull Mode: Register the parser with lparseRegisterPull(), then repeatedly call lparseLine() to retrieve each line.

Push Mode: Register with lparseRegisterPush() and provide a callback that is invoked for each line as data becomes available.

Example (pull mode):

VFSFile *file = vfsOpen(vfs, _S"config.txt", FS_Read);
StreamBuffer *sb = sbufCreate(4096);
sbufFilePRegisterPull(sb, file, true);
string line = 0;
while (lparseLine(sb, &line)) {
// process line
}
strDestroy(&line);
@ FS_Read
Open for reading.
Definition file.h:36
struct VFSFile VFSFile
Definition vfs.h:44
VFSFile * vfsOpen(VFS *vfs, strref path, flags_t flags)
bool sbufFilePRegisterPull(StreamBuffer *sb, VFSFile *file, bool close)
@ LPARSE_Auto
Auto-detect line ending style from first line found.
Definition lineparse.h:66
bool lparseLine(StreamBuffer *sb, string *out)
bool lparseRegisterPull(StreamBuffer *sb, uint32 flags)
StreamBuffer * sbufCreate(size_t targetsz)
void strDestroy(strhandle ps)
#define _S
Creates a static ASCII string from a string literal.
Definition strbase.h:392

Example (push mode):

bool processLine(strref line, void *ctx) {
// process each line
return true; // continue parsing
}
VFSFile *file = vfsOpen(vfs, _S"data.txt", FS_Read);
StreamBuffer *sb = sbufCreate(4096);
lparseRegisterPush(sb, processLine, NULL, NULL, LPARSE_LF);
sbufFileIn(sb, file, true); // automatically calls processLine for each line
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)