summaryrefslogtreecommitdiff
path: root/src/u16.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/u16.hh')
-rw-r--r--src/u16.hh11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/u16.hh b/src/u16.hh
index 781e6a4..d6a3672 100644
--- a/src/u16.hh
+++ b/src/u16.hh
@@ -38,19 +38,24 @@ std::expected<uint32_t, u::ReadError> read(T& start, const T& end) {
template<std::forward_iterator T>
requires std::is_same_v<std::iter_value_t<T>, uint16_t>
std::expected<uint32_t, u::ReadErrorReplace> read_replace(T& start,
- const T& end) {
+ const T& end,
+ bool eof) {
+ auto const tmp = start;
auto ret = read(start, end);
if (ret.has_value())
return *ret;
switch (ret.error()) {
case u::ReadError::Incomplete:
+ if (eof)
+ break;
return std::unexpected(u::ReadErrorReplace::Incomplete);
case u::ReadError::End:
return std::unexpected(u::ReadErrorReplace::End);
case u::ReadError::Invalid:
- return 0xfffd;
+ break;
}
- std::unreachable();
+ start = tmp + 1;
+ return 0xfffd;
}
template<std::forward_iterator T>