From 87cdf728902c3cf3290e4452e7d550082b53aa34 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Wed, 26 Jan 2005 18:11:02 +0000 Subject: [PATCH] fix meaning of \B 2005-01-26 Paolo Bonzini * posix/regcomp.c (peek_token): Fix ctx_type for \B. (parse_expression): Lower token->opr.ctx_type == NOT_WORD_DELIM. * posix/regex_internal.h (re_context_type): Add NOT_WORD_DELIM and OUTSIDE_WORD. * posix/PCRE.tests: Adjust \B tests to check if it matches outside a word. git-archimport-id: bonzini@gnu.org--2004b/sed--stable--4.1--patch-36 --- NEWS | 2 ++ lib/regcomp.c | 11 ++++++----- lib/regex_internal.h | 4 +++- testsuite/PCRE.tests | 12 +++++++++--- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 39aefa7..7d864ee 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ Sed 4.1.4 +* \B correctly means "not on a word boundary" rather than "inside a word" + * bugfixes for platform without internationalization * more thorough testing framework for tarballs (`make full-distcheck') diff --git a/lib/regcomp.c b/lib/regcomp.c index 586ebc7..93a6d76 100644 --- a/lib/regcomp.c +++ b/lib/regcomp.c @@ -1864,7 +1864,7 @@ peek_token (token, input, syntax) if (!(syntax & RE_NO_GNU_OPS)) { token->type = ANCHOR; - token->opr.ctx_type = INSIDE_WORD; + token->opr.ctx_type = NOT_WORD_DELIM; } break; case 'w': @@ -2352,15 +2352,16 @@ parse_expression (regexp, preg, token, syntax, nest, err) break; case ANCHOR: if ((token->opr.ctx_type - & (WORD_DELIM | INSIDE_WORD | WORD_FIRST | WORD_LAST)) + & (WORD_DELIM | NOT_WORD_DELIM | WORD_FIRST | WORD_LAST)) && dfa->word_ops_used == 0) init_word_char (dfa); - if (token->opr.ctx_type == WORD_DELIM) + if (token->opr.ctx_type >= DUMMY_CONSTRAINT) { + int delim = (token->opr.ctx_type == WORD_DELIM); bin_tree_t *tree_first, *tree_last; - token->opr.ctx_type = WORD_FIRST; + token->opr.ctx_type = delim ? WORD_FIRST : INSIDE_WORD; tree_first = create_token_tree (dfa, NULL, NULL, token); - token->opr.ctx_type = WORD_LAST; + token->opr.ctx_type = delim ? WORD_LAST : OUTSIDE_WORD; tree_last = create_token_tree (dfa, NULL, NULL, token); tree = create_tree (dfa, tree_first, tree_last, OP_ALT); if (BE (tree_first == NULL || tree_last == NULL || tree == NULL, 0)) diff --git a/lib/regex_internal.h b/lib/regex_internal.h index ae77aeb..02bdec7 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -148,13 +148,15 @@ static inline void bitset_mask (bitset dest, const bitset src); typedef enum { INSIDE_WORD = PREV_WORD_CONSTRAINT | NEXT_WORD_CONSTRAINT, + OUTSIDE_WORD = PREV_NOTWORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT, WORD_FIRST = PREV_NOTWORD_CONSTRAINT | NEXT_WORD_CONSTRAINT, WORD_LAST = PREV_WORD_CONSTRAINT | NEXT_NOTWORD_CONSTRAINT, LINE_FIRST = PREV_NEWLINE_CONSTRAINT, LINE_LAST = NEXT_NEWLINE_CONSTRAINT, BUF_FIRST = PREV_BEGBUF_CONSTRAINT, BUF_LAST = NEXT_ENDBUF_CONSTRAINT, - WORD_DELIM = DUMMY_CONSTRAINT + WORD_DELIM = DUMMY_CONSTRAINT, + NOT_WORD_DELIM = DUMMY_CONSTRAINT << 1, } re_context_type; typedef struct diff --git a/testsuite/PCRE.tests b/testsuite/PCRE.tests index 0fb9cad..fa83bc9 100644 --- a/testsuite/PCRE.tests +++ b/testsuite/PCRE.tests @@ -1420,17 +1420,23 @@ No match -a- No match -/\By\b/ +/\B.\b/ xy 0: y + x.!?y + 0: ? -/\by\B/ +/\b.\B/ yz 0: y + x.!?y + 0: . -/\By\B/ +/\B.\B/ xyz 0: y + x.!?y + 0: ! /\w/ a