Replace deprecated wstring_convert with Windows API functions.
--- a/src/in_xsf_framework/convert.h
+++ b/src/in_xsf_framework/convert.h
@@ -14,6 +14,7 @@
#include <vector>
#include <memory>
#include <cmath>
+#include "windowsh_wrapper.h"
/*
* The following exception class and the *stringify and convert* functions are
@@ -153,14 +154,20 @@
static std::wstring StringToWString(const std::string &str)
{
- static std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
- return conv.from_bytes(str);
+ auto strC = str.c_str();
+ int bufferSize = MultiByteToWideChar(CP_UTF8, 0, strC, -1, nullptr, 0);
+ auto buffer = std::vector<wchar_t>(bufferSize);
+ MultiByteToWideChar(CP_UTF8, 0, strC, -1, &buffer[0], bufferSize);
+ return std::wstring(buffer.begin(), buffer.end());
}
static std::string WStringToString(const std::wstring &wstr)
{
- static std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
- return conv.to_bytes(wstr);
+ auto wstrC = wstr.c_str();
+ int bufferSize = WideCharToMultiByte(CP_UTF8, 0, wstrC, -1, nullptr, 0, nullptr, nullptr);
+ auto buffer = std::vector<char>(bufferSize);
+ WideCharToMultiByte(CP_UTF8, 0, wstrC, -1, &buffer[0], bufferSize, nullptr, nullptr);
+ return std::string(buffer.begin(), buffer.end());
}
};