6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
13 * LOCATION: see http://www.boost.org for most recent version.
14 * FILE regex_iterator.hpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Provides regex_iterator implementation.
19 #ifndef BOOST_REGEX_V4_REGEX_ITERATOR_HPP
20 #define BOOST_REGEX_V4_REGEX_ITERATOR_HPP
22 #include <boost/shared_ptr.hpp>
26 #ifdef BOOST_HAS_ABI_HEADERS
27 # include BOOST_ABI_PREFIX
30 template <class BidirectionalIterator,
34 class regex_iterator_implementation
36 typedef basic_regex<charT, traits, Allocator> regex_type;
38 match_results<BidirectionalIterator> what; // current match
39 BidirectionalIterator base; // start of sequence
40 BidirectionalIterator end; // end of sequence
41 const regex_type* pre; // the expression
42 match_flag_type flags; // flags for matching
45 regex_iterator_implementation(const regex_type* p, BidirectionalIterator last, match_flag_type f)
46 : base(), end(last), pre(p), flags(f){}
47 bool init(BidirectionalIterator first)
50 return regex_search(first, end, what, *pre, flags);
52 bool compare(const regex_iterator_implementation& that)
54 if(this == &that) return true;
55 return (pre == that.pre) && (end == that.end) && (flags == that.flags) && (what[0].first == that.what[0].first) && (what[0].second == that.what[0].second);
57 const match_results<BidirectionalIterator>& get()
61 if(what.prefix().first != what[0].second)
62 flags |= match_prev_avail;
63 BidirectionalIterator next_start = what[0].second;
64 match_flag_type f(flags);
66 f |= regex_constants::match_not_initial_null;
67 bool result = regex_search(next_start, end, what, *pre, f);
74 template <class BidirectionalIterator,
75 class charT = BOOST_DEDUCED_TYPENAME re_detail::regex_iterator_traits<BidirectionalIterator>::value_type,
76 class traits = regex_traits<charT>,
77 class Allocator = BOOST_DEFAULT_ALLOCATOR(charT) >
79 #ifndef BOOST_NO_STD_ITERATOR
80 : public std::iterator<
81 std::forward_iterator_tag,
82 match_results<BidirectionalIterator>,
83 typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type,
84 const match_results<BidirectionalIterator>*,
85 const match_results<BidirectionalIterator>& >
89 typedef regex_iterator_implementation<BidirectionalIterator, charT, traits, Allocator> impl;
90 typedef shared_ptr<impl> pimpl;
92 typedef basic_regex<charT, traits, Allocator> regex_type;
93 typedef match_results<BidirectionalIterator> value_type;
94 typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
96 typedef const value_type* pointer;
97 typedef const value_type& reference;
98 typedef std::forward_iterator_tag iterator_category;
101 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
102 const regex_type& re,
103 match_flag_type m = match_default)
104 : pdata(new impl(&re, b, m))
111 regex_iterator(const regex_iterator& that)
112 : pdata(that.pdata) {}
113 regex_iterator& operator=(const regex_iterator& that)
118 bool operator==(const regex_iterator& that)const
120 if((pdata.get() == 0) || (that.pdata.get() == 0))
121 return pdata.get() == that.pdata.get();
122 return pdata->compare(*(that.pdata.get()));
124 bool operator!=(const regex_iterator& that)const
125 { return !(*this == that); }
126 const value_type& operator*()const
127 { return pdata->get(); }
128 const value_type* operator->()const
129 { return &(pdata->get()); }
130 regex_iterator& operator++()
133 if(0 == pdata->next())
139 regex_iterator operator++(int)
141 regex_iterator result(*this);
152 if(pdata.get() && !pdata.unique())
154 pdata.reset(new impl(*(pdata.get())));
159 typedef regex_iterator<const char*> cregex_iterator;
160 typedef regex_iterator<std::string::const_iterator> sregex_iterator;
161 #ifndef BOOST_NO_WREGEX
162 typedef regex_iterator<const wchar_t*> wcregex_iterator;
163 typedef regex_iterator<std::wstring::const_iterator> wsregex_iterator;
166 #ifdef BOOST_HAS_ABI_HEADERS
167 # include BOOST_ABI_SUFFIX
172 #endif // BOOST_REGEX_V4_REGEX_ITERATOR_HPP