updates
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -185,14 +185,21 @@ amsarray<amsstring> splitpath(const amsstring &s);
|
|||||||
//selects between the outermost set of delimitleft and delimitright chars
|
//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 select_between(const amsstring &s, const ams_chartype delimitleft, const ams_chartype delimitright);
|
||||||
|
|
||||||
|
//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 concatenate(const amsarray<amsstring> &slist);
|
amsstring concatenate(const amsarray<amsstring> &slist);
|
||||||
|
|
||||||
|
//adds \n between each line in the concatenated string
|
||||||
|
amsstring concat_lines(const amsarray<amsstring> &lns);//
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void freadline(FILE *fp, amsstring *s);
|
void freadline(FILE *fp, amsstring *s);
|
||||||
void freadlines(FILE *fp, std::vector<amsstring> *lines);
|
void freadlines(FILE *fp, amsarray<amsstring> *lines);
|
||||||
void fwritelines(FILE *fp, amsstring *s);
|
void fwritelines(FILE *fp, amsstring *s);
|
||||||
void fwritelines(FILE *fp, std::vector<amsstring> *lines);
|
void fwritelines(FILE *fp, amsarray<amsstring> *lines);
|
||||||
void freadtxtfile(FILE *fp, amsstring *s);
|
void freadtxtfile(FILE *fp, amsstring *s);
|
||||||
|
|
||||||
int readtextfile(const amsstring fname, amsstring *s);
|
int readtextfile(const amsstring fname, amsstring *s);
|
||||||
|
|||||||
@ -19,7 +19,7 @@ namespace ams
|
|||||||
|
|
||||||
void amsstring4_test_concatenation_operators();
|
void amsstring4_test_concatenation_operators();
|
||||||
|
|
||||||
|
void amsstring4_test_convenience1a();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -793,8 +793,8 @@ namespace ams
|
|||||||
cc = 0;
|
cc = 0;
|
||||||
for(I=length-indstart-1;I>=0;I--)
|
for(I=length-indstart-1;I>=0;I--)
|
||||||
{
|
{
|
||||||
c1 = cstring[I];
|
if(I>=0 && I<length) c1 = cstring[I];
|
||||||
c2 = findstr[J];
|
if(J>=0 && J<findstrlen) c2 = findstr[J];
|
||||||
b1 = casesens&&(c1==c2);
|
b1 = casesens&&(c1==c2);
|
||||||
b2 = (!casesens)&&(ams::tolower(c1)==ams::tolower(c2));
|
b2 = (!casesens)&&(ams::tolower(c1)==ams::tolower(c2));
|
||||||
beq = b1 || b2;
|
beq = b1 || b2;
|
||||||
@ -808,7 +808,7 @@ namespace ams
|
|||||||
{
|
{
|
||||||
cc+=1;
|
cc+=1;
|
||||||
J--;
|
J--;
|
||||||
if(cc==findstrlen || J<0)
|
if(cc>=findstrlen || J<0)
|
||||||
{
|
{
|
||||||
ret = I;
|
ret = I;
|
||||||
break;
|
break;
|
||||||
@ -1270,7 +1270,7 @@ namespace ams
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freadlines(FILE *fp, std::vector<amsstring> *lines)
|
void freadlines(FILE *fp, amsarray<amsstring> *lines)
|
||||||
{
|
{
|
||||||
amsstring ln;
|
amsstring ln;
|
||||||
//note - this does not resize the lines to zero, just adds to them
|
//note - this does not resize the lines to zero, just adds to them
|
||||||
@ -1294,7 +1294,7 @@ namespace ams
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fwritelines(FILE *fp, std::vector<amsstring> *lines)
|
void fwritelines(FILE *fp, amsarray<amsstring> *lines)
|
||||||
{
|
{
|
||||||
int I;
|
int I;
|
||||||
if(fp!=NULL && lines!=NULL)
|
if(fp!=NULL && lines!=NULL)
|
||||||
|
|||||||
@ -440,4 +440,162 @@ amsstring concatenate(const amsarray<amsstring> &slist)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void amsstring4_test_findright()
|
||||||
|
{
|
||||||
|
amsstring s1,s2;
|
||||||
|
int I;
|
||||||
|
int I1,I2,I3,I4;
|
||||||
|
|
||||||
|
s1 = "sdkfjskdfksd";
|
||||||
|
for(I=-1;I<s1.length+2;I++)
|
||||||
|
{
|
||||||
|
s2 = s1;
|
||||||
|
s2.insert(I,".");
|
||||||
|
I1 = s2.find('.');
|
||||||
|
I2 = s2.find(".");
|
||||||
|
I3 = s2.findright('.');
|
||||||
|
I4 = s2.findright(".");
|
||||||
|
|
||||||
|
printf("s = '%s'\n",s2.cstring);
|
||||||
|
printf("Found . at (%d,%d,%d,%d)\n",I1,I2,I3,I4);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
for(I=-1;I<s1.length+2;I++)
|
||||||
|
{
|
||||||
|
s2 = s1;
|
||||||
|
s2.insert(I,".");
|
||||||
|
s2.insert(I+3,".");
|
||||||
|
I1 = s2.find('.');
|
||||||
|
I2 = s2.find(".");
|
||||||
|
I3 = s2.findright('.');
|
||||||
|
I4 = s2.findright(".");
|
||||||
|
|
||||||
|
printf("s = '%s'\n",s2.cstring);
|
||||||
|
printf("Found . at (%d,%d,%d,%d)\n",I1,I2,I3,I4);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
for(I=-1;I<s1.length+2;I++)
|
||||||
|
{
|
||||||
|
s2 = s1;
|
||||||
|
s2.insert(I,"FND");
|
||||||
|
I1 = s2.find("FND");
|
||||||
|
I2 = s2.findright("FND");
|
||||||
|
|
||||||
|
printf("s = '%s'\n",s2.cstring);
|
||||||
|
printf("Found . at (%d,%d)\n",I1,I2);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
for(I=-1;I<s1.length+2;I++)
|
||||||
|
{
|
||||||
|
s2 = s1;
|
||||||
|
s2.insert(I,"FND");
|
||||||
|
s2.insert(I+5,"FND");
|
||||||
|
I1 = s2.find("FND");
|
||||||
|
I2 = s2.findright("FND");
|
||||||
|
I3 = s2.find("FNF");
|
||||||
|
I4 = s2.findright("FNF");
|
||||||
|
|
||||||
|
printf("s = '%s'\n",s2.cstring);
|
||||||
|
printf("Found . at (%d,%d,%d,%d)\n",I1,I2,I3,I4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void amsstring4_test_convenience1a()
|
||||||
|
{
|
||||||
|
amsstring s1,s2;
|
||||||
|
amsarray<amsstring> sa;
|
||||||
|
int I;
|
||||||
|
|
||||||
|
s1 = "a string\nwith multiple\nlines\n\r";
|
||||||
|
sa = splitlines(s1);
|
||||||
|
for(I=0;I<sa.length;I++)
|
||||||
|
{
|
||||||
|
printf("%d:%d: %s\n",I,sa[I].length,sa[I].cstring);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
s1 = " some, comma, separated,variables,,";
|
||||||
|
sa = split(s1,',');
|
||||||
|
for(I=0;I<sa.length;I++)
|
||||||
|
{
|
||||||
|
printf("%d:%d: %s\n",I,sa[I].length,sa[I].cstring);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
s1 = " some:: oddly:: separated:variables::";
|
||||||
|
sa = split(s1,"::");
|
||||||
|
for(I=0;I<sa.length;I++)
|
||||||
|
{
|
||||||
|
printf("%d:%d: %s\n",I,sa[I].length,sa[I].cstring);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\n\n");
|
||||||
|
s1 = " a string with lots\tof\t\twhitespace ";
|
||||||
|
sa = splitwhitespace(s1);
|
||||||
|
for(I=0;I<sa.length;I++)
|
||||||
|
{
|
||||||
|
printf("%d:%d: %s\n",I,sa[I].length,sa[I].cstring);
|
||||||
|
}
|
||||||
|
|
||||||
|
s2 = stripwhitespace(s1);
|
||||||
|
printf("s1 = '%s'\ns2='%s'\n",s1.cstring,s2.cstring);
|
||||||
|
s2 = stripallwhitespace(s1);
|
||||||
|
printf("s3 = '%s'\n",s2.cstring);
|
||||||
|
|
||||||
|
s1 = "astring.with.separatorchars";
|
||||||
|
printf("'%s' split: '%s' '%s'\n",s1.cstring,splitfirst(s1,'.')[0].cstring, splitfirst(s1,'.')[1].cstring);
|
||||||
|
s1 = "astring_without_separatorchars";
|
||||||
|
printf("'%s' split: '%s' '%s'\n",s1.cstring,splitfirst(s1,'.')[0].cstring, splitfirst(s1,'.')[1].cstring);
|
||||||
|
|
||||||
|
s1 = "astring::with::separator:strs";
|
||||||
|
printf("'%s' split: '%s' '%s'\n",s1.cstring,splitfirst(s1,"::")[0].cstring, splitfirst(s1,"::")[1].cstring);
|
||||||
|
s1 = "astring_without_separatorstrs";
|
||||||
|
printf("'%s' split: '%s' '%s'\n",s1.cstring,splitfirst(s1,"::")[0].cstring, splitfirst(s1,"::")[1].cstring);
|
||||||
|
|
||||||
|
s1 = "somefilewithoutextension";
|
||||||
|
sa = splitext(s1);
|
||||||
|
printf("splitext('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||||
|
|
||||||
|
s1 = "somefilewithalittleext.";
|
||||||
|
sa = splitext(s1);
|
||||||
|
printf("splitext('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||||
|
|
||||||
|
s1 = "somefilewith.anextension";
|
||||||
|
sa = splitext(s1);
|
||||||
|
printf("splitext('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||||
|
|
||||||
|
s1 = "somefilewith.many.extensions";
|
||||||
|
sa = splitext(s1);
|
||||||
|
printf("splitext('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||||
|
|
||||||
|
s1 = "somepathnoseparators";
|
||||||
|
sa = splitpath(s1);
|
||||||
|
printf("splitpath('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||||
|
|
||||||
|
s1 = "\\someotherpath";
|
||||||
|
sa = splitpath(s1);
|
||||||
|
printf("splitpath('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||||
|
|
||||||
|
s1 = "/someotherpath";
|
||||||
|
sa = splitpath(s1);
|
||||||
|
printf("splitpath('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||||
|
|
||||||
|
s1 = "C:\\someotherpath";
|
||||||
|
sa = splitpath(s1);
|
||||||
|
printf("splitpath('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||||
|
|
||||||
|
s1 = "C:\\some\\other\\path";
|
||||||
|
sa = splitpath(s1);
|
||||||
|
printf("splitpath('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||||
|
|
||||||
|
s1 = "/some/other/path";
|
||||||
|
sa = splitpath(s1);
|
||||||
|
printf("splitpath('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
};//end namespace ams
|
};//end namespace ams
|
||||||
@ -313,17 +313,16 @@ namespace ams
|
|||||||
int I;
|
int I;
|
||||||
amsstring q1;
|
amsstring q1;
|
||||||
amsarray<amsstring> lns;
|
amsarray<amsstring> lns;
|
||||||
std::vector<amsstring> lns2;
|
|
||||||
q1 = "This is a \n string on \n multiple \r\n lines\n\n with CR\\LFs\n";
|
q1 = "This is a \n string on \n multiple \r\n lines\n\n with CR\\LFs\n";
|
||||||
//q1 = "\n\n";
|
//q1 = "\n\n";
|
||||||
//q1 = "";
|
//q1 = "";
|
||||||
//q1 = "More malformed\r string nonsense\n\r\n\r\r\na";
|
//q1 = "More malformed\r string nonsense\n\r\n\r\r\na";
|
||||||
|
|
||||||
printf("q1='%s'\n",q1.cstring);
|
printf("q1='%s'\n",q1.cstring);
|
||||||
splitlines(&q1,&lns2);
|
splitlines(&q1,&lns);
|
||||||
for(I=0;I<lns2.size();I++)
|
for(I=0;I<lns.size();I++)
|
||||||
{
|
{
|
||||||
printf("Line %d: '%s'\n",I,lns2[I].cstring);
|
printf("Line %d: '%s'\n",I,lns[I].cstring);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -331,7 +330,7 @@ namespace ams
|
|||||||
void amsstring4_test_split()
|
void amsstring4_test_split()
|
||||||
{
|
{
|
||||||
amsstring q1;
|
amsstring q1;
|
||||||
std::vector<amsstring> strs;
|
amsarray<amsstring> strs;
|
||||||
int I;
|
int I;
|
||||||
|
|
||||||
q1 = "this is a string to split ";
|
q1 = "this is a string to split ";
|
||||||
@ -396,7 +395,7 @@ namespace ams
|
|||||||
void amsstring4_test_strip()
|
void amsstring4_test_strip()
|
||||||
{
|
{
|
||||||
amsstring q1;
|
amsstring q1;
|
||||||
std::vector<amsstring> strs;
|
amsarray<amsstring> strs;
|
||||||
int I;
|
int I;
|
||||||
|
|
||||||
q1 = " ";
|
q1 = " ";
|
||||||
@ -425,7 +424,7 @@ namespace ams
|
|||||||
FILE *fp2 = NULL;
|
FILE *fp2 = NULL;
|
||||||
int I;
|
int I;
|
||||||
amsstring q;
|
amsstring q;
|
||||||
std::vector<amsstring> q2;
|
amsarray<amsstring> q2;
|
||||||
|
|
||||||
fp = fopen("./ref/0p375_hexbolt.scad","r");
|
fp = fopen("./ref/0p375_hexbolt.scad","r");
|
||||||
fp2 = fopen("./ref/testrewrite.scad","w+");
|
fp2 = fopen("./ref/testrewrite.scad","w+");
|
||||||
|
|||||||
@ -22,5 +22,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
// amsstring4_test_concatenation_operators();
|
// amsstring4_test_concatenation_operators();
|
||||||
|
|
||||||
|
amsstring4_test_convenience1a();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user