6 * Use, modification and distribution are subject to the
\r
7 * Boost Software License, Version 1.0. (See accompanying file
\r
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
\r
13 * LOCATION: see http://www.boost.org for most recent version.
\r
14 * FILE u32regex_iterator.hpp
\r
15 * VERSION see <boost/version.hpp>
\r
16 * DESCRIPTION: Provides u32regex_iterator implementation.
\r
19 #ifndef BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
\r
20 #define BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
\r
24 #ifdef BOOST_HAS_ABI_HEADERS
\r
25 # include BOOST_ABI_PREFIX
\r
28 template <class BidirectionalIterator>
\r
29 class u32regex_iterator_implementation
\r
31 typedef u32regex regex_type;
\r
33 match_results<BidirectionalIterator> what; // current match
\r
34 BidirectionalIterator base; // start of sequence
\r
35 BidirectionalIterator end; // end of sequence
\r
36 const regex_type re; // the expression
\r
37 match_flag_type flags; // flags for matching
\r
40 u32regex_iterator_implementation(const regex_type* p, BidirectionalIterator last, match_flag_type f)
\r
41 : base(), end(last), re(*p), flags(f){}
\r
42 bool init(BidirectionalIterator first)
\r
45 return u32regex_search(first, end, what, re, flags, base);
\r
47 bool compare(const u32regex_iterator_implementation& that)
\r
49 if(this == &that) return true;
\r
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);
\r
52 const match_results<BidirectionalIterator>& get()
\r
56 //if(what.prefix().first != what[0].second)
\r
57 // flags |= match_prev_avail;
\r
58 BidirectionalIterator next_start = what[0].second;
\r
59 match_flag_type f(flags);
\r
61 f |= regex_constants::match_not_initial_null;
\r
62 //if(base != next_start)
\r
63 // f |= regex_constants::match_not_bob;
\r
64 bool result = u32regex_search(next_start, end, what, re, f, base);
\r
66 what.set_base(base);
\r
70 u32regex_iterator_implementation& operator=(const u32regex_iterator_implementation&);
\r
73 template <class BidirectionalIterator>
\r
74 class u32regex_iterator
\r
75 #ifndef BOOST_NO_STD_ITERATOR
\r
76 : public std::iterator<
\r
77 std::forward_iterator_tag,
\r
78 match_results<BidirectionalIterator>,
\r
79 typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type,
\r
80 const match_results<BidirectionalIterator>*,
\r
81 const match_results<BidirectionalIterator>& >
\r
85 typedef u32regex_iterator_implementation<BidirectionalIterator> impl;
\r
86 typedef shared_ptr<impl> pimpl;
\r
88 typedef u32regex regex_type;
\r
89 typedef match_results<BidirectionalIterator> value_type;
\r
90 typedef typename re_detail::regex_iterator_traits<BidirectionalIterator>::difference_type
\r
92 typedef const value_type* pointer;
\r
93 typedef const value_type& reference;
\r
94 typedef std::forward_iterator_tag iterator_category;
\r
96 u32regex_iterator(){}
\r
97 u32regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
\r
98 const regex_type& re,
\r
99 match_flag_type m = match_default)
\r
100 : pdata(new impl(&re, b, m))
\r
102 if(!pdata->init(a))
\r
107 u32regex_iterator(const u32regex_iterator& that)
\r
108 : pdata(that.pdata) {}
\r
109 u32regex_iterator& operator=(const u32regex_iterator& that)
\r
111 pdata = that.pdata;
\r
114 bool operator==(const u32regex_iterator& that)const
\r
116 if((pdata.get() == 0) || (that.pdata.get() == 0))
\r
117 return pdata.get() == that.pdata.get();
\r
118 return pdata->compare(*(that.pdata.get()));
\r
120 bool operator!=(const u32regex_iterator& that)const
\r
121 { return !(*this == that); }
\r
122 const value_type& operator*()const
\r
123 { return pdata->get(); }
\r
124 const value_type* operator->()const
\r
125 { return &(pdata->get()); }
\r
126 u32regex_iterator& operator++()
\r
129 if(0 == pdata->next())
\r
135 u32regex_iterator operator++(int)
\r
137 u32regex_iterator result(*this);
\r
148 if(pdata.get() && !pdata.unique())
\r
150 pdata.reset(new impl(*(pdata.get())));
\r
155 typedef u32regex_iterator<const char*> utf8regex_iterator;
\r
156 typedef u32regex_iterator<const UChar*> utf16regex_iterator;
\r
157 typedef u32regex_iterator<const UChar32*> utf32regex_iterator;
\r
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)
\r
161 return u32regex_iterator<const char*>(p, p+std::strlen(p), e, m);
\r
163 #ifndef BOOST_NO_WREGEX
\r
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)
\r
166 return u32regex_iterator<const wchar_t*>(p, p+std::wcslen(p), e, m);
\r
169 #if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2)
\r
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)
\r
172 return u32regex_iterator<const UChar*>(p, p+u_strlen(p), e, m);
\r
175 template <class charT, class Traits, class Alloc>
\r
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)
\r
178 typedef typename std::basic_string<charT, Traits, Alloc>::const_iterator iter_type;
\r
179 return u32regex_iterator<iter_type>(p.begin(), p.end(), e, m);
\r
181 inline u32regex_iterator<const UChar*> make_u32regex_iterator(const UnicodeString& s, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
\r
183 return u32regex_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, m);
\r
186 #ifdef BOOST_HAS_ABI_HEADERS
\r
187 # include BOOST_ABI_SUFFIX
\r
190 } // namespace boost
\r
192 #endif // BOOST_REGEX_V4_REGEX_ITERATOR_HPP
\r