Recovering from cvs repository crash: readded regex iterator code.

[SVN r18360]
This commit is contained in:
John Maddock
2003-05-08 10:50:30 +00:00
parent c8f2ed3bdb
commit 7321d18f08
10 changed files with 523 additions and 101 deletions

View File

@ -463,7 +463,7 @@ void raise_error(const traits& t, unsigned code)
# undef BOOST_REGEX_HAS_MS_STACK_GUARD
# endif
# ifndef BOOST_REGEX_MAX_CACHE_BLOCKS
# define BOOST_REGEX_MAX_CACHE_BLOCKS BOOST_REGEX_MAX_BLOCKS
# define BOOST_REGEX_MAX_CACHE_BLOCKS 16
# endif
#endif

View File

@ -78,8 +78,7 @@
// #define BOOST_REGEX_MAX_BLOCKS 1024
// define this if you want to set the maximum number of memory blocks
// cached by the non-recursive algorithm: Normally this is the same as
// BOOST_REGEX_MAX_BLOCKS, but can be higher if you have multiple threads
// all using boost.regex, or lower if you don't want boost.regex to cache
// memory.
// #define BOOST_REGEX_MAX_CACHE_BLOCKS 1024
// cached by the non-recursive algorithm: Normally this is 16, but can be
// higher if you have multiple threads all using boost.regex, or lower
// if you don't want boost.regex to cache memory.
// #define BOOST_REGEX_MAX_CACHE_BLOCKS 16

View File

@ -51,7 +51,8 @@ typedef enum _match_flags
// uninterupted from the previous one
match_partial = match_continuous << 1, // find partial matches
match_stop = match_partial << 1, // stop after first match (grep)
match_stop = match_partial << 1, // stop after first match (grep) V3 only
match_not_initial_null = match_stop, // don't match initial null, V4 only
match_all = match_stop << 1, // must find the whole of input even if match_any is set
match_perl = match_all << 1, // Use perl matching rules
match_posix = match_perl << 1, // Use POSIX matching rules
@ -108,23 +109,23 @@ using regex_constants::match_not_eow;
using regex_constants::match_not_dot_newline;
using regex_constants::match_not_dot_null;
using regex_constants::match_prev_avail;
using regex_constants::match_init;
//using regex_constants::match_init;
using regex_constants::match_any;
using regex_constants::match_not_null;
using regex_constants::match_continuous;
using regex_constants::match_partial;
using regex_constants::match_stop;
//using regex_constants::match_stop;
using regex_constants::match_all;
using regex_constants::match_perl;
using regex_constants::match_posix;
using regex_constants::match_nosubs;
using regex_constants::match_max;
//using regex_constants::match_max;
using regex_constants::format_all;
using regex_constants::format_sed;
using regex_constants::format_perl;
using regex_constants::format_no_copy;
using regex_constants::format_first_only;
using regex_constants::format_is_if;
//using regex_constants::format_is_if;
} // namespace boost
#endif // __cplusplus

View File

@ -25,7 +25,7 @@
#define BOOST_REGEX_V4_PERL_MATCHER_COMMON_HPP
#ifdef __BORLANDC__
# pragma option push -a8 -b -Vx -Ve -pc -w-8027
# pragma option push -a8 -b -Vx -Ve -pc -w-8027 -w-8066 -w-8008
#endif
namespace boost{
@ -150,7 +150,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find()
#endif
state_count = 0;
if((m_match_flags & match_init) == 0)
if((m_match_flags & regex_constants::match_init) == 0)
{
// reset our state machine:
position = base;
@ -158,7 +158,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find()
pstate = access::first(re);
m_presult->set_size((m_match_flags & match_nosubs) ? 1 : re.mark_count(), base, last);
m_presult->set_base(base);
m_match_flags |= match_init;
m_match_flags |= regex_constants::match_init;
}
else
{
@ -296,6 +296,11 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_start_line
return true;
}
}
else if(traits_inst.is_separator(*t))
{
pstate = pstate->next.p;
return true;
}
return false;
}
@ -350,6 +355,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_match()
return false;
if((m_match_flags & match_all) && (position != last))
return false;
if((m_match_flags & regex_constants::match_not_initial_null) && (position == search_base))
return false;
m_presult->set_second(position);
pstate = 0;
m_has_found_match = true;
@ -671,7 +678,11 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::find_restart_lin
return false;
++position;
if(position == last)
{
if((access::first(re)->can_be_null) && match_prefix())
return true;
return false;
}
if( access::can_start(*position, _map, (unsigned char)mask_any) )
{

View File

@ -27,7 +27,7 @@
#include <new>
#ifdef __BORLANDC__
# pragma option push -a8 -b -Vx -Ve -pc -w-8027
# pragma option push -a8 -b -Vx -Ve -pc -w-8027 -w-8066 -w-8008
#endif
namespace boost{
@ -479,7 +479,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
++count;
}
// remember where we got to if this is a leading repeat:
if(rep->leading)
if((rep->leading) && (count < rep->max))
restart = position;
// push backtrack info if available:
if(count - rep->min)
@ -512,7 +512,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
if(rep->greedy)
{
if(rep->leading)
if((rep->leading) && (count < rep->max))
restart = position;
// push backtrack info if available:
if(count - rep->min)
@ -565,14 +565,13 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
++count;
}
}
if(rep->leading)
restart = position;
if(count < rep->min)
return false;
if(rep->greedy)
{
if(rep->leading)
if((rep->leading) && (count < rep->max))
restart = position;
// push backtrack info if available:
if(count - rep->min)
@ -627,14 +626,13 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
++count;
}
}
if(rep->leading)
restart = position;
if(count < rep->min)
return false;
if(rep->greedy)
{
if(rep->leading)
if((rep->leading) && (count < rep->max))
restart = position;
// push backtrack info if available:
if(count - rep->min)
@ -689,14 +687,13 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
++count;
}
}
if(rep->leading)
restart = position;
if(count < rep->min)
return false;
if(rep->greedy)
{
if(rep->leading)
if((rep->leading) && (count < rep->max))
restart = position;
// push backtrack info if available:
if(count - rep->min)
@ -903,6 +900,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_
pstate = rep->next.p;
position = pmp->last_position;
if(position != last)
{
// wind forward until we can skip out of the repeat:
do
{
@ -915,8 +914,15 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_slow_dot_
++count;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
if((count == rep->max) || (position == last))
}
if(position == last)
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(rep->can_be_null & mask_skip)
return true;
}
else if(count == rep->max)
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
@ -948,8 +954,9 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_
unsigned count = pmp->count;
assert(count < rep->max);
assert(position != last);
position = pmp->last_position;
if(position != last)
{
// wind forward until we can skip out of the repeat:
do
@ -957,8 +964,16 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_fast_dot_
++position;
++count;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
}
if((count == rep->max) || (position == last))
if(position == last)
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(rep->can_be_null & mask_skip)
return true;
}
else if(count == rep->max)
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
@ -996,9 +1011,10 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repe
assert(rep->next.p);
assert(rep->alt.p);
assert(rep->next.p->type == syntax_element_literal);
assert(position != last);
assert(count < rep->max);
if(position != last)
{
// wind forward until we can skip out of the repeat:
do
{
@ -1012,8 +1028,15 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_char_repe
++ position;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
if((count == rep->max) || (position == last))
}
if(position == last)
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(rep->can_be_null & mask_skip)
return true;
}
else if(count == rep->max)
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
@ -1051,9 +1074,10 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
assert(rep->next.p);
assert(rep->alt.p);
assert(rep->next.p->type == syntax_element_set);
assert(position != last);
assert(count < rep->max);
if(position != last)
{
// wind forward until we can skip out of the repeat:
do
{
@ -1067,8 +1091,15 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_short_set
++ position;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
if((count == rep->max) || (position == last))
}
if(position == last)
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(rep->can_be_null & mask_skip)
return true;
}
else if(count == rep->max)
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
@ -1109,6 +1140,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
assert(position != last);
assert(count < rep->max);
if(position != last)
{
// wind forward until we can skip out of the repeat:
do
{
@ -1122,8 +1155,15 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::unwind_long_set_
++count;
pstate = rep->next.p;
}while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip));
if((count == rep->max) || (position == last))
}
if(position == last)
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();
if(rep->can_be_null & mask_skip)
return true;
}
else if(count == rep->max)
{
// can't repeat any more, remove the pushed state:
destroy_single_repeat();

View File

@ -25,7 +25,7 @@
#define BOOST_REGEX_V4_PERL_MATCHER_RECURSIVE_HPP
#ifdef __BORLANDC__
# pragma option push -a8 -b -Vx -Ve -pc -w-8027
# pragma option push -a8 -b -Vx -Ve -pc -w-8027 -w-8066 -w-8008
#endif
namespace boost{
@ -294,7 +294,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
break;
++count;
}
if(rep->leading)
if((rep->leading) && (count < rep->max))
restart = position;
pstate = rep;
return backtrack_till_match(count - rep->min);
@ -305,7 +305,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
BidiIterator save_pos;
do
{
if(rep->leading)
if((rep->leading) && (rep->max == UINT_MAX))
restart = position;
pstate = rep->alt.p;
save_pos = position;
@ -342,6 +342,8 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
if(rep->min > count)
return false; // not enough text left to match
std::advance(position, count);
if((rep->leading) && (count < rep->max) && (rep->greedy))
restart = position;
if(rep->greedy)
return backtrack_till_match(count - rep->min);
@ -354,7 +356,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_dot_repeat
++position;
++count;
}
if(rep->leading)
if((rep->leading) && (count == UINT_MAX))
restart = position;
pstate = rep->alt.p;
save_pos = position;
@ -406,7 +408,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
++count;
}
}
if(rep->leading)
if((rep->leading) && (count < rep->max) && (rep->greedy))
restart = position;
if(count < rep->min)
return false;
@ -428,7 +430,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_char_repea
else
return false; // counldn't repeat even though it was the only option
}
if(rep->leading)
if((rep->leading) && (rep->max == UINT_MAX))
restart = position;
pstate = rep->alt.p;
save_pos = position;
@ -479,7 +481,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
++count;
}
}
if(rep->leading)
if((rep->leading) && (count < rep->max) && (rep->greedy))
restart = position;
if(count < rep->min)
return false;
@ -501,7 +503,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_set_repeat
else
return false; // counldn't repeat even though it was the only option
}
if(rep->leading)
if((rep->leading) && (rep->max == UINT_MAX))
restart = position;
pstate = rep->alt.p;
save_pos = position;
@ -552,7 +554,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
++count;
}
}
if(rep->leading)
if((rep->leading) && (count < rep->max) && (rep->greedy))
restart = position;
if(count < rep->min)
return false;
@ -574,7 +576,7 @@ bool perl_matcher<BidiIterator, Allocator, traits, Allocator2>::match_long_set_r
else
return false; // counldn't repeat even though it was the only option
}
if(rep->leading)
if((rep->leading) && (rep->max == UINT_MAX))
restart = position;
pstate = rep->alt.p;
save_pos = position;

View File

@ -154,6 +154,12 @@ typedef match_results<std::wstring::const_iterator> wsmatch;
#ifndef BOOST_REGEX_SPLIT_HPP
#include <boost/regex/v4/regex_split.hpp>
#endif
#ifndef BOOST_REGEX_ITERATOR_HPP
#include <boost/regex/v4/regex_iterator.hpp>
#endif
#ifndef BOOST_REGEX_TOKEN_ITERATOR_HPP
#include <boost/regex/v4/regex_token_iterator.hpp>
#endif
#endif // __cplusplus

View File

@ -364,7 +364,7 @@ expand_sub:
return out;
}
case traits_type::syntax_colon:
if(flags & format_is_if)
if(flags & regex_constants::format_is_if)
{
++fmt;
return out;
@ -396,7 +396,7 @@ expand_sub:
unsigned int id = traits_inst.toi(fmt, fmt_end, 10);
if(m[id].matched)
{
oi_assign(&out, _reg_format_aux(out, m, fmt, flags | format_is_if, traits_inst));
oi_assign(&out, _reg_format_aux(out, m, fmt, flags | regex_constants::format_is_if, traits_inst));
if(traits_inst.syntax_type((traits_size_type)(traits_uchar_type)(*(fmt-1))) == traits_type::syntax_colon)
re_skip_format(fmt, traits_inst);
}
@ -404,7 +404,7 @@ expand_sub:
{
re_skip_format(fmt, traits_inst);
if(traits_inst.syntax_type((traits_size_type)(traits_uchar_type)(*(fmt-1))) == traits_type::syntax_colon)
oi_assign(&out, _reg_format_aux(out, m, fmt, flags | format_is_if, traits_inst));
oi_assign(&out, _reg_format_aux(out, m, fmt, flags | regex_constants::format_is_if, traits_inst));
}
return out;
}

View File

@ -0,0 +1,154 @@
/*
*
* Copyright (c) 2003
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_iterator.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Provides regex_iterator implementation.
*/
#ifndef BOOST_REGEX_V4_REGEX_ITERATOR_HPP
#define BOOST_REGEX_V4_REGEX_ITERATOR_HPP
#include <boost/shared_ptr.hpp>
namespace boost{
template <class BidirectionalIterator,
class charT,
class traits,
class Allocator>
class regex_iterator_implementation
{
typedef basic_regex<charT, traits, Allocator> regex_type;
match_results<BidirectionalIterator> what; // current match
BidirectionalIterator base; // start of sequence
BidirectionalIterator end; // end of sequence
const regex_type* pre; // the expression
match_flag_type flags; // flags for matching
public:
regex_iterator_implementation(const regex_type* p, BidirectionalIterator last, match_flag_type f)
: base(), end(last), pre(p), flags(f){}
bool init(BidirectionalIterator first)
{
base = first;
return regex_search(first, end, what, *pre, flags);
}
bool compare(const regex_iterator_implementation& that)
{
if(this == &that) return true;
return (pre == that.pre) && (end == that.end) && (flags == that.flags) && (what[0].first == that.what[0].first) && (what[0].second == that.what[0].second);
}
const match_results<BidirectionalIterator>& get()
{ return what; }
bool next()
{
if(what.prefix().first != what[0].second)
flags |= match_prev_avail;
BidirectionalIterator next_start = what[0].second;
match_flag_type f(flags);
if(!what.length())
f |= regex_constants::match_not_initial_null;
bool result = regex_search(next_start, end, what, *pre, f);
if(result)
what.set_base(base);
return result;
}
};
template <class BidirectionalIterator,
class charT = typename re_detail::regex_iterator_traits<BidirectionalIterator>::value_type,
class traits = regex_traits<charT>,
class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) >
class regex_iterator
{
private:
typedef regex_iterator_implementation<BidirectionalIterator, charT, traits, Allocator> impl;
typedef shared_ptr<impl> pimpl;
public:
typedef basic_regex<charT, traits, Allocator> regex_type;
typedef match_results<BidirectionalIterator> value_type;
typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef std::forward_iterator_tag iterator_category;
regex_iterator(){}
regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re,
match_flag_type m = match_default)
: pdata(new impl(&re, b, m))
{
if(!pdata->init(a))
{
pdata.reset();
}
}
regex_iterator(const regex_iterator& that)
: pdata(that.pdata) {}
regex_iterator& operator=(const regex_iterator& that)
{
pdata = that.pdata;
return *this;
}
bool operator==(const regex_iterator& that)
{
if((pdata.get() == 0) || (that.pdata.get() == 0))
return pdata.get() == that.pdata.get();
return pdata->compare(*(that.pdata.get()));
}
bool operator!=(const regex_iterator& that)
{ return !(*this == that); }
const value_type& operator*()
{ return pdata->get(); }
const value_type* operator->()
{ return &(pdata->get()); }
regex_iterator& operator++()
{
cow();
if(0 == pdata->next())
{
pdata.reset();
}
return *this;
}
regex_iterator operator++(int)
{
regex_iterator result(*this);
++(*this);
return result;
}
private:
pimpl pdata;
void cow()
{
// copy-on-write
if(pdata.get() && !pdata.unique())
{
pdata.reset(new impl(*(pdata.get())));
}
}
};
} // namespace boost
#endif // BOOST_REGEX_V4_REGEX_ITERATOR_HPP

View File

@ -0,0 +1,209 @@
/*
*
* Copyright (c) 2003
* Dr John Maddock
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Dr John Maddock makes no representations
* about the suitability of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*
*/
/*
* LOCATION: see http://www.boost.org for most recent version.
* FILE regex_token_iterator.hpp
* VERSION see <boost/version.hpp>
* DESCRIPTION: Provides regex_token_iterator implementation.
*/
#ifndef BOOST_REGEX_V4_REGEX_TOKEN_ITERATOR_HPP
#define BOOST_REGEX_V4_REGEX_TOKEN_ITERATOR_HPP
#include <boost/shared_ptr.hpp>
namespace boost{
template <class BidirectionalIterator,
class charT,
class traits,
class Allocator>
class regex_token_iterator_implementation
{
typedef basic_regex<charT, traits, Allocator> regex_type;
typedef std::basic_string<charT> value_type;
match_results<BidirectionalIterator> what; // current match
BidirectionalIterator end; // end of search area
const regex_type* pre; // the expression
match_flag_type flags; // match flags
std::basic_string<charT> result; // the current string result
std::vector<int>::size_type N; // the current sub-expression being enumerated
std::vector<int> subs; // the sub-expressions to enumerate
public:
regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, int sub, match_flag_type f)
: end(last), pre(p), flags(f){ subs.push_back(sub); }
regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const std::vector<int>& v, match_flag_type f)
: end(last), pre(p), subs(v), flags(f){}
template <std::size_t N>
regex_token_iterator_implementation(const regex_type* p, BidirectionalIterator last, const int (&submatches)[N], match_flag_type f)
: end(last), pre(p), flags(f)
{
for(std::size_t i = 0; i < N; ++i)
subs.push_back(submatches[i]);
}
bool init(BidirectionalIterator first)
{
if(regex_search(first, end, what, *pre, flags) == true)
{
N = 0;
result = ((subs[N] == -1) ? value_type(what.prefix().str()) : value_type(what[(int)subs[N]].str()));
return true;
}
else if((N == -1) && (first != end))
{
result = value_type(first, end);
return true;
}
return false;
}
bool compare(const regex_token_iterator_implementation& that)
{
if(this == &that) return true;
return (pre == that.pre)
&& (end == that.end)
&& (flags == that.flags)
&& (N == that.N)
&& (what[0].first == that.what[0].first)
&& (what[0].second == that.what[0].second);
}
const std::basic_string<charT>& get()
{ return result; }
bool next()
{
if(N == -1)
return false;
if(N+1 < subs.size())
{
++N;
result =((subs[N] == -1) ? value_type(what.prefix().str()) : value_type(what[subs[N]].str()));
return true;
}
if(what.prefix().first != what[0].second)
flags |= match_prev_avail;
BidirectionalIterator last_end = what[0].second;
if(regex_search(what[0].second, end, what, *pre, ((what[0].first == what[0].second) ? flags | regex_constants::match_not_initial_null : flags)))
{
N =0;
result =((subs[N] == -1) ? value_type(what.prefix().str()) : value_type(what[subs[N]].str()));
return true;
}
else if((last_end != end) && (subs[0] == -1))
{
N =-1;
result =value_type(last_end, end);
return true;
}
return false;
}
};
template <class BidirectionalIterator,
class charT = typename re_detail::regex_iterator_traits<BidirectionalIterator>::value_type,
class traits = regex_traits<charT>,
class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) >
class regex_token_iterator
{
private:
typedef regex_token_iterator_implementation<BidirectionalIterator, charT, traits, Allocator> impl;
typedef shared_ptr<impl> pimpl;
public:
typedef basic_regex<charT, traits, Allocator> regex_type;
typedef std::basic_string<charT> value_type;
typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef std::forward_iterator_tag iterator_category;
regex_token_iterator(){}
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
int submatch = 0, match_flag_type m = match_default)
: pdata(new impl(&re, b, submatch, m))
{
if(!pdata->init(a))
pdata.reset();
}
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
const std::vector<int>& submatches, match_flag_type m = match_default)
: pdata(new impl(&re, b, submatches, m))
{
if(!pdata->init(a))
pdata.reset();
}
template <std::size_t N>
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, const regex_type& re,
const int (&submatches)[N], match_flag_type m = match_default)
: pdata(new impl(&re, b, submatches, m))
{
if(!pdata->init(a))
pdata.reset();
}
regex_token_iterator(const regex_token_iterator& that)
: pdata(that.pdata) {}
regex_token_iterator& operator=(const regex_token_iterator& that)
{
pdata = that.pdata;
return *this;
}
bool operator==(const regex_token_iterator& that)
{
if((pdata.get() == 0) || (that.pdata.get() == 0))
return pdata.get() == that.pdata.get();
return pdata->compare(*(that.pdata.get()));
}
bool operator!=(const regex_token_iterator& that)
{ return !(*this == that); }
const value_type& operator*()
{ return pdata->get(); }
const value_type* operator->()
{ return &(pdata->get()); }
regex_token_iterator& operator++()
{
cow();
if(0 == pdata->next())
{
pdata.reset();
}
return *this;
}
regex_token_iterator operator++(int)
{
regex_token_iterator result(*this);
++(*this);
return result;
}
private:
pimpl pdata;
void cow()
{
// copy-on-write
if(pdata.get() && !pdata.unique())
{
pdata.reset(new impl(*(pdata.get())));
}
}
};
} // namespace boost
#endif // BOOST_REGEX_V4_REGEX_TOKEN_ITERATOR_HPP