Compare commits

...

12 Commits

Author SHA1 Message Date
799b09dc26 Define BOOST_REGEX_UCHAR_IS_WCHAR_T, use it to disable overloads 2017-12-24 01:49:32 +02:00
fe9d2a2d66 Merge pull request #54 from DanielaE/fix/no-iterator-inheritance
Inheritance from std::iterator is deprecated in c++17. Therefore repl…
2017-12-23 19:35:28 +00:00
59d501b07b Regex: fix integer shift warning/error in icu.cpp 2017-12-23 19:18:08 +00:00
d5bf5966e2 Merge pull request #53 from DanielaE/fix/replace-deprecated-allocator-members
replace members of std::allocate which are deprecated in c++17 by the…
2017-12-23 19:11:18 +00:00
912ba92bae Merge pull request #52 from rummt/patch-1
typo in error message 'openening' should be 'opening'
2017-12-23 19:03:15 +00:00
cc5a4e85ae Inheriting std::iterator is deprecated in c++17.
Therefore replace the inheritance by lifting std::iterator's members into the derived class. Fortunately, this is already done in Boost.Regex so that dropping the inheritance is a no-brainer.

Signed-off-by: Daniela Engert <dani@ngrt.de>
2017-12-22 15:59:49 +01:00
e6ce5523c6 replace members of std::allocate which are deprecated in c++17 by their cousins from std::allocator_traits.
Signed-off-by: Daniela Engert <dani@ngrt.de>
2017-12-21 17:48:23 +01:00
c60ee3189d Merge branch 'develop' of https://github.com/boostorg/regex into develop 2017-12-16 09:26:46 +00:00
e62d8b5332 Regex.C++17: Fix iterator usage. 2017-12-16 09:26:33 +00:00
a3f1cf9dfc typo in error message 'openening' should be 'opening' 2017-12-12 11:07:59 +00:00
47be67134a Fix -Wshadow warnings in quick.cpp 2017-12-03 00:36:11 +02:00
00e802c671 Add quick test target (for CI) 2017-12-02 18:24:00 +02:00
14 changed files with 106 additions and 59 deletions

View File

@ -67,18 +67,14 @@ ostream& operator << (ostream& os, const std::wstring& s)
template <class S>
class string_out_iterator
#ifndef BOOST_NO_STD_ITERATOR
: public std::iterator<std::output_iterator_tag, void, void, void, void>
#endif // ndef BOOST_NO_STD_ITERATOR
{
#ifdef BOOST_NO_STD_ITERATOR
public:
typedef std::output_iterator_tag iterator_category;
typedef void value_type;
typedef void difference_type;
typedef void pointer;
typedef void reference;
#endif // BOOST_NO_STD_ITERATOR
private:
S* out;
public:
string_out_iterator(S& s) : out(&s) {}

View File

@ -26,6 +26,7 @@
#include <boost/regex.hpp>
#include <boost/regex/pending/unicode_iterator.hpp>
#include <boost/mpl/int_fwd.hpp>
#include <boost/static_assert.hpp>
#include <bitset>
#ifdef BOOST_MSVC
@ -334,6 +335,34 @@ inline u32regex do_make_u32regex(InputIterator i,
#endif
}
// BOOST_REGEX_UCHAR_IS_WCHAR_T
//
// Source inspection of unicode/umachine.h in ICU version 59 indicates that:
//
// On version 59, UChar is always char16_t in C++ mode (and uint16_t in C mode)
//
// On earlier versions, the logic is
//
// #if U_SIZEOF_WCHAR_T==2
// typedef wchar_t OldUChar;
// #elif defined(__CHAR16_TYPE__)
// typedef __CHAR16_TYPE__ OldUChar;
// #else
// typedef uint16_t OldUChar;
// #endif
//
// That is, UChar is wchar_t only on versions below 59, when U_SIZEOF_WCHAR_T==2
//
// Hence,
#define BOOST_REGEX_UCHAR_IS_WCHAR_T (U_ICU_VERSION_MAJOR_NUM < 59 && U_SIZEOF_WCHAR_T == 2)
#if BOOST_REGEX_UCHAR_IS_WCHAR_T
BOOST_STATIC_ASSERT((boost::is_same<UChar, wchar_t>::value));
#else
BOOST_STATIC_ASSERT(!(boost::is_same<UChar, wchar_t>::value));
#endif
//
// Construction from an iterator pair:
//
@ -364,7 +393,7 @@ inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_o
return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast<boost::mpl::int_<sizeof(wchar_t)> const*>(0));
}
#endif
#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
#if !BOOST_REGEX_UCHAR_IS_WCHAR_T
inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl)
{
return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + u_strlen(p), opt, static_cast<boost::mpl::int_<2> const*>(0));
@ -481,7 +510,7 @@ inline bool u32regex_match(const UChar* p,
{
return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
}
#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
#if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
inline bool u32regex_match(const wchar_t* p,
match_results<const wchar_t*>& m,
const u32regex& e,
@ -545,7 +574,7 @@ inline bool u32regex_match(const UChar* p,
match_results<const UChar*> m;
return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast<mpl::int_<2> const*>(0));
}
#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
#if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
inline bool u32regex_match(const wchar_t* p,
const u32regex& e,
match_flag_type flags = match_default)
@ -666,7 +695,7 @@ inline bool u32regex_search(const UChar* p,
{
return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
}
#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
#if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
inline bool u32regex_search(const wchar_t* p,
match_results<const wchar_t*>& m,
const u32regex& e,
@ -727,7 +756,7 @@ inline bool u32regex_search(const UChar* p,
match_results<const UChar*> m;
return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast<mpl::int_<2> const*>(0));
}
#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX)
#if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX)
inline bool u32regex_search(const wchar_t* p,
const u32regex& e,
match_flag_type flags = match_default)

View File

@ -183,7 +183,7 @@ void basic_regex_parser<charT, traits>::parse(const charT* p1, const charT* p2,
// have had an unexpected ')' :
if(!result)
{
fail(regex_constants::error_paren, ::boost::BOOST_REGEX_DETAIL_NS::distance(m_base, m_position), "Found a closing ) with no corresponding openening parenthesis.");
fail(regex_constants::error_paren, ::boost::BOOST_REGEX_DETAIL_NS::distance(m_base, m_position), "Found a closing ) with no corresponding opening parenthesis.");
return;
}
// if an error has been set then give up now:

View File

@ -195,9 +195,6 @@ public:
};
class BOOST_REGEX_DECL mapfile_iterator
#if !defined(BOOST_NO_STD_ITERATOR) || defined(BOOST_MSVC_STD_ITERATOR)
: public std::iterator<std::random_access_iterator_tag, char>
#endif
{
typedef mapfile::pointer internal_pointer;
internal_pointer* node;

View File

@ -56,7 +56,9 @@ private:
#endif
public:
typedef sub_match<BidiIterator> value_type;
#if !defined(BOOST_NO_STD_ALLOCATOR) && !(defined(BOOST_MSVC) && defined(_STLPORT_VERSION))
#ifndef BOOST_NO_CXX11_ALLOCATOR
typedef typename std::allocator_traits<Allocator>::value_type const & const_reference;
#elif !defined(BOOST_NO_STD_ALLOCATOR) && !(defined(BOOST_MSVC) && defined(_STLPORT_VERSION))
typedef typename Allocator::const_reference const_reference;
#else
typedef const value_type& const_reference;
@ -66,7 +68,11 @@ public:
typedef const_iterator iterator;
typedef typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits<
BidiIterator>::difference_type difference_type;
#ifdef BOOST_NO_CXX11_ALLOCATOR
typedef typename Allocator::size_type size_type;
#else
typedef typename std::allocator_traits<Allocator>::size_type size_type;
#endif
typedef Allocator allocator_type;
typedef typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits<
BidiIterator>::value_type char_type;

View File

@ -800,9 +800,6 @@ void basic_regex_formatter<OutputIterator, Results, traits, ForwardIter>::put(co
template <class S>
class string_out_iterator
#ifndef BOOST_NO_STD_ITERATOR
: public std::iterator<std::output_iterator_tag, typename S::value_type>
#endif
{
S* out;
public:
@ -816,13 +813,11 @@ public:
return *this;
}
#ifdef BOOST_NO_STD_ITERATOR
typedef std::ptrdiff_t difference_type;
typedef typename S::value_type value_type;
typedef value_type* pointer;
typedef value_type& reference;
typedef std::output_iterator_tag iterator_category;
#endif
};
template <class OutputIterator, class Iterator, class Alloc, class ForwardIter, class traits>

View File

@ -85,14 +85,6 @@ template <class BidirectionalIterator,
class charT = BOOST_DEDUCED_TYPENAME BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::value_type,
class traits = regex_traits<charT> >
class regex_iterator
#ifndef BOOST_NO_STD_ITERATOR
: public std::iterator<
std::forward_iterator_tag,
match_results<BidirectionalIterator>,
typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::difference_type,
const match_results<BidirectionalIterator>*,
const match_results<BidirectionalIterator>& >
#endif
{
private:
typedef regex_iterator_implementation<BidirectionalIterator, charT, traits> impl;

View File

@ -167,14 +167,6 @@ template <class BidirectionalIterator,
class charT = BOOST_DEDUCED_TYPENAME BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::value_type,
class traits = regex_traits<charT> >
class regex_token_iterator
#ifndef BOOST_NO_STD_ITERATOR
: public std::iterator<
std::forward_iterator_tag,
sub_match<BidirectionalIterator>,
typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::difference_type,
const sub_match<BidirectionalIterator>*,
const sub_match<BidirectionalIterator>& >
#endif
{
private:
typedef regex_token_iterator_implementation<BidirectionalIterator, charT, traits> impl;

View File

@ -72,14 +72,6 @@ private:
template <class BidirectionalIterator>
class u32regex_iterator
#ifndef BOOST_NO_STD_ITERATOR
: public std::iterator<
std::forward_iterator_tag,
match_results<BidirectionalIterator>,
typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::difference_type,
const match_results<BidirectionalIterator>*,
const match_results<BidirectionalIterator>& >
#endif
{
private:
typedef u32regex_iterator_implementation<BidirectionalIterator> impl;

View File

@ -155,14 +155,6 @@ private:
template <class BidirectionalIterator>
class u32regex_token_iterator
#ifndef BOOST_NO_STD_ITERATOR
: public std::iterator<
std::forward_iterator_tag,
sub_match<BidirectionalIterator>,
typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::difference_type,
const sub_match<BidirectionalIterator>*,
const sub_match<BidirectionalIterator>& >
#endif
{
private:
typedef u32regex_token_iterator_implementation<BidirectionalIterator> impl;

View File

@ -481,7 +481,7 @@ icu_regex_traits::string_type icu_regex_traits::lookup_collatename(const char_ty
bool icu_regex_traits::isctype(char_type c, char_class_type f) const
{
// check for standard catagories first:
char_class_type m = char_class_type(1u << u_charType(c));
char_class_type m = char_class_type(1uLL << u_charType(c));
if((m & f) != 0)
return true;
// now check for special cases:

View File

@ -194,4 +194,5 @@ compile test_consolidated.cpp ;
build-project ../example ;
# `quick` target (for CI)
run quick.cpp ../build//boost_regex ;

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

@ -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)