mirror of
https://github.com/neovim/neovim.git
synced 2025-10-04 00:46:30 +00:00
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
This commit is contained in:

committed by
Thiago de Arruda

parent
d4f8a86700
commit
e772cfcc55
52
src/regexp.c
52
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,
|
||||
|
Reference in New Issue
Block a user