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
75 #ifndef BOOST_NO_STD_ITERATOR
76 : public std::iterator<
77 std::forward_iterator_tag,
78 match_results<BidirectionalIterator>,
79 typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::difference_type,
80 const match_results<BidirectionalIterator>*,
81 const match_results<BidirectionalIterator>& >
85 typedef u32regex_iterator_implementation<BidirectionalIterator> impl;
86 typedef shared_ptr<impl> pimpl;
88 typedef u32regex regex_type;
89 typedef match_results<BidirectionalIterator> value_type;
90 typedef typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits<BidirectionalIterator>::difference_type
92 typedef const value_type* pointer;
93 typedef const value_type& reference;
94 typedef std::forward_iterator_tag iterator_category;
97 u32regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
99 match_flag_type m = match_default)
100 : pdata(new impl(&re, b, m))
107 u32regex_iterator(const u32regex_iterator& that)
108 : pdata(that.pdata) {}
109 u32regex_iterator& operator=(const u32regex_iterator& that)
114 bool operator==(const u32regex_iterator& that)const
116 if((pdata.get() == 0) || (that.pdata.get() == 0))
117 return pdata.get() == that.pdata.get();
118 return pdata->compare(*(that.pdata.get()));
120 bool operator!=(const u32regex_iterator& that)const
121 { return !(*this == that); }
122 const value_type& operator*()const
123 { return pdata->get(); }
124 const value_type* operator->()const
125 { return &(pdata->get()); }
126 u32regex_iterator& operator++()
129 if(0 == pdata->next())
135 u32regex_iterator operator++(int)
137 u32regex_iterator result(*this);
148 if(pdata.get() && !pdata.unique())
150 pdata.reset(new impl(*(pdata.get())));
155 typedef u32regex_iterator<const char*> utf8regex_iterator;
156 typedef u32regex_iterator<const UChar*> utf16regex_iterator;
157 typedef u32regex_iterator<const UChar32*> utf32regex_iterator;
159 inline u32regex_iterator<const char*> make_u32regex_iterator(const char* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
161 return u32regex_iterator<const char*>(p, p+std::strlen(p), e, m);
163 #ifndef BOOST_NO_WREGEX
164 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)
166 return u32regex_iterator<const wchar_t*>(p, p+std::wcslen(p), e, m);
169 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
170 inline u32regex_iterator<const UChar*> make_u32regex_iterator(const UChar* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
172 return u32regex_iterator<const UChar*>(p, p+u_strlen(p), e, m);
175 template <class charT, class Traits, class Alloc>
176 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)
178 typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
179 return u32regex_iterator<iter_type>(p.begin(), p.end(), e, m);
181 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)
183 return u32regex_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, m);
186 #ifdef BOOST_HAS_ABI_HEADERS
187 # include BOOST_ABI_SUFFIX
192 #endif // BOOST_REGEX_V4_REGEX_ITERATOR_HPP