diff --git a/source/Enderal DLL/src/Util.h b/source/Enderal DLL/src/Util.h index fb2d119f5..fe8b13384 100644 --- a/source/Enderal DLL/src/Util.h +++ b/source/Enderal DLL/src/Util.h @@ -330,15 +330,15 @@ inline RE::BSFixedString GetPlayerHash() return buf; } -inline RE::BSFixedString StringToHex(RE::BSFixedString a_string) +// Two digits per byte, as the engine writes save names ("%.2X"). char is signed, so a byte +// above 0x7F (any UTF-8 non-ASCII character) must be widened as unsigned, or it prints as FFFFFFxx. +inline std::string StringToHex(std::string_view a_string) { - std::string_view str(a_string); - - std::stringstream sstream; - for (auto ch : str) { - sstream << std::uppercase << std::hex << static_cast(ch); + std::string result; + result.reserve(a_string.size() * 2); + for (const auto ch : a_string) { + result += std::format("{:02X}", static_cast(ch)); } - - return sstream.str(); + return result; }