Browse code

Replace deprecated wstring_convert with Windows API functions.

Naram Qashat authored on 2021/03/19 11:27:57
Showing 1 changed files
... ...
@@ -14,6 +14,7 @@
14 14
 #include <vector>
15 15
 #include <memory>
16 16
 #include <cmath>
17
+#include "windowsh_wrapper.h"
17 18
 
18 19
 /*
19 20
  * The following exception class and the *stringify and convert* functions are
... ...
@@ -153,13 +154,19 @@ public:
153 154
 
154 155
 	static std::wstring StringToWString(const std::string &str)
155 156
 	{
156
-		static std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
157
-		return conv.from_bytes(str);
157
+		auto strC = str.c_str();
158
+		int bufferSize = MultiByteToWideChar(CP_UTF8, 0, strC, -1, nullptr, 0);
159
+		auto buffer = std::vector<wchar_t>(bufferSize);
160
+		MultiByteToWideChar(CP_UTF8, 0, strC, -1, &buffer[0], bufferSize);
161
+		return std::wstring(buffer.begin(), buffer.end());
158 162
 	}
159 163
 
160 164
 	static std::string WStringToString(const std::wstring &wstr)
161 165
 	{
162
-		static std::wstring_convert<std::codecvt_utf8<wchar_t>> conv;
163
-		return conv.to_bytes(wstr);
166
+		auto wstrC = wstr.c_str();
167
+		int bufferSize = WideCharToMultiByte(CP_UTF8, 0, wstrC, -1, nullptr, 0, nullptr, nullptr);
168
+		auto buffer = std::vector<char>(bufferSize);
169
+		WideCharToMultiByte(CP_UTF8, 0, wstrC, -1, &buffer[0], bufferSize, nullptr, nullptr);
170
+		return std::string(buffer.begin(), buffer.end());
164 171
 	}
165 172
 };