diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/dynload.cpp | 21 | ||||
-rw-r--r-- | common/strutils.h | 43 |
2 files changed, 44 insertions, 20 deletions
diff --git a/common/dynload.cpp b/common/dynload.cpp index 89824f78..98d2c521 100644 --- a/common/dynload.cpp +++ b/common/dynload.cpp @@ -3,29 +3,10 @@ #include "dynload.h" +#include "strutils.h" #ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#include <windows.h> - -#include <string> - -inline std::wstring utf8_to_wstr(const char *str) -{ - std::wstring ret; - - int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0); - if(len > 0) - { - ret.resize(len); - MultiByteToWideChar(CP_UTF8, 0, str, -1, &ret[0], len); - ret.pop_back(); - } - - return ret; -} - void *LoadLib(const char *name) { std::wstring wname{utf8_to_wstr(name)}; diff --git a/common/strutils.h b/common/strutils.h new file mode 100644 index 00000000..2bfd15fc --- /dev/null +++ b/common/strutils.h @@ -0,0 +1,43 @@ +#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 */ |