21 #ifndef G_NET_LINE_BUFFER__H
22 #define G_NET_LINE_BUFFER__H
31 class LineBufferConfig ;
32 class LineBufferIterator ;
56 G_EXCEPTION( ErrorOverflow ,
"line buffer overflow" ) ;
61 void add(
const std::string & data ) ;
64 void add(
const char * data ,
size_t size ) ;
75 std::string
eol()
const ;
81 template <
typename Tsink>
82 void apply(
const char * data ,
size_t data_size , Tsink sink ) ;
112 void precheck(
size_t ) ;
113 void linecheck(
size_t ) ;
115 void addextra(
const char * ,
size_t ) ;
117 const char * extraeol()
const ;
122 size_t m_warn_limit ;
123 size_t m_fail_limit ;
124 std::string m_store ;
125 const char * m_extra_data ;
126 size_t m_extra_size ;
130 const char * m_line_data ;
156 std::string
line()
const ;
159 std::string
eol()
const ;
178 size_t warn = 0U ,
size_t fail = 0U ) ;
186 const std::string &
eol()
const ;
189 size_t warn()
const ;
192 size_t fail()
const ;
239 template <
typename T>
242 addextra( data , size ) ;
260 return m_buffer.more() ;
266 return std::string( m_buffer.lineData() , m_buffer.lineSize() ) ;
272 return m_buffer.eolSize() == 0U ? std::string() : m_buffer.eol() ;
278 return m_buffer.lineData() ;
284 return m_buffer.lineSize() ;
290 return m_buffer.eolSize() ;
std::string eol() const
Returns the current line ending but returns the empty string if currently inside an expect() block...
static LineBufferConfig newline()
Convenience factory function.
static LineBufferConfig http()
Convenience factory function.
static LineBufferConfig pop()
Convenience factory function.
void expect(size_t n)
The next 'n' bytes extracted will be extracted in one contiguous block, without regard to line ending...
const char * lineData() const
See LineBuffer::lineData().
Syntactic sugar for calling GNet::LineBuffer iteration methods.
std::string line() const
Returns the current line.
bool more()
Returns true if there is lineData() to be had.
size_t eolSize() const
See LineBuffer::eolSize().
LineBufferIterator(LineBuffer &buffer)
Constructor.
A configuration structure for GNet::LineBuffer.
static LineBufferConfig autodetect()
Convenience factory function.
LineBufferConfig(const std::string &eol=std::string(1U,'\n'), size_t warn=0U, size_t fail=0U)
Constructor.
LineBuffer(LineBufferConfig)
Constructor.
const std::string & eol() const
Returns the end-of-line string as passed to the constructor.
static LineBufferConfig smtp()
Convenience factory function.
size_t lineSize() const
See LineBuffer::lineSize().
static LineBufferConfig crlf()
Convenience factory function.
void add(const std::string &data)
Adds a data segment.
A class that does line buffering, supporting auto-detection of line endings and fixed-size extraction...
size_t lineSize() const
Returns the size of the current line, excluding the line ending.
size_t eolSize() const
Returns the size of current line ending.
std::string eol() const
Returns the end-of-line string as passed in to the constructor, or as auto-detected.
size_t warn() const
Returns the warn-limit, as passed to the constructor.
const char * lineData() const
Returns a pointer for the current line, including the line ending.
size_t fail() const
Returns the fail-limit, as passed to the constructor.
void apply(const char *data, size_t data_size, Tsink sink)
Adds the data and passes complete lines to the sink functor with line-data, line-size and eol-size pa...
bool more()
See LineBuffer::more().