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/backends/nntpchan-daemon/libnntpchan/line.cpp

46 lines
757 B
C++
Raw Normal View History

2017-10-11 18:48:27 +05:00
#include <nntpchan/line.hpp>
2016-10-15 21:37:59 +05:00
2017-10-17 19:29:56 +05:00
namespace nntpchan
{
2016-10-15 21:37:59 +05:00
2017-10-17 19:29:56 +05:00
LineReader::LineReader(size_t limit) : m_close(false), lineLimit(limit) {}
2017-05-03 17:09:23 +05:00
2017-10-17 19:29:56 +05:00
void LineReader::Data(const char *data, ssize_t l)
{
if (l <= 0)
return;
// process leftovers
std::size_t idx = 0;
std::size_t pos = 0;
while (l-- > 0)
2016-10-15 21:37:59 +05:00
{
2017-10-17 19:29:56 +05:00
char c = data[idx++];
if (c == '\n')
{
OnLine(data, pos);
pos = 0;
data += idx;
}
else if (c == '\r' && data[idx] == '\n')
{
OnLine(data, pos);
data += idx + 1;
pos = 0;
}
else
{
pos++;
2016-10-15 21:37:59 +05:00
}
}
2017-10-17 19:29:56 +05:00
}
2016-10-15 21:37:59 +05:00
2017-10-17 19:29:56 +05:00
void LineReader::OnLine(const char *d, const size_t l)
{
std::string line;
line += std::string(d, l);
HandleLine(line);
}
2016-10-15 21:37:59 +05:00
2017-10-17 19:29:56 +05:00
bool LineReader::ShouldClose() { return m_close; }
2016-10-15 21:37:59 +05:00
}