Added possibility to strip left and right to strip_edges (#4594)
(cherry picked from commit 49c473bb36
)
This commit is contained in:
parent
6d50ccfd32
commit
c575f31d5d
|
@ -2867,25 +2867,29 @@ CharType String::ord_at(int p_idx) const {
|
||||||
return operator[](p_idx);
|
return operator[](p_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
String String::strip_edges() const {
|
String String::strip_edges(bool left, bool right) const {
|
||||||
|
|
||||||
int len=length();
|
int len=length();
|
||||||
int beg=0,end=len;
|
int beg=0,end=len;
|
||||||
|
|
||||||
for (int i=0;i<length();i++) {
|
if(left) {
|
||||||
|
for (int i=0;i<len;i++) {
|
||||||
|
|
||||||
if (operator[](i)<=32)
|
if (operator[](i)<=32)
|
||||||
beg++;
|
beg++;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=(int)(length()-1);i>=0;i--) {
|
if(right) {
|
||||||
|
for (int i=(int)(len-1);i>=0;i--) {
|
||||||
|
|
||||||
if (operator[](i)<=32)
|
if (operator[](i)<=32)
|
||||||
end--;
|
end--;
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (beg==0 && end==len)
|
if (beg==0 && end==len)
|
||||||
|
|
|
@ -169,7 +169,7 @@ public:
|
||||||
|
|
||||||
String left(int p_pos) const;
|
String left(int p_pos) const;
|
||||||
String right(int p_pos) const;
|
String right(int p_pos) const;
|
||||||
String strip_edges() const;
|
String strip_edges(bool left = true, bool right = true) const;
|
||||||
String strip_escapes() const;
|
String strip_escapes() const;
|
||||||
String extension() const;
|
String extension() const;
|
||||||
String basename() const;
|
String basename() const;
|
||||||
|
|
|
@ -256,7 +256,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
|
||||||
VCALL_LOCALMEM0R(String,to_lower);
|
VCALL_LOCALMEM0R(String,to_lower);
|
||||||
VCALL_LOCALMEM1R(String,left);
|
VCALL_LOCALMEM1R(String,left);
|
||||||
VCALL_LOCALMEM1R(String,right);
|
VCALL_LOCALMEM1R(String,right);
|
||||||
VCALL_LOCALMEM0R(String,strip_edges);
|
VCALL_LOCALMEM2R(String,strip_edges);
|
||||||
VCALL_LOCALMEM0R(String,extension);
|
VCALL_LOCALMEM0R(String,extension);
|
||||||
VCALL_LOCALMEM0R(String,basename);
|
VCALL_LOCALMEM0R(String,basename);
|
||||||
VCALL_LOCALMEM1R(String,plus_file);
|
VCALL_LOCALMEM1R(String,plus_file);
|
||||||
|
@ -1275,7 +1275,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
|
||||||
|
|
||||||
ADDFUNC1(STRING,STRING,String,left,INT,"pos",varray());
|
ADDFUNC1(STRING,STRING,String,left,INT,"pos",varray());
|
||||||
ADDFUNC1(STRING,STRING,String,right,INT,"pos",varray());
|
ADDFUNC1(STRING,STRING,String,right,INT,"pos",varray());
|
||||||
ADDFUNC0(STRING,STRING,String,strip_edges,varray());
|
ADDFUNC2(STRING,STRING,String,strip_edges,BOOL,"left",BOOL,"right",varray(true,true));
|
||||||
ADDFUNC0(STRING,STRING,String,extension,varray());
|
ADDFUNC0(STRING,STRING,String,extension,varray());
|
||||||
ADDFUNC0(STRING,STRING,String,basename,varray());
|
ADDFUNC0(STRING,STRING,String,basename,varray());
|
||||||
ADDFUNC1(STRING,STRING,String,plus_file,STRING,"file",varray());
|
ADDFUNC1(STRING,STRING,String,plus_file,STRING,"file",varray());
|
||||||
|
|
Loading…
Reference in New Issue