Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace std::codecvt by MultiByteToWideChar due to deprecation #29

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions source/utils/path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include <linux/limits.h>
#include <sys/types.h>
#include <unistd.h>
#elif defined(_MSC_VER)
#include <codecvt>
#endif

#include <xlnt/utils/path.hpp>
Expand Down Expand Up @@ -231,8 +229,20 @@ const std::string &path::string() const
#ifdef _MSC_VER
std::wstring path::wstring() const
{
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> convert;
return convert.from_bytes(string());
const std::string &path_str = string();
int size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path_str.c_str(), static_cast<int>(path_str.length()), nullptr, 0);
m7913d marked this conversation as resolved.
Show resolved Hide resolved

if (size > 0)
{
std::wstring path_converted(size, L'\0');
// Note: const_cast is NOT necessary in C++17 and newer!
size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, path_str.c_str(), static_cast<int>(path_str.length()), const_cast<wchar_t *>(path_converted.data()), size);
m7913d marked this conversation as resolved.
Show resolved Hide resolved
return path_converted;
}
else
{
return {};
}
}
#endif

Expand Down