286 lines
3.9 KiB
C++
286 lines
3.9 KiB
C++
#include "StdAfx.h"
|
|
#include "WCString.h"
|
|
#include "globalFunc.h"
|
|
|
|
WCString::WCString(const wchar_t *pszFormat, ...)
|
|
: str(NULL)
|
|
{
|
|
if (!pszFormat)
|
|
{
|
|
return;
|
|
}
|
|
else if (!pszFormat[0])
|
|
{
|
|
str = new wchar_t[1];
|
|
str[0] = NULL;
|
|
return;
|
|
}
|
|
|
|
wchar_t szVal[1024];
|
|
va_list vlist;
|
|
|
|
va_start(vlist, pszFormat);
|
|
vswprintf(szVal, pszFormat, vlist);
|
|
va_end(vlist);
|
|
|
|
str = GlobalFunc::WStrNew(szVal);
|
|
}
|
|
|
|
WCString::WCString(int nLen)
|
|
{
|
|
if (nLen <= 0)
|
|
{
|
|
exit(1);
|
|
}
|
|
|
|
str = new wchar_t [nLen];
|
|
str[0] = 0;
|
|
}
|
|
|
|
WCString::WCString(const WCString &szSrc)
|
|
: str(NULL)
|
|
{
|
|
(*this) = szSrc.str;
|
|
}
|
|
|
|
WCString::~WCString()
|
|
{
|
|
if (str)
|
|
{
|
|
delete [] str;
|
|
}
|
|
}
|
|
|
|
#ifdef _UNICODE
|
|
WCString::WCString(const CString &strSrc)
|
|
: str(NULL)
|
|
{
|
|
(*this) = (const wchar_t *)strSrc;
|
|
}
|
|
|
|
WCString & WCString::operator = (const CString &strSrc)
|
|
{
|
|
return ((*this) = (const wchar_t *)strSrc);
|
|
}
|
|
|
|
WCString & WCString::operator << (const CString &strSrc)
|
|
{
|
|
// str的空间要足够大
|
|
return ((*this) << (const wchar_t *)strSrc);
|
|
}
|
|
|
|
int WCString::operator == (const CString &strSrc) const
|
|
{
|
|
return ((*this) == (const wchar_t *)strSrc);
|
|
}
|
|
|
|
int WCString::operator != (const CString &strSrc) const
|
|
{
|
|
return ((*this) != (const wchar_t *)strSrc);
|
|
}
|
|
|
|
#endif
|
|
|
|
int WCString::Length()
|
|
{
|
|
if (str)
|
|
{
|
|
return wcslen(str);
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
wchar_t * WCString::_StrChr(wchar_t szVal)
|
|
{
|
|
return wcschr(str,szVal);
|
|
}
|
|
|
|
WCString::operator const wchar_t * () const
|
|
{
|
|
return str;
|
|
}
|
|
|
|
// Provide 97.6.28
|
|
WCString::operator wchar_t * ()
|
|
{
|
|
return str;
|
|
}
|
|
|
|
wchar_t & WCString::operator [] (int nIndex)
|
|
{
|
|
return str[nIndex];
|
|
}
|
|
|
|
const wchar_t & WCString::operator [] (int nIndex) const
|
|
{
|
|
return str[nIndex];
|
|
}
|
|
|
|
WCString & WCString::operator << (const wchar_t *pszVal)
|
|
{
|
|
// str的空间要足够大
|
|
if (!str)
|
|
{
|
|
str = new wchar_t [256];
|
|
str[0] = 0;
|
|
}
|
|
|
|
wcscat(str, pszVal);
|
|
return *this;
|
|
}
|
|
|
|
#ifdef _UNICODE
|
|
|
|
WCString & WCString::operator << (int iVal)
|
|
{
|
|
if (!str)
|
|
{
|
|
str = new wchar_t [256];
|
|
str[0] = 0;
|
|
}
|
|
|
|
wchar_t szOut[30];
|
|
_swprintf(szOut, _T("%d"), iVal);
|
|
wcscat(str, szOut);
|
|
return *this;
|
|
}
|
|
|
|
WCString & WCString::operator << (long iVal)
|
|
{
|
|
if (!str)
|
|
{
|
|
str = new wchar_t [256];
|
|
str[0] = 0;
|
|
}
|
|
|
|
wchar_t szOut[30];
|
|
_swprintf(szOut,_T("%ld"), iVal);
|
|
wcscat(str, szOut);
|
|
return *this;
|
|
}
|
|
|
|
WCString & WCString::operator << (double dVal)
|
|
{
|
|
if (!str)
|
|
{
|
|
str = new wchar_t [256];
|
|
str[0] = 0;
|
|
}
|
|
|
|
wchar_t szOut[60];
|
|
_swprintf(szOut, _T("%g"), dVal);
|
|
wcscat(str, szOut);
|
|
return *this;
|
|
}
|
|
|
|
WCString & WCString::operator << (double * pdVal)
|
|
{
|
|
if (!str)
|
|
{
|
|
str = new wchar_t [256];
|
|
str[0] = 0;
|
|
}
|
|
|
|
wchar_t szOut[120];
|
|
_swprintf(szOut, _T("(%g,%g,%g)"), pdVal[0], pdVal[1], pdVal[2]);
|
|
wcscat(str, szOut);
|
|
return *this;
|
|
}
|
|
#endif
|
|
|
|
int WCString::operator !() const
|
|
{
|
|
return (!str || !str[0]) ? 1 : 0;
|
|
}
|
|
//
|
|
//WCString & WCString::operator = (int nLength)
|
|
//{
|
|
// if (nLength > 0 )
|
|
// {
|
|
// str = new wchar_t [nLength];
|
|
// str[0] = 0;
|
|
// }
|
|
// return *this;
|
|
//}
|
|
|
|
WCString & WCString::operator = (const wchar_t * pszSrc)
|
|
{
|
|
if (str)
|
|
{
|
|
delete[] str;
|
|
}
|
|
|
|
if (pszSrc)
|
|
{
|
|
str = GlobalFunc::WStrNew(pszSrc);
|
|
}
|
|
else
|
|
{
|
|
str = NULL;
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
WCString & WCString::operator = (const WCString & szSrc)
|
|
{
|
|
if (str)
|
|
{
|
|
delete[] str;
|
|
}
|
|
|
|
if (szSrc.str)
|
|
{
|
|
str = GlobalFunc::WStrNew(szSrc.str);
|
|
}
|
|
else
|
|
{
|
|
str = NULL;
|
|
}
|
|
|
|
return *this;
|
|
}
|
|
|
|
int WCString::operator == (const wchar_t *pszSrc) const
|
|
{
|
|
if (!str || !pszSrc)
|
|
{
|
|
exit(1);
|
|
}
|
|
|
|
return !wcscmp(str, pszSrc);
|
|
}
|
|
|
|
int WCString::operator != (const wchar_t *pszSrc) const
|
|
{
|
|
if (!str || !pszSrc)
|
|
{
|
|
exit(1);
|
|
}
|
|
|
|
return wcscmp(str, pszSrc);
|
|
}
|
|
|
|
int WCString::operator == (const WCString &szSrc) const
|
|
{
|
|
if (!str || !szSrc.str)
|
|
{
|
|
exit(1);
|
|
}
|
|
|
|
return !wcscmp(str, szSrc.str);
|
|
}
|
|
|
|
int WCString::operator != (const WCString &szSrc) const
|
|
{
|
|
if (!str || !szSrc.str)
|
|
{
|
|
exit(1);
|
|
}
|
|
|
|
return wcscmp(str, szSrc.str);
|
|
}
|