add multi "strechar" functions,"BaseString::FindExcludeChar" functions.
This commit is contained in:
@@ -870,12 +870,14 @@ namespace hgl
|
|||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FindChar(const T ch)const{return FindChar(0,ch);} ///<返回当前字符串中指定字符开始的索引(从左至右)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在当前字符串中查找字符
|
* 在当前字符串中查找字符
|
||||||
* @param pos 起始查找位置
|
* @param pos 起始查找位置
|
||||||
* @param ch 要查找的字符,可以是多个,找到任意一个就算
|
* @param ch 要查找的字符,可以是多个,找到任意一个就算
|
||||||
*/
|
*/
|
||||||
int FindChar(int pos,const BaseString<T> &ch)const ///<返回当前字符串中指定字符中的任意一个开始的索引(从左至右)
|
int FindChar(int pos,const BaseString<T> &ch)const ///<返回当前字符串中指定字符(多个任选一)的索引(从左至右)
|
||||||
{
|
{
|
||||||
if(!data.valid())
|
if(!data.valid())
|
||||||
return(-1);
|
return(-1);
|
||||||
@@ -888,7 +890,7 @@ namespace hgl
|
|||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FindChar(const T ch)const{return FindChar(0,ch);} ///<返回当前字符串中指定字符开始的索引(从左至右)
|
int FindChar(const BaseString<T> &ch)const{return FindChar(0,ch);} ///<返回当前字符串中指定字符(多个任选一)的索引(从左至右)
|
||||||
|
|
||||||
int FindRightChar(const T ch)const ///<返回当前字符串中指定字符开始的索引(从右至左)
|
int FindRightChar(const T ch)const ///<返回当前字符串中指定字符开始的索引(从右至左)
|
||||||
{
|
{
|
||||||
@@ -903,7 +905,7 @@ namespace hgl
|
|||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FindRightChar(const BaseString<T> &ch)const ///<返回当前字符串中指定字符开始的索引(从右至左)
|
int FindRightChar(const BaseString<T> &ch)const ///<返回当前字符串中指定字符(多个任选一)开始的索引(从右至左)
|
||||||
{
|
{
|
||||||
if(!data.valid())
|
if(!data.valid())
|
||||||
return(-1);
|
return(-1);
|
||||||
@@ -935,7 +937,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回当前字符串中指定字符开始的索引(从右至左)
|
* 返回当前字符串中指定字符(多个任选一)开始的索引(从右至左)
|
||||||
* @param off 从右至左跳过不查的字符个数
|
* @param off 从右至左跳过不查的字符个数
|
||||||
* @param ch 要查找的字符
|
* @param ch 要查找的字符
|
||||||
*/
|
*/
|
||||||
@@ -952,6 +954,46 @@ namespace hgl
|
|||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回当前字符串中排除指定字符外的第一个字符的索引
|
||||||
|
* @param pos 起始查找位置
|
||||||
|
* @param ch 要排除的字符
|
||||||
|
*/
|
||||||
|
int FindExcludeChar(const int pos,const T &ch)const
|
||||||
|
{
|
||||||
|
if(!data.valid())
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
const T *result=hgl::strechr(data->c_str()+pos,ch);
|
||||||
|
|
||||||
|
if(result)
|
||||||
|
return result-(data->c_str()+pos);
|
||||||
|
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int FindExcludeChar(const T &ch)const{return FindExcludeChar(ch);}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回当前字符串中排除指定字符外的第一个字符的索引
|
||||||
|
* @param pos 起始查找位置
|
||||||
|
* @param ch 要排除的字符
|
||||||
|
*/
|
||||||
|
int FindExcludeChar(const int pos,const BaseString<T> &ch)const
|
||||||
|
{
|
||||||
|
if(!data.valid())
|
||||||
|
return(-1);
|
||||||
|
|
||||||
|
const T *result=hgl::strechr(data->c_str()+pos,ch.c_str(),ch.Length());
|
||||||
|
|
||||||
|
if(result)
|
||||||
|
return result-(data->c_str()+pos);
|
||||||
|
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int FindExcludeChar(const BaseString &ch){return FindExcludeChar(0,ch);}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在整个字符串内,查找指定字符串
|
* 在整个字符串内,查找指定字符串
|
||||||
* @param str 要查找的字符串
|
* @param str 要查找的字符串
|
||||||
|
@@ -567,7 +567,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在字符串中查找某个字符,指定字符串最大长度
|
* 在字符串中查找多个字符中的任意一个,指定字符串最大长度
|
||||||
* @param str 字符串
|
* @param str 字符串
|
||||||
* @param ch 字符
|
* @param ch 字符
|
||||||
* @param n 字符串长度
|
* @param n 字符串长度
|
||||||
@@ -590,7 +590,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在字符串中查找某个字符
|
* 在字符串中查找多个字符中的任意一个
|
||||||
* @param str 字符串
|
* @param str 字符串
|
||||||
* @param ch 字符列表
|
* @param ch 字符列表
|
||||||
* @param ch_count 字符个数
|
* @param ch_count 字符个数
|
||||||
@@ -612,6 +612,74 @@ namespace hgl
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在字符串中查找排除指定字符外的第一个字符
|
||||||
|
* @param str 字符串
|
||||||
|
* @param ch 要排除的字符
|
||||||
|
* @return 查找到的位置指针
|
||||||
|
*/
|
||||||
|
template<typename TS,typename TC>
|
||||||
|
TS *strechr(TS *str,TC ch)
|
||||||
|
{
|
||||||
|
if(!str||!(*str)||ch==0)return(nullptr);
|
||||||
|
|
||||||
|
while(*str)
|
||||||
|
{
|
||||||
|
if(*str!=ch)
|
||||||
|
return(str);
|
||||||
|
else
|
||||||
|
++str;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在字符串中查找排除指定字符外的第一个字符,指定字符串最大长度
|
||||||
|
* @param str 字符串
|
||||||
|
* @param ch 要排除的字符
|
||||||
|
* @param n 字符串长度
|
||||||
|
* @return 查找到的位置指针
|
||||||
|
*/
|
||||||
|
template<typename TS,typename TC>
|
||||||
|
TS *strechr(TS *str,TC ch,int n)
|
||||||
|
{
|
||||||
|
if(!str||!(*str)||ch==0||n<=0)return(nullptr);
|
||||||
|
|
||||||
|
while(*str&&n--)
|
||||||
|
{
|
||||||
|
if(*str!=ch)
|
||||||
|
return(str);
|
||||||
|
else
|
||||||
|
++str;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在字符串中查找在字符串中查找排除指定字符外的第一个字符
|
||||||
|
* @param str 字符串
|
||||||
|
* @param ch 要排除的字符列表
|
||||||
|
* @param ch_count 字符个数
|
||||||
|
* @return 查找到的位置指针
|
||||||
|
*/
|
||||||
|
template<typename TS,typename TC>
|
||||||
|
TS *strechr(TS *str,TC *ch,const int ch_count)
|
||||||
|
{
|
||||||
|
if(!str||!(*str)||!ch||!(*ch)||ch_count<=0)return(nullptr);
|
||||||
|
|
||||||
|
while(*str)
|
||||||
|
{
|
||||||
|
if(!strchr(ch,*str,ch_count))
|
||||||
|
return(str);
|
||||||
|
|
||||||
|
++str;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在字符串中从结尾处开始查找某个字符
|
* 在字符串中从结尾处开始查找某个字符
|
||||||
* @param str 字符串
|
* @param str 字符串
|
||||||
|
Reference in New Issue
Block a user