From aa49abdf239bae6065fddd0839ec67a404c9748c Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Mon, 15 Sep 2025 21:15:53 +0200 Subject: Add .clang-format Make it easier to keep a consistent style --- src/umod8.hh | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/umod8.hh') 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 // IWYU pragma: export +#include // IWYU pragma: export #include #include #include @@ -11,10 +11,11 @@ namespace umod8 { -template +template requires std::is_same_v, uint8_t> std::expected 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 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 read(T& start, const T& end) { return u; } -template +template requires std::is_same_v, uint8_t> std::expected read_replace(T& start, const T& end, @@ -133,19 +135,22 @@ std::expected read_replace(T& start, return 0xfffd; } -template +template requires std::is_same_v, 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(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(code >> 6); std::advance(start, 1); *start = 0x80 | static_cast(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(code >> 12); std::advance(start, 1); *start = 0x80 | static_cast((code >> 6) & 0x3f); @@ -165,20 +170,23 @@ bool write(T& start, const T& end, uint32_t code) { return true; } -template +template requires std::is_same_v, 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: -- cgit v1.3