diff options
| author | Treeston <treeston.mmoc@gmail.com> | 2020-08-04 17:03:26 +0200 |
|---|---|---|
| committer | Treeston <treeston.mmoc@gmail.com> | 2020-08-04 17:03:26 +0200 |
| commit | 7b8b999516a824b0c417631a77f133eb47b8b2f4 (patch) | |
| tree | cb143b086758b088652b79300ca88ffeb77c06de /src/common | |
| parent | c8fed48b161cfff5fa90d8bf4342ede88086ada4 (diff) | |
Core/Common: Move old-style pointer+size HexStr methods to Trinity::Impl where they can't hurt anyone
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/Utilities/Util.cpp | 8 | ||||
| -rw-r--r-- | src/common/Utilities/Util.h | 17 |
2 files changed, 15 insertions, 10 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index 7e4b9130e82..8f37d8928ce 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -611,7 +611,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; @@ -635,11 +635,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 59d7d53bce9..4ee7c99c4ff 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -305,15 +305,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 <typename Container> -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 <size_t Size> void HexStrToByteArray(std::string const& str, std::array<uint8, Size>& buf, bool reverse = false) { - ASSERT(str.size() == (2 * Size)); - HexStrToByteArray(str, buf.data(), reverse); + Trinity::Impl::HexStrToByteArray(str, buf.data(), Size, reverse); } template <size_t Size> std::array<uint8, Size> HexStrToByteArray(std::string const& str, bool reverse = false) |
