2010-04-20 09:04:26 +00:00
|
|
|
// tstring.cpp
|
|
|
|
//
|
|
|
|
// This file is a part of Unicode NSIS.
|
|
|
|
//
|
2013-05-17 19:31:36 +00:00
|
|
|
// Copyright (C) 2007-2013 Jim Park
|
2010-04-20 09:04:26 +00:00
|
|
|
//
|
|
|
|
// Licensed under the zlib/libpng license (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
//
|
|
|
|
// This software is provided 'as-is', without any expressed or implied
|
|
|
|
// warranty.
|
|
|
|
//
|
|
|
|
// Provides TSTRING support.
|
|
|
|
|
|
|
|
#ifdef _UNICODE
|
|
|
|
|
|
|
|
#include "tstring.h"
|
2010-05-03 10:12:33 +00:00
|
|
|
#include "util.h"
|
2010-04-20 09:04:26 +00:00
|
|
|
#include <vector>
|
2012-10-13 01:47:50 +00:00
|
|
|
#include <stdio.h>
|
2010-04-20 09:04:26 +00:00
|
|
|
|
|
|
|
|
2013-03-24 06:08:16 +00:00
|
|
|
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; }
|
|
|
|
|
2013-03-24 22:37:00 +00:00
|
|
|
CtoTString::operator const wchar_t*() const { return GetTStr(); }
|
2013-03-24 06:08:16 +00:00
|
|
|
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; }
|
|
|
|
|
2013-03-24 22:37:00 +00:00
|
|
|
TtoCString::operator const char*() const { return m_cStr; }
|
2013-03-24 06:08:16 +00:00
|
|
|
|
2010-04-20 09:04:26 +00:00
|
|
|
#endif
|