fix substr command

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6358 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lucas GAUTHERON
2011-04-26 12:12:33 +00:00
parent d8f93a4bf3
commit ad9826cac8
2 changed files with 16 additions and 9 deletions
+12 -5
View File
@@ -1242,20 +1242,27 @@ void timestring_()
int millis_() { extern int totalmillis; return totalmillis; }
void strlen_(char *s) { string r; formatstring(r)("%d", strlen(s)); result(r); }
void substr_(char *fs, char *pa, char *pb)
void substr_(char *fs, char *pa, char *len)
{
int ia = atoi(pa);
int ib = atoi(pb);
int ilen = atoi(len);
string subq;
string subr;
subr[0] = '\0';
if(ia>(int)strlen(fs))
{
return;
}
if(ia>=0)
{
if(ib<=0 || ib>=(int)strlen(fs)) ib = strlen(fs);
if(!ilen)
{
ilen = strlen(fs)-ia;
}
copystring(subq, fs + ia);
strncpy(subr, subq, ib - ia);
strncpy(subr, subq, ilen);
}
subr[ib-ia] = '\0';
subr[ilen] = '\0';
result(subr);
}
void l0(int p, int v) { string f; string r; formatstring(f)("%%0%dd", p); formatstring(r)(f, v); result(r); }