summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2014-04-02 19:00:58 +0200
committerBram Moolenaar <Bram@vim.org>2014-04-02 19:00:58 +0200
commit41571769c9a236fd07b333a5eb98c461636b466c (patch)
treeec1ea68205a7a81587973c381cfe55f4188924d1 /src/eval.c
parentfe5aab63feb2b03656700d3738d46a19e99edde0 (diff)
updated for version 7.4.241v7.4.241
Problem: The string returned by submatch() does not distinguish between a NL from a line break and a NL that stands for a NUL character. Solution: Add a second argument to return a list. (ZyX)
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/eval.c b/src/eval.c
index 05f91b303e..7b682572cf 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -8129,7 +8129,7 @@ static struct fst
{"strridx", 2, 3, f_strridx},
{"strtrans", 1, 1, f_strtrans},
{"strwidth", 1, 1, f_strwidth},
- {"submatch", 1, 1, f_submatch},
+ {"submatch", 1, 2, f_submatch},
{"substitute", 4, 4, f_substitute},
{"synID", 3, 3, f_synID},
{"synIDattr", 2, 3, f_synIDattr},
@@ -17890,9 +17890,32 @@ f_submatch(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
- rettv->v_type = VAR_STRING;
- rettv->vval.v_string =
- reg_submatch((int)get_tv_number_chk(&argvars[0], NULL));
+ int error = FALSE;
+ char_u **match;
+ char_u **s;
+ listitem_T *li;
+ int no;
+ int retList = 0;
+
+ no = (int)get_tv_number_chk(&argvars[0], &error);
+ if (error)
+ return;
+ error = FALSE;
+ if (argvars[1].v_type != VAR_UNKNOWN)
+ retList = get_tv_number_chk(&argvars[1], &error);
+ if (error)
+ return;
+
+ if (retList == 0)
+ {
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = reg_submatch(no);
+ }
+ else
+ {
+ rettv->v_type = VAR_LIST;
+ rettv->vval.v_list = reg_submatch_list(no);
+ }
}
/*