aboutsummaryrefslogtreecommitdiff
path: root/src/common/Utilities/Util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/Utilities/Util.cpp')
-rw-r--r--src/common/Utilities/Util.cpp17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp
index fdd49b49855..ac97e724902 100644
--- a/src/common/Utilities/Util.cpp
+++ b/src/common/Utilities/Util.cpp
@@ -843,15 +843,13 @@ std::string Trinity::Impl::ByteArrayToHexStr(uint8 const* bytes, size_t arrayLen
op = -1;
}
- std::ostringstream ss;
+ std::string result;
+ result.reserve(arrayLen * 2);
+ auto inserter = std::back_inserter(result);
for (int32 i = init; i != end; i += op)
- {
- char buffer[4];
- sprintf(buffer, "%02X", bytes[i]);
- ss << buffer;
- }
+ Trinity::StringFormatTo(inserter, "{:02X}", bytes[i]);
- return ss.str();
+ return result;
}
void Trinity::Impl::HexStrToByteArray(std::string_view str, uint8* out, size_t outlen, bool reverse /*= false*/)
@@ -871,10 +869,7 @@ void Trinity::Impl::HexStrToByteArray(std::string_view str, uint8* out, size_t o
uint32 j = 0;
for (int32 i = init; i != end; i += 2 * op)
- {
- char buffer[3] = { str[i], str[i + 1], '\0' };
- out[j++] = uint8(strtoul(buffer, nullptr, 16));
- }
+ out[j++] = Trinity::StringTo<uint8>(str.substr(i, 2), 16).value_or(0);
}
bool StringEqualI(std::string_view a, std::string_view b)