From 215ca470b38fe7ff47d8efbb0c0c6df9d4108165 Mon Sep 17 00:00:00 2001 From: Brady Date: Wed, 31 Jul 2024 16:38:14 -0500 Subject: [PATCH] Add `hat::to_string(signature_view)` --- include/libhat/Signature.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/libhat/Signature.hpp b/include/libhat/Signature.hpp index 0db6b1b..596031d 100644 --- a/include/libhat/Signature.hpp +++ b/include/libhat/Signature.hpp @@ -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(element.value() >> 4) & 0xFu], + hex[static_cast(element.value() >> 0) & 0xFu], + ' ' + }; + } else { + ret += "? "; + } + } + ret.pop_back(); + return ret; + } } namespace hat::literals::signature_literals {