ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR > Class Template Reference

Collects bytes into NUL terminated lines of up to N - 1 characters; IGNORE_CHAR bytes are skipped and an overlong line is dropped up to its terminator. More...

#include <line_reader.h>

Public Member Functions

char * feed (uint8_t c)
 Feed one byte; returns the completed line (empty lines included), valid until the next call, or nullptr.
 
char * feed (uint8_t c, size_t &len)
 As feed(c), and sets len to the line length when a line is returned.
 
size_t length () const
 Length of the partial line; 0 after a line is returned and while an overlong line is dropped.
 
const char * partial ()
 The partial line, NUL terminated, for prompts with no line end; the first N - 1 characters on the byte that overflowed, empty while the rest of that line is dropped.
 
bool overflowed () const
 True only right after the feed() that found the line too long; the rest of that line is then dropped.
 
void log_if_overflowed (const char *tag) const
 Log the shared "line dropped" warning when the last feed() overflowed.
 
void reset ()
 Forget the partial line and start a new one with the next byte.
 
void restart_with (uint8_t c)
 Start a new line with c, e.g. the byte that overflowed; c must not be TERMINATOR_CHAR or IGNORE_CHAR.
 
void discard_line ()
 Drop everything up to and including the next terminator.
 

Protected Member Functions

pos_t end_ () const
 

Protected Attributes

char buf_ [N]
 
pos_t pos_ {0}
 

Detailed Description

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
class esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >

Collects bytes into NUL terminated lines of up to N - 1 characters; IGNORE_CHAR bytes are skipped and an overlong line is dropped up to its terminator.

Definition at line 15 of file line_reader.h.

Member Function Documentation

◆ discard_line()

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
void esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::discard_line ( )
inline

Drop everything up to and including the next terminator.

Definition at line 85 of file line_reader.h.

◆ end_()

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
pos_t esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::end_ ( ) const
inlineprotected

Definition at line 88 of file line_reader.h.

◆ feed() [1/2]

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
char * esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::feed ( uint8_t c)
inline

Feed one byte; returns the completed line (empty lines included), valid until the next call, or nullptr.

Definition at line 23 of file line_reader.h.

◆ feed() [2/2]

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
char * esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::feed ( uint8_t c,
size_t & len )
inline

As feed(c), and sets len to the line length when a line is returned.

Definition at line 29 of file line_reader.h.

◆ length()

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
size_t esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::length ( ) const
inline

Length of the partial line; 0 after a line is returned and while an overlong line is dropped.

Definition at line 56 of file line_reader.h.

◆ log_if_overflowed()

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
void esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::log_if_overflowed ( const char * tag) const
inline

Log the shared "line dropped" warning when the last feed() overflowed.

Definition at line 69 of file line_reader.h.

◆ overflowed()

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
bool esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::overflowed ( ) const
inline

True only right after the feed() that found the line too long; the rest of that line is then dropped.

Definition at line 66 of file line_reader.h.

◆ partial()

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
const char * esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::partial ( )
inline

The partial line, NUL terminated, for prompts with no line end; the first N - 1 characters on the byte that overflowed, empty while the rest of that line is dropped.

Definition at line 60 of file line_reader.h.

◆ reset()

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
void esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::reset ( )
inline

Forget the partial line and start a new one with the next byte.

Definition at line 76 of file line_reader.h.

◆ restart_with()

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
void esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::restart_with ( uint8_t c)
inline

Start a new line with c, e.g. the byte that overflowed; c must not be TERMINATOR_CHAR or IGNORE_CHAR.

Definition at line 79 of file line_reader.h.

Field Documentation

◆ buf_

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
char esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::buf_[N]
protected

Definition at line 95 of file line_reader.h.

◆ pos_

template<size_t N, char TERMINATOR_CHAR = '\n', char IGNORE_CHAR = '\r'>
pos_t esphome::LineReader< N, TERMINATOR_CHAR, IGNORE_CHAR >::pos_ {0}
protected

Definition at line 96 of file line_reader.h.


The documentation for this class was generated from the following file: