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:
- Reading text files line by line
- Processing log files
- Parsing configuration files
- Any line-oriented data processing
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):
string line = 0;
}
@ FS_Read
Open for reading.
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.
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.
Example (push mode):
bool processLine(strref line, void *ctx) {
return true;
}
bool sbufFileIn(StreamBuffer *sb, VFSFile *file, bool close)
@ LPARSE_LF
Expect LF (Unix-style) line endings.
bool lparseRegisterPush(StreamBuffer *sb, lparseLineCB pline, sbufCleanupCB pcleanup, void *ctx, uint32 flags)