mirror of
https://github.com/boostorg/regex.git
synced 2025-07-23 09:07:25 +02:00
Copy named sub-expression info when adapting ICU via iterators.
Fixes: https://svn.boost.org/trac10/ticket/13126.
This commit is contained in:
@ -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:
|
// regex_match overloads that widen the character type as appropriate:
|
||||||
//
|
//
|
||||||
namespace BOOST_REGEX_DETAIL_NS{
|
namespace BOOST_REGEX_DETAIL_NS{
|
||||||
template<class MR1, class MR2>
|
template<class MR1, class MR2, class NSubs>
|
||||||
void copy_results(MR1& out, MR2 const& in)
|
void copy_results(MR1& out, MR2 const& in, NSubs named_subs)
|
||||||
{
|
{
|
||||||
// copy results from an adapted MR2 match_results:
|
// copy results from an adapted MR2 match_results:
|
||||||
out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
|
out.set_size(in.size(), in.prefix().first.base(), in.suffix().second.base());
|
||||||
out.set_base(in.base().base());
|
out.set_base(in.base().base());
|
||||||
|
out.set_named_subs(named_subs);
|
||||||
for(int i = 0; i < (int)in.size(); ++i)
|
for(int i = 0; i < (int)in.size(); ++i)
|
||||||
{
|
{
|
||||||
if(in[i].matched || !i)
|
if(in[i].matched || !i)
|
||||||
@ -443,7 +444,7 @@ bool do_regex_match(BidiIterator first, BidiIterator last,
|
|||||||
match_type what;
|
match_type what;
|
||||||
bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
|
bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
|
||||||
// copy results across to m:
|
// copy results across to m:
|
||||||
if(result) copy_results(m, what);
|
if(result) copy_results(m, what, e.get_named_subs());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
template <class BidiIterator, class Allocator>
|
template <class BidiIterator, class Allocator>
|
||||||
@ -459,7 +460,7 @@ bool do_regex_match(BidiIterator first, BidiIterator last,
|
|||||||
match_type what;
|
match_type what;
|
||||||
bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
|
bool result = ::boost::regex_match(conv_type(first, first, last), conv_type(last, first, last), what, e, flags);
|
||||||
// copy results across to m:
|
// copy results across to m:
|
||||||
if(result) copy_results(m, what);
|
if(result) copy_results(m, what, e.get_named_subs());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} // namespace BOOST_REGEX_DETAIL_NS
|
} // namespace BOOST_REGEX_DETAIL_NS
|
||||||
@ -618,7 +619,7 @@ bool do_regex_search(BidiIterator first, BidiIterator last,
|
|||||||
match_type what;
|
match_type what;
|
||||||
bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
|
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:
|
// copy results across to m:
|
||||||
if(result) copy_results(m, what);
|
if(result) copy_results(m, what, e.get_named_subs());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
template <class BidiIterator, class Allocator>
|
template <class BidiIterator, class Allocator>
|
||||||
@ -635,7 +636,7 @@ bool do_regex_search(BidiIterator first, BidiIterator last,
|
|||||||
match_type what;
|
match_type what;
|
||||||
bool result = ::boost::regex_search(conv_type(first, first, last), conv_type(last, first, last), what, e, flags, conv_type(base));
|
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:
|
// copy results across to m:
|
||||||
if(result) copy_results(m, what);
|
if(result) copy_results(m, what, e.get_named_subs());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
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 <class MR1, class MR2>
|
template <class MR1, class MR2>
|
||||||
void compare_result(const MR1& w1, const MR2& w2, boost::mpl::int_<1> const*)
|
void compare_result(const MR1& w1, const MR2& w2, boost::mpl::int_<1> const*)
|
||||||
|
Reference in New Issue
Block a user