diff --git a/docs/reference.xml b/docs/reference.xml index c24d78a8..d24abee2 100644 --- a/docs/reference.xml +++ b/docs/reference.xml @@ -337,6 +337,34 @@ + + Copys a substring out of the original. + + + + + + + + Character indexes begins at 0. The end position is the char that is not included anymore. + + + + + + + + + + + + + + + Controls the script flow based on a boolean expression. diff --git a/source/src/command.cpp b/source/src/command.cpp index cd17ac80..e53aa584 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -1214,10 +1214,26 @@ void timestring_() int millis_() { extern int totalmillis; return totalmillis; } void strlen_(char *s) { string r; formatstring(r)("%d", strlen(s)); result(r); } +void strcpy_(char *s, char *a, char *b) +{ + int ia = atoi(a); + int ib = atoi(b); + string q; + string r; + r[0] = '\0'; + if(ia>=0) + { + if(ib<=0 && ib>=strlen(s)) ib = strlen(s)-1; + copystring(q, s + ia); + strncpy(r, q, ib - ia); + } + result(r); +} 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(strcpy, strcpy_, ARG_3STR); COMMAND(l0, ARG_2INT); COMMAND(systime, ARG_NONE); COMMANDN(timestamp, timestamp_, ARG_NONE);