diff options
Diffstat (limited to 'zen/string_tools.h')
-rw-r--r-- | zen/string_tools.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/zen/string_tools.h b/zen/string_tools.h index 40a4ea52..cd26f5fd 100644 --- a/zen/string_tools.h +++ b/zen/string_tools.h @@ -83,6 +83,7 @@ template <class Num, class S> Num stringTo(const S& str); std::pair<char, char> hexify (unsigned char c, bool upperCase = true); char unhexify(char high, char low); +std::string formatAsHexString(const std::string& blob); //bytes -> (human-readable) hex string template <class S, class T, class Num> S printNumber(const T& format, const Num& number); //format a single number using std::snprintf() @@ -848,6 +849,20 @@ char unhexify(char high, char low) } +inline +std::string formatAsHexString(const std::string& blob) +{ + std::string output; + for (const char c : blob) + { + const auto [high, low] = hexify(c, false /*upperCase*/); + output += high; + output += low; + } + return output; +} + + } #endif //STRING_TOOLS_H_213458973046 |