Simple character-by-character parser that emits SdFatFileInfo via a callback.
More...
#include <SdFatParser.h>
|
| | SdFatParser () |
| | Constructs the parser and reserves internal buffer capacity.
|
| |
| size_t | write (uint8_t c) override |
| | Consumes one character of input.
|
| |
| void | setCallback (void(*cb)(SdFatFileInfo &, void *ref), void *ref=nullptr) |
| | Sets the callback that receives parsed entries.
|
| |
|
| int | spaceCount () |
| | Counts leading spaces in the current line buffer.
|
| |
| void | parse () |
| | Parses the accumulated line and emits a callback if set.
|
| |
| void | rtrim (std::string &s) |
| |
| void | ltrim (std::string &s) |
| |
| void | trim (std::string &s) |
| |
Simple character-by-character parser that emits SdFatFileInfo via a callback.
Typical usage:
- Create an instance.
- Provide a callback with setCallback().
- Stream characters into the instance using Print::write() or print().
The parser treats each newline ('
') as the end of one listing line. It uses the number of leading spaces to compute the nesting level (2 spaces = 1 level). A trailing '/' marks a directory entry.
◆ SdFatParser()
| tiny_dlna::SdFatParser::SdFatParser |
( |
| ) |
|
|
inline |
Constructs the parser and reserves internal buffer capacity.
◆ ltrim()
| void tiny_dlna::SdFatParser::ltrim |
( |
std::string & |
s | ) |
|
|
inlineprotected |
◆ parse()
| void tiny_dlna::SdFatParser::parse |
( |
| ) |
|
|
inlineprotected |
Parses the accumulated line and emits a callback if set.
Determines nesting level from leading spaces (2 spaces == 1 level), strips the indentation, infers directory status from a trailing '/', and notifies the user callback.
◆ rtrim()
| void tiny_dlna::SdFatParser::rtrim |
( |
std::string & |
s | ) |
|
|
inlineprotected |
◆ setCallback()
| void tiny_dlna::SdFatParser::setCallback |
( |
void(*)(SdFatFileInfo &, void *ref) |
cb, |
|
|
void * |
ref = nullptr |
|
) |
| |
|
inline |
Sets the callback that receives parsed entries.
- Parameters
-
| cb | A function pointer taking an SdFatFileInfo& and user reference. The callback may be null to disable notifications. |
| ref | Opaque user data passed back to the callback. |
◆ spaceCount()
| int tiny_dlna::SdFatParser::spaceCount |
( |
| ) |
|
|
inlineprotected |
Counts leading spaces in the current line buffer.
- Returns
- Number of consecutive spaces from the beginning of the buffer.
◆ trim()
| void tiny_dlna::SdFatParser::trim |
( |
std::string & |
s | ) |
|
|
inlineprotected |
◆ write()
| size_t tiny_dlna::SdFatParser::write |
( |
uint8_t |
c | ) |
|
|
inlineoverride |
Consumes one character of input.
- Parameters
-
| c | The character to process. |
- Returns
- Always returns 1 to conform to Print::write contract.
Processing rules:
- On '
': finishes the current line and triggers parsing/callback.
- On '\t': ignored (tabs are skipped).
- Otherwise: appended to the current line buffer.
◆ cb
User-provided callback invoked after each parsed line.
◆ info
Reused struct populated for each parsed entry to minimize allocations.
◆ name
| std::string tiny_dlna::SdFatParser::name |
|
protected |
Accumulates characters until a newline terminates the line.
◆ ref
| void* tiny_dlna::SdFatParser::ref = nullptr |
|
protected |
Opaque user pointer returned to the callback.
The documentation for this class was generated from the following file: