LIRC libraries
Linux Infrared Remote Control
Loading...
Searching...
No Matches
line_buffer.cpp
Go to the documentation of this file.
1/**********************************************************************
2** line_buffer.cpp ****************************************************
3***********************************************************************
4*
5* line_buffer - line buffer for use with read(2)
6*
7* Copyright (c) 2015 Alec Leamas
8*
9* */
10
16#include <errno.h>
17#include <string.h>
18
19#include "line_buffer.h"
20
21
23{
24 return buff.find('\n') != std::string::npos;
25}
26
27
28void LineBuffer::append(const char* input, size_t size)
29{
30 buff.append(input, size);
31}
32
33
34const char* LineBuffer::c_str()
35{
36 return buff.c_str();
37}
38
39
41{
42 size_t nl = buff.find('\n');
43 if (nl == std::string::npos)
44 return "";
45 std::string line(buff.substr(0, nl + 1));
46 buff.erase(0, nl + 1);
47
48 /* remove DOS line endings */
49 size_t pos = line.rfind("\r");
50 if (pos == line.size() - 1)
51 line.erase(pos, 1);
52 return line;
53}
54
55
56LineBuffer::LineBuffer()
57{
58 buff = "";
59}
const char * c_str()
Peek the complete buffer contents.
void append(const char *line, size_t size)
Insert data in buffer.
std::string get_next_line()
Return and remove first line in buffer, possibly "".
bool has_lines()
Check if get_next_line() returns a non-empty string.
Implements the line buffer class.