summaryrefslogtreecommitdiff
path: root/src/u8.hh
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-09-15 21:15:53 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-09-15 21:15:53 +0200
commitaa49abdf239bae6065fddd0839ec67a404c9748c (patch)
tree631fbb2df58aa35df3d60c65c037ef74b1807114 /src/u8.hh
parentbf41a601fd0447bcf3a2937a595a1cd8ca5c1633 (diff)
Add .clang-format
Make it easier to keep a consistent style
Diffstat (limited to 'src/u8.hh')
-rw-r--r--src/u8.hh39
1 files changed, 24 insertions, 15 deletions
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 <cstdint> // IWYU pragma: export
+#include <cstdint> // IWYU pragma: export
#include <expected>
#include <iterator>
#include <type_traits>
@@ -11,10 +11,11 @@
namespace u8 {
-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 0xf:
@@ -102,7 +103,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,
@@ -125,26 +126,30 @@ 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 < 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);
std::advance(start, 1);
*start = 0x80 | static_cast<uint8_t>(code & 0x3f);
} else {
- if (std::distance(start, end) < 4) return false;
+ if (std::distance(start, end) < 4)
+ return false;
*start = 0xf0 | static_cast<uint8_t>(code >> 18);
std::advance(start, 1);
*start = 0x80 | static_cast<uint8_t>((code >> 12) & 0x3f);
@@ -157,22 +162,26 @@ 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 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: