Files
envi-code/SourceCode/Code2026/tg_shs/shs_geLib/TWCString.cpp
T
2026-09-28 15:28:50 +08:00

296 lines
4.2 KiB
C++

//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TWCString.cpp
// = Version : ver2.0
// = Author : xlc
// = CreateDate : 2002-09-09
// = Description: 类的定义
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TWCString.h"
#include "TchGlobalFunc.h"
TWCString::TWCString(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 = WStrNew(szVal);
}
TWCString::TWCString(int nLen)
{
if (nLen <= 0)
{
exit(1);
}
str = new wchar_t [nLen];
str[0] = 0;
}
TWCString::TWCString(const TWCString &szSrc)
: str(NULL)
{
(*this) = szSrc.str;
}
TWCString::~TWCString()
{
if (str)
{
delete [] str;
}
}
#ifdef _UNICODE
TWCString::TWCString(const CString &strSrc)
: str(NULL)
{
(*this) = (const wchar_t *)strSrc;
}
TWCString & TWCString::operator = (const CString &strSrc)
{
return ((*this) = (const wchar_t *)strSrc);
}
TWCString & TWCString::operator << (const CString &strSrc)
{
// str的空间要足够大
return ((*this) << (const wchar_t *)strSrc);
}
int TWCString::operator == (const CString &strSrc) const
{
return ((*this) == (const wchar_t *)strSrc);
}
int TWCString::operator != (const CString &strSrc) const
{
return ((*this) != (const wchar_t *)strSrc);
}
#endif
int TWCString::Length()
{
if (str)
{
return wcslen(str);
}
else
{
return 0;
}
}
wchar_t * TWCString::StrChr(wchar_t szVal)
{
return wcschr(str,szVal);
}
TWCString::operator const wchar_t * () const
{
return str;
}
// Provide 97.6.28
TWCString::operator wchar_t * ()
{
return str;
}
wchar_t & TWCString::operator [] (int nIndex)
{
return str[nIndex];
}
const wchar_t & TWCString::operator [] (int nIndex) const
{
return str[nIndex];
}
TWCString & TWCString::operator << (const wchar_t *pszVal)
{
// str的空间要足够大
if (!str)
{
str = new wchar_t [256];
str[0] = 0;
}
wcscat(str, pszVal);
return *this;
}
#ifdef _UNICODE
TWCString & TWCString::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;
}
TWCString & TWCString::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;
}
TWCString & TWCString::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;
}
TWCString & TWCString::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 TWCString::operator !() const
{
return (!str || !str[0]) ? 1 : 0;
}
//
//TWCString & TWCString::operator = (int nLength)
//{
// if (nLength > 0 )
// {
// str = new wchar_t [nLength];
// str[0] = 0;
// }
// return *this;
//}
TWCString & TWCString::operator = (const wchar_t * pszSrc)
{
if (str)
{
delete[] str;
}
if (pszSrc)
{
str = WStrNew(pszSrc);
}
else
{
str = NULL;
}
return *this;
}
TWCString & TWCString::operator = (const TWCString & szSrc)
{
if (str)
{
delete[] str;
}
if (szSrc.str)
{
str = WStrNew(szSrc.str);
}
else
{
str = NULL;
}
return *this;
}
int TWCString::operator == (const wchar_t *pszSrc) const
{
if (!str || !pszSrc)
{
exit(1);
}
return !wcscmp(str, pszSrc);
}
int TWCString::operator != (const wchar_t *pszSrc) const
{
if (!str || !pszSrc)
{
exit(1);
}
return wcscmp(str, pszSrc);
}
int TWCString::operator == (const TWCString &szSrc) const
{
if (!str || !szSrc.str)
{
exit(1);
}
return !wcscmp(str, szSrc.str);
}
int TWCString::operator != (const TWCString &szSrc) const
{
if (!str || !szSrc.str)
{
exit(1);
}
return wcscmp(str, szSrc.str);
}