diff --git a/include/boost/regex/v4/basic_regex.hpp b/include/boost/regex/v4/basic_regex.hpp index 0b63e3aa..ae861522 100644 --- a/include/boost/regex/v4/basic_regex.hpp +++ b/include/boost/regex/v4/basic_regex.hpp @@ -236,9 +236,7 @@ public: } std::pair BOOST_REGEX_CALL subexpression(std::size_t n)const { - if(n == 0) - boost::throw_exception(std::out_of_range("0 is not a valid subexpression index.")); - const std::pair& pi = this->m_subs.at(n - 1); + const std::pair& pi = this->m_subs.at(n); std::pair p(expression() + pi.first, expression() + pi.second); return p; } @@ -266,7 +264,7 @@ public: } size_type BOOST_REGEX_CALL mark_count()const { - return this->m_mark_count; + return this->m_mark_count - 1; } const re_detail::re_syntax_base* get_first_state()const { diff --git a/include/boost/regex/v4/perl_matcher_common.hpp b/include/boost/regex/v4/perl_matcher_common.hpp index a5476e6c..480d8f14 100644 --- a/include/boost/regex/v4/perl_matcher_common.hpp +++ b/include/boost/regex/v4/perl_matcher_common.hpp @@ -200,7 +200,7 @@ bool perl_matcher::match_imp() search_base = base; state_count = 0; m_match_flags |= regex_constants::match_all; - m_presult->set_size((m_match_flags & match_nosubs) ? 1 : re.mark_count(), search_base, last); + m_presult->set_size((m_match_flags & match_nosubs) ? 1 : 1 + re.mark_count(), search_base, last); m_presult->set_base(base); m_presult->set_named_subs(this->re.get_named_subs()); if(m_match_flags & match_posix) @@ -262,7 +262,7 @@ bool perl_matcher::find_imp() // reset our state machine: search_base = position = base; pstate = re.get_first_state(); - m_presult->set_size((m_match_flags & match_nosubs) ? 1 : re.mark_count(), base, last); + m_presult->set_size((m_match_flags & match_nosubs) ? 1 : 1 + re.mark_count(), base, last); m_presult->set_base(base); m_presult->set_named_subs(this->re.get_named_subs()); m_match_flags |= regex_constants::match_init; @@ -281,13 +281,13 @@ bool perl_matcher::find_imp() ++position; } // reset $` start: - m_presult->set_size((m_match_flags & match_nosubs) ? 1 : re.mark_count(), search_base, last); + m_presult->set_size((m_match_flags & match_nosubs) ? 1 : 1 + re.mark_count(), search_base, last); //if((base != search_base) && (base == backstop)) // m_match_flags |= match_prev_avail; } if(m_match_flags & match_posix) { - m_result.set_size(re.mark_count(), base, last); + m_result.set_size(1 + re.mark_count(), base, last); m_result.set_base(base); } diff --git a/include/boost/regex/v4/regex_split.hpp b/include/boost/regex/v4/regex_split.hpp index 534fb58e..c12d7baa 100644 --- a/include/boost/regex/v4/regex_split.hpp +++ b/include/boost/regex/v4/regex_split.hpp @@ -119,7 +119,7 @@ std::size_t regex_split(OutputIterator out, // if there is still input left, do a final push as long as max_split // is not exhausted, and we're not splitting sub-expressions rather // than whitespace: - if(max_split && (last != s.end()) && (e.mark_count() == 1)) + if(max_split && (last != s.end()) && (e.mark_count() == 0)) { *out = std::basic_string((ci_t)last, (ci_t)s.end()); ++out; diff --git a/src/posix_api.cpp b/src/posix_api.cpp index e59c19ea..8a803b3c 100644 --- a/src/posix_api.cpp +++ b/src/posix_api.cpp @@ -125,7 +125,7 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompA(regex_tA* expression, const char #endif expression->re_magic = magic_value; static_cast(expression->guts)->set_expression(ptr, p2, flags); - expression->re_nsub = static_cast(expression->guts)->mark_count() - 1; + expression->re_nsub = static_cast(expression->guts)->mark_count(); result = static_cast(expression->guts)->error_code(); #ifndef BOOST_NO_EXCEPTIONS } diff --git a/src/wide_posix_api.cpp b/src/wide_posix_api.cpp index ff5c90d8..41704cd0 100644 --- a/src/wide_posix_api.cpp +++ b/src/wide_posix_api.cpp @@ -135,7 +135,7 @@ BOOST_REGEX_DECL int BOOST_REGEX_CCALL regcompW(regex_tW* expression, const wcha #endif expression->re_magic = wmagic_value; static_cast(expression->guts)->set_expression(ptr, p2, flags); - expression->re_nsub = static_cast(expression->guts)->mark_count() - 1; + expression->re_nsub = static_cast(expression->guts)->mark_count(); result = static_cast(expression->guts)->error_code(); #ifndef BOOST_NO_EXCEPTIONS } diff --git a/test/regress/test_regex_search.hpp b/test/regress/test_regex_search.hpp index 030a3c1b..66cb248b 100644 --- a/test/regress/test_regex_search.hpp +++ b/test/regress/test_regex_search.hpp @@ -511,7 +511,7 @@ void test(boost::basic_regex& r, const test_regex_search_tag&) } } r.assign(expression, syntax_options | boost::regbase::save_subexpression_location); - for(std::size_t i = 1; i < r.mark_count(); ++i) + for(std::size_t i = 0; i < r.mark_count(); ++i) { std::pair p = r.subexpression(i); if(*p.first != '(')