strpos command

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6364 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lucas GAUTHERON
2011-04-27 10:49:15 +00:00
parent 0de227020d
commit 4e9be4519d
2 changed files with 61 additions and 0 deletions
+24
View File
@@ -1279,11 +1279,35 @@ void substr_(char *fs, char *pa, char *len)
result(newstring(fs + ia, ilen));
}
void strpos_(char *haystack, char *needle, char *occurence)
{
int position = -1;
char *ptr = haystack;
if(haystack && needle)
for(int iocc = atoi(occurence); iocc >= 0; iocc--)
{
ptr = strstr(ptr, needle);
if (ptr)
{
position = ptr-haystack;
ptr += strlen(needle);
}
else
{
position = -1;
break;
}
}
intret(position);
}
void l0(int p, int v) { string f; string r; formatstring(f)("%%0%dd", p); formatstring(r)(f, v); result(r); }
COMMANDN(millis, millis_, ARG_IVAL);
COMMANDN(strlen, strlen_, ARG_1STR);
COMMANDN(substr, substr_, ARG_3STR);
COMMANDN(strpos, strpos_, ARG_3STR);
COMMAND(l0, ARG_2INT);
COMMAND(systime, ARG_NONE);
COMMANDN(timestamp, timestamp_, ARG_NONE);