forked from boostorg/regex
Compare commits
12 Commits
boost-1.67
...
pr/fix-uch
Author | SHA1 | Date | |
---|---|---|---|
799b09dc26 | |||
fe9d2a2d66 | |||
59d501b07b | |||
d5bf5966e2 | |||
912ba92bae | |||
cc5a4e85ae | |||
e6ce5523c6 | |||
c60ee3189d | |||
e62d8b5332 | |||
a3f1cf9dfc | |||
47be67134a | |||
00e802c671 |
@ -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) {}
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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
55
test/quick.cpp
Normal 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();
|
||||
}
|
@ -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)
|
||||
|
Reference in New Issue
Block a user