diff --git a/include/boost/regex/config.hpp b/include/boost/regex/config.hpp index 8817ef2c..7585aa56 100644 --- a/include/boost/regex/config.hpp +++ b/include/boost/regex/config.hpp @@ -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 diff --git a/include/boost/regex/user.hpp b/include/boost/regex/user.hpp index 37f18db8..fd5f45d1 100644 --- a/include/boost/regex/user.hpp +++ b/include/boost/regex/user.hpp @@ -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 diff --git a/include/boost/regex/v4/match_flags.hpp b/include/boost/regex/v4/match_flags.hpp index 8e033b20..b12c3519 100644 --- a/include/boost/regex/v4/match_flags.hpp +++ b/include/boost/regex/v4/match_flags.hpp @@ -51,11 +51,12 @@ 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 - match_nosubs = match_posix << 1, // don't trap marked subs + match_nosubs = match_posix << 1, // don't trap marked subs match_max = match_nosubs, format_perl = 0, // perl style replacement @@ -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 diff --git a/include/boost/regex/v4/perl_matcher_common.hpp b/include/boost/regex/v4/perl_matcher_common.hpp index 80501227..4a950467 100644 --- a/include/boost/regex/v4/perl_matcher_common.hpp +++ b/include/boost/regex/v4/perl_matcher_common.hpp @@ -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::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::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::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::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::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) ) { diff --git a/include/boost/regex/v4/perl_matcher_non_recursive.hpp b/include/boost/regex/v4/perl_matcher_non_recursive.hpp index e7f26cec..d1f85ae3 100644 --- a/include/boost/regex/v4/perl_matcher_non_recursive.hpp +++ b/include/boost/regex/v4/perl_matcher_non_recursive.hpp @@ -27,7 +27,7 @@ #include #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::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::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::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::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::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,20 +900,29 @@ bool perl_matcher::unwind_slow_dot_ pstate = rep->next.p; position = pmp->last_position; - // wind forward until we can skip out of the repeat: - do + if(position != last) { - if(!match_wild()) + // wind forward until we can skip out of the repeat: + do { - // failed repeat match, discard this state and look for another: - destroy_single_repeat(); + if(!match_wild()) + { + // failed repeat match, discard this state and look for another: + destroy_single_repeat(); + return true; + } + ++count; + pstate = rep->next.p; + }while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip)); + } + if(position == last) + { + // can't repeat any more, remove the pushed state: + destroy_single_repeat(); + if(rep->can_be_null & mask_skip) return true; - } - ++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)) + } + else if(count == rep->max) { // can't repeat any more, remove the pushed state: destroy_single_repeat(); @@ -948,17 +954,26 @@ bool perl_matcher::unwind_fast_dot_ unsigned count = pmp->count; assert(count < rep->max); - assert(position != last); position = pmp->last_position; - - // wind forward until we can skip out of the repeat: - do + if(position != last) { - ++position; - ++count; - }while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip)); - - if((count == rep->max) || (position == last)) + + // wind forward until we can skip out of the repeat: + do + { + ++position; + ++count; + }while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip)); + } + + 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,24 +1011,32 @@ bool perl_matcher::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); - // wind forward until we can skip out of the repeat: - do + if(position != last) { - if(traits_inst.translate(*position, icase) != what) + // wind forward until we can skip out of the repeat: + do { - // failed repeat match, discard this state and look for another: - destroy_single_repeat(); + if(traits_inst.translate(*position, icase) != what) + { + // failed repeat match, discard this state and look for another: + destroy_single_repeat(); + return true; + } + ++count; + ++ position; + pstate = rep->next.p; + }while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip)); + } + if(position == last) + { + // can't repeat any more, remove the pushed state: + destroy_single_repeat(); + if(rep->can_be_null & mask_skip) return true; - } - ++count; - ++ 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)) + } + else if(count == rep->max) { // can't repeat any more, remove the pushed state: destroy_single_repeat(); @@ -1051,24 +1074,32 @@ bool perl_matcher::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); - - // wind forward until we can skip out of the repeat: - do - { - if(!map[(traits_uchar_type)traits_inst.translate(*position, icase)]) - { - // failed repeat match, discard this state and look for another: - destroy_single_repeat(); - return true; - } - ++count; - ++ 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) + { + // wind forward until we can skip out of the repeat: + do + { + if(!map[(traits_uchar_type)traits_inst.translate(*position, icase)]) + { + // failed repeat match, discard this state and look for another: + destroy_single_repeat(); + return true; + } + ++count; + ++ position; + pstate = rep->next.p; + }while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip)); + } + 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,21 +1140,30 @@ bool perl_matcher::unwind_long_set_ assert(position != last); assert(count < rep->max); - // wind forward until we can skip out of the repeat: - do + if(position != last) { - if(position == re_is_set_member(position, last, set, re)) + // wind forward until we can skip out of the repeat: + do { - // failed repeat match, discard this state and look for another: - destroy_single_repeat(); + if(position == re_is_set_member(position, last, set, re)) + { + // failed repeat match, discard this state and look for another: + destroy_single_repeat(); + return true; + } + ++position; + ++count; + pstate = rep->next.p; + }while((count < rep->max) && (position != last) && !access::can_start(*position, rep->_map, mask_skip)); + } + if(position == last) + { + // can't repeat any more, remove the pushed state: + destroy_single_repeat(); + if(rep->can_be_null & mask_skip) return true; - } - ++position; - ++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)) + } + else if(count == rep->max) { // can't repeat any more, remove the pushed state: destroy_single_repeat(); diff --git a/include/boost/regex/v4/perl_matcher_recursive.hpp b/include/boost/regex/v4/perl_matcher_recursive.hpp index a832257f..1f1f9cd6 100644 --- a/include/boost/regex/v4/perl_matcher_recursive.hpp +++ b/include/boost/regex/v4/perl_matcher_recursive.hpp @@ -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::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::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::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::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::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::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::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::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::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::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; diff --git a/include/boost/regex/v4/regex.hpp b/include/boost/regex/v4/regex.hpp index c9a7a86d..34c3c4ea 100644 --- a/include/boost/regex/v4/regex.hpp +++ b/include/boost/regex/v4/regex.hpp @@ -154,6 +154,12 @@ typedef match_results wsmatch; #ifndef BOOST_REGEX_SPLIT_HPP #include #endif +#ifndef BOOST_REGEX_ITERATOR_HPP +#include +#endif +#ifndef BOOST_REGEX_TOKEN_ITERATOR_HPP +#include +#endif #endif // __cplusplus diff --git a/include/boost/regex/v4/regex_format.hpp b/include/boost/regex/v4/regex_format.hpp index 697a8ad5..e0331c26 100644 --- a/include/boost/regex/v4/regex_format.hpp +++ b/include/boost/regex/v4/regex_format.hpp @@ -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; } diff --git a/include/boost/regex/v4/regex_iterator.hpp b/include/boost/regex/v4/regex_iterator.hpp new file mode 100644 index 00000000..b19fb909 --- /dev/null +++ b/include/boost/regex/v4/regex_iterator.hpp @@ -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 + * DESCRIPTION: Provides regex_iterator implementation. + */ + +#ifndef BOOST_REGEX_V4_REGEX_ITERATOR_HPP +#define BOOST_REGEX_V4_REGEX_ITERATOR_HPP + +#include + +namespace boost{ + +template +class regex_iterator_implementation +{ + typedef basic_regex regex_type; + + match_results 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& 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 ::value_type, + class traits = regex_traits, + class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) > +class regex_iterator +{ +private: + typedef regex_iterator_implementation impl; + typedef shared_ptr pimpl; +public: + typedef basic_regex regex_type; + typedef match_results value_type; + typedef typename re_detail::regex_iterator_traits::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 diff --git a/include/boost/regex/v4/regex_token_iterator.hpp b/include/boost/regex/v4/regex_token_iterator.hpp new file mode 100644 index 00000000..39e1affd --- /dev/null +++ b/include/boost/regex/v4/regex_token_iterator.hpp @@ -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 + * DESCRIPTION: Provides regex_token_iterator implementation. + */ + +#ifndef BOOST_REGEX_V4_REGEX_TOKEN_ITERATOR_HPP +#define BOOST_REGEX_V4_REGEX_TOKEN_ITERATOR_HPP + +#include + +namespace boost{ + +template +class regex_token_iterator_implementation +{ + typedef basic_regex regex_type; + typedef std::basic_string value_type; + + match_results what; // current match + BidirectionalIterator end; // end of search area + const regex_type* pre; // the expression + match_flag_type flags; // match flags + std::basic_string result; // the current string result + std::vector::size_type N; // the current sub-expression being enumerated + std::vector 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& v, match_flag_type f) + : end(last), pre(p), subs(v), flags(f){} + template + 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& 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 ::value_type, + class traits = regex_traits, + class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) > +class regex_token_iterator +{ +private: + typedef regex_token_iterator_implementation impl; + typedef shared_ptr pimpl; +public: + typedef basic_regex regex_type; + typedef std::basic_string value_type; + typedef typename re_detail::regex_iterator_traits::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& submatches, match_flag_type m = match_default) + : pdata(new impl(&re, b, submatches, m)) + { + if(!pdata->init(a)) + pdata.reset(); + } + template + 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 \ No newline at end of file