Fixed compiling issue on windows concerning cAudioString
This commit is contained in:
parent
241a89c919
commit
fadc71272b
|
@ -10,6 +10,7 @@
|
|||
#include "cSTLAllocator.h"
|
||||
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef CAUDIO_PLATFORM_WIN
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
|
@ -78,6 +79,14 @@ namespace cAudio
|
|||
return buffer[id];
|
||||
#endif
|
||||
}
|
||||
|
||||
static wchar_t* charToWChar(const char* text)
|
||||
{
|
||||
size_t size = strlen(text) + 1;
|
||||
wchar_t* wa = new wchar_t[size];
|
||||
mbstowcs(wa, text, size);
|
||||
return wa;
|
||||
}
|
||||
|
||||
static const char* toUTF8(const cAudioString& str)
|
||||
{
|
||||
|
@ -85,12 +94,12 @@ namespace cAudio
|
|||
static char buffer[8][1024];
|
||||
id = ++id & 0x7;
|
||||
|
||||
int buff_size = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), (int)(str.size() < 1023 ? str.size() : 1023), buffer[id], 1023, 0, false);
|
||||
int buff_size = WideCharToMultiByte(CP_UTF8, 0, charToWChar(str.c_str()), (int)(str.size() < 1023 ? str.size() : 1023), buffer[id], 1023, 0, false);
|
||||
buffer[id][buff_size] = 0;
|
||||
buffer[id][1023] = 0;
|
||||
return buffer[id];
|
||||
}
|
||||
|
||||
|
||||
static cAudioString fromUTF8(const char* str)
|
||||
{
|
||||
wchar_t* buffer = 0;
|
||||
|
@ -99,9 +108,12 @@ namespace cAudio
|
|||
return cAudioString();
|
||||
|
||||
buffer = new wchar_t[buff_size + 1];
|
||||
|
||||
memset((void*)buffer, 0, sizeof(wchar_t) * (buff_size + 1));
|
||||
MultiByteToWideChar(CP_UTF8, 0, str, (int)strlen(str), buffer, buff_size);
|
||||
cAudioString s(buffer);
|
||||
char* convert = new char[buff_size+1];
|
||||
wcstombs(convert, buffer, sizeof(wchar_t) * (buff_size + 1));
|
||||
cAudioString s(convert);
|
||||
delete[] buffer;
|
||||
return s;
|
||||
}
|
||||
|
@ -123,3 +135,4 @@ namespace cAudio
|
|||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue