mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:7.4.184
Problem: match() does not work properly with a {count} argument. Solution: Compute the length once and update it. Quit the loop when at the end. (Hirohito Higashi) https://code.google.com/p/vim/source/detail?r=9ac2fc63501d3eff92446c03b2822b30b169db5a
This commit is contained in:
parent
10f899e8e7
commit
f826b4c616
15
src/eval.c
15
src/eval.c
@ -11465,6 +11465,7 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int start);
|
|||||||
static void find_some_match(typval_T *argvars, typval_T *rettv, int type)
|
static void find_some_match(typval_T *argvars, typval_T *rettv, int type)
|
||||||
{
|
{
|
||||||
char_u *str = NULL;
|
char_u *str = NULL;
|
||||||
|
long len = 0;
|
||||||
char_u *expr = NULL;
|
char_u *expr = NULL;
|
||||||
char_u *pat;
|
char_u *pat;
|
||||||
regmatch_T regmatch;
|
regmatch_T regmatch;
|
||||||
@ -11498,8 +11499,10 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int type)
|
|||||||
if ((l = argvars[0].vval.v_list) == NULL)
|
if ((l = argvars[0].vval.v_list) == NULL)
|
||||||
goto theend;
|
goto theend;
|
||||||
li = l->lv_first;
|
li = l->lv_first;
|
||||||
} else
|
} else {
|
||||||
expr = str = get_tv_string(&argvars[0]);
|
expr = str = get_tv_string(&argvars[0]);
|
||||||
|
len = (long)STRLEN(str);
|
||||||
|
}
|
||||||
|
|
||||||
pat = get_tv_string_buf_chk(&argvars[1], patbuf);
|
pat = get_tv_string_buf_chk(&argvars[1], patbuf);
|
||||||
if (pat == NULL)
|
if (pat == NULL)
|
||||||
@ -11519,15 +11522,17 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int type)
|
|||||||
} else {
|
} else {
|
||||||
if (start < 0)
|
if (start < 0)
|
||||||
start = 0;
|
start = 0;
|
||||||
if (start > (long)STRLEN(str))
|
if (start > len)
|
||||||
goto theend;
|
goto theend;
|
||||||
/* When "count" argument is there ignore matches before "start",
|
/* When "count" argument is there ignore matches before "start",
|
||||||
* otherwise skip part of the string. Differs when pattern is "^"
|
* otherwise skip part of the string. Differs when pattern is "^"
|
||||||
* or "\<". */
|
* or "\<". */
|
||||||
if (argvars[3].v_type != VAR_UNKNOWN)
|
if (argvars[3].v_type != VAR_UNKNOWN)
|
||||||
startcol = start;
|
startcol = start;
|
||||||
else
|
else {
|
||||||
str += start;
|
str += start;
|
||||||
|
len -= start;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argvars[3].v_type != VAR_UNKNOWN)
|
if (argvars[3].v_type != VAR_UNKNOWN)
|
||||||
@ -11566,6 +11571,10 @@ static void find_some_match(typval_T *argvars, typval_T *rettv, int type)
|
|||||||
} else {
|
} else {
|
||||||
startcol = (colnr_T)(regmatch.startp[0]
|
startcol = (colnr_T)(regmatch.startp[0]
|
||||||
+ (*mb_ptr2len)(regmatch.startp[0]) - str);
|
+ (*mb_ptr2len)(regmatch.startp[0]) - str);
|
||||||
|
if (startcol > (colnr_T)len || str + startcol <= regmatch.startp[0]) {
|
||||||
|
match = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ Note that the end-of-line moves the cursor to the next test line.
|
|||||||
|
|
||||||
Also test match() and matchstr()
|
Also test match() and matchstr()
|
||||||
|
|
||||||
|
Also test the gn command and repeating it.
|
||||||
|
|
||||||
STARTTEST
|
STARTTEST
|
||||||
:so small.vim
|
:so small.vim
|
||||||
/^start:/
|
/^start:/
|
||||||
@ -28,6 +30,28 @@ fXdat
|
|||||||
:put =matchstr(\"abcd\", \".\", 0, -1) " a
|
:put =matchstr(\"abcd\", \".\", 0, -1) " a
|
||||||
:put =match(\"abcd\", \".\", 0, 5) " -1
|
:put =match(\"abcd\", \".\", 0, 5) " -1
|
||||||
:put =match(\"abcd\", \".\", 0, -1) " 0
|
:put =match(\"abcd\", \".\", 0, -1) " 0
|
||||||
|
:put =match('abc', '.', 0, 1) " 0
|
||||||
|
:put =match('abc', '.', 0, 2) " 1
|
||||||
|
:put =match('abc', '.', 0, 3) " 2
|
||||||
|
:put =match('abc', '.', 0, 4) " -1
|
||||||
|
:put =match('abc', '.', 1, 1) " 1
|
||||||
|
:put =match('abc', '.', 2, 1) " 2
|
||||||
|
:put =match('abc', '.', 3, 1) " -1
|
||||||
|
:put =match('abc', '$', 0, 1) " 3
|
||||||
|
:put =match('abc', '$', 0, 2) " -1
|
||||||
|
:put =match('abc', '$', 1, 1) " 3
|
||||||
|
:put =match('abc', '$', 2, 1) " 3
|
||||||
|
:put =match('abc', '$', 3, 1) " 3
|
||||||
|
:put =match('abc', '$', 4, 1) " -1
|
||||||
|
:put =match('abc', '\zs', 0, 1) " 0
|
||||||
|
:put =match('abc', '\zs', 0, 2) " 1
|
||||||
|
:put =match('abc', '\zs', 0, 3) " 2
|
||||||
|
:put =match('abc', '\zs', 0, 4) " 3
|
||||||
|
:put =match('abc', '\zs', 0, 5) " -1
|
||||||
|
:put =match('abc', '\zs', 1, 1) " 1
|
||||||
|
:put =match('abc', '\zs', 2, 1) " 2
|
||||||
|
:put =match('abc', '\zs', 3, 1) " 3
|
||||||
|
:put =match('abc', '\zs', 4, 1) " -1
|
||||||
/^foobar
|
/^foobar
|
||||||
gncsearchmatch/one\_s*two\_s
|
gncsearchmatch/one\_s*two\_s
|
||||||
:1
|
:1
|
||||||
@ -49,6 +73,12 @@ cgnj
|
|||||||
:" Make sure there is no other match y uppercase.
|
:" Make sure there is no other match y uppercase.
|
||||||
/x59
|
/x59
|
||||||
gggnd
|
gggnd
|
||||||
|
:" test repeating dgn
|
||||||
|
/^Johnny
|
||||||
|
ggdgn.
|
||||||
|
:" test repeating gUgn
|
||||||
|
/^Depp
|
||||||
|
gggUgn.
|
||||||
:/^start:/,/^end:/wq! test.out
|
:/^start:/,/^end:/wq! test.out
|
||||||
ENDTEST
|
ENDTEST
|
||||||
|
|
||||||
@ -81,4 +111,13 @@ for (i=0; i<=10; i++)
|
|||||||
Y
|
Y
|
||||||
text
|
text
|
||||||
Y
|
Y
|
||||||
|
--1
|
||||||
|
Johnny
|
||||||
|
--2
|
||||||
|
Johnny
|
||||||
|
--3
|
||||||
|
Depp
|
||||||
|
--4
|
||||||
|
Depp
|
||||||
|
--5
|
||||||
end:
|
end:
|
||||||
|
@ -18,6 +18,28 @@ c
|
|||||||
a
|
a
|
||||||
-1
|
-1
|
||||||
0
|
0
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
-1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
-1
|
||||||
|
3
|
||||||
|
-1
|
||||||
|
3
|
||||||
|
3
|
||||||
|
3
|
||||||
|
-1
|
||||||
|
0
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
-1
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
-1
|
||||||
SEARCH:
|
SEARCH:
|
||||||
searchmatch
|
searchmatch
|
||||||
abcdx | | abcdx
|
abcdx | | abcdx
|
||||||
@ -30,4 +52,13 @@ for (j=0; i<=10; i++)
|
|||||||
|
|
||||||
text
|
text
|
||||||
Y
|
Y
|
||||||
|
--1
|
||||||
|
|
||||||
|
--2
|
||||||
|
|
||||||
|
--3
|
||||||
|
DEPP
|
||||||
|
--4
|
||||||
|
DEPP
|
||||||
|
--5
|
||||||
end:
|
end:
|
||||||
|
@ -202,6 +202,9 @@ static char *(features[]) = {
|
|||||||
|
|
||||||
static int included_patches[] = {
|
static int included_patches[] = {
|
||||||
// Add new patch number below this line
|
// Add new patch number below this line
|
||||||
|
184,
|
||||||
|
//183,
|
||||||
|
//182,
|
||||||
181,
|
181,
|
||||||
//180,
|
//180,
|
||||||
//179,
|
//179,
|
||||||
|
Loading…
Reference in New Issue
Block a user