From 43af25ac0bdba1e242a9900eabdb647f79748560 Mon Sep 17 00:00:00 2001 From: kichik Date: Sun, 24 Mar 2013 06:08:16 +0000 Subject: [PATCH] MultiByteToWideChar is defined by tchar.h, but tchar.h includes tstring.h also, it seems _TSTRING_H_ is used by something else git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6313 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/tstring.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ Source/tstring.h | 51 ++++++++++++---------------------------------- 2 files changed, 59 insertions(+), 38 deletions(-) diff --git a/Source/tstring.cpp b/Source/tstring.cpp index e8a5ee97..82fb699d 100644 --- a/Source/tstring.cpp +++ b/Source/tstring.cpp @@ -101,4 +101,50 @@ FILE* FileOpenUnicodeText(const TCHAR* file, const TCHAR* mode, BOOL* unicode) return _tfopen(file, strMode.c_str()); } +CtoTString::CtoTString(const char* str) +{ + int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); + m_wStr = (wchar_t*) malloc(len*sizeof(wchar_t)); + MultiByteToWideChar(CP_ACP, 0, str, -1, m_wStr, len); +} + +CtoTString::CtoTString(const char* str, UINT cp) +{ + int len = MultiByteToWideChar(cp, 0, str, -1, NULL, 0); + m_wStr = (wchar_t*) malloc(len*sizeof(wchar_t)); + MultiByteToWideChar(cp, 0, str, -1, m_wStr, len); +} + +CtoTString::CtoTString(const std::string& str) +{ + int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length()+1, NULL, 0); + m_wStr = (wchar_t*) malloc(len*sizeof(wchar_t)); + MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length()+1, m_wStr, len); +} + +CtoTString::~CtoTString() { free(m_wStr); m_wStr = 0; } + +operator const CtoTString::wchar_t*() const { return GetTStr(); } +inline const wchar_t* CtoTString::GetTStr() const { return m_wStr; } + + + +TtoCString::TtoCString(const wchar_t* wStr) +{ + int len = WideCharToMultiByte(CP_ACP, 0, wStr, -1, NULL, 0, 0, 0); + m_cStr = (char*) malloc(len); + WideCharToMultiByte(CP_ACP, 0, wStr, -1, m_cStr, len, 0, 0); +} + +TtoCString::TtoCString(const tstring& wStr) +{ + int len = WideCharToMultiByte(CP_ACP, 0, wStr.c_str(), wStr.length()+1, NULL, 0, 0, 0); + m_cStr = (char*) malloc(len); + WideCharToMultiByte(CP_ACP, 0, wStr.c_str(), wStr.length()+1, m_cStr, len, 0, 0); +} + +TtoCString::~TtoCString() { free(m_cStr); m_cStr = 0; } + +operator const TtoCString::char*() const { return m_cStr; } + #endif diff --git a/Source/tstring.h b/Source/tstring.h index d85f612b..e8fd0e75 100644 --- a/Source/tstring.h +++ b/Source/tstring.h @@ -16,8 +16,8 @@ Unicode support by Jim Park -- 07/23/2007 */ -#ifndef _TSTRING_ -#define _TSTRING_ +#ifndef NSIS_TSTRING___H__ +#define NSIS_TSTRING___H__ #include "Platform.h" #include "tchar.h" @@ -57,29 +57,14 @@ typedef std::ifstream tifstream; class CtoTString { public: - CtoTString(const char* str) - { - int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); - m_wStr = (wchar_t*) malloc(len*sizeof(wchar_t)); - MultiByteToWideChar(CP_ACP, 0, str, -1, m_wStr, len); - } - CtoTString(const char* str, UINT cp) - { - int len = MultiByteToWideChar(cp, 0, str, -1, NULL, 0); - m_wStr = (wchar_t*) malloc(len*sizeof(wchar_t)); - MultiByteToWideChar(cp, 0, str, -1, m_wStr, len); - } - CtoTString(const std::string& str) - { - int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length()+1, NULL, 0); - m_wStr = (wchar_t*) malloc(len*sizeof(wchar_t)); - MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length()+1, m_wStr, len); - } + CtoTString(const char* str); + CtoTString(const char* str, UINT cp); + CtoTString(const std::string& str); - ~CtoTString() { free(m_wStr); m_wStr = 0; } + ~CtoTString(); - operator const wchar_t*() const { return GetTStr(); } - inline const wchar_t*GetTStr() const { return m_wStr; } + operator const wchar_t*() const; + inline const wchar_t*GetTStr() const; private: wchar_t* m_wStr; @@ -90,26 +75,16 @@ private: class TtoCString { public: - TtoCString(const wchar_t* wStr) - { - int len = WideCharToMultiByte(CP_ACP, 0, wStr, -1, NULL, 0, 0, 0); - m_cStr = (char*) malloc(len); - WideCharToMultiByte(CP_ACP, 0, wStr, -1, m_cStr, len, 0, 0); - } - TtoCString(const tstring& wStr) - { - int len = WideCharToMultiByte(CP_ACP, 0, wStr.c_str(), wStr.length()+1, NULL, 0, 0, 0); - m_cStr = (char*) malloc(len); - WideCharToMultiByte(CP_ACP, 0, wStr.c_str(), wStr.length()+1, m_cStr, len, 0, 0); - } + TtoCString(const wchar_t* wStr); + TtoCString(const tstring& wStr); - ~TtoCString() { free(m_cStr); m_cStr = 0; } + ~TtoCString(); - operator const char*() const { return m_cStr; } + operator const char*() const; private: char* m_cStr; }; #endif // _UNICODE -#endif +#endif // NSIS_TSTRING___H__