32 m_eol_length(eol.length()) ,
33 m_p(std::string::npos) ,
34 m_current_valid(false) ,
41 void GNet::LineBuffer::lock()
49 m_current_valid = false ;
50 m_store.erase( 0U , n ) ;
51 if( m_p != std::string::npos )
59 m_store.append( p , n ) ;
73 if( (m_store.length()+n) > m_limit )
77 m_p = std::string::npos ;
79 m_current_valid = false ;
85 G_ERROR(
"GNet::LineBuffer::check: line too long: discarding " << total <<
" bytes" ) ;
91 if( m_p == std::string::npos )
94 start = (start+1U) > m_eol_length ? (start+1U-m_eol_length) : 0U ;
95 m_p = m_store.find( m_eol , start ) ;
101 return m_p != std::string::npos ;
106 G_ASSERT( m_p != std::string::npos ) ;
109 if( ! m_current_valid )
112 this_->m_current = std::string( m_store , 0U , m_p ) ;
113 this_->m_current_valid = true ;
120 G_ASSERT( m_p != std::string::npos ) ;
124 m_current_valid = false ;
125 m_store.erase( 0U , m_p + m_eol_length ) ;
126 m_p = m_store.find( m_eol ) ;
131 std::string s( current() ) ;
140 return m_b.m_p != std::string::npos ;
150 m_b.m_current.resize( n ) ;
151 m_b.m_current.replace( 0U , n , m_b.m_store.data() + m_n , n ) ;
152 m_n = m_b.m_p + m_b.m_eol_length ;
153 m_b.m_p = m_n == m_store_length ? std::string::npos : m_b.m_store.find(m_b.m_eol,m_n) ;
154 return m_b.m_current ;
void add(const std::string &segment)
Adds a data segment.
const std::string & current() const
Returns the current line, without extracting it.
std::string::size_type size_type
A std::size_t type.
bool more() const
Returns true if there is a line() to be had.
LineBuffer(const std::string &eol=std::string("\n"), bool do_throw_on_overflow=false)
Constructor.
const std::string & line()
Returns the current line and increments the iterator.
A class which does line buffering.
std::string line()
Extracts a line and returns it as a string.
bool more() const
Returns true if there are complete line(s) to be extracted.
void discard()
Discards the current line.