updating convenience functions, const
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -103,28 +103,35 @@ public:
|
|||||||
void append(const ams_chartype *other);
|
void append(const ams_chartype *other);
|
||||||
void append(const ams_chartype other);
|
void append(const ams_chartype other);
|
||||||
|
|
||||||
amsstring operator+(const amsstring &other);
|
amsstring operator+(const amsstring &other) const;
|
||||||
const amsstring operator+(const amsstring &other) const;
|
amsstring operator+(const ams_chartype *other) const;
|
||||||
amsstring operator+(const ams_chartype *other);
|
amsstring operator+(const ams_chartype other) const;
|
||||||
const amsstring operator+(const ams_chartype *other) const;
|
|
||||||
amsstring operator+(const ams_chartype other);
|
|
||||||
const amsstring operator+(const ams_chartype other) const;
|
|
||||||
|
|
||||||
//Find
|
//Find
|
||||||
int find(const amsstring findstr, const int indstart=0, const bool casesens=1) const;
|
int find(const amsstring findstr, const int indstart=0, const bool casesens=1) const;
|
||||||
int find(const ams_chartype *findstr, const int indstart=0, const bool casesens=1) const;
|
int find(const ams_chartype *findstr, const int indstart=0, const bool casesens=1) const;
|
||||||
int find(const ams_chartype c, const int indstart=0, const bool casesens=1) const;
|
int find(const ams_chartype c, const int indstart=0, const bool casesens=1) const;
|
||||||
|
|
||||||
|
//todo
|
||||||
|
// finds first instance starting from length-indstart-1 from the right
|
||||||
|
int findright(const amsstring findstr, const int indstart=0, const bool casesens=1) const;
|
||||||
|
int findright(const ams_chartype *findstr, const int indstart=0, const bool casesens=1) const;
|
||||||
|
int findright(const ams_chartype c, const int indstart=0, const bool casesens=1) const;
|
||||||
|
|
||||||
//formatted input
|
//formatted input
|
||||||
int sprintf(int bufflen, const ams_chartype *formatstring, ...);
|
int sprintf(int bufflen, const ams_chartype *formatstring, ...);
|
||||||
|
|
||||||
void tolower();
|
void tolower();
|
||||||
void toupper();
|
void toupper();
|
||||||
|
amsstring lower() const;
|
||||||
|
amsstring upper() const;
|
||||||
|
|
||||||
bool isvalidnumber();
|
bool isvalidnumber() const;
|
||||||
double strtonum();
|
double strtonum() const;
|
||||||
|
|
||||||
//updated convenience functions as class members
|
//updated convenience functions as class members
|
||||||
|
//todo
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//needs work
|
//needs work
|
||||||
|
|||||||
@ -779,6 +779,17 @@ namespace ams
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amsstring amsstring::lower() const
|
||||||
|
{
|
||||||
|
amsstring ret = *this;
|
||||||
|
int I;
|
||||||
|
for(I=0;I<length;I++)
|
||||||
|
{
|
||||||
|
ret.cstring[I] = (ams_chartype) ams::tolower(ret.cstring[I]);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void amsstring::toupper()
|
void amsstring::toupper()
|
||||||
{
|
{
|
||||||
@ -789,6 +800,17 @@ namespace ams
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amsstring amsstring::upper() const
|
||||||
|
{
|
||||||
|
amsstring ret = *this;
|
||||||
|
int I;
|
||||||
|
for(I=0;I<length;I++)
|
||||||
|
{
|
||||||
|
ret.cstring[I] = (ams_chartype) ams::toupper(ret.cstring[I]);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int amsstring::sprintf(int bufflen, const ams_chartype *formatstring, ...)
|
int amsstring::sprintf(int bufflen, const ams_chartype *formatstring, ...)
|
||||||
{
|
{
|
||||||
@ -815,7 +837,7 @@ namespace ams
|
|||||||
}
|
}
|
||||||
|
|
||||||
//also returns true for nan
|
//also returns true for nan
|
||||||
bool amsstring::isvalidnumber()
|
bool amsstring::isvalidnumber() const
|
||||||
{
|
{
|
||||||
bool ret = 0;
|
bool ret = 0;
|
||||||
double d;
|
double d;
|
||||||
@ -840,60 +862,11 @@ namespace ams
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
double amsstring::strtonum()
|
double amsstring::strtonum() const
|
||||||
{
|
{
|
||||||
return amsstrtonum(this->cstring);
|
return amsstrtonum(this->cstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void splitlines(amsstring *s, std::vector<amsstring> *lns)
|
|
||||||
{
|
|
||||||
int I,I1,I2;
|
|
||||||
amsstring q;
|
|
||||||
int mode;
|
|
||||||
ams_chartype c;
|
|
||||||
|
|
||||||
lns->resize(0);
|
|
||||||
|
|
||||||
I1 = 0;
|
|
||||||
I = 0;
|
|
||||||
mode = 0;
|
|
||||||
while(I<s->size())
|
|
||||||
{
|
|
||||||
c = s->at(I);
|
|
||||||
if(mode==0 && c==ams_char_cr)
|
|
||||||
{
|
|
||||||
mode=1;
|
|
||||||
I2 = I;
|
|
||||||
}
|
|
||||||
else if(mode==0 && c==ams_char_lf)
|
|
||||||
{
|
|
||||||
mode = 0;
|
|
||||||
I2 = I;
|
|
||||||
s->substring(I1,I2,&q);
|
|
||||||
lns->push_back(q);
|
|
||||||
I1 = I+1;
|
|
||||||
}
|
|
||||||
else if(mode==1 && c==ams_char_lf)
|
|
||||||
{
|
|
||||||
mode = 0;
|
|
||||||
s->substring(I1,I2,&q);
|
|
||||||
lns->push_back(q);
|
|
||||||
I1 = I+1;
|
|
||||||
}
|
|
||||||
else if(mode==1)
|
|
||||||
{
|
|
||||||
mode = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
I = I + 1;
|
|
||||||
}
|
|
||||||
s->substring(I1,s->length,&q);
|
|
||||||
lns->push_back(q);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void splitlines(const amsstring *s, ams::amsarray<amsstring> *lns)
|
void splitlines(const amsstring *s, ams::amsarray<amsstring> *lns)
|
||||||
{
|
{
|
||||||
int I,I1,I2;
|
int I,I1,I2;
|
||||||
@ -942,106 +915,7 @@ namespace ams
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void splitlines(amsstring *s, std::vector<amsstring> *lns)
|
|
||||||
{
|
|
||||||
//windows uses \r\n, linux uses \n as a line delimiter
|
|
||||||
int I;
|
|
||||||
amsstring q;
|
|
||||||
lns->resize(0);
|
|
||||||
int ind1 = 0;
|
|
||||||
int ind2 = 0;
|
|
||||||
int mode = 0;
|
|
||||||
int cs;
|
|
||||||
I = 0;
|
|
||||||
ams_chartype c;
|
|
||||||
|
|
||||||
|
|
||||||
while(I<s->length)
|
|
||||||
{
|
|
||||||
c = s->cstring[I];
|
|
||||||
cs = 0; //has the character been 'consumed' by the state machine?
|
|
||||||
if(c=='\n'&&mode==0&&cs==0)
|
|
||||||
{
|
|
||||||
|
|
||||||
cs = 1;
|
|
||||||
ind2 = I-1;
|
|
||||||
ind2 = ams::max<int>(0,ind2);
|
|
||||||
s->substring(ind1,ind2+1,&q);
|
|
||||||
lns->push_back(q);
|
|
||||||
ind1 = I+1;
|
|
||||||
ind2 = I+1;
|
|
||||||
ind1 = ams::min<int>(s->length,ind1);
|
|
||||||
ind2 = ams::min<int>(s->length,ind2);
|
|
||||||
}
|
|
||||||
if(c=='\r'&&mode==0&&cs==0)
|
|
||||||
{
|
|
||||||
cs = 1;
|
|
||||||
mode = 1;
|
|
||||||
}
|
|
||||||
if(c=='\n'&&mode==1&&cs==0)
|
|
||||||
{
|
|
||||||
cs = 1;
|
|
||||||
ind2 = I-2;
|
|
||||||
ind2 = ams::max<int>(0,ind2);
|
|
||||||
s->substring(ind1,ind2+1,&q);
|
|
||||||
lns->push_back(q);
|
|
||||||
ind1 = I+1;
|
|
||||||
ind2 = I+1;
|
|
||||||
ind1 = ams::min<int>(s->length,ind1);
|
|
||||||
ind2 = ams::min<int>(s->length,ind2);
|
|
||||||
mode = 0;
|
|
||||||
}
|
|
||||||
I = I + 1;
|
|
||||||
}
|
|
||||||
if(ind1<s->length)
|
|
||||||
{
|
|
||||||
s->substring(ind1,s->length+1,&q);
|
|
||||||
lns->push_back(q);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// void split(const amsstring *s, const ams_chartype delimitchar, std::vector<amsstring> *lns)
|
|
||||||
// {
|
|
||||||
// amsstring q;
|
|
||||||
// lns->resize(0);
|
|
||||||
|
|
||||||
|
|
||||||
// int I = 0;
|
|
||||||
// int ind1;
|
|
||||||
// int ind2;
|
|
||||||
// //int cs;
|
|
||||||
// ind1 = 0;
|
|
||||||
// ams_chartype c;
|
|
||||||
// while(I<s->length)
|
|
||||||
// {
|
|
||||||
// c = s->cstring[I];
|
|
||||||
// //cs = 0;
|
|
||||||
// if(c==delimitchar)
|
|
||||||
// {
|
|
||||||
// ind2 = I;
|
|
||||||
// ind2 = max<int>(0,ind2);
|
|
||||||
// s->substring(ind1,ind2,&q);
|
|
||||||
// lns->push_back(q);
|
|
||||||
// ind1 = I+1;
|
|
||||||
// ind2 = I+1;
|
|
||||||
// ind1 = min<int>(s->length,ind1);
|
|
||||||
// ind2 = min<int>(s->length,ind2);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// I = I + 1;
|
|
||||||
// }
|
|
||||||
// if(ind1<s->length&&s->cstring[ind1]!=delimitchar)
|
|
||||||
// {
|
|
||||||
// s->substring(ind1,s->length,&q);
|
|
||||||
// lns->push_back(q);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
void split(const amsstring *s, const ams_chartype delimitchar, ams::amsarray<amsstring> *lns)
|
void split(const amsstring *s, const ams_chartype delimitchar, ams::amsarray<amsstring> *lns)
|
||||||
{
|
{
|
||||||
@ -1082,84 +956,6 @@ namespace ams
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void split(const amsstring *s, const ams_chartype *delimitstr, std::vector<amsstring> *lns)
|
|
||||||
// {
|
|
||||||
// amsstring q;
|
|
||||||
// int I;
|
|
||||||
// int ind1,ind2;
|
|
||||||
// int cs;
|
|
||||||
// int cnt;
|
|
||||||
// ams_chartype c;
|
|
||||||
// int N = amsstring_strlen(delimitstr);
|
|
||||||
|
|
||||||
// if(lns!=NULL && delimitstr!=NULL)
|
|
||||||
// {
|
|
||||||
// if(N>0)
|
|
||||||
// {
|
|
||||||
// lns->resize(0);
|
|
||||||
|
|
||||||
// ind1 = 0;
|
|
||||||
// I = 0;
|
|
||||||
// cs = 0;
|
|
||||||
// cnt = 0;
|
|
||||||
// while(I<s->size())
|
|
||||||
// {
|
|
||||||
// c = s->at(I);
|
|
||||||
// if(cs==0 && c==delimitstr[cnt])
|
|
||||||
// {
|
|
||||||
// cs=1;
|
|
||||||
// ind2 = I;
|
|
||||||
// cnt = cnt+1;
|
|
||||||
// }
|
|
||||||
// else if(cs==1 && c==delimitstr[cnt])
|
|
||||||
// {
|
|
||||||
// cs=1;
|
|
||||||
// cnt = cnt+1;
|
|
||||||
// }
|
|
||||||
// else if(cs==1 && c!=delimitstr[cnt])
|
|
||||||
// {
|
|
||||||
// cs = 0;
|
|
||||||
// ind2 = ind1;
|
|
||||||
// cnt = 0;
|
|
||||||
// I = I - 1; //step back so you can evaluate this char again
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if(cnt>=N)
|
|
||||||
// {
|
|
||||||
// //cut string from (ind1,ind2)
|
|
||||||
// cs = 0;
|
|
||||||
|
|
||||||
// ind1 = min<int>(ind1,s->size());
|
|
||||||
// ind1 = max<int>(ind1,0);
|
|
||||||
// ind2 = min<int>(ind2,s->size());
|
|
||||||
// ind2 = max<int>(ind2,0);
|
|
||||||
// ind2 = max<int>(ind2,ind1);
|
|
||||||
|
|
||||||
// s->substring(ind1,ind2,&q);
|
|
||||||
// lns->push_back(q);
|
|
||||||
|
|
||||||
// ind1 = I + 1;
|
|
||||||
// ind2 = I + 1;
|
|
||||||
// cnt = 0;
|
|
||||||
// }
|
|
||||||
// I = I + 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if(ind1<s->size())
|
|
||||||
// {
|
|
||||||
// s->substring(ind1,s->size(),&q);
|
|
||||||
// lns->push_back(q);
|
|
||||||
// }
|
|
||||||
// } //N>0
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// lns->push_back(*s);
|
|
||||||
// }
|
|
||||||
// } //lns!=NULL
|
|
||||||
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
void split(const amsstring *s, const ams_chartype *delimitstr, ams::amsarray<amsstring> *lns)
|
void split(const amsstring *s, const ams_chartype *delimitstr, ams::amsarray<amsstring> *lns)
|
||||||
{
|
{
|
||||||
amsstring q;
|
amsstring q;
|
||||||
@ -1238,63 +1034,12 @@ namespace ams
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void split(const amsstring *s, amsstring *delimitstr, std::vector<amsstring> *lns)
|
|
||||||
// {
|
|
||||||
// split(s,delimitstr->cstring,lns);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
void split(const amsstring *s, amsstring *delimitstr, ams::amsarray<amsstring> *lns)
|
void split(const amsstring *s, amsstring *delimitstr, ams::amsarray<amsstring> *lns)
|
||||||
{
|
{
|
||||||
split(s,delimitstr->cstring,lns);
|
split(s,delimitstr->cstring,lns);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// void splitwhitespace(const amsstring *s, std::vector<amsstring> *lns)
|
|
||||||
// {
|
|
||||||
// int I;
|
|
||||||
// int mode;
|
|
||||||
// ams_chartype c;
|
|
||||||
// int ind1 = 0;
|
|
||||||
// int ind2 = 0;
|
|
||||||
// I = 0;
|
|
||||||
// mode = 0;
|
|
||||||
// amsstring q;
|
|
||||||
// bool qf = 0;
|
|
||||||
|
|
||||||
// if(s!=NULL && lns!=NULL)
|
|
||||||
// {
|
|
||||||
// lns->resize(0);
|
|
||||||
// while(qf==0)
|
|
||||||
// {
|
|
||||||
// c = s->cstring[I];
|
|
||||||
// if(!(isspace(c)||c==' '||c=='\t')&&mode==0)
|
|
||||||
// {
|
|
||||||
// mode = 1;
|
|
||||||
// ind1 = I;
|
|
||||||
// ind1 = ams::max<int>(0,ind1);
|
|
||||||
// }
|
|
||||||
// if((isspace(c)||c==' '||c=='\t'||c=='\0')&&mode==1)
|
|
||||||
// {
|
|
||||||
// mode = 0;
|
|
||||||
// ind2 = I;
|
|
||||||
// ind2 = ams::min<int>(ind2,s->length);
|
|
||||||
// s->substring(ind1,ind2,&q);
|
|
||||||
// //printf("debug: %d, %s\n",I,q.cstring);
|
|
||||||
// lns->push_back(q);
|
|
||||||
// }
|
|
||||||
// if(I>=s->length)
|
|
||||||
// {
|
|
||||||
// qf = 1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// I = I + 1;
|
|
||||||
// }
|
|
||||||
// } //test null pointers
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
void splitwhitespace(const amsstring *s, ams::amsarray<amsstring> *lns)
|
void splitwhitespace(const amsstring *s, ams::amsarray<amsstring> *lns)
|
||||||
{
|
{
|
||||||
int I;
|
int I;
|
||||||
@ -1520,7 +1265,7 @@ namespace ams
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
amsstring amsstring::operator+(const amsstring &other)
|
amsstring amsstring::operator+(const amsstring &other) const
|
||||||
{
|
{
|
||||||
amsstring ret;
|
amsstring ret;
|
||||||
amsstring q1 = *this;
|
amsstring q1 = *this;
|
||||||
@ -1531,18 +1276,7 @@ namespace ams
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const amsstring amsstring::operator+(const amsstring &other) const
|
amsstring amsstring::operator+(const ams_chartype *other) const
|
||||||
{
|
|
||||||
amsstring ret;
|
|
||||||
amsstring q1 = *this;
|
|
||||||
amsstring q2 = other;
|
|
||||||
ret = "";
|
|
||||||
ret.append(q1);
|
|
||||||
ret.append(q2);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
amsstring amsstring::operator+(const ams_chartype *other)
|
|
||||||
{
|
{
|
||||||
amsstring ret;
|
amsstring ret;
|
||||||
amsstring q1 = *this;
|
amsstring q1 = *this;
|
||||||
@ -1552,27 +1286,7 @@ namespace ams
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const amsstring amsstring::operator+(const ams_chartype *other) const
|
amsstring amsstring::operator+(const ams_chartype other) const
|
||||||
{
|
|
||||||
amsstring ret;
|
|
||||||
amsstring q1 = *this;
|
|
||||||
ret = "";
|
|
||||||
ret.append(q1);
|
|
||||||
ret.append(other);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
amsstring amsstring::operator+(const ams_chartype other)
|
|
||||||
{
|
|
||||||
amsstring ret;
|
|
||||||
amsstring q1 = *this;
|
|
||||||
ret = "";
|
|
||||||
ret.append(q1);
|
|
||||||
ret.append(other);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
const amsstring amsstring::operator+(const ams_chartype other) const
|
|
||||||
{
|
{
|
||||||
amsstring ret;
|
amsstring ret;
|
||||||
amsstring q1 = *this;
|
amsstring q1 = *this;
|
||||||
@ -1581,6 +1295,7 @@ namespace ams
|
|||||||
ret.append(other);
|
ret.append(other);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -3,16 +3,236 @@
|
|||||||
namespace ams
|
namespace ams
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//Updated convenience functions: updated for a more python style
|
||||||
amsarray<amsstring> splitlines(const amsstring &s)
|
amsarray<amsstring> splitlines(const amsstring &s)
|
||||||
{
|
{
|
||||||
amsarray<amsstring> ret;
|
amsarray<amsstring> ret;
|
||||||
splitlines(&s,&ret);
|
|
||||||
|
int I,I1,I2;
|
||||||
|
amsstring q;
|
||||||
|
int mode;
|
||||||
|
ams_chartype c;
|
||||||
|
|
||||||
|
ret.resize(0);
|
||||||
|
|
||||||
|
I1 = 0;
|
||||||
|
I = 0;
|
||||||
|
mode = 0;
|
||||||
|
while(I<s.size())
|
||||||
|
{
|
||||||
|
c = s.at(I);
|
||||||
|
if(mode==0 && c==ams_char_cr)
|
||||||
|
{
|
||||||
|
mode=1;
|
||||||
|
I2 = I;
|
||||||
|
}
|
||||||
|
else if(mode==0 && c==ams_char_lf)
|
||||||
|
{
|
||||||
|
mode = 0;
|
||||||
|
I2 = I;
|
||||||
|
s.substring(I1,I2,&q);
|
||||||
|
ret.push_back(q);
|
||||||
|
I1 = I+1;
|
||||||
|
}
|
||||||
|
else if(mode==1 && c==ams_char_lf)
|
||||||
|
{
|
||||||
|
mode = 0;
|
||||||
|
s.substring(I1,I2,&q);
|
||||||
|
ret.push_back(q);
|
||||||
|
I1 = I+1;
|
||||||
|
}
|
||||||
|
else if(mode==1)
|
||||||
|
{
|
||||||
|
mode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
I = I + 1;
|
||||||
|
}
|
||||||
|
s.substring(I1,s.length,&q);
|
||||||
|
ret.push_back(q);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
amsarray<amsstring> split(const amsstring &s, const ams_chartype delimitchar)
|
amsarray<amsstring> split(const amsstring &s, const ams_chartype delimitchar)
|
||||||
{
|
{
|
||||||
amsarray<amsstring> ret;
|
amsarray<amsstring> ret;
|
||||||
|
amsstring q;
|
||||||
|
ret.resize(0);
|
||||||
|
|
||||||
|
|
||||||
|
int I = 0;
|
||||||
|
int ind1;
|
||||||
|
int ind2;
|
||||||
|
//int cs;
|
||||||
|
ind1 = 0;
|
||||||
|
ams_chartype c;
|
||||||
|
while(I<s.length)
|
||||||
|
{
|
||||||
|
c = s.cstring[I];
|
||||||
|
//cs = 0;
|
||||||
|
if(c==delimitchar)
|
||||||
|
{
|
||||||
|
ind2 = I;
|
||||||
|
ind2 = max<int>(0,ind2);
|
||||||
|
s.substring(ind1,ind2,&q);
|
||||||
|
ret.push_back(q);
|
||||||
|
ind1 = I+1;
|
||||||
|
ind2 = I+1;
|
||||||
|
ind1 = min<int>(s.length,ind1);
|
||||||
|
ind2 = min<int>(s.length,ind2);
|
||||||
|
}
|
||||||
|
|
||||||
|
I = I + 1;
|
||||||
|
}
|
||||||
|
if(ind1<s.length&&s.cstring[ind1]!=delimitchar)
|
||||||
|
{
|
||||||
|
s.substring(ind1,s.length,&q);
|
||||||
|
ret.push_back(q);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int amsstring_strlen(const ams_chartype *c)
|
||||||
|
{
|
||||||
|
int I;
|
||||||
|
if(c!=NULL)
|
||||||
|
{
|
||||||
|
I = 0;
|
||||||
|
while(c[I]!='\0')
|
||||||
|
{
|
||||||
|
I++;
|
||||||
|
}
|
||||||
|
return I;
|
||||||
|
//return strlen((const char*) c);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
amsarray<amsstring> split(const amsstring &s, const ams_chartype *delimitstr)
|
||||||
|
{
|
||||||
|
amsarray<amsstring> ret;
|
||||||
|
|
||||||
|
amsstring q;
|
||||||
|
int I;
|
||||||
|
int ind1,ind2;
|
||||||
|
int cs;
|
||||||
|
int cnt;
|
||||||
|
ams_chartype c;
|
||||||
|
int N = amsstring_strlen(delimitstr);
|
||||||
|
|
||||||
|
if(delimitstr!=NULL)
|
||||||
|
{
|
||||||
|
if(N>0)
|
||||||
|
{
|
||||||
|
ret.resize(0);
|
||||||
|
|
||||||
|
ind1 = 0;
|
||||||
|
I = 0;
|
||||||
|
cs = 0;
|
||||||
|
cnt = 0;
|
||||||
|
while(I<s.size())
|
||||||
|
{
|
||||||
|
c = s.at(I);
|
||||||
|
if(cs==0 && c==delimitstr[cnt])
|
||||||
|
{
|
||||||
|
cs=1;
|
||||||
|
ind2 = I;
|
||||||
|
cnt = cnt+1;
|
||||||
|
}
|
||||||
|
else if(cs==1 && c==delimitstr[cnt])
|
||||||
|
{
|
||||||
|
cs=1;
|
||||||
|
cnt = cnt+1;
|
||||||
|
}
|
||||||
|
else if(cs==1 && c!=delimitstr[cnt])
|
||||||
|
{
|
||||||
|
cs = 0;
|
||||||
|
ind2 = ind1;
|
||||||
|
cnt = 0;
|
||||||
|
I = I - 1; //step back so you can evaluate this char again
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cnt>=N)
|
||||||
|
{
|
||||||
|
//cut string from (ind1,ind2)
|
||||||
|
cs = 0;
|
||||||
|
|
||||||
|
ind1 = min<int>(ind1,s.size());
|
||||||
|
ind1 = max<int>(ind1,0);
|
||||||
|
ind2 = min<int>(ind2,s.size());
|
||||||
|
ind2 = max<int>(ind2,0);
|
||||||
|
ind2 = max<int>(ind2,ind1);
|
||||||
|
|
||||||
|
s.substring(ind1,ind2,&q);
|
||||||
|
ret.push_back(q);
|
||||||
|
|
||||||
|
ind1 = I + 1;
|
||||||
|
ind2 = I + 1;
|
||||||
|
cnt = 0;
|
||||||
|
}
|
||||||
|
I = I + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ind1<s.size())
|
||||||
|
{
|
||||||
|
s.substring(ind1,s.size(),&q);
|
||||||
|
ret.push_back(q);
|
||||||
|
}
|
||||||
|
} //N>0
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret.push_back(s);
|
||||||
|
}
|
||||||
|
} //ret!=NULL
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
//splits into two guaranteed pieces
|
||||||
|
//if a delimitchar or delimitstr is not encountered, the first piece will contain the entire string and the second will be ""
|
||||||
|
amsarray<amsstring> splitfirst(const amsstring &s, const ams_chartype delimitchar)
|
||||||
|
{
|
||||||
|
amsarray<amsstring> ret;
|
||||||
|
int ind;
|
||||||
|
|
||||||
|
ret.resize(2);
|
||||||
|
ind = s.find(delimitchar);
|
||||||
|
if(ind>=0)
|
||||||
|
{
|
||||||
|
ret[0] = s.substring(0,ind);
|
||||||
|
ret[1] = s.substring(ind+1,s.length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret[0] = s;
|
||||||
|
ret[1] = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
amsarray<amsstring> splitfirst(const amsstring &s, const ams_chartype *delimitstr)
|
||||||
|
{
|
||||||
|
amsarray<amsstring> ret;
|
||||||
|
int ind;
|
||||||
|
|
||||||
|
ret.resize(2);
|
||||||
|
|
||||||
|
ind = s.find(delimitstr);
|
||||||
|
if(ind>=0)
|
||||||
|
{
|
||||||
|
ret[0] = s.substring(0,ind);
|
||||||
|
ret[1] = s.substring(ind+amsstring_strlen(delimitstr),s.length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret[0] = s;
|
||||||
|
ret[1] = "";
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,6 +241,43 @@ amsarray<amsstring> splitwhitespace(const amsstring &s)
|
|||||||
{
|
{
|
||||||
amsarray<amsstring> ret;
|
amsarray<amsstring> ret;
|
||||||
|
|
||||||
|
int I;
|
||||||
|
int mode;
|
||||||
|
ams_chartype c;
|
||||||
|
int ind1 = 0;
|
||||||
|
int ind2 = 0;
|
||||||
|
I = 0;
|
||||||
|
mode = 0;
|
||||||
|
amsstring q;
|
||||||
|
bool qf = 0;
|
||||||
|
|
||||||
|
ret.resize(0);
|
||||||
|
while(qf==0)
|
||||||
|
{
|
||||||
|
c = s.cstring[I];
|
||||||
|
if(!(isspace(c)||c==' '||c=='\t')&&mode==0)
|
||||||
|
{
|
||||||
|
mode = 1;
|
||||||
|
ind1 = I;
|
||||||
|
ind1 = ams::max<int>(0,ind1);
|
||||||
|
}
|
||||||
|
if((isspace(c)||c==' '||c=='\t'||c=='\0')&&mode==1)
|
||||||
|
{
|
||||||
|
mode = 0;
|
||||||
|
ind2 = I;
|
||||||
|
ind2 = ams::min<int>(ind2,s.length);
|
||||||
|
s.substring(ind1,ind2,&q);
|
||||||
|
//printf("debug: %d, %s\n",I,q.cstring);
|
||||||
|
ret.push_back(q);
|
||||||
|
}
|
||||||
|
if(I>=s.length)
|
||||||
|
{
|
||||||
|
qf = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
I = I + 1;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +295,8 @@ amsstring stripallwhitespace(const amsstring &s)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//splits into two guaranteed pieces
|
||||||
|
//if an extension separator . is not encountered, the first piece will contain the entire string, the second ""
|
||||||
amsarray<amsstring> splitext(const amsstring &s)
|
amsarray<amsstring> splitext(const amsstring &s)
|
||||||
{
|
{
|
||||||
amsarray<amsstring> ret;
|
amsarray<amsstring> ret;
|
||||||
@ -45,6 +304,8 @@ amsarray<amsstring> splitext(const amsstring &s)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//splits into two guaranteed pieces
|
||||||
|
//if a path separator is not encountered, the second piece will contain the entire string, and the first ""
|
||||||
amsarray<amsstring> splitpath(const amsstring &s)
|
amsarray<amsstring> splitpath(const amsstring &s)
|
||||||
{
|
{
|
||||||
amsarray<amsstring> ret;
|
amsarray<amsstring> ret;
|
||||||
@ -60,4 +321,11 @@ amsstring select_between(const amsstring &s, const ams_chartype delimitleft, con
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amsstring concatenate(const amsarray<amsstring> &slist)
|
||||||
|
{
|
||||||
|
amsstring ret;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
};//end namespace ams
|
};//end namespace ams
|
||||||
Reference in New Issue
Block a user