From fa8ab6eb98395ed468046c261fe120082d4e019b Mon Sep 17 00:00:00 2001 From: Treeston Date: Tue, 4 Aug 2020 17:03:26 +0200 Subject: Core/Common: Move old-style pointer+size HexStr methods to Trinity::Impl where they can't hurt anyone (cherry picked from commit 7b8b999516a824b0c417631a77f133eb47b8b2f4) --- src/common/Utilities/Util.cpp | 8 +++----- src/common/Utilities/Util.h | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src/common/Utilities') diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index e443e77125b..42f87c36991 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -794,7 +794,7 @@ bool Utf8ToUpperOnlyLatin(std::string& utf8String) return WStrToUtf8(wstr, utf8String); } -std::string ByteArrayToHexStr(uint8 const* bytes, size_t arrayLen, bool reverse /* = false */) +std::string Trinity::Impl::ByteArrayToHexStr(uint8 const* bytes, size_t arrayLen, bool reverse /* = false */) { int32 init = 0; int32 end = arrayLen; @@ -818,11 +818,9 @@ std::string ByteArrayToHexStr(uint8 const* bytes, size_t arrayLen, bool reverse return ss.str(); } -void HexStrToByteArray(std::string const& str, uint8* out, bool reverse /*= false*/) +void Trinity::Impl::HexStrToByteArray(std::string const& str, uint8* out, size_t outlen, bool reverse /*= false*/) { - // string must have even number of characters - if (str.length() & 1) - return; + ASSERT(str.size() == (2 * outlen)); int32 init = 0; int32 end = int32(str.length()); diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index f34b6d6ad96..18a380ea9b4 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -340,15 +340,22 @@ TC_COMMON_API bool IsIPAddress(char const* ipaddress); TC_COMMON_API uint32 CreatePIDFile(std::string const& filename); TC_COMMON_API uint32 GetPID(); -TC_COMMON_API std::string ByteArrayToHexStr(uint8 const* bytes, size_t length, bool reverse = false); +namespace Trinity::Impl +{ + TC_COMMON_API std::string ByteArrayToHexStr(uint8 const* bytes, size_t length, bool reverse = false); + TC_COMMON_API void HexStrToByteArray(std::string const& str, uint8* out, size_t outlen, bool reverse = false); +} + template -std::string ByteArrayToHexStr(Container const& c, bool reverse = false) { return ByteArrayToHexStr(std::data(c), std::size(c), reverse); } -TC_COMMON_API void HexStrToByteArray(std::string const& str, uint8* out, bool reverse = false); +std::string ByteArrayToHexStr(Container const& c, bool reverse = false) +{ + return Trinity::Impl::ByteArrayToHexStr(std::data(c), std::size(c), reverse); +} + template void HexStrToByteArray(std::string const& str, std::array& buf, bool reverse = false) { - ASSERT(str.size() == (2 * Size)); - HexStrToByteArray(str, buf.data(), reverse); + Trinity::Impl::HexStrToByteArray(str, buf.data(), Size, reverse); } template std::array HexStrToByteArray(std::string const& str, bool reverse = false) -- cgit v1.2.3