11 [[nodiscard]]
static constexpr
char encode2(uint8_t
x)
13 return (
x < 10) ? char(
x +
'0') : char(
x - 10 +
'A');
15 [[nodiscard]]
static auto encode(uint8_t
x)
19 std::string encode(
const uint8_t* input,
size_t len,
bool newlines)
23 if (newlines && !ret.empty()) ret +=
'\n';
24 int t = int(std::min<size_t>(16, len));
26 ret += encode(*input++);
27 if (i != (
t - 1)) ret +=
' ';
34 [[nodiscard]]
static constexpr
int decode(
char x)
36 if ((
'0' <=
x) && (
x <=
'9')) {
38 }
else if ((
'A' <=
x) && (
x <=
'F')) {
40 }
else if ((
'a' <=
x) && (
x <=
'f')) {
46 std::pair<MemBuffer<uint8_t>,
size_t> decode(std::string_view input)
48 auto inSize = input.size();
49 auto outSize = inSize / 2;
55 for (
char c : input) {
57 if (d == -1)
continue;
61 ret[out++] = (tmp << 4) | d;
66 assert(outSize >= out);
68 return {std::move(ret), out};
76 for (
char c : input) {
78 if (d == -1)
continue;
82 if (out == outSize) [[unlikely]]
return false;
83 output[out++] = (tmp << 4) | d;
88 return out == outSize;
This class manages the lifetime of a block of memory.
void resize(size_t size)
Grow or shrink the memory block.
bool decode_inplace(std::string_view input, uint8_t *output, size_t outSize)
constexpr KeyMatrixPosition x
Keyboard bindings.
TemporaryString tmpStrCat(Ts &&... ts)
constexpr auto xrange(T e)