aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2010-10-16 19:38:19 +1000
committerSteve Bennett <steveb@workware.net.au>2010-10-20 10:26:03 +1000
commitdad7d138ad9d14cc9af7ec2139ac860c4bdf9f27 (patch)
tree6f89263f8181b4e8c16c6aacdbb7834c9c16e4c0
parentba3931f5846e4214bdb7cdc75868741e3208f63d (diff)
downloadjimtcl-dad7d138ad9d14cc9af7ec2139ac860c4bdf9f27.zip
jimtcl-dad7d138ad9d14cc9af7ec2139ac860c4bdf9f27.tar.gz
jimtcl-dad7d138ad9d14cc9af7ec2139ac860c4bdf9f27.tar.bz2
Allow regexp/regsub -start to be an index
Allows, e.g. -start end-4 Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--jim-regexp.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/jim-regexp.c b/jim-regexp.c
index 713d90c..89861c4 100644
--- a/jim-regexp.c
+++ b/jim-regexp.c
@@ -112,7 +112,7 @@ int Jim_RegexpCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
int opt_inline = 0;
regex_t *regex;
int match, i, j;
- long offset = 0;
+ int offset = 0;
regmatch_t *pmatch = NULL;
int source_len;
int result = JIM_OK;
@@ -151,7 +151,7 @@ int Jim_RegexpCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
if (++i == argc) {
goto wrongNumArgs;
}
- if (Jim_GetLong(interp, argv[i], &offset) != JIM_OK) {
+ if (Jim_GetIndex(interp, argv[i], &offset) != JIM_OK) {
return JIM_ERR;
}
}
@@ -200,6 +200,9 @@ int Jim_RegexpCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
* If it points past the end of the string, point to the terminating null
*/
if (offset) {
+ if (offset < 0) {
+ offset += source_len + 1;
+ }
if (offset > source_len) {
source_str += source_len;
}
@@ -318,7 +321,7 @@ int Jim_RegsubCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
int regcomp_flags = 0;
int opt_all = 0;
- long offset = 0;
+ int offset = 0;
regex_t *regex;
const char *p;
int result;
@@ -355,7 +358,8 @@ int Jim_RegsubCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
if (++i == argc) {
goto wrongNumArgs;
}
- if (Jim_GetLong(interp, argv[i], &offset) != JIM_OK) {
+ if (Jim_GetIndex(interp, argv[i], &offset) != JIM_OK) {
+ printf("Failed getindex\n");
return JIM_ERR;
}
}
@@ -394,6 +398,9 @@ int Jim_RegsubCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
* If it points past the end of the string, point to the terminating null
*/
if (offset) {
+ if (offset < 0) {
+ offset += source_len + 1;
+ }
if (offset > source_len) {
offset = source_len;
}