0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

updated for version 7.4.262

Problem:    Duplicate code in regexec().
Solution:   Add line_lbr flag to regexec_nl().
This commit is contained in:
Bram Moolenaar
2014-04-23 19:06:37 +02:00
parent 93fc481b57
commit 2af78a1408
4 changed files with 16 additions and 79 deletions

View File

@@ -3709,25 +3709,28 @@ static lpos_T reg_endzpos[NSUBEXP]; /* idem, end pos */
/* TRUE if using multi-line regexp. */ /* TRUE if using multi-line regexp. */
#define REG_MULTI (reg_match == NULL) #define REG_MULTI (reg_match == NULL)
static int bt_regexec __ARGS((regmatch_T *rmp, char_u *line, colnr_T col)); static int bt_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col, int line_lbr));
/* /*
* Match a regexp against a string. * Match a regexp against a string.
* "rmp->regprog" is a compiled regexp as returned by vim_regcomp(). * "rmp->regprog" is a compiled regexp as returned by vim_regcomp().
* Uses curbuf for line count and 'iskeyword'. * Uses curbuf for line count and 'iskeyword'.
* if "line_lbr" is TRUE consider a "\n" in "line" to be a line break.
* *
* Return TRUE if there is a match, FALSE if not. * Return TRUE if there is a match, FALSE if not.
*/ */
static int static int
bt_regexec(rmp, line, col) bt_regexec_nl(rmp, line, col, line_lbr)
regmatch_T *rmp; regmatch_T *rmp;
char_u *line; /* string to match against */ char_u *line; /* string to match against */
colnr_T col; /* column to start looking for match */ colnr_T col; /* column to start looking for match */
int line_lbr;
{ {
reg_match = rmp; reg_match = rmp;
reg_mmatch = NULL; reg_mmatch = NULL;
reg_maxline = 0; reg_maxline = 0;
reg_line_lbr = FALSE; reg_line_lbr = line_lbr;
reg_buf = curbuf; reg_buf = curbuf;
reg_win = NULL; reg_win = NULL;
ireg_ic = rmp->rm_ic; ireg_ic = rmp->rm_ic;
@@ -3738,35 +3741,6 @@ bt_regexec(rmp, line, col)
return (bt_regexec_both(line, col, NULL) != 0); return (bt_regexec_both(line, col, NULL) != 0);
} }
#if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
|| defined(FIND_REPLACE_DIALOG) || defined(PROTO)
static int bt_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col));
/*
* Like vim_regexec(), but consider a "\n" in "line" to be a line break.
*/
static int
bt_regexec_nl(rmp, line, col)
regmatch_T *rmp;
char_u *line; /* string to match against */
colnr_T col; /* column to start looking for match */
{
reg_match = rmp;
reg_mmatch = NULL;
reg_maxline = 0;
reg_line_lbr = TRUE;
reg_buf = curbuf;
reg_win = NULL;
ireg_ic = rmp->rm_ic;
#ifdef FEAT_MBYTE
ireg_icombine = FALSE;
#endif
ireg_maxcol = 0;
return (bt_regexec_both(line, col, NULL) != 0);
}
#endif
static long bt_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm)); static long bt_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm));
/* /*
@@ -7985,11 +7959,7 @@ static regengine_T bt_regengine =
{ {
bt_regcomp, bt_regcomp,
bt_regfree, bt_regfree,
bt_regexec,
#if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
|| defined(FIND_REPLACE_DIALOG) || defined(PROTO)
bt_regexec_nl, bt_regexec_nl,
#endif
bt_regexec_multi bt_regexec_multi
#ifdef DEBUG #ifdef DEBUG
,(char_u *)"" ,(char_u *)""
@@ -8003,11 +7973,7 @@ static regengine_T nfa_regengine =
{ {
nfa_regcomp, nfa_regcomp,
nfa_regfree, nfa_regfree,
nfa_regexec,
#if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
|| defined(FIND_REPLACE_DIALOG) || defined(PROTO)
nfa_regexec_nl, nfa_regexec_nl,
#endif
nfa_regexec_multi nfa_regexec_multi
#ifdef DEBUG #ifdef DEBUG
,(char_u *)"" ,(char_u *)""
@@ -8131,7 +8097,7 @@ vim_regexec(rmp, line, col)
char_u *line; /* string to match against */ char_u *line; /* string to match against */
colnr_T col; /* column to start looking for match */ colnr_T col; /* column to start looking for match */
{ {
return rmp->regprog->engine->regexec(rmp, line, col); return rmp->regprog->engine->regexec_nl(rmp, line, col, FALSE);
} }
#if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \ #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
@@ -8145,7 +8111,7 @@ vim_regexec_nl(rmp, line, col)
char_u *line; char_u *line;
colnr_T col; colnr_T col;
{ {
return rmp->regprog->engine->regexec_nl(rmp, line, col); return rmp->regprog->engine->regexec_nl(rmp, line, col, TRUE);
} }
#endif #endif

View File

@@ -149,11 +149,7 @@ struct regengine
{ {
regprog_T *(*regcomp)(char_u*, int); regprog_T *(*regcomp)(char_u*, int);
void (*regfree)(regprog_T *); void (*regfree)(regprog_T *);
int (*regexec)(regmatch_T*, char_u*, colnr_T); int (*regexec_nl)(regmatch_T*, char_u*, colnr_T, int);
#if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
|| defined(FIND_REPLACE_DIALOG) || defined(PROTO)
int (*regexec_nl)(regmatch_T*, char_u*, colnr_T);
#endif
long (*regexec_multi)(regmmatch_T*, win_T*, buf_T*, linenr_T, colnr_T, proftime_T*); long (*regexec_multi)(regmmatch_T*, win_T*, buf_T*, linenr_T, colnr_T, proftime_T*);
#ifdef DEBUG #ifdef DEBUG
char_u *expr; char_u *expr;

View File

@@ -311,7 +311,7 @@ static long nfa_regtry __ARGS((nfa_regprog_T *prog, colnr_T col));
static long nfa_regexec_both __ARGS((char_u *line, colnr_T col)); static long nfa_regexec_both __ARGS((char_u *line, colnr_T col));
static regprog_T *nfa_regcomp __ARGS((char_u *expr, int re_flags)); static regprog_T *nfa_regcomp __ARGS((char_u *expr, int re_flags));
static void nfa_regfree __ARGS((regprog_T *prog)); static void nfa_regfree __ARGS((regprog_T *prog));
static int nfa_regexec __ARGS((regmatch_T *rmp, char_u *line, colnr_T col)); static int nfa_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col, int line_lbr));
static long nfa_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm)); static long nfa_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm));
static int match_follows __ARGS((nfa_state_T *startstate, int depth)); static int match_follows __ARGS((nfa_state_T *startstate, int depth));
static int failure_chance __ARGS((nfa_state_T *state, int depth)); static int failure_chance __ARGS((nfa_state_T *state, int depth));
@@ -7060,19 +7060,21 @@ nfa_regfree(prog)
* Match a regexp against a string. * Match a regexp against a string.
* "rmp->regprog" is a compiled regexp as returned by nfa_regcomp(). * "rmp->regprog" is a compiled regexp as returned by nfa_regcomp().
* Uses curbuf for line count and 'iskeyword'. * Uses curbuf for line count and 'iskeyword'.
* If "line_lbr" is TRUE consider a "\n" in "line" to be a line break.
* *
* Return TRUE if there is a match, FALSE if not. * Return TRUE if there is a match, FALSE if not.
*/ */
static int static int
nfa_regexec(rmp, line, col) nfa_regexec_nl(rmp, line, col, line_lbr)
regmatch_T *rmp; regmatch_T *rmp;
char_u *line; /* string to match against */ char_u *line; /* string to match against */
colnr_T col; /* column to start looking for match */ colnr_T col; /* column to start looking for match */
int line_lbr;
{ {
reg_match = rmp; reg_match = rmp;
reg_mmatch = NULL; reg_mmatch = NULL;
reg_maxline = 0; reg_maxline = 0;
reg_line_lbr = FALSE; reg_line_lbr = line_lbr;
reg_buf = curbuf; reg_buf = curbuf;
reg_win = NULL; reg_win = NULL;
ireg_ic = rmp->rm_ic; ireg_ic = rmp->rm_ic;
@@ -7083,35 +7085,6 @@ nfa_regexec(rmp, line, col)
return (nfa_regexec_both(line, col) != 0); return (nfa_regexec_both(line, col) != 0);
} }
#if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \
|| defined(FIND_REPLACE_DIALOG) || defined(PROTO)
static int nfa_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col));
/*
* Like nfa_regexec(), but consider a "\n" in "line" to be a line break.
*/
static int
nfa_regexec_nl(rmp, line, col)
regmatch_T *rmp;
char_u *line; /* string to match against */
colnr_T col; /* column to start looking for match */
{
reg_match = rmp;
reg_mmatch = NULL;
reg_maxline = 0;
reg_line_lbr = TRUE;
reg_buf = curbuf;
reg_win = NULL;
ireg_ic = rmp->rm_ic;
#ifdef FEAT_MBYTE
ireg_icombine = FALSE;
#endif
ireg_maxcol = 0;
return (nfa_regexec_both(line, col) != 0);
}
#endif
/* /*
* Match a regexp against multiple lines. * Match a regexp against multiple lines.

View File

@@ -734,6 +734,8 @@ 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 */
/**/
262,
/**/ /**/
261, 261,
/**/ /**/