From 478f9536e46e6930f08dc508105b5f0cfe457d10 Mon Sep 17 00:00:00 2001 From: kichik Date: Thu, 25 Jan 2007 13:04:52 +0000 Subject: [PATCH] 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 --- Source/winchar.cpp | 13 +++++++------ Source/winchar.h | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Source/winchar.cpp b/Source/winchar.cpp index 56b98e31..cb9a568a 100644 --- a/Source/winchar.cpp +++ b/Source/winchar.cpp @@ -6,28 +6,29 @@ using std::runtime_error; -WCHAR *winchar_fromansi(const char* s) { - int l = MultiByteToWideChar(CP_ACP, 0, s, -1, 0, 0); +WCHAR *winchar_fromansi(const char* s, unsigned int codepage/*=CP_ACP*/) +{ + int l = MultiByteToWideChar(codepage, 0, s, -1, 0, 0); if (l == 0) throw runtime_error("Unicode conversion failed"); 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"); 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) throw runtime_error("Unicode conversion failed"); 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"); return s; diff --git a/Source/winchar.h b/Source/winchar.h index 53e5046e..de16eb6c 100644 --- a/Source/winchar.h +++ b/Source/winchar.h @@ -1,7 +1,7 @@ #include "Platform.h" -WCHAR *winchar_fromansi(const char* s); -char *winchar_toansi(const WCHAR* ws); +WCHAR *winchar_fromansi(const char* s, unsigned int codepage = CP_ACP); +char *winchar_toansi(const WCHAR* ws, unsigned int codepage = CP_ACP); WCHAR *winchar_strcpy(WCHAR *ws1, const WCHAR *ws2); WCHAR *winchar_strncpy(WCHAR *ws1, const WCHAR *ws2, size_t n); size_t winchar_strlen(WCHAR *ws);