2015-05-06 21:31:40 +00:00
|
|
|
#ifndef __ATLSTR_H__
|
|
|
|
#define __ATLSTR_H__
|
|
|
|
|
|
|
|
#pragma once
|
2015-09-24 18:06:02 +00:00
|
|
|
#include "atlbase.h"
|
|
|
|
#include "cstringt.h"
|
2015-05-06 21:31:40 +00:00
|
|
|
|
|
|
|
namespace ATL
|
|
|
|
{
|
2015-09-23 20:05:31 +00:00
|
|
|
|
|
|
|
class CAtlStringMgr : public IAtlStringMgr
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
IAtlMemMgr* m_MemMgr;
|
|
|
|
CNilStringData m_NilStrData;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CAtlStringMgr(_In_opt_ IAtlMemMgr* MemMgr = NULL):
|
|
|
|
m_MemMgr(MemMgr)
|
2015-05-06 21:31:40 +00:00
|
|
|
{
|
2015-09-23 20:05:31 +00:00
|
|
|
m_NilStrData.SetManager(this);
|
|
|
|
}
|
2015-05-06 21:31:40 +00:00
|
|
|
|
2015-09-23 20:05:31 +00:00
|
|
|
virtual ~CAtlStringMgr(void)
|
|
|
|
{
|
|
|
|
}
|
2015-05-06 21:31:40 +00:00
|
|
|
|
2015-09-23 20:05:31 +00:00
|
|
|
static IAtlStringMgr* GetInstance(void)
|
|
|
|
{
|
|
|
|
static CWin32Heap Win32Heap(::GetProcessHeap());
|
|
|
|
static CAtlStringMgr StringMgr(&Win32Heap);
|
|
|
|
return &StringMgr;
|
|
|
|
}
|
2015-05-06 21:31:40 +00:00
|
|
|
|
2015-09-23 20:05:31 +00:00
|
|
|
virtual _Ret_maybenull_ _Post_writable_byte_size_(sizeof(CStringData) + NumChars * CharSize) CStringData* Allocate(
|
|
|
|
_In_ int NumChars,
|
|
|
|
_In_ int CharSize)
|
2015-05-06 21:31:40 +00:00
|
|
|
{
|
2015-09-23 20:05:31 +00:00
|
|
|
size_t SizeBytes;
|
|
|
|
CStringData* StrData;
|
|
|
|
|
|
|
|
SizeBytes = sizeof(CStringData) + ((NumChars + 1) * CharSize);
|
|
|
|
|
|
|
|
StrData = static_cast<CStringData*>(m_MemMgr->Allocate(SizeBytes));
|
|
|
|
if (StrData == NULL) return NULL;
|
|
|
|
|
|
|
|
StrData->pStringMgr = this;
|
|
|
|
StrData->nRefs = 1;
|
|
|
|
StrData->nAllocLength = NumChars;
|
|
|
|
StrData->nDataLength = 0;
|
|
|
|
|
|
|
|
return StrData;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Free(_In_ CStringData* StrData)
|
|
|
|
{
|
|
|
|
ATLASSERT(StrData->pStringMgr == this);
|
|
|
|
m_MemMgr->Free(StrData);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual _Ret_maybenull_ _Post_writable_byte_size_(sizeof(CStringData) + nChars*nCharSize) CStringData* Reallocate(
|
|
|
|
_Inout_ _Post_readable_byte_size_(sizeof(CStringData)) CStringData* StrData,
|
|
|
|
_In_ int nChars,
|
|
|
|
_In_ int nCharSize) throw()
|
|
|
|
{
|
|
|
|
ATLASSERT(StrData->pStringMgr == this);
|
|
|
|
|
|
|
|
CStringData* pNewData;
|
|
|
|
ULONG SizeBytes;
|
|
|
|
ULONG nDataBytes;
|
|
|
|
|
|
|
|
nChars++;
|
|
|
|
nDataBytes = nChars * nCharSize;
|
|
|
|
SizeBytes = sizeof(CStringData) + nDataBytes;
|
|
|
|
|
2015-09-24 20:59:09 +00:00
|
|
|
pNewData = static_cast<CStringData*>(m_MemMgr->Reallocate(StrData, SizeBytes));
|
2015-09-23 20:05:31 +00:00
|
|
|
if (pNewData == NULL) return NULL;
|
|
|
|
|
|
|
|
pNewData->nAllocLength = nChars - 1;
|
|
|
|
return pNewData;
|
|
|
|
}
|
|
|
|
virtual CStringData* GetNilString() throw()
|
|
|
|
{
|
|
|
|
m_NilStrData.AddRef();
|
|
|
|
return &m_NilStrData;
|
|
|
|
}
|
|
|
|
virtual IAtlStringMgr* Clone() throw()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool StaticInitialize()
|
|
|
|
{
|
|
|
|
GetInstance();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-30 19:55:52 +00:00
|
|
|
|
2015-10-12 20:33:33 +00:00
|
|
|
template< typename _CharType = wchar_t >
|
|
|
|
class ChTraitsOS :
|
|
|
|
public ChTraitsBase < _CharType >
|
|
|
|
{
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-10-25 23:10:43 +00:00
|
|
|
template<typename _BaseType = wchar_t, class StringIterator = ChTraitsOS<_BaseType> >
|
2015-09-30 19:55:52 +00:00
|
|
|
class StrTraitATL :
|
|
|
|
public StringIterator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static HINSTANCE FindStringResourceInstance(_In_ UINT nID) throw()
|
|
|
|
{
|
|
|
|
return AtlFindStringResourceInstance(nID);
|
|
|
|
}
|
|
|
|
|
|
|
|
static IAtlStringMgr* GetDefaultManager() throw()
|
|
|
|
{
|
|
|
|
return CAtlStringMgr::GetInstance();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-10-25 23:10:43 +00:00
|
|
|
typedef CStringT< wchar_t, StrTraitATL< wchar_t, ChTraitsCRT<wchar_t> > > CAtlStringW;
|
[ATL][ATL_APITEST] Implement / Improve CString, based upon the code that was already there. CORE-11579 #resolve
Add code + tests for:
Conversion of A->W and W->A, equality operators, MakeLower, MakeUpper, Find, FindOneOf, ReverseFind, Compare, Mid, Left, Right, Format, Replace, Trim, TrimLeft, TrimRight.
svn path=/trunk/; revision=72061
2016-07-30 19:07:43 +00:00
|
|
|
typedef CStringT< char, StrTraitATL< char, ChTraitsCRT<char> > > CAtlStringA;
|
|
|
|
|
|
|
|
|
|
|
|
typedef CAtlStringW CStringW;
|
|
|
|
typedef CAtlStringA CStringA;
|
|
|
|
|
2015-09-30 19:55:52 +00:00
|
|
|
|
2016-09-24 18:01:49 +00:00
|
|
|
#ifdef UNICODE
|
|
|
|
typedef CAtlStringW CAtlString;
|
|
|
|
typedef CStringW CString;
|
|
|
|
#else
|
|
|
|
typedef CAtlStringA CAtlString;
|
|
|
|
typedef CStringA CString;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2015-09-30 19:55:52 +00:00
|
|
|
}
|
2015-05-06 21:31:40 +00:00
|
|
|
|
|
|
|
#endif
|