From 5c543a8e2b88e17607885a6cc23466328c6e0e5f Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Tue, 1 Aug 2017 19:43:44 +0100 Subject: [PATCH] Copy named sub-expression info when adapting ICU via iterators. Fixes: https://svn.boost.org/trac10/ticket/13126. --- include/boost/regex/icu.hpp | 13 +++++++------ test/regress/test_icu.cpp | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/include/boost/regex/icu.hpp b/include/boost/regex/icu.hpp index 8be8e60a..f1ca99c9 100644 --- a/include/boost/regex/icu.hpp +++ b/include/boost/regex/icu.hpp @@ -389,12 +389,13 @@ inline u32regex make_u32regex(const U_NAMESPACE_QUALIFIER UnicodeString& s, boos // regex_match overloads that widen the character type as appropriate: // namespace BOOST_REGEX_DETAIL_NS{ -template -void copy_results(MR1& out, MR2 const& in) +template +void copy_results(MR1& out, MR2 const& in, NSubs named_subs) { // copy results from an adapted MR2 match_results: out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base()); out.set_base(in.base().base()); + out.set_named_subs(named_subs); for(int i = 0; i < (int)in.size(); ++i) { if(in[i].matched || !i) @@ -443,7 +444,7 @@ bool do_regex_match(BidiIterator first, BidiIterator last, match_type what; bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags); // copy results across to m: - if(result) copy_results(m, what); + if(result) copy_results(m, what, e.get_named_subs()); return result; } template @@ -459,7 +460,7 @@ bool do_regex_match(BidiIterator first, BidiIterator last, match_type what; bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags); // copy results across to m: - if(result) copy_results(m, what); + if(result) copy_results(m, what, e.get_named_subs()); return result; } } // namespace BOOST_REGEX_DETAIL_NS @@ -618,7 +619,7 @@ bool do_regex_search(BidiIterator first, BidiIterator last, match_type what; bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base)); // copy results across to m: - if(result) copy_results(m, what); + if(result) copy_results(m, what, e.get_named_subs()); return result; } template @@ -635,7 +636,7 @@ bool do_regex_search(BidiIterator first, BidiIterator last, match_type what; bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base)); // copy results across to m: - if(result) copy_results(m, what); + if(result) copy_results(m, what, e.get_named_subs()); return result; } } diff --git a/test/regress/test_icu.cpp b/test/regress/test_icu.cpp index 6e21cf37..67044f0e 100644 --- a/test/regress/test_icu.cpp +++ b/test/regress/test_icu.cpp @@ -96,6 +96,40 @@ void compare_result(const MR1& w1, const MR2& w2, boost::mpl::int_<2> const*) BOOST_REGEX_TEST_ERROR("Matched mismatch in match_results class", UChar32); } } + // + // We don't have a way to access a list of named sub-expressions since we only store + // hashes, but "abc" and "N" are common names used in our tests, so check those: + // + if (w1["abc"].matched) + { + if (w2["abc"].matched == 0) + { + BOOST_REGEX_TEST_ERROR("Matched mismatch in match_results class", UChar32); + } + if ((w1.position("abc") != boost::BOOST_REGEX_DETAIL_NS::distance(iterator_type(w2.prefix().first), iterator_type(w2["abc"].first))) || (w1.length("abc") != boost::BOOST_REGEX_DETAIL_NS::distance(iterator_type(w2["abc"].first), iterator_type(w2["abc"].second)))) + { + BOOST_REGEX_TEST_ERROR("Iterator mismatch in match_results class", UChar32); + } + } + else if (w2["abc"].matched) + { + BOOST_REGEX_TEST_ERROR("Matched mismatch in match_results class", UChar32); + } + if (w1["N"].matched) + { + if (w2["N"].matched == 0) + { + BOOST_REGEX_TEST_ERROR("Matched mismatch in match_results class", UChar32); + } + if ((w1.position("N") != boost::BOOST_REGEX_DETAIL_NS::distance(iterator_type(w2.prefix().first), iterator_type(w2["N"].first))) || (w1.length("N") != boost::BOOST_REGEX_DETAIL_NS::distance(iterator_type(w2["N"].first), iterator_type(w2["N"].second)))) + { + BOOST_REGEX_TEST_ERROR("Iterator mismatch in match_results class", UChar32); + } + } + else if (w2["N"].matched) + { + BOOST_REGEX_TEST_ERROR("Matched mismatch in match_results class", UChar32); + } } template void compare_result(const MR1& w1, const MR2& w2, boost::mpl::int_<1> const*)