LIRC libraries: /home/mk/tmp/lirc/lib/line_buffer.cpp (6f8ea22 2016-08-09 14:47:27 +0200) Source File

| LIRC libraries LinuxInfraredRemoteControl

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
22 bool LineBuffer::has_lines()
23 {
24 return buff.find('\n') != std::string::npos;
25 }
26
27
28 void LineBuffer::append(const char* input, size_t size)
29 {
30 buff.append(input, size);
31 }
32
33
34 const char* LineBuffer::c_str()
35 {
36 return buff.c_str();
37 }
38
39
40 std::string LineBuffer::get_next_line()
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
56 LineBuffer::LineBuffer()
57 {
58 buff = "";
59 }
LineBuffer::get_next_line
std::string get_next_line()
Definition: line_buffer.cpp:40
LineBuffer::c_str
const char * c_str()
Definition: line_buffer.cpp:34
LineBuffer::append
void append(const char *line, size_t size)
Definition: line_buffer.cpp:28
LineBuffer::has_lines
bool has_lines()
Definition: line_buffer.cpp:22