Correct behaviour of \b when matching null-strings.

See https://github.com/boostorg/regex/issues/40
This commit is contained in:
jzmaddock
2018-07-21 15:19:41 +01:00
parent 867cc5f0fc
commit 231dbc3ebf
2 changed files with 29 additions and 2 deletions

View File

@ -476,12 +476,14 @@ bool perl_matcher<BidiIterator, Allocator, traits>::match_word_boundary()
} }
else else
{ {
b = (m_match_flags & match_not_eow) ? true : false; if (m_match_flags & match_not_eow)
return false;
b = false;
} }
if((position == backstop) && ((m_match_flags & match_prev_avail) == 0)) if((position == backstop) && ((m_match_flags & match_prev_avail) == 0))
{ {
if(m_match_flags & match_not_bow) if(m_match_flags & match_not_bow)
b ^= true; return false;
else else
b ^= false; b ^= false;
} }

View File

@ -169,5 +169,30 @@ void test_assertion_escapes()
TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl, L"abc\u2028bar", match_default, make_array(0, 4, -2, -2)); TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl, L"abc\u2028bar", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl, L"abc\u2029bar", match_default, make_array(0, 4, -2, -2)); TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl, L"abc\u2029bar", match_default, make_array(0, 4, -2, -2));
} }
// Bug report: https://github.com/boostorg/regex/issues/40
TEST_REGEX_SEARCH("\\b", perl, "", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "", match_not_bow | match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "-", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "-", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "-", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "", match_not_bow | match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "-", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "-", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "-", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "", match_not_bow | match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "-", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "-", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "-", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2));
} }