Merge branch 'develop'

This commit is contained in:
jzmaddock
2018-09-15 08:59:28 +01:00
41 changed files with 428 additions and 115 deletions

View File

@ -194,4 +194,10 @@ compile test_consolidated.cpp ;
build-project ../example ;
# `quick` target (for CI)
run quick.cpp ../build//boost_regex ;
compile test_warnings.cpp
: <toolset>msvc:<warnings>all <toolset>msvc:<warnings-as-errors>on
<toolset>gcc:<warnings>all <toolset>gcc:<warnings-as-errors>on
<toolset>clang:<warnings>all <toolset>clang:<warnings-as-errors>on ;

View File

@ -39,7 +39,7 @@ int main()
{
char buf[256];
regerrorA(result, &re, buf, sizeof(buf));
printf(buf);
puts(buf);
return result;
}
assert(re.re_nsub == 0);
@ -50,7 +50,7 @@ int main()
{
char buf[256];
regerrorA(result, &re, buf, sizeof(buf));
printf(buf);
puts(buf);
regfreeA(&re);
return result;
}

View File

@ -50,7 +50,7 @@ int main()
regerror(result, &re, buf, sizeof(buf));
for(i = 0; i < 256; ++i)
nbuf[i] = (char)(buf[i]);
printf(nbuf);
puts(nbuf);
return result;
}
if(re.re_nsub != 0)
@ -66,7 +66,7 @@ int main()
regerror(result, &re, buf, sizeof(buf));
for(i = 0; i < 256; ++i)
nbuf[i] = (char)(buf[i]);
printf(nbuf);
puts(nbuf);
regfree(&re);
return result;
}

View File

@ -29,9 +29,9 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
template <int N>
int array_size(const char* (&p)[N])
size_t array_size(const char* (&p)[N])
{
for(int i = 0; i < N; ++i)
for(size_t i = 0; i < N; ++i)
if(p[i] == 0)
return i;
return N;

View File

@ -33,7 +33,34 @@
#include <boost/regex/concepts.hpp>
#endif
template <class I>
void check_token_iterator(I i)
{
typedef typename I::value_type value_type;
typedef typename value_type::value_type char_type;
typedef std::basic_string<char_type> string_type;
I j;
std::vector<string_type> v;
while (i != j)
{
v.push_back(i->str());
++i;
}
}
template <class I>
void check_iterator(I i)
{
typedef typename I::value_type value_type;
std::vector <value_type> v(i, I());
(void)v;
}
int main()
{
// VC6 and VC7 can't cope with the iterator architypes,
@ -150,6 +177,64 @@ int main()
s1 = boost::u32regex_replace(s1, e1, s1);
s2 = boost::u32regex_replace(s2, e1, s2);
std::vector<int> subs1;
int subs2[2] = { 1, 2 };
check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, 0, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, 0));
check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1));
check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, 0, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, 0));
check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1));
check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, 0, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, 0));
check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1));
check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, 0, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, 0));
check_token_iterator(boost::make_u32regex_token_iterator(s1, e1));
check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, 0, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, 0));
check_token_iterator(boost::make_u32regex_token_iterator(s2, e1));
check_token_iterator(boost::make_u32regex_token_iterator(us, e1, 0, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator(us, e1, 0));
check_token_iterator(boost::make_u32regex_token_iterator(us, e1));
check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs2, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs2));
check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs2, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs2));
check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs2, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs2));
check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs2, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs2));
check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs2, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs2));
check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs2, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs2));
check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs1, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs1));
check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs1, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs1));
check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs1, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs1));
check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs1, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs1));
check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs1, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs1));
check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs1, boost::regex_constants::match_default));
check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs1));
check_iterator(boost::make_u32regex_iterator((const char*)(pb), e1, boost::regex_constants::match_default));
check_iterator(boost::make_u32regex_iterator((const char*)(pb), e1));
check_iterator(boost::make_u32regex_iterator((const UChar*)(pb), e1, boost::regex_constants::match_default));
check_iterator(boost::make_u32regex_iterator((const UChar*)(pb), e1));
check_iterator(boost::make_u32regex_iterator((const wchar_t*)(pb), e1, boost::regex_constants::match_default));
check_iterator(boost::make_u32regex_iterator((const wchar_t*)(pb), e1));
check_iterator(boost::make_u32regex_iterator(s1, e1, boost::regex_constants::match_default));
check_iterator(boost::make_u32regex_iterator(s2, e1));
check_iterator(boost::make_u32regex_iterator(us, e1));
#endif
return 0;
}

55
test/quick.cpp Normal file
View File

@ -0,0 +1,55 @@
// Copyright 1998-2002 John Maddock
// Copyright 2017 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
//
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/regex
#include <boost/regex.hpp>
#include <boost/core/lightweight_test.hpp>
#include <string>
bool validate_card_format(const std::string& s)
{
static const boost::regex e("(\\d{4}[- ]){3}\\d{4}");
return boost::regex_match(s, e);
}
const boost::regex card_rx("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z");
const std::string machine_format("\\1\\2\\3\\4");
const std::string human_format("\\1-\\2-\\3-\\4");
std::string machine_readable_card_number(const std::string& s)
{
return boost::regex_replace(s, card_rx, machine_format, boost::match_default | boost::format_sed);
}
std::string human_readable_card_number(const std::string& s)
{
return boost::regex_replace(s, card_rx, human_format, boost::match_default | boost::format_sed);
}
int main()
{
std::string s[ 4 ] = { "0000111122223333", "0000 1111 2222 3333", "0000-1111-2222-3333", "000-1111-2222-3333" };
BOOST_TEST( !validate_card_format( s[0] ) );
BOOST_TEST_EQ( machine_readable_card_number( s[0] ), s[0] );
BOOST_TEST_EQ( human_readable_card_number( s[0] ), s[2] );
BOOST_TEST( validate_card_format( s[1] ) );
BOOST_TEST_EQ( machine_readable_card_number( s[1] ), s[0] );
BOOST_TEST_EQ( human_readable_card_number( s[1] ), s[2] );
BOOST_TEST( validate_card_format( s[2] ) );
BOOST_TEST_EQ( machine_readable_card_number( s[2] ), s[0] );
BOOST_TEST_EQ( human_readable_card_number( s[2] ), s[2] );
BOOST_TEST( !validate_card_format( s[3] ) );
return boost::report_errors();
}

View File

@ -169,5 +169,48 @@ void test_assertion_escapes()
TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl, L"abc\u2028bar", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl, L"abc\u2029bar", match_default, make_array(0, 4, -2, -2));
}
// Bug report: https://github.com/boostorg/regex/issues/40
TEST_REGEX_SEARCH("\\b", perl, "", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "", match_not_bow | match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "-", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "-", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "-", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\b", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "", match_not_bow | match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "-", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "-", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "-", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\<", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "", match_not_bow | match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "-", match_default, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "-", match_not_bow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "-", match_not_eow, make_array(-2, -2));
TEST_REGEX_SEARCH("\\>", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2));
// Bug report https://github.com/boostorg/regex/issues/57
// Line ending \R:
TEST_REGEX_SEARCH("\\R", perl | no_escape_in_lists, "foo\nbar", match_default, make_array(3, 4, -2, -2));
TEST_REGEX_SEARCH("\\R", perl | no_escape_in_lists, "foo\rbar", match_default, make_array(3, 4, -2, -2));
TEST_REGEX_SEARCH("\\R", perl | no_escape_in_lists, "foo\r\nbar", match_default, make_array(3, 5, -2, -2));
TEST_REGEX_SEARCH("(?x) abc \\R", perl | no_escape_in_lists, "abc\r\nbar", match_default, make_array(0, 5, -2, -2));
TEST_REGEX_SEARCH("(?x) abc \\R", perl | no_escape_in_lists, "abc\012bar", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH("(?x) abc \\R", perl | no_escape_in_lists, "abc\013bar", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH("(?x) abc \\R", perl | no_escape_in_lists, "abc\013bar", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH("(?x) abc \\R", perl | no_escape_in_lists, "abc\205bar", match_default, make_array(0, 4, -2, -2));
// see if \u works:
if(*w == 0x2028u)
{
TEST_REGEX_SEARCH_W(L"\\R", perl | no_escape_in_lists, L"foo\u2028bar", match_default, make_array(3, 4, -2, -2));
TEST_REGEX_SEARCH_W(L"\\R", perl | no_escape_in_lists, L"foo\u2029bar", match_default, make_array(3, 4, -2, -2));
TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl | no_escape_in_lists, L"abc\u2028bar", match_default, make_array(0, 4, -2, -2));
TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl | no_escape_in_lists, L"abc\u2029bar", match_default, make_array(0, 4, -2, -2));
}
}

View File

@ -33,16 +33,16 @@ namespace unnecessary_fix{
//
template <class Seq>
class back_insert_iterator
#ifndef BOOST_NO_STD_ITERATOR
: public std::iterator<std::output_iterator_tag,void,void,void,void>
#endif
{
private:
Seq* container;
public:
typedef const typename Seq::value_type value_type;
typedef Seq container_type;
typedef std::output_iterator_tag iterator_category;
typedef void difference_type;
typedef void pointer;
typedef void reference;
typedef std::output_iterator_tag iterator_category;
explicit back_insert_iterator(Seq& x) : container(&x) {}
back_insert_iterator& operator=(const value_type& val)

View File

@ -49,7 +49,9 @@ test_locale::test_locale(const char* c_name, boost::uint32_t lcid)
#else
s_c_locale = no_test;
#endif
#if !defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_EXCEPTIONS)
// Disabled for VC15.7 (and later?) as the C runtime asserts if you pass an invalid
// locale name to std::locale, rather than throwing the expected exception.
#if !defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_EXCEPTIONS) && !BOOST_WORKAROUND(BOOST_MSVC, > 1913)
// back up the C++ locale and create the new one:
m_old_cpp_locale = s_cpp_locale_inst;
m_old_cpp_state = s_cpp_locale;

View File

@ -65,8 +65,8 @@ void report_unexpected_exception(const E& e, int severity, const char* file, int
}
#define BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) \
catch(const std::exception& e) \
{ report_unexpected_exception(e, severity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); }\
catch(const std::exception& __e) \
{ report_unexpected_exception(__e, severity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); }\
catch(...)\
{ BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Exception of unknown type was thrown" << std::endl; report_severity(severity); }

29
test/test_warnings.cpp Normal file
View File

@ -0,0 +1,29 @@
/*
*
* Copyright (c) 2018
* John Maddock
*
* Use, modification and distribution are subject to the
* Boost Software License, Version 1.0. (See accompanying file
* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*
*/
#ifdef _MSC_VER
#pragma warning(disable:4820 4668)
#endif
#ifdef __APPLE_CC__
#pragma clang diagnostic ignored "-Wc++11-long-long"
#endif
#include <boost/regex.hpp>
void test_proc()
{
std::string text, re;
boost::regex exp(re);
regex_match(text, exp);
}

View File

@ -157,22 +157,30 @@ void spot_checks()
void test(const std::vector< ::boost::uint32_t>& v)
{
typedef std::vector< ::boost::uint32_t> vector32_type;
#ifdef TEST_UTF16
typedef std::vector< ::boost::uint16_t> vector16_type;
#endif
typedef std::vector< ::boost::uint8_t> vector8_type;
#ifdef TEST_UTF16
typedef boost::u32_to_u16_iterator<vector32_type::const_iterator, ::boost::uint16_t> u32to16type;
typedef boost::u16_to_u32_iterator<vector16_type::const_iterator, ::boost::uint32_t> u16to32type;
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_STD_ITERATOR) && !defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
typedef std::reverse_iterator<u32to16type> ru32to16type;
typedef std::reverse_iterator<u16to32type> ru16to32type;
#endif
#endif // TEST_UTF16
#ifdef TEST_UTF8
typedef boost::u32_to_u8_iterator<vector32_type::const_iterator, ::boost::uint8_t> u32to8type;
typedef boost::u8_to_u32_iterator<vector8_type::const_iterator, ::boost::uint32_t> u8to32type;
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_STD_ITERATOR) && !defined(_RWSTD_NO_CLASS_PARTIAL_SPEC)
typedef std::reverse_iterator<u32to8type> ru32to8type;
typedef std::reverse_iterator<u8to32type> ru8to32type;
#endif
#endif // TEST_UTF8
vector8_type v8;
#ifdef TEST_UTF16
vector16_type v16;
#endif
vector32_type v32;
vector32_type::const_iterator i, j, k;