blob: b60e7766ab5bb60040040ce34cbfd7e719a0bca0 [file] [log] [blame]
Howard Hinnant3257c982010-06-17 00:34:59 +00001// -*- C++ -*-
2//===--------------------------- regex ------------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_REGEX
12#define _LIBCPP_REGEX
13
14/*
15 regex synopsis
16
17#include <initializer_list>
18
19namespace std
20{
21
22namespace regex_constants
23{
24
25emum syntax_option_type
26{
27 icase = unspecified,
28 nosubs = unspecified,
29 optimize = unspecified,
30 collate = unspecified,
31 ECMAScript = unspecified,
32 basic = unspecified,
33 extended = unspecified,
34 awk = unspecified,
35 grep = unspecified,
36 egrep = unspecified
37};
38
39constexpr syntax_option_type operator~(syntax_option_type f);
40constexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs);
41constexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs);
42
43enum match_flag_type
44{
45 match_default = 0,
46 match_not_bol = unspecified,
47 match_not_eol = unspecified,
48 match_not_bow = unspecified,
49 match_not_eow = unspecified,
50 match_any = unspecified,
51 match_not_null = unspecified,
52 match_continuous = unspecified,
53 match_prev_avail = unspecified,
54 format_default = 0,
55 format_sed = unspecified,
56 format_no_copy = unspecified,
57 format_first_only = unspecified
58};
59
60constexpr match_flag_type operator~(match_flag_type f);
61constexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs);
62constexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs);
63
64enum error_type
65{
66 error_collate = unspecified,
67 error_ctype = unspecified,
68 error_escape = unspecified,
69 error_backref = unspecified,
70 error_brack = unspecified,
71 error_paren = unspecified,
72 error_brace = unspecified,
73 error_badbrace = unspecified,
74 error_range = unspecified,
75 error_space = unspecified,
76 error_badrepeat = unspecified,
77 error_complexity = unspecified,
78 error_stack = unspecified
79};
80
81} // regex_constants
82
83class regex_error
84 : public runtime_error
85{
86public:
87 explicit regex_error(regex_constants::error_type ecode);
88 regex_constants::error_type code() const;
89};
90
91template <class charT>
92struct regex_traits
93{
94public:
95 typedef charT char_type;
96 typedef basic_string<char_type> string_type;
97 typedef locale locale_type;
98 typedef /bitmask_type/ char_class_type;
99
100 regex_traits();
101
102 static size_t length(const char_type* p);
103 charT translate(charT c) const;
104 charT translate_nocase(charT c) const;
105 template <class ForwardIterator>
106 string_type
107 transform(ForwardIterator first, ForwardIterator last) const;
108 template <class ForwardIterator>
109 string_type
110 transform_primary( ForwardIterator first, ForwardIterator last) const;
111 template <class ForwardIterator>
112 string_type
113 lookup_collatename(ForwardIterator first, ForwardIterator last) const;
114 template <class ForwardIterator>
115 char_class_type
116 lookup_classname(ForwardIterator first, ForwardIterator last,
117 bool icase = false) const;
118 bool isctype(charT c, char_class_type f) const;
119 int value(charT ch, int radix) const;
120 locale_type imbue(locale_type l);
121 locale_type getloc()const;
122};
123
124template <class charT, class traits = regex_traits<charT>>
125class basic_regex
126{
127public:
128 // types:
129 typedef charT value_type;
130 typedef regex_constants::syntax_option_type flag_type;
131 typedef typename traits::locale_type locale_type;
132
133 // constants:
134 static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
135 static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
136 static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
137 static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
138 static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
139 static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
140 static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
141 static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
142 static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
143 static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
144
145 // construct/copy/destroy:
146 basic_regex();
147 explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
148 basic_regex(const charT* p, size_t len, flag_type f);
149 basic_regex(const basic_regex&);
150 basic_regex(basic_regex&&);
151 template <class ST, class SA>
152 explicit basic_regex(const basic_string<charT, ST, SA>& p,
153 flag_type f = regex_constants::ECMAScript);
154 template <class ForwardIterator>
155 basic_regex(ForwardIterator first, ForwardIterator last,
156 flag_type f = regex_constants::ECMAScript);
157 basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
158
159 ~basic_regex();
160
161 basic_regex& operator=(const basic_regex&);
162 basic_regex& operator=(basic_regex&&);
163 basic_regex& operator=(const charT* ptr);
164 basic_regex& operator=(initializer_list<charT> il);
165 template <class ST, class SA>
166 basic_regex& operator=(const basic_string<charT, ST, SA>& p);
167
168 // assign:
169 basic_regex& assign(const basic_regex& that);
170 basic_regex& assign(basic_regex&& that);
171 basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
172 basic_regex& assign(const charT* p, size_t len, flag_type f);
173 template <class string_traits, class A>
174 basic_regex& assign(const basic_string<charT, string_traits, A>& s,
175 flag_type f = regex_constants::ECMAScript);
176 template <class InputIterator>
177 basic_regex& assign(InputIterator first, InputIterator last,
178 flag_type f = regex_constants::ECMAScript);
179 basic_regex& assign(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
180
181 // const operations:
182 unsigned mark_count() const;
183 flag_type flags() const;
184
185 // locale:
186 locale_type imbue(locale_type loc);
187 locale_type getloc() const;
188
189 // swap:
190 void swap(basic_regex&);
191};
192
193typedef basic_regex<char> regex;
194typedef basic_regex<wchar_t> wregex;
195
196template <class charT, class traits>
197 void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
198
199template <class BidirectionalIterator>
200class sub_match
201 : public pair<BidirectionalIterator, BidirectionalIterator>
202{
203public:
204 typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
205 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
206 typedef BidirectionalIterator iterator;
207 typedef basic_string<value_type> string_type;
208
209 bool matched;
210
211 difference_type length() const;
212 operator string_type() const;
213 string_type str() const;
214
215 int compare(const sub_match& s) const;
216 int compare(const string_type& s) const;
217 int compare(const value_type* s) const;
218};
219
220typedef sub_match<const char*> csub_match;
221typedef sub_match<const wchar_t*> wcsub_match;
222typedef sub_match<string::const_iterator> ssub_match;
223typedef sub_match<wstring::const_iterator> wssub_match;
224
225template <class BiIter>
226 bool
227 operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
228
229template <class BiIter>
230 bool
231 operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
232
233template <class BiIter>
234 bool
235 operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
236
237template <class BiIter>
238 bool
239 operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
240
241template <class BiIter>
242 bool
243 operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
244
245template <class BiIter>
246 bool
247 operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
248
249template <class BiIter, class ST, class SA>
250 bool
251 operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
252 const sub_match<BiIter>& rhs);
253
254template <class BiIter, class ST, class SA>
255 bool
256 operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
257 const sub_match<BiIter>& rhs);
258
259template <class BiIter, class ST, class SA>
260 bool
261 operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
262 const sub_match<BiIter>& rhs);
263
264template <class BiIter, class ST, class SA>
265 bool
266 operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
267 const sub_match<BiIter>& rhs);
268
269template <class BiIter, class ST, class SA>
270 bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
271 const sub_match<BiIter>& rhs);
272
273template <class BiIter, class ST, class SA>
274 bool
275 operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
276 const sub_match<BiIter>& rhs);
277
278template <class BiIter, class ST, class SA>
279 bool
280 operator==(const sub_match<BiIter>& lhs,
281 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
282
283template <class BiIter, class ST, class SA>
284 bool
285 operator!=(const sub_match<BiIter>& lhs,
286 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
287
288template <class BiIter, class ST, class SA>
289 bool
290 operator<(const sub_match<BiIter>& lhs,
291 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
292
293template <class BiIter, class ST, class SA>
294 bool operator>(const sub_match<BiIter>& lhs,
295 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
296
297template <class BiIter, class ST, class SA>
298 bool
299 operator>=(const sub_match<BiIter>& lhs,
300 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
301
302template <class BiIter, class ST, class SA>
303 bool
304 operator<=(const sub_match<BiIter>& lhs,
305 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
306
307template <class BiIter>
308 bool
309 operator==(typename iterator_traits<BiIter>::value_type const* lhs,
310 const sub_match<BiIter>& rhs);
311
312template <class BiIter>
313 bool
314 operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
315 const sub_match<BiIter>& rhs);
316
317template <class BiIter>
318 bool
319 operator<(typename iterator_traits<BiIter>::value_type const* lhs,
320 const sub_match<BiIter>& rhs);
321
322template <class BiIter>
323 bool
324 operator>(typename iterator_traits<BiIter>::value_type const* lhs,
325 const sub_match<BiIter>& rhs);
326
327template <class BiIter>
328 bool
329 operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
330 const sub_match<BiIter>& rhs);
331
332template <class BiIter>
333 bool
334 operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
335 const sub_match<BiIter>& rhs);
336
337template <class BiIter>
338 bool
339 operator==(const sub_match<BiIter>& lhs,
340 typename iterator_traits<BiIter>::value_type const* rhs);
341
342template <class BiIter>
343 bool
344 operator!=(const sub_match<BiIter>& lhs,
345 typename iterator_traits<BiIter>::value_type const* rhs);
346
347template <class BiIter>
348 bool
349 operator<(const sub_match<BiIter>& lhs,
350 typename iterator_traits<BiIter>::value_type const* rhs);
351
352template <class BiIter>
353 bool
354 operator>(const sub_match<BiIter>& lhs,
355 typename iterator_traits<BiIter>::value_type const* rhs);
356
357template <class BiIter>
358 bool
359 operator>=(const sub_match<BiIter>& lhs,
360 typename iterator_traits<BiIter>::value_type const* rhs);
361
362template <class BiIter>
363 bool
364 operator<=(const sub_match<BiIter>& lhs,
365 typename iterator_traits<BiIter>::value_type const* rhs);
366
367template <class BiIter>
368 bool
369 operator==(typename iterator_traits<BiIter>::value_type const& lhs,
370 const sub_match<BiIter>& rhs);
371
372template <class BiIter>
373 bool
374 operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
375 const sub_match<BiIter>& rhs);
376
377template <class BiIter>
378 bool
379 operator<(typename iterator_traits<BiIter>::value_type const& lhs,
380 const sub_match<BiIter>& rhs);
381
382template <class BiIter>
383 bool
384 operator>(typename iterator_traits<BiIter>::value_type const& lhs,
385 const sub_match<BiIter>& rhs);
386
387template <class BiIter>
388 bool
389 operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
390 const sub_match<BiIter>& rhs);
391
392template <class BiIter>
393 bool
394 operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
395 const sub_match<BiIter>& rhs);
396
397template <class BiIter>
398 bool
399 operator==(const sub_match<BiIter>& lhs,
400 typename iterator_traits<BiIter>::value_type const& rhs);
401
402template <class BiIter>
403 bool
404 operator!=(const sub_match<BiIter>& lhs,
405 typename iterator_traits<BiIter>::value_type const& rhs);
406
407template <class BiIter>
408 bool
409 operator<(const sub_match<BiIter>& lhs,
410 typename iterator_traits<BiIter>::value_type const& rhs);
411
412template <class BiIter>
413 bool
414 operator>(const sub_match<BiIter>& lhs,
415 typename iterator_traits<BiIter>::value_type const& rhs);
416
417template <class BiIter>
418 bool
419 operator>=(const sub_match<BiIter>& lhs,
420 typename iterator_traits<BiIter>::value_type const& rhs);
421
422template <class BiIter>
423 bool
424 operator<=(const sub_match<BiIter>& lhs,
425 typename iterator_traits<BiIter>::value_type const& rhs);
426
427template <class charT, class ST, class BiIter>
428 basic_ostream<charT, ST>&
429 operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
430
431template <class BidirectionalIterator,
432 class Allocator = allocator<sub_match<BidirectionalIterator>>>
433class match_results
434{
435public:
436 typedef sub_match<BidirectionalIterator> value_type;
437 typedef const value_type& const_reference;
438 typedef const_reference reference;
439 typedef /implementation-defined/ const_iterator;
440 typedef const_iterator iterator;
441 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
442 typedef typename allocator_traits<Allocator>::size_type size_type;
443 typedef Allocator allocator_type;
444 typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
445 typedef basic_string<char_type> string_type;
446
447 // construct/copy/destroy:
448 explicit match_results(const Allocator& a = Allocator());
449 match_results(const match_results& m);
450 match_results(match_results&& m);
451 match_results& operator=(const match_results& m);
452 match_results& operator=(match_results&& m);
453 ~match_results();
454
455 // size:
456 size_type size() const;
457 size_type max_size() const;
458 bool empty() const;
459
460 // element access:
461 difference_type length(size_type sub = 0) const;
462 difference_type position(size_type sub = 0) const;
463 string_type str(size_type sub = 0) const;
464 const_reference operator[](size_type n) const;
465
466 const_reference prefix() const;
467 const_reference suffix() const;
468
469 const_iterator begin() const;
470 const_iterator end() const;
471 const_iterator cbegin() const;
472 const_iterator cend() const;
473
474 // format:
475 template <class OutputIter>
476 OutputIter
477 format(OutputIter out, const char_type* fmt_first,
478 const char_type* fmt_last,
479 regex_constants::match_flag_type flags = regex_constants::format_default) const;
480 template <class OutputIter, class ST, class SA>
481 OutputIter
482 format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
483 regex_constants::match_flag_type flags = regex_constants::format_default) const;
484 template <class ST, class SA>
485 basic_string<char_type, ST, SA>
486 format(const basic_string<char_type, ST, SA>& fmt,
487 regex_constants::match_flag_type flags = regex_constants::format_default) const;
488 string_type
489 format(const char_type* fmt,
490 regex_constants::match_flag_type flags = regex_constants::format_default) const;
491
492 // allocator:
493 allocator_type get_allocator() const;
494
495 // swap:
496 void swap(match_results& that);
497};
498
499typedef match_results<const char*> cmatch;
500typedef match_results<const wchar_t*> wcmatch;
501typedef match_results<string::const_iterator> smatch;
502typedef match_results<wstring::const_iterator> wsmatch;
503
504template <class BidirectionalIterator, class Allocator>
505 bool
506 operator==(const match_results<BidirectionalIterator, Allocator>& m1,
507 const match_results<BidirectionalIterator, Allocator>& m2);
508
509template <class BidirectionalIterator, class Allocator>
510 bool
511 operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
512 const match_results<BidirectionalIterator, Allocator>& m2);
513
514template <class BidirectionalIterator, class Allocator>
515 void
516 swap(match_results<BidirectionalIterator, Allocator>& m1,
517 match_results<BidirectionalIterator, Allocator>& m2);
518
519template <class BidirectionalIterator, class Allocator, class charT, class traits>
520 bool
521 regex_match(BidirectionalIterator first, BidirectionalIterator last,
522 match_results<BidirectionalIterator, Allocator>& m,
523 const basic_regex<charT, traits>& e,
524 regex_constants::match_flag_type flags = regex_constants::match_default);
525
526template <class BidirectionalIterator, class charT, class traits>
527 bool
528 regex_match(BidirectionalIterator first, BidirectionalIterator last,
529 const basic_regex<charT, traits>& e,
530 regex_constants::match_flag_type flags = regex_constants::match_default);
531
532template <class charT, class Allocator, class traits>
533 bool
534 regex_match(const charT* str, match_results<const charT*, Allocator>& m,
535 const basic_regex<charT, traits>& e,
536 regex_constants::match_flag_type flags = regex_constants::match_default);
537
538template <class ST, class SA, class Allocator, class charT, class traits>
539 bool
540 regex_match(const basic_string<charT, ST, SA>& s,
541 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
542 const basic_regex<charT, traits>& e,
543 regex_constants::match_flag_type flags = regex_constants::match_default);
544
545template <class charT, class traits>
546 bool
547 regex_match(const charT* str, const basic_regex<charT, traits>& e,
548 regex_constants::match_flag_type flags = regex_constants::match_default);
549
550template <class ST, class SA, class charT, class traits>
551 bool
552 regex_match(const basic_string<charT, ST, SA>& s,
553 const basic_regex<charT, traits>& e,
554 regex_constants::match_flag_type flags = regex_constants::match_default);
555
556template <class BidirectionalIterator, class Allocator, class charT, class traits>
557 bool
558 regex_search(BidirectionalIterator first, BidirectionalIterator last,
559 match_results<BidirectionalIterator, Allocator>& m,
560 const basic_regex<charT, traits>& e,
561 regex_constants::match_flag_type flags = regex_constants::match_default);
562
563template <class BidirectionalIterator, class charT, class traits>
564 bool
565 regex_search(BidirectionalIterator first, BidirectionalIterator last,
566 const basic_regex<charT, traits>& e,
567 regex_constants::match_flag_type flags = regex_constants::match_default);
568
569template <class charT, class Allocator, class traits>
570 bool
571 regex_search(const charT* str, match_results<const charT*, Allocator>& m,
572 const basic_regex<charT, traits>& e,
573 regex_constants::match_flag_type flags = regex_constants::match_default);
574
575template <class charT, class traits>
576 bool
577 regex_search(const charT* str, const basic_regex<charT, traits>& e,
578 regex_constants::match_flag_type flags = regex_constants::match_default);
579
580template <class ST, class SA, class charT, class traits>
581 bool
582 regex_search(const basic_string<charT, ST, SA>& s,
583 const basic_regex<charT, traits>& e,
584 regex_constants::match_flag_type flags = regex_constants::match_default);
585
586template <class ST, class SA, class Allocator, class charT, class traits>
587 bool
588 regex_search(const basic_string<charT, ST, SA>& s,
589 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
590 const basic_regex<charT, traits>& e,
591 regex_constants::match_flag_type flags = regex_constants::match_default);
592
593template <class OutputIterator, class BidirectionalIterator,
594 class traits, class charT, class ST, class SA>
595 OutputIterator
596 regex_replace(OutputIterator out,
597 BidirectionalIterator first, BidirectionalIterator last,
598 const basic_regex<charT, traits>& e,
599 const basic_string<charT, ST, SA>& fmt,
600 regex_constants::match_flag_type flags = regex_constants::match_default);
601
602template <class OutputIterator, class BidirectionalIterator,
603 class traits, class charT>
604 OutputIterator
605 regex_replace(OutputIterator out,
606 BidirectionalIterator first, BidirectionalIterator last,
607 const basic_regex<charT, traits>& e, const charT* fmt,
608 regex_constants::match_flag_type flags = regex_constants::match_default);
609
610template <class traits, class charT, class ST, class SA, class FST, class FSA>>
611 basic_string<charT, ST, SA>
612 regex_replace(const basic_string<charT, ST, SA>& s,
613 const basic_regex<charT, traits>& e,
614 const basic_string<charT, FST, FSA>& fmt,
615 regex_constants::match_flag_type flags = regex_constants::match_default);
616
617template <class traits, class charT, class ST, class SA>
618 basic_string<charT, ST, SA>
619 regex_replace(const basic_string<charT, ST, SA>& s,
620 const basic_regex<charT, traits>& e, const charT* fmt,
621 regex_constants::match_flag_type flags = regex_constants::match_default);
622
623template <class traits, class charT, class ST, class SA>
624 basic_string<charT>
625 regex_replace(const charT* s,
626 const basic_regex<charT, traits>& e,
627 const basic_string<charT, ST, SA>& fmt,
628 regex_constants::match_flag_type flags = regex_constants::match_default);
629
630template <class traits, class charT>
631 basic_string<charT>
632 regex_replace(const charT* s,
633 const basic_regex<charT, traits>& e,
634 const charT* fmt,
635 regex_constants::match_flag_type flags = regex_constants::match_default);
636
637template <class BidirectionalIterator,
638 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
639 class traits = regex_traits<charT>>
640class regex_iterator
641{
642public:
643 typedef basic_regex<charT, traits> regex_type;
644 typedef match_results<BidirectionalIterator> value_type;
645 typedef ptrdiff_t difference_type;
646 typedef const value_type* pointer;
647 typedef const value_type& reference;
648 typedef forward_iterator_tag iterator_category;
649
650 regex_iterator();
651 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
652 const regex_type& re,
653 regex_constants::match_flag_type m = regex_constants::match_default);
654 regex_iterator(const regex_iterator&);
655 regex_iterator& operator=(const regex_iterator&);
656
657 bool operator==(const regex_iterator&) const;
658 bool operator!=(const regex_iterator&) const;
659
660 const value_type& operator*() const;
661 const value_type* operator->() const;
662
663 regex_iterator& operator++();
664 regex_iterator operator++(int);
665};
666
667typedef regex_iterator<const char*> cregex_iterator;
668typedef regex_iterator<const wchar_t*> wcregex_iterator;
669typedef regex_iterator<string::const_iterator> sregex_iterator;
670typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
671
672template <class BidirectionalIterator,
673 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
674 class traits = regex_traits<charT>>
675class regex_token_iterator
676{
677public:
678 typedef basic_regex<charT, traits> regex_type;
679 typedef sub_match<BidirectionalIterator> value_type;
680 typedef ptrdiff_t difference_type;
681 typedef const value_type* pointer;
682 typedef const value_type& reference;
683 typedef forward_iterator_tag iterator_category;
684
685 regex_token_iterator();
686 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
687 const regex_type& re, int submatch = 0,
688 regex_constants::match_flag_type m = regex_constants::match_default);
689 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
690 const regex_type& re, const vector<int>& submatches,
691 regex_constants::match_flag_type m = regex_constants::match_default);
692 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
693 const regex_type& re, initializer_list<int> submatches,
694 regex_constants::match_flag_type m = regex_constants::match_default);
695 template <size_t N>
696 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
697 const regex_type& re, const int (&submatches)[N],
698 regex_constants::match_flag_type m = regex_constants::match_default);
699 regex_token_iterator(const regex_token_iterator&);
700 regex_token_iterator& operator=(const regex_token_iterator&);
701
702 bool operator==(const regex_token_iterator&) const;
703 bool operator!=(const regex_token_iterator&) const;
704
705 const value_type& operator*() const;
706 const value_type* operator->() const;
707
708 regex_token_iterator& operator++();
709 regex_token_iterator operator++(int);
710};
711
712typedef regex_token_iterator<const char*> cregex_token_iterator;
713typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
714typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
715typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
716
717} // std
718*/
719
Howard Hinnantac303862010-07-12 15:51:17 +0000720// temporary!
Howard Hinnante77aa5e2010-07-08 17:43:58 +0000721#include <sstream>
722#include <cassert>
723
Howard Hinnant3257c982010-06-17 00:34:59 +0000724#include <__config>
725#include <stdexcept>
726#include <__locale>
Howard Hinnant8c2c18d2010-06-24 21:28:00 +0000727#include <initializer_list>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +0000728#include <utility>
729#include <iterator>
730#include <string>
Howard Hinnant7e9d84b2010-06-30 00:21:42 +0000731#include <memory>
732#include <vector>
Howard Hinnantac303862010-07-12 15:51:17 +0000733#include <deque>
Howard Hinnant3257c982010-06-17 00:34:59 +0000734
735#pragma GCC system_header
736
737_LIBCPP_BEGIN_NAMESPACE_STD
738
739namespace regex_constants
740{
741
742// syntax_option_type
743
744enum syntax_option_type
745{
746 icase = 1 << 0,
747 nosubs = 1 << 1,
748 optimize = 1 << 2,
749 collate = 1 << 3,
750 ECMAScript = 1 << 4,
751 basic = 1 << 5,
752 extended = 1 << 6,
753 awk = 1 << 7,
754 grep = 1 << 8,
755 egrep = 1 << 9
756};
757
758inline
759/*constexpr*/
760syntax_option_type
761operator~(syntax_option_type __x)
762{
763 return syntax_option_type(~int(__x));
764}
765
766inline
767/*constexpr*/
768syntax_option_type
769operator&(syntax_option_type __x, syntax_option_type __y)
770{
771 return syntax_option_type(int(__x) & int(__y));
772}
773
774inline
775/*constexpr*/
776syntax_option_type
777operator|(syntax_option_type __x, syntax_option_type __y)
778{
779 return syntax_option_type(int(__x) | int(__y));
780}
781
782inline
783/*constexpr*/
784syntax_option_type
785operator^(syntax_option_type __x, syntax_option_type __y)
786{
787 return syntax_option_type(int(__x) ^ int(__y));
788}
789
790inline
791/*constexpr*/
792syntax_option_type&
793operator&=(syntax_option_type& __x, syntax_option_type __y)
794{
795 __x = __x & __y;
796 return __x;
797}
798
799inline
800/*constexpr*/
801syntax_option_type&
802operator|=(syntax_option_type& __x, syntax_option_type __y)
803{
804 __x = __x | __y;
805 return __x;
806}
807
808inline
809/*constexpr*/
810syntax_option_type&
811operator^=(syntax_option_type& __x, syntax_option_type __y)
812{
813 __x = __x ^ __y;
814 return __x;
815}
816
817// match_flag_type
818
819enum match_flag_type
820{
821 match_default = 0,
822 match_not_bol = 1 << 0,
823 match_not_eol = 1 << 1,
824 match_not_bow = 1 << 2,
825 match_not_eow = 1 << 3,
826 match_any = 1 << 4,
827 match_not_null = 1 << 5,
828 match_continuous = 1 << 6,
829 match_prev_avail = 1 << 7,
830 format_default = 0,
831 format_sed = 1 << 8,
832 format_no_copy = 1 << 9,
833 format_first_only = 1 << 10
834};
835
836inline
837/*constexpr*/
838match_flag_type
839operator~(match_flag_type __x)
840{
841 return match_flag_type(~int(__x));
842}
843
844inline
845/*constexpr*/
846match_flag_type
847operator&(match_flag_type __x, match_flag_type __y)
848{
849 return match_flag_type(int(__x) & int(__y));
850}
851
852inline
853/*constexpr*/
854match_flag_type
855operator|(match_flag_type __x, match_flag_type __y)
856{
857 return match_flag_type(int(__x) | int(__y));
858}
859
860inline
861/*constexpr*/
862match_flag_type
863operator^(match_flag_type __x, match_flag_type __y)
864{
865 return match_flag_type(int(__x) ^ int(__y));
866}
867
868inline
869/*constexpr*/
870match_flag_type&
871operator&=(match_flag_type& __x, match_flag_type __y)
872{
873 __x = __x & __y;
874 return __x;
875}
876
877inline
878/*constexpr*/
879match_flag_type&
880operator|=(match_flag_type& __x, match_flag_type __y)
881{
882 __x = __x | __y;
883 return __x;
884}
885
886inline
887/*constexpr*/
888match_flag_type&
889operator^=(match_flag_type& __x, match_flag_type __y)
890{
891 __x = __x ^ __y;
892 return __x;
893}
894
895enum error_type
896{
897 error_collate = 1,
898 error_ctype,
899 error_escape,
900 error_backref,
901 error_brack,
902 error_paren,
903 error_brace,
904 error_badbrace,
905 error_range,
906 error_space,
907 error_badrepeat,
908 error_complexity,
Howard Hinnant8c2c18d2010-06-24 21:28:00 +0000909 error_stack,
910 error_temp
Howard Hinnant3257c982010-06-17 00:34:59 +0000911};
912
913} // regex_constants
914
915class _LIBCPP_EXCEPTION_ABI regex_error
916 : public runtime_error
917{
918 regex_constants::error_type __code_;
919public:
920 explicit regex_error(regex_constants::error_type __ecode);
921 virtual ~regex_error() throw();
922 regex_constants::error_type code() const {return __code_;}
923};
924
925template <class _CharT>
926struct regex_traits
927{
928public:
929 typedef _CharT char_type;
930 typedef basic_string<char_type> string_type;
931 typedef locale locale_type;
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000932 typedef ctype_base::mask char_class_type;
Howard Hinnant3257c982010-06-17 00:34:59 +0000933
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000934 static const char_class_type __regex_word = 0x80;
Howard Hinnant3257c982010-06-17 00:34:59 +0000935private:
936 locale __loc_;
937 const ctype<char_type>* __ct_;
938 const collate<char_type>* __col_;
939
940public:
941 regex_traits();
942
943 static size_t length(const char_type* __p)
944 {return char_traits<char_type>::length(__p);}
945 char_type translate(char_type __c) const {return __c;}
946 char_type translate_nocase(char_type __c) const;
947 template <class _ForwardIterator>
948 string_type
949 transform(_ForwardIterator __f, _ForwardIterator __l) const;
950 template <class _ForwardIterator>
951 string_type
952 transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
953 {return __transform_primary(__f, __l, char_type());}
954 template <class _ForwardIterator>
955 string_type
956 lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
957 {return __lookup_collatename(__f, __l, char_type());}
958 template <class _ForwardIterator>
959 char_class_type
960 lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000961 bool __icase = false) const
962 {return __lookup_classname(__f, __l, __icase, char_type());}
963 bool isctype(char_type __c, char_class_type __m) const;
964 int value(char_type __ch, int __radix) const
965 {return __value(__ch, __radix);}
Howard Hinnant3257c982010-06-17 00:34:59 +0000966 locale_type imbue(locale_type __l);
967 locale_type getloc()const {return __loc_;}
968
969private:
970 void __init();
971
972 template <class _ForwardIterator>
973 string_type
974 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
975 template <class _ForwardIterator>
976 string_type
977 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
978
979 template <class _ForwardIterator>
980 string_type
981 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
982 template <class _ForwardIterator>
983 string_type
984 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000985
986 template <class _ForwardIterator>
987 char_class_type
988 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
989 bool __icase, char) const;
990 template <class _ForwardIterator>
991 char_class_type
992 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
993 bool __icase, wchar_t) const;
994
995 static int __value(unsigned char __ch, int __radix);
996 int __value(char __ch, int __radix) const
997 {return __value(static_cast<unsigned char>(__ch), __radix);}
998 int __value(wchar_t __ch, int __radix) const;
Howard Hinnant3257c982010-06-17 00:34:59 +0000999};
1000
1001template <class _CharT>
1002regex_traits<_CharT>::regex_traits()
1003{
1004 __init();
1005}
1006
1007template <class _CharT>
1008typename regex_traits<_CharT>::char_type
1009regex_traits<_CharT>::translate_nocase(char_type __c) const
1010{
1011 return __ct_->tolower(__c);
1012}
1013
1014template <class _CharT>
1015template <class _ForwardIterator>
1016typename regex_traits<_CharT>::string_type
1017regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
1018{
1019 string_type __s(__f, __l);
1020 return __col_->transform(__s.data(), __s.data() + __s.size());
1021}
1022
1023template <class _CharT>
1024void
1025regex_traits<_CharT>::__init()
1026{
1027 __ct_ = &use_facet<ctype<char_type> >(__loc_);
1028 __col_ = &use_facet<collate<char_type> >(__loc_);
1029}
1030
1031template <class _CharT>
1032typename regex_traits<_CharT>::locale_type
1033regex_traits<_CharT>::imbue(locale_type __l)
1034{
1035 locale __r = __loc_;
1036 __loc_ = __l;
1037 __init();
1038 return __r;
1039}
1040
1041// transform_primary is very FreeBSD-specific
1042
1043template <class _CharT>
1044template <class _ForwardIterator>
1045typename regex_traits<_CharT>::string_type
1046regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1047 _ForwardIterator __l, char) const
1048{
1049 const string_type __s(__f, __l);
1050 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1051 switch (__d.size())
1052 {
1053 case 1:
1054 break;
1055 case 12:
1056 __d[11] = __d[3];
1057 break;
1058 default:
1059 __d.clear();
1060 break;
1061 }
1062 return __d;
1063}
1064
1065template <class _CharT>
1066template <class _ForwardIterator>
1067typename regex_traits<_CharT>::string_type
1068regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1069 _ForwardIterator __l, wchar_t) const
1070{
1071 const string_type __s(__f, __l);
1072 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1073 switch (__d.size())
1074 {
1075 case 1:
1076 break;
1077 case 3:
1078 __d[2] = __d[0];
1079 break;
1080 default:
1081 __d.clear();
1082 break;
1083 }
1084 return __d;
1085}
1086
1087// lookup_collatename is very FreeBSD-specific
1088
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001089string __get_collation_name(const char* __s);
Howard Hinnant3257c982010-06-17 00:34:59 +00001090
1091template <class _CharT>
1092template <class _ForwardIterator>
1093typename regex_traits<_CharT>::string_type
1094regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1095 _ForwardIterator __l, char) const
1096{
1097 string_type __s(__f, __l);
1098 string_type __r;
1099 if (!__s.empty())
1100 {
1101 __r = __get_collation_name(__s.c_str());
1102 if (__r.empty() && __s.size() <= 2)
1103 {
1104 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1105 if (__r.size() == 1 || __r.size() == 12)
1106 __r = __s;
1107 else
1108 __r.clear();
1109 }
1110 }
1111 return __r;
1112}
1113
1114template <class _CharT>
1115template <class _ForwardIterator>
1116typename regex_traits<_CharT>::string_type
1117regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1118 _ForwardIterator __l, wchar_t) const
1119{
1120 string_type __s(__f, __l);
1121 string __n;
1122 __n.reserve(__s.size());
1123 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1124 __i != __e; ++__i)
1125 {
1126 if (static_cast<unsigned>(*__i) >= 127)
1127 return string_type();
1128 __n.push_back(char(*__i));
1129 }
1130 string_type __r;
1131 if (!__s.empty())
1132 {
1133 __n = __get_collation_name(__n.c_str());
1134 if (!__n.empty())
1135 __r.assign(__n.begin(), __n.end());
1136 else if (__s.size() <= 2)
1137 {
1138 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1139 if (__r.size() == 1 || __r.size() == 3)
1140 __r = __s;
1141 else
1142 __r.clear();
1143 }
1144 }
1145 return __r;
1146}
1147
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001148// lookup_classname
1149
1150ctype_base::mask __get_classname(const char* __s, bool __icase);
1151
1152template <class _CharT>
1153template <class _ForwardIterator>
1154typename regex_traits<_CharT>::char_class_type
1155regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1156 _ForwardIterator __l,
1157 bool __icase, char) const
1158{
1159 string_type __s(__f, __l);
1160 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1161 return __get_classname(__s.c_str(), __icase);
1162}
1163
1164template <class _CharT>
1165template <class _ForwardIterator>
1166typename regex_traits<_CharT>::char_class_type
1167regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1168 _ForwardIterator __l,
1169 bool __icase, wchar_t) const
1170{
1171 string_type __s(__f, __l);
1172 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1173 string __n;
1174 __n.reserve(__s.size());
1175 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1176 __i != __e; ++__i)
1177 {
1178 if (static_cast<unsigned>(*__i) >= 127)
1179 return char_class_type();
1180 __n.push_back(char(*__i));
1181 }
1182 return __get_classname(__n.c_str(), __icase);
1183}
1184
1185template <class _CharT>
1186bool
1187regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
1188{
1189 if (__ct_->is(__m, __c))
1190 return true;
1191 return (__c == '_' && (__m & __regex_word));
1192}
1193
1194template <class _CharT>
1195int
1196regex_traits<_CharT>::__value(unsigned char __ch, int __radix)
1197{
1198 if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
1199 return __ch - '0';
1200 if (__radix != 8)
1201 {
1202 if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
1203 return __ch - '0';
1204 if (__radix == 16)
1205 {
1206 __ch |= 0x20; // tolower
1207 if ('a' <= __ch && __ch <= 'f')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001208 return __ch - ('a' - 10);
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001209 }
1210 }
1211 return -1;
1212}
1213
1214template <class _CharT>
1215inline
1216int
1217regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const
1218{
1219 return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
1220}
1221
Howard Hinnantac303862010-07-12 15:51:17 +00001222template <class _CharT> class __node;
1223
1224template <class _BidirectionalIterator> class sub_match;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001225
Howard Hinnant17615b02010-07-27 01:25:38 +00001226template <class _BidirectionalIterator,
1227 class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1228class match_results;
1229
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001230template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001231struct __state
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001232{
1233 enum
1234 {
1235 __end_state = -1000,
1236 __consume_input, // -999
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001237 __begin_marked_expr, // -998
1238 __end_marked_expr, // -997
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001239 __pop_state, // -996
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001240 __accept_and_consume, // -995
1241 __accept_but_not_consume, // -994
1242 __reject, // -993
Howard Hinnantac303862010-07-12 15:51:17 +00001243 __split,
1244 __repeat
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001245 };
1246
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001247 int __do_;
Howard Hinnantac303862010-07-12 15:51:17 +00001248 const _CharT* __first_;
1249 const _CharT* __current_;
1250 const _CharT* __last_;
1251 vector<sub_match<const _CharT*> > __sub_matches_;
1252 vector<pair<size_t, const _CharT*> > __loop_data_;
1253 const __node<_CharT>* __node_;
1254 regex_constants::match_flag_type __flags_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001255
Howard Hinnantac303862010-07-12 15:51:17 +00001256 __state()
1257 : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
1258 __node_(nullptr), __flags_() {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001259};
1260
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001261template <class _CharT>
1262ostream&
Howard Hinnantac303862010-07-12 15:51:17 +00001263operator<<(ostream& os, const __state<_CharT>& c)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001264{
1265 os << c.__do_;
Howard Hinnantac303862010-07-12 15:51:17 +00001266 if (c.__node_)
1267 os << ", " << c.__node_->speak();
1268else
1269 os << ", null";
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001270 return os;
1271}
1272
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001273
Howard Hinnantac303862010-07-12 15:51:17 +00001274// __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001275
1276template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001277class __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001278{
Howard Hinnantac303862010-07-12 15:51:17 +00001279 __node(const __node&);
1280 __node& operator=(const __node&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001281public:
Howard Hinnantac303862010-07-12 15:51:17 +00001282 typedef _STD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001283
Howard Hinnantac303862010-07-12 15:51:17 +00001284 __node() {}
1285 virtual ~__node() {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001286
Howard Hinnantac303862010-07-12 15:51:17 +00001287 virtual void __exec(__state&) const {};
1288 virtual void __exec_split(bool, __state&) const {};
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001289
Howard Hinnantac303862010-07-12 15:51:17 +00001290 virtual string speak() const {return "__node";}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001291};
1292
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001293// __end_state
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001294
1295template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001296class __end_state
Howard Hinnantac303862010-07-12 15:51:17 +00001297 : public __node<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001298{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001299public:
Howard Hinnantac303862010-07-12 15:51:17 +00001300 typedef _STD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001301
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001302 __end_state() {}
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001303
Howard Hinnantac303862010-07-12 15:51:17 +00001304 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001305
1306 virtual string speak() const {return "end state";}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001307};
1308
1309template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001310void
1311__end_state<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001312{
Howard Hinnantac303862010-07-12 15:51:17 +00001313 __s.__do_ = __state::__end_state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001314}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001315
1316// __has_one_state
1317
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001318template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001319class __has_one_state
Howard Hinnantac303862010-07-12 15:51:17 +00001320 : public __node<_CharT>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001321{
Howard Hinnantac303862010-07-12 15:51:17 +00001322 __node<_CharT>* __first_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001323
1324public:
Howard Hinnantac303862010-07-12 15:51:17 +00001325 explicit __has_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001326 : __first_(__s) {}
1327
Howard Hinnantac303862010-07-12 15:51:17 +00001328 __node<_CharT>* first() const {return __first_;}
1329 __node<_CharT>*& first() {return __first_;}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001330};
1331
1332// __owns_one_state
1333
1334template <class _CharT>
1335class __owns_one_state
1336 : public __has_one_state<_CharT>
1337{
1338 typedef __has_one_state<_CharT> base;
1339
1340public:
Howard Hinnantac303862010-07-12 15:51:17 +00001341 explicit __owns_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001342 : base(__s) {}
1343
1344 virtual ~__owns_one_state();
1345};
1346
1347template <class _CharT>
1348__owns_one_state<_CharT>::~__owns_one_state()
1349{
1350 delete this->first();
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001351}
1352
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001353// __empty_state
1354
1355template <class _CharT>
1356class __empty_state
1357 : public __owns_one_state<_CharT>
1358{
1359 typedef __owns_one_state<_CharT> base;
1360
1361public:
Howard Hinnantac303862010-07-12 15:51:17 +00001362 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001363
Howard Hinnantac303862010-07-12 15:51:17 +00001364 explicit __empty_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001365 : base(__s) {}
1366
Howard Hinnantac303862010-07-12 15:51:17 +00001367 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001368
1369 virtual string speak() const {return "empty state";}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001370};
1371
1372template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001373void
1374__empty_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001375{
Howard Hinnantac303862010-07-12 15:51:17 +00001376 __s.__do_ = __state::__accept_but_not_consume;
1377 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001378}
1379
1380// __empty_non_own_state
1381
1382template <class _CharT>
1383class __empty_non_own_state
1384 : public __has_one_state<_CharT>
1385{
1386 typedef __has_one_state<_CharT> base;
1387
1388public:
Howard Hinnantac303862010-07-12 15:51:17 +00001389 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001390
Howard Hinnantac303862010-07-12 15:51:17 +00001391 explicit __empty_non_own_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001392 : base(__s) {}
1393
Howard Hinnantac303862010-07-12 15:51:17 +00001394 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001395
1396 virtual string speak() const {return "empty non-owning state";}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001397};
1398
1399template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001400void
1401__empty_non_own_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001402{
Howard Hinnantac303862010-07-12 15:51:17 +00001403 __s.__do_ = __state::__accept_but_not_consume;
1404 __s.__node_ = this->first();
1405}
1406
1407// __repeat_one_loop
1408
1409template <class _CharT>
1410class __repeat_one_loop
1411 : public __has_one_state<_CharT>
1412{
1413 typedef __has_one_state<_CharT> base;
1414
1415public:
1416 typedef _STD::__state<_CharT> __state;
1417
1418 explicit __repeat_one_loop(__node<_CharT>* __s)
1419 : base(__s) {}
1420
1421 virtual void __exec(__state&) const;
1422
1423 virtual string speak() const {return "repeat loop";}
1424};
1425
1426template <class _CharT>
1427void
1428__repeat_one_loop<_CharT>::__exec(__state& __s) const
1429{
1430 __s.__do_ = __state::__repeat;
1431 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001432}
1433
1434// __owns_two_states
1435
1436template <class _CharT>
1437class __owns_two_states
1438 : public __owns_one_state<_CharT>
1439{
1440 typedef __owns_one_state<_CharT> base;
1441
1442 base* __second_;
1443
1444public:
Howard Hinnantac303862010-07-12 15:51:17 +00001445 explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001446 : base(__s1), __second_(__s2) {}
1447
1448 virtual ~__owns_two_states();
1449
1450 base* second() const {return __second_;}
1451 base*& second() {return __second_;}
1452};
1453
1454template <class _CharT>
1455__owns_two_states<_CharT>::~__owns_two_states()
1456{
1457 delete __second_;
1458}
1459
1460// __loop
1461
1462template <class _CharT>
1463class __loop
1464 : public __owns_two_states<_CharT>
1465{
1466 typedef __owns_two_states<_CharT> base;
1467
1468 size_t __min_;
1469 size_t __max_;
1470 unsigned __loop_id_;
Howard Hinnantac303862010-07-12 15:51:17 +00001471 unsigned __mexp_begin_;
1472 unsigned __mexp_end_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001473 bool __greedy_;
1474
1475public:
Howard Hinnantac303862010-07-12 15:51:17 +00001476 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001477
1478 explicit __loop(unsigned __loop_id,
Howard Hinnantac303862010-07-12 15:51:17 +00001479 __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
1480 unsigned __mexp_begin, unsigned __mexp_end,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001481 bool __greedy = true,
1482 size_t __min = 0,
1483 size_t __max = numeric_limits<size_t>::max())
1484 : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
Howard Hinnantac303862010-07-12 15:51:17 +00001485 __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001486 __greedy_(__greedy) {}
1487
Howard Hinnantac303862010-07-12 15:51:17 +00001488 virtual void __exec(__state& __s) const;
1489 virtual void __exec_split(bool __second, __state& __s) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001490
1491 virtual string speak() const
1492 {
1493 ostringstream os;
Howard Hinnantac303862010-07-12 15:51:17 +00001494 os << "loop "<< __loop_id_ << " {" << __min_ << ',' << __max_ << "}";
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001495 if (!__greedy_)
1496 os << " not";
1497 os << " greedy";
1498 return os.str();
1499 }
Howard Hinnantac303862010-07-12 15:51:17 +00001500
1501private:
1502 void __init_repeat(__state& __s) const
1503 {
1504 __s.__loop_data_[__loop_id_].second = __s.__current_;
1505 for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
1506 {
1507 __s.__sub_matches_[__i].first = __s.__last_;
1508 __s.__sub_matches_[__i].second = __s.__last_;
1509 __s.__sub_matches_[__i].matched = false;
1510 }
1511 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001512};
1513
1514template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001515void
1516__loop<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001517{
Howard Hinnantac303862010-07-12 15:51:17 +00001518 if (__s.__do_ == __state::__repeat)
1519 {
1520 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1521 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1522 if (__do_repeat && __do_alt &&
1523 __s.__loop_data_[__loop_id_].second == __s.__current_)
1524 __do_repeat = false;
1525 if (__do_repeat && __do_alt)
1526 __s.__do_ = __state::__split;
1527 else if (__do_repeat)
1528 {
1529 __s.__do_ = __state::__accept_but_not_consume;
1530 __s.__node_ = this->first();
1531 __init_repeat(__s);
1532 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001533 else
Howard Hinnantac303862010-07-12 15:51:17 +00001534 {
1535 __s.__do_ = __state::__accept_but_not_consume;
1536 __s.__node_ = this->second();
1537 }
1538 }
1539 else
1540 {
1541 if (__max_ > 0)
1542 __s.__do_ = __state::__split;
1543 else
1544 {
1545 __s.__do_ = __state::__accept_but_not_consume;
1546 __s.__node_ = this->second();
1547 }
1548 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001549}
1550
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001551template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001552void
1553__loop<_CharT>::__exec_split(bool __second, __state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001554{
Howard Hinnantac303862010-07-12 15:51:17 +00001555 __s.__do_ = __state::__accept_but_not_consume;
1556 if (__greedy_ != __second)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001557 {
Howard Hinnantac303862010-07-12 15:51:17 +00001558 __s.__node_ = this->first();
1559 __init_repeat(__s);
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001560 }
Howard Hinnantac303862010-07-12 15:51:17 +00001561 else
1562 __s.__node_ = this->second();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001563}
1564
Howard Hinnantaa698082010-07-16 19:08:36 +00001565// __alternate
1566
1567template <class _CharT>
1568class __alternate
1569 : public __owns_two_states<_CharT>
1570{
1571 typedef __owns_two_states<_CharT> base;
1572
1573public:
1574 typedef _STD::__state<_CharT> __state;
1575
1576 explicit __alternate(__owns_one_state<_CharT>* __s1,
1577 __owns_one_state<_CharT>* __s2)
1578 : base(__s1, __s2) {}
1579
1580 virtual void __exec(__state& __s) const;
1581 virtual void __exec_split(bool __second, __state& __s) const;
1582
1583 virtual string speak() const
1584 {
1585 ostringstream os;
1586 os << "__alternate";
1587 return os.str();
1588 }
1589};
1590
1591template <class _CharT>
1592void
1593__alternate<_CharT>::__exec(__state& __s) const
1594{
1595 __s.__do_ = __state::__split;
1596}
1597
1598template <class _CharT>
1599void
1600__alternate<_CharT>::__exec_split(bool __second, __state& __s) const
1601{
1602 __s.__do_ = __state::__accept_but_not_consume;
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001603 if (__second)
Howard Hinnantaa698082010-07-16 19:08:36 +00001604 __s.__node_ = this->second();
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001605 else
1606 __s.__node_ = this->first();
Howard Hinnantaa698082010-07-16 19:08:36 +00001607}
1608
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001609// __begin_marked_subexpression
1610
1611template <class _CharT>
1612class __begin_marked_subexpression
1613 : public __owns_one_state<_CharT>
1614{
1615 typedef __owns_one_state<_CharT> base;
1616
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001617 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001618public:
Howard Hinnantac303862010-07-12 15:51:17 +00001619 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001620
Howard Hinnantac303862010-07-12 15:51:17 +00001621 explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001622 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001623
Howard Hinnantac303862010-07-12 15:51:17 +00001624 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001625
1626 virtual string speak() const
1627 {
1628 ostringstream os;
1629 os << "begin marked expr " << __mexp_;
1630 return os.str();
1631 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001632};
1633
1634template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001635void
1636__begin_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001637{
Howard Hinnantac303862010-07-12 15:51:17 +00001638 __s.__do_ = __state::__accept_but_not_consume;
1639 __s.__sub_matches_[__mexp_-1].first = __s.__current_;
1640 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001641}
1642
1643// __end_marked_subexpression
1644
1645template <class _CharT>
1646class __end_marked_subexpression
1647 : public __owns_one_state<_CharT>
1648{
1649 typedef __owns_one_state<_CharT> base;
1650
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001651 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001652public:
Howard Hinnantac303862010-07-12 15:51:17 +00001653 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001654
Howard Hinnantac303862010-07-12 15:51:17 +00001655 explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001656 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001657
Howard Hinnantac303862010-07-12 15:51:17 +00001658 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001659
1660 virtual string speak() const
1661 {
1662 ostringstream os;
1663 os << "end marked expr " << __mexp_;
1664 return os.str();
1665 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001666};
1667
1668template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001669void
1670__end_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001671{
Howard Hinnantac303862010-07-12 15:51:17 +00001672 __s.__do_ = __state::__accept_but_not_consume;
1673 __s.__sub_matches_[__mexp_-1].second = __s.__current_;
1674 __s.__sub_matches_[__mexp_-1].matched = true;
1675 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001676}
1677
Howard Hinnantcba352d2010-07-12 18:16:05 +00001678// __back_ref
1679
1680template <class _CharT>
1681class __back_ref
1682 : public __owns_one_state<_CharT>
1683{
1684 typedef __owns_one_state<_CharT> base;
1685
1686 unsigned __mexp_;
1687public:
1688 typedef _STD::__state<_CharT> __state;
1689
1690 explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
1691 : base(__s), __mexp_(__mexp) {}
1692
1693 virtual void __exec(__state&) const;
1694
1695 virtual string speak() const
1696 {
1697 ostringstream os;
1698 os << "__back_ref " << __mexp_;
1699 return os.str();
1700 }
1701};
1702
1703template <class _CharT>
1704void
1705__back_ref<_CharT>::__exec(__state& __s) const
1706{
1707 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1708 if (__sm.matched)
1709 {
1710 ptrdiff_t __len = __sm.second - __sm.first;
1711 if (__s.__last_ - __s.__current_ >= __len &&
1712 _STD::equal(__sm.first, __sm.second, __s.__current_))
1713 {
1714 __s.__do_ = __state::__accept_but_not_consume;
1715 __s.__current_ += __len;
1716 __s.__node_ = this->first();
1717 }
1718 else
1719 {
1720 __s.__do_ = __state::__reject;
1721 __s.__node_ = nullptr;
1722 }
1723 }
1724 else
1725 {
1726 __s.__do_ = __state::__reject;
1727 __s.__node_ = nullptr;
1728 }
1729}
1730
Howard Hinnante34f17d2010-07-12 19:11:27 +00001731// __back_ref_icase
1732
1733template <class _CharT, class _Traits>
1734class __back_ref_icase
1735 : public __owns_one_state<_CharT>
1736{
1737 typedef __owns_one_state<_CharT> base;
1738
1739 _Traits __traits_;
1740 unsigned __mexp_;
1741public:
1742 typedef _STD::__state<_CharT> __state;
1743
1744 explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
1745 __node<_CharT>* __s)
1746 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1747
1748 virtual void __exec(__state&) const;
1749
1750 virtual string speak() const
1751 {
1752 ostringstream os;
1753 os << "__back_ref_icase " << __mexp_;
1754 return os.str();
1755 }
1756};
1757
1758template <class _CharT, class _Traits>
1759void
1760__back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
1761{
1762 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1763 if (__sm.matched)
1764 {
1765 ptrdiff_t __len = __sm.second - __sm.first;
1766 if (__s.__last_ - __s.__current_ >= __len)
1767 {
1768 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1769 {
1770 if (__traits_.translate_nocase(__sm.first[__i]) !=
1771 __traits_.translate_nocase(__s.__current_[__i]))
1772 goto __not_equal;
1773 }
1774 __s.__do_ = __state::__accept_but_not_consume;
1775 __s.__current_ += __len;
1776 __s.__node_ = this->first();
1777 }
1778 else
1779 {
1780 __s.__do_ = __state::__reject;
1781 __s.__node_ = nullptr;
1782 }
1783 }
1784 else
1785 {
1786__not_equal:
1787 __s.__do_ = __state::__reject;
1788 __s.__node_ = nullptr;
1789 }
1790}
1791
1792// __back_ref_collate
1793
1794template <class _CharT, class _Traits>
1795class __back_ref_collate
1796 : public __owns_one_state<_CharT>
1797{
1798 typedef __owns_one_state<_CharT> base;
1799
1800 _Traits __traits_;
1801 unsigned __mexp_;
1802public:
1803 typedef _STD::__state<_CharT> __state;
1804
1805 explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
1806 __node<_CharT>* __s)
1807 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1808
1809 virtual void __exec(__state&) const;
1810
1811 virtual string speak() const
1812 {
1813 ostringstream os;
1814 os << "__back_ref_collate " << __mexp_;
1815 return os.str();
1816 }
1817};
1818
1819template <class _CharT, class _Traits>
1820void
1821__back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
1822{
1823 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1824 if (__sm.matched)
1825 {
1826 ptrdiff_t __len = __sm.second - __sm.first;
1827 if (__s.__last_ - __s.__current_ >= __len)
1828 {
1829 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1830 {
1831 if (__traits_.translate(__sm.first[__i]) !=
1832 __traits_.translate(__s.__current_[__i]))
1833 goto __not_equal;
1834 }
1835 __s.__do_ = __state::__accept_but_not_consume;
1836 __s.__current_ += __len;
1837 __s.__node_ = this->first();
1838 }
1839 else
1840 {
1841 __s.__do_ = __state::__reject;
1842 __s.__node_ = nullptr;
1843 }
1844 }
1845 else
1846 {
1847__not_equal:
1848 __s.__do_ = __state::__reject;
1849 __s.__node_ = nullptr;
1850 }
1851}
1852
Howard Hinnant17615b02010-07-27 01:25:38 +00001853// __word_boundary
1854
1855template <class _CharT, class _Traits>
1856class __word_boundary
1857 : public __owns_one_state<_CharT>
1858{
1859 typedef __owns_one_state<_CharT> base;
1860
1861 _Traits __traits_;
1862 bool __invert_;
1863public:
1864 typedef _STD::__state<_CharT> __state;
1865
1866 explicit __word_boundary(const _Traits& __traits, bool __invert,
1867 __node<_CharT>* __s)
1868 : base(__s), __traits_(__traits), __invert_(__invert) {}
1869
1870 virtual void __exec(__state&) const;
1871
1872 virtual string speak() const
1873 {
1874 ostringstream os;
1875 if (__invert_)
1876 os << "__word_boundary";
1877 else
1878 os << "not __word_boundary";
1879 return os.str();
1880 }
1881};
1882
1883template <class _CharT, class _Traits>
1884void
1885__word_boundary<_CharT, _Traits>::__exec(__state& __s) const
1886{
1887 bool __is_word_b = false;
1888 if (__s.__first_ != __s.__last_)
1889 {
1890 if (__s.__current_ == __s.__last_)
1891 {
1892 if (!(__s.__flags_ & regex_constants::match_not_eow))
1893 {
1894 _CharT __c = __s.__current_[-1];
1895 __is_word_b = __c == '_' ||
1896 __traits_.isctype(__c, ctype_base::alnum);
1897 }
1898 }
1899 else if (__s.__current_ == __s.__first_)
1900 {
1901 if (!(__s.__flags_ & regex_constants::match_not_bow))
1902 {
1903 _CharT __c = *__s.__current_;
1904 __is_word_b = __c == '_' ||
1905 __traits_.isctype(__c, ctype_base::alnum);
1906 }
1907 }
1908 else
1909 {
1910 _CharT __c1 = __s.__current_[-1];
1911 _CharT __c2 = *__s.__current_;
1912 bool __is_c1_b = __c1 == '_' ||
1913 __traits_.isctype(__c1, ctype_base::alnum);
1914 bool __is_c2_b = __c2 == '_' ||
1915 __traits_.isctype(__c2, ctype_base::alnum);
1916 __is_word_b = __is_c1_b != __is_c2_b;
1917 }
1918 }
1919 if (__is_word_b != __invert_)
1920 {
1921 __s.__do_ = __state::__accept_but_not_consume;
1922 __s.__node_ = this->first();
1923 }
1924 else
1925 {
1926 __s.__do_ = __state::__reject;
1927 __s.__node_ = nullptr;
1928 }
1929}
1930
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001931// __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001932
1933template <class _CharT>
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001934class __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001935 : public __owns_one_state<_CharT>
1936{
1937 typedef __owns_one_state<_CharT> base;
1938
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001939public:
Howard Hinnantac303862010-07-12 15:51:17 +00001940 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001941
Howard Hinnantac303862010-07-12 15:51:17 +00001942 __r_anchor(__node<_CharT>* __s)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001943 : base(__s) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001944
Howard Hinnantac303862010-07-12 15:51:17 +00001945 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001946
1947 virtual string speak() const
1948 {
1949 ostringstream os;
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001950 os << "right anchor";
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001951 return os.str();
1952 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001953};
1954
1955template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001956void
1957__r_anchor<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001958{
Howard Hinnantac303862010-07-12 15:51:17 +00001959 if (__s.__current_ == __s.__last_)
1960 {
1961 __s.__do_ = __state::__accept_but_not_consume;
1962 __s.__node_ = this->first();
1963 }
1964 else
1965 {
1966 __s.__do_ = __state::__reject;
1967 __s.__node_ = nullptr;
1968 }
1969}
1970
1971// __match_any
1972
1973template <class _CharT>
1974class __match_any
1975 : public __owns_one_state<_CharT>
1976{
1977 typedef __owns_one_state<_CharT> base;
1978
1979public:
1980 typedef _STD::__state<_CharT> __state;
1981
1982 __match_any(__node<_CharT>* __s)
1983 : base(__s) {}
1984
1985 virtual void __exec(__state&) const;
1986
1987 virtual string speak() const
1988 {
1989 ostringstream os;
1990 os << "match any";
1991 return os.str();
1992 }
1993};
1994
1995template <class _CharT>
1996void
1997__match_any<_CharT>::__exec(__state& __s) const
1998{
1999 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
2000 {
2001 __s.__do_ = __state::__accept_and_consume;
2002 ++__s.__current_;
2003 __s.__node_ = this->first();
2004 }
2005 else
2006 {
2007 __s.__do_ = __state::__reject;
2008 __s.__node_ = nullptr;
2009 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002010}
2011
Howard Hinnant17615b02010-07-27 01:25:38 +00002012// __match_any_but_newline
2013
2014template <class _CharT>
2015class __match_any_but_newline
2016 : public __owns_one_state<_CharT>
2017{
2018 typedef __owns_one_state<_CharT> base;
2019
2020public:
2021 typedef _STD::__state<_CharT> __state;
2022
2023 __match_any_but_newline(__node<_CharT>* __s)
2024 : base(__s) {}
2025
2026 virtual void __exec(__state&) const;
2027
2028 virtual string speak() const
2029 {
2030 ostringstream os;
2031 os << "match any but newline";
2032 return os.str();
2033 }
2034};
2035
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002036// __match_char
2037
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002038template <class _CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002039class __match_char
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002040 : public __owns_one_state<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002041{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002042 typedef __owns_one_state<_CharT> base;
2043
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002044 _CharT __c_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002045
2046 __match_char(const __match_char&);
2047 __match_char& operator=(const __match_char&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002048public:
Howard Hinnantac303862010-07-12 15:51:17 +00002049 typedef _STD::__state<_CharT> __state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002050
Howard Hinnantac303862010-07-12 15:51:17 +00002051 __match_char(_CharT __c, __node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002052 : base(__s), __c_(__c) {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002053
Howard Hinnantac303862010-07-12 15:51:17 +00002054 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002055
2056 virtual string speak() const
2057 {
2058 ostringstream os;
2059 os << "match char " << __c_;
2060 return os.str();
2061 }
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002062};
2063
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002064template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00002065void
2066__match_char<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002067{
Howard Hinnantac303862010-07-12 15:51:17 +00002068 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
2069 {
2070 __s.__do_ = __state::__accept_and_consume;
2071 ++__s.__current_;
2072 __s.__node_ = this->first();
2073 }
2074 else
2075 {
2076 __s.__do_ = __state::__reject;
2077 __s.__node_ = nullptr;
2078 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002079}
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002080
Howard Hinnante34f17d2010-07-12 19:11:27 +00002081// __match_char_icase
2082
2083template <class _CharT, class _Traits>
2084class __match_char_icase
2085 : public __owns_one_state<_CharT>
2086{
2087 typedef __owns_one_state<_CharT> base;
2088
2089 _Traits __traits_;
2090 _CharT __c_;
2091
2092 __match_char_icase(const __match_char_icase&);
2093 __match_char_icase& operator=(const __match_char_icase&);
2094public:
2095 typedef _STD::__state<_CharT> __state;
2096
2097 __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2098 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
2099
2100 virtual void __exec(__state&) const;
2101
2102 virtual string speak() const
2103 {
2104 ostringstream os;
2105 os << "match char icase " << __c_;
2106 return os.str();
2107 }
2108};
2109
2110template <class _CharT, class _Traits>
2111void
2112__match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
2113{
2114 if (__s.__current_ != __s.__last_ &&
2115 __traits_.translate_nocase(*__s.__current_) == __c_)
2116 {
2117 __s.__do_ = __state::__accept_and_consume;
2118 ++__s.__current_;
2119 __s.__node_ = this->first();
2120 }
2121 else
2122 {
2123 __s.__do_ = __state::__reject;
2124 __s.__node_ = nullptr;
2125 }
2126}
2127
2128// __match_char_collate
2129
2130template <class _CharT, class _Traits>
2131class __match_char_collate
2132 : public __owns_one_state<_CharT>
2133{
2134 typedef __owns_one_state<_CharT> base;
2135
2136 _Traits __traits_;
2137 _CharT __c_;
2138
2139 __match_char_collate(const __match_char_collate&);
2140 __match_char_collate& operator=(const __match_char_collate&);
2141public:
2142 typedef _STD::__state<_CharT> __state;
2143
2144 __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2145 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2146
2147 virtual void __exec(__state&) const;
2148
2149 virtual string speak() const
2150 {
2151 ostringstream os;
2152 os << "match char icase " << __c_;
2153 return os.str();
2154 }
2155};
2156
2157template <class _CharT, class _Traits>
2158void
2159__match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
2160{
2161 if (__s.__current_ != __s.__last_ &&
2162 __traits_.translate(*__s.__current_) == __c_)
2163 {
2164 __s.__do_ = __state::__accept_and_consume;
2165 ++__s.__current_;
2166 __s.__node_ = this->first();
2167 }
2168 else
2169 {
2170 __s.__do_ = __state::__reject;
2171 __s.__node_ = nullptr;
2172 }
2173}
2174
Howard Hinnant173968a2010-07-13 21:48:06 +00002175// __bracket_expression
2176
2177template <class _CharT, class _Traits>
2178class __bracket_expression
2179 : public __owns_one_state<_CharT>
2180{
2181 typedef __owns_one_state<_CharT> base;
2182 typedef typename _Traits::string_type string_type;
2183
2184 _Traits __traits_;
2185 vector<_CharT> __chars_;
2186 vector<pair<string_type, string_type> > __ranges_;
2187 vector<pair<_CharT, _CharT> > __digraphs_;
2188 vector<string_type> __equivalences_;
2189 ctype_base::mask __mask_;
2190 bool __negate_;
2191 bool __icase_;
2192 bool __collate_;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002193 bool __might_have_digraph_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002194
2195 __bracket_expression(const __bracket_expression&);
2196 __bracket_expression& operator=(const __bracket_expression&);
2197public:
2198 typedef _STD::__state<_CharT> __state;
2199
2200 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
2201 bool __negate, bool __icase, bool __collate)
2202 : base(__s), __traits_(__traits), __mask_(), __negate_(__negate),
Howard Hinnant68025ed2010-07-14 15:45:11 +00002203 __icase_(__icase), __collate_(__collate),
2204 __might_have_digraph_(__traits_.getloc().name() != "C") {}
Howard Hinnant173968a2010-07-13 21:48:06 +00002205
2206 virtual void __exec(__state&) const;
2207
2208 void __add_char(_CharT __c)
2209 {
2210 if (__icase_)
2211 __chars_.push_back(__traits_.translate_nocase(__c));
2212 else if (__collate_)
2213 __chars_.push_back(__traits_.translate(__c));
2214 else
2215 __chars_.push_back(__c);
2216 }
2217 void __add_range(string_type __b, string_type __e)
2218 {
2219 if (__collate_)
2220 {
2221 if (__icase_)
2222 {
2223 for (size_t __i = 0; __i < __b.size(); ++__i)
2224 __b[__i] = __traits_.translate_nocase(__b[__i]);
2225 for (size_t __i = 0; __i < __e.size(); ++__i)
2226 __e[__i] = __traits_.translate_nocase(__e[__i]);
2227 }
2228 else
2229 {
2230 for (size_t __i = 0; __i < __b.size(); ++__i)
2231 __b[__i] = __traits_.translate(__b[__i]);
2232 for (size_t __i = 0; __i < __e.size(); ++__i)
2233 __e[__i] = __traits_.translate(__e[__i]);
2234 }
2235 __ranges_.push_back(make_pair(
2236 __traits_.transform(__b.begin(), __b.end()),
2237 __traits_.transform(__e.begin(), __e.end())));
2238 }
2239 else
2240 {
2241 if (__b.size() != 1 || __e.size() != 1)
2242 throw regex_error(regex_constants::error_collate);
2243 if (__icase_)
2244 {
2245 __b[0] = __traits_.translate_nocase(__b[0]);
2246 __e[0] = __traits_.translate_nocase(__e[0]);
2247 }
2248 __ranges_.push_back(make_pair(_STD::move(__b), _STD::move(__e)));
2249 }
2250 }
2251 void __add_digraph(_CharT __c1, _CharT __c2)
2252 {
2253 if (__icase_)
2254 __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
2255 __traits_.translate_nocase(__c2)));
2256 else if (__collate_)
2257 __digraphs_.push_back(make_pair(__traits_.translate(__c1),
2258 __traits_.translate(__c2)));
2259 else
2260 __digraphs_.push_back(make_pair(__c1, __c2));
2261 }
2262 void __add_equivalence(const string_type& __s)
2263 {__equivalences_.push_back(__s);}
2264 void __add_class(ctype_base::mask __mask)
2265 {__mask_ |= __mask;}
2266
2267 virtual string speak() const
2268 {
2269 ostringstream os;
2270 os << "__bracket_expression ";
2271 return os.str();
2272 }
2273};
2274
2275template <class _CharT, class _Traits>
2276void
2277__bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
2278{
2279 bool __found = false;
2280 unsigned __consumed = 0;
2281 if (__s.__current_ != __s.__last_)
2282 {
2283 ++__consumed;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002284 if (__might_have_digraph_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002285 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002286 const _CharT* __next = next(__s.__current_);
2287 if (__next != __s.__last_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002288 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002289 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2290 if (__icase_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002291 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002292 __ch2.first = __traits_.translate_nocase(__ch2.first);
2293 __ch2.second = __traits_.translate_nocase(__ch2.second);
2294 }
2295 else if (__collate_)
2296 {
2297 __ch2.first = __traits_.translate(__ch2.first);
2298 __ch2.second = __traits_.translate(__ch2.second);
2299 }
2300 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
2301 {
2302 // __ch2 is a digraph in this locale
2303 ++__consumed;
2304 for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
2305 {
2306 if (__ch2 == __digraphs_[__i])
2307 {
2308 __found = true;
2309 goto __exit;
2310 }
2311 }
2312 if (__collate_ && !__ranges_.empty())
2313 {
2314 string_type __s2 = __traits_.transform(&__ch2.first,
2315 &__ch2.first + 2);
2316 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2317 {
2318 if (__ranges_[__i].first <= __s2 &&
2319 __s2 <= __ranges_[__i].second)
2320 {
2321 __found = true;
2322 goto __exit;
2323 }
2324 }
2325 }
2326 if (!__equivalences_.empty())
2327 {
2328 string_type __s2 = __traits_.transform_primary(&__ch2.first,
2329 &__ch2.first + 2);
2330 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2331 {
2332 if (__s2 == __equivalences_[__i])
2333 {
2334 __found = true;
2335 goto __exit;
2336 }
2337 }
2338 }
2339 if (__traits_.isctype(__ch2.first, __mask_) &&
2340 __traits_.isctype(__ch2.second, __mask_))
Howard Hinnant173968a2010-07-13 21:48:06 +00002341 {
2342 __found = true;
2343 goto __exit;
2344 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002345 goto __exit;
2346 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002347 }
2348 }
2349 // test *__s.__current_ as not a digraph
2350 _CharT __ch = *__s.__current_;
2351 if (__icase_)
2352 __ch = __traits_.translate_nocase(__ch);
2353 else if (__collate_)
2354 __ch = __traits_.translate(__ch);
2355 for (size_t __i = 0; __i < __chars_.size(); ++__i)
2356 {
2357 if (__ch == __chars_[__i])
2358 {
2359 __found = true;
2360 goto __exit;
2361 }
2362 }
2363 if (!__ranges_.empty())
2364 {
2365 string_type __s2 = __collate_ ?
2366 __traits_.transform(&__ch, &__ch + 1) :
2367 string_type(1, __ch);
2368 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2369 {
2370 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
2371 {
2372 __found = true;
2373 goto __exit;
2374 }
2375 }
2376 }
2377 if (!__equivalences_.empty())
2378 {
2379 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2380 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2381 {
2382 if (__s2 == __equivalences_[__i])
2383 {
2384 __found = true;
2385 goto __exit;
2386 }
2387 }
2388 }
2389 if (__traits_.isctype(__ch, __mask_))
2390 __found = true;
2391 }
2392 else
2393 __found = __negate_; // force reject
2394__exit:
2395 if (__found != __negate_)
2396 {
Howard Hinnant173968a2010-07-13 21:48:06 +00002397 __s.__do_ = __state::__accept_and_consume;
2398 __s.__current_ += __consumed;
2399 __s.__node_ = this->first();
2400 }
2401 else
2402 {
2403 __s.__do_ = __state::__reject;
2404 __s.__node_ = nullptr;
2405 }
2406}
2407
Howard Hinnant17615b02010-07-27 01:25:38 +00002408// __lookahead
2409
2410template <class _CharT, class _Traits>
2411class __lookahead
2412 : public __owns_one_state<_CharT>
2413{
2414 typedef __owns_one_state<_CharT> base;
2415
2416 _Traits __traits_;
2417 bool __invert_;
2418
2419 __lookahead(const __lookahead&);
2420 __lookahead& operator=(const __lookahead&);
2421public:
2422 typedef _STD::__state<_CharT> __state;
2423
2424 __lookahead(const _Traits& __traits, bool __invert, __node<_CharT>* __s)
2425 : base(__s), __traits_(__traits), __invert_(__invert) {}
2426
2427 virtual void __exec(__state&) const;
2428
2429 virtual string speak() const
2430 {
2431 ostringstream os;
2432 if (__invert_)
2433 os << "lookahead";
2434 else
2435 os << "not lookahead";
2436 return os.str();
2437 }
2438};
2439
2440template <class _CharT, class _Traits>
2441void
2442__lookahead<_CharT, _Traits>::__exec(__state& __s) const
2443{
2444// match_results<const _CharT*> __m;
2445// __m.__init(1 + mark_count(), __s.__current_, __s.__last_);
2446// bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
2447// __m, __s.__flags_);
2448// if (__matched != __invert_)
2449// {
2450// __s.__do_ = __state::__accept_but_not_consume;
2451// __s.__node_ = this->first();
2452// }
2453// else
2454// {
2455// __s.__do_ = __state::__reject;
2456// __s.__node_ = nullptr;
2457// }
2458}
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002459
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002460template <class _CharT, class _Traits = regex_traits<_CharT> >
2461class basic_regex
2462{
2463public:
2464 // types:
2465 typedef _CharT value_type;
2466 typedef regex_constants::syntax_option_type flag_type;
2467 typedef typename _Traits::locale_type locale_type;
2468
2469private:
2470 _Traits __traits_;
2471 flag_type __flags_;
2472 unsigned __marked_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002473 unsigned __loop_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002474 int __open_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002475 shared_ptr<__empty_state<_CharT> > __start_;
2476 __owns_one_state<_CharT>* __end_;
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002477 bool __left_anchor_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002478
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002479 typedef _STD::__state<_CharT> __state;
Howard Hinnantac303862010-07-12 15:51:17 +00002480 typedef _STD::__node<_CharT> __node;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002481
2482public:
2483 // constants:
2484 static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase;
2485 static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2486 static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize;
2487 static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate;
2488 static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2489 static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic;
2490 static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended;
2491 static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk;
2492 static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep;
2493 static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep;
2494
2495 // construct/copy/destroy:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002496 basic_regex()
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002497 : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0),
2498 __end_(0), __left_anchor_(false)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002499 {}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002500 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002501 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2502 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002503 {__parse(__p, __p + __traits_.length(__p));}
2504 basic_regex(const value_type* __p, size_t __len, flag_type __f)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002505 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2506 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002507 {__parse(__p, __p + __len);}
2508 basic_regex(const basic_regex&);
2509#ifdef _LIBCPP_MOVE
2510 basic_regex(basic_regex&&);
2511#endif
2512 template <class _ST, class _SA>
2513 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2514 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002515 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2516 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002517 {__parse(__p.begin(), __p.end());}
2518 template <class _ForwardIterator>
2519 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
2520 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002521 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2522 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002523 {__parse(__first, __last);}
2524 basic_regex(initializer_list<value_type> __il,
2525 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002526 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2527 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002528 {__parse(__il.begin(), __il.end());}
2529
2530 ~basic_regex();
2531
2532 basic_regex& operator=(const basic_regex&);
2533#ifdef _LIBCPP_MOVE
2534 basic_regex& operator=(basic_regex&&);
2535#endif
2536 basic_regex& operator=(const value_type* __p);
2537 basic_regex& operator=(initializer_list<value_type> __il);
2538 template <class _ST, class _SA>
2539 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p);
2540
2541 // assign:
2542 basic_regex& assign(const basic_regex& __that);
2543#ifdef _LIBCPP_MOVE
2544 basic_regex& assign(basic_regex&& __that);
2545#endif
2546 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript);
2547 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f);
2548 template <class _ST, class _SA>
2549 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
2550 flag_type __f = regex_constants::ECMAScript);
2551 template <class _InputIterator>
2552 basic_regex& assign(_InputIterator __first, _InputIterator __last,
2553 flag_type __f = regex_constants::ECMAScript);
2554 basic_regex& assign(initializer_list<value_type> __il,
2555 flag_type = regex_constants::ECMAScript);
2556
2557 // const operations:
2558 unsigned mark_count() const {return __marked_count_;}
2559 flag_type flags() const {return __flags_;}
2560
2561 // locale:
2562 locale_type imbue(locale_type __loc) {return __traits_.imbue(__loc);}
2563 locale_type getloc() const {return __traits_.getloc();}
2564
2565 // swap:
2566 void swap(basic_regex&);
2567
2568private:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002569 unsigned __loop_count() const {return __loop_count_;}
2570
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002571 template <class _ForwardIterator>
2572 void __parse(_ForwardIterator __first, _ForwardIterator __last);
2573 template <class _ForwardIterator>
2574 _ForwardIterator
2575 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2576 template <class _ForwardIterator>
2577 _ForwardIterator
2578 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2579 template <class _ForwardIterator>
2580 _ForwardIterator
2581 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2582 template <class _ForwardIterator>
2583 _ForwardIterator
2584 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2585 template <class _ForwardIterator>
2586 _ForwardIterator
2587 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2588 template <class _ForwardIterator>
2589 _ForwardIterator
2590 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2591 template <class _ForwardIterator>
2592 _ForwardIterator
2593 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2594 template <class _ForwardIterator>
2595 _ForwardIterator
2596 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2597 template <class _ForwardIterator>
2598 _ForwardIterator
2599 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2600 template <class _ForwardIterator>
2601 _ForwardIterator
2602 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2603 template <class _ForwardIterator>
2604 _ForwardIterator
2605 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2606 template <class _ForwardIterator>
2607 _ForwardIterator
2608 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2609 template <class _ForwardIterator>
2610 _ForwardIterator
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002611 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002612 __owns_one_state<_CharT>* __s,
2613 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002614 template <class _ForwardIterator>
2615 _ForwardIterator
Howard Hinnantaa698082010-07-16 19:08:36 +00002616 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2617 __owns_one_state<_CharT>* __s,
2618 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002619 template <class _ForwardIterator>
2620 _ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00002621 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2622 template <class _ForwardIterator>
2623 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002624 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
2625 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002626 template <class _ForwardIterator>
2627 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002628 __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
2629 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002630 template <class _ForwardIterator>
2631 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002632 __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
2633 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002634 template <class _ForwardIterator>
2635 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002636 __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
2637 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002638 template <class _ForwardIterator>
2639 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002640 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
2641 basic_string<_CharT>& __col_sym);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002642 template <class _ForwardIterator>
2643 _ForwardIterator
2644 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002645 template <class _ForwardIterator>
2646 _ForwardIterator
2647 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2648 template <class _ForwardIterator>
2649 _ForwardIterator
2650 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2651 template <class _ForwardIterator>
2652 _ForwardIterator
2653 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2654 template <class _ForwardIterator>
2655 _ForwardIterator
2656 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2657 template <class _ForwardIterator>
2658 _ForwardIterator
2659 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2660 template <class _ForwardIterator>
2661 _ForwardIterator
2662 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002663 template <class _ForwardIterator>
2664 _ForwardIterator
2665 __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2666 template <class _ForwardIterator>
2667 _ForwardIterator
2668 __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2669 template <class _ForwardIterator>
2670 _ForwardIterator
2671 __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2672 template <class _ForwardIterator>
2673 _ForwardIterator
2674 __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2675 template <class _ForwardIterator>
2676 _ForwardIterator
2677 __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2678 template <class _ForwardIterator>
2679 _ForwardIterator
Howard Hinnant17615b02010-07-27 01:25:38 +00002680 __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2681 template <class _ForwardIterator>
2682 _ForwardIterator
2683 __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2684 template <class _ForwardIterator>
2685 _ForwardIterator
2686 __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2687 template <class _ForwardIterator>
2688 _ForwardIterator
2689 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last);
2690 template <class _ForwardIterator>
2691 _ForwardIterator
2692 __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002693
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002694 void __push_l_anchor() {__left_anchor_ = true;}
2695 void __push_r_anchor();
Howard Hinnantac303862010-07-12 15:51:17 +00002696 void __push_match_any();
Howard Hinnant17615b02010-07-27 01:25:38 +00002697 void __push_match_any_but_newline();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002698 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2699 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2700 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2701 __mexp_begin, __mexp_end);}
Howard Hinnant17615b02010-07-27 01:25:38 +00002702 void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2703 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2704 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2705 __mexp_begin, __mexp_end, false);}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002706 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2707 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2708 bool __greedy = true);
Howard Hinnant173968a2010-07-13 21:48:06 +00002709 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002710 void __push_char(value_type __c);
Howard Hinnantcba352d2010-07-12 18:16:05 +00002711 void __push_back_ref(int __i);
Howard Hinnantaa698082010-07-16 19:08:36 +00002712 void __push_alternation(__owns_one_state<_CharT>* __sa,
2713 __owns_one_state<_CharT>* __sb);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002714 void __push_begin_marked_subexpression();
2715 void __push_end_marked_subexpression(unsigned);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002716 void __push_empty();
Howard Hinnant17615b02010-07-27 01:25:38 +00002717 void __push_word_boundary(bool);
2718 void __push_lookahead(bool) {}
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002719
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002720 template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002721 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002722 __search(const _CharT* __first, const _CharT* __last,
2723 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002724 regex_constants::match_flag_type __flags) const;
2725
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002726 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002727 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002728 __match_at_start(const _CharT* __first, const _CharT* __last,
2729 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002730 vector<size_t>& __lc,
2731 regex_constants::match_flag_type __flags) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00002732 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002733 bool
Howard Hinnant17615b02010-07-27 01:25:38 +00002734 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
2735 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002736 regex_constants::match_flag_type __flags) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002737 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002738 bool
2739 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002740 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002741 vector<size_t>& __lc,
2742 regex_constants::match_flag_type __flags) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002743 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002744 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002745 __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
2746 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002747 vector<size_t>& __lc,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002748 regex_constants::match_flag_type __flags) const;
2749
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002750 template <class _B, class _A, class _C, class _T>
2751 friend
2752 bool
2753 regex_search(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
2754 regex_constants::match_flag_type);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002755
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002756 template <class _A, class _C, class _T>
2757 friend
2758 bool
2759 regex_search(const _C*, const _C*, match_results<const _C*, _A>&,
2760 const basic_regex<_C, _T>&, regex_constants::match_flag_type);
2761
2762 template <class _B, class _C, class _T>
2763 friend
2764 bool
2765 regex_search(_B, _B, const basic_regex<_C, _T>&,
2766 regex_constants::match_flag_type);
2767
2768 template <class _C, class _T>
2769 friend
2770 bool
2771 regex_search(const _C*, const _C*,
2772 const basic_regex<_C, _T>&, regex_constants::match_flag_type);
2773
2774 template <class _C, class _A, class _T>
2775 friend
2776 bool
2777 regex_search(const _C*, match_results<const _C*, _A>&, const basic_regex<_C, _T>&,
2778 regex_constants::match_flag_type);
2779
2780 template <class _ST, class _SA, class _C, class _T>
2781 friend
2782 bool
2783 regex_search(const basic_string<_C, _ST, _SA>& __s,
2784 const basic_regex<_C, _T>& __e,
2785 regex_constants::match_flag_type __flags);
2786
2787 template <class _ST, class _SA, class _A, class _C, class _T>
2788 friend
2789 bool
2790 regex_search(const basic_string<_C, _ST, _SA>& __s,
2791 match_results<typename basic_string<_C, _ST, _SA>::const_iterator, _A>&,
2792 const basic_regex<_C, _T>& __e,
2793 regex_constants::match_flag_type __flags);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002794};
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002795
2796template <class _CharT, class _Traits>
2797basic_regex<_CharT, _Traits>::~basic_regex()
2798{
2799}
2800
2801template <class _CharT, class _Traits>
2802template <class _ForwardIterator>
2803void
2804basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
2805 _ForwardIterator __last)
2806{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002807 {
Howard Hinnantac303862010-07-12 15:51:17 +00002808 unique_ptr<__node> __h(new __end_state<_CharT>);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002809 __start_.reset(new __empty_state<_CharT>(__h.get()));
2810 __h.release();
2811 __end_ = __start_.get();
2812 }
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002813 switch (__flags_ & 0x3F0)
2814 {
2815 case ECMAScript:
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002816 __parse_ecma_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002817 break;
2818 case basic:
2819 __parse_basic_reg_exp(__first, __last);
2820 break;
2821 case extended:
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002822 __parse_extended_reg_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002823 break;
2824 case awk:
2825 break;
2826 case grep:
2827 break;
2828 case egrep:
2829 break;
2830 default:
2831 throw regex_error(regex_constants::error_temp);
2832 }
2833}
2834
2835template <class _CharT, class _Traits>
2836template <class _ForwardIterator>
2837_ForwardIterator
2838basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
2839 _ForwardIterator __last)
2840{
2841 if (__first != __last)
2842 {
2843 if (*__first == '^')
2844 {
2845 __push_l_anchor();
2846 ++__first;
2847 }
2848 if (__first != __last)
2849 {
2850 __first = __parse_RE_expression(__first, __last);
2851 if (__first != __last)
2852 {
2853 _ForwardIterator __temp = next(__first);
2854 if (__temp == __last && *__first == '$')
2855 {
2856 __push_r_anchor();
2857 ++__first;
2858 }
2859 }
2860 }
2861 if (__first != __last)
2862 throw regex_error(regex_constants::error_temp);
2863 }
2864 return __first;
2865}
2866
2867template <class _CharT, class _Traits>
2868template <class _ForwardIterator>
2869_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002870basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
2871 _ForwardIterator __last)
2872{
Howard Hinnantaa698082010-07-16 19:08:36 +00002873 __owns_one_state<_CharT>* __sa = __end_;
2874 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
2875 if (__temp == __first)
2876 throw regex_error(regex_constants::error_temp);
2877 __first = __temp;
2878 while (__first != __last && *__first == '|')
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002879 {
Howard Hinnantaa698082010-07-16 19:08:36 +00002880 __owns_one_state<_CharT>* __sb = __end_;
2881 __temp = __parse_ERE_branch(++__first, __last);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002882 if (__temp == __first)
2883 throw regex_error(regex_constants::error_temp);
Howard Hinnantaa698082010-07-16 19:08:36 +00002884 __push_alternation(__sa, __sb);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002885 __first = __temp;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002886 }
2887 return __first;
2888}
2889
2890template <class _CharT, class _Traits>
2891template <class _ForwardIterator>
2892_ForwardIterator
2893basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
2894 _ForwardIterator __last)
2895{
2896 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
2897 if (__temp == __first)
2898 throw regex_error(regex_constants::error_temp);
2899 do
2900 {
2901 __first = __temp;
2902 __temp = __parse_ERE_expression(__first, __last);
2903 } while (__temp != __first);
2904 return __first;
2905}
2906
2907template <class _CharT, class _Traits>
2908template <class _ForwardIterator>
2909_ForwardIterator
2910basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
2911 _ForwardIterator __last)
2912{
Howard Hinnantaa698082010-07-16 19:08:36 +00002913 __owns_one_state<_CharT>* __e = __end_;
2914 unsigned __mexp_begin = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002915 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
2916 if (__temp == __first && __temp != __last)
2917 {
2918 switch (*__temp)
2919 {
2920 case '^':
2921 __push_l_anchor();
2922 ++__temp;
2923 break;
2924 case '$':
2925 __push_r_anchor();
2926 ++__temp;
2927 break;
2928 case '(':
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002929 __push_begin_marked_subexpression();
2930 unsigned __temp_count = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002931 ++__open_count_;
2932 __temp = __parse_extended_reg_exp(++__temp, __last);
2933 if (__temp == __last || *__temp != ')')
2934 throw regex_error(regex_constants::error_paren);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002935 __push_end_marked_subexpression(__temp_count);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002936 --__open_count_;
2937 ++__temp;
2938 break;
2939 }
2940 }
2941 if (__temp != __first)
Howard Hinnantaa698082010-07-16 19:08:36 +00002942 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
2943 __marked_count_+1);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002944 __first = __temp;
2945 return __first;
2946}
2947
2948template <class _CharT, class _Traits>
2949template <class _ForwardIterator>
2950_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002951basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
2952 _ForwardIterator __last)
2953{
2954 while (true)
2955 {
2956 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
2957 if (__temp == __first)
2958 break;
2959 __first = __temp;
2960 }
2961 return __first;
2962}
2963
2964template <class _CharT, class _Traits>
2965template <class _ForwardIterator>
2966_ForwardIterator
2967basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
2968 _ForwardIterator __last)
2969{
2970 if (__first != __last)
2971 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002972 __owns_one_state<_CharT>* __e = __end_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002973 unsigned __mexp_begin = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002974 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
2975 if (__temp != __first)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002976 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
2977 __mexp_begin+1, __marked_count_+1);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002978 }
2979 return __first;
2980}
2981
2982template <class _CharT, class _Traits>
2983template <class _ForwardIterator>
2984_ForwardIterator
2985basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
2986 _ForwardIterator __last)
2987{
2988 _ForwardIterator __temp = __first;
2989 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
2990 if (__temp == __first)
2991 {
2992 __temp = __parse_Back_open_paren(__first, __last);
2993 if (__temp != __first)
2994 {
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002995 __push_begin_marked_subexpression();
2996 unsigned __temp_count = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002997 __first = __parse_RE_expression(__temp, __last);
2998 __temp = __parse_Back_close_paren(__first, __last);
2999 if (__temp == __first)
3000 throw regex_error(regex_constants::error_paren);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003001 __push_end_marked_subexpression(__temp_count);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003002 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003003 }
3004 else
3005 __first = __parse_BACKREF(__first, __last);
3006 }
3007 return __first;
3008}
3009
3010template <class _CharT, class _Traits>
3011template <class _ForwardIterator>
3012_ForwardIterator
3013basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
3014 _ForwardIterator __first,
3015 _ForwardIterator __last)
3016{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003017 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003018 if (__temp == __first)
3019 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003020 __temp = __parse_QUOTED_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003021 if (__temp == __first)
3022 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003023 if (__temp != __last && *__temp == '.')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003024 {
3025 __push_match_any();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003026 ++__temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003027 }
3028 else
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003029 __temp = __parse_bracket_expression(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003030 }
3031 }
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003032 __first = __temp;
3033 return __first;
3034}
3035
3036template <class _CharT, class _Traits>
3037template <class _ForwardIterator>
3038_ForwardIterator
3039basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
3040 _ForwardIterator __first,
3041 _ForwardIterator __last)
3042{
3043 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
3044 if (__temp == __first)
3045 {
3046 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
3047 if (__temp == __first)
3048 {
3049 if (__temp != __last && *__temp == '.')
3050 {
3051 __push_match_any();
3052 ++__temp;
3053 }
3054 else
3055 __temp = __parse_bracket_expression(__first, __last);
3056 }
3057 }
3058 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003059 return __first;
3060}
3061
3062template <class _CharT, class _Traits>
3063template <class _ForwardIterator>
3064_ForwardIterator
3065basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
3066 _ForwardIterator __last)
3067{
3068 if (__first != __last)
3069 {
3070 _ForwardIterator __temp = next(__first);
3071 if (__temp != __last)
3072 {
3073 if (*__first == '\\' && *__temp == '(')
3074 __first = ++__temp;
3075 }
3076 }
3077 return __first;
3078}
3079
3080template <class _CharT, class _Traits>
3081template <class _ForwardIterator>
3082_ForwardIterator
3083basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
3084 _ForwardIterator __last)
3085{
3086 if (__first != __last)
3087 {
3088 _ForwardIterator __temp = next(__first);
3089 if (__temp != __last)
3090 {
3091 if (*__first == '\\' && *__temp == ')')
3092 __first = ++__temp;
3093 }
3094 }
3095 return __first;
3096}
3097
3098template <class _CharT, class _Traits>
3099template <class _ForwardIterator>
3100_ForwardIterator
3101basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
3102 _ForwardIterator __last)
3103{
3104 if (__first != __last)
3105 {
3106 _ForwardIterator __temp = next(__first);
3107 if (__temp != __last)
3108 {
3109 if (*__first == '\\' && *__temp == '{')
3110 __first = ++__temp;
3111 }
3112 }
3113 return __first;
3114}
3115
3116template <class _CharT, class _Traits>
3117template <class _ForwardIterator>
3118_ForwardIterator
3119basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
3120 _ForwardIterator __last)
3121{
3122 if (__first != __last)
3123 {
3124 _ForwardIterator __temp = next(__first);
3125 if (__temp != __last)
3126 {
3127 if (*__first == '\\' && *__temp == '}')
3128 __first = ++__temp;
3129 }
3130 }
3131 return __first;
3132}
3133
3134template <class _CharT, class _Traits>
3135template <class _ForwardIterator>
3136_ForwardIterator
3137basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
3138 _ForwardIterator __last)
3139{
3140 if (__first != __last)
3141 {
3142 _ForwardIterator __temp = next(__first);
3143 if (__temp != __last)
3144 {
3145 if (*__first == '\\' && '1' <= *__temp && *__temp <= '9')
3146 {
3147 __push_back_ref(*__temp - '0');
3148 __first = ++__temp;
3149 }
3150 }
3151 }
3152 return __first;
3153}
3154
3155template <class _CharT, class _Traits>
3156template <class _ForwardIterator>
3157_ForwardIterator
3158basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
3159 _ForwardIterator __last)
3160{
3161 if (__first != __last)
3162 {
3163 _ForwardIterator __temp = next(__first);
3164 if (__temp == __last && *__first == '$')
3165 return __first;
3166 // Not called inside a bracket
3167 if (*__first == '.' || *__first == '\\' || *__first == '[')
3168 return __first;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003169 __push_char(*__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003170 ++__first;
3171 }
3172 return __first;
3173}
3174
3175template <class _CharT, class _Traits>
3176template <class _ForwardIterator>
3177_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003178basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
3179 _ForwardIterator __last)
3180{
3181 if (__first != __last)
3182 {
3183 switch (*__first)
3184 {
3185 case '^':
3186 case '.':
3187 case '[':
3188 case '$':
3189 case '(':
3190 case '|':
3191 case '*':
3192 case '+':
3193 case '?':
3194 case '{':
3195 case '\\':
3196 break;
3197 case ')':
3198 if (__open_count_ == 0)
3199 {
3200 __push_char(*__first);
3201 ++__first;
3202 }
3203 break;
3204 default:
3205 __push_char(*__first);
3206 ++__first;
3207 break;
3208 }
3209 }
3210 return __first;
3211}
3212
3213template <class _CharT, class _Traits>
3214template <class _ForwardIterator>
3215_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003216basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
3217 _ForwardIterator __last)
3218{
3219 if (__first != __last)
3220 {
3221 _ForwardIterator __temp = next(__first);
3222 if (__temp != __last)
3223 {
3224 if (*__first == '\\')
3225 {
3226 switch (*__temp)
3227 {
3228 case '^':
3229 case '.':
3230 case '*':
3231 case '[':
3232 case '$':
3233 case '\\':
Howard Hinnant0de86b62010-06-25 20:56:08 +00003234 __push_char(*__temp);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003235 __first = ++__temp;
3236 break;
3237 }
3238 }
3239 }
3240 }
3241 return __first;
3242}
3243
3244template <class _CharT, class _Traits>
3245template <class _ForwardIterator>
3246_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003247basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
3248 _ForwardIterator __last)
3249{
3250 if (__first != __last)
3251 {
3252 _ForwardIterator __temp = next(__first);
3253 if (__temp != __last)
3254 {
3255 if (*__first == '\\')
3256 {
3257 switch (*__temp)
3258 {
3259 case '^':
3260 case '.':
3261 case '*':
3262 case '[':
3263 case '$':
3264 case '\\':
3265 case '(':
3266 case ')':
3267 case '|':
3268 case '+':
3269 case '?':
3270 case '{':
3271 __push_char(*__temp);
3272 __first = ++__temp;
3273 break;
3274 }
3275 }
3276 }
3277 }
3278 return __first;
3279}
3280
3281template <class _CharT, class _Traits>
3282template <class _ForwardIterator>
3283_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003284basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003285 _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003286 __owns_one_state<_CharT>* __s,
3287 unsigned __mexp_begin,
3288 unsigned __mexp_end)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003289{
3290 if (__first != __last)
3291 {
Howard Hinnant0de86b62010-06-25 20:56:08 +00003292 if (*__first == '*')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003293 {
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003294 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003295 ++__first;
3296 }
3297 else
3298 {
3299 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3300 if (__temp != __first)
3301 {
3302 int __min = 0;
3303 __first = __temp;
3304 __temp = __parse_DUP_COUNT(__first, __last, __min);
3305 if (__temp == __first)
3306 throw regex_error(regex_constants::error_badbrace);
3307 __first = __temp;
3308 if (__first == __last)
3309 throw regex_error(regex_constants::error_brace);
3310 if (*__first != ',')
3311 {
3312 __temp = __parse_Back_close_brace(__first, __last);
3313 if (__temp == __first)
3314 throw regex_error(regex_constants::error_brace);
Howard Hinnantcba352d2010-07-12 18:16:05 +00003315 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
3316 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003317 __first = __temp;
3318 }
3319 else
3320 {
3321 ++__first; // consume ','
3322 int __max = -1;
3323 __first = __parse_DUP_COUNT(__first, __last, __max);
3324 __temp = __parse_Back_close_brace(__first, __last);
3325 if (__temp == __first)
3326 throw regex_error(regex_constants::error_brace);
3327 if (__max == -1)
Howard Hinnantaa698082010-07-16 19:08:36 +00003328 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003329 else
3330 {
3331 if (__max < __min)
3332 throw regex_error(regex_constants::error_badbrace);
Howard Hinnantcba352d2010-07-12 18:16:05 +00003333 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
3334 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003335 }
3336 __first = __temp;
3337 }
3338 }
3339 }
3340 }
3341 return __first;
3342}
3343
Howard Hinnant0de86b62010-06-25 20:56:08 +00003344template <class _CharT, class _Traits>
3345template <class _ForwardIterator>
3346_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003347basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantaa698082010-07-16 19:08:36 +00003348 _ForwardIterator __last,
3349 __owns_one_state<_CharT>* __s,
3350 unsigned __mexp_begin,
3351 unsigned __mexp_end)
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003352{
3353 if (__first != __last)
3354 {
3355 switch (*__first)
3356 {
3357 case '*':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003358 ++__first;
Howard Hinnant17615b02010-07-27 01:25:38 +00003359 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3360 {
3361 ++__first;
3362 __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3363 }
3364 else
3365 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003366 break;
3367 case '+':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003368 ++__first;
Howard Hinnant17615b02010-07-27 01:25:38 +00003369 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3370 {
3371 ++__first;
3372 __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3373 }
3374 else
3375 __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003376 break;
3377 case '?':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003378 ++__first;
Howard Hinnant17615b02010-07-27 01:25:38 +00003379 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3380 {
3381 ++__first;
3382 __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3383 }
3384 else
3385 __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003386 break;
3387 case '{':
3388 {
3389 int __min;
Howard Hinnantaa698082010-07-16 19:08:36 +00003390 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003391 if (__temp == __first)
3392 throw regex_error(regex_constants::error_badbrace);
3393 __first = __temp;
3394 if (__first == __last)
3395 throw regex_error(regex_constants::error_brace);
3396 switch (*__first)
3397 {
3398 case '}':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003399 ++__first;
Howard Hinnant17615b02010-07-27 01:25:38 +00003400 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3401 {
3402 ++__first;
3403 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3404 }
3405 else
3406 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003407 break;
3408 case ',':
3409 if (++__first == __last)
3410 throw regex_error(regex_constants::error_badbrace);
3411 if (*__first == '}')
3412 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003413 ++__first;
Howard Hinnant17615b02010-07-27 01:25:38 +00003414 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3415 {
3416 ++__first;
3417 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3418 }
3419 else
3420 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003421 }
3422 else
3423 {
Howard Hinnantaa698082010-07-16 19:08:36 +00003424 int __max = -1;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003425 __temp = __parse_DUP_COUNT(__first, __last, __max);
3426 if (__temp == __first)
3427 throw regex_error(regex_constants::error_brace);
3428 __first = __temp;
3429 if (__first == __last || *__first != '}')
3430 throw regex_error(regex_constants::error_brace);
3431 ++__first;
3432 if (__max < __min)
3433 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant17615b02010-07-27 01:25:38 +00003434 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3435 {
3436 ++__first;
3437 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3438 }
3439 else
3440 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003441 }
Howard Hinnantaa698082010-07-16 19:08:36 +00003442 break;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003443 default:
3444 throw regex_error(regex_constants::error_badbrace);
3445 }
3446 }
3447 break;
3448 }
3449 }
3450 return __first;
3451}
3452
3453template <class _CharT, class _Traits>
3454template <class _ForwardIterator>
3455_ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00003456basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
3457 _ForwardIterator __last)
3458{
3459 if (__first != __last && *__first == '[')
3460 {
3461 if (++__first == __last)
3462 throw regex_error(regex_constants::error_brack);
Howard Hinnant173968a2010-07-13 21:48:06 +00003463 bool __negate = false;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003464 if (*__first == '^')
3465 {
3466 ++__first;
Howard Hinnant173968a2010-07-13 21:48:06 +00003467 __negate = true;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003468 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003469 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3470 // __ml owned by *this
Howard Hinnant0de86b62010-06-25 20:56:08 +00003471 if (__first == __last)
3472 throw regex_error(regex_constants::error_brack);
3473 if (*__first == ']')
3474 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003475 __ml->__add_char(']');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003476 ++__first;
3477 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003478 __first = __parse_follow_list(__first, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003479 if (__first == __last)
3480 throw regex_error(regex_constants::error_brack);
3481 if (*__first == '-')
3482 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003483 __ml->__add_char('-');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003484 ++__first;
3485 }
3486 if (__first == __last || *__first != ']')
3487 throw regex_error(regex_constants::error_brack);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003488 ++__first;
3489 }
3490 return __first;
3491}
3492
3493template <class _CharT, class _Traits>
3494template <class _ForwardIterator>
3495_ForwardIterator
3496basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003497 _ForwardIterator __last,
3498 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003499{
3500 if (__first != __last)
3501 {
3502 while (true)
3503 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003504 _ForwardIterator __temp = __parse_expression_term(__first, __last,
3505 __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003506 if (__temp == __first)
3507 break;
3508 __first = __temp;
3509 }
3510 }
3511 return __first;
3512}
3513
3514template <class _CharT, class _Traits>
3515template <class _ForwardIterator>
3516_ForwardIterator
3517basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003518 _ForwardIterator __last,
3519 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003520{
3521 if (__first != __last && *__first != ']')
3522 {
3523 bool __parsed_one = false;
3524 _ForwardIterator __temp = next(__first);
Howard Hinnant173968a2010-07-13 21:48:06 +00003525 basic_string<_CharT> __start_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003526 if (__temp != __last && *__first == '[')
3527 {
3528 if (*__temp == '=')
Howard Hinnant173968a2010-07-13 21:48:06 +00003529 return __parse_equivalence_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003530 else if (*__temp == ':')
Howard Hinnant173968a2010-07-13 21:48:06 +00003531 return __parse_character_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003532 else if (*__temp == '.')
3533 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003534 __first = __parse_collating_symbol(++__temp, __last, __start_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003535 __parsed_one = true;
3536 }
3537 }
3538 if (!__parsed_one)
3539 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003540 __start_range = *__first;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003541 ++__first;
3542 }
3543 if (__first != __last && *__first != ']')
3544 {
3545 __temp = next(__first);
3546 if (__temp != __last && *__first == '-' && *__temp != ']')
3547 {
3548 // parse a range
Howard Hinnant173968a2010-07-13 21:48:06 +00003549 basic_string<_CharT> __end_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003550 __first = __temp;
3551 ++__temp;
3552 if (__temp != __last && *__first == '[' && *__temp == '.')
Howard Hinnant173968a2010-07-13 21:48:06 +00003553 __first = __parse_collating_symbol(++__temp, __last, __end_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003554 else
3555 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003556 __end_range = *__first;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003557 ++__first;
3558 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003559 __ml->__add_range(_STD::move(__start_range), _STD::move(__end_range));
Howard Hinnant0de86b62010-06-25 20:56:08 +00003560 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003561 else
3562 {
3563 if (__start_range.size() == 1)
3564 __ml->__add_char(__start_range[0]);
3565 else
3566 __ml->__add_digraph(__start_range[0], __start_range[1]);
3567 }
3568 }
3569 else
3570 {
3571 if (__start_range.size() == 1)
3572 __ml->__add_char(__start_range[0]);
3573 else
3574 __ml->__add_digraph(__start_range[0], __start_range[1]);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003575 }
3576 }
3577 return __first;
3578}
3579
3580template <class _CharT, class _Traits>
3581template <class _ForwardIterator>
3582_ForwardIterator
3583basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003584 _ForwardIterator __last,
3585 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003586{
3587 // Found [=
3588 // This means =] must exist
3589 value_type _Equal_close[2] = {'=', ']'};
3590 _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close,
3591 _Equal_close+2);
3592 if (__temp == __last)
3593 throw regex_error(regex_constants::error_brack);
3594 // [__first, __temp) contains all text in [= ... =]
3595 typedef typename _Traits::string_type string_type;
3596 string_type __collate_name =
3597 __traits_.lookup_collatename(__first, __temp);
3598 if (__collate_name.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003599 throw regex_error(regex_constants::error_collate);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003600 string_type __equiv_name =
3601 __traits_.transform_primary(__collate_name.begin(),
3602 __collate_name.end());
3603 if (!__equiv_name.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003604 __ml->__add_equivalence(__equiv_name);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003605 else
Howard Hinnant173968a2010-07-13 21:48:06 +00003606 {
3607 switch (__collate_name.size())
3608 {
3609 case 1:
3610 __ml->__add_char(__collate_name[0]);
3611 break;
3612 case 2:
3613 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
3614 break;
3615 default:
3616 throw regex_error(regex_constants::error_collate);
3617 }
3618 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003619 __first = next(__temp, 2);
3620 return __first;
3621}
3622
3623template <class _CharT, class _Traits>
3624template <class _ForwardIterator>
3625_ForwardIterator
3626basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003627 _ForwardIterator __last,
3628 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003629{
3630 // Found [:
3631 // This means :] must exist
3632 value_type _Colon_close[2] = {':', ']'};
3633 _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close,
3634 _Colon_close+2);
3635 if (__temp == __last)
3636 throw regex_error(regex_constants::error_brack);
3637 // [__first, __temp) contains all text in [: ... :]
3638 typedef typename _Traits::char_class_type char_class_type;
3639 char_class_type __class_type =
3640 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
3641 if (__class_type == 0)
3642 throw regex_error(regex_constants::error_brack);
Howard Hinnant173968a2010-07-13 21:48:06 +00003643 __ml->__add_class(__class_type);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003644 __first = next(__temp, 2);
3645 return __first;
3646}
3647
3648template <class _CharT, class _Traits>
3649template <class _ForwardIterator>
3650_ForwardIterator
3651basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003652 _ForwardIterator __last,
3653 basic_string<_CharT>& __col_sym)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003654{
3655 // Found [.
3656 // This means .] must exist
3657 value_type _Dot_close[2] = {'.', ']'};
3658 _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close,
3659 _Dot_close+2);
3660 if (__temp == __last)
3661 throw regex_error(regex_constants::error_brack);
3662 // [__first, __temp) contains all text in [. ... .]
3663 typedef typename _Traits::string_type string_type;
Howard Hinnant173968a2010-07-13 21:48:06 +00003664 __col_sym = __traits_.lookup_collatename(__first, __temp);
3665 switch (__col_sym.size())
3666 {
3667 case 1:
3668 case 2:
3669 break;
3670 default:
3671 throw regex_error(regex_constants::error_collate);
3672 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003673 __first = next(__temp, 2);
3674 return __first;
3675}
3676
3677template <class _CharT, class _Traits>
3678template <class _ForwardIterator>
3679_ForwardIterator
3680basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
3681 _ForwardIterator __last,
3682 int& __c)
3683{
3684 if (__first != __last && '0' <= *__first && *__first <= '9')
3685 {
3686 __c = *__first - '0';
3687 for (++__first; __first != __last && '0' <= *__first && *__first <= '9';
3688 ++__first)
3689 {
3690 __c *= 10;
3691 __c += *__first - '0';
3692 }
3693 }
3694 return __first;
3695}
3696
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003697template <class _CharT, class _Traits>
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003698template <class _ForwardIterator>
3699_ForwardIterator
3700basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
3701 _ForwardIterator __last)
3702{
3703 __owns_one_state<_CharT>* __sa = __end_;
3704 _ForwardIterator __temp = __parse_alternative(__first, __last);
3705 if (__temp == __first)
3706 __push_empty();
3707 __first = __temp;
3708 while (__first != __last && *__first == '|')
3709 {
3710 __owns_one_state<_CharT>* __sb = __end_;
3711 __temp = __parse_alternative(++__first, __last);
3712 if (__temp == __first)
3713 __push_empty();
3714 __push_alternation(__sa, __sb);
3715 __first = __temp;
3716 }
3717 return __first;
3718}
3719
3720template <class _CharT, class _Traits>
3721template <class _ForwardIterator>
3722_ForwardIterator
3723basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
3724 _ForwardIterator __last)
3725{
3726 while (true)
3727 {
3728 _ForwardIterator __temp = __parse_term(__first, __last);
3729 if (__temp == __first)
3730 break;
3731 __first = __temp;
3732 }
3733 return __first;
3734}
3735
3736template <class _CharT, class _Traits>
3737template <class _ForwardIterator>
3738_ForwardIterator
3739basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
3740 _ForwardIterator __last)
3741{
3742 _ForwardIterator __temp = __parse_assertion(__first, __last);
3743 if (__temp == __first)
3744 {
Howard Hinnant17615b02010-07-27 01:25:38 +00003745 __owns_one_state<_CharT>* __e = __end_;
3746 unsigned __mexp_begin = __marked_count_;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003747 __temp = __parse_atom(__first, __last);
3748 if (__temp != __first)
Howard Hinnant17615b02010-07-27 01:25:38 +00003749 __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
3750 __mexp_begin+1, __marked_count_+1);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003751 }
Howard Hinnant17615b02010-07-27 01:25:38 +00003752 else
3753 __first = __temp;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003754 return __first;
3755}
3756
3757template <class _CharT, class _Traits>
3758template <class _ForwardIterator>
3759_ForwardIterator
3760basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
3761 _ForwardIterator __last)
3762{
3763 if (__first != __last)
3764 {
3765 switch (*__first)
3766 {
3767 case '^':
3768 __push_l_anchor();
3769 ++__first;
3770 break;
3771 case '$':
3772 __push_r_anchor();
3773 ++__first;
3774 break;
3775 case '\\':
3776 {
3777 _ForwardIterator __temp = _STD::next(__first);
3778 if (__temp != __last)
3779 {
3780 if (*__temp == 'b')
3781 {
Howard Hinnant17615b02010-07-27 01:25:38 +00003782 __push_word_boundary(false);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003783 __first = ++__temp;
3784 }
3785 else if (*__temp == 'B')
3786 {
Howard Hinnant17615b02010-07-27 01:25:38 +00003787 __push_word_boundary(true);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003788 __first = ++__temp;
3789 }
3790 }
3791 }
3792 break;
3793 case '(':
3794 {
3795 _ForwardIterator __temp = _STD::next(__first);
3796 if (__temp != __last && *__temp == '?')
3797 {
3798 if (++__temp != __last)
3799 {
3800 switch (*__temp)
3801 {
3802 case '=':
Howard Hinnant17615b02010-07-27 01:25:38 +00003803 __push_lookahead(false);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003804 __temp = __parse_ecma_exp(++__temp, __last);
3805 if (__temp == __last || *__temp != ')')
3806 throw regex_error(regex_constants::error_paren);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003807 __first = ++__temp;
3808 break;
3809 case '!':
Howard Hinnant17615b02010-07-27 01:25:38 +00003810 __push_lookahead(true);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003811 __temp = __parse_ecma_exp(++__temp, __last);
3812 if (__temp == __last || *__temp != ')')
3813 throw regex_error(regex_constants::error_paren);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003814 __first = ++__temp;
3815 break;
3816 }
3817 }
3818 }
3819 }
3820 break;
3821 }
3822 }
3823 return __first;
3824}
3825
3826template <class _CharT, class _Traits>
3827template <class _ForwardIterator>
3828_ForwardIterator
3829basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
3830 _ForwardIterator __last)
3831{
Howard Hinnant17615b02010-07-27 01:25:38 +00003832 if (__first != __last)
3833 {
3834 switch (*__first)
3835 {
3836 case '.':
3837 __push_match_any_but_newline();
3838 ++__first;
3839 break;
3840 case '\\':
3841 __first = __parse_atom_escape(__first, __last);
3842 break;
3843 case '[':
3844 __first = __parse_bracket_expression(__first, __last);
3845 break;
3846 case '(':
3847 {
3848 if (++__first == __last)
3849 throw regex_error(regex_constants::error_paren);
3850 _ForwardIterator __temp = _STD::next(__first);
3851 if (__temp != __last && *__first == '?' && *__temp == ':')
3852 {
3853 ++__open_count_;
3854 __first = __parse_ecma_exp(++__temp, __last);
3855 if (__first == __last || *__first != ')')
3856 throw regex_error(regex_constants::error_paren);
3857 --__open_count_;
3858 ++__first;
3859 }
3860 else
3861 {
3862 __push_begin_marked_subexpression();
3863 unsigned __temp_count = __marked_count_;
3864 ++__open_count_;
3865 __first = __parse_ecma_exp(__first, __last);
3866 if (__first == __last || *__first != ')')
3867 throw regex_error(regex_constants::error_paren);
3868 __push_end_marked_subexpression(__temp_count);
3869 --__open_count_;
3870 ++__first;
3871 }
3872 }
3873 break;
3874 default:
3875 __first = __parse_pattern_character(__first, __last);
3876 break;
3877 }
3878 }
3879 return __first;
3880}
3881
3882template <class _CharT, class _Traits>
3883template <class _ForwardIterator>
3884_ForwardIterator
3885basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
3886 _ForwardIterator __last)
3887{
3888 if (__first != __last && *__first == '\\')
3889 {
3890 _ForwardIterator __t1 = _STD::next(__first);
3891 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
3892 if (__t2 != __t1)
3893 __first = __t2;
3894 else
3895 {
3896 __t2 = __parse_character_class_escape(__t1, __last);
3897 if (__t2 != __t1)
3898 __first = __t2;
3899 else
3900 {
3901 __t2 = __parse_character_escape(__t1, __last);
3902 if (__t2 != __t1)
3903 __first = __t2;
3904 }
3905 }
3906 }
3907 return __first;
3908}
3909
3910template <class _CharT, class _Traits>
3911template <class _ForwardIterator>
3912_ForwardIterator
3913basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
3914 _ForwardIterator __last)
3915{
3916 if (__first != __last)
3917 {
3918 if (*__first == '0')
3919 {
3920 __push_char(_CharT());
3921 ++__first;
3922 }
3923 else if ('1' <= *__first && *__first <= '9')
3924 {
3925 unsigned __v = *__first - '0';
3926 for (++__first; '0' <= *__first && *__first <= '9'; ++__first)
3927 __v = 10 * __v + *__first - '0';
3928 if (__v > mark_count())
3929 throw regex_error(regex_constants::error_backref);
3930 __push_back_ref(__v);
3931 }
3932 }
3933 return __first;
3934}
3935
3936template <class _CharT, class _Traits>
3937template <class _ForwardIterator>
3938_ForwardIterator
3939basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
3940 _ForwardIterator __last)
3941{
3942 if (__first != __last)
3943 {
3944 __bracket_expression<_CharT, _Traits>* __ml;
3945 switch (*__first)
3946 {
3947 case 'd':
3948 __ml = __start_matching_list(false);
3949 __ml->__add_class(ctype_base::digit);
3950 ++__first;
3951 break;
3952 case 'D':
3953 __ml = __start_matching_list(true);
3954 __ml->__add_class(ctype_base::digit);
3955 ++__first;
3956 break;
3957 case 's':
3958 __ml = __start_matching_list(false);
3959 __ml->__add_class(ctype_base::space);
3960 ++__first;
3961 break;
3962 case 'S':
3963 __ml = __start_matching_list(true);
3964 __ml->__add_class(ctype_base::space);
3965 ++__first;
3966 break;
3967 case 'w':
3968 __ml = __start_matching_list(false);
3969 __ml->__add_class(ctype_base::alnum);
3970 __ml->__add_char('_');
3971 ++__first;
3972 break;
3973 case 'W':
3974 __ml = __start_matching_list(true);
3975 __ml->__add_class(ctype_base::alnum);
3976 __ml->__add_char('_');
3977 ++__first;
3978 break;
3979 }
3980 }
3981 return __first;
3982}
3983
3984template <class _CharT, class _Traits>
3985template <class _ForwardIterator>
3986_ForwardIterator
3987basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
3988 _ForwardIterator __last)
3989{
3990 if (__first != __last)
3991 {
3992 _ForwardIterator __t;
3993 unsigned __sum = 0;
3994 int __hd;
3995 switch (*__first)
3996 {
3997 case 'f':
3998 __push_char(_CharT(0xC));
3999 ++__first;
4000 break;
4001 case 'n':
4002 __push_char(_CharT(0xA));
4003 ++__first;
4004 break;
4005 case 'r':
4006 __push_char(_CharT(0xD));
4007 ++__first;
4008 break;
4009 case 't':
4010 __push_char(_CharT(0x9));
4011 ++__first;
4012 break;
4013 case 'v':
4014 __push_char(_CharT(0xB));
4015 ++__first;
4016 break;
4017 case 'c':
4018 if ((__t = _STD::next(__first)) != __last)
4019 {
4020 if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z')
4021 {
4022 __push_char(_CharT(*__t % 32));
4023 __first = ++__t;
4024 }
4025 }
4026 break;
4027 case 'u':
4028 if (++__first == __last)
4029 throw regex_error(regex_constants::error_escape);
4030 __hd = __traits_.value(*__first, 16);
4031 if (__hd == -1)
4032 throw regex_error(regex_constants::error_escape);
4033 __sum = 16 * __sum + __hd;
4034 if (++__first == __last)
4035 throw regex_error(regex_constants::error_escape);
4036 __hd = __traits_.value(*__first, 16);
4037 if (__hd == -1)
4038 throw regex_error(regex_constants::error_escape);
4039 __sum = 16 * __sum + __hd;
4040 // drop through
4041 case 'x':
4042 if (++__first == __last)
4043 throw regex_error(regex_constants::error_escape);
4044 __hd = __traits_.value(*__first, 16);
4045 if (__hd == -1)
4046 throw regex_error(regex_constants::error_escape);
4047 __sum = 16 * __sum + __hd;
4048 if (++__first == __last)
4049 throw regex_error(regex_constants::error_escape);
4050 __hd = __traits_.value(*__first, 16);
4051 if (__hd == -1)
4052 throw regex_error(regex_constants::error_escape);
4053 __sum = 16 * __sum + __hd;
4054 __push_char(_CharT(__sum));
4055 ++__first;
4056 break;
4057 default:
4058 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
4059 {
4060 __push_char(*__first);
4061 ++__first;
4062 }
4063 break;
4064 }
4065 }
4066 return __first;
4067}
4068
4069template <class _CharT, class _Traits>
4070template <class _ForwardIterator>
4071_ForwardIterator
4072basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
4073 _ForwardIterator __last)
4074{
4075 if (__first != __last)
4076 {
4077 switch (*__first)
4078 {
4079 case '^':
4080 case '$':
4081 case '\\':
4082 case '.':
4083 case '*':
4084 case '+':
4085 case '?':
4086 case '(':
4087 case ')':
4088 case '[':
4089 case ']':
4090 case '{':
4091 case '}':
4092 case '|':
4093 break;
4094 default:
4095 __push_char(*__first);
4096 ++__first;
4097 break;
4098 }
4099 }
4100 return __first;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004101}
4102
4103template <class _CharT, class _Traits>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004104void
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004105basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
4106 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
4107 bool __greedy)
4108{
4109 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4110 __end_->first() = nullptr;
Howard Hinnantac303862010-07-12 15:51:17 +00004111 unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
4112 __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
4113 __min, __max));
4114 __s->first() = nullptr;
4115 __e1.release();
4116 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004117 __end_ = __e2->second();
Howard Hinnantac303862010-07-12 15:51:17 +00004118 __s->first() = __e2.release();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004119 ++__loop_count_;
4120}
4121
4122template <class _CharT, class _Traits>
4123void
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004124basic_regex<_CharT, _Traits>::__push_char(value_type __c)
4125{
Howard Hinnant173968a2010-07-13 21:48:06 +00004126 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004127 __end_->first() = new __match_char_icase<_CharT, _Traits>
4128 (__traits_, __c, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004129 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004130 __end_->first() = new __match_char_collate<_CharT, _Traits>
4131 (__traits_, __c, __end_->first());
4132 else
4133 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
Howard Hinnante77aa5e2010-07-08 17:43:58 +00004134 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004135}
4136
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004137template <class _CharT, class _Traits>
4138void
4139basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
4140{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004141 if (!(__flags_ & nosubs))
4142 {
4143 __end_->first() =
4144 new __begin_marked_subexpression<_CharT>(++__marked_count_,
4145 __end_->first());
4146 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4147 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004148}
4149
4150template <class _CharT, class _Traits>
4151void
4152basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
4153{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004154 if (!(__flags_ & nosubs))
4155 {
4156 __end_->first() =
4157 new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4158 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4159 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004160}
4161
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004162template <class _CharT, class _Traits>
4163void
4164basic_regex<_CharT, _Traits>::__push_r_anchor()
4165{
4166 __end_->first() = new __r_anchor<_CharT>(__end_->first());
4167 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4168}
4169
Howard Hinnantac303862010-07-12 15:51:17 +00004170template <class _CharT, class _Traits>
4171void
4172basic_regex<_CharT, _Traits>::__push_match_any()
4173{
4174 __end_->first() = new __match_any<_CharT>(__end_->first());
4175 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4176}
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004177
Howard Hinnantcba352d2010-07-12 18:16:05 +00004178template <class _CharT, class _Traits>
4179void
Howard Hinnant17615b02010-07-27 01:25:38 +00004180basic_regex<_CharT, _Traits>::__push_match_any_but_newline()
4181{
4182 __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
4183 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4184}
4185
4186template <class _CharT, class _Traits>
4187void
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004188basic_regex<_CharT, _Traits>::__push_empty()
4189{
4190 __end_->first() = new __empty_state<_CharT>(__end_->first());
4191 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4192}
4193
4194template <class _CharT, class _Traits>
4195void
Howard Hinnant17615b02010-07-27 01:25:38 +00004196basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
4197{
4198 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
4199 __end_->first());
4200 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4201}
4202
4203template <class _CharT, class _Traits>
4204void
Howard Hinnantcba352d2010-07-12 18:16:05 +00004205basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
4206{
Howard Hinnant173968a2010-07-13 21:48:06 +00004207 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004208 __end_->first() = new __back_ref_icase<_CharT, _Traits>
4209 (__traits_, __i, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004210 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004211 __end_->first() = new __back_ref_collate<_CharT, _Traits>
4212 (__traits_, __i, __end_->first());
4213 else
4214 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
Howard Hinnantcba352d2010-07-12 18:16:05 +00004215 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4216}
4217
Howard Hinnant173968a2010-07-13 21:48:06 +00004218template <class _CharT, class _Traits>
Howard Hinnantaa698082010-07-16 19:08:36 +00004219void
4220basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
4221 __owns_one_state<_CharT>* __ea)
4222{
4223 __sa->first() = new __alternate<_CharT>(
4224 static_cast<__owns_one_state<_CharT>*>(__sa->first()),
4225 static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4226 __ea->first() = nullptr;
4227 __ea->first() = new __empty_state<_CharT>(__end_->first());
4228 __end_->first() = nullptr;
4229 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4230 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4231}
4232
4233template <class _CharT, class _Traits>
Howard Hinnant173968a2010-07-13 21:48:06 +00004234__bracket_expression<_CharT, _Traits>*
4235basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
4236{
4237 __bracket_expression<_CharT, _Traits>* __r =
4238 new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
4239 __negate, __flags_ & icase,
4240 __flags_ & collate);
4241 __end_->first() = __r;
4242 __end_ = __r;
4243 return __r;
4244}
4245
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00004246typedef basic_regex<char> regex;
4247typedef basic_regex<wchar_t> wregex;
4248
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004249// sub_match
4250
4251template <class _BidirectionalIterator>
4252class sub_match
4253 : public pair<_BidirectionalIterator, _BidirectionalIterator>
4254{
4255public:
4256 typedef _BidirectionalIterator iterator;
4257 typedef typename iterator_traits<iterator>::value_type value_type;
4258 typedef typename iterator_traits<iterator>::difference_type difference_type;
4259 typedef basic_string<value_type> string_type;
4260
4261 bool matched;
4262
4263 difference_type length() const
4264 {return matched ? _STD::distance(this->first, this->second) : 0;}
4265 string_type str() const
4266 {return matched ? string_type(this->first, this->second) : string_type();}
4267 operator string_type() const
4268 {return str();}
4269
4270 int compare(const sub_match& __s) const
4271 {return str().compare(__s.str());}
4272 int compare(const string_type& __s) const
4273 {return str().compare(__s);}
4274 int compare(const value_type* __s) const
4275 {return str().compare(__s);}
4276};
4277
4278typedef sub_match<const char*> csub_match;
4279typedef sub_match<const wchar_t*> wcsub_match;
4280typedef sub_match<string::const_iterator> ssub_match;
4281typedef sub_match<wstring::const_iterator> wssub_match;
4282
4283template <class _BiIter>
4284inline _LIBCPP_INLINE_VISIBILITY
4285bool
4286operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4287{
4288 return __x.compare(__y) == 0;
4289}
4290
4291template <class _BiIter>
4292inline _LIBCPP_INLINE_VISIBILITY
4293bool
4294operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4295{
4296 return !(__x == __y);
4297}
4298
4299template <class _BiIter>
4300inline _LIBCPP_INLINE_VISIBILITY
4301bool
4302operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4303{
4304 return __x.compare(__y) < 0;
4305}
4306
4307template <class _BiIter>
4308inline _LIBCPP_INLINE_VISIBILITY
4309bool
4310operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4311{
4312 return !(__y < __x);
4313}
4314
4315template <class _BiIter>
4316inline _LIBCPP_INLINE_VISIBILITY
4317bool
4318operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4319{
4320 return !(__x < __y);
4321}
4322
4323template <class _BiIter>
4324inline _LIBCPP_INLINE_VISIBILITY
4325bool
4326operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4327{
4328 return __y < __x;
4329}
4330
4331template <class _BiIter, class _ST, class _SA>
4332inline _LIBCPP_INLINE_VISIBILITY
4333bool
4334operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4335 const sub_match<_BiIter>& __y)
4336{
4337 return __y.compare(__x.c_str()) == 0;
4338}
4339
4340template <class _BiIter, class _ST, class _SA>
4341inline _LIBCPP_INLINE_VISIBILITY
4342bool
4343operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4344 const sub_match<_BiIter>& __y)
4345{
4346 return !(__x == __y);
4347}
4348
4349template <class _BiIter, class _ST, class _SA>
4350inline _LIBCPP_INLINE_VISIBILITY
4351bool
4352operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4353 const sub_match<_BiIter>& __y)
4354{
4355 return __y.compare(__x.c_str()) > 0;
4356}
4357
4358template <class _BiIter, class _ST, class _SA>
4359inline _LIBCPP_INLINE_VISIBILITY
4360bool
4361operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4362 const sub_match<_BiIter>& __y)
4363{
4364 return __y < __x;
4365}
4366
4367template <class _BiIter, class _ST, class _SA>
4368inline _LIBCPP_INLINE_VISIBILITY
4369bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4370 const sub_match<_BiIter>& __y)
4371{
4372 return !(__x < __y);
4373}
4374
4375template <class _BiIter, class _ST, class _SA>
4376inline _LIBCPP_INLINE_VISIBILITY
4377bool
4378operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4379 const sub_match<_BiIter>& __y)
4380{
4381 return !(__y < __x);
4382}
4383
4384template <class _BiIter, class _ST, class _SA>
4385inline _LIBCPP_INLINE_VISIBILITY
4386bool
4387operator==(const sub_match<_BiIter>& __x,
4388 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4389{
4390 return __x.compare(__y.c_str()) == 0;
4391}
4392
4393template <class _BiIter, class _ST, class _SA>
4394inline _LIBCPP_INLINE_VISIBILITY
4395bool
4396operator!=(const sub_match<_BiIter>& __x,
4397 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4398{
4399 return !(__x == __y);
4400}
4401
4402template <class _BiIter, class _ST, class _SA>
4403inline _LIBCPP_INLINE_VISIBILITY
4404bool
4405operator<(const sub_match<_BiIter>& __x,
4406 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4407{
4408 return __x.compare(__y.c_str()) < 0;
4409}
4410
4411template <class _BiIter, class _ST, class _SA>
4412inline _LIBCPP_INLINE_VISIBILITY
4413bool operator>(const sub_match<_BiIter>& __x,
4414 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4415{
4416 return __y < __x;
4417}
4418
4419template <class _BiIter, class _ST, class _SA>
4420inline _LIBCPP_INLINE_VISIBILITY
4421bool
4422operator>=(const sub_match<_BiIter>& __x,
4423 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4424{
4425 return !(__x < __y);
4426}
4427
4428template <class _BiIter, class _ST, class _SA>
4429inline _LIBCPP_INLINE_VISIBILITY
4430bool
4431operator<=(const sub_match<_BiIter>& __x,
4432 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4433{
4434 return !(__y < __x);
4435}
4436
4437template <class _BiIter>
4438inline _LIBCPP_INLINE_VISIBILITY
4439bool
4440operator==(typename iterator_traits<_BiIter>::value_type const* __x,
4441 const sub_match<_BiIter>& __y)
4442{
4443 return __y.compare(__x) == 0;
4444}
4445
4446template <class _BiIter>
4447inline _LIBCPP_INLINE_VISIBILITY
4448bool
4449operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
4450 const sub_match<_BiIter>& __y)
4451{
4452 return !(__x == __y);
4453}
4454
4455template <class _BiIter>
4456inline _LIBCPP_INLINE_VISIBILITY
4457bool
4458operator<(typename iterator_traits<_BiIter>::value_type const* __x,
4459 const sub_match<_BiIter>& __y)
4460{
4461 return __y.compare(__x) > 0;
4462}
4463
4464template <class _BiIter>
4465inline _LIBCPP_INLINE_VISIBILITY
4466bool
4467operator>(typename iterator_traits<_BiIter>::value_type const* __x,
4468 const sub_match<_BiIter>& __y)
4469{
4470 return __y < __x;
4471}
4472
4473template <class _BiIter>
4474inline _LIBCPP_INLINE_VISIBILITY
4475bool
4476operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
4477 const sub_match<_BiIter>& __y)
4478{
4479 return !(__x < __y);
4480}
4481
4482template <class _BiIter>
4483inline _LIBCPP_INLINE_VISIBILITY
4484bool
4485operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
4486 const sub_match<_BiIter>& __y)
4487{
4488 return !(__y < __x);
4489}
4490
4491template <class _BiIter>
4492inline _LIBCPP_INLINE_VISIBILITY
4493bool
4494operator==(const sub_match<_BiIter>& __x,
4495 typename iterator_traits<_BiIter>::value_type const* __y)
4496{
4497 return __x.compare(__y) == 0;
4498}
4499
4500template <class _BiIter>
4501inline _LIBCPP_INLINE_VISIBILITY
4502bool
4503operator!=(const sub_match<_BiIter>& __x,
4504 typename iterator_traits<_BiIter>::value_type const* __y)
4505{
4506 return !(__x == __y);
4507}
4508
4509template <class _BiIter>
4510inline _LIBCPP_INLINE_VISIBILITY
4511bool
4512operator<(const sub_match<_BiIter>& __x,
4513 typename iterator_traits<_BiIter>::value_type const* __y)
4514{
4515 return __x.compare(__y) < 0;
4516}
4517
4518template <class _BiIter>
4519inline _LIBCPP_INLINE_VISIBILITY
4520bool
4521operator>(const sub_match<_BiIter>& __x,
4522 typename iterator_traits<_BiIter>::value_type const* __y)
4523{
4524 return __y < __x;
4525}
4526
4527template <class _BiIter>
4528inline _LIBCPP_INLINE_VISIBILITY
4529bool
4530operator>=(const sub_match<_BiIter>& __x,
4531 typename iterator_traits<_BiIter>::value_type const* __y)
4532{
4533 return !(__x < __y);
4534}
4535
4536template <class _BiIter>
4537inline _LIBCPP_INLINE_VISIBILITY
4538bool
4539operator<=(const sub_match<_BiIter>& __x,
4540 typename iterator_traits<_BiIter>::value_type const* __y)
4541{
4542 return !(__y < __x);
4543}
4544
4545template <class _BiIter>
4546inline _LIBCPP_INLINE_VISIBILITY
4547bool
4548operator==(typename iterator_traits<_BiIter>::value_type const& __x,
4549 const sub_match<_BiIter>& __y)
4550{
4551 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4552 return __y.compare(string_type(1, __x)) == 0;
4553}
4554
4555template <class _BiIter>
4556inline _LIBCPP_INLINE_VISIBILITY
4557bool
4558operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
4559 const sub_match<_BiIter>& __y)
4560{
4561 return !(__x == __y);
4562}
4563
4564template <class _BiIter>
4565inline _LIBCPP_INLINE_VISIBILITY
4566bool
4567operator<(typename iterator_traits<_BiIter>::value_type const& __x,
4568 const sub_match<_BiIter>& __y)
4569{
4570 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4571 return __y.compare(string_type(1, __x)) > 0;
4572}
4573
4574template <class _BiIter>
4575inline _LIBCPP_INLINE_VISIBILITY
4576bool
4577operator>(typename iterator_traits<_BiIter>::value_type const& __x,
4578 const sub_match<_BiIter>& __y)
4579{
4580 return __y < __x;
4581}
4582
4583template <class _BiIter>
4584inline _LIBCPP_INLINE_VISIBILITY
4585bool
4586operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
4587 const sub_match<_BiIter>& __y)
4588{
4589 return !(__x < __y);
4590}
4591
4592template <class _BiIter>
4593inline _LIBCPP_INLINE_VISIBILITY
4594bool
4595operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
4596 const sub_match<_BiIter>& __y)
4597{
4598 return !(__y < __x);
4599}
4600
4601template <class _BiIter>
4602inline _LIBCPP_INLINE_VISIBILITY
4603bool
4604operator==(const sub_match<_BiIter>& __x,
4605 typename iterator_traits<_BiIter>::value_type const& __y)
4606{
4607 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4608 return __x.compare(string_type(1, __y)) == 0;
4609}
4610
4611template <class _BiIter>
4612inline _LIBCPP_INLINE_VISIBILITY
4613bool
4614operator!=(const sub_match<_BiIter>& __x,
4615 typename iterator_traits<_BiIter>::value_type const& __y)
4616{
4617 return !(__x == __y);
4618}
4619
4620template <class _BiIter>
4621inline _LIBCPP_INLINE_VISIBILITY
4622bool
4623operator<(const sub_match<_BiIter>& __x,
4624 typename iterator_traits<_BiIter>::value_type const& __y)
4625{
4626 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4627 return __x.compare(string_type(1, __y)) < 0;
4628}
4629
4630template <class _BiIter>
4631inline _LIBCPP_INLINE_VISIBILITY
4632bool
4633operator>(const sub_match<_BiIter>& __x,
4634 typename iterator_traits<_BiIter>::value_type const& __y)
4635{
4636 return __y < __x;
4637}
4638
4639template <class _BiIter>
4640inline _LIBCPP_INLINE_VISIBILITY
4641bool
4642operator>=(const sub_match<_BiIter>& __x,
4643 typename iterator_traits<_BiIter>::value_type const& __y)
4644{
4645 return !(__x < __y);
4646}
4647
4648template <class _BiIter>
4649inline _LIBCPP_INLINE_VISIBILITY
4650bool
4651operator<=(const sub_match<_BiIter>& __x,
4652 typename iterator_traits<_BiIter>::value_type const& __y)
4653{
4654 return !(__y < __x);
4655}
4656
4657template <class _CharT, class _ST, class _BiIter>
4658inline _LIBCPP_INLINE_VISIBILITY
4659basic_ostream<_CharT, _ST>&
4660operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
4661{
4662 return __os << __m.str();
4663}
4664
Howard Hinnant17615b02010-07-27 01:25:38 +00004665template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00004666class match_results
4667{
4668public:
4669 typedef _Allocator allocator_type;
4670 typedef sub_match<_BidirectionalIterator> value_type;
4671private:
4672 typedef vector<value_type, allocator_type> __container_type;
4673
4674 __container_type __matches_;
4675 value_type __unmatched_;
4676 value_type __prefix_;
4677 value_type __suffix_;
4678public:
4679 typedef const value_type& const_reference;
4680 typedef const_reference reference;
4681 typedef typename __container_type::const_iterator const_iterator;
4682 typedef const_iterator iterator;
4683 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
4684 typedef typename allocator_traits<allocator_type>::size_type size_type;
4685 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
4686 typedef basic_string<char_type> string_type;
4687
4688 // construct/copy/destroy:
4689 explicit match_results(const allocator_type& __a = allocator_type());
4690// match_results(const match_results&) = default;
4691// match_results& operator=(const match_results&) = default;
4692#ifdef _LIBCPP_MOVE
4693// match_results(match_results&& __m) = default;
4694// match_results& operator=(match_results&& __m) = default;
4695#endif
4696// ~match_results() = default;
4697
4698 // size:
4699 size_type size() const {return __matches_.size();}
4700 size_type max_size() const {return __matches_.max_size();}
4701 bool empty() const {return size() == 0;}
4702
4703 // element access:
4704 difference_type length(size_type __sub = 0) const
4705 {return (*this)[__sub].length();}
4706 difference_type position(size_type __sub = 0) const
4707 {return _STD::distance(__prefix_.first, (*this)[__sub].first);}
4708 string_type str(size_type __sub = 0) const
4709 {return (*this)[__sub].str();}
4710 const_reference operator[](size_type __n) const
4711 {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
4712
4713 const_reference prefix() const {return __prefix_;}
4714 const_reference suffix() const {return __suffix_;}
4715
4716 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
4717 const_iterator end() const {return __matches_.end();}
4718 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
4719 const_iterator cend() const {return __matches_.end();}
4720
4721 // format:
4722 template <class _OutputIter>
4723 _OutputIter
4724 format(_OutputIter __out, const char_type* __fmt_first,
4725 const char_type* __fmt_last,
4726 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
4727 template <class _OutputIter, class _ST, class _SA>
4728 _OutputIter
4729 format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt,
4730 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
4731 template <class _ST, class _SA>
4732 basic_string<char_type, _ST, _SA>
4733 format(const basic_string<char_type, _ST, _SA>& __fmt,
4734 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
4735 string_type
4736 format(const char_type* __fmt,
4737 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
4738
4739 // allocator:
4740 allocator_type get_allocator() const {return __matches_.get_allocator();}
4741
4742 // swap:
4743 void swap(match_results& __m);
4744
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004745 template <class _B, class _A>
4746 void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
4747 const match_results<_B, _A>& __m)
4748 {
4749 _B __mf = __m.prefix().first;
4750 __matches_.resize(__m.size());
4751 for (size_type __i = 0; __i < __matches_.size(); ++__i)
4752 {
4753 __matches_[__i].first = next(__f, _STD::distance(__mf, __m[__i].first));
4754 __matches_[__i].second = next(__f, _STD::distance(__mf, __m[__i].second));
4755 __matches_[__i].matched = __m[__i].matched;
4756 }
4757 __unmatched_.first = __l;
4758 __unmatched_.second = __l;
4759 __unmatched_.matched = false;
4760 __prefix_.first = next(__f, _STD::distance(__mf, __m.prefix().first));
4761 __prefix_.second = next(__f, _STD::distance(__mf, __m.prefix().second));
4762 __prefix_.matched = __m.prefix().matched;
4763 __suffix_.first = next(__f, _STD::distance(__mf, __m.suffix().first));
4764 __suffix_.second = next(__f, _STD::distance(__mf, __m.suffix().second));
4765 __suffix_.matched = __m.suffix().matched;
4766 }
4767
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004768private:
4769 void __init(unsigned __s,
4770 _BidirectionalIterator __f, _BidirectionalIterator __l);
4771
4772 template <class, class> friend class basic_regex;
4773
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00004774 template <class _B, class _A, class _C, class _T>
4775 friend
4776 bool
4777 regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
4778 regex_constants::match_flag_type);
4779};
4780
4781template <class _BidirectionalIterator, class _Allocator>
4782match_results<_BidirectionalIterator, _Allocator>::match_results(
4783 const allocator_type& __a)
4784 : __matches_(__a),
4785 __unmatched_(),
4786 __prefix_(),
4787 __suffix_()
4788{
4789}
4790
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004791template <class _BidirectionalIterator, class _Allocator>
4792void
4793match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
4794 _BidirectionalIterator __f, _BidirectionalIterator __l)
4795{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004796 __unmatched_.first = __l;
4797 __unmatched_.second = __l;
4798 __unmatched_.matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004799 __matches_.assign(__s, __unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004800 __prefix_.first = __f;
4801 __prefix_.second = __f;
4802 __prefix_.matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00004803 __suffix_ = __unmatched_;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004804}
4805
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00004806typedef match_results<const char*> cmatch;
4807typedef match_results<const wchar_t*> wcmatch;
4808typedef match_results<string::const_iterator> smatch;
4809typedef match_results<wstring::const_iterator> wsmatch;
4810
4811template <class _BidirectionalIterator, class _Allocator>
4812 bool
4813 operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
4814 const match_results<_BidirectionalIterator, _Allocator>& __y);
4815
4816template <class _BidirectionalIterator, class _Allocator>
4817 bool
4818 operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
4819 const match_results<_BidirectionalIterator, _Allocator>& __y);
4820
4821template <class _BidirectionalIterator, class _Allocator>
4822 void
4823 swap(match_results<_BidirectionalIterator, _Allocator>& __x,
4824 match_results<_BidirectionalIterator, _Allocator>& __y);
4825
4826// regex_search
4827
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004828template <class _CharT, class _Traits>
Howard Hinnant17615b02010-07-27 01:25:38 +00004829template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004830bool
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004831basic_regex<_CharT, _Traits>::__match_at_start_ecma(
Howard Hinnant17615b02010-07-27 01:25:38 +00004832 const _CharT* __first, const _CharT* __last,
4833 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004834 regex_constants::match_flag_type __flags) const
4835{
Howard Hinnant17615b02010-07-27 01:25:38 +00004836 vector<__state> __states;
4837 ptrdiff_t __j = 0;
4838 ptrdiff_t _N = _STD::distance(__first, __last);
4839 __node* __st = __start_.get();
4840 if (__st)
4841 {
4842 __states.push_back(__state());
4843 __states.back().__do_ = 0;
4844 __states.back().__first_ = __first;
4845 __states.back().__current_ = __first;
4846 __states.back().__last_ = __last;
4847 __states.back().__sub_matches_.resize(mark_count());
4848 __states.back().__loop_data_.resize(__loop_count());
4849 __states.back().__node_ = __st;
4850 __states.back().__flags_ = __flags;
4851 bool __matched = false;
4852 do
4853 {
4854 __state& __s = __states.back();
4855 if (__s.__node_)
4856 __s.__node_->__exec(__s);
4857 switch (__s.__do_)
4858 {
4859 case __state::__end_state:
4860 __m.__matches_[0].first = __first;
4861 __m.__matches_[0].second = _STD::next(__first, __s.__current_ - __first);
4862 __m.__matches_[0].matched = true;
4863 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
4864 __m.__matches_[__i+1] = __s.__sub_matches_[__i];
4865 return true;
4866 case __state::__accept_and_consume:
4867 case __state::__repeat:
4868 case __state::__accept_but_not_consume:
4869 break;
4870 case __state::__split:
4871 {
4872 __state __snext = __s;
4873 __s.__node_->__exec_split(true, __s);
4874 __snext.__node_->__exec_split(false, __snext);
4875 __states.push_back(_STD::move(__snext));
4876 }
4877 break;
4878 case __state::__reject:
4879 __states.pop_back();
4880 break;
4881 default:
4882 throw regex_error(regex_constants::error_temp);
4883 break;
4884 }
4885 } while (!__states.empty());
4886 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004887 return false;
4888}
4889
4890template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004891template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004892bool
4893basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
4894 const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004895 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004896 vector<size_t>& __lc,
4897 regex_constants::match_flag_type __flags) const
4898{
Howard Hinnantac303862010-07-12 15:51:17 +00004899 deque<__state> __states;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004900 ptrdiff_t __highest_j = 0;
4901 ptrdiff_t _N = _STD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00004902 __node* __st = __start_.get();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004903 if (__st)
4904 {
Howard Hinnantac303862010-07-12 15:51:17 +00004905 __states.push_back(__state());
Howard Hinnantac303862010-07-12 15:51:17 +00004906 __states.back().__do_ = 0;
4907 __states.back().__first_ = __first;
4908 __states.back().__current_ = __first;
4909 __states.back().__last_ = __last;
4910 __states.back().__loop_data_.resize(__loop_count());
4911 __states.back().__node_ = __st;
4912 __states.back().__flags_ = __flags;
Howard Hinnant68025ed2010-07-14 15:45:11 +00004913 bool __matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004914 do
4915 {
Howard Hinnantac303862010-07-12 15:51:17 +00004916 __state& __s = __states.back();
4917 if (__s.__node_)
4918 __s.__node_->__exec(__s);
4919 switch (__s.__do_)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004920 {
Howard Hinnantac303862010-07-12 15:51:17 +00004921 case __state::__end_state:
Howard Hinnant68025ed2010-07-14 15:45:11 +00004922 if (__highest_j < __s.__current_ - __s.__first_)
4923 {
4924 __highest_j = __s.__current_ - __s.__first_;
4925 __matched = true;
4926 }
Howard Hinnantac303862010-07-12 15:51:17 +00004927 if (__highest_j == _N)
4928 __states.clear();
4929 else
4930 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004931 break;
Howard Hinnantac303862010-07-12 15:51:17 +00004932 case __state::__consume_input:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004933 break;
Howard Hinnantac303862010-07-12 15:51:17 +00004934 case __state::__accept_and_consume:
Howard Hinnantac303862010-07-12 15:51:17 +00004935 __states.push_front(_STD::move(__s));
4936 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004937 break;
Howard Hinnantac303862010-07-12 15:51:17 +00004938 case __state::__repeat:
4939 case __state::__accept_but_not_consume:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004940 break;
Howard Hinnantac303862010-07-12 15:51:17 +00004941 case __state::__split:
4942 {
4943 __state __snext = __s;
4944 __s.__node_->__exec_split(true, __s);
4945 __snext.__node_->__exec_split(false, __snext);
4946 __states.push_back(_STD::move(__snext));
4947 }
4948 break;
4949 case __state::__reject:
4950 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004951 break;
4952 default:
4953 throw regex_error(regex_constants::error_temp);
4954 break;
4955 }
Howard Hinnantac303862010-07-12 15:51:17 +00004956 } while (!__states.empty());
Howard Hinnant68025ed2010-07-14 15:45:11 +00004957 if (__matched)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004958 {
4959 __m.__matches_[0].first = __first;
4960 __m.__matches_[0].second = _STD::next(__first, __highest_j);
4961 __m.__matches_[0].matched = true;
4962 return true;
4963 }
4964 }
4965 return false;
4966}
4967
4968template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004969template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004970bool
4971basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004972 const _CharT* __first, const _CharT* __last,
4973 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00004974 vector<size_t>& __lc,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004975 regex_constants::match_flag_type __flags) const
4976{
Howard Hinnantac303862010-07-12 15:51:17 +00004977 vector<__state> __states;
Howard Hinnantac303862010-07-12 15:51:17 +00004978 __state __best_state;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004979 ptrdiff_t __j = 0;
4980 ptrdiff_t __highest_j = 0;
4981 ptrdiff_t _N = _STD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00004982 __node* __st = __start_.get();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00004983 if (__st)
4984 {
Howard Hinnantac303862010-07-12 15:51:17 +00004985 __states.push_back(__state());
4986 __states.back().__do_ = 0;
4987 __states.back().__first_ = __first;
4988 __states.back().__current_ = __first;
4989 __states.back().__last_ = __last;
4990 __states.back().__sub_matches_.resize(mark_count());
4991 __states.back().__loop_data_.resize(__loop_count());
4992 __states.back().__node_ = __st;
4993 __states.back().__flags_ = __flags;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004994 const _CharT* __current = __first;
Howard Hinnantac303862010-07-12 15:51:17 +00004995 bool __matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00004996 do
4997 {
Howard Hinnantac303862010-07-12 15:51:17 +00004998 __state& __s = __states.back();
4999 if (__s.__node_)
5000 __s.__node_->__exec(__s);
5001 switch (__s.__do_)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005002 {
Howard Hinnantac303862010-07-12 15:51:17 +00005003 case __state::__end_state:
5004 if (__j == 0 || __highest_j < __j)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005005 {
Howard Hinnantac303862010-07-12 15:51:17 +00005006 __matched = true;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005007 __highest_j = __j;
Howard Hinnantac303862010-07-12 15:51:17 +00005008 __best_state = __s;
5009 if (__highest_j == _N || __highest_j == 0)
5010 __states.clear();
5011 else
5012 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005013 }
5014 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005015 case __state::__accept_and_consume:
Howard Hinnantcba352d2010-07-12 18:16:05 +00005016 __j += __s.__current_ - __current;
5017 __current = __s.__current_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005018 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005019 case __state::__repeat:
5020 case __state::__accept_but_not_consume:
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005021 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005022 case __state::__split:
5023 {
5024 __state __snext = __s;
5025 __s.__node_->__exec_split(true, __s);
5026 __snext.__node_->__exec_split(false, __snext);
5027 __states.push_back(_STD::move(__snext));
5028 }
5029 break;
5030 case __state::__reject:
5031 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005032 break;
5033 default:
5034 throw regex_error(regex_constants::error_temp);
5035 break;
5036 }
Howard Hinnantac303862010-07-12 15:51:17 +00005037 } while (!__states.empty());
5038 if (__matched)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005039 {
5040 __m.__matches_[0].first = __first;
5041 __m.__matches_[0].second = _STD::next(__first, __highest_j);
5042 __m.__matches_[0].matched = true;
Howard Hinnantac303862010-07-12 15:51:17 +00005043 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
5044 __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005045 return true;
5046 }
5047 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005048 return false;
5049}
5050
5051template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005052template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005053bool
5054basic_regex<_CharT, _Traits>::__match_at_start(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005055 const _CharT* __first, const _CharT* __last,
5056 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005057 vector<size_t>& __lc,
5058 regex_constants::match_flag_type __flags) const
5059{
5060 if (__flags_ & ECMAScript)
5061 return __match_at_start_ecma(__first, __last, __m, __flags);
5062 if (mark_count() == 0)
5063 return __match_at_start_posix_nosubs(__first, __last, __m, __lc, __flags);
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005064 return __match_at_start_posix_subs(__first, __last, __m, __lc, __flags);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005065}
5066
5067template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005068template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005069bool
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005070basic_regex<_CharT, _Traits>::__search(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005071 const _CharT* __first, const _CharT* __last,
5072 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005073 regex_constants::match_flag_type __flags) const
5074{
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00005075 if (__left_anchor_)
5076 __flags |= regex_constants::match_continuous;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005077 __m.__init(1 + mark_count(), __first, __last);
5078 vector<size_t> __lc(__loop_count());
5079 if (__match_at_start(__first, __last, __m, __lc, __flags))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005080 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005081 __m.__prefix_.second = __m[0].first;
5082 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5083 __m.__suffix_.first = __m[0].second;
5084 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5085 return true;
5086 }
5087 if (!(__flags & regex_constants::match_continuous))
5088 {
5089 __m.__matches_.assign(__m.size(), __m.__unmatched_);
5090 for (++__first; __first != __last; ++__first)
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005091 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005092 if (__match_at_start(__first, __last, __m, __lc, __flags))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005093 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005094 __m.__prefix_.second = __m[0].first;
5095 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5096 __m.__suffix_.first = __m[0].second;
5097 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5098 return true;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005099 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005100 __m.__matches_.assign(__m.size(), __m.__unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005101 }
5102 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005103 __m.__matches_.clear();
5104 return false;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005105}
5106
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005107template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005108inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005109bool
5110regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5111 match_results<_BidirectionalIterator, _Allocator>& __m,
5112 const basic_regex<_CharT, _Traits>& __e,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005113 regex_constants::match_flag_type __flags = regex_constants::match_default)
5114{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005115 basic_string<_CharT> __s(__first, __last);
5116 match_results<const _CharT*> __mc;
5117 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5118 __m.__assign(__first, __last, __mc);
5119 return __r;
5120}
5121
5122template <class _Allocator, class _CharT, class _Traits>
5123inline _LIBCPP_INLINE_VISIBILITY
5124bool
5125regex_search(const _CharT* __first, const _CharT* __last,
5126 match_results<const _CharT*, _Allocator>& __m,
5127 const basic_regex<_CharT, _Traits>& __e,
5128 regex_constants::match_flag_type __flags = regex_constants::match_default)
5129{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005130 return __e.__search(__first, __last, __m, __flags);
5131}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005132
5133template <class _BidirectionalIterator, class _CharT, class _Traits>
5134inline _LIBCPP_INLINE_VISIBILITY
5135bool
5136regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5137 const basic_regex<_CharT, _Traits>& __e,
5138 regex_constants::match_flag_type __flags = regex_constants::match_default)
5139{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005140 basic_string<_CharT> __s(__first, __last);
5141 match_results<const _CharT*> __mc;
5142 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5143}
5144
5145template <class _CharT, class _Traits>
5146inline _LIBCPP_INLINE_VISIBILITY
5147bool
5148regex_search(const _CharT* __first, const _CharT* __last,
5149 const basic_regex<_CharT, _Traits>& __e,
5150 regex_constants::match_flag_type __flags = regex_constants::match_default)
5151{
5152 match_results<const _CharT*> __mc;
5153 return __e.__search(__first, __last, __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005154}
5155
5156template <class _CharT, class _Allocator, class _Traits>
5157inline _LIBCPP_INLINE_VISIBILITY
5158bool
5159regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5160 const basic_regex<_CharT, _Traits>& __e,
5161 regex_constants::match_flag_type __flags = regex_constants::match_default)
5162{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005163 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005164}
5165
5166template <class _CharT, class _Traits>
5167inline _LIBCPP_INLINE_VISIBILITY
5168bool
5169regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5170 regex_constants::match_flag_type __flags = regex_constants::match_default)
5171{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005172 match_results<const _CharT*> __m;
5173 return _STD::regex_search(__str, __m, __e, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005174}
5175
5176template <class _ST, class _SA, class _CharT, class _Traits>
5177inline _LIBCPP_INLINE_VISIBILITY
5178bool
5179regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5180 const basic_regex<_CharT, _Traits>& __e,
5181 regex_constants::match_flag_type __flags = regex_constants::match_default)
5182{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005183 match_results<const _CharT*> __mc;
5184 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005185}
5186
5187template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5188inline _LIBCPP_INLINE_VISIBILITY
5189bool
5190regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5191 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5192 const basic_regex<_CharT, _Traits>& __e,
5193 regex_constants::match_flag_type __flags = regex_constants::match_default)
5194{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005195 match_results<const _CharT*> __mc;
5196 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5197 __m.__assign(__s.begin(), __s.end(), __mc);
5198 return __r;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005199}
5200
5201// regex_match
5202
5203template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5204bool
5205regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5206 match_results<_BidirectionalIterator, _Allocator>& __m,
5207 const basic_regex<_CharT, _Traits>& __e,
5208 regex_constants::match_flag_type __flags = regex_constants::match_default)
5209{
5210 bool __r = _STD::regex_search(__first, __last, __m, __e,
5211 __flags | regex_constants::match_continuous);
5212 if (__r)
5213 {
5214 __r = !__m.suffix().matched;
5215 if (!__r)
5216 __m.__matches_.clear();
5217 }
5218 return __r;
5219}
5220
5221template <class _BidirectionalIterator, class _CharT, class _Traits>
5222inline _LIBCPP_INLINE_VISIBILITY
5223bool
5224regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5225 const basic_regex<_CharT, _Traits>& __e,
5226 regex_constants::match_flag_type __flags = regex_constants::match_default)
5227{
5228 match_results<_BidirectionalIterator> __m;
5229 return _STD::regex_match(__first, __last, __m, __e, __flags);
5230}
5231
5232template <class _CharT, class _Allocator, class _Traits>
5233inline _LIBCPP_INLINE_VISIBILITY
5234bool
5235regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5236 const basic_regex<_CharT, _Traits>& __e,
5237 regex_constants::match_flag_type __flags = regex_constants::match_default)
5238{
5239 return _STD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
5240}
5241
5242template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5243inline _LIBCPP_INLINE_VISIBILITY
5244bool
5245regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5246 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5247 const basic_regex<_CharT, _Traits>& __e,
5248 regex_constants::match_flag_type __flags = regex_constants::match_default)
5249{
5250 return _STD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
5251}
5252
5253template <class _CharT, class _Traits>
5254inline _LIBCPP_INLINE_VISIBILITY
5255bool
5256regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5257 regex_constants::match_flag_type __flags = regex_constants::match_default)
5258{
5259 return _STD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
5260}
5261
5262template <class _ST, class _SA, class _CharT, class _Traits>
5263inline _LIBCPP_INLINE_VISIBILITY
5264bool
5265regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5266 const basic_regex<_CharT, _Traits>& __e,
5267 regex_constants::match_flag_type __flags = regex_constants::match_default)
5268{
5269 return _STD::regex_match(__s.begin(), __s.end(), __e, __flags);
5270}
5271
Howard Hinnant3257c982010-06-17 00:34:59 +00005272_LIBCPP_END_NAMESPACE_STD
5273
5274#endif // _LIBCPP_REGEX