1 #ifndef BLANK_IO_LINEBUFFER_HPP_
2 #define BLANK_IO_LINEBUFFER_HPP_
11 template<std::size_t size>
15 explicit LineBuffer(char term = '\n') noexcept
20 char *begin() noexcept {
23 const char *begin() const noexcept {
26 char *end() noexcept {
29 const char *end() const noexcept {
33 /// extract one line from the buffer, terminator not included
34 /// @return false if the buffer does not contain a complete line
35 bool Extract(std::string &line) {
36 char *line_end = std::find(begin(), end(), term);
37 if (line_end == end()) {
40 line.assign(begin(), line_end);
42 std::move(line_end, end(), begin());
43 head -= std::distance(begin(), line_end);
47 /// get a pointer to append data to the buffer
48 /// it is safe to write at most Remain() bytes
49 char *WriteHead() noexcept {
53 // call when data has been written to WriteHead()
54 void Update(std::size_t written) {
55 assert(written <= Remain());
59 std::size_t Remain() const noexcept {
60 return std::distance(end(), buffer + size);