updates
This commit is contained in:
@ -793,8 +793,8 @@ namespace ams
|
||||
cc = 0;
|
||||
for(I=length-indstart-1;I>=0;I--)
|
||||
{
|
||||
c1 = cstring[I];
|
||||
c2 = findstr[J];
|
||||
if(I>=0 && I<length) c1 = cstring[I];
|
||||
if(J>=0 && J<findstrlen) c2 = findstr[J];
|
||||
b1 = casesens&&(c1==c2);
|
||||
b2 = (!casesens)&&(ams::tolower(c1)==ams::tolower(c2));
|
||||
beq = b1 || b2;
|
||||
@ -808,7 +808,7 @@ namespace ams
|
||||
{
|
||||
cc+=1;
|
||||
J--;
|
||||
if(cc==findstrlen || J<0)
|
||||
if(cc>=findstrlen || J<0)
|
||||
{
|
||||
ret = I;
|
||||
break;
|
||||
@ -1270,7 +1270,7 @@ namespace ams
|
||||
return;
|
||||
}
|
||||
|
||||
void freadlines(FILE *fp, std::vector<amsstring> *lines)
|
||||
void freadlines(FILE *fp, amsarray<amsstring> *lines)
|
||||
{
|
||||
amsstring ln;
|
||||
//note - this does not resize the lines to zero, just adds to them
|
||||
@ -1294,7 +1294,7 @@ namespace ams
|
||||
return;
|
||||
}
|
||||
|
||||
void fwritelines(FILE *fp, std::vector<amsstring> *lines)
|
||||
void fwritelines(FILE *fp, amsarray<amsstring> *lines)
|
||||
{
|
||||
int I;
|
||||
if(fp!=NULL && lines!=NULL)
|
||||
|
||||
@ -440,4 +440,162 @@ amsstring concatenate(const amsarray<amsstring> &slist)
|
||||
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
|
||||
@ -313,17 +313,16 @@ namespace ams
|
||||
int I;
|
||||
amsstring q1;
|
||||
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 = "\n\n";
|
||||
//q1 = "";
|
||||
//q1 = "More malformed\r string nonsense\n\r\n\r\r\na";
|
||||
|
||||
printf("q1='%s'\n",q1.cstring);
|
||||
splitlines(&q1,&lns2);
|
||||
for(I=0;I<lns2.size();I++)
|
||||
splitlines(&q1,&lns);
|
||||
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;
|
||||
}
|
||||
@ -331,7 +330,7 @@ namespace ams
|
||||
void amsstring4_test_split()
|
||||
{
|
||||
amsstring q1;
|
||||
std::vector<amsstring> strs;
|
||||
amsarray<amsstring> strs;
|
||||
int I;
|
||||
|
||||
q1 = "this is a string to split ";
|
||||
@ -396,7 +395,7 @@ namespace ams
|
||||
void amsstring4_test_strip()
|
||||
{
|
||||
amsstring q1;
|
||||
std::vector<amsstring> strs;
|
||||
amsarray<amsstring> strs;
|
||||
int I;
|
||||
|
||||
q1 = " ";
|
||||
@ -425,7 +424,7 @@ namespace ams
|
||||
FILE *fp2 = NULL;
|
||||
int I;
|
||||
amsstring q;
|
||||
std::vector<amsstring> q2;
|
||||
amsarray<amsstring> q2;
|
||||
|
||||
fp = fopen("./ref/0p375_hexbolt.scad","r");
|
||||
fp2 = fopen("./ref/testrewrite.scad","w+");
|
||||
|
||||
@ -21,6 +21,8 @@ int main(int argc, char* argv[])
|
||||
// amsstring4_test_freadwrite();
|
||||
|
||||
// amsstring4_test_concatenation_operators();
|
||||
|
||||
amsstring4_test_convenience1a();
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user