mirror of
https://github.com/boostorg/regex.git
synced 2025-07-16 05:42:15 +02:00
Empty expressions, and empty alternatives are now
allowed when using the Perl regular expression syntax. This change has been added for Perl compatibility, when the new [syntax_option_type] ['no_empty_expressions] is set then the old behaviour is preserved and empty expressions are prohibited. This is issue [@https://svn.boost.org/trac/boost/ticket/1081 #1081]. Fixes #1081. [SVN r50374]
This commit is contained in:
@ -109,7 +109,11 @@ void basic_regex_parser<charT, traits>::parse(const charT* p1, const charT* p2,
|
||||
m_position = m_base = p1;
|
||||
m_end = p2;
|
||||
// empty strings are errors:
|
||||
if(p1 == p2)
|
||||
if((p1 == p2) &&
|
||||
(
|
||||
(l_flags & regbase::main_option_type) != regbase::perl_syntax_group)
|
||||
|| (l_flags & regbase::no_empty_expressions)
|
||||
)
|
||||
{
|
||||
fail(regex_constants::error_empty, 0);
|
||||
return;
|
||||
@ -926,7 +930,15 @@ bool basic_regex_parser<charT, traits>::parse_alt()
|
||||
// error check: if there have been no previous states,
|
||||
// or if the last state was a '(' then error:
|
||||
//
|
||||
if((this->m_last_state == 0) || (this->m_last_state->type == syntax_element_startmark))
|
||||
if(
|
||||
((this->m_last_state == 0) || (this->m_last_state->type == syntax_element_startmark))
|
||||
&&
|
||||
!(
|
||||
((this->flags() & regbase::main_option_type) == regbase::perl_syntax_group)
|
||||
&&
|
||||
((this->flags() & regbase::no_empty_expressions) == 0)
|
||||
)
|
||||
)
|
||||
{
|
||||
fail(regex_constants::error_empty, this->m_position - this->m_base);
|
||||
return false;
|
||||
@ -2075,7 +2087,14 @@ bool basic_regex_parser<charT, traits>::unwind_alts(std::ptrdiff_t last_paren_st
|
||||
// alternative then that's an error:
|
||||
//
|
||||
if((this->m_alt_insert_point == static_cast<std::ptrdiff_t>(this->m_pdata->m_data.size()))
|
||||
&& m_alt_jumps.size() && (m_alt_jumps.back() > last_paren_start))
|
||||
&& m_alt_jumps.size() && (m_alt_jumps.back() > last_paren_start)
|
||||
&&
|
||||
!(
|
||||
((this->flags() & regbase::main_option_type) == regbase::perl_syntax_group)
|
||||
&&
|
||||
((this->flags() & regbase::no_empty_expressions) == 0)
|
||||
)
|
||||
)
|
||||
{
|
||||
fail(regex_constants::error_empty, this->m_position - this->m_base);
|
||||
return false;
|
||||
|
@ -85,6 +85,7 @@ public:
|
||||
collate = 1 << 21, // use locale specific collation
|
||||
nosubs = 1 << 22, // don't mark sub-expressions
|
||||
save_subexpression_location = 1 << 23, // save subexpression locations
|
||||
no_empty_expressions = 1 << 24, // no empty expressions allowed
|
||||
optimize = 0, // not really supported
|
||||
|
||||
|
||||
@ -143,6 +144,7 @@ namespace regex_constants{
|
||||
mod_s = ::boost::regbase::mod_s,
|
||||
no_mod_s = ::boost::regbase::no_mod_s,
|
||||
save_subexpression_location = ::boost::regbase::save_subexpression_location,
|
||||
no_empty_expressions = ::boost::regbase::no_empty_expressions,
|
||||
|
||||
basic = ::boost::regbase::basic,
|
||||
extended = ::boost::regbase::extended,
|
||||
|
Reference in New Issue
Block a user