Skip to content

Commit 3905d71

Browse files
committed
Removed deprecated functions in C++17, defined in <codecvt> header.
1 parent b99c72a commit 3905d71

File tree

8 files changed

+112
-171
lines changed

8 files changed

+112
-171
lines changed

LinkList.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,40 @@ bool CLinkSnapshot::DeleteLink(DWORD dwLinkID)
208208
return false;
209209
}
210210

211-
std::wstring utf8_to_wstring(const std::string& str)
211+
std::wstring utf8_to_wstring(const std::string& string)
212212
{
213-
// convert UTF-8 string to wstring
214-
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
215-
return myconv.from_bytes(str);
213+
if (string.empty())
214+
{
215+
return L"";
216+
}
217+
218+
const auto size_needed = MultiByteToWideChar(CP_UTF8, 0, string.data(), (int)string.size(), nullptr, 0);
219+
if (size_needed <= 0)
220+
{
221+
throw std::runtime_error("MultiByteToWideChar() failed: " + std::to_string(size_needed));
222+
}
223+
224+
std::wstring result(size_needed, 0);
225+
MultiByteToWideChar(CP_UTF8, 0, string.data(), (int)string.size(), result.data(), size_needed);
226+
return result;
216227
}
217228

218-
std::string wstring_to_utf8(const std::wstring& str)
229+
std::string wstring_to_utf8(const std::wstring& wide_string)
219230
{
220-
// convert wstring to UTF-8 string
221-
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
222-
return myconv.to_bytes(str);
231+
if (wide_string.empty())
232+
{
233+
return "";
234+
}
235+
236+
const auto size_needed = WideCharToMultiByte(CP_UTF8, 0, wide_string.data(), (int)wide_string.size(), nullptr, 0, nullptr, nullptr);
237+
if (size_needed <= 0)
238+
{
239+
throw std::runtime_error("WideCharToMultiByte() failed: " + std::to_string(size_needed));
240+
}
241+
242+
std::string result(size_needed, 0);
243+
WideCharToMultiByte(CP_UTF8, 0, wide_string.data(), (int)wide_string.size(), result.data(), size_needed, nullptr, nullptr);
244+
return result;
223245
}
224246

225247
CString GetModuleFileName(_Inout_opt_ DWORD* pdwLastError = nullptr);

ReleaseNotes.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,11 @@ <h2>History</h2>
9696
<li>Updated <code>genUp4win</code> library to the latest version available.</li>
9797
</ul>
9898
</li>
99-
<li>Version 1.23 (TBD):
99+
<li>Version 1.23 (March 8<sup>th</sup>, 2025):
100100
<ul>
101101
<li>Updated <code>genUp4win</code> library to the latest version available.</li>
102102
<li>Updated Lee Thomason's <code>TinyXML2</code> library to the latest version available.</li>
103+
<li>Removed deprecated functions in C++17, defined in <code>&lt;codecvt&gt;</code> header.
103104
</ul>
104105
</li>
105106
</ul>

0 commit comments

Comments
 (0)