mirror of https://github.com/tongzx/nt5src
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
951 B
61 lines
951 B
// CUSTRING.CPP
|
|
//
|
|
// Implementation of the CUSTRING class, a lightweight class used to convert
|
|
// strings seamlessly between ANSI and Unicode.
|
|
//
|
|
// Derived from STRCORE.CPP.
|
|
|
|
#include "precomp.h"
|
|
#include <cstring.hpp>
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
|
|
CUSTRING::CUSTRING(PCWSTR wszText) :
|
|
wszData((PWSTR)wszText),
|
|
szData(NULL),
|
|
bUnicodeNew(FALSE),
|
|
bAnsiNew(FALSE)
|
|
{
|
|
// AssignString;
|
|
}
|
|
|
|
CUSTRING::CUSTRING(PCSTR szText) :
|
|
szData((PSTR)szText),
|
|
wszData(NULL),
|
|
bUnicodeNew(FALSE),
|
|
bAnsiNew(FALSE)
|
|
{
|
|
// AssignString;
|
|
}
|
|
|
|
CUSTRING::~CUSTRING()
|
|
{
|
|
if (bUnicodeNew) {
|
|
delete wszData;
|
|
}
|
|
if (bAnsiNew) {
|
|
delete szData;
|
|
}
|
|
}
|
|
|
|
CUSTRING::operator PWSTR()
|
|
{
|
|
if (szData && !wszData) {
|
|
wszData = AnsiToUnicode(szData);
|
|
bUnicodeNew = TRUE;
|
|
}
|
|
return wszData;
|
|
}
|
|
|
|
CUSTRING::operator PSTR()
|
|
{
|
|
if (wszData && !szData) {
|
|
szData = UnicodeToAnsi(wszData);
|
|
bAnsiNew = TRUE;
|
|
}
|
|
return szData;
|
|
}
|