From ce0d3641028478cca26f7f32ef1ac93a0e66b57a Mon Sep 17 00:00:00 2001 From: sauron Date: Thu, 9 Oct 2025 10:41:59 +0900 Subject: [PATCH] commit 2025-10-09 10:41 bug fix about wchar_t in ZCppMain/ZtCStringEx.H and add ZftAtoI(), ZftAotL() etc in ZCppMain/ZMainHead.H --- ZCppMain/ZMainHead.H | 98 +++++++++++++++++++++++++++++++------- ZCppMain/ZtCStringEx.H | 54 +++++++++------------ ZCppMain/ZtCStringStd.H | 35 ++++++++++++++ ZCppMainTest/ZtCStringBase_000.cpp | 33 +++++++++++-- 4 files changed, 165 insertions(+), 55 deletions(-) diff --git a/ZCppMain/ZMainHead.H b/ZCppMain/ZMainHead.H index c7b4369..0758e15 100644 --- a/ZCppMain/ZMainHead.H +++ b/ZCppMain/ZMainHead.H @@ -193,6 +193,7 @@ #include #include #include +#include #define _CODE_OLD_ 0 @@ -817,22 +818,11 @@ namespace ZNsMain template class ZtCCharInt - { - public: typedef typename ZtCCharIntBySize::TypeInte TypeInt; - };/* - template class ZtCCharInt*/ - - template<> class ZtCCharInt - { - public: typedef typename ZtCCharIntBySize::TypeInt TypeInt; - };/* - template<> class ZtCCharInt*/ - - template<> class ZtCCharInt - { - public: typedef typename ZtCCharIntBySize::TypeInt TypeInt; - };/* - template<> class ZtCCharInt*/ + { public: typedef typename ZtCCharIntBySize::TypeInt TypeInt; }; + template<> class ZtCCharInt + { public: typedef typename ZtCCharIntBySize::TypeInt TypeInt; }; + template<> class ZtCCharInt + { public: typedef typename ZtCCharIntBySize::TypeInt TypeInt; }; template ZTypIntE ZftGetCompareCode @@ -3814,6 +3804,78 @@ namespace ZNsMain inline double ZfAtoD(const char* ApcChar)*/ + /*############################################################################# + + ■ #include + long int wcstol(const wchar_t *nptr, wchar_t **endptr, int base); + + #include + long long int wcstoll(const wchar_t *nptr, wchar_t **endptr, int base); + + + float wcstof ( const wchar_t* str, wchar_t** str_end ); (since C++11) + double wcstod ( const wchar_t* str, wchar_t** str_end ); + long double wcstold( const wchar_t* str, wchar_t** str_end ); (since C++11) + + -- 2025-10-08 09:23 + #############################################################################*/ + template inline + ZTypInt ZftAtoI (const TTypChar* ApcChar){ return 0; } + template<> inline + ZTypInt ZftAtoI (const char* ApcChar){ return ZfAtoI(ApcChar); } + template<> inline + ZTypInt ZftAtoI (const wchar_t* ApcChar){ return (ZTypInt)::wcstol(ApcChar, 0, 0) ; } + + template inline + ZTypLong ZftAtoL (const TTypChar* ApcChar){ return 0; } + template<> inline + ZTypLong ZftAtoL (const char* ApcChar){ return ZfAtoI(ApcChar); } + template<> inline + ZTypLong ZftAtoL (const wchar_t* ApcChar){ return ::wcstol(ApcChar, 0, 0) ; } + + template inline + ZTypLLong ZftAtoLL(const TTypChar* ApcChar){ return 0; } + template<> inline + ZTypLLong ZftAtoLL(const char* ApcChar){ return ZfAtoLL(ApcChar); } + template<> inline + ZTypLLong ZftAtoLL(const wchar_t* ApcChar){ return ::wcstoll(ApcChar, 0, 0) ; } + + template inline + double ZftAtoD (const TTypChar* ApcChar){ return 0; } + template<> inline + double ZftAtoD (const char* ApcChar){ return ZfAtoD(ApcChar); } + template<> inline + double ZftAtoD (const wchar_t* ApcChar){ return ::wcstod(ApcChar, 0) ; } + + + template inline + ZTypInt ZftAtoI (const TTypChar* ApcChar, ZTypInt AI_Length){ return 0; } + template<> inline + ZTypInt ZftAtoI (const char* ApcChar, ZTypInt AI_Length){ return ZfAtoI(ApcChar); } + template<> inline + ZTypInt ZftAtoI (const wchar_t* ApcChar, ZTypInt AI_Length){ return (ZTypInt)::wcstol(ApcChar, 0, 0) ; } + + template inline + ZTypLong ZftAtoL (const TTypChar* ApcChar, ZTypInt AI_Length){ return 0; } + template<> inline + ZTypLong ZftAtoL (const char* ApcChar, ZTypInt AI_Length){ return ZfAtoI(ApcChar); } + template<> inline + ZTypLong ZftAtoL (const wchar_t* ApcChar, ZTypInt AI_Length){ return ::wcstol(ApcChar, 0, 0) ; } + + template inline + ZTypLLong ZftAtoLL(const TTypChar* ApcChar, ZTypInt AI_Length){ return 0; } + template<> inline + ZTypLLong ZftAtoLL(const char* ApcChar, ZTypInt AI_Length){ return ZfAtoLL(ApcChar); } + template<> inline + ZTypLLong ZftAtoLL(const wchar_t* ApcChar, ZTypInt AI_Length){ return ::wcstoll(ApcChar, 0, 0) ; } + + template inline + double ZftAtoD (const TTypChar* ApcChar, ZTypInt AI_Length){ return 0; } + template<> inline + double ZftAtoD (const char* ApcChar, ZTypInt AI_Length){ return ZfAtoD(ApcChar); } + template<> inline + double ZftAtoD (const wchar_t* ApcChar, ZTypInt AI_Length){ return ::wcstod(ApcChar, 0) ; } + inline ZTypLLong AtoLL(const char* ApcChar){return ZfAtoLL(ApcChar);} @@ -3837,9 +3899,9 @@ namespace ZNsMain ZTypLength VL_Length=0; - while(*(ApcChar+VL_Length)!=_T('\0')) + while(*(ApcChar+VL_Length)!=TTypeCh('\0')) ++VL_Length; - /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ + /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ return VL_Length; }/* diff --git a/ZCppMain/ZtCStringEx.H b/ZCppMain/ZtCStringEx.H index e5c27f8..65d351f 100644 --- a/ZCppMain/ZtCStringEx.H +++ b/ZCppMain/ZtCStringEx.H @@ -1300,12 +1300,12 @@ namespace ZNsMain bool operator<=(TypeCharC* APC_Data) const{return Minus(APC_Data)<=0 ;} bool operator< (TypeCharC* APC_Data) const{return Minus(APC_Data)< 0 ;} - bool operator==(const ZCStringBase& rhs) const{return Minus(rhs.data(), rhs.GetUseLength())==0 ;} - bool operator!=(const ZCStringBase& rhs) const{return Minus(rhs.data(), rhs.GetUseLength())!=0 ;} - bool operator> (const ZCStringBase& rhs) const{return Minus(rhs)> 0;} - bool operator>=(const ZCStringBase& rhs) const{return Minus(rhs)>=0;} - bool operator< (const ZCStringBase& rhs) const{return Minus(rhs)< 0;} - bool operator<=(const ZCStringBase& rhs) const{return Minus(rhs)<=0;} + bool operator==(const ZCStringBase& rhs ) const{return Minus(rhs.data(), rhs.GetUseLength())==0 ;} + bool operator!=(const ZCStringBase& rhs ) const{return Minus(rhs.data(), rhs.GetUseLength())!=0 ;} + bool operator> (const ZCStringBase& rhs ) const{return Minus(rhs)> 0;} + bool operator>=(const ZCStringBase& rhs ) const{return Minus(rhs)>=0;} + bool operator< (const ZCStringBase& rhs ) const{return Minus(rhs)< 0;} + bool operator<=(const ZCStringBase& rhs ) const{return Minus(rhs)<=0;} bool operator==(const ZCChars& AR_CChars) const{return Minus(AR_CChars.data(), AR_CChars.size())==0 ;} bool operator!=(const ZCChars& AR_CChars) const{return Minus(AR_CChars.data(), AR_CChars.size())!=0 ;} @@ -1928,36 +1928,23 @@ namespace ZNsMain }/* bool IsEmpty() const*/ - int GetInt () const{return ZNsMain::ZfAtoI (mpc_Data);} - ZTypLong GetLong () const{return ZNsMain::ZfAtoL (mpc_Data);} - ZTypLLong GetLongLong() const{return ZNsMain::ZfAtoLL(mpc_Data);} - ZTypLLong GetLLong () const{return ZNsMain::ZfAtoLL(mpc_Data);} - double GetDouble () const{return ZNsMain::ZfAtoD (mpc_Data);} - - ZCStringBase& ConvertLLong() - { - ZNsMain::ZTypLLong LLongValue = ZNsMain::ZfAtoLL(mpc_Data); - - this->Invalid(); return (*this)(LLongValue); - }/* - ZCStringBase& ConvertLLong()*/ - - ZCStringBase& ConvertLong() - { - ZNsMain::ZTypLLong LongValue = ZNsMain::ZfAtoL(mpc_Data); - - this->Invalid(); return (*this)(LongValue); - }/* - ZCStringBase& ConvertLong()*/ + int GetInt () const{return ZNsMain::ZftAtoI (mpc_Data);} + ZTypLong GetLong () const{return ZNsMain::ZftAtoL (mpc_Data);} + ZTypLLong GetLongLong() const{return ZNsMain::ZftAtoLL(mpc_Data);} + ZTypLLong GetLLong () const{return ZNsMain::ZftAtoLL(mpc_Data);} + double GetDouble () const{return ZNsMain::ZftAtoD (mpc_Data);} ZCStringBase& Format(TypeCharC* APC_Format, ...) { // 이 함수 수행전에 적당한 문자열 메모리가 할당되어 있어야 한다. - va_list VP_VarParam; + va_list VP_VarParam; va_start(VP_VarParam, APC_Format); - vsprintf(mpc_Data, APC_Format, VP_VarParam); + + if(sizeof(TypeChar)<=1) + ::vsprintf ((char* )mpc_Data, /*+++*/ (char* )APC_Format, VP_VarParam); + else ::vswprintf((wchar_t*)mpc_Data, size(), (wchar_t*)APC_Format, VP_VarParam); InvalidNull(); return *this; }/* @@ -1969,9 +1956,12 @@ namespace ZNsMain ReAllocKeep(ml_UseLen+AL_FormatSize); - va_list VP_VarParam; - va_start( VP_VarParam, APC_Format); - vsprintf(mpc_Data+ml_UseLen, APC_Format, VP_VarParam); + va_list VP_VarParam; + va_start(VP_VarParam, APC_Format); + + if(sizeof(TypeChar)<=1) + ::vsprintf ((char* )mpc_Data, /*+++*/ (char* )APC_Format, VP_VarParam); + else ::vswprintf((wchar_t*)mpc_Data, size(), (wchar_t*)APC_Format, VP_VarParam); InvalidNull(ml_UseLen); return *this; }/* diff --git a/ZCppMain/ZtCStringStd.H b/ZCppMain/ZtCStringStd.H index 40adeb0..b963306 100644 --- a/ZCppMain/ZtCStringStd.H +++ b/ZCppMain/ZtCStringStd.H @@ -62,6 +62,34 @@ namespace ZNsMain }/* ZtCStringStd& operator=(const TypeBase& rhs)*/ + ZtCStringStd& operator=(const ZCCharView& AR_View) + { + if(this->data()==AR_View.data()){ return *this; } + if( 1 > AR_View.size()) + { this->resize(0); return *this; } + + this->resize(AR_View.size()); + + const int CI_CopySize = + AR_View.size() * sizeof(TypeChar) ; + + ::memcpy(this->data(), AR_View.data(), CI_CopySize); + + return *this; /*::::::::::::::::::::::::::::::::::*/ + }/* + ZtCStringStd& operator=(const ZCCharView& AR_View)*/ + + + ZtCStringStd& operator=(ZTypInt AI_Int ) + { this->resize(0); return (*this)(AI_Int ); } + ZtCStringStd& operator=(ZTypLong AL_Long ) + { this->resize(0); return (*this)(AL_Long ); } + ZtCStringStd& operator=(ZTypLLong AL_LLong ) + { this->resize(0); return (*this)(AL_LLong ); } + ZtCStringStd& operator=(double AD_Double) + { this->resize(0); return (*this)(AD_Double); } + + template void FindPosToList ///////////// ( @@ -457,6 +485,13 @@ namespace ZNsMain }/* ZtCStringStd& operator()(double AD_DoubleParam)*/ + + int GetInt () const{return ZNsMain::ZftAtoI (this->data());} + ZTypLong GetLong () const{return ZNsMain::ZftAtoL (this->data());} + ZTypLLong GetLongLong() const{return ZNsMain::ZftAtoLL(this->data());} + ZTypLLong GetLLong () const{return ZNsMain::ZftAtoLL(this->data());} + double GetDouble () const{return ZNsMain::ZftAtoD (this->data());} + public: };/* template diff --git a/ZCppMainTest/ZtCStringBase_000.cpp b/ZCppMainTest/ZtCStringBase_000.cpp index bf84af8..0afbd7c 100644 --- a/ZCppMainTest/ZtCStringBase_000.cpp +++ b/ZCppMainTest/ZtCStringBase_000.cpp @@ -20,7 +20,8 @@ namespace ZNsMain typedef ZtCStringBase ZCStringBase ; typedef ZtCStringBase ZCStringBaseW ; - typedef ZCStringBase::ZCCharView ZCCharView ; + typedef ZCStringBase ::ZCCharView ZCCharView ; + typedef ZCStringBaseW::ZCCharView ZCCharViewW ; typedef ZtCCharType ZCCharType ; typedef ZtCCharType ZCCharTypeW ; @@ -61,19 +62,35 @@ namespace ZNsMain ZCStringBaseW VO_ZCStringBaseW; ZCStringStdW VO_ZCStringStdW ; - VO_ZCStringBaseW(123); - cout<<"* after VO_ZCStringBaseW(123)"<