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>
28 #pragma warning(disable: 4103)
30 #ifdef BOOST_HAS_ABI_HEADERS
31 # include BOOST_ABI_PREFIX
37 template <class BidirectionalIterator,
40 class regex_iterator_implementation
42 typedef basic_regex<charT, traits> regex_type;
44 match_results<BidirectionalIterator> what; // current match
45 BidirectionalIterator base; // start of sequence
46 BidirectionalIterator end; // end of sequence
47 const regex_type re; // the expression
48 match_flag_type flags; // flags for matching
51 regex_iterator_implementation(const regex_type* p, BidirectionalIterator last, match_flag_type f)
52 : base(), end(last), re(*p), flags(f){}
53 bool init(BidirectionalIterator first)
56 return regex_search(first, end, what, re, flags);
58 bool compare(const regex_iterator_implementation& that)
60 if(this == &that) return true;
61 return (&re.get_data() == &that.re.get_data()) && (end == that.end) && (flags == that.flags) && (what[0].first == that.what[0].first) && (what[0].second == that.what[0].second);
63 const match_results<BidirectionalIterator>& get()
67 //if(what.prefix().first != what[0].second)
68 // flags |= match_prev_avail;
69 BidirectionalIterator next_start = what[0].second;
70 match_flag_type f(flags);
72 f |= regex_constants::match_not_initial_null;
73 //if(base != next_start)
74 // f |= regex_constants::match_not_bob;
75 bool result = regex_search(next_start, end, what, re, f, base);
81 regex_iterator_implementation& operator=(const regex_iterator_implementation&);
84 template <class BidirectionalIterator,
85 class charT = BOOST_DEDUCED_TYPENAME re_detail::regex_iterator_traits<BidirectionalIterator>::value_type,
86 class traits = regex_traits<charT> >
88 #ifndef BOOST_NO_STD_ITERATOR
89 : public std::iterator<
90 std::forward_iterator_tag,
91 match_results<BidirectionalIterator>,
92 typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type,
93 const match_results<BidirectionalIterator>*,
94 const match_results<BidirectionalIterator>& >
98 typedef regex_iterator_implementation<BidirectionalIterator, charT, traits> impl;
99 typedef shared_ptr<impl> pimpl;
101 typedef basic_regex<charT, traits> regex_type;
102 typedef match_results<BidirectionalIterator> value_type;
103 typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
105 typedef const value_type* pointer;
106 typedef const value_type& reference;
107 typedef std::forward_iterator_tag iterator_category;
110 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
111 const regex_type& re,
112 match_flag_type m = match_default)
113 : pdata(new impl(&re, b, m))
120 regex_iterator(const regex_iterator& that)
121 : pdata(that.pdata) {}
122 regex_iterator& operator=(const regex_iterator& that)
127 bool operator==(const regex_iterator& that)const
129 if((pdata.get() == 0) || (that.pdata.get() == 0))
130 return pdata.get() == that.pdata.get();
131 return pdata->compare(*(that.pdata.get()));
133 bool operator!=(const regex_iterator& that)const
134 { return !(*this == that); }
135 const value_type& operator*()const
136 { return pdata->get(); }
137 const value_type* operator->()const
138 { return &(pdata->get()); }
139 regex_iterator& operator++()
142 if(0 == pdata->next())
148 regex_iterator operator++(int)
150 regex_iterator result(*this);
161 if(pdata.get() && !pdata.unique())
163 pdata.reset(new impl(*(pdata.get())));
168 typedef regex_iterator<const char*> cregex_iterator;
169 typedef regex_iterator<std::string::const_iterator> sregex_iterator;
170 #ifndef BOOST_NO_WREGEX
171 typedef regex_iterator<const wchar_t*> wcregex_iterator;
172 typedef regex_iterator<std::wstring::const_iterator> wsregex_iterator;
175 // make_regex_iterator:
176 template <class charT, class traits>
177 inline regex_iterator<const charT*, charT, traits> make_regex_iterator(const charT* p, const basic_regex<charT, traits>& e, regex_constants::match_flag_type m = regex_constants::match_default)
179 return regex_iterator<const charT*, charT, traits>(p, p+traits::length(p), e, m);
181 template <class charT, class traits, class ST, class SA>
182 inline regex_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits> make_regex_iterator(const std::basic_string<charT, ST, SA>& p, const basic_regex<charT, traits>& e, regex_constants::match_flag_type m = regex_constants::match_default)
184 return regex_iterator<typename std::basic_string<charT, ST, SA>::const_iterator, charT, traits>(p.begin(), p.end(), e, m);
188 #pragma warning(push)
189 #pragma warning(disable: 4103)
191 #ifdef BOOST_HAS_ABI_HEADERS
192 # include BOOST_ABI_SUFFIX
200 #endif // BOOST_REGEX_V4_REGEX_ITERATOR_HPP