Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.
nntpchan/contrib/frontends/cpp/nntpchan-daemon/src/line.cpp

45 lines
822 B
C++
Raw Normal View History

2016-10-15 21:37:59 +05:00
#include "line.hpp"
#include <iostream>
namespace nntpchan {
void LineReader::OnData(const char * d, ssize_t l)
{
if(l <= 0) return;
std::size_t idx = 0;
while(l-- > 0) {
char c = d[idx++];
if(c == '\n') {
OnLine(d, idx-2);
d += idx;
2016-10-15 22:53:35 +05:00
} else if (c == '\r' && d[idx] == '\n') {
OnLine(d, idx-2);
d += idx + 1;
2016-10-15 21:37:59 +05:00
}
}
}
void LineReader::OnLine(const char *d, const size_t l)
{
std::string line(d, l);
HandleLine(line);
}
bool LineReader::HasNextLine()
{
return m_sendlines.size() > 0;
}
std::string LineReader::GetNextLine()
{
std::string line = m_sendlines[0];
m_sendlines.pop_front();
return line;
}
void LineReader::QueueLine(const std::string & line)
{
m_sendlines.push_back(line);
}
}