diff --git a/build_linux64/libamsstring4.linux64.a b/build_linux64/libamsstring4.linux64.a index b3f7698..025bd53 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 be08aea..0916c57 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 06818fb..089b9fb 100644 Binary files a/build_linux64/objstore/amsstring4_convenience1.o and b/build_linux64/objstore/amsstring4_convenience1.o differ diff --git a/build_linux64/tests b/build_linux64/tests index eadb4dd..2574ac9 100644 Binary files a/build_linux64/tests and b/build_linux64/tests differ diff --git a/include/amsstring4/amsstring4.hpp b/include/amsstring4/amsstring4.hpp index 7c6e1ec..cd0d9c8 100644 --- a/include/amsstring4/amsstring4.hpp +++ b/include/amsstring4/amsstring4.hpp @@ -41,6 +41,12 @@ static const ams_chartype ams_char_nt = (ams_chartype) '\0'; //null terminator static const ams_chartype ams_char_dq = (ams_chartype) '"'; //doublequote static const ams_chartype ams_char_sq = (ams_chartype) '\''; //singlequote +ams_chartype tolower(ams_chartype c); +ams_chartype toupper(ams_chartype c); +bool amsstring_isspace(ams_chartype c); +int amsstring_strlen(const ams_chartype *c); +bool amsstring_ischarnumeric(const ams_chartype c); + class amsstring { @@ -191,12 +197,12 @@ amsstring select_between(const amsstring &s, const ams_chartype delimitleft, con //selects between the outermost set of delimitleft and delimitright strings //if delimitleft or delimitright strings are empty, selects the left or right end of the array -amsstring select_between(const amsstring &s, const ams_chartype *delimitleft, const ams_chartype *delimitright); // +amsstring select_between(const amsstring &s, const ams_chartype *delimitleft, const ams_chartype *delimitright); amsstring concatenate(const amsarray &slist); //adds \n between each line in the concatenated string -amsstring concat_lines(const amsarray &lns);// +amsstring concat_lines(const amsarray &lns); diff --git a/include/amsstring4/amsstring4_tests.hpp b/include/amsstring4/amsstring4_tests.hpp index 9795998..c26b76f 100644 --- a/include/amsstring4/amsstring4_tests.hpp +++ b/include/amsstring4/amsstring4_tests.hpp @@ -20,6 +20,7 @@ namespace ams void amsstring4_test_concatenation_operators(); void amsstring4_test_convenience1a(); + void amsstring4_test_convenience1b(); }; diff --git a/src/amsstring4/amsstring4_class.cpp b/src/amsstring4/amsstring4_class.cpp index f988166..1cb2ef8 100644 --- a/src/amsstring4/amsstring4_class.cpp +++ b/src/amsstring4/amsstring4_class.cpp @@ -3,7 +3,20 @@ namespace ams { - ams_chartype tolower(ams_chartype c) + //isspace() is locale dependent. For determinism's sake, I am going to implement my own checks. + /* Returns true for the 6 ASCII white-space characters: \t \n \v \f \r ' '. */ + bool amsstring_isspace(const ams_chartype c) + { + bool ret = 0; + //isspace(c)||c==' '||c=='\t'||c=='\n'||c=='\r'||c=='\f'||c=='\v'||(int)c==9||(int)c==10||(int)c==11||(int)c==12 + //ret = (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' || c == ' '); + + ret = ((c == '\t') || (c == '\n') || (c == '\v') || (c == '\f') || (c == '\r') || (c == ' ') || ((int)c==10) || ((int)c==11) || ((int)c==12) ); + + return ret; + } + + ams_chartype tolower(const ams_chartype c) { unsigned char c2 = (unsigned char) c; ams_chartype ret; @@ -18,7 +31,7 @@ namespace ams return ret; } - ams_chartype toupper(ams_chartype c) + ams_chartype toupper(const ams_chartype c) { unsigned char c2 = (unsigned char) c; ams_chartype ret; @@ -32,8 +45,18 @@ namespace ams } return ret; } + + //isspace() is locale dependent. For determinism's sake, I am going to implement my own checks. + //returns true if a character is of a type used forming a decimal number + bool amsstring_ischarnumeric(const ams_chartype c) + { + ams_chartype cl = ams::tolower(c); + bool ret = 0; + ret = ret || ( ((int)cl>=48) && ((int)cl<=57) ) || cl=='.' || cl=='e' || '-'; + return ret; + } - static int amsstring_strlen(const ams_chartype *c) + int amsstring_strlen(const ams_chartype *c) { int I; if(c!=NULL) @@ -1138,13 +1161,15 @@ namespace ams while(qf==0) { c = s->cstring[I]; - if(!(isspace(c)||c==' '||c=='\t')&&mode==0) + //if(!(isspace(c)||c==' '||c=='\t')&&mode==0) + if(!(amsstring_isspace(c))&&mode==0) { mode = 1; ind1 = I; ind1 = ams::max(0,ind1); } - if((isspace(c)||c==' '||c=='\t'||c=='\0')&&mode==1) + //if((isspace(c)||c==' '||c=='\t'||c=='\0')&&mode==1) + if((amsstring_isspace(c))&&mode==1) { mode = 0; ind2 = I; @@ -1179,7 +1204,8 @@ namespace ams for(I=0;Ilength;I++) { c = s->cstring[I]; - if(!(isspace(c)||c==' '||c=='\t')) + //if(!(isspace(c)||c==' '||c=='\t')) + if(!(amsstring_isspace(c))) { ind1 = I; break; @@ -1188,7 +1214,8 @@ namespace ams for(I=s->length-1;I>=0;I--) { c = s->cstring[I]; - if(!(isspace(c)||c==' '||c=='\t')) + //if(!(isspace(c)||c==' '||c=='\t')) + if(!(amsstring_isspace(c))) { ind2 = I+1; break; @@ -1219,7 +1246,8 @@ namespace ams for(I=0;Ilength;I++) { c = s->cstring[I]; - if(!(isspace(c)||c==' '||c=='\t'||c=='\n'||c=='\r'||c=='\f'||c=='\v'||(int)c==9||(int)c==10||(int)c==11||(int)c==12)) + //if(!(isspace(c)||c==' '||c=='\t'||c=='\n'||c=='\r'||c=='\f'||c=='\v'||(int)c==9||(int)c==10||(int)c==11||(int)c==12)) + if(!(amsstring_isspace(c))) { q.cstring[J] = s->cstring[I]; J = J + 1; diff --git a/src/amsstring4/amsstring4_convenience1.cpp b/src/amsstring4/amsstring4_convenience1.cpp index 651c703..05ca3ab 100644 --- a/src/amsstring4/amsstring4_convenience1.cpp +++ b/src/amsstring4/amsstring4_convenience1.cpp @@ -94,22 +94,22 @@ amsarray split(const amsstring &s, const ams_chartype delimitchar) 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; -} +// 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 split(const amsstring &s, const ams_chartype *delimitstr) { @@ -255,13 +255,15 @@ amsarray splitwhitespace(const amsstring &s) while(qf==0) { c = s.cstring[I]; - if(!(isspace(c)||c==' '||c=='\t')&&mode==0) + //if(!(isspace(c)||c==' '||c=='\t')&&mode==0) + if(!(amsstring_isspace(c))&&mode==0) { mode = 1; ind1 = I; ind1 = ams::max(0,ind1); } - if((isspace(c)||c==' '||c=='\t'||c=='\0')&&mode==1) + //if((isspace(c)||c==' '||c=='\t'||c=='\0')&&mode==1) + if((amsstring_isspace(c))&&mode==1) { mode = 0; ind2 = I; @@ -295,7 +297,8 @@ amsstring stripwhitespace(const amsstring &s) for(I=0;I=0;I--) { c = s.cstring[I]; - if(!(isspace(c)||c==' '||c=='\t')) + //if(!(isspace(c)||c==' '||c=='\t')) + if(!(amsstring_isspace(c))) { ind2 = I+1; break; @@ -335,7 +339,8 @@ amsstring stripallwhitespace(const amsstring &s) for(I=0;I0) + ind1 = s.find(delimitleft); + if(slen2>0) + ind2 = s.findright(delimitright); + + if(ind1<0) ind1=0; + if(ind2<0) ind2=s.length; + + ret = s.substring(ind1,ind2); + + return ret; +} + amsstring concatenate(const amsarray &slist) { amsstring ret; @@ -440,6 +471,60 @@ amsstring concatenate(const amsarray &slist) return ret; } +amsstring concat_lines(const amsarray &slist) +{ + amsstring ret; + amsstring s; + int I; + ret.resize(0); + for(I=0;I splitalphanum(const amsstring &s) +{ + amsarray sa; + int I0,I1,I; + int mode; + ams_chartype c; + amsstring s2; + + mode = 0; + for(I=0;I