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

@ -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* [])