diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-09-15 21:15:53 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-09-15 21:15:53 +0200 |
| commit | aa49abdf239bae6065fddd0839ec67a404c9748c (patch) | |
| tree | 631fbb2df58aa35df3d60c65c037ef74b1807114 /src/umod8.hh | |
| parent | bf41a601fd0447bcf3a2937a595a1cd8ca5c1633 (diff) | |
Add .clang-format
Make it easier to keep a consistent style
Diffstat (limited to 'src/umod8.hh')
| -rw-r--r-- | src/umod8.hh | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/umod8.hh b/src/umod8.hh index b91b199..4731942 100644 --- a/src/umod8.hh +++ b/src/umod8.hh @@ -1,9 +1,9 @@ #ifndef UMOD8_HH #define UMOD8_HH -#include "u.hh" // IWYU pragma: export +#include "u.hh" // IWYU pragma: export -#include <cstdint> // IWYU pragma: export +#include <cstdint> // IWYU pragma: export #include <expected> #include <iterator> #include <type_traits> @@ -11,10 +11,11 @@ namespace umod8 { -template<std::forward_iterator T> +template <std::forward_iterator T> requires std::is_same_v<std::iter_value_t<T>, uint8_t> std::expected<uint32_t, u::ReadError> read(T& start, const T& end) { - if (start == end) return std::unexpected(u::ReadError::End); + if (start == end) + return std::unexpected(u::ReadError::End); uint32_t u; switch (*start >> 4) { case 0xe: { @@ -44,7 +45,8 @@ std::expected<uint32_t, u::ReadError> read(T& start, const T& end) { std::advance(start, 1); // Not going recursive here as we don't want it unbounded // Lone surrogate pair at end == invalid. - if (start == end) return std::unexpected(u::ReadError::Invalid); + if (start == end) + return std::unexpected(u::ReadError::Invalid); if ((*start >> 4) == 0xe) { if (std::distance(start, end) < 3) { start = tmp; @@ -110,7 +112,7 @@ std::expected<uint32_t, u::ReadError> read(T& start, const T& end) { return u; } -template<std::forward_iterator T> +template <std::forward_iterator T> requires std::is_same_v<std::iter_value_t<T>, uint8_t> std::expected<uint32_t, u::ReadErrorReplace> read_replace(T& start, const T& end, @@ -133,19 +135,22 @@ std::expected<uint32_t, u::ReadErrorReplace> read_replace(T& start, return 0xfffd; } -template<std::forward_iterator T> +template <std::forward_iterator T> requires std::is_same_v<std::iter_value_t<T>, uint8_t> bool write(T& start, const T& end, uint32_t code) { if (code > 0 && code < 0x80) { - if (start == end) return false; + if (start == end) + return false; *start = static_cast<uint8_t>(code); } else if (code < 0x800) { - if (std::distance(start, end) < 2) return false; + if (std::distance(start, end) < 2) + return false; *start = 0xc0 | static_cast<uint8_t>(code >> 6); std::advance(start, 1); *start = 0x80 | static_cast<uint8_t>(code & 0x3f); } else if (code < 0x10000) { - if (std::distance(start, end) < 3) return false; + if (std::distance(start, end) < 3) + return false; *start = 0xe0 | static_cast<uint8_t>(code >> 12); std::advance(start, 1); *start = 0x80 | static_cast<uint8_t>((code >> 6) & 0x3f); @@ -165,20 +170,23 @@ bool write(T& start, const T& end, uint32_t code) { return true; } -template<std::forward_iterator T> +template <std::forward_iterator T> requires std::is_same_v<std::iter_value_t<T>, uint8_t> bool skip(T& start, const T& end) { - if (start == end) return false; + if (start == end) + return false; switch (*start >> 4) { case 0xe: { auto tmp = start; - if (read(start, end).has_value()) return true; + if (read(start, end).has_value()) + return true; start = tmp; return false; } case 0xc: case 0xd: - if (std::distance(start, end) < 2) return false; + if (std::distance(start, end) < 2) + return false; std::advance(start, 2); break; default: |
