diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | alc/alc.cpp | 1 | ||||
-rw-r--r-- | alc/alconfig.cpp | 1 | ||||
-rw-r--r-- | alc/backends/dsound.cpp | 1 | ||||
-rw-r--r-- | alc/backends/wasapi.cpp | 1 | ||||
-rw-r--r-- | alc/backends/wave.cpp | 1 | ||||
-rw-r--r-- | alc/backends/winmm.cpp | 1 | ||||
-rw-r--r-- | alc/compat.h | 30 | ||||
-rw-r--r-- | alc/helpers.cpp | 1 | ||||
-rw-r--r-- | common/dynload.cpp | 21 | ||||
-rw-r--r-- | common/strutils.h | 43 |
11 files changed, 52 insertions, 50 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fe05f35..cfcfd6aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -604,6 +604,7 @@ SET(COMMON_OBJS common/intrusive_ptr.h common/math_defs.h common/opthelpers.h + common/strutils.h common/threads.cpp common/threads.h common/vecmat.h diff --git a/alc/alc.cpp b/alc/alc.cpp index c1989913..adead648 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -85,6 +85,7 @@ #include "mastering.h" #include "opthelpers.h" #include "ringbuffer.h" +#include "strutils.h" #include "threads.h" #include "uhjfilter.h" #include "vecmat.h" diff --git a/alc/alconfig.cpp b/alc/alconfig.cpp index e7632ef7..f6190b58 100644 --- a/alc/alconfig.cpp +++ b/alc/alconfig.cpp @@ -47,6 +47,7 @@ #include "alcmain.h" #include "logging.h" +#include "strutils.h" #include "compat.h" diff --git a/alc/backends/dsound.cpp b/alc/backends/dsound.cpp index b9e52c0c..ad182cf7 100644 --- a/alc/backends/dsound.cpp +++ b/alc/backends/dsound.cpp @@ -49,6 +49,7 @@ #include "ringbuffer.h" #include "compat.h" #include "dynload.h" +#include "strutils.h" #include "threads.h" /* MinGW-w64 needs this for some unknown reason now. */ diff --git a/alc/backends/wasapi.cpp b/alc/backends/wasapi.cpp index bd009463..cc53be66 100644 --- a/alc/backends/wasapi.cpp +++ b/alc/backends/wasapi.cpp @@ -59,6 +59,7 @@ #include "ringbuffer.h" #include "compat.h" #include "converter.h" +#include "strutils.h" #include "threads.h" diff --git a/alc/backends/wave.cpp b/alc/backends/wave.cpp index 6ca2fab4..aa4130af 100644 --- a/alc/backends/wave.cpp +++ b/alc/backends/wave.cpp @@ -43,6 +43,7 @@ #include "compat.h" #include "endiantest.h" #include "logging.h" +#include "strutils.h" #include "threads.h" #include "vector.h" diff --git a/alc/backends/winmm.cpp b/alc/backends/winmm.cpp index cd32e95b..b6787a24 100644 --- a/alc/backends/winmm.cpp +++ b/alc/backends/winmm.cpp @@ -40,6 +40,7 @@ #include "alcmain.h" #include "alu.h" #include "ringbuffer.h" +#include "strutils.h" #include "threads.h" #include "compat.h" diff --git a/alc/compat.h b/alc/compat.h index 648fa5b1..f2e10513 100644 --- a/alc/compat.h +++ b/alc/compat.h @@ -10,36 +10,6 @@ #include <string> #include <fstream> -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, NULL, 0); - if(len > 0) - { - ret.resize(len); - MultiByteToWideChar(CP_UTF8, 0, str, -1, &ret[0], len); - ret.pop_back(); - } - - return ret; -} - namespace al { diff --git a/alc/helpers.cpp b/alc/helpers.cpp index b952c5ed..27219b03 100644 --- a/alc/helpers.cpp +++ b/alc/helpers.cpp @@ -106,6 +106,7 @@ DEFINE_PROPERTYKEY(PKEY_AudioEndpoint_GUID, 0x1da5d803, 0xd492, 0x4edd, 0x8c, 0x #include "cpu_caps.h" #include "fpu_modes.h" #include "logging.h" +#include "strutils.h" #include "vector.h" 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 */ |