forked from boostorg/regex
Fix /analyse errors from VC8.
Update test cases appropriately. [SVN r31988]
This commit is contained in:
@ -23,6 +23,13 @@
|
||||
#pragma warning(disable:4267)
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_NO_STDC_NAMESPACE
|
||||
namespace std{
|
||||
using ::atoi;
|
||||
using ::wcstol;
|
||||
}
|
||||
#endif
|
||||
|
||||
int get_posix_compile_options(boost::regex_constants::syntax_option_type opts)
|
||||
{
|
||||
using namespace boost;
|
||||
@ -93,19 +100,23 @@ void test_deprecated(const char&, const test_regex_search_tag&)
|
||||
return;
|
||||
}
|
||||
// try and find the first occurance:
|
||||
boost::regmatch_t matches[50];
|
||||
if(boost::regexecA(&re, search_text.c_str(), 50, matches, posix_match_options) == 0)
|
||||
static const unsigned max_subs = 100;
|
||||
boost::regmatch_t matches[max_subs];
|
||||
if(boost::regexecA(&re, search_text.c_str(), max_subs, matches, posix_match_options) == 0)
|
||||
{
|
||||
int i = 0;
|
||||
while(results[2*i] != -2)
|
||||
{
|
||||
if(results[2*i] != matches[i].rm_so)
|
||||
if(max_subs > i)
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("Mismatch in start of subexpression " << i << " found with the POSIX C API.", char);
|
||||
}
|
||||
if(results[2*i+1] != matches[i].rm_eo)
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("Mismatch in end of subexpression " << i << " found with the POSIX C API.", char);
|
||||
if(results[2*i] != matches[i].rm_so)
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("Mismatch in start of subexpression " << i << " found with the POSIX C API.", char);
|
||||
}
|
||||
if(results[2*i+1] != matches[i].rm_eo)
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("Mismatch in end of subexpression " << i << " found with the POSIX C API.", char);
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
@ -213,19 +224,23 @@ void test_deprecated(const wchar_t&, const test_regex_search_tag&)
|
||||
return;
|
||||
}
|
||||
// try and find the first occurance:
|
||||
boost::regmatch_t matches[50];
|
||||
if(boost::regexecW(&re, search_text.c_str(), 50, matches, posix_match_options) == 0)
|
||||
static const unsigned max_subs = 100;
|
||||
boost::regmatch_t matches[max_subs];
|
||||
if(boost::regexecW(&re, search_text.c_str(), max_subs, matches, posix_match_options) == 0)
|
||||
{
|
||||
int i = 0;
|
||||
while(results[2*i] != -2)
|
||||
{
|
||||
if(results[2*i] != matches[i].rm_so)
|
||||
if(max_subs > i)
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("Mismatch in start of subexpression " << i << " found with the POSIX C API.", wchar_t);
|
||||
}
|
||||
if(results[2*i+1] != matches[i].rm_eo)
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("Mismatch in end of subexpression " << i << " found with the POSIX C API.", wchar_t);
|
||||
if(results[2*i] != matches[i].rm_so)
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("Mismatch in start of subexpression " << i << " found with the POSIX C API.", wchar_t);
|
||||
}
|
||||
if(results[2*i+1] != matches[i].rm_eo)
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("Mismatch in end of subexpression " << i << " found with the POSIX C API.", wchar_t);
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
@ -253,11 +268,34 @@ void test_deprecated(const char&, const test_invalid_regex_tag&)
|
||||
|
||||
// OK try and compile the expression:
|
||||
boost::regex_tA re;
|
||||
if(boost::regcompA(&re, expression.c_str(), posix_options) == 0)
|
||||
int code = boost::regcompA(&re, expression.c_str(), posix_options);
|
||||
if(code == 0)
|
||||
{
|
||||
boost::regfreeA(&re);
|
||||
BOOST_REGEX_TEST_ERROR("Expression : \"" << expression.c_str() << "\" unexpectedly compiled with the POSIX C API.", char);
|
||||
}
|
||||
else
|
||||
{
|
||||
char buf[100];
|
||||
int s = boost::regerrorA(code, &re, 0, 0);
|
||||
if(s < 100)
|
||||
s = boost::regerrorA(code, &re, buf, 100);
|
||||
s = boost::regerrorA(code | boost::REG_ITOA, &re, 0, 0);
|
||||
if(s < 100)
|
||||
{
|
||||
s = boost::regerrorA(code | boost::REG_ITOA, &re, buf, 100);
|
||||
re.re_endp = buf;
|
||||
s = boost::regerrorA(code | boost::REG_ATOI, &re, buf, 100);
|
||||
if(s)
|
||||
{
|
||||
int code2 = std::atoi(buf);
|
||||
if(code2 != code)
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("Got a bad error code from regerrA with REG_ATOI set: ", char);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
// now try the RegEx class:
|
||||
//
|
||||
@ -307,10 +345,33 @@ void test_deprecated(const wchar_t&, const test_invalid_regex_tag&)
|
||||
|
||||
// OK try and compile the expression:
|
||||
boost::regex_tW re;
|
||||
if(boost::regcompW(&re, expression.c_str(), posix_options) == 0)
|
||||
int code = boost::regcompW(&re, expression.c_str(), posix_options);
|
||||
if(code == 0)
|
||||
{
|
||||
boost::regfreeW(&re);
|
||||
BOOST_REGEX_TEST_ERROR("Expression : \"" << expression.c_str() << "\" unexpectedly compiled with the POSIX C API.", wchar_t);
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t buf[100];
|
||||
int s = boost::regerrorW(code, &re, 0, 0);
|
||||
if(s < 100)
|
||||
s = boost::regerrorW(code, &re, buf, 100);
|
||||
s = boost::regerrorW(code | boost::REG_ITOA, &re, 0, 0);
|
||||
if(s < 100)
|
||||
{
|
||||
s = boost::regerrorW(code | boost::REG_ITOA, &re, buf, 100);
|
||||
re.re_endp = buf;
|
||||
s = boost::regerrorW(code | boost::REG_ATOI, &re, buf, 100);
|
||||
if(s)
|
||||
{
|
||||
long code2 = std::wcstol(buf, 0, 10);
|
||||
if(code2 != code)
|
||||
{
|
||||
BOOST_REGEX_TEST_ERROR("Got a bad error code from regerrW with REG_ATOI set: ", char);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -75,6 +75,30 @@ void test_tricky_cases()
|
||||
TEST_REGEX_SEARCH("a(bbb+|bb+|b)bb", perl, "abbb", match_default, make_array(0, 4, 1, 2, -2, -2));
|
||||
TEST_REGEX_SEARCH("(.*).*", perl, "abcdef", match_default, make_array(0, 6, 0, 6, -2, 6, 6, 6, 6, -2, -2));
|
||||
TEST_REGEX_SEARCH("(a*)*", perl, "bc", match_default, make_array(0, 0, 0, 0, -2, 1, 1, 1, 1, -2, 2, 2, 2, 2, -2, -2));
|
||||
TEST_REGEX_SEARCH("Z(((((((a+)+)+)+)+)+)+)+|Y(((((((a+)+)+)+)+)+)+)+|X(((((((a+)+)+)+)+)+)+)+|W(((((((a+)+)+)+)+)+)+)+|V(((((((a+)+)+)+)+)+)+)+|CZ(((((((a+)+)+)+)+)+)+)+|CY(((((((a+)+)+)+)+)+)+)+|CX(((((((a+)+)+)+)+)+)+)+|CW(((((((a+)+)+)+)+)+)+)+|CV(((((((a+)+)+)+)+)+)+)+|(a+)+", perl, "bc", match_default, make_array(-2, -2));
|
||||
TEST_REGEX_SEARCH("Z(((((((a+)+)+)+)+)+)+)+|Y(((((((a+)+)+)+)+)+)+)+|X(((((((a+)+)+)+)+)+)+)+|W(((((((a+)+)+)+)+)+)+)+|V(((((((a+)+)+)+)+)+)+)+|CZ(((((((a+)+)+)+)+)+)+)+|CY(((((((a+)+)+)+)+)+)+)+|CX(((((((a+)+)+)+)+)+)+)+|CW(((((((a+)+)+)+)+)+)+)+|CV(((((((a+)+)+)+)+)+)+)+|(a+)+", perl, "aaa", match_default,
|
||||
make_array(0, 3,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
0, 3,
|
||||
-2, -2));
|
||||
TEST_REGEX_SEARCH("Z(((((((a+)+)+)+)+)+)+)+|Y(((((((a+)+)+)+)+)+)+)+|X(((((((a+)+)+)+)+)+)+)+|W(((((((a+)+)+)+)+)+)+)+|V(((((((a+)+)+)+)+)+)+)+|CZ(((((((a+)+)+)+)+)+)+)+|CY(((((((a+)+)+)+)+)+)+)+|CX(((((((a+)+)+)+)+)+)+)+|CW(((((((a+)+)+)+)+)+)+)+|CV(((((((a+)+)+)+)+)+)+)+|(a+)+",
|
||||
perl, "Zaaa", match_default,
|
||||
make_array(0, 4,
|
||||
1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1,
|
||||
-2, -2));
|
||||
TEST_REGEX_SEARCH("xyx*xz", perl, "xyxxxxyxxxz", match_default, make_array(5, 11, -2, -2));
|
||||
// do we get the right subexpression when it is used more than once?
|
||||
TEST_REGEX_SEARCH("a(b|c)*d", perl, "ad", match_default, make_array(0, 2, -1, -1, -2, -2));
|
||||
|
Reference in New Issue
Block a user