aboutsummaryrefslogtreecommitdiff
path: root/src/regexp.c
diff options
context:
space:
mode:
authoroni-link <knil.ino@gmail.com>2014-04-28 19:52:05 +0200
committerThiago de Arruda <tpadilha84@gmail.com>2014-04-28 16:16:40 -0300
commite772cfcc55878f82b5ab1358a10dcdca6c326e08 (patch)
tree2148c497f724cbbd54943935e3ee93c0b9013767 /src/regexp.c
parentd4f8a86700a1e5c7b3694a34392f311d78e023a6 (diff)
downloadrneovim-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/regexp.c')
-rw-r--r--src/regexp.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/regexp.c b/src/regexp.c
index 454fdbe01e..35ed1b85f7 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -6929,6 +6929,58 @@ char_u *reg_submatch(int no)
return retval;
}
+// Used for the submatch() function with the optional non-zero argument: get
+// the list of strings from the n'th submatch in allocated memory with NULs
+// represented in NLs.
+// Returns a list of allocated strings. Returns NULL when not in a ":s"
+// command, for a non-existing submatch and for any error.
+list_T *reg_submatch_list(int no)
+{
+ if (!can_f_submatch || no < 0) {
+ return NULL;
+ }
+
+ linenr_T slnum;
+ linenr_T elnum;
+ list_T *list;
+ char_u *s;
+
+ if (submatch_match == NULL) {
+ slnum = submatch_mmatch->startpos[no].lnum;
+ elnum = submatch_mmatch->endpos[no].lnum;
+ if (slnum < 0 || elnum < 0) {
+ return NULL;
+ }
+
+ colnr_T scol = submatch_mmatch->startpos[no].col;
+ colnr_T ecol = submatch_mmatch->endpos[no].col;
+
+ list = list_alloc();
+
+ s = reg_getline_submatch(slnum) + scol;
+ if (slnum == elnum) {
+ list_append_string(list, s, ecol - scol);
+ } else {
+ list_append_string(list, s, -1);
+ for (int i = 1; i < elnum - slnum; i++) {
+ s = reg_getline_submatch(slnum + i);
+ list_append_string(list, s, -1);
+ }
+ s = reg_getline_submatch(elnum);
+ list_append_string(list, s, ecol);
+ }
+ } else {
+ s = submatch_match->startp[no];
+ if (s == NULL || submatch_match->endp[no] == NULL) {
+ return NULL;
+ }
+ list = list_alloc();
+ list_append_string(list, s, (int)(submatch_match->endp[no] - s));
+ }
+
+ return list;
+}
+
static regengine_T bt_regengine =
{
bt_regcomp,