delpi  0.0.1
DElta-complete LP solver
Loading...
Searching...
No Matches
BufferLineSource.cpp
Go to the documentation of this file.
1
8
9#include "delpi/util/error.h"
10
11namespace delpi {
12BufferLineSource::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
16bool 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
28void BufferLineSource::initialize(const char *data, const std::size_t length) {
29 cur_ = data;
30 end_ = data + length;
31}
32
33} // namespace delpi
const char * end_
Pointer to the end of the buffer.
const char * cur_
Pointer to the current position in the buffer.
void initialize(const char *data, std::size_t length)
Force a reinitialization of the object, setting cur_ and end_ to the new values.
bool nextLine(std::string_view &out)
Retrieve the next line from the buffer.
Global namespace for the delpi library.