Mercurial > vim
comparison src/regexp.c @ 5838:0ea551fa607d v7.4.262
updated for version 7.4.262
Problem: Duplicate code in regexec().
Solution: Add line_lbr flag to regexec_nl().
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 23 Apr 2014 19:06:37 +0200 |
parents | 43c6cd07c8de |
children | b5972833add9 |
comparison
equal
deleted
inserted
replaced
5837:b74d21ce03a9 | 5838:0ea551fa607d |
---|---|
3707 #endif | 3707 #endif |
3708 | 3708 |
3709 /* TRUE if using multi-line regexp. */ | 3709 /* TRUE if using multi-line regexp. */ |
3710 #define REG_MULTI (reg_match == NULL) | 3710 #define REG_MULTI (reg_match == NULL) |
3711 | 3711 |
3712 static int bt_regexec __ARGS((regmatch_T *rmp, char_u *line, colnr_T col)); | 3712 static int bt_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col, int line_lbr)); |
3713 | |
3713 | 3714 |
3714 /* | 3715 /* |
3715 * Match a regexp against a string. | 3716 * Match a regexp against a string. |
3716 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp(). | 3717 * "rmp->regprog" is a compiled regexp as returned by vim_regcomp(). |
3717 * Uses curbuf for line count and 'iskeyword'. | 3718 * Uses curbuf for line count and 'iskeyword'. |
3719 * if "line_lbr" is TRUE consider a "\n" in "line" to be a line break. | |
3718 * | 3720 * |
3719 * Return TRUE if there is a match, FALSE if not. | 3721 * Return TRUE if there is a match, FALSE if not. |
3720 */ | 3722 */ |
3721 static int | 3723 static int |
3722 bt_regexec(rmp, line, col) | 3724 bt_regexec_nl(rmp, line, col, line_lbr) |
3723 regmatch_T *rmp; | 3725 regmatch_T *rmp; |
3724 char_u *line; /* string to match against */ | 3726 char_u *line; /* string to match against */ |
3725 colnr_T col; /* column to start looking for match */ | 3727 colnr_T col; /* column to start looking for match */ |
3728 int line_lbr; | |
3726 { | 3729 { |
3727 reg_match = rmp; | 3730 reg_match = rmp; |
3728 reg_mmatch = NULL; | 3731 reg_mmatch = NULL; |
3729 reg_maxline = 0; | 3732 reg_maxline = 0; |
3730 reg_line_lbr = FALSE; | 3733 reg_line_lbr = line_lbr; |
3731 reg_buf = curbuf; | 3734 reg_buf = curbuf; |
3732 reg_win = NULL; | 3735 reg_win = NULL; |
3733 ireg_ic = rmp->rm_ic; | 3736 ireg_ic = rmp->rm_ic; |
3734 #ifdef FEAT_MBYTE | 3737 #ifdef FEAT_MBYTE |
3735 ireg_icombine = FALSE; | 3738 ireg_icombine = FALSE; |
3736 #endif | 3739 #endif |
3737 ireg_maxcol = 0; | 3740 ireg_maxcol = 0; |
3738 return (bt_regexec_both(line, col, NULL) != 0); | 3741 return (bt_regexec_both(line, col, NULL) != 0); |
3739 } | 3742 } |
3740 | |
3741 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \ | |
3742 || defined(FIND_REPLACE_DIALOG) || defined(PROTO) | |
3743 | |
3744 static int bt_regexec_nl __ARGS((regmatch_T *rmp, char_u *line, colnr_T col)); | |
3745 | |
3746 /* | |
3747 * Like vim_regexec(), but consider a "\n" in "line" to be a line break. | |
3748 */ | |
3749 static int | |
3750 bt_regexec_nl(rmp, line, col) | |
3751 regmatch_T *rmp; | |
3752 char_u *line; /* string to match against */ | |
3753 colnr_T col; /* column to start looking for match */ | |
3754 { | |
3755 reg_match = rmp; | |
3756 reg_mmatch = NULL; | |
3757 reg_maxline = 0; | |
3758 reg_line_lbr = TRUE; | |
3759 reg_buf = curbuf; | |
3760 reg_win = NULL; | |
3761 ireg_ic = rmp->rm_ic; | |
3762 #ifdef FEAT_MBYTE | |
3763 ireg_icombine = FALSE; | |
3764 #endif | |
3765 ireg_maxcol = 0; | |
3766 return (bt_regexec_both(line, col, NULL) != 0); | |
3767 } | |
3768 #endif | |
3769 | 3743 |
3770 static long bt_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm)); | 3744 static long bt_regexec_multi __ARGS((regmmatch_T *rmp, win_T *win, buf_T *buf, linenr_T lnum, colnr_T col, proftime_T *tm)); |
3771 | 3745 |
3772 /* | 3746 /* |
3773 * Match a regexp against multiple lines. | 3747 * Match a regexp against multiple lines. |
7983 | 7957 |
7984 static regengine_T bt_regengine = | 7958 static regengine_T bt_regengine = |
7985 { | 7959 { |
7986 bt_regcomp, | 7960 bt_regcomp, |
7987 bt_regfree, | 7961 bt_regfree, |
7988 bt_regexec, | |
7989 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \ | |
7990 || defined(FIND_REPLACE_DIALOG) || defined(PROTO) | |
7991 bt_regexec_nl, | 7962 bt_regexec_nl, |
7992 #endif | |
7993 bt_regexec_multi | 7963 bt_regexec_multi |
7994 #ifdef DEBUG | 7964 #ifdef DEBUG |
7995 ,(char_u *)"" | 7965 ,(char_u *)"" |
7996 #endif | 7966 #endif |
7997 }; | 7967 }; |
8001 | 7971 |
8002 static regengine_T nfa_regengine = | 7972 static regengine_T nfa_regengine = |
8003 { | 7973 { |
8004 nfa_regcomp, | 7974 nfa_regcomp, |
8005 nfa_regfree, | 7975 nfa_regfree, |
8006 nfa_regexec, | |
8007 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \ | |
8008 || defined(FIND_REPLACE_DIALOG) || defined(PROTO) | |
8009 nfa_regexec_nl, | 7976 nfa_regexec_nl, |
8010 #endif | |
8011 nfa_regexec_multi | 7977 nfa_regexec_multi |
8012 #ifdef DEBUG | 7978 #ifdef DEBUG |
8013 ,(char_u *)"" | 7979 ,(char_u *)"" |
8014 #endif | 7980 #endif |
8015 }; | 7981 }; |
8129 vim_regexec(rmp, line, col) | 8095 vim_regexec(rmp, line, col) |
8130 regmatch_T *rmp; | 8096 regmatch_T *rmp; |
8131 char_u *line; /* string to match against */ | 8097 char_u *line; /* string to match against */ |
8132 colnr_T col; /* column to start looking for match */ | 8098 colnr_T col; /* column to start looking for match */ |
8133 { | 8099 { |
8134 return rmp->regprog->engine->regexec(rmp, line, col); | 8100 return rmp->regprog->engine->regexec_nl(rmp, line, col, FALSE); |
8135 } | 8101 } |
8136 | 8102 |
8137 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \ | 8103 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL) \ |
8138 || defined(FIND_REPLACE_DIALOG) || defined(PROTO) | 8104 || defined(FIND_REPLACE_DIALOG) || defined(PROTO) |
8139 /* | 8105 /* |
8143 vim_regexec_nl(rmp, line, col) | 8109 vim_regexec_nl(rmp, line, col) |
8144 regmatch_T *rmp; | 8110 regmatch_T *rmp; |
8145 char_u *line; | 8111 char_u *line; |
8146 colnr_T col; | 8112 colnr_T col; |
8147 { | 8113 { |
8148 return rmp->regprog->engine->regexec_nl(rmp, line, col); | 8114 return rmp->regprog->engine->regexec_nl(rmp, line, col, TRUE); |
8149 } | 8115 } |
8150 #endif | 8116 #endif |
8151 | 8117 |
8152 /* | 8118 /* |
8153 * Match a regexp against multiple lines. | 8119 * Match a regexp against multiple lines. |