diff options
author | oni-link <knil.ino@gmail.com> | 2014-04-28 19:52:05 +0200 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2014-04-28 16:16:40 -0300 |
commit | e772cfcc55878f82b5ab1358a10dcdca6c326e08 (patch) | |
tree | 2148c497f724cbbd54943935e3ee93c0b9013767 /src/eval.c | |
parent | d4f8a86700a1e5c7b3694a34392f311d78e023a6 (diff) | |
download | rneovim-e772cfcc55878f82b5ab1358a10dcdca6c326e08.tar.gz rneovim-e772cfcc55878f82b5ab1358a10dcdca6c326e08.tar.bz2 rneovim-e772cfcc55878f82b5ab1358a10dcdca6c326e08.zip |
vim-patch:7.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)
https://code.google.com/p/vim/source/detail?r=a63d0cd691dc925283815d17d62f4e948d723a59
Diffstat (limited to 'src/eval.c')
-rw-r--r-- | src/eval.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/eval.c b/src/eval.c index 34539f022b..c59b335a6a 100644 --- a/src/eval.c +++ b/src/eval.c @@ -7029,7 +7029,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}, @@ -14441,9 +14441,28 @@ static void f_strtrans(typval_T *argvars, typval_T *rettv) */ static void f_submatch(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; + int no = (int)get_tv_number_chk(&argvars[0], &error); + if (error) { + return; + } + + int retList = 0; + + 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); + } } /* |