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/u8.hh | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'src/u8.hh') diff --git a/src/u8.hh b/src/u8.hh index b89f80f..5292602 100644 --- a/src/u8.hh +++ b/src/u8.hh @@ -1,9 +1,9 @@ #ifndef U8_HH #define U8_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 u8 { -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 0xf: @@ -102,7 +103,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, @@ -125,26 +126,30 @@ 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 < 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); std::advance(start, 1); *start = 0x80 | static_cast(code & 0x3f); } else { - if (std::distance(start, end) < 4) return false; + if (std::distance(start, end) < 4) + return false; *start = 0xf0 | static_cast(code >> 18); std::advance(start, 1); *start = 0x80 | static_cast((code >> 12) & 0x3f); @@ -157,22 +162,26 @@ 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 0xf: - if (std::distance(start, end) < 4) return false; + if (std::distance(start, end) < 4) + return false; std::advance(start, 4); break; case 0xe: - if (std::distance(start, end) < 3) return false; + if (std::distance(start, end) < 3) + return false; std::advance(start, 3); break; 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