LIRC libraries: /tmp/work/src/lirc-0.10.2/lib/line_buffer.cpp Source File

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
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
40std::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
56LineBuffer::LineBuffer()
57{
58 buff = "";
59}
LineBuffer::c_str
const char * c_str()
Peek the complete buffer contents.
Definition: line_buffer.cpp:34
LineBuffer::append
void append(const char *line, size_t size)
Insert data in buffer.
Definition: line_buffer.cpp:28
LineBuffer::get_next_line
std::string get_next_line()
Return and remove first line in buffer, possibly "".
Definition: line_buffer.cpp:40
LineBuffer::has_lines
bool has_lines()
Check if get_next_line() returns a non-empty string.
Definition: line_buffer.cpp:22
line_buffer.h
Implements the line buffer class.