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

Fix UWP support #831

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion include/date/date.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
#ifdef _MSC_VER
# pragma warning(push)
// warning C4127: conditional expression is constant
# pragma warning(disable : 4127)
# pragma warning(disable : 4127 4996)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the code which causes 4996?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied this from the original UWP support vcpkg patch. Looks like it's originally from here. I don't have a Windows dev environment, so I can't test these changes directly, but I know it fixed the UWP CI tests in vcpkg.

#endif

namespace date
Expand Down
59 changes: 30 additions & 29 deletions src/tz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,35 +202,6 @@ namespace
using co_task_mem_ptr = std::unique_ptr<wchar_t[], task_mem_deleter>;
}

static
std::wstring
convert_utf8_to_utf16(const std::string& s)
{
std::wstring out;
const int size = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, NULL, 0);

if (size == 0)
{
std::string msg = "Failed to determine required size when converting \"";
msg += s;
msg += "\" to UTF-16.";
throw std::runtime_error(msg);
}

out.resize(size);
const int check = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, &out[0], size);

if (size != check)
{
std::string msg = "Failed to convert \"";
msg += s;
msg += "\" to UTF-16.";
throw std::runtime_error(msg);
}

return out;
}

// We might need to know certain locations even if not using the remote API,
// so keep these routines out of that block for now.
static
Expand Down Expand Up @@ -268,6 +239,36 @@ get_download_folder()
# endif // !INSTALL

# endif // WINRT

static
std::wstring
convert_utf8_to_utf16(const std::string& s)
{
std::wstring out;
const int size = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, NULL, 0);

if (size == 0)
{
std::string msg = "Failed to determine required size when converting \"";
msg += s;
msg += "\" to UTF-16.";
throw std::runtime_error(msg);
}

out.resize(size);
const int check = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, &out[0], size);

if (size != check)
{
std::string msg = "Failed to convert \"";
msg += s;
msg += "\" to UTF-16.";
throw std::runtime_error(msg);
}

return out;
}

# else // !_WIN32

# if !defined(INSTALL)
Expand Down