422 lines
15 KiB
C++
422 lines
15 KiB
C++
|
|
|
|
#ifndef __ZCPPMAIIN_ZCSTRINGSTD_H__
|
|
#define __ZCPPMAIIN_ZCSTRINGSTD_H__
|
|
|
|
|
|
#include<string>
|
|
#include "ZCppMain/ZtCMainChars.H"
|
|
|
|
|
|
namespace ZNsMain
|
|
{
|
|
|
|
class ZCStringStd : public std::string
|
|
{
|
|
public:
|
|
typedef ZNsChars::ZNsType::ZtCTypeChars<char> ZCTypeChars;
|
|
typedef ZNsChars::ZtCMainChars<ZCTypeChars> ZCMainChars;
|
|
public:
|
|
typedef char TypeChar ;
|
|
typedef char* TypePChar ;
|
|
typedef const char* TypeCPChar;
|
|
typedef std::string TypeBase ;
|
|
typedef std::string TypeStrStd;
|
|
typedef ZTypLength TypeLength;
|
|
typedef ZTypLength TypeSize ;
|
|
public:
|
|
|
|
ZCStringStd(): TypeStrStd(){}
|
|
ZCStringStd(const ZCStringStd& rhs): TypeStrStd(rhs){}
|
|
ZCStringStd(const char* APC_Origin, TypeLength AL_Length): TypeStrStd(APC_Origin, AL_Length){}
|
|
ZCStringStd(const char* APC_Origin): TypeStrStd(APC_Origin){}
|
|
|
|
ZCStringStd& operator=(const ZCStringStd& rhs)
|
|
{
|
|
if(this==&rhs){ return *this; }
|
|
|
|
this->TypeStrStd::operator=(rhs); return *this;
|
|
}/*
|
|
ZCStringStd& operator=(const ZCStringStd& rhs)*/
|
|
|
|
ZCStringStd& operator=(const TypeBase& rhs)
|
|
{
|
|
if(this->data()==rhs.data()){ return *this; }
|
|
|
|
this->TypeStrStd::operator=(rhs); return *this;
|
|
}/*
|
|
ZCStringStd& operator=(const TypeBase& rhs)*/
|
|
|
|
|
|
template<typename TPosList> void FindPosToList /////////////
|
|
(
|
|
TPosList& ARR_CPosList, TypeCPChar APC_SearchData,
|
|
TypeLength AL_SearchLen, TypeLength AL_Offset=0
|
|
)
|
|
/*########################################################*/
|
|
{
|
|
// TPosList : ZNsMain::ZtCList<TypeLength> etc
|
|
|
|
if(0 > AL_Offset) AL_Offset=0 ;
|
|
if(this->size() <= AL_Offset) return ;
|
|
if(this->size() < 1 ) return ;
|
|
|
|
const char* 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
|
|
)
|
|
##########################################################*/
|
|
|
|
|
|
template<typename TPosList> ZCStringStd& ReplaceByPosList
|
|
(
|
|
TPosList& AR_CPosList ,
|
|
TypeCPChar APC_Replace ,
|
|
TypeLength AL_Replace ,
|
|
TypeLength AL_Searched
|
|
)
|
|
/*##########################################################*/
|
|
{
|
|
// TPosList : ZNsMain::ZtCList<TypeLength> etc
|
|
// AL_Replace : APC_Replace 의 길이
|
|
// AL_Searched : 이전에 찾은 길이
|
|
// ARR_SaveOut : AL_Replace>AL_Searched 인 경우에 여기에 저장한다.
|
|
|
|
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<char*>(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
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
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
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
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
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
if(VL_MemMoveSize>0)*/
|
|
|
|
VPC_DestStart = VPC_ThisStart + VL_SearchedPos + VL_DiffLength*(VL_PosListSize - i) ;
|
|
|
|
::memcpy /*::::::::::::::::::::::::::::::::::::::::*/
|
|
(
|
|
VPC_DestStart, APC_Replace, AL_Replace
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
|
|
VL_SearchedPre = VL_SearchedPos; --VL_NowEleNo;
|
|
|
|
AR_CPosList.ItPrev(VH_IterEasyID);
|
|
}/*
|
|
__for1(TypeLength, i, VL_PosListSize)*/
|
|
|
|
|
|
return *this;
|
|
}/*
|
|
template<typename TPosList> ZCStringStd& ReplaceByPosList
|
|
(
|
|
TPosList& AR_CPosList ,
|
|
TypeCPChar APC_Replace ,
|
|
TypeLength AL_Replace ,
|
|
TypeLength AL_Searched
|
|
)
|
|
############################################################*/
|
|
|
|
|
|
ZCStringStd& 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;
|
|
|
|
ZtCList<TypeLength> VO_CPosCList; FindPosToList
|
|
(
|
|
RR(VO_CPosCList), APC_Search, AL_Search, AL_Offset
|
|
);
|
|
/*////////////////////////////////////////////*/
|
|
|
|
return ReplaceByPosList /*::::::::::::::::::::::::::::*/
|
|
(
|
|
VO_CPosCList, APC_Replace, AL_Replace, AL_Search
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
ZCStringStd& Replace /*######################################################
|
|
(
|
|
TypeCPChar APC_Search, TypeCPChar APC_Replace,
|
|
TypeLength AL_Search , TypeLength AL_Replace , TypeLength AL_Offset=0
|
|
)
|
|
###########################################################################*/
|
|
|
|
|
|
ZCStringStd& 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);
|
|
}/*
|
|
ZCStringStd& Replace /*######################################################
|
|
(
|
|
TypeCPChar APC_Search, TypeCPChar APC_Replace, TypeLength AL_Offset=0
|
|
)
|
|
###########################################################################*/
|
|
|
|
|
|
ZCStringStd& operator()(ZCStringStd& rhs)
|
|
{
|
|
if(this==&rhs) return *this; this->append(rhs); return *this;
|
|
}/*
|
|
ZCStringStd& operator()(ZCStringStd& rhs)*/
|
|
|
|
ZCStringStd& operator()(TypeCPChar APC_Data, TypeLength AI_Length)
|
|
{
|
|
if(this->data()==APC_Data) return *this;
|
|
|
|
this->append(APC_Data, AI_Length); return *this;
|
|
}/*
|
|
ZCStringStd& operator()(TypeCPChar APC_Data, TypeLength AI_Length)*/
|
|
|
|
ZCStringStd& operator()(TypeCPChar APC_Data)
|
|
{
|
|
if(this->data()==APC_Data) return *this;
|
|
|
|
this->append(APC_Data); return *this;
|
|
}/*
|
|
ZCStringStd& operator()(TypeCPChar APC_Data)*/
|
|
|
|
ZCStringStd& operator()(TypeLength AI_Repeat, char AC_Data)
|
|
{
|
|
this->append(AI_Repeat, AC_Data); return *this;
|
|
}/*
|
|
ZCStringStd& operator()(char AC_Data, TypeLength AI_Repeat)*/
|
|
|
|
ZCStringStd& operator()(char AC_Data, TypeLength AI_Repeat=1)
|
|
{
|
|
this->append(AI_Repeat, AC_Data); return *this;
|
|
}/*
|
|
ZCStringStd& operator()(char AC_Data, TypeLength AI_Repeat=1)*/
|
|
|
|
|
|
ZCStringStd& 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);
|
|
}/*
|
|
ZCStringStd& operator()(int AI_IntParam)*/
|
|
|
|
ZCStringStd& 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);
|
|
}/*
|
|
ZCStringStd& operator()(ZTypUInt AUI_UIntParam)*/
|
|
|
|
ZCStringStd& 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);
|
|
}/*
|
|
ZCStringStd& operator()(long AL_LongParam)*/
|
|
|
|
ZCStringStd& 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);
|
|
}/*
|
|
ZCStringStd& operator()(ZTypULong AUL_ULongParam)*/
|
|
|
|
ZCStringStd& 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);
|
|
}/*
|
|
ZCStringStd& operator()(ZTypLLong ALL_LLongParam)*/
|
|
|
|
ZCStringStd& 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);
|
|
}/*
|
|
ZCStringStd& operator()(ZTypULLong AULL_LLongParam)*/
|
|
|
|
ZCStringStd& 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);
|
|
}/*
|
|
ZCStringStd& operator()(double AD_DoubleParam)*/
|
|
|
|
public:
|
|
};/*
|
|
class ZCStringStd : public std::string*/
|
|
|
|
|
|
|
|
std::ostream& operator <<
|
|
(std::ostream& AR_COStream, const ZCStringStd& AR_CStringBase)
|
|
{
|
|
AR_COStream<<static_cast<const std::string&>(AR_CStringBase); return AR_COStream;
|
|
}/*
|
|
std::ostream& operator <<
|
|
(std::ostream& AR_COStream, const ZCStringStd& AR_CStringBase)*/
|
|
|
|
|
|
}/*
|
|
namespace ZNsMain*/
|
|
|
|
|
|
|
|
#endif //__ZCPPMAIIN_ZCSTRINGSTD_H__
|