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/u16.hh | |
| parent | bf41a601fd0447bcf3a2937a595a1cd8ca5c1633 (diff) | |
Add .clang-format
Make it easier to keep a consistent style
Diffstat (limited to 'src/u16.hh')
| -rw-r--r-- | src/u16.hh | 27 |
1 files changed, 16 insertions, 11 deletions
@@ -1,9 +1,9 @@ #ifndef U16_HH #define U16_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 u16 { -template<std::forward_iterator T> +template <std::forward_iterator T> requires std::is_same_v<std::iter_value_t<T>, uint16_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); uint16_t u = *start; if (u >= 0xd800 && u <= 0xdbff) { if (std::distance(start, end) < 2) { @@ -35,7 +36,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>, uint16_t> std::expected<uint32_t, u::ReadErrorReplace> read_replace(T& start, const T& end, @@ -58,14 +59,16 @@ 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>, uint16_t> bool write(T& start, const T& end, uint32_t code) { if (code < 0x10000) { - if (start == end) return false; + if (start == end) + return false; *start = static_cast<uint16_t>(code); } else { - if (std::distance(start, end) < 2) return false; + if (std::distance(start, end) < 2) + return false; code -= 0x10000; *start = static_cast<uint16_t>(0xd800 + (code >> 10)); std::advance(start, 1); @@ -75,12 +78,14 @@ 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>, uint16_t> bool skip(T& start, const T& end) { - if (start == end) return false; + if (start == end) + return false; if (*start >= 0xd800 && *start <= 0xdbff) { - if (std::distance(start, end) < 2) return false; + if (std::distance(start, end) < 2) + return false; std::advance(start, 2); return true; } |
