add support for codepage selection in winchar_*ansi
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4886 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
ac156f5ebe
commit
478f9536e4
2 changed files with 9 additions and 8 deletions
|
@ -6,28 +6,29 @@
|
||||||
|
|
||||||
using std::runtime_error;
|
using std::runtime_error;
|
||||||
|
|
||||||
WCHAR *winchar_fromansi(const char* s) {
|
WCHAR *winchar_fromansi(const char* s, unsigned int codepage/*=CP_ACP*/)
|
||||||
int l = MultiByteToWideChar(CP_ACP, 0, s, -1, 0, 0);
|
{
|
||||||
|
int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0);
|
||||||
if (l == 0)
|
if (l == 0)
|
||||||
throw runtime_error("Unicode conversion failed");
|
throw runtime_error("Unicode conversion failed");
|
||||||
|
|
||||||
WCHAR *ws = new WCHAR[l + 1];
|
WCHAR *ws = new WCHAR[l + 1];
|
||||||
|
|
||||||
if (MultiByteToWideChar(CP_ACP, 0, s, -1, ws, l + 1) == 0)
|
if (MultiByteToWideChar(codepage, 0, s, -1, ws, l + 1) == 0)
|
||||||
throw runtime_error("Unicode conversion failed");
|
throw runtime_error("Unicode conversion failed");
|
||||||
|
|
||||||
return ws;
|
return ws;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *winchar_toansi(const WCHAR* ws)
|
char *winchar_toansi(const WCHAR* ws, unsigned int codepage/*=CP_ACP*/)
|
||||||
{
|
{
|
||||||
int l = WideCharToMultiByte(CP_ACP, 0, ws, -1, 0, 0, 0, 0);
|
int l = WideCharToMultiByte(codepage, 0, ws, -1, 0, 0, 0, 0);
|
||||||
if (l == 0)
|
if (l == 0)
|
||||||
throw runtime_error("Unicode conversion failed");
|
throw runtime_error("Unicode conversion failed");
|
||||||
|
|
||||||
char *s = new char[l + 1];
|
char *s = new char[l + 1];
|
||||||
|
|
||||||
if (WideCharToMultiByte(CP_ACP, 0, ws, -1, s, l + 1, 0, 0) == 0)
|
if (WideCharToMultiByte(codepage, 0, ws, -1, s, l + 1, 0, 0) == 0)
|
||||||
throw runtime_error("Unicode conversion failed");
|
throw runtime_error("Unicode conversion failed");
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
|
|
||||||
WCHAR *winchar_fromansi(const char* s);
|
WCHAR *winchar_fromansi(const char* s, unsigned int codepage = CP_ACP);
|
||||||
char *winchar_toansi(const WCHAR* ws);
|
char *winchar_toansi(const WCHAR* ws, unsigned int codepage = CP_ACP);
|
||||||
WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2);
|
WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2);
|
||||||
WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n);
|
WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n);
|
||||||
size_t winchar_strlen(WCHAR *ws);
|
size_t winchar_strlen(WCHAR *ws);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue