Files
openal-soft/common/strutils.h
T
2019-08-11 18:50:07 -07:00

44 lines
810 B
C++

#ifndef AL_STRUTILS_H
#define AL_STRUTILS_H
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string>
inline std::string wstr_to_utf8(const WCHAR *wstr)
{
std::string ret;
int len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr);
if(len > 0)
{
ret.resize(len);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &ret[0], len, nullptr, nullptr);
ret.pop_back();
}
return ret;
}
inline std::wstring utf8_to_wstr(const char *str)
{
std::wstring ret;
int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, nullptr, 0);
if(len > 0)
{
ret.resize(len);
MultiByteToWideChar(CP_UTF8, 0, str, -1, &ret[0], len);
ret.pop_back();
}
return ret;
}
#endif
#endif /* AL_STRUTILS_H */