Skip to content

Commit

Permalink
Add hat::to_string(signature_view)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroMemes committed Jul 31, 2024
1 parent 148f66b commit 215ca47
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/libhat/Signature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@ namespace hat {
std::ranges::move(sig, arr.begin());
return arr;
}

[[nodiscard]] constexpr std::string to_string(const signature_view signature) {
static constexpr std::string_view hex{"0123456789ABCDEF"};
std::string ret;
ret.reserve(signature.size() * 3);
for (auto& element : signature) {
if (element.has_value()) {
ret += {
hex[static_cast<size_t>(element.value() >> 4) & 0xFu],
hex[static_cast<size_t>(element.value() >> 0) & 0xFu],
' '
};
} else {
ret += "? ";
}
}
ret.pop_back();
return ret;
}
}

namespace hat::literals::signature_literals {
Expand Down

0 comments on commit 215ca47

Please sign in to comment.