Chris@16
|
1 /*
|
Chris@16
|
2 *
|
Chris@16
|
3 * Copyright (c) 1998-2004 John Maddock
|
Chris@16
|
4 * Copyright 2011 Garmin Ltd. or its subsidiaries
|
Chris@16
|
5 *
|
Chris@16
|
6 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
7 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
8 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 *
|
Chris@16
|
10 */
|
Chris@16
|
11
|
Chris@16
|
12 /*
|
Chris@16
|
13 * LOCATION: see http://www.boost.org/ for most recent version.
|
Chris@16
|
14 * FILE basic_regex.cpp
|
Chris@16
|
15 * VERSION see <boost/version.hpp>
|
Chris@16
|
16 * DESCRIPTION: Declares template class basic_regex.
|
Chris@16
|
17 */
|
Chris@16
|
18
|
Chris@16
|
19 #ifndef BOOST_REGEX_V4_BASIC_REGEX_HPP
|
Chris@16
|
20 #define BOOST_REGEX_V4_BASIC_REGEX_HPP
|
Chris@16
|
21
|
Chris@16
|
22 #include <boost/type_traits/is_same.hpp>
|
Chris@16
|
23 #include <boost/functional/hash.hpp>
|
Chris@16
|
24
|
Chris@16
|
25 #ifdef BOOST_MSVC
|
Chris@16
|
26 #pragma warning(push)
|
Chris@16
|
27 #pragma warning(disable: 4103)
|
Chris@16
|
28 #endif
|
Chris@16
|
29 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
30 # include BOOST_ABI_PREFIX
|
Chris@16
|
31 #endif
|
Chris@16
|
32 #ifdef BOOST_MSVC
|
Chris@16
|
33 #pragma warning(pop)
|
Chris@16
|
34 #endif
|
Chris@16
|
35
|
Chris@16
|
36 namespace boost{
|
Chris@16
|
37 #ifdef BOOST_MSVC
|
Chris@16
|
38 #pragma warning(push)
|
Chris@16
|
39 #pragma warning(disable : 4251 4231 4800)
|
Chris@16
|
40 #if BOOST_MSVC < 1600
|
Chris@16
|
41 #pragma warning(disable : 4660)
|
Chris@16
|
42 #endif
|
Chris@16
|
43 #endif
|
Chris@16
|
44
|
Chris@16
|
45 namespace re_detail{
|
Chris@16
|
46
|
Chris@16
|
47 //
|
Chris@16
|
48 // forward declaration, we will need this one later:
|
Chris@16
|
49 //
|
Chris@16
|
50 template <class charT, class traits>
|
Chris@16
|
51 class basic_regex_parser;
|
Chris@16
|
52
|
Chris@16
|
53 template <class I>
|
Chris@16
|
54 void bubble_down_one(I first, I last)
|
Chris@16
|
55 {
|
Chris@16
|
56 if(first != last)
|
Chris@16
|
57 {
|
Chris@16
|
58 I next = last - 1;
|
Chris@16
|
59 while((next != first) && (*next < *(next-1)))
|
Chris@16
|
60 {
|
Chris@16
|
61 (next-1)->swap(*next);
|
Chris@16
|
62 --next;
|
Chris@16
|
63 }
|
Chris@16
|
64 }
|
Chris@16
|
65 }
|
Chris@16
|
66
|
Chris@16
|
67 template <class Iterator>
|
Chris@16
|
68 inline int hash_value_from_capture_name(Iterator i, Iterator j)
|
Chris@16
|
69 {
|
Chris@16
|
70 std::size_t r = boost::hash_range(i, j);
|
Chris@16
|
71 r %= ((std::numeric_limits<int>::max)() - 10001);
|
Chris@16
|
72 r += 10000;
|
Chris@16
|
73 return static_cast<int>(r);
|
Chris@16
|
74 }
|
Chris@16
|
75
|
Chris@16
|
76 class named_subexpressions
|
Chris@16
|
77 {
|
Chris@16
|
78 public:
|
Chris@16
|
79 struct name
|
Chris@16
|
80 {
|
Chris@16
|
81 template <class charT>
|
Chris@16
|
82 name(const charT* i, const charT* j, int idx)
|
Chris@16
|
83 : index(idx)
|
Chris@16
|
84 {
|
Chris@16
|
85 hash = hash_value_from_capture_name(i, j);
|
Chris@16
|
86 }
|
Chris@16
|
87 name(int h, int idx)
|
Chris@16
|
88 : index(idx), hash(h)
|
Chris@16
|
89 {
|
Chris@16
|
90 }
|
Chris@16
|
91 int index;
|
Chris@16
|
92 int hash;
|
Chris@16
|
93 bool operator < (const name& other)const
|
Chris@16
|
94 {
|
Chris@16
|
95 return hash < other.hash;
|
Chris@16
|
96 }
|
Chris@16
|
97 bool operator == (const name& other)const
|
Chris@16
|
98 {
|
Chris@16
|
99 return hash == other.hash;
|
Chris@16
|
100 }
|
Chris@16
|
101 void swap(name& other)
|
Chris@16
|
102 {
|
Chris@16
|
103 std::swap(index, other.index);
|
Chris@16
|
104 std::swap(hash, other.hash);
|
Chris@16
|
105 }
|
Chris@16
|
106 };
|
Chris@16
|
107
|
Chris@16
|
108 typedef std::vector<name>::const_iterator const_iterator;
|
Chris@16
|
109 typedef std::pair<const_iterator, const_iterator> range_type;
|
Chris@16
|
110
|
Chris@16
|
111 named_subexpressions(){}
|
Chris@16
|
112
|
Chris@16
|
113 template <class charT>
|
Chris@16
|
114 void set_name(const charT* i, const charT* j, int index)
|
Chris@16
|
115 {
|
Chris@16
|
116 m_sub_names.push_back(name(i, j, index));
|
Chris@16
|
117 bubble_down_one(m_sub_names.begin(), m_sub_names.end());
|
Chris@16
|
118 }
|
Chris@16
|
119 template <class charT>
|
Chris@16
|
120 int get_id(const charT* i, const charT* j)const
|
Chris@16
|
121 {
|
Chris@16
|
122 name t(i, j, 0);
|
Chris@16
|
123 typename std::vector<name>::const_iterator pos = std::lower_bound(m_sub_names.begin(), m_sub_names.end(), t);
|
Chris@16
|
124 if((pos != m_sub_names.end()) && (*pos == t))
|
Chris@16
|
125 {
|
Chris@16
|
126 return pos->index;
|
Chris@16
|
127 }
|
Chris@16
|
128 return -1;
|
Chris@16
|
129 }
|
Chris@16
|
130 template <class charT>
|
Chris@16
|
131 range_type equal_range(const charT* i, const charT* j)const
|
Chris@16
|
132 {
|
Chris@16
|
133 name t(i, j, 0);
|
Chris@16
|
134 return std::equal_range(m_sub_names.begin(), m_sub_names.end(), t);
|
Chris@16
|
135 }
|
Chris@16
|
136 int get_id(int h)const
|
Chris@16
|
137 {
|
Chris@16
|
138 name t(h, 0);
|
Chris@16
|
139 std::vector<name>::const_iterator pos = std::lower_bound(m_sub_names.begin(), m_sub_names.end(), t);
|
Chris@16
|
140 if((pos != m_sub_names.end()) && (*pos == t))
|
Chris@16
|
141 {
|
Chris@16
|
142 return pos->index;
|
Chris@16
|
143 }
|
Chris@16
|
144 return -1;
|
Chris@16
|
145 }
|
Chris@16
|
146 range_type equal_range(int h)const
|
Chris@16
|
147 {
|
Chris@16
|
148 name t(h, 0);
|
Chris@16
|
149 return std::equal_range(m_sub_names.begin(), m_sub_names.end(), t);
|
Chris@16
|
150 }
|
Chris@16
|
151 private:
|
Chris@16
|
152 std::vector<name> m_sub_names;
|
Chris@16
|
153 };
|
Chris@16
|
154
|
Chris@16
|
155 //
|
Chris@16
|
156 // class regex_data:
|
Chris@16
|
157 // represents the data we wish to expose to the matching algorithms.
|
Chris@16
|
158 //
|
Chris@16
|
159 template <class charT, class traits>
|
Chris@16
|
160 struct regex_data : public named_subexpressions
|
Chris@16
|
161 {
|
Chris@16
|
162 typedef regex_constants::syntax_option_type flag_type;
|
Chris@16
|
163 typedef std::size_t size_type;
|
Chris@16
|
164
|
Chris@16
|
165 regex_data(const ::boost::shared_ptr<
|
Chris@16
|
166 ::boost::regex_traits_wrapper<traits> >& t)
|
Chris@16
|
167 : m_ptraits(t), m_expression(0), m_expression_len(0) {}
|
Chris@16
|
168 regex_data()
|
Chris@16
|
169 : m_ptraits(new ::boost::regex_traits_wrapper<traits>()), m_expression(0), m_expression_len(0) {}
|
Chris@16
|
170
|
Chris@16
|
171 ::boost::shared_ptr<
|
Chris@16
|
172 ::boost::regex_traits_wrapper<traits>
|
Chris@16
|
173 > m_ptraits; // traits class instance
|
Chris@16
|
174 flag_type m_flags; // flags with which we were compiled
|
Chris@16
|
175 int m_status; // error code (0 implies OK).
|
Chris@16
|
176 const charT* m_expression; // the original expression
|
Chris@16
|
177 std::ptrdiff_t m_expression_len; // the length of the original expression
|
Chris@16
|
178 size_type m_mark_count; // the number of marked sub-expressions
|
Chris@16
|
179 re_detail::re_syntax_base* m_first_state; // the first state of the machine
|
Chris@16
|
180 unsigned m_restart_type; // search optimisation type
|
Chris@16
|
181 unsigned char m_startmap[1 << CHAR_BIT]; // which characters can start a match
|
Chris@16
|
182 unsigned int m_can_be_null; // whether we can match a null string
|
Chris@16
|
183 re_detail::raw_storage m_data; // the buffer in which our states are constructed
|
Chris@16
|
184 typename traits::char_class_type m_word_mask; // mask used to determine if a character is a word character
|
Chris@16
|
185 std::vector<
|
Chris@16
|
186 std::pair<
|
Chris@16
|
187 std::size_t, std::size_t> > m_subs; // Position of sub-expressions within the *string*.
|
Chris@16
|
188 bool m_has_recursions; // whether we have recursive expressions;
|
Chris@16
|
189 };
|
Chris@16
|
190 //
|
Chris@16
|
191 // class basic_regex_implementation
|
Chris@16
|
192 // pimpl implementation class for basic_regex.
|
Chris@16
|
193 //
|
Chris@16
|
194 template <class charT, class traits>
|
Chris@16
|
195 class basic_regex_implementation
|
Chris@16
|
196 : public regex_data<charT, traits>
|
Chris@16
|
197 {
|
Chris@16
|
198 public:
|
Chris@16
|
199 typedef regex_constants::syntax_option_type flag_type;
|
Chris@16
|
200 typedef std::ptrdiff_t difference_type;
|
Chris@16
|
201 typedef std::size_t size_type;
|
Chris@16
|
202 typedef typename traits::locale_type locale_type;
|
Chris@16
|
203 typedef const charT* const_iterator;
|
Chris@16
|
204
|
Chris@16
|
205 basic_regex_implementation(){}
|
Chris@16
|
206 basic_regex_implementation(const ::boost::shared_ptr<
|
Chris@16
|
207 ::boost::regex_traits_wrapper<traits> >& t)
|
Chris@16
|
208 : regex_data<charT, traits>(t) {}
|
Chris@16
|
209 void assign(const charT* arg_first,
|
Chris@16
|
210 const charT* arg_last,
|
Chris@16
|
211 flag_type f)
|
Chris@16
|
212 {
|
Chris@16
|
213 regex_data<charT, traits>* pdat = this;
|
Chris@16
|
214 basic_regex_parser<charT, traits> parser(pdat);
|
Chris@16
|
215 parser.parse(arg_first, arg_last, f);
|
Chris@16
|
216 }
|
Chris@16
|
217
|
Chris@16
|
218 locale_type BOOST_REGEX_CALL imbue(locale_type l)
|
Chris@16
|
219 {
|
Chris@16
|
220 return this->m_ptraits->imbue(l);
|
Chris@16
|
221 }
|
Chris@16
|
222 locale_type BOOST_REGEX_CALL getloc()const
|
Chris@16
|
223 {
|
Chris@16
|
224 return this->m_ptraits->getloc();
|
Chris@16
|
225 }
|
Chris@16
|
226 std::basic_string<charT> BOOST_REGEX_CALL str()const
|
Chris@16
|
227 {
|
Chris@16
|
228 std::basic_string<charT> result;
|
Chris@16
|
229 if(this->m_status == 0)
|
Chris@16
|
230 result = std::basic_string<charT>(this->m_expression, this->m_expression_len);
|
Chris@16
|
231 return result;
|
Chris@16
|
232 }
|
Chris@16
|
233 const_iterator BOOST_REGEX_CALL expression()const
|
Chris@16
|
234 {
|
Chris@16
|
235 return this->m_expression;
|
Chris@16
|
236 }
|
Chris@16
|
237 std::pair<const_iterator, const_iterator> BOOST_REGEX_CALL subexpression(std::size_t n)const
|
Chris@16
|
238 {
|
Chris@101
|
239 const std::pair<std::size_t, std::size_t>& pi = this->m_subs.at(n);
|
Chris@16
|
240 std::pair<const_iterator, const_iterator> p(expression() + pi.first, expression() + pi.second);
|
Chris@16
|
241 return p;
|
Chris@16
|
242 }
|
Chris@16
|
243 //
|
Chris@16
|
244 // begin, end:
|
Chris@16
|
245 const_iterator BOOST_REGEX_CALL begin()const
|
Chris@16
|
246 {
|
Chris@16
|
247 return (this->m_status ? 0 : this->m_expression);
|
Chris@16
|
248 }
|
Chris@16
|
249 const_iterator BOOST_REGEX_CALL end()const
|
Chris@16
|
250 {
|
Chris@16
|
251 return (this->m_status ? 0 : this->m_expression + this->m_expression_len);
|
Chris@16
|
252 }
|
Chris@16
|
253 flag_type BOOST_REGEX_CALL flags()const
|
Chris@16
|
254 {
|
Chris@16
|
255 return this->m_flags;
|
Chris@16
|
256 }
|
Chris@16
|
257 size_type BOOST_REGEX_CALL size()const
|
Chris@16
|
258 {
|
Chris@16
|
259 return this->m_expression_len;
|
Chris@16
|
260 }
|
Chris@16
|
261 int BOOST_REGEX_CALL status()const
|
Chris@16
|
262 {
|
Chris@16
|
263 return this->m_status;
|
Chris@16
|
264 }
|
Chris@16
|
265 size_type BOOST_REGEX_CALL mark_count()const
|
Chris@16
|
266 {
|
Chris@101
|
267 return this->m_mark_count - 1;
|
Chris@16
|
268 }
|
Chris@16
|
269 const re_detail::re_syntax_base* get_first_state()const
|
Chris@16
|
270 {
|
Chris@16
|
271 return this->m_first_state;
|
Chris@16
|
272 }
|
Chris@16
|
273 unsigned get_restart_type()const
|
Chris@16
|
274 {
|
Chris@16
|
275 return this->m_restart_type;
|
Chris@16
|
276 }
|
Chris@16
|
277 const unsigned char* get_map()const
|
Chris@16
|
278 {
|
Chris@16
|
279 return this->m_startmap;
|
Chris@16
|
280 }
|
Chris@16
|
281 const ::boost::regex_traits_wrapper<traits>& get_traits()const
|
Chris@16
|
282 {
|
Chris@16
|
283 return *(this->m_ptraits);
|
Chris@16
|
284 }
|
Chris@16
|
285 bool can_be_null()const
|
Chris@16
|
286 {
|
Chris@16
|
287 return this->m_can_be_null;
|
Chris@16
|
288 }
|
Chris@16
|
289 const regex_data<charT, traits>& get_data()const
|
Chris@16
|
290 {
|
Chris@16
|
291 basic_regex_implementation<charT, traits> const* p = this;
|
Chris@16
|
292 return *static_cast<const regex_data<charT, traits>*>(p);
|
Chris@16
|
293 }
|
Chris@16
|
294 };
|
Chris@16
|
295
|
Chris@16
|
296 } // namespace re_detail
|
Chris@16
|
297 //
|
Chris@16
|
298 // class basic_regex:
|
Chris@16
|
299 // represents the compiled
|
Chris@16
|
300 // regular expression:
|
Chris@16
|
301 //
|
Chris@16
|
302
|
Chris@16
|
303 #ifdef BOOST_REGEX_NO_FWD
|
Chris@16
|
304 template <class charT, class traits = regex_traits<charT> >
|
Chris@16
|
305 #else
|
Chris@16
|
306 template <class charT, class traits >
|
Chris@16
|
307 #endif
|
Chris@16
|
308 class basic_regex : public regbase
|
Chris@16
|
309 {
|
Chris@16
|
310 public:
|
Chris@16
|
311 // typedefs:
|
Chris@16
|
312 typedef std::size_t traits_size_type;
|
Chris@16
|
313 typedef typename traits::string_type traits_string_type;
|
Chris@16
|
314 typedef charT char_type;
|
Chris@16
|
315 typedef traits traits_type;
|
Chris@16
|
316
|
Chris@16
|
317 typedef charT value_type;
|
Chris@16
|
318 typedef charT& reference;
|
Chris@16
|
319 typedef const charT& const_reference;
|
Chris@16
|
320 typedef const charT* const_iterator;
|
Chris@16
|
321 typedef const_iterator iterator;
|
Chris@16
|
322 typedef std::ptrdiff_t difference_type;
|
Chris@16
|
323 typedef std::size_t size_type;
|
Chris@16
|
324 typedef regex_constants::syntax_option_type flag_type;
|
Chris@16
|
325 // locale_type
|
Chris@16
|
326 // placeholder for actual locale type used by the
|
Chris@16
|
327 // traits class to localise *this.
|
Chris@16
|
328 typedef typename traits::locale_type locale_type;
|
Chris@16
|
329
|
Chris@16
|
330 public:
|
Chris@16
|
331 explicit basic_regex(){}
|
Chris@16
|
332 explicit basic_regex(const charT* p, flag_type f = regex_constants::normal)
|
Chris@16
|
333 {
|
Chris@16
|
334 assign(p, f);
|
Chris@16
|
335 }
|
Chris@16
|
336 basic_regex(const charT* p1, const charT* p2, flag_type f = regex_constants::normal)
|
Chris@16
|
337 {
|
Chris@16
|
338 assign(p1, p2, f);
|
Chris@16
|
339 }
|
Chris@16
|
340 basic_regex(const charT* p, size_type len, flag_type f)
|
Chris@16
|
341 {
|
Chris@16
|
342 assign(p, len, f);
|
Chris@16
|
343 }
|
Chris@16
|
344 basic_regex(const basic_regex& that)
|
Chris@16
|
345 : m_pimpl(that.m_pimpl) {}
|
Chris@16
|
346 ~basic_regex(){}
|
Chris@16
|
347 basic_regex& BOOST_REGEX_CALL operator=(const basic_regex& that)
|
Chris@16
|
348 {
|
Chris@16
|
349 return assign(that);
|
Chris@16
|
350 }
|
Chris@16
|
351 basic_regex& BOOST_REGEX_CALL operator=(const charT* ptr)
|
Chris@16
|
352 {
|
Chris@16
|
353 return assign(ptr);
|
Chris@16
|
354 }
|
Chris@16
|
355
|
Chris@16
|
356 //
|
Chris@16
|
357 // assign:
|
Chris@16
|
358 basic_regex& assign(const basic_regex& that)
|
Chris@16
|
359 {
|
Chris@16
|
360 m_pimpl = that.m_pimpl;
|
Chris@16
|
361 return *this;
|
Chris@16
|
362 }
|
Chris@16
|
363 basic_regex& assign(const charT* p, flag_type f = regex_constants::normal)
|
Chris@16
|
364 {
|
Chris@16
|
365 return assign(p, p + traits::length(p), f);
|
Chris@16
|
366 }
|
Chris@16
|
367 basic_regex& assign(const charT* p, size_type len, flag_type f)
|
Chris@16
|
368 {
|
Chris@16
|
369 return assign(p, p + len, f);
|
Chris@16
|
370 }
|
Chris@16
|
371 private:
|
Chris@16
|
372 basic_regex& do_assign(const charT* p1,
|
Chris@16
|
373 const charT* p2,
|
Chris@16
|
374 flag_type f);
|
Chris@16
|
375 public:
|
Chris@16
|
376 basic_regex& assign(const charT* p1,
|
Chris@16
|
377 const charT* p2,
|
Chris@16
|
378 flag_type f = regex_constants::normal)
|
Chris@16
|
379 {
|
Chris@16
|
380 return do_assign(p1, p2, f);
|
Chris@16
|
381 }
|
Chris@16
|
382 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
|
Chris@16
|
383
|
Chris@16
|
384 template <class ST, class SA>
|
Chris@16
|
385 unsigned int BOOST_REGEX_CALL set_expression(const std::basic_string<charT, ST, SA>& p, flag_type f = regex_constants::normal)
|
Chris@16
|
386 {
|
Chris@16
|
387 return set_expression(p.data(), p.data() + p.size(), f);
|
Chris@16
|
388 }
|
Chris@16
|
389
|
Chris@16
|
390 template <class ST, class SA>
|
Chris@16
|
391 explicit basic_regex(const std::basic_string<charT, ST, SA>& p, flag_type f = regex_constants::normal)
|
Chris@16
|
392 {
|
Chris@16
|
393 assign(p, f);
|
Chris@16
|
394 }
|
Chris@16
|
395
|
Chris@16
|
396 template <class InputIterator>
|
Chris@16
|
397 basic_regex(InputIterator arg_first, InputIterator arg_last, flag_type f = regex_constants::normal)
|
Chris@16
|
398 {
|
Chris@16
|
399 typedef typename traits::string_type seq_type;
|
Chris@16
|
400 seq_type a(arg_first, arg_last);
|
Chris@16
|
401 if(a.size())
|
Chris@16
|
402 assign(static_cast<const charT*>(&*a.begin()), static_cast<const charT*>(&*a.begin() + a.size()), f);
|
Chris@16
|
403 else
|
Chris@16
|
404 assign(static_cast<const charT*>(0), static_cast<const charT*>(0), f);
|
Chris@16
|
405 }
|
Chris@16
|
406
|
Chris@16
|
407 template <class ST, class SA>
|
Chris@16
|
408 basic_regex& BOOST_REGEX_CALL operator=(const std::basic_string<charT, ST, SA>& p)
|
Chris@16
|
409 {
|
Chris@16
|
410 return assign(p.data(), p.data() + p.size(), regex_constants::normal);
|
Chris@16
|
411 }
|
Chris@16
|
412
|
Chris@16
|
413 template <class string_traits, class A>
|
Chris@16
|
414 basic_regex& BOOST_REGEX_CALL assign(
|
Chris@16
|
415 const std::basic_string<charT, string_traits, A>& s,
|
Chris@16
|
416 flag_type f = regex_constants::normal)
|
Chris@16
|
417 {
|
Chris@16
|
418 return assign(s.data(), s.data() + s.size(), f);
|
Chris@16
|
419 }
|
Chris@16
|
420
|
Chris@16
|
421 template <class InputIterator>
|
Chris@16
|
422 basic_regex& BOOST_REGEX_CALL assign(InputIterator arg_first,
|
Chris@16
|
423 InputIterator arg_last,
|
Chris@16
|
424 flag_type f = regex_constants::normal)
|
Chris@16
|
425 {
|
Chris@16
|
426 typedef typename traits::string_type seq_type;
|
Chris@16
|
427 seq_type a(arg_first, arg_last);
|
Chris@16
|
428 if(a.size())
|
Chris@16
|
429 {
|
Chris@16
|
430 const charT* p1 = &*a.begin();
|
Chris@16
|
431 const charT* p2 = &*a.begin() + a.size();
|
Chris@16
|
432 return assign(p1, p2, f);
|
Chris@16
|
433 }
|
Chris@16
|
434 return assign(static_cast<const charT*>(0), static_cast<const charT*>(0), f);
|
Chris@16
|
435 }
|
Chris@16
|
436 #else
|
Chris@16
|
437 unsigned int BOOST_REGEX_CALL set_expression(const std::basic_string<charT>& p, flag_type f = regex_constants::normal)
|
Chris@16
|
438 {
|
Chris@16
|
439 return set_expression(p.data(), p.data() + p.size(), f);
|
Chris@16
|
440 }
|
Chris@16
|
441
|
Chris@16
|
442 basic_regex(const std::basic_string<charT>& p, flag_type f = regex_constants::normal)
|
Chris@16
|
443 {
|
Chris@16
|
444 assign(p, f);
|
Chris@16
|
445 }
|
Chris@16
|
446
|
Chris@16
|
447 basic_regex& BOOST_REGEX_CALL operator=(const std::basic_string<charT>& p)
|
Chris@16
|
448 {
|
Chris@16
|
449 return assign(p.data(), p.data() + p.size(), regex_constants::normal);
|
Chris@16
|
450 }
|
Chris@16
|
451
|
Chris@16
|
452 basic_regex& BOOST_REGEX_CALL assign(
|
Chris@16
|
453 const std::basic_string<charT>& s,
|
Chris@16
|
454 flag_type f = regex_constants::normal)
|
Chris@16
|
455 {
|
Chris@16
|
456 return assign(s.data(), s.data() + s.size(), f);
|
Chris@16
|
457 }
|
Chris@16
|
458
|
Chris@16
|
459 #endif
|
Chris@16
|
460
|
Chris@16
|
461 //
|
Chris@16
|
462 // locale:
|
Chris@16
|
463 locale_type BOOST_REGEX_CALL imbue(locale_type l);
|
Chris@16
|
464 locale_type BOOST_REGEX_CALL getloc()const
|
Chris@16
|
465 {
|
Chris@16
|
466 return m_pimpl.get() ? m_pimpl->getloc() : locale_type();
|
Chris@16
|
467 }
|
Chris@16
|
468 //
|
Chris@16
|
469 // getflags:
|
Chris@16
|
470 // retained for backwards compatibility only, "flags"
|
Chris@16
|
471 // is now the preferred name:
|
Chris@16
|
472 flag_type BOOST_REGEX_CALL getflags()const
|
Chris@16
|
473 {
|
Chris@16
|
474 return flags();
|
Chris@16
|
475 }
|
Chris@16
|
476 flag_type BOOST_REGEX_CALL flags()const
|
Chris@16
|
477 {
|
Chris@16
|
478 return m_pimpl.get() ? m_pimpl->flags() : 0;
|
Chris@16
|
479 }
|
Chris@16
|
480 //
|
Chris@16
|
481 // str:
|
Chris@16
|
482 std::basic_string<charT> BOOST_REGEX_CALL str()const
|
Chris@16
|
483 {
|
Chris@16
|
484 return m_pimpl.get() ? m_pimpl->str() : std::basic_string<charT>();
|
Chris@16
|
485 }
|
Chris@16
|
486 //
|
Chris@16
|
487 // begin, end, subexpression:
|
Chris@16
|
488 std::pair<const_iterator, const_iterator> BOOST_REGEX_CALL subexpression(std::size_t n)const
|
Chris@16
|
489 {
|
Chris@16
|
490 if(!m_pimpl.get())
|
Chris@16
|
491 boost::throw_exception(std::logic_error("Can't access subexpressions in an invalid regex."));
|
Chris@16
|
492 return m_pimpl->subexpression(n);
|
Chris@16
|
493 }
|
Chris@16
|
494 const_iterator BOOST_REGEX_CALL begin()const
|
Chris@16
|
495 {
|
Chris@16
|
496 return (m_pimpl.get() ? m_pimpl->begin() : 0);
|
Chris@16
|
497 }
|
Chris@16
|
498 const_iterator BOOST_REGEX_CALL end()const
|
Chris@16
|
499 {
|
Chris@16
|
500 return (m_pimpl.get() ? m_pimpl->end() : 0);
|
Chris@16
|
501 }
|
Chris@16
|
502 //
|
Chris@16
|
503 // swap:
|
Chris@16
|
504 void BOOST_REGEX_CALL swap(basic_regex& that)throw()
|
Chris@16
|
505 {
|
Chris@16
|
506 m_pimpl.swap(that.m_pimpl);
|
Chris@16
|
507 }
|
Chris@16
|
508 //
|
Chris@16
|
509 // size:
|
Chris@16
|
510 size_type BOOST_REGEX_CALL size()const
|
Chris@16
|
511 {
|
Chris@16
|
512 return (m_pimpl.get() ? m_pimpl->size() : 0);
|
Chris@16
|
513 }
|
Chris@16
|
514 //
|
Chris@16
|
515 // max_size:
|
Chris@16
|
516 size_type BOOST_REGEX_CALL max_size()const
|
Chris@16
|
517 {
|
Chris@16
|
518 return UINT_MAX;
|
Chris@16
|
519 }
|
Chris@16
|
520 //
|
Chris@16
|
521 // empty:
|
Chris@16
|
522 bool BOOST_REGEX_CALL empty()const
|
Chris@16
|
523 {
|
Chris@16
|
524 return (m_pimpl.get() ? 0 != m_pimpl->status() : true);
|
Chris@16
|
525 }
|
Chris@16
|
526
|
Chris@16
|
527 size_type BOOST_REGEX_CALL mark_count()const
|
Chris@16
|
528 {
|
Chris@16
|
529 return (m_pimpl.get() ? m_pimpl->mark_count() : 0);
|
Chris@16
|
530 }
|
Chris@16
|
531
|
Chris@16
|
532 int status()const
|
Chris@16
|
533 {
|
Chris@16
|
534 return (m_pimpl.get() ? m_pimpl->status() : regex_constants::error_empty);
|
Chris@16
|
535 }
|
Chris@16
|
536
|
Chris@16
|
537 int BOOST_REGEX_CALL compare(const basic_regex& that) const
|
Chris@16
|
538 {
|
Chris@16
|
539 if(m_pimpl.get() == that.m_pimpl.get())
|
Chris@16
|
540 return 0;
|
Chris@16
|
541 if(!m_pimpl.get())
|
Chris@16
|
542 return -1;
|
Chris@16
|
543 if(!that.m_pimpl.get())
|
Chris@16
|
544 return 1;
|
Chris@16
|
545 if(status() != that.status())
|
Chris@16
|
546 return status() - that.status();
|
Chris@16
|
547 if(flags() != that.flags())
|
Chris@16
|
548 return flags() - that.flags();
|
Chris@16
|
549 return str().compare(that.str());
|
Chris@16
|
550 }
|
Chris@16
|
551 bool BOOST_REGEX_CALL operator==(const basic_regex& e)const
|
Chris@16
|
552 {
|
Chris@16
|
553 return compare(e) == 0;
|
Chris@16
|
554 }
|
Chris@16
|
555 bool BOOST_REGEX_CALL operator != (const basic_regex& e)const
|
Chris@16
|
556 {
|
Chris@16
|
557 return compare(e) != 0;
|
Chris@16
|
558 }
|
Chris@16
|
559 bool BOOST_REGEX_CALL operator<(const basic_regex& e)const
|
Chris@16
|
560 {
|
Chris@16
|
561 return compare(e) < 0;
|
Chris@16
|
562 }
|
Chris@16
|
563 bool BOOST_REGEX_CALL operator>(const basic_regex& e)const
|
Chris@16
|
564 {
|
Chris@16
|
565 return compare(e) > 0;
|
Chris@16
|
566 }
|
Chris@16
|
567 bool BOOST_REGEX_CALL operator<=(const basic_regex& e)const
|
Chris@16
|
568 {
|
Chris@16
|
569 return compare(e) <= 0;
|
Chris@16
|
570 }
|
Chris@16
|
571 bool BOOST_REGEX_CALL operator>=(const basic_regex& e)const
|
Chris@16
|
572 {
|
Chris@16
|
573 return compare(e) >= 0;
|
Chris@16
|
574 }
|
Chris@16
|
575
|
Chris@16
|
576 //
|
Chris@16
|
577 // The following are deprecated as public interfaces
|
Chris@16
|
578 // but are available for compatibility with earlier versions.
|
Chris@16
|
579 const charT* BOOST_REGEX_CALL expression()const
|
Chris@16
|
580 {
|
Chris@16
|
581 return (m_pimpl.get() && !m_pimpl->status() ? m_pimpl->expression() : 0);
|
Chris@16
|
582 }
|
Chris@16
|
583 unsigned int BOOST_REGEX_CALL set_expression(const charT* p1, const charT* p2, flag_type f = regex_constants::normal)
|
Chris@16
|
584 {
|
Chris@16
|
585 assign(p1, p2, f | regex_constants::no_except);
|
Chris@16
|
586 return status();
|
Chris@16
|
587 }
|
Chris@16
|
588 unsigned int BOOST_REGEX_CALL set_expression(const charT* p, flag_type f = regex_constants::normal)
|
Chris@16
|
589 {
|
Chris@16
|
590 assign(p, f | regex_constants::no_except);
|
Chris@16
|
591 return status();
|
Chris@16
|
592 }
|
Chris@16
|
593 unsigned int BOOST_REGEX_CALL error_code()const
|
Chris@16
|
594 {
|
Chris@16
|
595 return status();
|
Chris@16
|
596 }
|
Chris@16
|
597 //
|
Chris@16
|
598 // private access methods:
|
Chris@16
|
599 //
|
Chris@16
|
600 const re_detail::re_syntax_base* get_first_state()const
|
Chris@16
|
601 {
|
Chris@16
|
602 BOOST_ASSERT(0 != m_pimpl.get());
|
Chris@16
|
603 return m_pimpl->get_first_state();
|
Chris@16
|
604 }
|
Chris@16
|
605 unsigned get_restart_type()const
|
Chris@16
|
606 {
|
Chris@16
|
607 BOOST_ASSERT(0 != m_pimpl.get());
|
Chris@16
|
608 return m_pimpl->get_restart_type();
|
Chris@16
|
609 }
|
Chris@16
|
610 const unsigned char* get_map()const
|
Chris@16
|
611 {
|
Chris@16
|
612 BOOST_ASSERT(0 != m_pimpl.get());
|
Chris@16
|
613 return m_pimpl->get_map();
|
Chris@16
|
614 }
|
Chris@16
|
615 const ::boost::regex_traits_wrapper<traits>& get_traits()const
|
Chris@16
|
616 {
|
Chris@16
|
617 BOOST_ASSERT(0 != m_pimpl.get());
|
Chris@16
|
618 return m_pimpl->get_traits();
|
Chris@16
|
619 }
|
Chris@16
|
620 bool can_be_null()const
|
Chris@16
|
621 {
|
Chris@16
|
622 BOOST_ASSERT(0 != m_pimpl.get());
|
Chris@16
|
623 return m_pimpl->can_be_null();
|
Chris@16
|
624 }
|
Chris@16
|
625 const re_detail::regex_data<charT, traits>& get_data()const
|
Chris@16
|
626 {
|
Chris@16
|
627 BOOST_ASSERT(0 != m_pimpl.get());
|
Chris@16
|
628 return m_pimpl->get_data();
|
Chris@16
|
629 }
|
Chris@16
|
630 boost::shared_ptr<re_detail::named_subexpressions > get_named_subs()const
|
Chris@16
|
631 {
|
Chris@16
|
632 return m_pimpl;
|
Chris@16
|
633 }
|
Chris@16
|
634
|
Chris@16
|
635 private:
|
Chris@16
|
636 shared_ptr<re_detail::basic_regex_implementation<charT, traits> > m_pimpl;
|
Chris@16
|
637 };
|
Chris@16
|
638
|
Chris@16
|
639 //
|
Chris@16
|
640 // out of line members;
|
Chris@16
|
641 // these are the only members that mutate the basic_regex object,
|
Chris@16
|
642 // and are designed to provide the strong exception guarentee
|
Chris@16
|
643 // (in the event of a throw, the state of the object remains unchanged).
|
Chris@16
|
644 //
|
Chris@16
|
645 template <class charT, class traits>
|
Chris@16
|
646 basic_regex<charT, traits>& basic_regex<charT, traits>::do_assign(const charT* p1,
|
Chris@16
|
647 const charT* p2,
|
Chris@16
|
648 flag_type f)
|
Chris@16
|
649 {
|
Chris@16
|
650 shared_ptr<re_detail::basic_regex_implementation<charT, traits> > temp;
|
Chris@16
|
651 if(!m_pimpl.get())
|
Chris@16
|
652 {
|
Chris@16
|
653 temp = shared_ptr<re_detail::basic_regex_implementation<charT, traits> >(new re_detail::basic_regex_implementation<charT, traits>());
|
Chris@16
|
654 }
|
Chris@16
|
655 else
|
Chris@16
|
656 {
|
Chris@16
|
657 temp = shared_ptr<re_detail::basic_regex_implementation<charT, traits> >(new re_detail::basic_regex_implementation<charT, traits>(m_pimpl->m_ptraits));
|
Chris@16
|
658 }
|
Chris@16
|
659 temp->assign(p1, p2, f);
|
Chris@16
|
660 temp.swap(m_pimpl);
|
Chris@16
|
661 return *this;
|
Chris@16
|
662 }
|
Chris@16
|
663
|
Chris@16
|
664 template <class charT, class traits>
|
Chris@16
|
665 typename basic_regex<charT, traits>::locale_type BOOST_REGEX_CALL basic_regex<charT, traits>::imbue(locale_type l)
|
Chris@16
|
666 {
|
Chris@16
|
667 shared_ptr<re_detail::basic_regex_implementation<charT, traits> > temp(new re_detail::basic_regex_implementation<charT, traits>());
|
Chris@16
|
668 locale_type result = temp->imbue(l);
|
Chris@16
|
669 temp.swap(m_pimpl);
|
Chris@16
|
670 return result;
|
Chris@16
|
671 }
|
Chris@16
|
672
|
Chris@16
|
673 //
|
Chris@16
|
674 // non-members:
|
Chris@16
|
675 //
|
Chris@16
|
676 template <class charT, class traits>
|
Chris@16
|
677 void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2)
|
Chris@16
|
678 {
|
Chris@16
|
679 e1.swap(e2);
|
Chris@16
|
680 }
|
Chris@16
|
681
|
Chris@16
|
682 #ifndef BOOST_NO_STD_LOCALE
|
Chris@16
|
683 template <class charT, class traits, class traits2>
|
Chris@16
|
684 std::basic_ostream<charT, traits>&
|
Chris@16
|
685 operator << (std::basic_ostream<charT, traits>& os,
|
Chris@16
|
686 const basic_regex<charT, traits2>& e)
|
Chris@16
|
687 {
|
Chris@16
|
688 return (os << e.str());
|
Chris@16
|
689 }
|
Chris@16
|
690 #else
|
Chris@16
|
691 template <class traits>
|
Chris@16
|
692 std::ostream& operator << (std::ostream& os, const basic_regex<char, traits>& e)
|
Chris@16
|
693 {
|
Chris@16
|
694 return (os << e.str());
|
Chris@16
|
695 }
|
Chris@16
|
696 #endif
|
Chris@16
|
697
|
Chris@16
|
698 //
|
Chris@16
|
699 // class reg_expression:
|
Chris@16
|
700 // this is provided for backwards compatibility only,
|
Chris@16
|
701 // it is deprecated, no not use!
|
Chris@16
|
702 //
|
Chris@16
|
703 #ifdef BOOST_REGEX_NO_FWD
|
Chris@16
|
704 template <class charT, class traits = regex_traits<charT> >
|
Chris@16
|
705 #else
|
Chris@16
|
706 template <class charT, class traits >
|
Chris@16
|
707 #endif
|
Chris@16
|
708 class reg_expression : public basic_regex<charT, traits>
|
Chris@16
|
709 {
|
Chris@16
|
710 public:
|
Chris@16
|
711 typedef typename basic_regex<charT, traits>::flag_type flag_type;
|
Chris@16
|
712 typedef typename basic_regex<charT, traits>::size_type size_type;
|
Chris@16
|
713 explicit reg_expression(){}
|
Chris@16
|
714 explicit reg_expression(const charT* p, flag_type f = regex_constants::normal)
|
Chris@16
|
715 : basic_regex<charT, traits>(p, f){}
|
Chris@16
|
716 reg_expression(const charT* p1, const charT* p2, flag_type f = regex_constants::normal)
|
Chris@16
|
717 : basic_regex<charT, traits>(p1, p2, f){}
|
Chris@16
|
718 reg_expression(const charT* p, size_type len, flag_type f)
|
Chris@16
|
719 : basic_regex<charT, traits>(p, len, f){}
|
Chris@16
|
720 reg_expression(const reg_expression& that)
|
Chris@16
|
721 : basic_regex<charT, traits>(that) {}
|
Chris@16
|
722 ~reg_expression(){}
|
Chris@16
|
723 reg_expression& BOOST_REGEX_CALL operator=(const reg_expression& that)
|
Chris@16
|
724 {
|
Chris@16
|
725 return this->assign(that);
|
Chris@16
|
726 }
|
Chris@16
|
727
|
Chris@16
|
728 #if !defined(BOOST_NO_MEMBER_TEMPLATES)
|
Chris@16
|
729 template <class ST, class SA>
|
Chris@16
|
730 explicit reg_expression(const std::basic_string<charT, ST, SA>& p, flag_type f = regex_constants::normal)
|
Chris@16
|
731 : basic_regex<charT, traits>(p, f)
|
Chris@16
|
732 {
|
Chris@16
|
733 }
|
Chris@16
|
734
|
Chris@16
|
735 template <class InputIterator>
|
Chris@16
|
736 reg_expression(InputIterator arg_first, InputIterator arg_last, flag_type f = regex_constants::normal)
|
Chris@16
|
737 : basic_regex<charT, traits>(arg_first, arg_last, f)
|
Chris@16
|
738 {
|
Chris@16
|
739 }
|
Chris@16
|
740
|
Chris@16
|
741 template <class ST, class SA>
|
Chris@16
|
742 reg_expression& BOOST_REGEX_CALL operator=(const std::basic_string<charT, ST, SA>& p)
|
Chris@16
|
743 {
|
Chris@16
|
744 this->assign(p);
|
Chris@16
|
745 return *this;
|
Chris@16
|
746 }
|
Chris@16
|
747 #else
|
Chris@16
|
748 explicit reg_expression(const std::basic_string<charT>& p, flag_type f = regex_constants::normal)
|
Chris@16
|
749 : basic_regex<charT, traits>(p, f)
|
Chris@16
|
750 {
|
Chris@16
|
751 }
|
Chris@16
|
752
|
Chris@16
|
753 reg_expression& BOOST_REGEX_CALL operator=(const std::basic_string<charT>& p)
|
Chris@16
|
754 {
|
Chris@16
|
755 this->assign(p);
|
Chris@16
|
756 return *this;
|
Chris@16
|
757 }
|
Chris@16
|
758 #endif
|
Chris@16
|
759
|
Chris@16
|
760 };
|
Chris@16
|
761
|
Chris@16
|
762 #ifdef BOOST_MSVC
|
Chris@16
|
763 #pragma warning (pop)
|
Chris@16
|
764 #endif
|
Chris@16
|
765
|
Chris@16
|
766 } // namespace boost
|
Chris@16
|
767
|
Chris@16
|
768 #ifdef BOOST_MSVC
|
Chris@16
|
769 #pragma warning(push)
|
Chris@16
|
770 #pragma warning(disable: 4103)
|
Chris@16
|
771 #endif
|
Chris@16
|
772 #ifdef BOOST_HAS_ABI_HEADERS
|
Chris@16
|
773 # include BOOST_ABI_SUFFIX
|
Chris@16
|
774 #endif
|
Chris@16
|
775 #ifdef BOOST_MSVC
|
Chris@16
|
776 #pragma warning(pop)
|
Chris@16
|
777 #endif
|
Chris@16
|
778
|
Chris@16
|
779 #endif
|
Chris@16
|
780
|