newconveniencefunctions1
This commit is contained in:
Binary file not shown.
Binary file not shown.
BIN
build_linux64/objstore/amsstring4_convenience1.o
Normal file
BIN
build_linux64/objstore/amsstring4_convenience1.o
Normal file
Binary file not shown.
Binary file not shown.
@ -38,6 +38,9 @@ static const ams_chartype ams_char_cr = (ams_chartype) '\r'; //carriage return
|
||||
static const ams_chartype ams_char_lf = (ams_chartype) '\n'; //newline
|
||||
static const ams_chartype ams_char_tb = (ams_chartype) '\t'; //tab
|
||||
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
|
||||
|
||||
|
||||
class amsstring
|
||||
{
|
||||
@ -120,24 +123,26 @@ public:
|
||||
|
||||
bool isvalidnumber();
|
||||
double strtonum();
|
||||
|
||||
//updated convenience functions as class members
|
||||
};
|
||||
|
||||
//needs work
|
||||
void splitlines(amsstring *s, std::vector<amsstring> *lns);
|
||||
void splitlines(amsstring *s, ams::amsarray<amsstring> *lns);
|
||||
//void splitlines(const amsstring *s, std::vector<amsstring> *lns);
|
||||
void splitlines(const amsstring *s, ams::amsarray<amsstring> *lns);
|
||||
|
||||
void split(amsstring *s, const ams_chartype delimitchar, std::vector<amsstring> *lns);
|
||||
void split(amsstring *s, const ams_chartype delimitchar, ams::amsarray<amsstring> *lns);
|
||||
//void split(const amsstring *s, const ams_chartype delimitchar, std::vector<amsstring> *lns);
|
||||
void split(const amsstring *s, const ams_chartype delimitchar, ams::amsarray<amsstring> *lns);
|
||||
|
||||
void split(amsstring *s, const ams_chartype *delimitstr, std::vector<amsstring> *lns);
|
||||
void split(amsstring *s, const ams_chartype *delimitstr, ams::amsarray<amsstring> *lns);
|
||||
//void split(const amsstring *s, const ams_chartype *delimitstr, std::vector<amsstring> *lns);
|
||||
void split(const amsstring *s, const ams_chartype *delimitstr, ams::amsarray<amsstring> *lns);
|
||||
|
||||
void split(amsstring *s, amsstring *delimitstr, std::vector<amsstring> *lns);
|
||||
void split(amsstring *s, amsstring *delimitstr, ams::amsarray<amsstring> *lns);
|
||||
//void split(const amsstring *s, amsstring *delimitstr, std::vector<amsstring> *lns);
|
||||
void split(const amsstring *s, amsstring *delimitstr, ams::amsarray<amsstring> *lns);
|
||||
|
||||
//splits a string, not counting whitespaces between non-whitespace characters
|
||||
void splitwhitespace(amsstring *s, std::vector<amsstring> *lns);
|
||||
void splitwhitespace(amsstring *s, ams::amsarray<amsstring> *lns);
|
||||
//void splitwhitespace(const amsstring *s, std::vector<amsstring> *lns);
|
||||
void splitwhitespace(const amsstring *s, ams::amsarray<amsstring> *lns);
|
||||
|
||||
//removes all whitespace characters '\t','\r','\n' included
|
||||
//to the left and right of the string (but not in the middle)
|
||||
@ -146,6 +151,37 @@ void stripwhitespace(amsstring *s);
|
||||
//completely removes all whitespace entirely
|
||||
void stripallwhitespace(amsstring *s);
|
||||
|
||||
|
||||
//Updated convenience functions: updated for a more python style
|
||||
amsarray<amsstring> splitlines(const amsstring &s);
|
||||
amsarray<amsstring> split(const amsstring &s, const ams_chartype delimitchar);
|
||||
amsarray<amsstring> split(const amsstring &s, const ams_chartype *delimitstr);
|
||||
|
||||
//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> splitfirst(const amsstring &s, const ams_chartype *delimitstr);
|
||||
|
||||
//splits a string, not counting whitespaces between non-whitespace characters
|
||||
amsarray<amsstring> splitwhitespace(const amsstring &s);
|
||||
amsstring stripwhitespace(const amsstring &s);
|
||||
amsstring stripallwhitespace(const amsstring &s);
|
||||
|
||||
//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);
|
||||
|
||||
//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);
|
||||
|
||||
//selects between the outermost set of delimitleft and delimitright chars
|
||||
amsstring select_between(const amsstring &s, const ams_chartype delimitleft, const ams_chartype delimitright);
|
||||
|
||||
amsstring concatenate(const amsarray<amsstring> &slist);
|
||||
|
||||
|
||||
|
||||
void freadline(FILE *fp, amsstring *s);
|
||||
void freadlines(FILE *fp, std::vector<amsstring> *lines);
|
||||
void fwritelines(FILE *fp, amsstring *s);
|
||||
|
||||
@ -894,7 +894,7 @@ namespace ams
|
||||
return;
|
||||
}
|
||||
|
||||
void splitlines(amsstring *s, ams::amsarray<amsstring> *lns)
|
||||
void splitlines(const amsstring *s, ams::amsarray<amsstring> *lns)
|
||||
{
|
||||
int I,I1,I2;
|
||||
amsstring q;
|
||||
@ -1004,7 +1004,46 @@ namespace ams
|
||||
}
|
||||
*/
|
||||
|
||||
void split(amsstring *s, const ams_chartype delimitchar, std::vector<amsstring> *lns)
|
||||
// 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)
|
||||
{
|
||||
amsstring q;
|
||||
lns->resize(0);
|
||||
@ -1043,46 +1082,85 @@ namespace ams
|
||||
return;
|
||||
}
|
||||
|
||||
void split(amsstring *s, const ams_chartype delimitchar, ams::amsarray<amsstring> *lns)
|
||||
{
|
||||
amsstring q;
|
||||
lns->resize(0);
|
||||
// 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
|
||||
// }
|
||||
|
||||
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);
|
||||
}
|
||||
// if(cnt>=N)
|
||||
// {
|
||||
// //cut string from (ind1,ind2)
|
||||
// cs = 0;
|
||||
|
||||
I = I + 1;
|
||||
}
|
||||
if(ind1<s->length&&s->cstring[ind1]!=delimitchar)
|
||||
{
|
||||
s->substring(ind1,s->length,&q);
|
||||
lns->push_back(q);
|
||||
}
|
||||
// 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);
|
||||
|
||||
return;
|
||||
}
|
||||
// s->substring(ind1,ind2,&q);
|
||||
// lns->push_back(q);
|
||||
|
||||
// ind1 = I + 1;
|
||||
// ind2 = I + 1;
|
||||
// cnt = 0;
|
||||
// }
|
||||
// I = I + 1;
|
||||
// }
|
||||
|
||||
void split(amsstring *s, const ams_chartype *delimitstr, std::vector<amsstring> *lns)
|
||||
// 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)
|
||||
{
|
||||
amsstring q;
|
||||
int I;
|
||||
@ -1160,142 +1238,64 @@ namespace ams
|
||||
return;
|
||||
}
|
||||
|
||||
void split(amsstring *s, const ams_chartype *delimitstr, ams::amsarray<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);
|
||||
// void split(const amsstring *s, amsstring *delimitstr, std::vector<amsstring> *lns)
|
||||
// {
|
||||
// split(s,delimitstr->cstring,lns);
|
||||
// return;
|
||||
// }
|
||||
|
||||
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(amsstring *s, amsstring *delimitstr, std::vector<amsstring> *lns)
|
||||
{
|
||||
split(s,delimitstr->cstring,lns);
|
||||
return;
|
||||
}
|
||||
|
||||
void split(amsstring *s, amsstring *delimitstr, ams::amsarray<amsstring> *lns)
|
||||
void split(const amsstring *s, amsstring *delimitstr, ams::amsarray<amsstring> *lns)
|
||||
{
|
||||
split(s,delimitstr->cstring,lns);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void splitwhitespace(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;
|
||||
// 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;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
// I = I + 1;
|
||||
// }
|
||||
// } //test null pointers
|
||||
// return;
|
||||
// }
|
||||
|
||||
void splitwhitespace(amsstring *s, ams::amsarray<amsstring> *lns)
|
||||
void splitwhitespace(const amsstring *s, ams::amsarray<amsstring> *lns)
|
||||
{
|
||||
int I;
|
||||
int mode;
|
||||
|
||||
63
src/amsstring4/amsstring4_convenience1.cpp
Normal file
63
src/amsstring4/amsstring4_convenience1.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include <amsstring4/amsstring4.hpp>
|
||||
|
||||
namespace ams
|
||||
{
|
||||
|
||||
amsarray<amsstring> splitlines(const amsstring &s)
|
||||
{
|
||||
amsarray<amsstring> ret;
|
||||
splitlines(&s,&ret);
|
||||
return ret;
|
||||
}
|
||||
amsarray<amsstring> split(const amsstring &s, const ams_chartype delimitchar)
|
||||
{
|
||||
amsarray<amsstring> ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//splits a string, not counting whitespaces between non-whitespace characters
|
||||
amsarray<amsstring> splitwhitespace(const amsstring &s)
|
||||
{
|
||||
amsarray<amsstring> ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
amsstring stripwhitespace(const amsstring &s)
|
||||
{
|
||||
amsstring ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
amsstring stripallwhitespace(const amsstring &s)
|
||||
{
|
||||
amsstring ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
amsarray<amsstring> splitext(const amsstring &s)
|
||||
{
|
||||
amsarray<amsstring> ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
amsarray<amsstring> splitpath(const amsstring &s)
|
||||
{
|
||||
amsarray<amsstring> ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//selects between the outermost set of delimitleft and delimitright chars
|
||||
amsstring select_between(const amsstring &s, const ams_chartype delimitleft, const ams_chartype delimitright)
|
||||
{
|
||||
amsstring ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
};//end namespace ams
|
||||
24
src/main.cpp
24
src/main.cpp
@ -7,20 +7,20 @@ int main(int argc, char* argv[])
|
||||
int ret = 0;
|
||||
printf("ams string4 library tests.\n");
|
||||
|
||||
amsstring4_basic_string_test1();
|
||||
amsstring4_sscanf_test1();
|
||||
amsstring4_basic_string_test2();
|
||||
amsstring4_memoryleakcheck1();
|
||||
amsstring4_memoryleakcheck2();
|
||||
amsstring4_stringtests2();
|
||||
amsstring4_test_find();
|
||||
// amsstring4_basic_string_test1();
|
||||
// amsstring4_sscanf_test1();
|
||||
// amsstring4_basic_string_test2();
|
||||
// amsstring4_memoryleakcheck1();
|
||||
// amsstring4_memoryleakcheck2();
|
||||
// amsstring4_stringtests2();
|
||||
// amsstring4_test_find();
|
||||
|
||||
amsstring4_test_splitlines();
|
||||
amsstring4_test_split();
|
||||
amsstring4_test_strip();
|
||||
amsstring4_test_freadwrite();
|
||||
// amsstring4_test_splitlines();
|
||||
// amsstring4_test_split();
|
||||
// amsstring4_test_strip();
|
||||
// amsstring4_test_freadwrite();
|
||||
|
||||
amsstring4_test_concatenation_operators();
|
||||
// amsstring4_test_concatenation_operators();
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user