diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-09-22 23:38:21 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-09-22 23:38:21 +0200 |
| commit | ce271f82f16ee89a18e7bfc9ed8eab7cbd6f37bc (patch) | |
| tree | 3e568faf83ae750aa244cca87b55951c7401ef03 /src/uline.cc | |
| parent | 50348284f5d82ccfd65b0c803ba0ba895912ceff (diff) | |
Change io::Reader and company to return ReadError::Eof instead of 0.
It's debatable if Eof should be considered an error or not.
But it is pretty clear it generally is a special response that
needs special handling, so easier to keep with the unexpected lot.
Also keeps better at higher abstraction levels, such as the line
reader.
Diffstat (limited to 'src/uline.cc')
| -rw-r--r-- | src/uline.cc | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/uline.cc b/src/uline.cc index 7d4c7c7..358f36c 100644 --- a/src/uline.cc +++ b/src/uline.cc @@ -30,7 +30,7 @@ class UnicodeReader { end_(buffer_.get() + check::add(max_len, static_cast<size_t>(2))) {} [[nodiscard]] - std::expected<std::basic_string_view<T>, line::ReadError> read() { + std::expected<std::basic_string_view<T>, io::ReadError> read() { while (true) { search_ = std::find_first_of(search_, wptr_, line_terminators_.begin(), line_terminators_.end()); @@ -46,12 +46,11 @@ class UnicodeReader { 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(line::ReadError(got.error())); + return std::unexpected(got.error()); } } if (search_[1] == line_terminators_[1]) { @@ -68,15 +67,11 @@ class UnicodeReader { make_space_if_needed(); auto got = fill(); - if (got.has_value()) { - if (got.value() == 0) { - if (rptr_ == wptr_) { - return std::unexpected(line::ReadError()); - } + if (!got.has_value()) { + if (got.error() == io::ReadError::Eof && rptr_ != wptr_) { return line(wptr_ - rptr_, 0); } - } else { - return std::unexpected(line::ReadError(got.error())); + return std::unexpected(got.error()); } } } @@ -138,7 +133,7 @@ class ReaderImpl : public UnicodeReader<char, u8::Reader>, {'\r', '\n'}) {} [[nodiscard]] - std::expected<std::string_view, ::line::ReadError> read() override { + std::expected<std::string_view, io::ReadError> read() override { return UnicodeReader<char, u8::Reader>::read(); } @@ -170,7 +165,7 @@ class ReaderImpl : public UnicodeReader<char16_t, u16::Reader>, {u'\r', u'\n'}) {} [[nodiscard]] - std::expected<std::u16string_view, ::line::ReadError> read() override { + std::expected<std::u16string_view, io::ReadError> read() override { return UnicodeReader<char16_t, u16::Reader>::read(); } |
