From a13540be6f3ff37a696fbbf05aba98bd6e2d1a84 Mon Sep 17 00:00:00 2001 From: Jaquee Date: Fri, 4 Aug 2017 19:06:11 +0200 Subject: [PATCH] add string_tools::validate_hex() --- contrib/epee/include/string_tools.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h index ce7b2fb87..25639263c 100644 --- a/contrib/epee/include/string_tools.h +++ b/contrib/epee/include/string_tools.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -349,6 +350,11 @@ POP_WARNINGS s = *(t_pod_type*)bin_buff.data(); return true; } + //---------------------------------------------------------------------------- + inline bool validate_hex(uint64_t length, const std::string& str) + { + return std::regex_match(str, std::regex("'^[0-9abcdefABCDEF]+$'")) && str.size() == length; + } //---------------------------------------------------------------------------- inline std::string get_extension(const std::string& str) {