aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-08-11 18:50:07 -0700
committerChris Robinson <[email protected]>2019-08-11 18:50:07 -0700
commite200569cd319448d12099f27a2713c69da382d26 (patch)
tree5475e5aa20505bd403b46053321dd2d6a019ac5d /common
parent7118733458bc388a900677da6e0d4e4244d0f536 (diff)
Move the wstr converters to a separate header
Diffstat (limited to 'common')
-rw-r--r--common/dynload.cpp21
-rw-r--r--common/strutils.h43
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 */