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.

29 lines
561 B
C++
Raw Normal View History

2017-10-11 09:48:27 -04:00
#include <nntpchan/line.hpp>
2016-10-15 12:37:59 -04:00
2017-10-17 10:29:56 -04:00
namespace nntpchan
{
2016-10-15 12:37:59 -04:00
2017-10-17 10:29:56 -04:00
LineReader::LineReader(size_t limit) : m_close(false), lineLimit(limit) {}
2017-05-03 08:09:23 -04:00
2017-10-17 10:29:56 -04:00
void LineReader::Data(const char *data, ssize_t l)
{
if (l <= 0)
return;
2018-05-03 13:38:35 -04:00
m_line << m_leftover;
m_leftover = "";
m_line << std::string(data, l);
for(std::string line; std::getline(m_line, line); )
2016-10-15 12:37:59 -04:00
{
2018-05-03 13:38:35 -04:00
line.erase(std::remove(line.begin(), line.end(), '\r'), line.end());
HandleLine(line);
2016-10-15 12:37:59 -04:00
}
2018-05-03 13:38:35 -04:00
if(m_line)
m_leftover = m_line.str();
m_line.clear();
2017-10-17 10:29:56 -04:00
}
2016-10-15 12:37:59 -04:00
2017-10-17 10:29:56 -04:00
bool LineReader::ShouldClose() { return m_close; }
2016-10-15 12:37:59 -04:00
}