From 9a0b0abb9a3eff042aa9c81a8999812bfcbb47d3 Mon Sep 17 00:00:00 2001 From: Lucas GAUTHERON Date: Tue, 26 Apr 2011 15:00:27 +0000 Subject: [PATCH] substr & negative start position git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6362 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- docs/reference.xml | 6 +++--- source/src/command.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/reference.xml b/docs/reference.xml index 20ec4435..91aee752 100644 --- a/docs/reference.xml +++ b/docs/reference.xml @@ -439,7 +439,7 @@ - Character indexes begins at 0. + Character indexes begins at 0. If "start position" is negative, the reference is the end of the string. @@ -447,8 +447,8 @@ cdefg]]> - + (int)strlen(fs) || ia < 0 || ilen < 0) return; + int fslen = (int)strlen(fs); + if(ia<0) ia += fslen; + if(ia>fslen || ia < 0 || ilen < 0) return; - if(!ilen) ilen = strlen(fs)-ia; + if(!ilen) ilen = fslen-ia; result(newstring(fs + ia, ilen)); } + 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);