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