Skip to content

Instantly share code, notes, and snippets.

@SeanCline
Created August 18, 2016 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanCline/a039ea5d02901a730a76d94facce86e1 to your computer and use it in GitHub Desktop.
Save SeanCline/a039ea5d02901a730a76d94facce86e1 to your computer and use it in GitHub Desktop.
#pragma once
#include <string>
#include <codecvt>
Platform::String^ to_PlatformString(const char* from)
{
std::wstring_convert<std::codecvt<wchar_t, char, mbstate_t>> convert;
auto wide = convert.from_bytes(from);
return ref new Platform::String(wide.c_str(), static_cast<unsigned int>(wide.size()));
}
Platform::String^ to_PlatformString(const wchar_t* from)
{
return ref new Platform::String(from);
}
Platform::String^ to_PlatformString(const std::string& from)
{
std::wstring_convert<std::codecvt<wchar_t, char, mbstate_t>> convert;
auto wide = convert.from_bytes(from);
return ref new Platform::String(wide.c_str(), static_cast<unsigned int>(wide.size()));
}
Platform::String^ to_PlatformString(const std::wstring& from)
{
return ref new Platform::String(from.c_str(), static_cast<unsigned int>(from.size()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment