///////////////////////////////////////////////////////////////////////////////
//
// Copyright 1999 Alexander Keck
//
// $Workfile: UnicodeString.cpp $
//
// $Author: Alex $
//
// $Date: 16.03.99 8:43 $
//
// Contents: CUnicodeString - CUnicodeString Class
//
// Classes: CUnicodeString
//
// Functions: a lot
//
///////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "UnicodeString.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define _wcsinc(_pc) ((_pc)+1)
BOOL IsValidString(LPCSTR lpsz, int nLength)
{
if (lpsz == NULL)
return FALSE;
return ::IsBadStringPtrA(lpsz, nLength) == 0;
}
BOOL IsValidString(LPCWSTR lpsz, int nLength)
{
if (lpsz == NULL)
return FALSE;
return ::IsBadStringPtrW(lpsz, nLength) == 0;
}
CUnicodeString::CUnicodeString()
{
m_Length = 0;
m_MaximumLength = 0;
m_Buffer = NULL;
m_TempBuff = NULL;
}
CUnicodeString::CUnicodeString(UNICODE_STRING* puString)
{
m_TempBuff = NULL;
m_MaximumLength = m_Length = puString->Length;
m_Buffer = (LPWSTR)malloc((m_Length + 1) * sizeof(WCHAR));
memcpy(m_Buffer, puString->Buffer, m_Length * sizeof(WCHAR));
}
CUnicodeString::CUnicodeString(LPCWSTR pstrString)
{
m_TempBuff = NULL;
InitializeFromWideString(pstrString);
}
CUnicodeString::CUnicodeString(LPCSTR pstrString)
{
m_TempBuff = NULL;
InitializeFromString(pstrString);
}
CUnicodeString::CUnicodeString(const CUnicodeString& strString)
{
if(strString.IsEmpty())
{
m_Length = m_MaximumLength = 0;
m_Buffer = NULL;
m_TempBuff = NULL;
}
else
{
m_Length = strString.m_Length;
m_MaximumLength = strString.m_MaximumLength;
m_Buffer = (LPWSTR)malloc((m_Length + 1) * sizeof(WCHAR));
wcscpy(m_Buffer, strString.m_Buffer);
m_TempBuff = NULL;
}
}
CUnicodeString::~CUnicodeString()
{
if(m_Buffer)
free(m_Buffer);
if(m_TempBuff)
free(m_TempBuff);
}
const CUnicodeString& CUnicodeString::operator =(UNICODE_STRING* puString)
{
m_MaximumLength = m_Length = puString->Length;
m_Buffer = (LPWSTR)malloc((m_Length + 1) * sizeof(WCHAR));
memcpy(m_Buffer, puString->Buffer, m_Length * sizeof(WCHAR));
return *this;
}
const CUnicodeString& CUnicodeString::operator =(LPCWSTR pstrString)
{
if(pstrString == NULL)
{
Empty();
return *this;
}
ASSERT(IsValidString(pstrString));
if(m_Buffer)
free(m_Buffer);
InitializeFromWideString(pstrString);
return *this;
}
const CUnicodeString& CUnicodeString::operator =(LPCSTR pstrString)
{
if(pstrString == NULL)
{
Empty();
return *this;
}
ASSERT(IsValidString(pstrString));
if(m_Buffer)
free(m_Buffer);
InitializeFromString(pstrString);
return *this;
}
const CUnicodeString& CUnicodeString::operator =(WCHAR ch)
{
if(m_Buffer)
free(m_Buffer);
WCHAR pstrString[] = L"\0\0";
pstrString[0] = ch;
InitializeFromWideString(pstrString);
return *this;
}
const CUnicodeString& CUnicodeString::operator =(CHAR ch)
{
if(m_Buffer)
free(m_Buffer);
CHAR pstrString[] = "\0\0";
pstrString[0] = ch;
InitializeFromString(pstrString);
return *this;
}
const CUnicodeString& CUnicodeString::operator =(const CUnicodeString& strString)
{
if(m_TempBuff)
free(m_TempBuff);
if(m_Buffer)
free(m_Buffer);
if(strString.IsEmpty())
{
m_Length = m_MaximumLength = 0;
m_Buffer = NULL;
m_TempBuff = NULL;
}
else
{
m_Length = strString.m_Length;
m_MaximumLength = strString.m_MaximumLength;
m_Buffer = (LPWSTR)malloc((m_Length + 1) * sizeof(WCHAR));
wcscpy(m_Buffer, strString.m_Buffer);
m_TempBuff = NULL;
}
return *this;
}
BOOL CUnicodeString::InitializeFromWideString(LPCWSTR pstrString)
{
if(pstrString == NULL)
{
Empty();
return TRUE;
}
ASSERT(IsValidString(pstrString));
m_Length = wcslen(pstrString);
m_MaximumLength = m_Length;
m_Buffer = (LPWSTR)malloc((m_Length + 1) * sizeof(WCHAR));
wcscpy(m_Buffer, pstrString);
m_Buffer[m_Length] = L'\0';
if(m_Buffer)
return TRUE;
return FALSE;
}
BOOL CUnicodeString::InitializeFromString(LPCSTR pstrString)
{
if(pstrString == NULL)
{
Empty();
return TRUE;
}
ASSERT(IsValidString(pstrString));
m_Length = strlen(pstrString);
m_MaximumLength = m_Length;
m_Buffer = (LPWSTR)malloc((m_Length + 1) * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, pstrString, m_Length, m_Buffer, m_Length);
m_Buffer[m_Length] = L'\0';
if(m_Buffer)
return TRUE;
return FALSE;
}
void CUnicodeString::operator += (const CUnicodeString& usString)
{
m_Length += wcslen(usString);
LPWSTR pstrNewString = (LPWSTR)malloc(m_Length);
wcscpy(pstrNewString, m_Buffer);
wcscat(pstrNewString, usString);
free(m_Buffer);
m_Buffer = pstrNewString;
m_MaximumLength = m_Length;
}
void CUnicodeString::operator += (LPCWSTR pstrString)
{
ASSERT(IsValidString(pstrString));
m_Length += wcslen(pstrString);
LPWSTR pstrNewString = (LPWSTR)malloc(m_Length);
wcscpy(pstrNewString, m_Buffer);
wcscat(pstrNewString, pstrString);
free(m_Buffer);
m_Buffer = pstrNewString;
m_MaximumLength = m_Length;
}
void CUnicodeString::operator += (LPCSTR pstrString)
{
ASSERT(IsValidString(pstrString));
USHORT usNewLength = m_Length + strlen(pstrString);
LPWSTR pstrNewString = (LPWSTR)malloc(usNewLength);
wcscpy(pstrNewString, m_Buffer);
MultiByteToWideChar(CP_ACP, 0, pstrString, strlen(pstrString), &pstrNewString[m_Length], usNewLength - m_Length);
free(m_Buffer);
m_Buffer = pstrNewString;
m_Length = usNewLength;
m_MaximumLength = m_Length;
}
void CUnicodeString::operator += (WCHAR wch)
{
m_Length++;
LPWSTR pstrNewString = (LPWSTR)malloc(m_Length);
wcscpy(pstrNewString, m_Buffer);
pstrNewString[m_Length - 1] = wch;
pstrNewString[m_Length] = L'\0';
free(m_Buffer);
m_Buffer = pstrNewString;
m_MaximumLength = m_Length;
}
void CUnicodeString::operator += (CHAR ch)
{
USHORT usNewLength = m_Length + 1;
LPWSTR pstrNewString = (LPWSTR)malloc(usNewLength);
wcscpy(pstrNewString, m_Buffer);
MultiByteToWideChar(CP_ACP, 0, &ch, 1, &pstrNewString[m_Length], usNewLength - m_Length);
pstrNewString[usNewLength] = L'\0';
free(m_Buffer);
m_Buffer = pstrNewString;
m_Length = usNewLength;
m_MaximumLength = m_Length;
}
// CUnicodeString::operator const LPCSTR ()
BOOL operator ==(const CUnicodeString& s1, const CUnicodeString& s2)
{
if(wcslen(s1) != wcslen(s2))
return FALSE;
if(wcscmp(s1, s2))
return FALSE;
return TRUE;
}
BOOL operator ==(const CUnicodeString& s1, LPCWSTR s2)
{
ASSERT(IsValidString(s2));
if(wcslen(s1) != wcslen(s2))
return FALSE;
if(wcscmp(s1, s2))
return FALSE;
return TRUE;
}
BOOL operator ==(const CUnicodeString& s1, LPCSTR s2)
{
ASSERT(IsValidString(s2));
USHORT usLen = strlen(s2);
if(usLen != wcslen(s1))
return FALSE;
BOOL bRet = TRUE;
LPWSTR ws2 = (LPWSTR)malloc((usLen + 1) * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, s2, usLen, ws2, usLen);
ws2[usLen] = L'\0';
if(wcscmp(s1, ws2))
bRet = FALSE;
free(ws2);
return bRet;
}
BOOL operator ==(LPCWSTR s1, const CUnicodeString& s2)
{
ASSERT(IsValidString(s1));
if(wcslen(s1) != wcslen(s2))
return FALSE;
if(wcscmp(s1, s2))
return FALSE;
return TRUE;
}
BOOL operator ==(LPCSTR s1, const CUnicodeString& s2)
{
ASSERT(IsValidString(s1));
USHORT usLen = strlen(s1);
if(usLen != wcslen(s2))
return FALSE;
BOOL bRet = TRUE;
LPWSTR ws1 = (LPWSTR)malloc((usLen + 1) * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, s1, usLen, ws1, usLen);
ws1[usLen] = L'\0';
if(wcscmp(ws1, s2))
bRet = FALSE;
free(ws1);
return bRet;
}
BOOL operator !=(const CUnicodeString& s1, const CUnicodeString& s2)
{
if(wcslen(s1) != wcslen(s2))
return TRUE;
if(!w
unicode_string_src.zip_CUnicodeString pudn_UnicodeString.cpp_uni
版权申诉
104 浏览量
2022-09-23
07:41:06
上传
评论
收藏 6KB ZIP 举报
weixin_42653672
- 粉丝: 93
- 资源: 1万+
最新资源
- 基于STM32F103C8T6单片机蓄电池在线监测系统主板硬件(原理图+PCB)工程文件.zip
- mysql大纲资料.txt
- c++大纲资料.txt
- 效率工具bat脚本实现日志提取
- MyBatis 中动态 SQL 的示例
- STM8L101F3P6单片机+CC1100模块433M遥控器设计硬件(原理图+PCB)工程文件.zip
- 上传下载铁人下载系统 Liuxing 1.0-liuxing1.0.rar
- 南京邮电大学数学实验实力雄厚,凭借其优秀的师资力量、丰富的实践教学资源和卓越的科研成果,成为国内一流的数学实验教学和科研基地
- 【火爆朋友圈的今天吃什么源码 v1.0】随机的为用户带来每一天的用餐选择和推荐.rar
- MPU6050中文版数据手册
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈