From b689edaf75a84833603c3505ca3573f11a6df88c Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Thu, 4 Aug 2022 10:47:10 +0800 Subject: [PATCH] used GetFirstChar/GetLastChar instead of GetBeginChar/GetEndChar --- inc/hgl/filesystem/Filename.h | 6 +++--- inc/hgl/type/String.h | 38 +++++++++++++++-------------------- inc/hgl/type/StringInstance.h | 4 ++-- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/inc/hgl/filesystem/Filename.h b/inc/hgl/filesystem/Filename.h index 1a41f14..62998a4 100644 --- a/inc/hgl/filesystem/Filename.h +++ b/inc/hgl/filesystem/Filename.h @@ -110,9 +110,9 @@ namespace hgl { String fullname; - if(pathname.GetEndChar()==directory_separator_char) //结尾有分隔符 + if(pathname.GetLastChar()==directory_separator_char) //结尾有分隔符 { - if(filename.GetBeginChar()==directory_separator_char) //开头有分隔符 + if(filename.GetFirstChar()==directory_separator_char) //开头有分隔符 { fullname.SetString(pathname.c_str(),pathname.Length()-1); //少取一个字符 } @@ -125,7 +125,7 @@ namespace hgl { fullname=pathname; - if(filename.GetBeginChar()!=directory_separator_char) //开头没有分隔符 + if(filename.GetFirstChar()!=directory_separator_char) //开头没有分隔符 { fullname.Strcat(directory_separator_str); //添加分隔符 } diff --git a/inc/hgl/type/String.h b/inc/hgl/type/String.h index 4399a44..0845c80 100644 --- a/inc/hgl/type/String.h +++ b/inc/hgl/type/String.h @@ -183,15 +183,15 @@ namespace hgl virtual ~String()=default; - const T GetBeginChar()const ///<取得当前字符串第一个字符 + const T GetFirstChar()const ///<取得当前字符串第一个字符 { - return(data.valid()?data->GetBeginChar():0); + return(data.valid()?data->GetFirstChar():0); } - const T GetEndChar()const ///<取得当前字符串最后一个字符 + const T GetLastChar()const ///<取得当前字符串最后一个字符 { // if(!this)return(0); - return(data.valid()?data->GetEndChar():0); + return(data.valid()?data->GetLastChar():0); } const int Length()const ///<当前字符串长度 @@ -869,41 +869,35 @@ namespace hgl protected: - typedef const T *(*ConvFunc)(const T *,int &); + typedef const T *(*ConvFunc)(const T *,int &,const bool (*trimfunc)(const T &)); - bool StrConv(ConvFunc conv) + SelfClass StrConv(ConvFunc conv) const { if(!data.valid()||data->GetLength()<=0) - return(false); + return SelfClass(); int new_len=data->GetLength(); - const T *new_str=conv(data->c_str(),new_len); + const T *new_str=conv(data->c_str(),new_len,isspace); - if(new_len>0) - { - SetString(new_str,new_len); - return(true); - } - else - { - Clear(); - return(false); - } + if(new_len<=0) + return SelfClass(); + + return SelfClass(new_str,new_len); } public: - bool TrimLeft(){return StrConv(trimleft);} ///<删除字符串前端的空格、换行等不可视字符串 - bool TrimRight(){return StrConv(trimright);} ///<删除字符串后端的空格、换行等不可视字符串 - bool Trim(){return StrConv(trim);} ///<删除字符串两端的空格、换行等不可视字符串 + SelfClass TrimLeft ()const{return StrConv(trimleft);} ///<删除字符串前端的空格、换行等不可视字符串 + SelfClass TrimRight ()const{return StrConv(trimright);} ///<删除字符串后端的空格、换行等不可视字符串 + SelfClass Trim ()const{return StrConv(trim);} ///<删除字符串两端的空格、换行等不可视字符串 bool TrimLeft(int n){return Delete(0,n);} ///<删除字符串前端的指定个字符 bool TrimRight(int n){return Unlink()?data->TrimRight(n):false;} ///<删除字符串后端的指定个字符 bool ClipLeft(int n){return Unlink()?data->ClipLeft(n):false;} ///<截取字符串前端的指定个字符,等同TrimRight(lengths-n)) bool ClipRight(int n){return Delete(0,Length()-n);} ///<截取字符串后端的指定个字符,等同TrimLeft(length-n) - bool Clip(uint pos,int num) ///<从指定位置删除指定个字符 + bool Clip(uint pos,int num) ///<从指定位置删除指定个字符 { if(!Unlink()) return(false); diff --git a/inc/hgl/type/StringInstance.h b/inc/hgl/type/StringInstance.h index 315f0c4..393ed88 100644 --- a/inc/hgl/type/StringInstance.h +++ b/inc/hgl/type/StringInstance.h @@ -221,12 +221,12 @@ namespace hgl return(true); } - const T GetBeginChar()const + const T GetFirstChar()const { return buffer?*buffer:0; } - const T GetEndChar()const + const T GetLastChar()const { return buffer?*(buffer+length-1):0; }