改进BaseString/StringInstance
This commit is contained in:
@@ -191,7 +191,7 @@ namespace hgl
|
||||
int wlen;
|
||||
u16char *ws=u8_to_u16(u8_str,length,wlen);
|
||||
|
||||
return UTF16String(ws,wlen,true);
|
||||
return UTF16String::newOf(ws,wlen);
|
||||
}
|
||||
|
||||
inline UTF16String to_u16(const UTF8String &u8str)
|
||||
@@ -204,8 +204,8 @@ namespace hgl
|
||||
int wlen;
|
||||
|
||||
u16char *ws=u8_to_u16(str,strlen(str),wlen);
|
||||
|
||||
return UTF16String(ws,wlen,true);
|
||||
|
||||
return UTF16String::newOf(ws,wlen);
|
||||
}
|
||||
|
||||
inline UTF8String to_u8(const u16char *wide_str,int length)
|
||||
@@ -214,7 +214,7 @@ namespace hgl
|
||||
|
||||
char *us=u16_to_u8(wide_str,length,ulen);
|
||||
|
||||
return UTF8String(us,ulen,true);
|
||||
return UTF8String::newOf(us,ulen);
|
||||
}
|
||||
|
||||
inline UTF8String to_u8(const UTF16String &ws)
|
||||
|
@@ -21,7 +21,7 @@ namespace hgl
|
||||
{
|
||||
if(filename.GetBeginChar()==directory_separator_char) //开头有分隔符
|
||||
{
|
||||
fullname.Set(pathname.c_str(),pathname.Length()-1); //少取一个字符
|
||||
fullname.SetString(pathname.c_str(),pathname.Length()-1); //少取一个字符
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -36,12 +36,12 @@ namespace hgl
|
||||
|
||||
inline void DebugLog(LogLevel ll,const UTF16String &str,const char *filename,int line,const char *funcname)
|
||||
{
|
||||
Log(ll,str+U16_TEXT(">>LogFrom(\"")+to_u16(filename)+U16_TEXT("\", ")+UTF16String(line)+U16_TEXT(" line,func:\"")+to_u16(funcname)+U16_TEXT("\")"));
|
||||
Log(ll,str+U16_TEXT(">>LogFrom(\"")+to_u16(filename)+U16_TEXT("\", ")+UTF16String::valueOf(line)+U16_TEXT(" line,func:\"")+to_u16(funcname)+U16_TEXT("\")"));
|
||||
}
|
||||
|
||||
inline void DebugLog(LogLevel ll,const UTF8String &str,const char *filename,int line,const char *funcname)
|
||||
{
|
||||
Log(ll,str+U8_TEXT(">>LogFrom(\"")+UTF8String(filename)+U8_TEXT("\", ")+UTF8String(line)+U8_TEXT(" line,func:\"")+UTF8String(funcname)+U8_TEXT("\")"));
|
||||
Log(ll,str+U8_TEXT(">>LogFrom(\"")+UTF8String(filename)+U8_TEXT("\", ")+UTF8String::valueOf(line)+U8_TEXT(" line,func:\"")+UTF8String(funcname)+U8_TEXT("\")"));
|
||||
}
|
||||
|
||||
#define LOG_INFO(str) {Log(llLog, str);}
|
||||
@@ -49,9 +49,9 @@ namespace hgl
|
||||
#define LOG_PROBLEM(str) {Log(llProblem, str);}
|
||||
#define LOG_ERROR(str) {Log(llError, str);}
|
||||
|
||||
#define RETURN_FALSE {DebugLog(llLog,OS_TEXT("return(false)" ),__FILE__,__LINE__,__HGL_FUNC__);return(false);}
|
||||
#define RETURN_ERROR(v) {DebugLog(llLog,OS_TEXT("return error(")+OSString(v)+OS_TEXT(")"),__FILE__,__LINE__,__HGL_FUNC__);return(v);}
|
||||
#define RETURN_ERROR_NULL {DebugLog(llLog,OS_TEXT("return error(nullptr)" ),__FILE__,__LINE__,__HGL_FUNC__);return(nullptr);}
|
||||
#define RETURN_FALSE {DebugLog(llLog,OS_TEXT("return(false)"), __FILE__,__LINE__,__HGL_FUNC__);return(false);}
|
||||
#define RETURN_ERROR(v) {DebugLog(llLog,OS_TEXT("return error(")+OSString::valueOf(v)+OS_TEXT(")"), __FILE__,__LINE__,__HGL_FUNC__);return(v);}
|
||||
#define RETURN_ERROR_NULL {DebugLog(llLog,OS_TEXT("return error(nullptr)"), __FILE__,__LINE__,__HGL_FUNC__);return(nullptr);}
|
||||
|
||||
#define RETURN_BOOL(proc) {if(proc)return(true);RETURN_FALSE}
|
||||
|
||||
|
@@ -25,9 +25,37 @@ namespace hgl
|
||||
|
||||
BaseString()=default;
|
||||
|
||||
BaseString(InstClass *ic)
|
||||
{
|
||||
data=ic;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据一个C指针风格字符串设置当前字符串内容
|
||||
* @param str 字符串内容,需以0为结尾
|
||||
*/
|
||||
BaseString(const T *str)
|
||||
{
|
||||
Set(str);
|
||||
SetString(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据一个C指针风格字符串设置当前字符串内容(传入的str需要delete[])
|
||||
* @param str 字符串内容,在len<0的情况下,需以0为结尾
|
||||
* @param len 字符串长度,如果str以0为结尾,可以为负值,将启用自动计算长度
|
||||
*/
|
||||
BaseString(const T *str,int len)
|
||||
{
|
||||
SetString(str,len);
|
||||
}
|
||||
|
||||
static BaseString<T> newOf(T *str,const uint len)
|
||||
{
|
||||
StringInstance<T> *si=new StringInstance<T>();
|
||||
|
||||
si->InitFromInstance(str,len);
|
||||
|
||||
return BaseString<T>(si);
|
||||
}
|
||||
|
||||
BaseString(io::InputStream *is,int len=0)
|
||||
@@ -45,9 +73,11 @@ namespace hgl
|
||||
len=is->Read(str,len*sizeof(T));
|
||||
|
||||
str[len]=0;
|
||||
Set(str,len,true);
|
||||
SetInstance(str,len);
|
||||
}
|
||||
|
||||
BaseString(const char)=delete;
|
||||
|
||||
static BaseString<T> charOf(const T &ch)
|
||||
{
|
||||
T *str=new T[2];
|
||||
@@ -55,18 +85,7 @@ namespace hgl
|
||||
str[0]=ch;
|
||||
str[1]=0;
|
||||
|
||||
return BaseString<T>(str,1,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据一个C指针风格字符串设置当前字符串内容
|
||||
* @param str 字符串内容,在len<0的情况下,需以0为结尾
|
||||
* @param len 字符串长度,如果str以0为结尾,可以为负值,将启用自动计算长度
|
||||
* @param one_instance 是否仅有这一份实例,如果是将不会产生复岓是而是直接使用此值,最终delete[]释放
|
||||
*/
|
||||
BaseString(const T *str,int len,bool one_instance=false)
|
||||
{
|
||||
Set(str,len,one_instance);
|
||||
return BaseString<T>::newOf(str,1);
|
||||
}
|
||||
|
||||
BaseString(const InstClass &si)
|
||||
@@ -84,9 +103,19 @@ namespace hgl
|
||||
}
|
||||
|
||||
#define BASE_STRING_NUMBER_CONSTRUCT(type,func) \
|
||||
BaseString(const type num) \
|
||||
BaseString(const type num)=delete; \
|
||||
static BaseString<T> valueOf(const type value) \
|
||||
{ \
|
||||
Set(func(new T[8*sizeof(type)],8*sizeof(type),num),-1,true); \
|
||||
StringInstance<T> *si=new StringInstance<T>(); \
|
||||
\
|
||||
const int len=8*sizeof(type); \
|
||||
\
|
||||
T *tmp_str=new T[len]; \
|
||||
\
|
||||
func(tmp_str,len,value); \
|
||||
si->InitFromInstance(tmp_str,hgl::strlen(tmp_str)); \
|
||||
\
|
||||
return BaseString<T>(si); \
|
||||
}
|
||||
|
||||
BASE_STRING_NUMBER_CONSTRUCT(int, itos);
|
||||
@@ -99,7 +128,9 @@ namespace hgl
|
||||
|
||||
#undef BASE_STRING_NUMBER_CONSTRUCT
|
||||
|
||||
BaseString(const int *value,int N)
|
||||
BaseString(const int *value,int N)=delete;
|
||||
|
||||
static BaseString<T> valueOf(const int *value,int N)
|
||||
{
|
||||
const int size=N*sizeof(int)*8;
|
||||
int len;
|
||||
@@ -117,10 +148,12 @@ namespace hgl
|
||||
++value;
|
||||
}
|
||||
|
||||
Set(tmp_str);
|
||||
return BaseString<T>(tmp_str);
|
||||
}
|
||||
|
||||
BaseString(const float *value,int N)
|
||||
BaseString(const float *value,int N)=delete;
|
||||
|
||||
static BaseString<T> valueOf(const float *value,int N)
|
||||
{
|
||||
const int size=N*sizeof(float)*16;
|
||||
int len;
|
||||
@@ -137,8 +170,8 @@ namespace hgl
|
||||
ftos(tmp_str+len,size-len,*value);
|
||||
++value;
|
||||
}
|
||||
|
||||
Set(tmp_str);
|
||||
|
||||
return BaseString<T>(tmp_str);
|
||||
}
|
||||
|
||||
virtual ~BaseString()=default;
|
||||
@@ -209,9 +242,8 @@ namespace hgl
|
||||
* 根据一个C指针风格字符串设置当前字符串内容
|
||||
* @param str 字符串内容,在len<0的情况下,需以0为结尾
|
||||
* @param len 字符串长度,如果str以0为结尾,可以为负值,将启用自动计算长度
|
||||
* @param one_instance 是否仅有这一份实例,如果是将不会产生复岓是而是直接使用此值,最终delete[]释放
|
||||
*/
|
||||
void Set(const T *str,int len=-1,bool one_instance=false)
|
||||
void SetString(const T *str,int len=-1)
|
||||
{
|
||||
if(!str||!*str||!len) //len=-1为自检测,为0不处理
|
||||
{
|
||||
@@ -219,12 +251,35 @@ namespace hgl
|
||||
return;
|
||||
}
|
||||
|
||||
data=new InstClass(str,len,one_instance);
|
||||
data=new InstClass();
|
||||
data->InitFromString(str,len);
|
||||
}
|
||||
|
||||
void Strcpy(const T *str,int len=-1,bool one=false)
|
||||
/**
|
||||
* 根据一个C指针风格字符串设置当前字符串内容
|
||||
* @param str 字符串内容,在len<0的情况下,需以0为结尾
|
||||
* @param len 字符串长度
|
||||
*/
|
||||
void SetInstance(const T *str,const uint len)
|
||||
{
|
||||
Set(str,len,one);
|
||||
if(!str||!*str)
|
||||
{
|
||||
Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
data=new InstClass();
|
||||
data->InitFromInstance(str,len);
|
||||
}
|
||||
|
||||
void Strcpy(const T *str,int len=-1)
|
||||
{
|
||||
SetString(str,len);
|
||||
}
|
||||
|
||||
void StrcpyInstance(const T *str,int len=-1)
|
||||
{
|
||||
SetInstance(str,len);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,7 +418,7 @@ namespace hgl
|
||||
* @param str 要插入的字符串
|
||||
* @param len 要插入的字符个数,如果为-1则自动检测字符串长度
|
||||
*/
|
||||
bool Insert(int pos,const T *str,int len=-1)
|
||||
bool Insert(const uint pos,const T *str,int len=-1)
|
||||
{
|
||||
if(len==0)return(false);
|
||||
|
||||
@@ -376,7 +431,7 @@ namespace hgl
|
||||
}
|
||||
else
|
||||
{
|
||||
Set(str,len);
|
||||
SetString(str,len);
|
||||
return(true);
|
||||
}
|
||||
}
|
||||
@@ -386,7 +441,7 @@ namespace hgl
|
||||
* @param pos 要插入的位置
|
||||
* @param str 要插入的字符串
|
||||
*/
|
||||
bool Insert(int pos,const SelfClass &str)
|
||||
bool Insert(const uint pos,const SelfClass &str)
|
||||
{
|
||||
if((&str)==nullptr)
|
||||
return(false);
|
||||
@@ -418,7 +473,7 @@ namespace hgl
|
||||
* @param num 要删除的字符个数
|
||||
* @return 是否成功
|
||||
*/
|
||||
bool Delete(int pos,int num)
|
||||
bool Delete(const uint pos,int num)
|
||||
{
|
||||
if(pos<0||num<=0)return(false);
|
||||
|
||||
@@ -482,7 +537,7 @@ namespace hgl
|
||||
* @return 0 等同
|
||||
* @return >0 自身大
|
||||
*/
|
||||
int Comp(const int pos,const SelfClass &bs)const
|
||||
int Comp(const uint pos,const SelfClass &bs)const
|
||||
{
|
||||
if(!data.valid())
|
||||
return(bs.Length());
|
||||
@@ -502,7 +557,7 @@ namespace hgl
|
||||
* @return 0 等同
|
||||
* @return >0 自身大
|
||||
*/
|
||||
int Comp(const int pos,const SelfClass &bs,const int num)const
|
||||
int Comp(const uint pos,const SelfClass &bs,const int num)const
|
||||
{
|
||||
if(!data.valid())
|
||||
return(bs.Length());
|
||||
@@ -521,7 +576,7 @@ namespace hgl
|
||||
* @return 0 等同
|
||||
* @return >0 自身大
|
||||
*/
|
||||
int Comp(const int pos,const T *str)const
|
||||
int Comp(const uint pos,const T *str)const
|
||||
{
|
||||
if(!data.valid())
|
||||
{
|
||||
@@ -543,7 +598,7 @@ namespace hgl
|
||||
* @return 0 等同
|
||||
* @return >0 自身大
|
||||
*/
|
||||
int Comp(const int pos,const T *str,const int num)const
|
||||
int Comp(const uint pos,const T *str,const int num)const
|
||||
{
|
||||
if(!data.valid())
|
||||
{
|
||||
@@ -681,6 +736,28 @@ namespace hgl
|
||||
|
||||
return data->CaseComp(str,num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 和那一个字符串比较指字长度的字符,英文不区分大小写
|
||||
* @param str 比较字符串
|
||||
* @param num 比较字数
|
||||
* @return <0 自身小
|
||||
* @return 0 等同
|
||||
* @return >0 自身大
|
||||
*/
|
||||
int CaseComp(const uint pos,const T *str,const int num)const
|
||||
{
|
||||
if(!data.valid())
|
||||
{
|
||||
if(!str||num<=0)
|
||||
return 0;
|
||||
|
||||
return *str;
|
||||
}
|
||||
|
||||
return data->CaseComp(pos,str,num);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
bool ToBool(bool &result)const ///<将本类中的字符串转换成布尔数值并返回
|
||||
@@ -814,7 +891,7 @@ namespace hgl
|
||||
|
||||
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(int pos,int num) ///<从指定位置删除指定个字符
|
||||
bool Clip(uint pos,int num) ///<从指定位置删除指定个字符
|
||||
{
|
||||
if(!Unlink())
|
||||
return(false);
|
||||
@@ -874,7 +951,7 @@ namespace hgl
|
||||
int StatChar(const T ch)const{return data.valid()?StatChar(data->c_str(),ch):-1;} ///<统计字符串中某个字符的个数
|
||||
int StatLine()const{return data.valid()?StatLine(data->c_str()):-1;} ///<统计字符串行数
|
||||
|
||||
int FindChar(int pos,const T ch)const ///<返回当前字符串中指定字符开始的索引(从左至右)
|
||||
int FindChar(uint pos,const T ch)const ///<返回当前字符串中指定字符开始的索引(从左至右)
|
||||
{
|
||||
if(!data.valid())
|
||||
return(-1);
|
||||
@@ -894,7 +971,7 @@ namespace hgl
|
||||
* @param pos 起始查找位置
|
||||
* @param ch 要查找的字符,可以是多个,找到任意一个就算
|
||||
*/
|
||||
int FindChar(int pos,const BaseString<T> &ch)const ///<返回当前字符串中指定字符(多个任选一)的索引(从左至右)
|
||||
int FindChar(uint pos,const BaseString<T> &ch)const ///<返回当前字符串中指定字符(多个任选一)的索引(从左至右)
|
||||
{
|
||||
if(!data.valid())
|
||||
return(-1);
|
||||
@@ -976,7 +1053,7 @@ namespace hgl
|
||||
* @param pos 起始查找位置
|
||||
* @param ch 要排除的字符
|
||||
*/
|
||||
int FindExcludeChar(const int pos,const T &ch)const
|
||||
int FindExcludeChar(const uint pos,const T &ch)const
|
||||
{
|
||||
if(!data.valid())
|
||||
return(-1);
|
||||
@@ -996,7 +1073,7 @@ namespace hgl
|
||||
* @param pos 起始查找位置
|
||||
* @param ch 要排除的字符
|
||||
*/
|
||||
int FindExcludeChar(const int pos,const BaseString<T> &ch)const
|
||||
int FindExcludeChar(const uint pos,const BaseString<T> &ch)const
|
||||
{
|
||||
if(!data.valid())
|
||||
return(-1);
|
||||
@@ -1075,7 +1152,7 @@ namespace hgl
|
||||
* @param str 要写入的字符串
|
||||
* @return 是否成功
|
||||
*/
|
||||
bool WriteString(int pos,const SelfClass &str)
|
||||
bool WriteString(uint pos,const SelfClass &str)
|
||||
{
|
||||
if(!Unlink())
|
||||
return(false);
|
||||
@@ -1151,7 +1228,7 @@ namespace hgl
|
||||
|
||||
ms[new_len]=0;
|
||||
|
||||
return(SelfClass(ms,new_len,true));
|
||||
return BaseString::newOf(ms,new_len);
|
||||
}
|
||||
|
||||
SelfClass operator + (const SelfClass &str) const
|
||||
@@ -1168,7 +1245,7 @@ namespace hgl
|
||||
SelfClass operator + (const T ch) const
|
||||
{
|
||||
if(!data.valid())
|
||||
return(SelfClass(ch));
|
||||
return(SelfClass::charOf(ch));
|
||||
|
||||
return ComboString(data->c_str(),data->GetLength(),&ch,1);
|
||||
}
|
||||
|
@@ -250,7 +250,7 @@ namespace hgl
|
||||
* @return 字符串长度
|
||||
*/
|
||||
template<typename T>
|
||||
int strlen(const T *str,int max_len)
|
||||
int strlen(const T *str,uint max_len)
|
||||
{
|
||||
if(str&&*str)
|
||||
{
|
||||
@@ -2025,7 +2025,7 @@ namespace hgl
|
||||
* @return 转换后的字符串
|
||||
*/
|
||||
template<typename T,typename I>
|
||||
T *itos(T *str,int size,const I num)
|
||||
T *itos(T *str,const int size,const I num)
|
||||
{
|
||||
itos_rl(str,size,num);
|
||||
return str;
|
||||
|
@@ -14,8 +14,8 @@ namespace hgl
|
||||
|
||||
typedef StringInstance<T> SelfClass;
|
||||
|
||||
int length; ///<字符串长度
|
||||
int malloc_length; ///<空间实际分配长度
|
||||
uint length; ///<字符串长度
|
||||
uint malloc_length; ///<空间实际分配长度
|
||||
|
||||
T *buffer;
|
||||
|
||||
@@ -28,6 +28,17 @@ namespace hgl
|
||||
buffer=0;
|
||||
}
|
||||
|
||||
virtual void InitPrivate(const T *str,const uint len)
|
||||
{
|
||||
length=len;
|
||||
|
||||
malloc_length=power_to_2(length+1);
|
||||
|
||||
buffer=new T[malloc_length];
|
||||
memcpy(buffer,str,length*sizeof(T));
|
||||
buffer[length]=0;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
StringInstance()
|
||||
@@ -35,16 +46,21 @@ namespace hgl
|
||||
InitPrivate();
|
||||
}
|
||||
|
||||
StringInstance(const T *str,int len=-1,bool one_instance=false)
|
||||
/**
|
||||
* 初始化字符串实例(基于一个字符串)
|
||||
*/
|
||||
void InitFromString(const T *str,const int len)
|
||||
{
|
||||
if(!str)
|
||||
if(!str||!len)
|
||||
{
|
||||
InitPrivate();
|
||||
return;
|
||||
}
|
||||
|
||||
if(len<0)
|
||||
{
|
||||
length=hgl::strlen(str);
|
||||
}
|
||||
else
|
||||
{
|
||||
length=hgl::strlen(str,len);
|
||||
@@ -56,29 +72,50 @@ namespace hgl
|
||||
if(length<=0)
|
||||
{
|
||||
InitPrivate();
|
||||
return;
|
||||
}
|
||||
|
||||
if(one_instance)
|
||||
delete[] str;
|
||||
InitPrivate(str,length);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化字符串实例(基于一块已经分配好的内存)
|
||||
*/
|
||||
void InitFromInstance(T *str,const uint len)
|
||||
{
|
||||
if(!str)
|
||||
{
|
||||
InitPrivate();
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
length=hgl::strlen(str,len);
|
||||
|
||||
while(length&&!str[length-1]) //清除后面的0
|
||||
length--;
|
||||
}
|
||||
|
||||
if(length<=0)
|
||||
{
|
||||
InitPrivate();
|
||||
delete[] str;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(one_instance&&str[length]==0) //如果最后不是0,则需要重新分配内存创建带0结尾的字串
|
||||
if(str[length]==0) //如果最后不是0,则需要重新分配内存创建带0结尾的字串
|
||||
{
|
||||
malloc_length=len;
|
||||
buffer=(T *)str;
|
||||
|
||||
buffer=str;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
InitPrivate(str,length);
|
||||
|
||||
malloc_length=power_to_2(length+1);
|
||||
|
||||
buffer=new T[malloc_length];
|
||||
memcpy(buffer,str,length*sizeof(T));
|
||||
buffer[length]=0;
|
||||
|
||||
if(one_instance)
|
||||
delete[] str;
|
||||
}
|
||||
}
|
||||
|
||||
StringInstance(const SelfClass &bs)
|
||||
@@ -114,16 +151,35 @@ namespace hgl
|
||||
{
|
||||
if(!buffer)return(0);
|
||||
|
||||
return(new SelfClass(buffer,length));
|
||||
SelfClass *sc=new SelfClass();
|
||||
|
||||
sc->InitFromString(buffer,length);
|
||||
|
||||
return sc;
|
||||
}
|
||||
|
||||
SelfClass *CreateCopy(int start,int count=-1)
|
||||
SelfClass *CreateCopy(const uint start)
|
||||
{
|
||||
if(!buffer)return(nullptr);
|
||||
if(start<0||count==0)return(nullptr);
|
||||
if(count>0&&start+count>=length)return(nullptr);
|
||||
if(start>=length)return(nullptr);
|
||||
|
||||
SelfClass *sc=new SelfClass();
|
||||
|
||||
return(new SelfClass(buffer+start,count));
|
||||
sc->InitFromString(buffer+start,length-start);
|
||||
|
||||
return sc;
|
||||
}
|
||||
|
||||
SelfClass *CreateCopy(const uint start,const uint count)
|
||||
{
|
||||
if(!buffer)return(nullptr);
|
||||
if(count==0)return(nullptr);
|
||||
|
||||
SelfClass *sc=new SelfClass();
|
||||
|
||||
sc->InitFromString(buffer+start,start+count>=length?length-start:count);
|
||||
|
||||
return sc;
|
||||
}
|
||||
|
||||
T *Discard()
|
||||
@@ -140,12 +196,12 @@ namespace hgl
|
||||
return buffer;
|
||||
}
|
||||
|
||||
const int GetLength()const ///<取得字符串长度
|
||||
const uint GetLength()const ///<取得字符串长度
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
bool GetChar(int n,T &ch)const
|
||||
bool GetChar(const uint n,T &ch)const
|
||||
{
|
||||
if(n>=length)
|
||||
return(false);
|
||||
@@ -155,7 +211,7 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool SetChar(int n,const T &ch)
|
||||
bool SetChar(const uint n,const T &ch)
|
||||
{
|
||||
if(n>=length)
|
||||
return(false);
|
||||
@@ -198,7 +254,7 @@ namespace hgl
|
||||
* @return 0 等同
|
||||
* @return >0 我方大
|
||||
*/
|
||||
const int Comp(const int pos,const SelfClass *sc)const
|
||||
const int Comp(const uint pos,const SelfClass *sc)const
|
||||
{
|
||||
if(!sc)
|
||||
return length;
|
||||
@@ -229,7 +285,7 @@ namespace hgl
|
||||
* @return 0 等同
|
||||
* @return >0 我方大
|
||||
*/
|
||||
const int Comp(const int pos,const T *str)const
|
||||
const int Comp(const uint pos,const T *str)const
|
||||
{
|
||||
if(!str)
|
||||
return length;
|
||||
@@ -248,7 +304,7 @@ namespace hgl
|
||||
* @return 0 等同
|
||||
* @return >0 我方大
|
||||
*/
|
||||
const int Comp(const T *str,const int num)const
|
||||
const int Comp(const T *str,const uint num)const
|
||||
{
|
||||
if(!str)
|
||||
return length-num;
|
||||
@@ -258,13 +314,14 @@ namespace hgl
|
||||
|
||||
/**
|
||||
* 和一个字符串比较指字长度的字符
|
||||
* @param pos 起始偏移位置
|
||||
* @param str 比较字符串
|
||||
* @param num 比较字数
|
||||
* @return <0 我方小
|
||||
* @return 0 等同
|
||||
* @return >0 我方大
|
||||
*/
|
||||
const int Comp(const int pos,const T *str,const int num)const
|
||||
const int Comp(const uint pos,const T *str,const uint num)const
|
||||
{
|
||||
if(!str)
|
||||
return(length-pos);
|
||||
@@ -294,7 +351,7 @@ namespace hgl
|
||||
* @return 0 等同
|
||||
* @return >0 我方大
|
||||
*/
|
||||
const int CaseComp(const T &str)const
|
||||
const int CaseComp(const T *str)const
|
||||
{
|
||||
return hgl::stricmp(buffer,length,str,hgl::strlen(str));
|
||||
}
|
||||
@@ -306,7 +363,7 @@ namespace hgl
|
||||
* @return 0 等同
|
||||
* @return >0 我方大
|
||||
*/
|
||||
const int CaseComp(const SelfClass &sc,const int num)const
|
||||
const int CaseComp(const SelfClass &sc,const uint num)const
|
||||
{
|
||||
return hgl::stricmp(buffer,length,sc.buffer,num);
|
||||
}
|
||||
@@ -318,12 +375,25 @@ namespace hgl
|
||||
* @return 0 等同
|
||||
* @return >0 我方大
|
||||
*/
|
||||
const int CaseComp(const T &str,const int num)const
|
||||
const int CaseComp(const T *str,const uint num)const
|
||||
{
|
||||
return hgl::stricmp(buffer,length,str,num);
|
||||
}
|
||||
|
||||
bool Insert(int pos,const T *istr,int len) ///<插入一个字符串
|
||||
/**
|
||||
* 和那一个字符串进行比较指字长度的字符,英文不区分大小写
|
||||
* @param pos 起始偏移位置
|
||||
* @param str 比较字符串
|
||||
* @return <0 我方小
|
||||
* @return 0 等同
|
||||
* @return >0 我方大
|
||||
*/
|
||||
const int CaseComp(const uint pos,const T *str,const uint num)const
|
||||
{
|
||||
return hgl::stricmp(buffer+pos,length-pos,str,num);
|
||||
}
|
||||
|
||||
bool Insert(const uint pos,const T *istr,int len) ///<插入一个字符串
|
||||
{
|
||||
if(!istr||!*istr)
|
||||
return(false);
|
||||
@@ -335,7 +405,7 @@ namespace hgl
|
||||
|
||||
if(pos<0||pos>length||len<=0)return(false);
|
||||
|
||||
const int need_length=length+len+1;
|
||||
const uint need_length=length+len+1;
|
||||
|
||||
if(need_length>malloc_length)
|
||||
{
|
||||
@@ -369,16 +439,16 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Insert(int pos,const T &ch ){return Insert(pos, &ch, 1 );}
|
||||
bool Insert(int pos,const T *str ){return Insert(pos, str, hgl::strlen(str));}
|
||||
bool Insert(int pos,const SelfClass &str){return Insert(pos, str.c_str(),str.GetLength() );}
|
||||
bool Insert(uint pos,const T &ch ){return Insert(pos, &ch, 1 );}
|
||||
bool Insert(uint pos,const T *str ){return Insert(pos, str, hgl::strlen(str));}
|
||||
bool Insert(uint pos,const SelfClass &str){return Insert(pos, str.c_str(),str.GetLength() );}
|
||||
|
||||
bool Append(const T &ch ){return Insert(length, &ch, 1 );}
|
||||
bool Append(const T *str,const int len ){return Insert(length, str, len );}
|
||||
bool Append(const T *str ){return Insert(length, str, hgl::strlen(str));}
|
||||
bool Append(const SelfClass &str ){return Insert(length, str.c_str(),str.GetLength() );}
|
||||
|
||||
bool Delete(int pos,int num) ///<删除指定字符
|
||||
bool Delete(uint pos,int num) ///<删除指定字符
|
||||
{
|
||||
if(pos<0||pos>=length||num<0)return(false);
|
||||
|
||||
@@ -417,7 +487,7 @@ namespace hgl
|
||||
return ClipLeft(length-num);
|
||||
}
|
||||
|
||||
bool Clip(int pos,int num)
|
||||
bool Clip(uint pos,int num)
|
||||
{
|
||||
if(pos<0||pos>length
|
||||
||num<0||pos+num>length)
|
||||
@@ -472,7 +542,7 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool Write(int pos,const SelfClass &str)
|
||||
bool Write(uint pos,const SelfClass &str)
|
||||
{
|
||||
if(pos<0||pos>length)
|
||||
return(false);
|
||||
|
Reference in New Issue
Block a user