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 u32regex_iterator.hpp
15 * VERSION see <boost/version.hpp>
16 * DESCRIPTION: Provides u32regex_iterator implementation.
19 #ifndef BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
20 #define BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
24 #ifdef BOOST_HAS_ABI_HEADERS
25 # include BOOST_ABI_PREFIX
28 template <class BidirectionalIterator>
29 class u32regex_iterator_implementation
31 typedef u32regex regex_type;
33 match_results<BidirectionalIterator> what; // current match
34 BidirectionalIterator base; // start of sequence
35 BidirectionalIterator end; // end of sequence
36 const regex_type re; // the expression
37 match_flag_type flags; // flags for matching
40 u32regex_iterator_implementation(const regex_type* p, BidirectionalIterator last, match_flag_type f)
41 : base(), end(last), re(*p), flags(f){}
42 bool init(BidirectionalIterator first)
45 return u32regex_search(first, end, what, re, flags, base);
47 bool compare(const u32regex_iterator_implementation& that)
49 if(this == &that) return true;
50 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);
52 const match_results<BidirectionalIterator>& get()
56 //if(what.prefix().first != what[0].second)
57 // flags |= match_prev_avail;
58 BidirectionalIterator next_start = what[0].second;
59 match_flag_type f(flags);
61 f |= regex_constants::match_not_initial_null;
62 //if(base != next_start)
63 // f |= regex_constants::match_not_bob;
64 bool result = u32regex_search(next_start, end, what, re, f, base);
70 u32regex_iterator_implementation& operator=(const u32regex_iterator_implementation&);
73 template <class BidirectionalIterator>
74 class u32regex_iterator
77 typedef u32regex_iterator_implementation<BidirectionalIterator> impl;
78 typedef shared_ptr<impl> pimpl;
80 typedef u32regex regex_type;
81 typedef match_results<BidirectionalIterator> value_type;
82 typedef typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::difference_type
84 typedef const value_type* pointer;
85 typedef const value_type& reference;
86 typedef std::forward_iterator_tag iterator_category;
89 u32regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
91 match_flag_type m = match_default)
92 : pdata(new impl(&re, b, m))
99 u32regex_iterator(const u32regex_iterator& that)
100 : pdata(that.pdata) {}
101 u32regex_iterator& operator=(const u32regex_iterator& that)
106 bool operator==(const u32regex_iterator& that)const
108 if((pdata.get() == 0) || (that.pdata.get() == 0))
109 return pdata.get() == that.pdata.get();
110 return pdata->compare(*(that.pdata.get()));
112 bool operator!=(const u32regex_iterator& that)const
113 { return !(*this == that); }
114 const value_type& operator*()const
115 { return pdata->get(); }
116 const value_type* operator->()const
117 { return &(pdata->get()); }
118 u32regex_iterator& operator++()
121 if(0 == pdata->next())
127 u32regex_iterator operator++(int)
129 u32regex_iterator result(*this);
140 if(pdata.get() && !pdata.unique())
142 pdata.reset(new impl(*(pdata.get())));
147 typedef u32regex_iterator<const char*> utf8regex_iterator;
148 typedef u32regex_iterator<const UChar*> utf16regex_iterator;
149 typedef u32regex_iterator<const UChar32*> utf32regex_iterator;
151 inline u32regex_iterator<const char*> make_u32regex_iterator(const char* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
153 return u32regex_iterator<const char*>(p, p+std::strlen(p), e, m);
155 #ifndef BOOST_NO_WREGEX
156 inline u32regex_iterator<const wchar_t*> make_u32regex_iterator(const wchar_t* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
158 return u32regex_iterator<const wchar_t*>(p, p+std::wcslen(p), e, m);
161 #if !defined(BOOST_REGEX_UCHAR_IS_WCHAR_T)
162 inline u32regex_iterator<const UChar*> make_u32regex_iterator(const UChar* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
164 return u32regex_iterator<const UChar*>(p, p+u_strlen(p), e, m);
167 template <class charT, class Traits, class Alloc>
168 inline u32regex_iterator<typename std::basic_string<charT, Traits, Alloc>::const_iterator> make_u32regex_iterator(const std::basic_string<charT, Traits, Alloc>& p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
170 typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
171 return u32regex_iterator<iter_type>(p.begin(), p.end(), e, m);
173 inline u32regex_iterator<const UChar*> make_u32regex_iterator(const U_NAMESPACE_QUALIFIER UnicodeString& s, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
175 return u32regex_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, m);
178 #ifdef BOOST_HAS_ABI_HEADERS
179 # include BOOST_ABI_SUFFIX
184 #endif // BOOST_REGEX_V4_REGEX_ITERATOR_HPP