Move the wstr converters to a separate header

This commit is contained in:
Chris Robinson 2019-08-11 18:50:07 -07:00
parent 7118733458
commit e200569cd3
11 changed files with 52 additions and 50 deletions

View File

@ -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

View File

@ -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"

View File

@ -47,6 +47,7 @@
#include "alcmain.h"
#include "logging.h"
#include "strutils.h"
#include "compat.h"

View File

@ -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. */

View File

@ -59,6 +59,7 @@
#include "ringbuffer.h"
#include "compat.h"
#include "converter.h"
#include "strutils.h"
#include "threads.h"

View File

@ -43,6 +43,7 @@
#include "compat.h"
#include "endiantest.h"
#include "logging.h"
#include "strutils.h"
#include "threads.h"
#include "vector.h"

View File

@ -40,6 +40,7 @@
#include "alcmain.h"
#include "alu.h"
#include "ringbuffer.h"
#include "strutils.h"
#include "threads.h"
#include "compat.h"

View File

@ -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 {

View File

@ -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"

View File

@ -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)};

43
common/strutils.h Normal file
View File

@ -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 */