2021-09-22 03:27 PM - edited 2021-09-22 03:52 PM
Hi
How to convert from GS::UniString to std::string?
(I need to pass it to another API which takes std::string)
Thanks.
2021-09-22 04:42 PM
To convert between GS::UniString and std::wstring:
GS::UniString ToUniString (const std::wstring& str)
{
static_assert (sizeof (GS::UniChar::Layout) == sizeof (wchar_t), "string character size mismatch");
return GS::UniString ((const GS::UniChar::Layout*) str.c_str (), (GS::USize) str.size ());
}
std::wstring ToWString (const GS::UniString& str)
{
static_assert (sizeof (GS::UniChar::Layout) == sizeof (wchar_t), "string character size mismatch");
return std::wstring ((const wchar_t*) str.ToUStr ().Get (), str.GetLength ());
}
To convert between std::string and std::wstring:
std::wstring StringToWString (const std::string& str)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> convert;
return std::wstring (convert.from_bytes (str));
}
std::string WStringToString (const std::wstring& str)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> convert;
return std::string (convert.to_bytes (str));
}
2021-09-22 05:28 PM
Hi Viktor,
Thanks for that info.
I found that simply doing: std::string myStdStr(myUniStr.ToCStr()) works.
2021-09-27 07:59 PM - edited 2021-09-27 08:00 PM
(removed because redundant suggestion)