summaryrefslogtreecommitdiff
path: root/src/line.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/line.cc')
-rw-r--r--src/line.cc23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/line.cc b/src/line.cc
index 8ee7134..23370fc 100644
--- a/src/line.cc
+++ b/src/line.cc
@@ -29,7 +29,7 @@ class ReaderImpl : public Reader {
search_(rptr_),
end_(buffer_.get() + check::add(max_len, static_cast<size_t>(2))) {}
- [[nodiscard]] std::expected<std::string_view, ReadError> read() override {
+ [[nodiscard]] std::expected<std::string_view, io::ReadError> read() override {
while (true) {
search_ = std::find_first_of(search_, wptr_, kLineTerminators,
kLineTerminators + 2);
@@ -45,12 +45,11 @@ class ReaderImpl : public Reader {
if (search_ + 1 == wptr_) {
make_space_if_needed();
auto got = fill();
- if (got.has_value()) {
- if (got.value() == 0) {
+ if (!got.has_value()) {
+ if (got.error() == io::ReadError::Eof) {
return line(search_ - rptr_, 1);
}
- } else {
- return std::unexpected(ReadError(got.error()));
+ return std::unexpected(got.error());
}
}
if (search_[1] == '\n') {
@@ -67,15 +66,11 @@ class ReaderImpl : public Reader {
make_space_if_needed();
auto got = fill();
- if (got.has_value()) {
- if (got.value() == 0) {
- if (rptr_ == wptr_) {
- return std::unexpected(ReadError());
- }
+ if (!got.has_value()) {
+ if (got.error() == io::ReadError::Eof && rptr_ != wptr_) {
return line(wptr_ - rptr_, 0);
}
- } else {
- return std::unexpected(ReadError(got.error()));
+ return std::unexpected(got.error());
}
}
}
@@ -124,10 +119,6 @@ class ReaderImpl : public Reader {
} // namespace
-ReadError::ReadError() : eof(true) {}
-
-ReadError::ReadError(io::ReadError error) : eof(false), io_error(error) {}
-
std::unique_ptr<Reader> open(std::unique_ptr<io::Reader> reader,
size_t max_len) {
return std::make_unique<ReaderImpl>(std::move(reader), max_len);