commit 2025-09-01 11:37 add Replace() in ZCppMain/ZCStringStd.H

This commit is contained in:
2025-09-02 11:37:49 +09:00
parent 50d2fac736
commit a2e2f8ce7b
4 changed files with 328 additions and 111 deletions

View File

@ -17,7 +17,9 @@ namespace ZNsMain
typedef ZNsChars::ZNsType::ZtCTypeChars<char> ZCTypeChars;
typedef ZNsChars::ZtCMainChars<ZCTypeChars> ZCMainChars;
public:
typedef char TypeData ;
typedef char TypeChar ;
typedef char* TypePChar ;
typedef const char* TypeCPChar;
typedef std::string TypeBase ;
typedef std::string TypeStrStd;
typedef ZTypLength TypeLength;
@ -29,28 +31,46 @@ namespace ZNsMain
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)
ZCStringStd& operator=(const ZCStringStd& rhs)
{
if(this==&rhs){ return *this; }
this->TypeStrStd::operator=(rhs); return *this;
}/*
ZCStringStd& operator==(const ZCStringStd& rhs)*/
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
(const char* APC_SearchData, TypeLength AL_SearchLen, TPosList& ARR_CPosList)
(
const char* APC_SearchData, TypeLength AL_SearchLen,
TPosList& ARR_CPosList , TypeLength AL_Offset=0
)
/*########################################################*/
{
// TPosList : ZNsMain::ZtCList<TypeLength> etc
if(this->size()<1) return;
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_Offset = 0 ;
TypeLength VL_OffsetNow = AL_Offset ;
while /*::::::::::::::::::::::::::::::::::::::::::::::*/
( ( VL_FindPos = ZCMainChars::FindPos
(
( VL_FindPos = ZCMainChars::FindPos
( VPC_OriginStart, APC_SearchData,
VL_OriginLen , AL_SearchLen, VL_Offset
VL_OriginLen , AL_SearchLen , VL_OffsetNow
)
)
>= 0
@ -59,18 +79,22 @@ namespace ZNsMain
{
ARR_CPosList.push_back(VL_FindPos);
VL_Offset = VL_FindPos + AL_SearchLen;
VL_OffsetNow = VL_FindPos + AL_SearchLen;
}
/*::::::::::::::::::::::::::::::::::::::::::::::::::::*/
}/*
template<typename TPosList> void FindPosToList
(const char* APC_SearchData, TypeLength AL_SearchLen, TFindList& ARR_CPosList)
*/
(
const char* APC_SearchData, TypeLength AL_SearchLen,
TPosList& ARR_CPosList , TypeLength AL_Offset=0
)
##########################################################*/
template<typename TPosList> ZCStringStd& ReplaceToOutByPosList
(
TPosList& AR_CPosList ,
const char* APC_Replace ,
TypeCPChar APC_Replace ,
TypeLength AL_Replace ,
TypeLength AL_Searched ,
ZCStringStd& ARR_SaveOut
@ -89,20 +113,20 @@ namespace ZNsMain
TypeLength VL_NeedSize = VL_ThisSize +
(AL_Replace-AL_Searched) * VL_PosListSize ;
char* VPC_ThisStart = this->data() ;
TypePChar VPC_ThisStart = this->data() ;
IterEasyID VH_IterEasyID = AR_CPosList.ItHID();
TypeLength VL_SearchedPos= 0 ;
TypeLength VL_SearchedPre= 0 ; // VL_SearchedPos 의 이전 값
if(AL_Replace<=AL_Searched) // 메모리 증가 불필요
{
char* VPC_MoveStart = 0 ;
char* VPC_DestStart = 0 ;
TypeLength VL_MoveStart = 0 ;
TypeLength VL_DestStart = 0 ;
TypePChar VPC_MoveStart = 0 ;
TypePChar VPC_DestStart = 0 ;
TypeLength VL_MoveStart = 0 ;
TypeLength VL_DestStart = 0 ;
TypeLength VL_MemMoveSize= 0 ;
char* VPC_RepalcePos= 0 ;
TypeLength VL_MemMoveSize= 0 ;
TypePChar VPC_RepalcePos= 0 ;
__for1(TypeLength, i, VL_PosListSize)
{
@ -155,14 +179,14 @@ namespace ZNsMain
ARR_SaveOut.resize(VL_NeedSize);
char* VPC_OutStart = ARR_SaveOut.data() ;
char* VPC_CopyStart = 0 ;
char* VPC_DestStart = 0 ;
TypePChar VPC_OutStart = ARR_SaveOut.data() ;
TypePChar VPC_CopyStart = 0 ;
TypePChar VPC_DestStart = 0 ;
TypeLength VL_CopyStart = 0 ;
TypeLength VL_DestStart = 0 ;
TypeLength VL_MemCopySize= 0 ;
char* VPC_RepalcePos= 0 ;
TypePChar VPC_RepalcePos= 0 ;
__for1(TypeLength, i, VL_PosListSize)
{
@ -218,20 +242,64 @@ namespace ZNsMain
template<typename TPosList> ZCStringStd& ReplaceToOutByPosList
(
TPosList& AR_CPosList ,
const char* APC_Replace ,
TypeCPChar APC_Replace ,
TypeLength AL_Replace ,
TypeLength AL_Searched ,
ZCStringStd& ARR_SaveOut
)
############################################################*/
ZCStringStd& Replace /*####################################################*/
(
TypeCPChar APC_Search , TypeLength AL_Search ,
TypeCPChar APC_Replace, 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
(
APC_Search, AL_Search, RR(VO_CPosCList), AL_Offset
);
/*////////////////////////////////////////////*/
ZCStringStd VO_CStringOut; return *this = ReplaceToOutByPosList
(
VO_CPosCList, APC_Replace, AL_Replace, AL_Search, RR(VO_CStringOut)
);
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
}/*
ZCStringStd& Replace /*######################################################
(
TypeCPChar APC_Search , TypeLength AL_Search ,
TypeCPChar APC_Replace, TypeLength AL_Replace, TypeLength AL_Offset=0
)
###########################################################################*/
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__