diff options
author | Andreas Schwab <schwab@linux-m68k.org> | 2012-06-10 10:39:19 +0200 |
---|---|---|
committer | Andreas Schwab <schwab@linux-m68k.org> | 2012-06-10 10:39:19 +0200 |
commit | 95988fcfa86170a61e488e5de3863468f50b6414 (patch) | |
tree | 86b2c2c7ff7402ec16340677c484774222224b67 /src/regex.c | |
parent | 642b6d30c61ec63bdd5d891dd6bb85260c88211a (diff) |
* regex.c (at_begline_loc_p): Also recognize `(?N:' and correctly
account for preceding backslashes. (Bug#11663)
Diffstat (limited to 'src/regex.c')
-rw-r--r-- | src/regex.c | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/regex.c b/src/regex.c index f9a12a3c2d..0dd3a18789 100644 --- a/src/regex.c +++ b/src/regex.c @@ -3824,18 +3824,37 @@ static boolean at_begline_loc_p (const re_char *pattern, const re_char *p, reg_syntax_t syntax) { re_char *prev = p - 2; - boolean prev_prev_backslash = prev > pattern && prev[-1] == '\\'; + boolean odd_backslashes; - return - /* After a subexpression? */ - (*prev == '(' && (syntax & RE_NO_BK_PARENS || prev_prev_backslash)) - /* After an alternative? */ - || (*prev == '|' && (syntax & RE_NO_BK_VBAR || prev_prev_backslash)) - /* After a shy subexpression? */ - || ((syntax & RE_SHY_GROUPS) && prev - 2 >= pattern - && prev[-1] == '?' && prev[-2] == '(' - && (syntax & RE_NO_BK_PARENS - || (prev - 3 >= pattern && prev[-3] == '\\'))); + /* After a subexpression? */ + if (*prev == '(') + odd_backslashes = (syntax & RE_NO_BK_PARENS) == 0; + + /* After an alternative? */ + else if (*prev == '|') + odd_backslashes = (syntax & RE_NO_BK_VBAR) == 0; + + /* After a shy subexpression? */ + else if (*prev == ':' && (syntax & RE_SHY_GROUPS)) + { + /* Skip over optional regnum. */ + while (prev - 1 >= pattern && prev[-1] >= '0' && prev[-1] <= '9') + --prev; + + if (!(prev - 2 >= pattern + && prev[-1] == '?' && prev[-2] == '(')) + return false; + prev -= 2; + odd_backslashes = (syntax & RE_NO_BK_PARENS) == 0; + } + else + return false; + + /* Count the number of preceding backslashes. */ + p = prev; + while (prev - 1 >= pattern && prev[-1] == '\\') + --prev; + return (p - prev) & odd_backslashes; } |