320 lines
12 KiB
C++
320 lines
12 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& ReplaceToOutByPosList
|
|
(
|
|
TPosList& AR_CPosList ,
|
|
TypeCPChar APC_Replace ,
|
|
TypeLength AL_Replace ,
|
|
TypeLength AL_Searched ,
|
|
ZCStringStd& ARR_SaveOut
|
|
)
|
|
/*##########################################################*/
|
|
{
|
|
// 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 = this->data() ;
|
|
IterEasyID VH_IterEasyID = AR_CPosList.ItHID();
|
|
TypeLength VL_SearchedPos= 0 ;
|
|
TypeLength VL_SearchedPre= 0 ; // VL_SearchedPos 의 이전 값
|
|
|
|
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_DestStart<VL_MoveStart && VL_DestStart<VL_ThisSize)
|
|
{
|
|
::memmove /*::::::::::::::::::::::::::::::*/
|
|
(
|
|
VPC_ThisStart + VL_DestStart,
|
|
VPC_ThisStart + VL_MoveStart,
|
|
VL_ThisSize - VL_MoveStart
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
if(VL_DestStart<VL_MoveStart && VL_DestStart<VL_ThisSize)*/
|
|
|
|
this->resize(VL_NeedSize); return *this;
|
|
}/*
|
|
if(AL_Replace<=AL_Searched) // 메모리 증가 불필요*/
|
|
|
|
|
|
ARR_SaveOut.resize(VL_NeedSize);
|
|
|
|
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 ;
|
|
TypePChar VPC_RepalcePos= 0 ;
|
|
|
|
__for1(TypeLength, i, VL_PosListSize)
|
|
{
|
|
VL_SearchedPos = AR_CPosList.ItD(VH_IterEasyID) ;
|
|
VPC_CopyStart = VPC_ThisStart + VL_SearchedPre ;
|
|
VL_DestStart = VL_SearchedPre +
|
|
( AL_Replace-AL_Searched ) * (i-1) ;
|
|
VPC_DestStart = VPC_OutStart + VL_DestStart ;
|
|
|
|
if(VL_SearchedPos>VL_SearchedPre)
|
|
{
|
|
VL_MemCopySize =
|
|
VL_SearchedPos - VL_SearchedPre ;
|
|
|
|
::memcpy /*:::::::::::::::::::::::::::::::::::::::*/
|
|
(
|
|
VPC_DestStart, VPC_CopyStart, VL_MemCopySize
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
if(VL_SearchedPos>VL_SearchedPre)*/
|
|
|
|
VL_SearchedPre = VL_SearchedPos + AL_Searched ;
|
|
VL_DestStart = VL_SearchedPos +
|
|
( AL_Replace-AL_Searched ) * (i-1) ;
|
|
VPC_RepalcePos = VPC_OutStart + VL_DestStart ;
|
|
|
|
::memcpy(VPC_RepalcePos, APC_Replace, AL_Replace) ;
|
|
|
|
AR_CPosList.ItNext(VH_IterEasyID);
|
|
}/*
|
|
__for1(TypeLength, i, VL_PosListSize)*/
|
|
|
|
|
|
if(VL_SearchedPre<VL_ThisSize)
|
|
{
|
|
VL_DestStart = VL_DestStart + AL_Replace ;
|
|
VPC_DestStart = VPC_OutStart + VL_DestStart ;
|
|
VPC_CopyStart = VPC_ThisStart+ VL_SearchedPre;
|
|
VL_MemCopySize = VL_ThisSize - VL_SearchedPre;
|
|
|
|
::memcpy /*:::::::::::::::::::::::::::::::::::::::*/
|
|
(
|
|
VPC_DestStart, VPC_CopyStart, VL_MemCopySize
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
}/*
|
|
if(VL_SearchedPre<VL_ThisSize)*/
|
|
|
|
|
|
return ARR_SaveOut;
|
|
}/*
|
|
template<typename TPosList> ZCStringStd& ReplaceToOutByPosList
|
|
(
|
|
TPosList& AR_CPosList ,
|
|
TypeCPChar APC_Replace ,
|
|
TypeLength AL_Replace ,
|
|
TypeLength AL_Searched ,
|
|
ZCStringStd& ARR_SaveOut
|
|
)
|
|
############################################################*/
|
|
|
|
|
|
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
|
|
);
|
|
/*////////////////////////////////////////////*/
|
|
|
|
ZCStringStd VO_CStringOut; return *this = ReplaceToOutByPosList
|
|
(
|
|
VO_CPosCList, APC_Replace, AL_Replace, AL_Search, RR(VO_CStringOut)
|
|
);
|
|
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
|
|
|
|
}/*
|
|
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
|
|
)
|
|
###########################################################################*/
|
|
|
|
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__
|