]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/regex/v4/u32regex_iterator.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / regex / v4 / u32regex_iterator.hpp
CommitLineData
7c673cae
FG
1/*
2 *
3 * Copyright (c) 2003
4 * John Maddock
5 *
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)
9 *
10 */
11
12 /*
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.
17 */
18
19#ifndef BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
20#define BOOST_REGEX_V4_U32REGEX_ITERATOR_HPP
21
22namespace boost{
23
24#ifdef BOOST_HAS_ABI_HEADERS
25# include BOOST_ABI_PREFIX
26#endif
27
28template <class BidirectionalIterator>
29class u32regex_iterator_implementation
30{
31 typedef u32regex regex_type;
32
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
38
39public:
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)
43 {
44 base = first;
45 return u32regex_search(first, end, what, re, flags, base);
46 }
47 bool compare(const u32regex_iterator_implementation& that)
48 {
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);
51 }
52 const match_results<BidirectionalIterator>& get()
53 { return what; }
54 bool next()
55 {
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);
60 if(!what.length())
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);
65 if(result)
66 what.set_base(base);
67 return result;
68 }
69private:
70 u32regex_iterator_implementation& operator=(const u32regex_iterator_implementation&);
71};
72
73template <class BidirectionalIterator>
74class u32regex_iterator
7c673cae
FG
75{
76private:
77 typedef u32regex_iterator_implementation<BidirectionalIterator> impl;
78 typedef shared_ptr<impl> pimpl;
79public:
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
83 difference_type;
84 typedef const value_type* pointer;
85 typedef const value_type& reference;
86 typedef std::forward_iterator_tag iterator_category;
87
88 u32regex_iterator(){}
89 u32regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
90 const regex_type& re,
91 match_flag_type m = match_default)
92 : pdata(new impl(&re, b, m))
93 {
94 if(!pdata->init(a))
95 {
96 pdata.reset();
97 }
98 }
99 u32regex_iterator(const u32regex_iterator& that)
100 : pdata(that.pdata) {}
101 u32regex_iterator& operator=(const u32regex_iterator& that)
102 {
103 pdata = that.pdata;
104 return *this;
105 }
106 bool operator==(const u32regex_iterator& that)const
107 {
108 if((pdata.get() == 0) || (that.pdata.get() == 0))
109 return pdata.get() == that.pdata.get();
110 return pdata->compare(*(that.pdata.get()));
111 }
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++()
119 {
120 cow();
121 if(0 == pdata->next())
122 {
123 pdata.reset();
124 }
125 return *this;
126 }
127 u32regex_iterator operator++(int)
128 {
129 u32regex_iterator result(*this);
130 ++(*this);
131 return result;
132 }
133private:
134
135 pimpl pdata;
136
137 void cow()
138 {
139 // copy-on-write
140 if(pdata.get() && !pdata.unique())
141 {
142 pdata.reset(new impl(*(pdata.get())));
143 }
144 }
145};
146
147typedef u32regex_iterator<const char*> utf8regex_iterator;
148typedef u32regex_iterator<const UChar*> utf16regex_iterator;
149typedef u32regex_iterator<const UChar32*> utf32regex_iterator;
150
151inline u32regex_iterator<const char*> make_u32regex_iterator(const char* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
152{
153 return u32regex_iterator<const char*>(p, p+std::strlen(p), e, m);
154}
155#ifndef BOOST_NO_WREGEX
156inline 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)
157{
158 return u32regex_iterator<const wchar_t*>(p, p+std::wcslen(p), e, m);
159}
160#endif
92f5a8d4 161#if !defined(BOOST_REGEX_UCHAR_IS_WCHAR_T)
7c673cae
FG
162inline u32regex_iterator<const UChar*> make_u32regex_iterator(const UChar* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default)
163{
164 return u32regex_iterator<const UChar*>(p, p+u_strlen(p), e, m);
165}
166#endif
167template <class charT, class Traits, class Alloc>
168inline 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)
169{
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);
172}
173inline 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)
174{
175 return u32regex_iterator<const UChar*>(s.getBuffer(), s.getBuffer() + s.length(), e, m);
176}
177
178#ifdef BOOST_HAS_ABI_HEADERS
179# include BOOST_ABI_SUFFIX
180#endif
181
182} // namespace boost
183
184#endif // BOOST_REGEX_V4_REGEX_ITERATOR_HPP
185