add notcodechar,clipleft,clipright functions.

enhanced trimleft,trimright,trim functions.
This commit is contained in:
hyzboy 2020-09-11 15:40:31 +08:00
parent 512894f080
commit 7cf856b4ee

View File

@ -219,6 +219,15 @@ namespace hgl
return(isalnum(ch)||ch=='_');
}
/**
* (线)
*/
template<typename T>
const bool notcodechar(const T ch)
{
return(!iscodechar(ch));
}
/**
* BASE64编码字符
*/
@ -1108,17 +1117,18 @@ namespace hgl
}
/**
*
*
* @param src
* @param len
* @return delete[]
* @param len ()
* @param trimfunc (isspace)
* @return
*/
template<typename T>
const T *trimleft(const T *src,int &len)
const T *trimleft(const T *src,int &len,const bool (*trimfunc)(const T)=isspace<T>)
{
const T *p=src;
while(*p&&isspace(*p)&&len)
while(*p&&trimfunc(*p)&&len)
{
p++;
len--;
@ -1131,14 +1141,18 @@ namespace hgl
}
/**
*
*
* @param src
* @param len ()
* @param trimfunc (isspace)
* @return
*/
template<typename T>
const T *trimright(const T *src,int &len)
const T *trimright(const T *src,int &len,const bool (*trimfunc)(const T)=isspace<T>)
{
const T *p=src+len-1;
while(isspace(*p)&&len)
while(trimfunc(*p)&&len)
{
p--;
len--;
@ -1151,21 +1165,25 @@ namespace hgl
}
/**
*
*
* @param src
* @param len ()
* @param trimfunc (isspace)
* @return
*/
template<typename T>
const T *trim(const T *src,int &len)
const T *trim(const T *src,int &len,const bool (*trimfunc)(const T)=isspace<T>)
{
const T *sp=src;
const T *ep=src+len-1;
while(*sp&&isspace(*sp)&&len)
while(*sp&&trimfunc(*sp)&&len)
{
++sp;
--len;
}
while(isspace(*ep)&&len)
while(trimfunc(*ep)&&len)
{
--ep;
--len;
@ -1176,6 +1194,50 @@ namespace hgl
return sp;
}
/**
*
* @param src
* @param len ()
* @param clipfunc (isspace)
* @return
*/
template<typename T>
const T *clipleft(const T *src,int &len,const bool (*clipfunc)(const T)=isspace<T>)
{
const T *p=src;
while(*p&&!clipfunc(*p)&&p-src<=len)
p++;
if(p==src)
return(nullptr);
len=p-src;
return src;
}
/**
*
* @param src
* @param len ()
* @param clipfunc (isspace)
* @return
*/
template<typename T>
const T *clipright(const T *src,int &len,const bool (*clipfunc)(const T)=isspace<T>)
{
const T *p=src+len-1;
while(!clipfunc(*p)&&src-p<=len)
p--;
if(len<=0)
return(nullptr);
len=src+len-p-1;
return p+1;
}
/**
*