delpi
0.0.1
DElta-complete LP solver
Toggle main menu visibility
Loading...
Searching...
No Matches
BufferLineSource.cpp
Go to the documentation of this file.
1
7
#include "
delpi/parser/BufferLineSource.h
"
8
9
#include "delpi/util/error.h"
10
11
namespace
delpi
{
12
BufferLineSource::BufferLineSource(
const
char
*data,
const
std::size_t length) : cur_{data}, end_{data + length} {
13
DELPI_ASSERT(data !=
nullptr
|| length == 0,
"Data pointer cannot be null with a positive length"
);
14
}
15
16
bool
BufferLineSource::nextLine
(std::string_view &out) {
17
if
(
cur_
>=
end_
)
return
false
;
18
const
char
*start =
cur_
;
19
while
(
cur_
<
end_
&& *
cur_
!=
'\n'
) ++
cur_
;
20
std::size_t len =
static_cast<
std::size_t
>
(
cur_
- start);
21
// Strip \r
22
if
(len > 0 && start[len - 1] ==
'\r'
) --len;
23
if
(
cur_
<
end_
) ++
cur_
;
// skip '\n'
24
out = {start, len};
25
return
true
;
26
}
27
28
void
BufferLineSource::initialize
(
const
char
*data,
const
std::size_t length) {
29
cur_
= data;
30
end_
= data + length;
31
}
32
33
}
// namespace delpi
BufferLineSource.h
delpi::BufferLineSource::end_
const char * end_
Pointer to the end of the buffer.
Definition
BufferLineSource.h:50
delpi::BufferLineSource::cur_
const char * cur_
Pointer to the current position in the buffer.
Definition
BufferLineSource.h:49
delpi::BufferLineSource::initialize
void initialize(const char *data, std::size_t length)
Force a reinitialization of the object, setting cur_ and end_ to the new values.
Definition
BufferLineSource.cpp:28
delpi::BufferLineSource::nextLine
bool nextLine(std::string_view &out)
Retrieve the next line from the buffer.
Definition
BufferLineSource.cpp:16
delpi
Global namespace for the delpi library.
delpi
parser
BufferLineSource.cpp
Generated by
1.17.0