Bitcoin Core 31.99.0
P2P Digital Currency
Public Member Functions | Private Attributes | List of all members
util::LineReader Class Reference

#include <string.h>

Public Member Functions

 LineReader (std::string_view str, size_t max_line_length)
 
std::optional< std::string_view > ReadLine () LIFETIMEBOUND
 Returns a string from current iterator position up to (but not including) next
and advances iterator to the character following the
on success. More...
 
std::string_view ReadLength (size_t len) LIFETIMEBOUND
 Returns string from current iterator position of specified length if possible and advances iterator on success. More...
 
size_t Remaining () const
 Returns remaining size of bytes in buffer. More...
 
size_t Consumed () const
 Returns number of bytes already read from buffer. More...
 

Private Attributes

const std::string_view m_str
 
const size_t m_max_line_length
 
std::string_view::iterator m_it
 

Detailed Description

Definition at line 268 of file string.h.

Constructor & Destructor Documentation

◆ LineReader()

util::LineReader::LineReader ( std::string_view  str,
size_t  max_line_length 
)
explicit

Definition at line 20 of file string.cpp.

Member Function Documentation

◆ Consumed()

size_t util::LineReader::Consumed ( ) const

Returns number of bytes already read from buffer.

Definition at line 73 of file string.cpp.

Here is the caller graph for this function:

◆ ReadLength()

std::string_view util::LineReader::ReadLength ( size_t  len)

Returns string from current iterator position of specified length if possible and advances iterator on success.

May exceed max_line_length but will not read past end of buffer.

Parameters
[in]lenThe number of bytes to read from the buffer
Returns
a string of the expected length.
Exceptions
astd::runtime_error if there is not enough data in the buffer.

Definition at line 59 of file string.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadLine()

std::optional< std::string_view > util::LineReader::ReadLine ( )

Returns a string from current iterator position up to (but not including) next
and advances iterator to the character following the
on success.

Will not return a line longer than max_line_length.

Returns
the next string from the buffer. std::nullopt if end of buffer is reached without finding a
.
Exceptions
astd::runtime_error if max_line_length + 1 bytes are read without finding
.

Definition at line 23 of file string.cpp.

Here is the caller graph for this function:

◆ Remaining()

size_t util::LineReader::Remaining ( ) const

Returns remaining size of bytes in buffer.

Definition at line 68 of file string.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ m_it

std::string_view::iterator util::LineReader::m_it
private

Definition at line 272 of file string.h.

◆ m_max_line_length

const size_t util::LineReader::m_max_line_length
private

Definition at line 271 of file string.h.

◆ m_str

const std::string_view util::LineReader::m_str
private

Definition at line 270 of file string.h.


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