| #include <stdplus/exception.hpp> |
| #include <stdplus/fd/line.hpp> |
| #include <stdplus/fd/ops.hpp> |
| LineReader::LineReader(Fd& fd) : fd(fd) {} |
| const std::string* LineReader::readLine() |
| throw exception::Eof("readLine"); |
| buf_data = read(fd, buf); |
| catch (const exception::Eof&) |
| for (size_t i = 0; i < buf_data.size(); ++i) |
| auto oldsize = line.size(); |
| line.resize(oldsize + i); |
| std::memcpy(line.data() + oldsize, buf_data.data(), i); |
| buf_data = buf_data.subspan(i + 1); |
| auto oldsize = line.size(); |
| line.resize(oldsize + buf_data.size()); |
| std::memcpy(line.data() + oldsize, buf_data.data(), buf_data.size()); |