457 lines
16 KiB
C++
457 lines
16 KiB
C++
|
|
|
|
#ifndef __ZCPPMAIIN_ZTCSTRINGSTD_H__
|
|
#define __ZCPPMAIIN_ZTCSTRINGSTD_H__
|
|
|
|
|
|
#include<string>
|
|
#include "ZCppMain/ZtCMainChars.H"
|
|
|
|
|
|
namespace ZNsMain
|
|
{
|
|
|
|
template
|
|
< typename TTypString = std::string >
|
|
class ZtCStringStd : public TTypString
|
|
{
|
|
public:
|
|
typedef typename TTypString::traits_type::char_type TypeChar ;
|
|
typedef typename TTypString::traits_type::int_type TypeCharInt ;
|
|
public:
|
|
typedef ZNsChars::ZNsType::
|
|
ZtCTypeChars <TypeChar > ZCTypeChars ;
|
|
typedef ZNsChars::
|
|
ZtCMainChars<ZCTypeChars> ZCMainChars ;
|
|
public:
|
|
typedef TypeChar* TypePChar ;
|
|
typedef const TypeChar* TypeCPChar ;
|
|
typedef TTypString TypeBase ;
|
|
typedef TTypString TypeStrStd ;
|
|
typedef ZTypLength TypeLength ;
|
|
typedef ZTypLength TypeSize ;
|
|
public:
|
|
typedef ZtCChars<TypePChar> ZCChars ;
|
|
typedef ZtCChars<TypePChar> ZCCharView ;
|
|
public:
|
|
|
|
ZtCStringStd(): TypeStrStd(){}
|
|
ZtCStringStd(const ZtCStringStd& rhs): TypeStrStd(rhs){}
|
|
ZtCStringStd(TypeCPChar APC_Origin, TypeLength AL_Length):
|
|
TypeStrStd(APC_Origin, AL_Length){}
|
|
|
|
ZtCStringStd(const ZCCharView& AR_View):
|
|
TypeStrStd(AR_View.data(), AR_View.size()){}
|
|
|
|
explicit ZtCStringStd(TypeCPChar APC_Origin):
|
|
TypeStrStd(APC_Origin){}
|
|
|
|
ZtCStringStd& operator=(const ZtCStringStd& rhs)
|
|
{
|
|
if(this==&rhs){ return *this; }
|
|
|
|
this->TypeStrStd::operator=(rhs); return *this;
|
|
}/*
|
|
ZtCStringStd& operator=(const ZtCStringStd& rhs)*/
|
|
|
|
ZtCStringStd& operator=(const TypeBase& rhs)
|
|
{
|
|
if(this->data()==rhs.data()){ return *this; }
|
|
|
|
this->TypeStrStd::operator=(rhs); return *this;
|
|
}/*
|
|
ZtCStringStd& operator=(const TypeBase& rhs)*/
|
|
|
|
|
|
template<typename TPosList> void FindPosToList /////////////
|
|
(
|
|
TPosList& ARR_CPosList, TypeCPChar APC_SearchData,
|
|
TypeLength AL_SearchLen, TypeLength AL_Offset=0
|
|
)
|
|
/*########################################################*/
|
|
{
|
|
// TPosList : ZNsMain::ZtCBaseList<TypeLength> etc
|
|
|
|
if(0 > AL_Offset) AL_Offset=0 ;
|
|
if(this->size() <= AL_Offset) return ;
|
|
if(this->size() < 1 ) return ;
|
|
|
|
const TypeChar* VPC_OriginStart = this->data();
|
|
TypeLength VL_OriginLen = this->size();
|
|
TypeLength VL_FindPos = -1 ;
|
|
TypeLength VL_OffsetNow = AL_Offset ;
|
|
|
|
while /*::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
(
|
|
( VL_FindPos = ZCMainChars::FindPos
|
|
( VPC_OriginStart, APC_SearchData,
|
|
VL_OriginLen , AL_SearchLen , VL_OffsetNow
|
|
)
|
|
) >= 0
|
|
)
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
{
|
|
ARR_CPosList.push_back(VL_FindPos);
|
|
|
|
VL_OffsetNow = VL_FindPos + AL_SearchLen;
|
|
}
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
template<typename TPosList> void FindPosToList /////////////
|
|
(
|
|
TPosList& ARR_CPosList, TypeCPChar APC_SearchData,
|
|
TypeLength AL_SearchLen, TypeLength AL_Offset=0
|
|
)
|
|
##########################################################*/
|
|
|
|
|
|
public :
|
|
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
private:
|
|
|
|
template<typename TPosList> ZtCStringStd& ReplaceByPosList ///////////////////
|
|
(
|
|
TPosList& AR_CPosList ,
|
|
TypeCPChar APC_Replace ,
|
|
TypeLength AL_Replace ,
|
|
TypeLength AL_Searched
|
|
)
|
|
/*#########################################################################*/
|
|
{
|
|
/*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
|
|
■ TPosList : ZNsMain::ZtCBaseList<TypeLength> etc
|
|
AL_Replace : APC_Replace 의 길이
|
|
AL_Searched : 이전에 찾은 길이
|
|
|
|
Replace() 에서 FindPosToList() 다음에 호출한다.
|
|
|
|
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
|
|
if(AR_CPosList.size()<1) return *this;
|
|
|
|
TypeLength VL_PosListSize= AR_CPosList.size() ;
|
|
TypeLength VL_ThisSize = this->size() ;
|
|
TypeLength VL_NeedSize = VL_ThisSize +
|
|
(AL_Replace-AL_Searched) * VL_PosListSize ;
|
|
|
|
TypePChar VPC_ThisStart = const_cast<TypeChar*>(this->data()) ;
|
|
IterEasyID VH_IterEasyID = AR_CPosList.ItHID();
|
|
TypeLength VL_SearchedPos= 0 ;
|
|
TypeLength VL_SearchedPre= 0 ; // VL_SearchedPos 의 이전 값
|
|
|
|
TypePChar VPC_MoveStart = 0 ;
|
|
TypePChar VPC_DestStart = 0 ;
|
|
TypeLength VL_MoveStart = 0 ;
|
|
TypeLength VL_DestStart = 0 ;
|
|
TypeLength VL_MemMoveSize= 0 ;
|
|
|
|
if(AL_Replace<=AL_Searched) // 메모리 증가 불필요
|
|
{
|
|
TypePChar VPC_MoveStart = 0 ;
|
|
TypePChar VPC_DestStart = 0 ;
|
|
TypeLength VL_MoveStart = 0 ;
|
|
TypeLength VL_DestStart = 0 ;
|
|
|
|
TypeLength VL_MemMoveSize= 0 ;
|
|
TypePChar VPC_RepalcePos= 0 ;
|
|
|
|
__for1(TypeLength, i, VL_PosListSize)
|
|
{
|
|
VL_SearchedPos = AR_CPosList.ItD(VH_IterEasyID) ;
|
|
VPC_RepalcePos = VPC_ThisStart + VL_SearchedPos -
|
|
( AL_Searched-AL_Replace ) * (i-1) ;
|
|
|
|
if(VL_MoveStart>VL_DestStart)
|
|
{
|
|
VL_MemMoveSize =
|
|
VL_SearchedPos - VL_SearchedPre - AL_Searched ;
|
|
VPC_MoveStart = VPC_ThisStart + VL_MoveStart ;
|
|
VPC_DestStart = VPC_ThisStart + VL_DestStart ;
|
|
|
|
::memmove /*::::::::::::::::::::::::::::::::::::::*/
|
|
(
|
|
VPC_DestStart, VPC_MoveStart, VL_MemMoveSize*sizeof(TypeChar)
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
if(VL_MoveStart>VL_DestStart)*/
|
|
|
|
VL_SearchedPre = VL_SearchedPos ;
|
|
VL_MoveStart = VL_SearchedPos+ AL_Searched ;
|
|
VL_DestStart = VL_SearchedPos+ AL_Searched -
|
|
( AL_Searched-AL_Replace ) * i ;
|
|
|
|
::memcpy(VPC_RepalcePos, APC_Replace, AL_Replace);
|
|
|
|
AR_CPosList.ItNext(VH_IterEasyID);
|
|
}/*
|
|
__for1(TypeLength, i, VL_PosListSize)*/
|
|
|
|
if(VL_ThisSize > VL_MoveStart)
|
|
{
|
|
::memmove /*::::::::::::::::::::::::::::::*/
|
|
(
|
|
VPC_ThisStart + VL_DestStart,
|
|
VPC_ThisStart + VL_MoveStart,
|
|
(VL_ThisSize - VL_MoveStart)*sizeof(TypeChar)
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
if(VL_ThisSize > VL_MoveStart)*/
|
|
|
|
this->resize(VL_NeedSize); return *this;
|
|
}/*
|
|
if(AL_Replace<=AL_Searched) // 메모리 증가 불필요*/
|
|
|
|
|
|
/*======*/ VL_SearchedPre = this->size() ;
|
|
/*======*/ VH_IterEasyID = AR_CPosList.ItTID() ;
|
|
TypeLength VL_NowEleNo = VL_PosListSize ;
|
|
TypeLength VL_DiffLength = AL_Replace-AL_Searched;
|
|
|
|
this->resize(VL_NeedSize); VPC_ThisStart = this->data();
|
|
|
|
__for1(TypeLength, i, VL_PosListSize)
|
|
{
|
|
VL_SearchedPos = AR_CPosList.ItD(VH_IterEasyID) ;
|
|
VL_MemMoveSize = VL_SearchedPre - (VL_SearchedPos+AL_Searched);
|
|
|
|
if(VL_MemMoveSize>0)
|
|
{
|
|
VPC_MoveStart = VPC_ThisStart + VL_SearchedPos + AL_Searched ;
|
|
VPC_DestStart = VPC_ThisStart + VL_SearchedPos + AL_Searched + VL_DiffLength*VL_NowEleNo ;
|
|
|
|
::memmove /*::::::::::::::::::::::::::::::::::::::::*/
|
|
(
|
|
VPC_DestStart, VPC_MoveStart, VL_MemMoveSize*sizeof(TypeChar)
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
if(VL_MemMoveSize>0)*/
|
|
|
|
VPC_DestStart = VPC_ThisStart + VL_SearchedPos + VL_DiffLength*(VL_PosListSize - i) ;
|
|
|
|
::memcpy /*::::::::::::::::::::::::::::::::::::::::*/
|
|
(
|
|
VPC_DestStart, APC_Replace, AL_Replace*sizeof(TypeChar)
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
|
|
VL_SearchedPre = VL_SearchedPos; --VL_NowEleNo;
|
|
|
|
AR_CPosList.ItPrev(VH_IterEasyID);
|
|
}/*
|
|
__for1(TypeLength, i, VL_PosListSize)*/
|
|
|
|
|
|
return *this;
|
|
}/*
|
|
template<typename TPosList> ZtCStringStd& ReplaceByPosList ///////////////////
|
|
(
|
|
TPosList& AR_CPosList ,
|
|
TypeCPChar APC_Replace ,
|
|
TypeLength AL_Replace ,
|
|
TypeLength AL_Searched
|
|
)
|
|
###########################################################################*/
|
|
|
|
|
|
private:
|
|
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
|
|
public :
|
|
|
|
|
|
ZtCStringStd& Replace /*////////////////////////////////////////////////////*/
|
|
(
|
|
TypeCPChar APC_Search, TypeCPChar APC_Replace,
|
|
TypeLength AL_Search , TypeLength AL_Replace , TypeLength AL_Offset=0
|
|
)
|
|
/*#########################################################################*/
|
|
{
|
|
if(0 > AL_Offset) AL_Offset=0 ;
|
|
if(this->size() <= AL_Offset) return *this;
|
|
if(this->size() < 1 ) return *this;
|
|
|
|
ZtCBaseList<TypeLength> VO_CPosCList; FindPosToList
|
|
(
|
|
RR(VO_CPosCList), APC_Search, AL_Search, AL_Offset
|
|
);
|
|
/*////////////////////////////////////////////////*/
|
|
|
|
return ReplaceByPosList /*::::::::::::::::::::::::::::*/
|
|
(
|
|
VO_CPosCList, APC_Replace, AL_Replace, AL_Search
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
ZtCStringStd& Replace ////////////////////////////////////////////////////////
|
|
(
|
|
TypeCPChar APC_Search, TypeCPChar APC_Replace,
|
|
TypeLength AL_Search , TypeLength AL_Replace , TypeLength AL_Offset=0
|
|
)
|
|
###########################################################################*/
|
|
|
|
|
|
ZtCStringStd& Replace /*////////////////////////////////////////////////////*/
|
|
(
|
|
TypeCPChar APC_Search, TypeCPChar APC_Replace, TypeLength AL_Offset=0
|
|
)
|
|
/*#########################################################################*/
|
|
{
|
|
return Replace(APC_Search, APC_Replace, ZftLength(APC_Search), ZftLength(APC_Replace), AL_Offset);
|
|
}/*
|
|
ZtCStringStd& Replace ////////////////////////////////////////////////////////
|
|
(
|
|
TypeCPChar APC_Search, TypeCPChar APC_Replace, TypeLength AL_Offset=0
|
|
)
|
|
###########################################################################*/
|
|
|
|
|
|
ZtCStringStd& operator()(ZtCStringStd& rhs)
|
|
{
|
|
if(this==&rhs) return *this; this->append(rhs); return *this;
|
|
}/*
|
|
ZtCStringStd& operator()(ZtCStringStd& rhs)*/
|
|
|
|
ZtCStringStd& operator()(TypeCPChar APC_Data, TypeLength AI_Length)
|
|
{
|
|
if(this->data()==APC_Data) return *this;
|
|
|
|
this->append(APC_Data, AI_Length); return *this;
|
|
}/*
|
|
ZtCStringStd& operator()(TypeCPChar APC_Data, TypeLength AI_Length)*/
|
|
|
|
ZtCStringStd& operator()(TypeCPChar APC_Data)
|
|
{
|
|
if(this->data()==APC_Data) return *this;
|
|
|
|
this->append(APC_Data); return *this;
|
|
}/*
|
|
ZtCStringStd& operator()(TypeCPChar APC_Data)*/
|
|
|
|
ZtCStringStd& operator()(TypeLength AI_Repeat, TypeChar AC_Data)
|
|
{
|
|
this->append(AI_Repeat, AC_Data); return *this;
|
|
}/*
|
|
ZtCStringStd& operator()(TypeChar AC_Data, TypeLength AI_Repeat)*/
|
|
|
|
ZtCStringStd& operator()(TypeChar AC_Data, TypeLength AI_Repeat=1)
|
|
{
|
|
this->append(AI_Repeat, AC_Data); return *this;
|
|
}/*
|
|
ZtCStringStd& operator()(TypeChar AC_Data, TypeLength AI_Repeat=1)*/
|
|
|
|
|
|
ZtCStringStd& operator()(int AI_IntParam)
|
|
{
|
|
const int CI_BuffSize=21; char VCA_BuffParam[CI_BuffSize];
|
|
|
|
int VI_ResultSize = ::sprintf(VCA_BuffParam, "%d", AI_IntParam);
|
|
|
|
return (*this)(VCA_BuffParam, VI_ResultSize);
|
|
}/*
|
|
ZtCStringStd& operator()(int AI_IntParam)*/
|
|
|
|
ZtCStringStd& operator()(ZTypUInt AUI_UIntParam)
|
|
{
|
|
const int CI_BuffSize=21; char VCA_BuffParam[CI_BuffSize];
|
|
|
|
int VI_ResultSize = ::sprintf(VCA_BuffParam, "%u", AUI_UIntParam);
|
|
|
|
return (*this)(VCA_BuffParam, VI_ResultSize);
|
|
}/*
|
|
ZtCStringStd& operator()(ZTypUInt AUI_UIntParam)*/
|
|
|
|
ZtCStringStd& operator()(long AL_LongParam)
|
|
{
|
|
const int CI_BuffSize=31; char VCA_BuffParam[CI_BuffSize];
|
|
|
|
int VI_ResultSize = ::sprintf(VCA_BuffParam, "%ld", AL_LongParam);
|
|
|
|
return (*this)(VCA_BuffParam, VI_ResultSize);
|
|
}/*
|
|
ZtCStringStd& operator()(long AL_LongParam)*/
|
|
|
|
ZtCStringStd& operator()(ZTypULong AUL_ULongParam)
|
|
{
|
|
const int CI_BuffSize=31; char VCA_BuffParam[CI_BuffSize];
|
|
|
|
int VI_ResultSize = ::sprintf(VCA_BuffParam, "%lu", AUL_ULongParam);
|
|
|
|
return (*this)(VCA_BuffParam, VI_ResultSize);
|
|
}/*
|
|
ZtCStringStd& operator()(ZTypULong AUL_ULongParam)*/
|
|
|
|
ZtCStringStd& operator()(ZTypLLong ALL_LLongParam)
|
|
{
|
|
const int CI_BuffSize=41; char VCA_BuffParam[CI_BuffSize];
|
|
|
|
#ifdef _WIN
|
|
int VI_ResultSize = ::sprintf(VCA_BuffParam, "%I64d", ALL_LLongParam);
|
|
#else
|
|
int VI_ResultSize = ::sprintf(VCA_BuffParam, "%lld" , ALL_LLongParam);
|
|
#endif
|
|
|
|
return (*this)(VCA_BuffParam, VI_ResultSize);
|
|
}/*
|
|
ZtCStringStd& operator()(ZTypLLong ALL_LLongParam)*/
|
|
|
|
ZtCStringStd& operator()(ZTypULLong AULL_LLongParam)
|
|
{
|
|
const int CI_BuffSize=41; char VCA_BuffParam[CI_BuffSize];
|
|
|
|
#ifdef _WIN
|
|
int VI_ResultSize = ::sprintf(VCA_BuffParam, "%I64u", AULL_LLongParam);
|
|
#else
|
|
int VI_ResultSize = ::sprintf(VCA_BuffParam, "%llu" , AULL_LLongParam);
|
|
#endif
|
|
|
|
return (*this)(VCA_BuffParam, VI_ResultSize);
|
|
}/*
|
|
ZtCStringStd& operator()(ZTypULLong AULL_LLongParam)*/
|
|
|
|
ZtCStringStd& operator()(double AD_DoubleParam)
|
|
{
|
|
const int CI_BuffSize=51 ;
|
|
char VCA_BuffParam[CI_BuffSize];
|
|
|
|
int VI_ResultSize = ::sprintf
|
|
(
|
|
VCA_BuffParam, "%f", AD_DoubleParam
|
|
);
|
|
/////////////////////////////
|
|
|
|
return (*this)(VCA_BuffParam);
|
|
}/*
|
|
ZtCStringStd& operator()(double AD_DoubleParam)*/
|
|
|
|
public:
|
|
};/*
|
|
template
|
|
< typename TTypString = std::string >
|
|
class ZtCStringStd : public TTypString */
|
|
|
|
|
|
template<typename TTypString> std::ostream& operator<<
|
|
(std::ostream& AR_COStream, const ZtCStringStd<TTypString>& AR_DataCStr)
|
|
{
|
|
typedef typename ZtCStringStd
|
|
<TTypString>::TypeBase TypeBaseCStr ;
|
|
|
|
AR_COStream<< static_cast
|
|
<const TypeBaseCStr&>(AR_DataCStr);
|
|
|
|
return AR_COStream; ///////////////////////////
|
|
}/*
|
|
template<typename TTypString> std::ostream& operator<<
|
|
(std::ostream& AR_COStream, const ZtCStringStd& AR_DataCStr)*/
|
|
|
|
|
|
}/*
|
|
namespace ZNsMain*/
|
|
|
|
|
|
|
|
#endif //__ZCPPMAIIN_ZTCSTRINGSTD_H__
|