updates
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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_dq = (ams_chartype) '"'; //doublequote
|
||||||
static const ams_chartype ams_char_sq = (ams_chartype) '\''; //singlequote
|
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
|
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
|
//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
|
//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<amsstring> &slist);
|
amsstring concatenate(const amsarray<amsstring> &slist);
|
||||||
|
|
||||||
//adds \n between each line in the concatenated string
|
//adds \n between each line in the concatenated string
|
||||||
amsstring concat_lines(const amsarray<amsstring> &lns);//
|
amsstring concat_lines(const amsarray<amsstring> &lns);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,7 @@ namespace ams
|
|||||||
void amsstring4_test_concatenation_operators();
|
void amsstring4_test_concatenation_operators();
|
||||||
|
|
||||||
void amsstring4_test_convenience1a();
|
void amsstring4_test_convenience1a();
|
||||||
|
void amsstring4_test_convenience1b();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,20 @@
|
|||||||
namespace ams
|
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;
|
unsigned char c2 = (unsigned char) c;
|
||||||
ams_chartype ret;
|
ams_chartype ret;
|
||||||
@ -18,7 +31,7 @@ namespace ams
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ams_chartype toupper(ams_chartype c)
|
ams_chartype toupper(const ams_chartype c)
|
||||||
{
|
{
|
||||||
unsigned char c2 = (unsigned char) c;
|
unsigned char c2 = (unsigned char) c;
|
||||||
ams_chartype ret;
|
ams_chartype ret;
|
||||||
@ -33,7 +46,17 @@ namespace ams
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int amsstring_strlen(const ams_chartype *c)
|
//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;
|
||||||
|
}
|
||||||
|
|
||||||
|
int amsstring_strlen(const ams_chartype *c)
|
||||||
{
|
{
|
||||||
int I;
|
int I;
|
||||||
if(c!=NULL)
|
if(c!=NULL)
|
||||||
@ -1138,13 +1161,15 @@ namespace ams
|
|||||||
while(qf==0)
|
while(qf==0)
|
||||||
{
|
{
|
||||||
c = s->cstring[I];
|
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;
|
mode = 1;
|
||||||
ind1 = I;
|
ind1 = I;
|
||||||
ind1 = ams::max<int>(0,ind1);
|
ind1 = ams::max<int>(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;
|
mode = 0;
|
||||||
ind2 = I;
|
ind2 = I;
|
||||||
@ -1179,7 +1204,8 @@ namespace ams
|
|||||||
for(I=0;I<s->length;I++)
|
for(I=0;I<s->length;I++)
|
||||||
{
|
{
|
||||||
c = s->cstring[I];
|
c = s->cstring[I];
|
||||||
if(!(isspace(c)||c==' '||c=='\t'))
|
//if(!(isspace(c)||c==' '||c=='\t'))
|
||||||
|
if(!(amsstring_isspace(c)))
|
||||||
{
|
{
|
||||||
ind1 = I;
|
ind1 = I;
|
||||||
break;
|
break;
|
||||||
@ -1188,7 +1214,8 @@ namespace ams
|
|||||||
for(I=s->length-1;I>=0;I--)
|
for(I=s->length-1;I>=0;I--)
|
||||||
{
|
{
|
||||||
c = s->cstring[I];
|
c = s->cstring[I];
|
||||||
if(!(isspace(c)||c==' '||c=='\t'))
|
//if(!(isspace(c)||c==' '||c=='\t'))
|
||||||
|
if(!(amsstring_isspace(c)))
|
||||||
{
|
{
|
||||||
ind2 = I+1;
|
ind2 = I+1;
|
||||||
break;
|
break;
|
||||||
@ -1219,7 +1246,8 @@ namespace ams
|
|||||||
for(I=0;I<s->length;I++)
|
for(I=0;I<s->length;I++)
|
||||||
{
|
{
|
||||||
c = s->cstring[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];
|
q.cstring[J] = s->cstring[I];
|
||||||
J = J + 1;
|
J = J + 1;
|
||||||
|
|||||||
@ -94,22 +94,22 @@ amsarray<amsstring> split(const amsstring &s, const ams_chartype delimitchar)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int amsstring_strlen(const ams_chartype *c)
|
// static int amsstring_strlen(const ams_chartype *c)
|
||||||
{
|
// {
|
||||||
int I;
|
// int I;
|
||||||
if(c!=NULL)
|
// if(c!=NULL)
|
||||||
{
|
// {
|
||||||
I = 0;
|
// I = 0;
|
||||||
while(c[I]!='\0')
|
// while(c[I]!='\0')
|
||||||
{
|
// {
|
||||||
I++;
|
// I++;
|
||||||
}
|
// }
|
||||||
return I;
|
// return I;
|
||||||
//return strlen((const char*) c);
|
// //return strlen((const char*) c);
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
amsarray<amsstring> split(const amsstring &s, const ams_chartype *delimitstr)
|
amsarray<amsstring> split(const amsstring &s, const ams_chartype *delimitstr)
|
||||||
{
|
{
|
||||||
@ -255,13 +255,15 @@ amsarray<amsstring> splitwhitespace(const amsstring &s)
|
|||||||
while(qf==0)
|
while(qf==0)
|
||||||
{
|
{
|
||||||
c = s.cstring[I];
|
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;
|
mode = 1;
|
||||||
ind1 = I;
|
ind1 = I;
|
||||||
ind1 = ams::max<int>(0,ind1);
|
ind1 = ams::max<int>(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;
|
mode = 0;
|
||||||
ind2 = I;
|
ind2 = I;
|
||||||
@ -295,7 +297,8 @@ amsstring stripwhitespace(const amsstring &s)
|
|||||||
for(I=0;I<s.length;I++)
|
for(I=0;I<s.length;I++)
|
||||||
{
|
{
|
||||||
c = s.cstring[I];
|
c = s.cstring[I];
|
||||||
if(!(isspace(c)||c==' '||c=='\t'))
|
//if(!(isspace(c)||c==' '||c=='\t'))
|
||||||
|
if(!(amsstring_isspace(c)))
|
||||||
{
|
{
|
||||||
ind1 = I;
|
ind1 = I;
|
||||||
break;
|
break;
|
||||||
@ -304,7 +307,8 @@ amsstring stripwhitespace(const amsstring &s)
|
|||||||
for(I=s.length-1;I>=0;I--)
|
for(I=s.length-1;I>=0;I--)
|
||||||
{
|
{
|
||||||
c = s.cstring[I];
|
c = s.cstring[I];
|
||||||
if(!(isspace(c)||c==' '||c=='\t'))
|
//if(!(isspace(c)||c==' '||c=='\t'))
|
||||||
|
if(!(amsstring_isspace(c)))
|
||||||
{
|
{
|
||||||
ind2 = I+1;
|
ind2 = I+1;
|
||||||
break;
|
break;
|
||||||
@ -335,7 +339,8 @@ amsstring stripallwhitespace(const amsstring &s)
|
|||||||
for(I=0;I<s.length;I++)
|
for(I=0;I<s.length;I++)
|
||||||
{
|
{
|
||||||
c = s.cstring[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)))
|
||||||
{
|
{
|
||||||
ret.cstring[J] = s.cstring[I];
|
ret.cstring[J] = s.cstring[I];
|
||||||
J = J + 1;
|
J = J + 1;
|
||||||
@ -426,6 +431,32 @@ amsstring select_between(const amsstring &s, const ams_chartype delimitleft, con
|
|||||||
return 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;
|
||||||
|
|
||||||
|
int ind1,ind2;
|
||||||
|
int slen1,slen2;
|
||||||
|
|
||||||
|
slen1 = amsstring_strlen(delimitleft);
|
||||||
|
slen2 = amsstring_strlen(delimitleft);
|
||||||
|
|
||||||
|
ind1 = -1;
|
||||||
|
ind2 = -1;
|
||||||
|
if(slen1>0)
|
||||||
|
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<amsstring> &slist)
|
amsstring concatenate(const amsarray<amsstring> &slist)
|
||||||
{
|
{
|
||||||
amsstring ret;
|
amsstring ret;
|
||||||
@ -440,6 +471,60 @@ amsstring concatenate(const amsarray<amsstring> &slist)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
amsstring concat_lines(const amsarray<amsstring> &slist)
|
||||||
|
{
|
||||||
|
amsstring ret;
|
||||||
|
amsstring s;
|
||||||
|
int I;
|
||||||
|
ret.resize(0);
|
||||||
|
for(I=0;I<slist.length;I++)
|
||||||
|
{
|
||||||
|
s = slist[I];
|
||||||
|
s=s+"\n"; //maybe check to see if a newline already exists for this line?
|
||||||
|
ret.append(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//splits a string into contiguous sets of alphanumeric characters delimited by any non-alphanum chars
|
||||||
|
//for eventual conversion of space,tab,comma separated numbers into numeric tuples and arrays
|
||||||
|
//This step does not check that each string is a valid number.
|
||||||
|
amsarray<amsstring> splitalphanum(const amsstring &s)
|
||||||
|
{
|
||||||
|
amsarray<amsstring> sa;
|
||||||
|
int I0,I1,I;
|
||||||
|
int mode;
|
||||||
|
ams_chartype c;
|
||||||
|
amsstring s2;
|
||||||
|
|
||||||
|
mode = 0;
|
||||||
|
for(I=0;I<s.length;I++)
|
||||||
|
{
|
||||||
|
c = s[I];
|
||||||
|
if(mode==0 && amsstring_ischarnumeric(c))
|
||||||
|
{
|
||||||
|
mode = 1;
|
||||||
|
I0 = I;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mode==1 && (!amsstring_ischarnumeric(c) || I==length-1)
|
||||||
|
{
|
||||||
|
I1 = I;
|
||||||
|
s2 = s.substring(I0,I1);
|
||||||
|
sa.append(s2);
|
||||||
|
mode = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sa;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////
|
||||||
|
// Testing //
|
||||||
|
/////////////
|
||||||
|
|
||||||
void amsstring4_test_findright()
|
void amsstring4_test_findright()
|
||||||
{
|
{
|
||||||
amsstring s1,s2;
|
amsstring s1,s2;
|
||||||
@ -594,6 +679,10 @@ void amsstring4_test_convenience1a()
|
|||||||
s1 = "/some/other/path";
|
s1 = "/some/other/path";
|
||||||
sa = splitpath(s1);
|
sa = splitpath(s1);
|
||||||
printf("splitpath('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
printf("splitpath('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||||
|
}
|
||||||
|
|
||||||
|
void amsstring4_test_convenience1b()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,8 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
// amsstring4_test_concatenation_operators();
|
// amsstring4_test_concatenation_operators();
|
||||||
|
|
||||||
amsstring4_test_convenience1a();
|
//amsstring4_test_convenience1a();
|
||||||
|
amsstring4_test_convenience1b();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user