Make sure FX slots that aren't made active are disabled
[openal-soft.git] / common / strutils.cpp
blob18c4947ad28816a921bc8a09e41c6fef84b462f8
2 #include "config.h"
4 #include "strutils.h"
6 #include <cstdlib>
9 #ifdef _WIN32
10 #define WIN32_LEAN_AND_MEAN
11 #include <windows.h>
13 std::string wstr_to_utf8(const WCHAR *wstr)
15 std::string ret;
17 int len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr);
18 if(len > 0)
20 ret.resize(len);
21 WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &ret[0], len, nullptr, nullptr);
22 ret.pop_back();
25 return ret;
28 std::wstring utf8_to_wstr(const char *str)
30 std::wstring ret;
32 int len = MultiByteToWideChar(CP_UTF8, 0, str, -1, nullptr, 0);
33 if(len > 0)
35 ret.resize(len);
36 MultiByteToWideChar(CP_UTF8, 0, str, -1, &ret[0], len);
37 ret.pop_back();
40 return ret;
42 #endif
44 namespace al {
46 al::optional<std::string> getenv(const char *envname)
48 const char *str{std::getenv(envname)};
49 if(str && str[0] != '\0')
50 return al::make_optional<std::string>(str);
51 return al::nullopt;
54 #ifdef _WIN32
55 al::optional<std::wstring> getenv(const WCHAR *envname)
57 const WCHAR *str{_wgetenv(envname)};
58 if(str && str[0] != L'\0')
59 return al::make_optional<std::wstring>(str);
60 return al::nullopt;
62 #endif
64 } // namespace al