splitalphanum
This commit is contained in:
@ -52,7 +52,7 @@ namespace ams
|
||||
{
|
||||
ams_chartype cl = ams::tolower(c);
|
||||
bool ret = 0;
|
||||
ret = ret || ( ((int)cl>=48) && ((int)cl<=57) ) || cl=='.' || cl=='e' || '-';
|
||||
ret = ret || ( ((int)cl>=48) && ((int)cl<=57)) || cl=='.' || cl=='e' || cl=='-';
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -354,7 +354,7 @@ 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)
|
||||
amsarray<amsstring> path_splitext(const amsstring &s)
|
||||
{
|
||||
amsarray<amsstring> ret;
|
||||
ret.resize(2);
|
||||
@ -378,7 +378,7 @@ 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)
|
||||
amsarray<amsstring> path_split(const amsstring &s)
|
||||
{
|
||||
amsarray<amsstring> ret;
|
||||
ret.resize(2);
|
||||
@ -509,7 +509,7 @@ amsarray<amsstring> splitalphanum(const amsstring &s)
|
||||
I0 = I;
|
||||
}
|
||||
|
||||
if(mode==1 && (!amsstring_ischarnumeric(c) || I==length-1)
|
||||
if(mode==1 && (!amsstring_ischarnumeric(c) || I>=(s.length-1)))
|
||||
{
|
||||
I1 = I;
|
||||
s2 = s.substring(I0,I1);
|
||||
@ -641,50 +641,76 @@ void amsstring4_test_convenience1a()
|
||||
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);
|
||||
sa = path_splitext(s1);
|
||||
printf("path_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);
|
||||
sa = path_splitext(s1);
|
||||
printf("path_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);
|
||||
sa = path_splitext(s1);
|
||||
printf("path_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);
|
||||
sa = path_splitext(s1);
|
||||
printf("path_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);
|
||||
sa = path_split(s1);
|
||||
printf("path_split('%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);
|
||||
sa = path_split(s1);
|
||||
printf("path_split('%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);
|
||||
sa = path_split(s1);
|
||||
printf("path_split('%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);
|
||||
sa = path_split(s1);
|
||||
printf("path_split('%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);
|
||||
sa = path_split(s1);
|
||||
printf("path_split('%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);
|
||||
sa = path_split(s1);
|
||||
printf("path_split('%s') = ['%s','%s']\n",s1.cstring,sa[0].cstring,sa[1].cstring);
|
||||
}
|
||||
|
||||
void amsstring4_test_convenience1b()
|
||||
{
|
||||
amsstring s1,s2;
|
||||
amsarray<amsstring> sa;
|
||||
int I;
|
||||
|
||||
s1 = "1e2e3,45, 6.7E8,-9.13E24 ";
|
||||
sa = splitalphanum(s1);
|
||||
for(I=0;I<sa.length;I++)
|
||||
{
|
||||
printf("s[%d] = '%s'\n",I,sa[I].cstring);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};//end namespace ams
|
||||
};//end namespace ams
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Examples of numeric literals categorized by type:
|
||||
|
||||
Integer Literals (Decimal): 0, 123, 45678, -99
|
||||
Floating-Point Literals (Decimal): 0.0, 1.0, 3.14159, -0.01, 123.456
|
||||
Scientific Notation (Exponential): 1.2E3, 1.2e-3, -1.2E3, -1.2E-3 (equivalent to
|
||||
|
||||
, etc.)
|
||||
Hexadecimal Literals (Base 16): 0x7B, 0x1A, 0xCAFEBABE (prefixed with 0x or 0X)
|
||||
Binary Literals (Base 2): 0b1111011, 0B101 (prefixed with 0b or 0B)
|
||||
Octal Literals (Base 8): 0173, 0755 (prefixed with 0 in many languages)
|
||||
Long/Typed Literals: 12345L, 100u, 50LL (suffixes define specific data types)
|
||||
Formatted Literals: 1_000_000, 232_45_4519 (underscores for readability, e.g., in Java/Scala)
|
||||
*/
|
||||
Reference in New Issue
Block a user