Fix copying of extra match data when using ICU.

See: https://svn.boost.org/trac/boost/ticket/12130
This commit is contained in:
jzmaddock
2016-06-12 13:09:12 +01:00
parent acade9f20c
commit a824b7d236
3 changed files with 78 additions and 2 deletions

View File

@ -403,6 +403,22 @@ void copy_results(MR1& out, MR2 const& in)
out.set_second(in[i].second.base(), i, in[i].matched);
}
}
#ifdef BOOST_REGEX_MATCH_EXTRA
// Copy full capture info as well:
for(int i = 0; i < (int)in.size(); ++i)
{
if(in[i].captures().size())
{
out[i].get_captures().assign(in[i].captures().size(), typename MR1::value_type());
for(int j = 0; j < out[i].captures().size(); ++j)
{
out[i].get_captures()[j].first = in[i].captures()[j].first.base();
out[i].get_captures()[j].second = in[i].captures()[j].second.base();
out[i].get_captures()[j].matched = in[i].captures()[j].matched;
}
}
}
#endif
}
template <class BidiIterator, class Allocator>

View File

@ -158,7 +158,7 @@ test-suite regex
[ run
# sources
captures/captures_test.cpp
captures//boost_regex_extra
captures//boost_regex_extra ../build//icu_options
: # additional args
: # test-files
: # requirements

View File

@ -21,8 +21,26 @@
#include "../test_macros.hpp"
#include <boost/array.hpp>
#ifdef BOOST_HAS_ICU
#include <boost/regex/icu.hpp>
#endif
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
template <int N>
int array_size(const char* (&p)[N])
{
for(int i = 0; i < N; ++i)
if(p[i] == 0)
return i;
return N;
}
std::wstring make_wstring(const char* p)
{
return std::wstring(p, p + strlen(p));
}
#ifdef __sgi
template <class T>
void test_captures(const std::string& regx, const std::string& text, const T& expected)
@ -42,13 +60,55 @@ void test_captures(const std::string& regx, const std::string& text, T& expected
#endif
for(i = 0; i < what.size(); ++i)
{
BOOST_CHECK(what.captures(i).size() <= ARRAY_SIZE(expected[i]));
BOOST_CHECK(what.captures(i).size() == array_size(expected[i]));
for(j = 0; j < what.captures(i).size(); ++j)
{
BOOST_CHECK(what.captures(i)[j] == expected[i][j]);
}
}
}
std::wstring wre(regx.begin(), regx.end());
std::wstring wtext(text.begin(), text.end());
boost::wregex we(wre);
boost::wsmatch wwhat;
if(boost::regex_match(wtext, wwhat, we, boost::match_extra))
{
unsigned i, j;
#ifndef __sgi
// strange type deduction causes this test to fail on SGI:
BOOST_CHECK(wwhat.size() == ARRAY_SIZE(expected));
#endif
for(i = 0; i < wwhat.size(); ++i)
{
BOOST_CHECK(wwhat.captures(i).size() == array_size(expected[i]));
for(j = 0; j < wwhat.captures(i).size(); ++j)
{
BOOST_CHECK(wwhat.captures(i)[j] == make_wstring(expected[i][j]));
}
}
}
#ifdef BOOST_HAS_ICU
boost::u32regex ure = boost::make_u32regex(regx);
what = boost::smatch();
if(boost::u32regex_match(text, what, ure, boost::match_extra))
{
unsigned i, j;
#ifndef __sgi
// strange type deduction causes this test to fail on SGI:
BOOST_CHECK(what.size() == ARRAY_SIZE(expected));
#endif
for(i = 0; i < what.size(); ++i)
{
BOOST_CHECK(what.captures(i).size() == array_size(expected[i]));
for(j = 0; j < what.captures(i).size(); ++j)
{
BOOST_CHECK(what.captures(i)[j] == expected[i][j]);
}
}
}
#endif
}
int cpp_main(int , char* [])