diff --git a/build_linux64/libamsstring4.linux64.a b/build_linux64/libamsstring4.linux64.a index c6cf565..5c9e1d8 100644 Binary files a/build_linux64/libamsstring4.linux64.a and b/build_linux64/libamsstring4.linux64.a differ diff --git a/build_linux64/objstore/amsstring4_class.o b/build_linux64/objstore/amsstring4_class.o index 277400e..5b485c7 100644 Binary files a/build_linux64/objstore/amsstring4_class.o and b/build_linux64/objstore/amsstring4_class.o differ diff --git a/build_linux64/objstore/amsstring4_convenience1.o b/build_linux64/objstore/amsstring4_convenience1.o index 09f4649..838ff70 100644 Binary files a/build_linux64/objstore/amsstring4_convenience1.o and b/build_linux64/objstore/amsstring4_convenience1.o differ diff --git a/include/amsstring4/amsstring4.hpp b/include/amsstring4/amsstring4.hpp index 07322a7..1460803 100644 --- a/include/amsstring4/amsstring4.hpp +++ b/include/amsstring4/amsstring4.hpp @@ -103,28 +103,35 @@ public: void append(const ams_chartype *other); void append(const ams_chartype other); - amsstring operator+(const amsstring &other); - const amsstring operator+(const amsstring &other) const; - amsstring operator+(const ams_chartype *other); - const amsstring operator+(const ams_chartype *other) const; - amsstring operator+(const ams_chartype other); - const amsstring operator+(const ams_chartype other) const; + amsstring operator+(const amsstring &other) const; + amsstring operator+(const ams_chartype *other) const; + amsstring operator+(const ams_chartype other) const; //Find 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 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 int sprintf(int bufflen, const ams_chartype *formatstring, ...); void tolower(); void toupper(); + amsstring lower() const; + amsstring upper() const; - bool isvalidnumber(); - double strtonum(); + bool isvalidnumber() const; + double strtonum() const; //updated convenience functions as class members + //todo + }; //needs work diff --git a/src/amsstring4/amsstring4_class.cpp b/src/amsstring4/amsstring4_class.cpp index 2af8e14..c38044b 100644 --- a/src/amsstring4/amsstring4_class.cpp +++ b/src/amsstring4/amsstring4_class.cpp @@ -779,6 +779,17 @@ namespace ams } return; } + + amsstring amsstring::lower() const + { + amsstring ret = *this; + int I; + for(I=0;Icstring); } - - void splitlines(amsstring *s, std::vector *lns) - { - int I,I1,I2; - amsstring q; - int mode; - ams_chartype c; - - lns->resize(0); - - I1 = 0; - I = 0; - mode = 0; - while(Isize()) - { - 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 *lns) { int I,I1,I2; @@ -942,106 +915,7 @@ namespace ams return; } - /* - void splitlines(amsstring *s, std::vector *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(Ilength) - { - 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(0,ind2); - s->substring(ind1,ind2+1,&q); - lns->push_back(q); - ind1 = I+1; - ind2 = I+1; - ind1 = ams::min(s->length,ind1); - ind2 = ams::min(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(0,ind2); - s->substring(ind1,ind2+1,&q); - lns->push_back(q); - ind1 = I+1; - ind2 = I+1; - ind1 = ams::min(s->length,ind1); - ind2 = ams::min(s->length,ind2); - mode = 0; - } - I = I + 1; - } - if(ind1length) - { - s->substring(ind1,s->length+1,&q); - lns->push_back(q); - } - - return; - } - */ - - // void split(const amsstring *s, const ams_chartype delimitchar, std::vector *lns) - // { - // amsstring q; - // lns->resize(0); - - - // int I = 0; - // int ind1; - // int ind2; - // //int cs; - // ind1 = 0; - // ams_chartype c; - // while(Ilength) - // { - // c = s->cstring[I]; - // //cs = 0; - // if(c==delimitchar) - // { - // ind2 = I; - // ind2 = max(0,ind2); - // s->substring(ind1,ind2,&q); - // lns->push_back(q); - // ind1 = I+1; - // ind2 = I+1; - // ind1 = min(s->length,ind1); - // ind2 = min(s->length,ind2); - // } - - // I = I + 1; - // } - // if(ind1length&&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 *lns) { @@ -1082,84 +956,6 @@ namespace ams return; } - // void split(const amsstring *s, const ams_chartype *delimitstr, std::vector *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(Isize()) - // { - // 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(ind1,s->size()); - // ind1 = max(ind1,0); - // ind2 = min(ind2,s->size()); - // ind2 = max(ind2,0); - // ind2 = max(ind2,ind1); - - // s->substring(ind1,ind2,&q); - // lns->push_back(q); - - // ind1 = I + 1; - // ind2 = I + 1; - // cnt = 0; - // } - // I = I + 1; - // } - - // if(ind1size()) - // { - // 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 *lns) { amsstring q; @@ -1238,63 +1034,12 @@ namespace ams return; } - // void split(const amsstring *s, amsstring *delimitstr, std::vector *lns) - // { - // split(s,delimitstr->cstring,lns); - // return; - // } - void split(const amsstring *s, amsstring *delimitstr, ams::amsarray *lns) { split(s,delimitstr->cstring,lns); return; } - - // void splitwhitespace(const amsstring *s, std::vector *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(0,ind1); - // } - // if((isspace(c)||c==' '||c=='\t'||c=='\0')&&mode==1) - // { - // mode = 0; - // ind2 = I; - // ind2 = ams::min(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 *lns) { int I; @@ -1520,7 +1265,7 @@ namespace ams return ret; } - amsstring amsstring::operator+(const amsstring &other) + amsstring amsstring::operator+(const amsstring &other) const { amsstring ret; amsstring q1 = *this; @@ -1531,18 +1276,7 @@ namespace ams return ret; } - const amsstring amsstring::operator+(const amsstring &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 amsstring::operator+(const ams_chartype *other) const { amsstring ret; amsstring q1 = *this; @@ -1552,27 +1286,7 @@ namespace ams return ret; } - 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 amsstring::operator+(const ams_chartype other) const { amsstring ret; amsstring q1 = *this; @@ -1581,6 +1295,7 @@ namespace ams ret.append(other); return ret; } + }; \ No newline at end of file diff --git a/src/amsstring4/amsstring4_convenience1.cpp b/src/amsstring4/amsstring4_convenience1.cpp index b770561..632a82a 100644 --- a/src/amsstring4/amsstring4_convenience1.cpp +++ b/src/amsstring4/amsstring4_convenience1.cpp @@ -3,16 +3,236 @@ namespace ams { +//Updated convenience functions: updated for a more python style amsarray splitlines(const amsstring &s) { amsarray 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 split(const amsstring &s, const ams_chartype delimitchar) { amsarray ret; + amsstring q; + ret.resize(0); + + + int I = 0; + int ind1; + int ind2; + //int cs; + ind1 = 0; + ams_chartype c; + while(I(0,ind2); + s.substring(ind1,ind2,&q); + ret.push_back(q); + ind1 = I+1; + ind2 = I+1; + ind1 = min(s.length,ind1); + ind2 = min(s.length,ind2); + } + + I = I + 1; + } + if(ind1 split(const amsstring &s, const ams_chartype *delimitstr) +{ + amsarray 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=N) + { + //cut string from (ind1,ind2) + cs = 0; + + ind1 = min(ind1,s.size()); + ind1 = max(ind1,0); + ind2 = min(ind2,s.size()); + ind2 = max(ind2,0); + ind2 = max(ind2,ind1); + + s.substring(ind1,ind2,&q); + ret.push_back(q); + + ind1 = I + 1; + ind2 = I + 1; + cnt = 0; + } + I = I + 1; + } + + if(ind10 + 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 splitfirst(const amsstring &s, const ams_chartype delimitchar) +{ + amsarray 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 splitfirst(const amsstring &s, const ams_chartype *delimitstr) +{ + amsarray 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; } @@ -21,6 +241,43 @@ amsarray splitwhitespace(const amsstring &s) { amsarray 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(0,ind1); + } + if((isspace(c)||c==' '||c=='\t'||c=='\0')&&mode==1) + { + mode = 0; + ind2 = I; + ind2 = ams::min(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; } @@ -38,6 +295,8 @@ amsstring stripallwhitespace(const amsstring &s) 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 splitext(const amsstring &s) { amsarray ret; @@ -45,6 +304,8 @@ amsarray splitext(const amsstring &s) 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 splitpath(const amsstring &s) { amsarray ret; @@ -60,4 +321,11 @@ amsstring select_between(const amsstring &s, const ams_chartype delimitleft, con return ret; } +amsstring concatenate(const amsarray &slist) +{ + amsstring ret; + + return ret; +} + };//end namespace ams \ No newline at end of file