Arduino DLNA Server
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tiny_dlna::SdFatParser Class Reference

Simple character-by-character parser that emits SdFatFileInfo via a callback. More...

#include <SdFatParser.h>

Inheritance diagram for tiny_dlna::SdFatParser:
Inheritance graph
[legend]

Public Member Functions

 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.
 

Protected Member Functions

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)
 

Protected Attributes

std::string name
 
void(* cb )(SdFatFileInfo &, void *ref) = nullptr
 
void * ref = nullptr
 
SdFatFileInfo info
 

Detailed Description

Simple character-by-character parser that emits SdFatFileInfo via a callback.

Typical usage:

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.

Constructor & Destructor Documentation

◆ SdFatParser()

tiny_dlna::SdFatParser::SdFatParser ( )
inline

Constructs the parser and reserves internal buffer capacity.

Member Function Documentation

◆ 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
cbA function pointer taking an SdFatFileInfo& and user reference. The callback may be null to disable notifications.
refOpaque 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
cThe 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.

Member Data Documentation

◆ cb

void(* tiny_dlna::SdFatParser::cb) (SdFatFileInfo &, void *ref) = nullptr
protected

User-provided callback invoked after each parsed line.

◆ info

SdFatFileInfo tiny_dlna::SdFatParser::info
protected

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: