diff --git a/include/boost/regex/icu.hpp b/include/boost/regex/icu.hpp index 719ee220..a57fe577 100644 --- a/include/boost/regex/icu.hpp +++ b/include/boost/regex/icu.hpp @@ -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 diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 6617d188..afde5fe7 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -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 diff --git a/test/captures/captures_test.cpp b/test/captures/captures_test.cpp index e0e3257c..3ea7f415 100644 --- a/test/captures/captures_test.cpp +++ b/test/captures/captures_test.cpp @@ -21,8 +21,26 @@ #include "../test_macros.hpp" #include +#ifdef BOOST_HAS_ICU +#include +#endif + #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +template +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 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* [])