blob: b8b4a285c93ed0fa84479726c9128d9e4e78b3cf [file] [log] [blame]
Howard Hinnant3257c982010-06-17 00:34:59 +00001// -*- C++ -*-
2//===--------------------------- regex ------------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3257c982010-06-17 00:34:59 +00008//
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
Howard Hinnant31aaf552010-12-08 21:07:55 +0000211 constexpr sub_match();
212
Howard Hinnant3257c982010-06-17 00:34:59 +0000213 difference_type length() const;
214 operator string_type() const;
215 string_type str() const;
216
217 int compare(const sub_match& s) const;
218 int compare(const string_type& s) const;
219 int compare(const value_type* s) const;
220};
221
222typedef sub_match<const char*> csub_match;
223typedef sub_match<const wchar_t*> wcsub_match;
224typedef sub_match<string::const_iterator> ssub_match;
225typedef sub_match<wstring::const_iterator> wssub_match;
226
227template <class BiIter>
228 bool
229 operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
230
231template <class BiIter>
232 bool
233 operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
234
235template <class BiIter>
236 bool
237 operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
238
239template <class BiIter>
240 bool
241 operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
242
243template <class BiIter>
244 bool
245 operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
246
247template <class BiIter>
248 bool
249 operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
250
251template <class BiIter, class ST, class SA>
252 bool
253 operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
254 const sub_match<BiIter>& rhs);
255
256template <class BiIter, class ST, class SA>
257 bool
258 operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
259 const sub_match<BiIter>& rhs);
260
261template <class BiIter, class ST, class SA>
262 bool
263 operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
264 const sub_match<BiIter>& rhs);
265
266template <class BiIter, class ST, class SA>
267 bool
268 operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
269 const sub_match<BiIter>& rhs);
270
271template <class BiIter, class ST, class SA>
272 bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
273 const sub_match<BiIter>& rhs);
274
275template <class BiIter, class ST, class SA>
276 bool
277 operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
278 const sub_match<BiIter>& rhs);
279
280template <class BiIter, class ST, class SA>
281 bool
282 operator==(const sub_match<BiIter>& lhs,
283 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
284
285template <class BiIter, class ST, class SA>
286 bool
287 operator!=(const sub_match<BiIter>& lhs,
288 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
289
290template <class BiIter, class ST, class SA>
291 bool
292 operator<(const sub_match<BiIter>& lhs,
293 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
294
295template <class BiIter, class ST, class SA>
296 bool operator>(const sub_match<BiIter>& lhs,
297 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
298
299template <class BiIter, class ST, class SA>
300 bool
301 operator>=(const sub_match<BiIter>& lhs,
302 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
303
304template <class BiIter, class ST, class SA>
305 bool
306 operator<=(const sub_match<BiIter>& lhs,
307 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
308
309template <class BiIter>
310 bool
311 operator==(typename iterator_traits<BiIter>::value_type const* lhs,
312 const sub_match<BiIter>& rhs);
313
314template <class BiIter>
315 bool
316 operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
317 const sub_match<BiIter>& rhs);
318
319template <class BiIter>
320 bool
321 operator<(typename iterator_traits<BiIter>::value_type const* lhs,
322 const sub_match<BiIter>& rhs);
323
324template <class BiIter>
325 bool
326 operator>(typename iterator_traits<BiIter>::value_type const* lhs,
327 const sub_match<BiIter>& rhs);
328
329template <class BiIter>
330 bool
331 operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
332 const sub_match<BiIter>& rhs);
333
334template <class BiIter>
335 bool
336 operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
337 const sub_match<BiIter>& rhs);
338
339template <class BiIter>
340 bool
341 operator==(const sub_match<BiIter>& lhs,
342 typename iterator_traits<BiIter>::value_type const* rhs);
343
344template <class BiIter>
345 bool
346 operator!=(const sub_match<BiIter>& lhs,
347 typename iterator_traits<BiIter>::value_type const* rhs);
348
349template <class BiIter>
350 bool
351 operator<(const sub_match<BiIter>& lhs,
352 typename iterator_traits<BiIter>::value_type const* rhs);
353
354template <class BiIter>
355 bool
356 operator>(const sub_match<BiIter>& lhs,
357 typename iterator_traits<BiIter>::value_type const* rhs);
358
359template <class BiIter>
360 bool
361 operator>=(const sub_match<BiIter>& lhs,
362 typename iterator_traits<BiIter>::value_type const* rhs);
363
364template <class BiIter>
365 bool
366 operator<=(const sub_match<BiIter>& lhs,
367 typename iterator_traits<BiIter>::value_type const* rhs);
368
369template <class BiIter>
370 bool
371 operator==(typename iterator_traits<BiIter>::value_type const& lhs,
372 const sub_match<BiIter>& rhs);
373
374template <class BiIter>
375 bool
376 operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
377 const sub_match<BiIter>& rhs);
378
379template <class BiIter>
380 bool
381 operator<(typename iterator_traits<BiIter>::value_type const& lhs,
382 const sub_match<BiIter>& rhs);
383
384template <class BiIter>
385 bool
386 operator>(typename iterator_traits<BiIter>::value_type const& lhs,
387 const sub_match<BiIter>& rhs);
388
389template <class BiIter>
390 bool
391 operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
392 const sub_match<BiIter>& rhs);
393
394template <class BiIter>
395 bool
396 operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
397 const sub_match<BiIter>& rhs);
398
399template <class BiIter>
400 bool
401 operator==(const sub_match<BiIter>& lhs,
402 typename iterator_traits<BiIter>::value_type const& rhs);
403
404template <class BiIter>
405 bool
406 operator!=(const sub_match<BiIter>& lhs,
407 typename iterator_traits<BiIter>::value_type const& rhs);
408
409template <class BiIter>
410 bool
411 operator<(const sub_match<BiIter>& lhs,
412 typename iterator_traits<BiIter>::value_type const& rhs);
413
414template <class BiIter>
415 bool
416 operator>(const sub_match<BiIter>& lhs,
417 typename iterator_traits<BiIter>::value_type const& rhs);
418
419template <class BiIter>
420 bool
421 operator>=(const sub_match<BiIter>& lhs,
422 typename iterator_traits<BiIter>::value_type const& rhs);
423
424template <class BiIter>
425 bool
426 operator<=(const sub_match<BiIter>& lhs,
427 typename iterator_traits<BiIter>::value_type const& rhs);
428
429template <class charT, class ST, class BiIter>
430 basic_ostream<charT, ST>&
431 operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
432
433template <class BidirectionalIterator,
434 class Allocator = allocator<sub_match<BidirectionalIterator>>>
435class match_results
436{
437public:
438 typedef sub_match<BidirectionalIterator> value_type;
439 typedef const value_type& const_reference;
440 typedef const_reference reference;
441 typedef /implementation-defined/ const_iterator;
442 typedef const_iterator iterator;
443 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
444 typedef typename allocator_traits<Allocator>::size_type size_type;
445 typedef Allocator allocator_type;
446 typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
447 typedef basic_string<char_type> string_type;
448
449 // construct/copy/destroy:
450 explicit match_results(const Allocator& a = Allocator());
451 match_results(const match_results& m);
452 match_results(match_results&& m);
453 match_results& operator=(const match_results& m);
454 match_results& operator=(match_results&& m);
455 ~match_results();
456
Howard Hinnant31aaf552010-12-08 21:07:55 +0000457 bool ready() const;
458
Howard Hinnant3257c982010-06-17 00:34:59 +0000459 // size:
460 size_type size() const;
461 size_type max_size() const;
462 bool empty() const;
463
464 // element access:
465 difference_type length(size_type sub = 0) const;
466 difference_type position(size_type sub = 0) const;
467 string_type str(size_type sub = 0) const;
468 const_reference operator[](size_type n) const;
469
470 const_reference prefix() const;
471 const_reference suffix() const;
472
473 const_iterator begin() const;
474 const_iterator end() const;
475 const_iterator cbegin() const;
476 const_iterator cend() const;
477
478 // format:
479 template <class OutputIter>
480 OutputIter
481 format(OutputIter out, const char_type* fmt_first,
482 const char_type* fmt_last,
483 regex_constants::match_flag_type flags = regex_constants::format_default) const;
484 template <class OutputIter, class ST, class SA>
485 OutputIter
486 format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
487 regex_constants::match_flag_type flags = regex_constants::format_default) const;
488 template <class ST, class SA>
489 basic_string<char_type, ST, SA>
490 format(const basic_string<char_type, ST, SA>& fmt,
491 regex_constants::match_flag_type flags = regex_constants::format_default) const;
492 string_type
493 format(const char_type* fmt,
494 regex_constants::match_flag_type flags = regex_constants::format_default) const;
495
496 // allocator:
497 allocator_type get_allocator() const;
498
499 // swap:
500 void swap(match_results& that);
501};
502
503typedef match_results<const char*> cmatch;
504typedef match_results<const wchar_t*> wcmatch;
505typedef match_results<string::const_iterator> smatch;
506typedef match_results<wstring::const_iterator> wsmatch;
507
508template <class BidirectionalIterator, class Allocator>
509 bool
510 operator==(const match_results<BidirectionalIterator, Allocator>& m1,
511 const match_results<BidirectionalIterator, Allocator>& m2);
512
513template <class BidirectionalIterator, class Allocator>
514 bool
515 operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
516 const match_results<BidirectionalIterator, Allocator>& m2);
517
518template <class BidirectionalIterator, class Allocator>
519 void
520 swap(match_results<BidirectionalIterator, Allocator>& m1,
521 match_results<BidirectionalIterator, Allocator>& m2);
522
523template <class BidirectionalIterator, class Allocator, class charT, class traits>
524 bool
525 regex_match(BidirectionalIterator first, BidirectionalIterator last,
526 match_results<BidirectionalIterator, Allocator>& m,
527 const basic_regex<charT, traits>& e,
528 regex_constants::match_flag_type flags = regex_constants::match_default);
529
530template <class BidirectionalIterator, class charT, class traits>
531 bool
532 regex_match(BidirectionalIterator first, BidirectionalIterator last,
533 const basic_regex<charT, traits>& e,
534 regex_constants::match_flag_type flags = regex_constants::match_default);
535
536template <class charT, class Allocator, class traits>
537 bool
538 regex_match(const charT* str, match_results<const charT*, Allocator>& m,
539 const basic_regex<charT, traits>& e,
540 regex_constants::match_flag_type flags = regex_constants::match_default);
541
542template <class ST, class SA, class Allocator, class charT, class traits>
543 bool
544 regex_match(const basic_string<charT, ST, SA>& s,
545 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
546 const basic_regex<charT, traits>& e,
547 regex_constants::match_flag_type flags = regex_constants::match_default);
548
549template <class charT, class traits>
550 bool
551 regex_match(const charT* str, const basic_regex<charT, traits>& e,
552 regex_constants::match_flag_type flags = regex_constants::match_default);
553
554template <class ST, class SA, class charT, class traits>
555 bool
556 regex_match(const basic_string<charT, ST, SA>& s,
557 const basic_regex<charT, traits>& e,
558 regex_constants::match_flag_type flags = regex_constants::match_default);
559
560template <class BidirectionalIterator, class Allocator, class charT, class traits>
561 bool
562 regex_search(BidirectionalIterator first, BidirectionalIterator last,
563 match_results<BidirectionalIterator, Allocator>& m,
564 const basic_regex<charT, traits>& e,
565 regex_constants::match_flag_type flags = regex_constants::match_default);
566
567template <class BidirectionalIterator, class charT, class traits>
568 bool
569 regex_search(BidirectionalIterator first, BidirectionalIterator last,
570 const basic_regex<charT, traits>& e,
571 regex_constants::match_flag_type flags = regex_constants::match_default);
572
573template <class charT, class Allocator, class traits>
574 bool
575 regex_search(const charT* str, match_results<const charT*, Allocator>& m,
576 const basic_regex<charT, traits>& e,
577 regex_constants::match_flag_type flags = regex_constants::match_default);
578
579template <class charT, class traits>
580 bool
581 regex_search(const charT* str, const basic_regex<charT, traits>& e,
582 regex_constants::match_flag_type flags = regex_constants::match_default);
583
584template <class ST, class SA, class charT, class traits>
585 bool
586 regex_search(const basic_string<charT, ST, SA>& s,
587 const basic_regex<charT, traits>& e,
588 regex_constants::match_flag_type flags = regex_constants::match_default);
589
590template <class ST, class SA, class Allocator, class charT, class traits>
591 bool
592 regex_search(const basic_string<charT, ST, SA>& s,
593 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
594 const basic_regex<charT, traits>& e,
595 regex_constants::match_flag_type flags = regex_constants::match_default);
596
597template <class OutputIterator, class BidirectionalIterator,
598 class traits, class charT, class ST, class SA>
599 OutputIterator
600 regex_replace(OutputIterator out,
601 BidirectionalIterator first, BidirectionalIterator last,
602 const basic_regex<charT, traits>& e,
603 const basic_string<charT, ST, SA>& fmt,
604 regex_constants::match_flag_type flags = regex_constants::match_default);
605
606template <class OutputIterator, class BidirectionalIterator,
607 class traits, class charT>
608 OutputIterator
609 regex_replace(OutputIterator out,
610 BidirectionalIterator first, BidirectionalIterator last,
611 const basic_regex<charT, traits>& e, const charT* fmt,
612 regex_constants::match_flag_type flags = regex_constants::match_default);
613
614template <class traits, class charT, class ST, class SA, class FST, class FSA>>
615 basic_string<charT, ST, SA>
616 regex_replace(const basic_string<charT, ST, SA>& s,
617 const basic_regex<charT, traits>& e,
618 const basic_string<charT, FST, FSA>& fmt,
619 regex_constants::match_flag_type flags = regex_constants::match_default);
620
621template <class traits, class charT, class ST, class SA>
622 basic_string<charT, ST, SA>
623 regex_replace(const basic_string<charT, ST, SA>& s,
624 const basic_regex<charT, traits>& e, const charT* fmt,
625 regex_constants::match_flag_type flags = regex_constants::match_default);
626
627template <class traits, class charT, class ST, class SA>
628 basic_string<charT>
629 regex_replace(const charT* s,
630 const basic_regex<charT, traits>& e,
631 const basic_string<charT, ST, SA>& fmt,
632 regex_constants::match_flag_type flags = regex_constants::match_default);
633
634template <class traits, class charT>
635 basic_string<charT>
636 regex_replace(const charT* s,
637 const basic_regex<charT, traits>& e,
638 const charT* fmt,
639 regex_constants::match_flag_type flags = regex_constants::match_default);
640
641template <class BidirectionalIterator,
642 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
643 class traits = regex_traits<charT>>
644class regex_iterator
645{
646public:
647 typedef basic_regex<charT, traits> regex_type;
648 typedef match_results<BidirectionalIterator> value_type;
649 typedef ptrdiff_t difference_type;
650 typedef const value_type* pointer;
651 typedef const value_type& reference;
652 typedef forward_iterator_tag iterator_category;
653
654 regex_iterator();
655 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
656 const regex_type& re,
657 regex_constants::match_flag_type m = regex_constants::match_default);
658 regex_iterator(const regex_iterator&);
659 regex_iterator& operator=(const regex_iterator&);
660
661 bool operator==(const regex_iterator&) const;
662 bool operator!=(const regex_iterator&) const;
663
664 const value_type& operator*() const;
665 const value_type* operator->() const;
666
667 regex_iterator& operator++();
668 regex_iterator operator++(int);
669};
670
671typedef regex_iterator<const char*> cregex_iterator;
672typedef regex_iterator<const wchar_t*> wcregex_iterator;
673typedef regex_iterator<string::const_iterator> sregex_iterator;
674typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
675
676template <class BidirectionalIterator,
677 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
678 class traits = regex_traits<charT>>
679class regex_token_iterator
680{
681public:
682 typedef basic_regex<charT, traits> regex_type;
683 typedef sub_match<BidirectionalIterator> value_type;
684 typedef ptrdiff_t difference_type;
685 typedef const value_type* pointer;
686 typedef const value_type& reference;
687 typedef forward_iterator_tag iterator_category;
688
689 regex_token_iterator();
690 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
691 const regex_type& re, int submatch = 0,
692 regex_constants::match_flag_type m = regex_constants::match_default);
693 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
694 const regex_type& re, const vector<int>& submatches,
695 regex_constants::match_flag_type m = regex_constants::match_default);
696 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
697 const regex_type& re, initializer_list<int> submatches,
698 regex_constants::match_flag_type m = regex_constants::match_default);
699 template <size_t N>
700 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
701 const regex_type& re, const int (&submatches)[N],
702 regex_constants::match_flag_type m = regex_constants::match_default);
703 regex_token_iterator(const regex_token_iterator&);
704 regex_token_iterator& operator=(const regex_token_iterator&);
705
706 bool operator==(const regex_token_iterator&) const;
707 bool operator!=(const regex_token_iterator&) const;
708
709 const value_type& operator*() const;
710 const value_type* operator->() const;
711
712 regex_token_iterator& operator++();
713 regex_token_iterator operator++(int);
714};
715
716typedef regex_token_iterator<const char*> cregex_token_iterator;
717typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
718typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
719typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
720
721} // std
722*/
723
724#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,
Howard Hinnantad2a7ab2010-07-27 17:24:17 +0000750 ECMAScript = 0,
751 basic = 1 << 4,
752 extended = 1 << 5,
753 awk = 1 << 6,
754 grep = 1 << 7,
755 egrep = 1 << 8
Howard Hinnant3257c982010-06-17 00:34:59 +0000756};
757
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000758inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000759/*constexpr*/
760syntax_option_type
761operator~(syntax_option_type __x)
762{
763 return syntax_option_type(~int(__x));
764}
765
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000766inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000767/*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
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000774inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000775/*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
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000782inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000783/*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
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000790inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000791/*constexpr*/
792syntax_option_type&
793operator&=(syntax_option_type& __x, syntax_option_type __y)
794{
795 __x = __x & __y;
796 return __x;
797}
798
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000799inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000800/*constexpr*/
801syntax_option_type&
802operator|=(syntax_option_type& __x, syntax_option_type __y)
803{
804 __x = __x | __y;
805 return __x;
806}
807
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000808inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000809/*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,
Howard Hinnanta712c722010-08-16 20:21:16 +0000833 format_first_only = 1 << 10,
834 __no_update_pos = 1 << 11
Howard Hinnant3257c982010-06-17 00:34:59 +0000835};
836
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000837inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000838/*constexpr*/
839match_flag_type
840operator~(match_flag_type __x)
841{
842 return match_flag_type(~int(__x));
843}
844
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000845inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000846/*constexpr*/
847match_flag_type
848operator&(match_flag_type __x, match_flag_type __y)
849{
850 return match_flag_type(int(__x) & int(__y));
851}
852
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000853inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000854/*constexpr*/
855match_flag_type
856operator|(match_flag_type __x, match_flag_type __y)
857{
858 return match_flag_type(int(__x) | int(__y));
859}
860
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000861inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000862/*constexpr*/
863match_flag_type
864operator^(match_flag_type __x, match_flag_type __y)
865{
866 return match_flag_type(int(__x) ^ int(__y));
867}
868
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000869inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000870/*constexpr*/
871match_flag_type&
872operator&=(match_flag_type& __x, match_flag_type __y)
873{
874 __x = __x & __y;
875 return __x;
876}
877
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000878inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000879/*constexpr*/
880match_flag_type&
881operator|=(match_flag_type& __x, match_flag_type __y)
882{
883 __x = __x | __y;
884 return __x;
885}
886
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000887inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000888/*constexpr*/
889match_flag_type&
890operator^=(match_flag_type& __x, match_flag_type __y)
891{
892 __x = __x ^ __y;
893 return __x;
894}
895
896enum error_type
897{
898 error_collate = 1,
899 error_ctype,
900 error_escape,
901 error_backref,
902 error_brack,
903 error_paren,
904 error_brace,
905 error_badbrace,
906 error_range,
907 error_space,
908 error_badrepeat,
909 error_complexity,
Howard Hinnant8c2c18d2010-06-24 21:28:00 +0000910 error_stack,
Howard Hinnantad2a7ab2010-07-27 17:24:17 +0000911 __re_err_grammar,
912 __re_err_empty,
913 __re_err_unknown
Howard Hinnant3257c982010-06-17 00:34:59 +0000914};
915
916} // regex_constants
917
918class _LIBCPP_EXCEPTION_ABI regex_error
919 : public runtime_error
920{
921 regex_constants::error_type __code_;
922public:
923 explicit regex_error(regex_constants::error_type __ecode);
924 virtual ~regex_error() throw();
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000926 regex_constants::error_type code() const {return __code_;}
927};
928
929template <class _CharT>
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000930struct _LIBCPP_VISIBLE regex_traits
Howard Hinnant3257c982010-06-17 00:34:59 +0000931{
932public:
933 typedef _CharT char_type;
934 typedef basic_string<char_type> string_type;
935 typedef locale locale_type;
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000936 typedef ctype_base::mask char_class_type;
Howard Hinnant3257c982010-06-17 00:34:59 +0000937
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000938 static const char_class_type __regex_word = 0x80;
Howard Hinnant3257c982010-06-17 00:34:59 +0000939private:
940 locale __loc_;
941 const ctype<char_type>* __ct_;
942 const collate<char_type>* __col_;
943
944public:
945 regex_traits();
946
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000947 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000948 static size_t length(const char_type* __p)
949 {return char_traits<char_type>::length(__p);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000951 char_type translate(char_type __c) const {return __c;}
952 char_type translate_nocase(char_type __c) const;
953 template <class _ForwardIterator>
954 string_type
955 transform(_ForwardIterator __f, _ForwardIterator __l) const;
956 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000958 string_type
959 transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
960 {return __transform_primary(__f, __l, char_type());}
961 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000963 string_type
964 lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
965 {return __lookup_collatename(__f, __l, char_type());}
966 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000968 char_class_type
969 lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000970 bool __icase = false) const
971 {return __lookup_classname(__f, __l, __icase, char_type());}
972 bool isctype(char_type __c, char_class_type __m) const;
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000974 int value(char_type __ch, int __radix) const
975 {return __value(__ch, __radix);}
Howard Hinnant3257c982010-06-17 00:34:59 +0000976 locale_type imbue(locale_type __l);
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000977 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000978 locale_type getloc()const {return __loc_;}
979
980private:
981 void __init();
982
983 template <class _ForwardIterator>
984 string_type
985 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
986 template <class _ForwardIterator>
987 string_type
988 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
989
990 template <class _ForwardIterator>
991 string_type
992 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
993 template <class _ForwardIterator>
994 string_type
995 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000996
997 template <class _ForwardIterator>
998 char_class_type
999 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1000 bool __icase, char) const;
1001 template <class _ForwardIterator>
1002 char_class_type
1003 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1004 bool __icase, wchar_t) const;
1005
1006 static int __value(unsigned char __ch, int __radix);
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001007 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001008 int __value(char __ch, int __radix) const
1009 {return __value(static_cast<unsigned char>(__ch), __radix);}
1010 int __value(wchar_t __ch, int __radix) const;
Howard Hinnant3257c982010-06-17 00:34:59 +00001011};
1012
1013template <class _CharT>
1014regex_traits<_CharT>::regex_traits()
1015{
1016 __init();
1017}
1018
1019template <class _CharT>
1020typename regex_traits<_CharT>::char_type
1021regex_traits<_CharT>::translate_nocase(char_type __c) const
1022{
1023 return __ct_->tolower(__c);
1024}
1025
1026template <class _CharT>
1027template <class _ForwardIterator>
1028typename regex_traits<_CharT>::string_type
1029regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
1030{
1031 string_type __s(__f, __l);
1032 return __col_->transform(__s.data(), __s.data() + __s.size());
1033}
1034
1035template <class _CharT>
1036void
1037regex_traits<_CharT>::__init()
1038{
1039 __ct_ = &use_facet<ctype<char_type> >(__loc_);
1040 __col_ = &use_facet<collate<char_type> >(__loc_);
1041}
1042
1043template <class _CharT>
1044typename regex_traits<_CharT>::locale_type
1045regex_traits<_CharT>::imbue(locale_type __l)
1046{
1047 locale __r = __loc_;
1048 __loc_ = __l;
1049 __init();
1050 return __r;
1051}
1052
1053// transform_primary is very FreeBSD-specific
1054
1055template <class _CharT>
1056template <class _ForwardIterator>
1057typename regex_traits<_CharT>::string_type
1058regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1059 _ForwardIterator __l, char) const
1060{
1061 const string_type __s(__f, __l);
1062 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1063 switch (__d.size())
1064 {
1065 case 1:
1066 break;
1067 case 12:
1068 __d[11] = __d[3];
1069 break;
1070 default:
1071 __d.clear();
1072 break;
1073 }
1074 return __d;
1075}
1076
1077template <class _CharT>
1078template <class _ForwardIterator>
1079typename regex_traits<_CharT>::string_type
1080regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1081 _ForwardIterator __l, wchar_t) const
1082{
1083 const string_type __s(__f, __l);
1084 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1085 switch (__d.size())
1086 {
1087 case 1:
1088 break;
1089 case 3:
1090 __d[2] = __d[0];
1091 break;
1092 default:
1093 __d.clear();
1094 break;
1095 }
1096 return __d;
1097}
1098
1099// lookup_collatename is very FreeBSD-specific
1100
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001101string __get_collation_name(const char* __s);
Howard Hinnant3257c982010-06-17 00:34:59 +00001102
1103template <class _CharT>
1104template <class _ForwardIterator>
1105typename regex_traits<_CharT>::string_type
1106regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1107 _ForwardIterator __l, char) const
1108{
1109 string_type __s(__f, __l);
1110 string_type __r;
1111 if (!__s.empty())
1112 {
1113 __r = __get_collation_name(__s.c_str());
1114 if (__r.empty() && __s.size() <= 2)
1115 {
1116 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1117 if (__r.size() == 1 || __r.size() == 12)
1118 __r = __s;
1119 else
1120 __r.clear();
1121 }
1122 }
1123 return __r;
1124}
1125
1126template <class _CharT>
1127template <class _ForwardIterator>
1128typename regex_traits<_CharT>::string_type
1129regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1130 _ForwardIterator __l, wchar_t) const
1131{
1132 string_type __s(__f, __l);
1133 string __n;
1134 __n.reserve(__s.size());
1135 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1136 __i != __e; ++__i)
1137 {
1138 if (static_cast<unsigned>(*__i) >= 127)
1139 return string_type();
1140 __n.push_back(char(*__i));
1141 }
1142 string_type __r;
1143 if (!__s.empty())
1144 {
1145 __n = __get_collation_name(__n.c_str());
1146 if (!__n.empty())
1147 __r.assign(__n.begin(), __n.end());
1148 else if (__s.size() <= 2)
1149 {
1150 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1151 if (__r.size() == 1 || __r.size() == 3)
1152 __r = __s;
1153 else
1154 __r.clear();
1155 }
1156 }
1157 return __r;
1158}
1159
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001160// lookup_classname
1161
1162ctype_base::mask __get_classname(const char* __s, bool __icase);
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, char) const
1170{
1171 string_type __s(__f, __l);
1172 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1173 return __get_classname(__s.c_str(), __icase);
1174}
1175
1176template <class _CharT>
1177template <class _ForwardIterator>
1178typename regex_traits<_CharT>::char_class_type
1179regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1180 _ForwardIterator __l,
1181 bool __icase, wchar_t) const
1182{
1183 string_type __s(__f, __l);
1184 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1185 string __n;
1186 __n.reserve(__s.size());
1187 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1188 __i != __e; ++__i)
1189 {
1190 if (static_cast<unsigned>(*__i) >= 127)
1191 return char_class_type();
1192 __n.push_back(char(*__i));
1193 }
1194 return __get_classname(__n.c_str(), __icase);
1195}
1196
1197template <class _CharT>
1198bool
1199regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
1200{
1201 if (__ct_->is(__m, __c))
1202 return true;
1203 return (__c == '_' && (__m & __regex_word));
1204}
1205
1206template <class _CharT>
1207int
1208regex_traits<_CharT>::__value(unsigned char __ch, int __radix)
1209{
1210 if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
1211 return __ch - '0';
1212 if (__radix != 8)
1213 {
1214 if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
1215 return __ch - '0';
1216 if (__radix == 16)
1217 {
1218 __ch |= 0x20; // tolower
1219 if ('a' <= __ch && __ch <= 'f')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001220 return __ch - ('a' - 10);
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001221 }
1222 }
1223 return -1;
1224}
1225
1226template <class _CharT>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001227inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001228int
1229regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const
1230{
1231 return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
1232}
1233
Howard Hinnantac303862010-07-12 15:51:17 +00001234template <class _CharT> class __node;
1235
1236template <class _BidirectionalIterator> class sub_match;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001237
Howard Hinnant17615b02010-07-27 01:25:38 +00001238template <class _BidirectionalIterator,
1239 class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1240class match_results;
1241
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001242template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001243struct __state
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001244{
1245 enum
1246 {
1247 __end_state = -1000,
1248 __consume_input, // -999
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001249 __begin_marked_expr, // -998
1250 __end_marked_expr, // -997
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001251 __pop_state, // -996
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001252 __accept_and_consume, // -995
1253 __accept_but_not_consume, // -994
1254 __reject, // -993
Howard Hinnantac303862010-07-12 15:51:17 +00001255 __split,
1256 __repeat
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001257 };
1258
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001259 int __do_;
Howard Hinnantac303862010-07-12 15:51:17 +00001260 const _CharT* __first_;
1261 const _CharT* __current_;
1262 const _CharT* __last_;
1263 vector<sub_match<const _CharT*> > __sub_matches_;
1264 vector<pair<size_t, const _CharT*> > __loop_data_;
1265 const __node<_CharT>* __node_;
1266 regex_constants::match_flag_type __flags_;
Howard Hinnant41fb6e12011-03-26 20:02:27 +00001267 bool __at_first_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001268
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001270 __state()
1271 : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
1272 __node_(nullptr), __flags_() {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001273};
1274
Howard Hinnantac303862010-07-12 15:51:17 +00001275// __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001276
1277template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001278class __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001279{
Howard Hinnantac303862010-07-12 15:51:17 +00001280 __node(const __node&);
1281 __node& operator=(const __node&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001282public:
Howard Hinnantac303862010-07-12 15:51:17 +00001283 typedef _STD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001284
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001286 __node() {}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001288 virtual ~__node() {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001289
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001291 virtual void __exec(__state&) const {};
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001293 virtual void __exec_split(bool, __state&) const {};
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001294};
1295
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001296// __end_state
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001297
1298template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001299class __end_state
Howard Hinnantac303862010-07-12 15:51:17 +00001300 : public __node<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001301{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001302public:
Howard Hinnantac303862010-07-12 15:51:17 +00001303 typedef _STD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001304
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001306 __end_state() {}
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001307
Howard Hinnantac303862010-07-12 15:51:17 +00001308 virtual void __exec(__state&) const;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001309};
1310
1311template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001312void
1313__end_state<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001314{
Howard Hinnantac303862010-07-12 15:51:17 +00001315 __s.__do_ = __state::__end_state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001316}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001317
1318// __has_one_state
1319
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001320template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001321class __has_one_state
Howard Hinnantac303862010-07-12 15:51:17 +00001322 : public __node<_CharT>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001323{
Howard Hinnantac303862010-07-12 15:51:17 +00001324 __node<_CharT>* __first_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001325
1326public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001327 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001328 explicit __has_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001329 : __first_(__s) {}
1330
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001332 __node<_CharT>* first() const {return __first_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001333 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001334 __node<_CharT>*& first() {return __first_;}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001335};
1336
1337// __owns_one_state
1338
1339template <class _CharT>
1340class __owns_one_state
1341 : public __has_one_state<_CharT>
1342{
1343 typedef __has_one_state<_CharT> base;
1344
1345public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001347 explicit __owns_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001348 : base(__s) {}
1349
1350 virtual ~__owns_one_state();
1351};
1352
1353template <class _CharT>
1354__owns_one_state<_CharT>::~__owns_one_state()
1355{
1356 delete this->first();
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001357}
1358
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001359// __empty_state
1360
1361template <class _CharT>
1362class __empty_state
1363 : public __owns_one_state<_CharT>
1364{
1365 typedef __owns_one_state<_CharT> base;
1366
1367public:
Howard Hinnantac303862010-07-12 15:51:17 +00001368 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001369
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001370 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001371 explicit __empty_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001372 : base(__s) {}
1373
Howard Hinnantac303862010-07-12 15:51:17 +00001374 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001375};
1376
1377template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001378void
1379__empty_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001380{
Howard Hinnantac303862010-07-12 15:51:17 +00001381 __s.__do_ = __state::__accept_but_not_consume;
1382 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001383}
1384
1385// __empty_non_own_state
1386
1387template <class _CharT>
1388class __empty_non_own_state
1389 : public __has_one_state<_CharT>
1390{
1391 typedef __has_one_state<_CharT> base;
1392
1393public:
Howard Hinnantac303862010-07-12 15:51:17 +00001394 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001395
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001396 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001397 explicit __empty_non_own_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001398 : base(__s) {}
1399
Howard Hinnantac303862010-07-12 15:51:17 +00001400 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001401};
1402
1403template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001404void
1405__empty_non_own_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001406{
Howard Hinnantac303862010-07-12 15:51:17 +00001407 __s.__do_ = __state::__accept_but_not_consume;
1408 __s.__node_ = this->first();
1409}
1410
1411// __repeat_one_loop
1412
1413template <class _CharT>
1414class __repeat_one_loop
1415 : public __has_one_state<_CharT>
1416{
1417 typedef __has_one_state<_CharT> base;
1418
1419public:
1420 typedef _STD::__state<_CharT> __state;
1421
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001423 explicit __repeat_one_loop(__node<_CharT>* __s)
1424 : base(__s) {}
1425
1426 virtual void __exec(__state&) const;
Howard Hinnantac303862010-07-12 15:51:17 +00001427};
1428
1429template <class _CharT>
1430void
1431__repeat_one_loop<_CharT>::__exec(__state& __s) const
1432{
1433 __s.__do_ = __state::__repeat;
1434 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001435}
1436
1437// __owns_two_states
1438
1439template <class _CharT>
1440class __owns_two_states
1441 : public __owns_one_state<_CharT>
1442{
1443 typedef __owns_one_state<_CharT> base;
1444
1445 base* __second_;
1446
1447public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001449 explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001450 : base(__s1), __second_(__s2) {}
1451
1452 virtual ~__owns_two_states();
1453
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001455 base* second() const {return __second_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001457 base*& second() {return __second_;}
1458};
1459
1460template <class _CharT>
1461__owns_two_states<_CharT>::~__owns_two_states()
1462{
1463 delete __second_;
1464}
1465
1466// __loop
1467
1468template <class _CharT>
1469class __loop
1470 : public __owns_two_states<_CharT>
1471{
1472 typedef __owns_two_states<_CharT> base;
1473
1474 size_t __min_;
1475 size_t __max_;
1476 unsigned __loop_id_;
Howard Hinnantac303862010-07-12 15:51:17 +00001477 unsigned __mexp_begin_;
1478 unsigned __mexp_end_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001479 bool __greedy_;
1480
1481public:
Howard Hinnantac303862010-07-12 15:51:17 +00001482 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001483
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001485 explicit __loop(unsigned __loop_id,
Howard Hinnantac303862010-07-12 15:51:17 +00001486 __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
1487 unsigned __mexp_begin, unsigned __mexp_end,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001488 bool __greedy = true,
1489 size_t __min = 0,
1490 size_t __max = numeric_limits<size_t>::max())
1491 : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
Howard Hinnantac303862010-07-12 15:51:17 +00001492 __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001493 __greedy_(__greedy) {}
1494
Howard Hinnantac303862010-07-12 15:51:17 +00001495 virtual void __exec(__state& __s) const;
1496 virtual void __exec_split(bool __second, __state& __s) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001497
Howard Hinnantac303862010-07-12 15:51:17 +00001498private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001500 void __init_repeat(__state& __s) const
1501 {
1502 __s.__loop_data_[__loop_id_].second = __s.__current_;
1503 for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
1504 {
1505 __s.__sub_matches_[__i].first = __s.__last_;
1506 __s.__sub_matches_[__i].second = __s.__last_;
1507 __s.__sub_matches_[__i].matched = false;
1508 }
1509 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001510};
1511
1512template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001513void
1514__loop<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001515{
Howard Hinnantac303862010-07-12 15:51:17 +00001516 if (__s.__do_ == __state::__repeat)
1517 {
1518 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1519 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1520 if (__do_repeat && __do_alt &&
1521 __s.__loop_data_[__loop_id_].second == __s.__current_)
1522 __do_repeat = false;
1523 if (__do_repeat && __do_alt)
1524 __s.__do_ = __state::__split;
1525 else if (__do_repeat)
1526 {
1527 __s.__do_ = __state::__accept_but_not_consume;
1528 __s.__node_ = this->first();
1529 __init_repeat(__s);
1530 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001531 else
Howard Hinnantac303862010-07-12 15:51:17 +00001532 {
1533 __s.__do_ = __state::__accept_but_not_consume;
1534 __s.__node_ = this->second();
1535 }
1536 }
1537 else
1538 {
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00001539 __s.__loop_data_[__loop_id_].first = 0;
1540 bool __do_repeat = 0 < __max_;
1541 bool __do_alt = 0 >= __min_;
1542 if (__do_repeat && __do_alt)
Howard Hinnantac303862010-07-12 15:51:17 +00001543 __s.__do_ = __state::__split;
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00001544 else if (__do_repeat)
1545 {
1546 __s.__do_ = __state::__accept_but_not_consume;
1547 __s.__node_ = this->first();
1548 __init_repeat(__s);
1549 }
Howard Hinnantac303862010-07-12 15:51:17 +00001550 else
1551 {
1552 __s.__do_ = __state::__accept_but_not_consume;
1553 __s.__node_ = this->second();
1554 }
1555 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001556}
1557
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001558template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001559void
1560__loop<_CharT>::__exec_split(bool __second, __state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001561{
Howard Hinnantac303862010-07-12 15:51:17 +00001562 __s.__do_ = __state::__accept_but_not_consume;
1563 if (__greedy_ != __second)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001564 {
Howard Hinnantac303862010-07-12 15:51:17 +00001565 __s.__node_ = this->first();
1566 __init_repeat(__s);
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001567 }
Howard Hinnantac303862010-07-12 15:51:17 +00001568 else
1569 __s.__node_ = this->second();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001570}
1571
Howard Hinnantaa698082010-07-16 19:08:36 +00001572// __alternate
1573
1574template <class _CharT>
1575class __alternate
1576 : public __owns_two_states<_CharT>
1577{
1578 typedef __owns_two_states<_CharT> base;
1579
1580public:
1581 typedef _STD::__state<_CharT> __state;
1582
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaa698082010-07-16 19:08:36 +00001584 explicit __alternate(__owns_one_state<_CharT>* __s1,
1585 __owns_one_state<_CharT>* __s2)
1586 : base(__s1, __s2) {}
1587
1588 virtual void __exec(__state& __s) const;
1589 virtual void __exec_split(bool __second, __state& __s) const;
Howard Hinnantaa698082010-07-16 19:08:36 +00001590};
1591
1592template <class _CharT>
1593void
1594__alternate<_CharT>::__exec(__state& __s) const
1595{
1596 __s.__do_ = __state::__split;
1597}
1598
1599template <class _CharT>
1600void
1601__alternate<_CharT>::__exec_split(bool __second, __state& __s) const
1602{
1603 __s.__do_ = __state::__accept_but_not_consume;
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001604 if (__second)
Howard Hinnantaa698082010-07-16 19:08:36 +00001605 __s.__node_ = this->second();
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001606 else
1607 __s.__node_ = this->first();
Howard Hinnantaa698082010-07-16 19:08:36 +00001608}
1609
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001610// __begin_marked_subexpression
1611
1612template <class _CharT>
1613class __begin_marked_subexpression
1614 : public __owns_one_state<_CharT>
1615{
1616 typedef __owns_one_state<_CharT> base;
1617
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001618 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001619public:
Howard Hinnantac303862010-07-12 15:51:17 +00001620 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001621
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001622 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001623 explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001624 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001625
Howard Hinnantac303862010-07-12 15:51:17 +00001626 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001627};
1628
1629template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001630void
1631__begin_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001632{
Howard Hinnantac303862010-07-12 15:51:17 +00001633 __s.__do_ = __state::__accept_but_not_consume;
1634 __s.__sub_matches_[__mexp_-1].first = __s.__current_;
1635 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001636}
1637
1638// __end_marked_subexpression
1639
1640template <class _CharT>
1641class __end_marked_subexpression
1642 : public __owns_one_state<_CharT>
1643{
1644 typedef __owns_one_state<_CharT> base;
1645
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001646 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001647public:
Howard Hinnantac303862010-07-12 15:51:17 +00001648 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001649
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001651 explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001652 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001653
Howard Hinnantac303862010-07-12 15:51:17 +00001654 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001655};
1656
1657template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001658void
1659__end_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001660{
Howard Hinnantac303862010-07-12 15:51:17 +00001661 __s.__do_ = __state::__accept_but_not_consume;
1662 __s.__sub_matches_[__mexp_-1].second = __s.__current_;
1663 __s.__sub_matches_[__mexp_-1].matched = true;
1664 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001665}
1666
Howard Hinnantcba352d2010-07-12 18:16:05 +00001667// __back_ref
1668
1669template <class _CharT>
1670class __back_ref
1671 : public __owns_one_state<_CharT>
1672{
1673 typedef __owns_one_state<_CharT> base;
1674
1675 unsigned __mexp_;
1676public:
1677 typedef _STD::__state<_CharT> __state;
1678
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001679 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcba352d2010-07-12 18:16:05 +00001680 explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
1681 : base(__s), __mexp_(__mexp) {}
1682
1683 virtual void __exec(__state&) const;
Howard Hinnantcba352d2010-07-12 18:16:05 +00001684};
1685
1686template <class _CharT>
1687void
1688__back_ref<_CharT>::__exec(__state& __s) const
1689{
1690 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1691 if (__sm.matched)
1692 {
1693 ptrdiff_t __len = __sm.second - __sm.first;
1694 if (__s.__last_ - __s.__current_ >= __len &&
1695 _STD::equal(__sm.first, __sm.second, __s.__current_))
1696 {
1697 __s.__do_ = __state::__accept_but_not_consume;
1698 __s.__current_ += __len;
1699 __s.__node_ = this->first();
1700 }
1701 else
1702 {
1703 __s.__do_ = __state::__reject;
1704 __s.__node_ = nullptr;
1705 }
1706 }
1707 else
1708 {
1709 __s.__do_ = __state::__reject;
1710 __s.__node_ = nullptr;
1711 }
1712}
1713
Howard Hinnante34f17d2010-07-12 19:11:27 +00001714// __back_ref_icase
1715
1716template <class _CharT, class _Traits>
1717class __back_ref_icase
1718 : public __owns_one_state<_CharT>
1719{
1720 typedef __owns_one_state<_CharT> base;
1721
1722 _Traits __traits_;
1723 unsigned __mexp_;
1724public:
1725 typedef _STD::__state<_CharT> __state;
1726
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001727 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00001728 explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
1729 __node<_CharT>* __s)
1730 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1731
1732 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00001733};
1734
1735template <class _CharT, class _Traits>
1736void
1737__back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
1738{
1739 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1740 if (__sm.matched)
1741 {
1742 ptrdiff_t __len = __sm.second - __sm.first;
1743 if (__s.__last_ - __s.__current_ >= __len)
1744 {
1745 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1746 {
1747 if (__traits_.translate_nocase(__sm.first[__i]) !=
1748 __traits_.translate_nocase(__s.__current_[__i]))
1749 goto __not_equal;
1750 }
1751 __s.__do_ = __state::__accept_but_not_consume;
1752 __s.__current_ += __len;
1753 __s.__node_ = this->first();
1754 }
1755 else
1756 {
1757 __s.__do_ = __state::__reject;
1758 __s.__node_ = nullptr;
1759 }
1760 }
1761 else
1762 {
1763__not_equal:
1764 __s.__do_ = __state::__reject;
1765 __s.__node_ = nullptr;
1766 }
1767}
1768
1769// __back_ref_collate
1770
1771template <class _CharT, class _Traits>
1772class __back_ref_collate
1773 : public __owns_one_state<_CharT>
1774{
1775 typedef __owns_one_state<_CharT> base;
1776
1777 _Traits __traits_;
1778 unsigned __mexp_;
1779public:
1780 typedef _STD::__state<_CharT> __state;
1781
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00001783 explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
1784 __node<_CharT>* __s)
1785 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1786
1787 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00001788};
1789
1790template <class _CharT, class _Traits>
1791void
1792__back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
1793{
1794 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1795 if (__sm.matched)
1796 {
1797 ptrdiff_t __len = __sm.second - __sm.first;
1798 if (__s.__last_ - __s.__current_ >= __len)
1799 {
1800 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1801 {
1802 if (__traits_.translate(__sm.first[__i]) !=
1803 __traits_.translate(__s.__current_[__i]))
1804 goto __not_equal;
1805 }
1806 __s.__do_ = __state::__accept_but_not_consume;
1807 __s.__current_ += __len;
1808 __s.__node_ = this->first();
1809 }
1810 else
1811 {
1812 __s.__do_ = __state::__reject;
1813 __s.__node_ = nullptr;
1814 }
1815 }
1816 else
1817 {
1818__not_equal:
1819 __s.__do_ = __state::__reject;
1820 __s.__node_ = nullptr;
1821 }
1822}
1823
Howard Hinnant17615b02010-07-27 01:25:38 +00001824// __word_boundary
1825
1826template <class _CharT, class _Traits>
1827class __word_boundary
1828 : public __owns_one_state<_CharT>
1829{
1830 typedef __owns_one_state<_CharT> base;
1831
1832 _Traits __traits_;
1833 bool __invert_;
1834public:
1835 typedef _STD::__state<_CharT> __state;
1836
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001837 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant17615b02010-07-27 01:25:38 +00001838 explicit __word_boundary(const _Traits& __traits, bool __invert,
1839 __node<_CharT>* __s)
1840 : base(__s), __traits_(__traits), __invert_(__invert) {}
1841
1842 virtual void __exec(__state&) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00001843};
1844
1845template <class _CharT, class _Traits>
1846void
1847__word_boundary<_CharT, _Traits>::__exec(__state& __s) const
1848{
1849 bool __is_word_b = false;
1850 if (__s.__first_ != __s.__last_)
1851 {
1852 if (__s.__current_ == __s.__last_)
1853 {
1854 if (!(__s.__flags_ & regex_constants::match_not_eow))
1855 {
1856 _CharT __c = __s.__current_[-1];
1857 __is_word_b = __c == '_' ||
1858 __traits_.isctype(__c, ctype_base::alnum);
1859 }
1860 }
Howard Hinnantf3dcca02010-07-29 15:17:28 +00001861 else if (__s.__current_ == __s.__first_ &&
1862 !(__s.__flags_ & regex_constants::match_prev_avail))
Howard Hinnant17615b02010-07-27 01:25:38 +00001863 {
1864 if (!(__s.__flags_ & regex_constants::match_not_bow))
1865 {
1866 _CharT __c = *__s.__current_;
1867 __is_word_b = __c == '_' ||
1868 __traits_.isctype(__c, ctype_base::alnum);
1869 }
1870 }
1871 else
1872 {
1873 _CharT __c1 = __s.__current_[-1];
1874 _CharT __c2 = *__s.__current_;
1875 bool __is_c1_b = __c1 == '_' ||
1876 __traits_.isctype(__c1, ctype_base::alnum);
1877 bool __is_c2_b = __c2 == '_' ||
1878 __traits_.isctype(__c2, ctype_base::alnum);
1879 __is_word_b = __is_c1_b != __is_c2_b;
1880 }
1881 }
1882 if (__is_word_b != __invert_)
1883 {
1884 __s.__do_ = __state::__accept_but_not_consume;
1885 __s.__node_ = this->first();
1886 }
1887 else
1888 {
1889 __s.__do_ = __state::__reject;
1890 __s.__node_ = nullptr;
1891 }
1892}
1893
Howard Hinnant41fb6e12011-03-26 20:02:27 +00001894// __l_anchor
1895
1896template <class _CharT>
1897class __l_anchor
1898 : public __owns_one_state<_CharT>
1899{
1900 typedef __owns_one_state<_CharT> base;
1901
1902public:
1903 typedef _STD::__state<_CharT> __state;
1904
1905 _LIBCPP_INLINE_VISIBILITY
1906 __l_anchor(__node<_CharT>* __s)
1907 : base(__s) {}
1908
1909 virtual void __exec(__state&) const;
1910};
1911
1912template <class _CharT>
1913void
1914__l_anchor<_CharT>::__exec(__state& __s) const
1915{
1916 if (__s.__at_first_ && __s.__current_ == __s.__first_)
1917 {
1918 __s.__do_ = __state::__accept_but_not_consume;
1919 __s.__node_ = this->first();
1920 }
1921 else
1922 {
1923 __s.__do_ = __state::__reject;
1924 __s.__node_ = nullptr;
1925 }
1926}
1927
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001928// __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001929
1930template <class _CharT>
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001931class __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001932 : public __owns_one_state<_CharT>
1933{
1934 typedef __owns_one_state<_CharT> base;
1935
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001936public:
Howard Hinnantac303862010-07-12 15:51:17 +00001937 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001938
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001940 __r_anchor(__node<_CharT>* __s)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001941 : base(__s) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001942
Howard Hinnantac303862010-07-12 15:51:17 +00001943 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001944};
1945
1946template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001947void
1948__r_anchor<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001949{
Howard Hinnantac303862010-07-12 15:51:17 +00001950 if (__s.__current_ == __s.__last_)
1951 {
1952 __s.__do_ = __state::__accept_but_not_consume;
1953 __s.__node_ = this->first();
1954 }
1955 else
1956 {
1957 __s.__do_ = __state::__reject;
1958 __s.__node_ = nullptr;
1959 }
1960}
1961
1962// __match_any
1963
1964template <class _CharT>
1965class __match_any
1966 : public __owns_one_state<_CharT>
1967{
1968 typedef __owns_one_state<_CharT> base;
1969
1970public:
1971 typedef _STD::__state<_CharT> __state;
1972
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001974 __match_any(__node<_CharT>* __s)
1975 : base(__s) {}
1976
1977 virtual void __exec(__state&) const;
Howard Hinnantac303862010-07-12 15:51:17 +00001978};
1979
1980template <class _CharT>
1981void
1982__match_any<_CharT>::__exec(__state& __s) const
1983{
1984 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
1985 {
1986 __s.__do_ = __state::__accept_and_consume;
1987 ++__s.__current_;
1988 __s.__node_ = this->first();
1989 }
1990 else
1991 {
1992 __s.__do_ = __state::__reject;
1993 __s.__node_ = nullptr;
1994 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001995}
1996
Howard Hinnant17615b02010-07-27 01:25:38 +00001997// __match_any_but_newline
1998
1999template <class _CharT>
2000class __match_any_but_newline
2001 : public __owns_one_state<_CharT>
2002{
2003 typedef __owns_one_state<_CharT> base;
2004
2005public:
2006 typedef _STD::__state<_CharT> __state;
2007
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant17615b02010-07-27 01:25:38 +00002009 __match_any_but_newline(__node<_CharT>* __s)
2010 : base(__s) {}
2011
2012 virtual void __exec(__state&) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00002013};
2014
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002015// __match_char
2016
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002017template <class _CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002018class __match_char
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002019 : public __owns_one_state<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002020{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002021 typedef __owns_one_state<_CharT> base;
2022
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002023 _CharT __c_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002024
2025 __match_char(const __match_char&);
2026 __match_char& operator=(const __match_char&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002027public:
Howard Hinnantac303862010-07-12 15:51:17 +00002028 typedef _STD::__state<_CharT> __state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002029
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00002031 __match_char(_CharT __c, __node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002032 : base(__s), __c_(__c) {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002033
Howard Hinnantac303862010-07-12 15:51:17 +00002034 virtual void __exec(__state&) const;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002035};
2036
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002037template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00002038void
2039__match_char<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002040{
Howard Hinnantac303862010-07-12 15:51:17 +00002041 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
2042 {
2043 __s.__do_ = __state::__accept_and_consume;
2044 ++__s.__current_;
2045 __s.__node_ = this->first();
2046 }
2047 else
2048 {
2049 __s.__do_ = __state::__reject;
2050 __s.__node_ = nullptr;
2051 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002052}
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002053
Howard Hinnante34f17d2010-07-12 19:11:27 +00002054// __match_char_icase
2055
2056template <class _CharT, class _Traits>
2057class __match_char_icase
2058 : public __owns_one_state<_CharT>
2059{
2060 typedef __owns_one_state<_CharT> base;
2061
2062 _Traits __traits_;
2063 _CharT __c_;
2064
2065 __match_char_icase(const __match_char_icase&);
2066 __match_char_icase& operator=(const __match_char_icase&);
2067public:
2068 typedef _STD::__state<_CharT> __state;
2069
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002070 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00002071 __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2072 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
2073
2074 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00002075};
2076
2077template <class _CharT, class _Traits>
2078void
2079__match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
2080{
2081 if (__s.__current_ != __s.__last_ &&
2082 __traits_.translate_nocase(*__s.__current_) == __c_)
2083 {
2084 __s.__do_ = __state::__accept_and_consume;
2085 ++__s.__current_;
2086 __s.__node_ = this->first();
2087 }
2088 else
2089 {
2090 __s.__do_ = __state::__reject;
2091 __s.__node_ = nullptr;
2092 }
2093}
2094
2095// __match_char_collate
2096
2097template <class _CharT, class _Traits>
2098class __match_char_collate
2099 : public __owns_one_state<_CharT>
2100{
2101 typedef __owns_one_state<_CharT> base;
2102
2103 _Traits __traits_;
2104 _CharT __c_;
2105
2106 __match_char_collate(const __match_char_collate&);
2107 __match_char_collate& operator=(const __match_char_collate&);
2108public:
2109 typedef _STD::__state<_CharT> __state;
2110
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00002112 __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2113 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2114
2115 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00002116};
2117
2118template <class _CharT, class _Traits>
2119void
2120__match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
2121{
2122 if (__s.__current_ != __s.__last_ &&
2123 __traits_.translate(*__s.__current_) == __c_)
2124 {
2125 __s.__do_ = __state::__accept_and_consume;
2126 ++__s.__current_;
2127 __s.__node_ = this->first();
2128 }
2129 else
2130 {
2131 __s.__do_ = __state::__reject;
2132 __s.__node_ = nullptr;
2133 }
2134}
2135
Howard Hinnant173968a2010-07-13 21:48:06 +00002136// __bracket_expression
2137
2138template <class _CharT, class _Traits>
2139class __bracket_expression
2140 : public __owns_one_state<_CharT>
2141{
2142 typedef __owns_one_state<_CharT> base;
2143 typedef typename _Traits::string_type string_type;
2144
2145 _Traits __traits_;
2146 vector<_CharT> __chars_;
Howard Hinnant15476f32010-07-28 17:35:27 +00002147 vector<_CharT> __neg_chars_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002148 vector<pair<string_type, string_type> > __ranges_;
2149 vector<pair<_CharT, _CharT> > __digraphs_;
2150 vector<string_type> __equivalences_;
2151 ctype_base::mask __mask_;
Howard Hinnant15476f32010-07-28 17:35:27 +00002152 ctype_base::mask __neg_mask_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002153 bool __negate_;
2154 bool __icase_;
2155 bool __collate_;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002156 bool __might_have_digraph_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002157
2158 __bracket_expression(const __bracket_expression&);
2159 __bracket_expression& operator=(const __bracket_expression&);
2160public:
2161 typedef _STD::__state<_CharT> __state;
2162
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002164 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
2165 bool __negate, bool __icase, bool __collate)
Howard Hinnant15476f32010-07-28 17:35:27 +00002166 : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
2167 __negate_(__negate), __icase_(__icase), __collate_(__collate),
Howard Hinnant68025ed2010-07-14 15:45:11 +00002168 __might_have_digraph_(__traits_.getloc().name() != "C") {}
Howard Hinnant173968a2010-07-13 21:48:06 +00002169
2170 virtual void __exec(__state&) const;
2171
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant15476f32010-07-28 17:35:27 +00002173 bool __negated() const {return __negate_;}
2174
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002176 void __add_char(_CharT __c)
2177 {
2178 if (__icase_)
2179 __chars_.push_back(__traits_.translate_nocase(__c));
2180 else if (__collate_)
2181 __chars_.push_back(__traits_.translate(__c));
2182 else
2183 __chars_.push_back(__c);
2184 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant15476f32010-07-28 17:35:27 +00002186 void __add_neg_char(_CharT __c)
2187 {
2188 if (__icase_)
2189 __neg_chars_.push_back(__traits_.translate_nocase(__c));
2190 else if (__collate_)
2191 __neg_chars_.push_back(__traits_.translate(__c));
2192 else
2193 __neg_chars_.push_back(__c);
2194 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002195 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002196 void __add_range(string_type __b, string_type __e)
2197 {
2198 if (__collate_)
2199 {
2200 if (__icase_)
2201 {
2202 for (size_t __i = 0; __i < __b.size(); ++__i)
2203 __b[__i] = __traits_.translate_nocase(__b[__i]);
2204 for (size_t __i = 0; __i < __e.size(); ++__i)
2205 __e[__i] = __traits_.translate_nocase(__e[__i]);
2206 }
2207 else
2208 {
2209 for (size_t __i = 0; __i < __b.size(); ++__i)
2210 __b[__i] = __traits_.translate(__b[__i]);
2211 for (size_t __i = 0; __i < __e.size(); ++__i)
2212 __e[__i] = __traits_.translate(__e[__i]);
2213 }
2214 __ranges_.push_back(make_pair(
2215 __traits_.transform(__b.begin(), __b.end()),
2216 __traits_.transform(__e.begin(), __e.end())));
2217 }
2218 else
2219 {
Howard Hinnantd4444702010-08-11 17:04:31 +00002220#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00002221 if (__b.size() != 1 || __e.size() != 1)
2222 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00002223#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00002224 if (__icase_)
2225 {
2226 __b[0] = __traits_.translate_nocase(__b[0]);
2227 __e[0] = __traits_.translate_nocase(__e[0]);
2228 }
2229 __ranges_.push_back(make_pair(_STD::move(__b), _STD::move(__e)));
2230 }
2231 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002233 void __add_digraph(_CharT __c1, _CharT __c2)
2234 {
2235 if (__icase_)
2236 __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
2237 __traits_.translate_nocase(__c2)));
2238 else if (__collate_)
2239 __digraphs_.push_back(make_pair(__traits_.translate(__c1),
2240 __traits_.translate(__c2)));
2241 else
2242 __digraphs_.push_back(make_pair(__c1, __c2));
2243 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002245 void __add_equivalence(const string_type& __s)
2246 {__equivalences_.push_back(__s);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002248 void __add_class(ctype_base::mask __mask)
2249 {__mask_ |= __mask;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant15476f32010-07-28 17:35:27 +00002251 void __add_neg_class(ctype_base::mask __mask)
2252 {__neg_mask_ |= __mask;}
Howard Hinnant173968a2010-07-13 21:48:06 +00002253};
2254
2255template <class _CharT, class _Traits>
2256void
2257__bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
2258{
2259 bool __found = false;
2260 unsigned __consumed = 0;
2261 if (__s.__current_ != __s.__last_)
2262 {
2263 ++__consumed;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002264 if (__might_have_digraph_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002265 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00002266 const _CharT* __next = _STD::next(__s.__current_);
Howard Hinnant68025ed2010-07-14 15:45:11 +00002267 if (__next != __s.__last_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002268 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002269 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2270 if (__icase_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002271 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002272 __ch2.first = __traits_.translate_nocase(__ch2.first);
2273 __ch2.second = __traits_.translate_nocase(__ch2.second);
2274 }
2275 else if (__collate_)
2276 {
2277 __ch2.first = __traits_.translate(__ch2.first);
2278 __ch2.second = __traits_.translate(__ch2.second);
2279 }
2280 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
2281 {
2282 // __ch2 is a digraph in this locale
2283 ++__consumed;
2284 for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
2285 {
2286 if (__ch2 == __digraphs_[__i])
2287 {
2288 __found = true;
2289 goto __exit;
2290 }
2291 }
2292 if (__collate_ && !__ranges_.empty())
2293 {
2294 string_type __s2 = __traits_.transform(&__ch2.first,
2295 &__ch2.first + 2);
2296 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2297 {
2298 if (__ranges_[__i].first <= __s2 &&
2299 __s2 <= __ranges_[__i].second)
2300 {
2301 __found = true;
2302 goto __exit;
2303 }
2304 }
2305 }
2306 if (!__equivalences_.empty())
2307 {
2308 string_type __s2 = __traits_.transform_primary(&__ch2.first,
2309 &__ch2.first + 2);
2310 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2311 {
2312 if (__s2 == __equivalences_[__i])
2313 {
2314 __found = true;
2315 goto __exit;
2316 }
2317 }
2318 }
2319 if (__traits_.isctype(__ch2.first, __mask_) &&
2320 __traits_.isctype(__ch2.second, __mask_))
Howard Hinnant173968a2010-07-13 21:48:06 +00002321 {
2322 __found = true;
2323 goto __exit;
2324 }
Howard Hinnant15476f32010-07-28 17:35:27 +00002325 if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
2326 !__traits_.isctype(__ch2.second, __neg_mask_))
2327 {
2328 __found = true;
2329 goto __exit;
2330 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002331 goto __exit;
2332 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002333 }
2334 }
2335 // test *__s.__current_ as not a digraph
2336 _CharT __ch = *__s.__current_;
2337 if (__icase_)
2338 __ch = __traits_.translate_nocase(__ch);
2339 else if (__collate_)
2340 __ch = __traits_.translate(__ch);
2341 for (size_t __i = 0; __i < __chars_.size(); ++__i)
2342 {
2343 if (__ch == __chars_[__i])
2344 {
2345 __found = true;
2346 goto __exit;
2347 }
2348 }
Howard Hinnant15476f32010-07-28 17:35:27 +00002349 if (!__neg_chars_.empty())
2350 {
2351 for (size_t __i = 0; __i < __neg_chars_.size(); ++__i)
2352 {
2353 if (__ch == __neg_chars_[__i])
2354 goto __is_neg_char;
2355 }
2356 __found = true;
2357 goto __exit;
2358 }
2359__is_neg_char:
Howard Hinnant173968a2010-07-13 21:48:06 +00002360 if (!__ranges_.empty())
2361 {
2362 string_type __s2 = __collate_ ?
2363 __traits_.transform(&__ch, &__ch + 1) :
2364 string_type(1, __ch);
2365 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2366 {
2367 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
2368 {
2369 __found = true;
2370 goto __exit;
2371 }
2372 }
2373 }
2374 if (!__equivalences_.empty())
2375 {
2376 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2377 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2378 {
2379 if (__s2 == __equivalences_[__i])
2380 {
2381 __found = true;
2382 goto __exit;
2383 }
2384 }
2385 }
2386 if (__traits_.isctype(__ch, __mask_))
Howard Hinnant15476f32010-07-28 17:35:27 +00002387 {
Howard Hinnant173968a2010-07-13 21:48:06 +00002388 __found = true;
Howard Hinnant15476f32010-07-28 17:35:27 +00002389 goto __exit;
2390 }
2391 if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_))
2392 {
2393 __found = true;
2394 goto __exit;
2395 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002396 }
2397 else
2398 __found = __negate_; // force reject
2399__exit:
2400 if (__found != __negate_)
2401 {
Howard Hinnant173968a2010-07-13 21:48:06 +00002402 __s.__do_ = __state::__accept_and_consume;
2403 __s.__current_ += __consumed;
2404 __s.__node_ = this->first();
2405 }
2406 else
2407 {
2408 __s.__do_ = __state::__reject;
2409 __s.__node_ = nullptr;
2410 }
2411}
2412
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002413template <class, class> class __lookahead;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002414
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002415template <class _CharT, class _Traits = regex_traits<_CharT> >
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002416class _LIBCPP_VISIBLE basic_regex
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002417{
2418public:
2419 // types:
2420 typedef _CharT value_type;
2421 typedef regex_constants::syntax_option_type flag_type;
2422 typedef typename _Traits::locale_type locale_type;
2423
2424private:
2425 _Traits __traits_;
2426 flag_type __flags_;
2427 unsigned __marked_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002428 unsigned __loop_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002429 int __open_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002430 shared_ptr<__empty_state<_CharT> > __start_;
2431 __owns_one_state<_CharT>* __end_;
2432
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002433 typedef _STD::__state<_CharT> __state;
Howard Hinnantac303862010-07-12 15:51:17 +00002434 typedef _STD::__node<_CharT> __node;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002435
2436public:
2437 // constants:
2438 static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase;
2439 static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2440 static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize;
2441 static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate;
2442 static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2443 static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic;
2444 static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended;
2445 static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk;
2446 static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep;
2447 static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep;
2448
2449 // construct/copy/destroy:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002451 basic_regex()
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002452 : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002453 __end_(0)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002454 {}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002456 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002457 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002458 __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002459 {__parse(__p, __p + __traits_.length(__p));}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002461 basic_regex(const value_type* __p, size_t __len, flag_type __f)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002462 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002463 __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002464 {__parse(__p, __p + __len);}
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002465// basic_regex(const basic_regex&) = default;
2466// basic_regex(basic_regex&&) = default;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002467 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002469 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2470 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002471 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002472 __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002473 {__parse(__p.begin(), __p.end());}
2474 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002476 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
2477 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002478 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002479 __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002480 {__parse(__first, __last);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002482 basic_regex(initializer_list<value_type> __il,
2483 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002484 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002485 __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002486 {__parse(__il.begin(), __il.end());}
2487
Howard Hinnant7026a172010-08-13 18:11:23 +00002488// ~basic_regex() = default;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002489
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002490// basic_regex& operator=(const basic_regex&) = default;
2491// basic_regex& operator=(basic_regex&&) = default;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002493 basic_regex& operator=(const value_type* __p)
2494 {return assign(__p);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002496 basic_regex& operator=(initializer_list<value_type> __il)
2497 {return assign(__il);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002498 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002499 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002500 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
2501 {return assign(__p);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002502
2503 // assign:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002504 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002505 basic_regex& assign(const basic_regex& __that)
2506 {return *this = __that;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002507 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002508 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2509 {return assign(__p, __p + __traits_.length(__p), __f);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002511 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f)
2512 {return assign(__p, __p + __len, __f);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002513 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002515 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
Howard Hinnant7026a172010-08-13 18:11:23 +00002516 flag_type __f = regex_constants::ECMAScript)
2517 {return assign(__s.begin(), __s.end(), __f);}
2518
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002519 template <class _InputIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002520 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002521 typename enable_if
2522 <
2523 __is_input_iterator <_InputIterator>::value &&
2524 !__is_forward_iterator<_InputIterator>::value,
2525 basic_regex&
2526 >::type
2527 assign(_InputIterator __first, _InputIterator __last,
2528 flag_type __f = regex_constants::ECMAScript)
2529 {
2530 basic_string<_CharT> __t(__first, __last);
2531 return assign(__t.begin(), __t.end(), __f);
2532 }
2533
2534private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002536 void __member_init(flag_type __f)
2537 {
2538 __flags_ = __f;
2539 __marked_count_ = 0;
2540 __loop_count_ = 0;
2541 __open_count_ = 0;
2542 __end_ = nullptr;
Howard Hinnant7026a172010-08-13 18:11:23 +00002543 }
2544public:
2545
2546 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002547 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002548 typename enable_if
2549 <
2550 __is_forward_iterator<_ForwardIterator>::value,
2551 basic_regex&
2552 >::type
2553 assign(_ForwardIterator __first, _ForwardIterator __last,
2554 flag_type __f = regex_constants::ECMAScript)
2555 {
2556 __member_init(__f);
2557 __parse(__first, __last);
2558 }
2559
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002561 basic_regex& assign(initializer_list<value_type> __il,
Howard Hinnant7026a172010-08-13 18:11:23 +00002562 flag_type __f = regex_constants::ECMAScript)
2563 {return assign(__il.begin(), __il.end(), __f);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002564
2565 // const operations:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002567 unsigned mark_count() const {return __marked_count_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002568 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002569 flag_type flags() const {return __flags_;}
2570
2571 // locale:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002573 locale_type imbue(locale_type __loc)
2574 {
2575 __member_init(ECMAScript);
2576 __start_.reset();
2577 return __traits_.imbue(__loc);
2578 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002579 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002580 locale_type getloc() const {return __traits_.getloc();}
2581
2582 // swap:
Howard Hinnant7026a172010-08-13 18:11:23 +00002583 void swap(basic_regex& __r);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002584
2585private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002587 unsigned __loop_count() const {return __loop_count_;}
2588
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002589 template <class _ForwardIterator>
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002590 _ForwardIterator
2591 __parse(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002592 template <class _ForwardIterator>
2593 _ForwardIterator
2594 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2595 template <class _ForwardIterator>
2596 _ForwardIterator
2597 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2598 template <class _ForwardIterator>
2599 _ForwardIterator
2600 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2601 template <class _ForwardIterator>
2602 _ForwardIterator
2603 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2604 template <class _ForwardIterator>
2605 _ForwardIterator
2606 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2607 template <class _ForwardIterator>
2608 _ForwardIterator
2609 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2610 template <class _ForwardIterator>
2611 _ForwardIterator
2612 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2613 template <class _ForwardIterator>
2614 _ForwardIterator
2615 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2616 template <class _ForwardIterator>
2617 _ForwardIterator
2618 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2619 template <class _ForwardIterator>
2620 _ForwardIterator
2621 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2622 template <class _ForwardIterator>
2623 _ForwardIterator
2624 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2625 template <class _ForwardIterator>
2626 _ForwardIterator
2627 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2628 template <class _ForwardIterator>
2629 _ForwardIterator
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002630 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002631 __owns_one_state<_CharT>* __s,
2632 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002633 template <class _ForwardIterator>
2634 _ForwardIterator
Howard Hinnantaa698082010-07-16 19:08:36 +00002635 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2636 __owns_one_state<_CharT>* __s,
2637 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002638 template <class _ForwardIterator>
2639 _ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00002640 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2641 template <class _ForwardIterator>
2642 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002643 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
2644 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002645 template <class _ForwardIterator>
2646 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002647 __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
2648 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002649 template <class _ForwardIterator>
2650 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002651 __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
2652 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002653 template <class _ForwardIterator>
2654 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002655 __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
2656 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002657 template <class _ForwardIterator>
2658 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002659 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
2660 basic_string<_CharT>& __col_sym);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002661 template <class _ForwardIterator>
2662 _ForwardIterator
2663 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002664 template <class _ForwardIterator>
2665 _ForwardIterator
2666 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2667 template <class _ForwardIterator>
2668 _ForwardIterator
2669 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2670 template <class _ForwardIterator>
2671 _ForwardIterator
2672 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2673 template <class _ForwardIterator>
2674 _ForwardIterator
2675 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2676 template <class _ForwardIterator>
2677 _ForwardIterator
2678 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2679 template <class _ForwardIterator>
2680 _ForwardIterator
2681 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002682 template <class _ForwardIterator>
2683 _ForwardIterator
2684 __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2685 template <class _ForwardIterator>
2686 _ForwardIterator
2687 __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2688 template <class _ForwardIterator>
2689 _ForwardIterator
2690 __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2691 template <class _ForwardIterator>
2692 _ForwardIterator
2693 __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2694 template <class _ForwardIterator>
2695 _ForwardIterator
2696 __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2697 template <class _ForwardIterator>
2698 _ForwardIterator
Howard Hinnant17615b02010-07-27 01:25:38 +00002699 __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2700 template <class _ForwardIterator>
2701 _ForwardIterator
2702 __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2703 template <class _ForwardIterator>
2704 _ForwardIterator
2705 __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2706 template <class _ForwardIterator>
2707 _ForwardIterator
Howard Hinnant15476f32010-07-28 17:35:27 +00002708 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
2709 basic_string<_CharT>* __str = nullptr);
Howard Hinnant17615b02010-07-27 01:25:38 +00002710 template <class _ForwardIterator>
2711 _ForwardIterator
2712 __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant856846b2010-07-27 19:53:10 +00002713 template <class _ForwardIterator>
2714 _ForwardIterator
2715 __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
2716 template <class _ForwardIterator>
2717 _ForwardIterator
2718 __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant15476f32010-07-28 17:35:27 +00002719 template <class _ForwardIterator>
2720 _ForwardIterator
2721 __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
2722 basic_string<_CharT>& __str,
2723 __bracket_expression<_CharT, _Traits>* __ml);
2724 template <class _ForwardIterator>
2725 _ForwardIterator
2726 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
2727 basic_string<_CharT>* __str = nullptr);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002728
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002729 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002730 void __push_l_anchor();
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002731 void __push_r_anchor();
Howard Hinnantac303862010-07-12 15:51:17 +00002732 void __push_match_any();
Howard Hinnant17615b02010-07-27 01:25:38 +00002733 void __push_match_any_but_newline();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002734 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002735 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2736 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2737 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2738 __mexp_begin, __mexp_end);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant17615b02010-07-27 01:25:38 +00002740 void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2741 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2742 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2743 __mexp_begin, __mexp_end, false);}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002744 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2745 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2746 bool __greedy = true);
Howard Hinnant173968a2010-07-13 21:48:06 +00002747 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002748 void __push_char(value_type __c);
Howard Hinnantcba352d2010-07-12 18:16:05 +00002749 void __push_back_ref(int __i);
Howard Hinnantaa698082010-07-16 19:08:36 +00002750 void __push_alternation(__owns_one_state<_CharT>* __sa,
2751 __owns_one_state<_CharT>* __sb);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002752 void __push_begin_marked_subexpression();
2753 void __push_end_marked_subexpression(unsigned);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002754 void __push_empty();
Howard Hinnant17615b02010-07-27 01:25:38 +00002755 void __push_word_boundary(bool);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002756 void __push_lookahead(const basic_regex&, bool);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002757
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002758 template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002759 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002760 __search(const _CharT* __first, const _CharT* __last,
2761 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002762 regex_constants::match_flag_type __flags) const;
2763
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002764 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002765 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002766 __match_at_start(const _CharT* __first, const _CharT* __last,
2767 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002768 regex_constants::match_flag_type __flags, bool) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00002769 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002770 bool
Howard Hinnant17615b02010-07-27 01:25:38 +00002771 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
2772 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002773 regex_constants::match_flag_type __flags, bool) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002774 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002775 bool
2776 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002777 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002778 regex_constants::match_flag_type __flags, bool) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002779 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002780 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002781 __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
2782 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002783 regex_constants::match_flag_type __flags, bool) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002784
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002785 template <class _B, class _A, class _C, class _T>
2786 friend
2787 bool
2788 regex_search(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
2789 regex_constants::match_flag_type);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002790
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002791 template <class _A, class _C, class _T>
2792 friend
2793 bool
2794 regex_search(const _C*, const _C*, match_results<const _C*, _A>&,
2795 const basic_regex<_C, _T>&, regex_constants::match_flag_type);
2796
2797 template <class _B, class _C, class _T>
2798 friend
2799 bool
2800 regex_search(_B, _B, const basic_regex<_C, _T>&,
2801 regex_constants::match_flag_type);
2802
2803 template <class _C, class _T>
2804 friend
2805 bool
2806 regex_search(const _C*, const _C*,
2807 const basic_regex<_C, _T>&, regex_constants::match_flag_type);
2808
2809 template <class _C, class _A, class _T>
2810 friend
2811 bool
2812 regex_search(const _C*, match_results<const _C*, _A>&, const basic_regex<_C, _T>&,
2813 regex_constants::match_flag_type);
2814
2815 template <class _ST, class _SA, class _C, class _T>
2816 friend
2817 bool
2818 regex_search(const basic_string<_C, _ST, _SA>& __s,
2819 const basic_regex<_C, _T>& __e,
2820 regex_constants::match_flag_type __flags);
2821
2822 template <class _ST, class _SA, class _A, class _C, class _T>
2823 friend
2824 bool
2825 regex_search(const basic_string<_C, _ST, _SA>& __s,
Howard Hinnant324bb032010-08-22 00:02:43 +00002826 match_results<typename basic_string<_C, _ST, _SA>::const_iterator, _A>&,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002827 const basic_regex<_C, _T>& __e,
2828 regex_constants::match_flag_type __flags);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002829
2830 template <class, class> friend class __lookahead;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002831};
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002832
2833template <class _CharT, class _Traits>
Howard Hinnant7026a172010-08-13 18:11:23 +00002834void
2835basic_regex<_CharT, _Traits>::swap(basic_regex& __r)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002836{
Howard Hinnant7026a172010-08-13 18:11:23 +00002837 using _STD::swap;
2838 swap(__traits_, __r.__traits_);
2839 swap(__flags_, __r.__flags_);
2840 swap(__marked_count_, __r.__marked_count_);
2841 swap(__loop_count_, __r.__loop_count_);
2842 swap(__open_count_, __r.__open_count_);
2843 swap(__start_, __r.__start_);
2844 swap(__end_, __r.__end_);
Howard Hinnant7026a172010-08-13 18:11:23 +00002845}
2846
2847template <class _CharT, class _Traits>
2848inline _LIBCPP_INLINE_VISIBILITY
2849void
2850swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
2851{
2852 return __x.swap(__y);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002853}
2854
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002855// __lookahead
2856
2857template <class _CharT, class _Traits>
2858class __lookahead
2859 : public __owns_one_state<_CharT>
2860{
2861 typedef __owns_one_state<_CharT> base;
2862
2863 basic_regex<_CharT, _Traits> __exp_;
2864 bool __invert_;
2865
2866 __lookahead(const __lookahead&);
2867 __lookahead& operator=(const __lookahead&);
2868public:
2869 typedef _STD::__state<_CharT> __state;
2870
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002872 __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s)
2873 : base(__s), __exp_(__exp), __invert_(__invert) {}
2874
2875 virtual void __exec(__state&) const;
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002876};
2877
2878template <class _CharT, class _Traits>
2879void
2880__lookahead<_CharT, _Traits>::__exec(__state& __s) const
2881{
2882 match_results<const _CharT*> __m;
2883 __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
2884 bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002885 __m,
2886 __s.__flags_ | regex_constants::match_continuous,
2887 true);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002888 if (__matched != __invert_)
2889 {
2890 __s.__do_ = __state::__accept_but_not_consume;
2891 __s.__node_ = this->first();
2892 }
2893 else
2894 {
2895 __s.__do_ = __state::__reject;
2896 __s.__node_ = nullptr;
2897 }
2898}
2899
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002900template <class _CharT, class _Traits>
2901template <class _ForwardIterator>
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002902_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002903basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
2904 _ForwardIterator __last)
2905{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002906 {
Howard Hinnantac303862010-07-12 15:51:17 +00002907 unique_ptr<__node> __h(new __end_state<_CharT>);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002908 __start_.reset(new __empty_state<_CharT>(__h.get()));
2909 __h.release();
2910 __end_ = __start_.get();
2911 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002912 switch (__flags_ & 0x1F0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002913 {
2914 case ECMAScript:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002915 __first = __parse_ecma_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002916 break;
2917 case basic:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002918 __first = __parse_basic_reg_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002919 break;
2920 case extended:
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002921 case awk:
Howard Hinnant15476f32010-07-28 17:35:27 +00002922 __first = __parse_extended_reg_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002923 break;
2924 case grep:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002925 __first = __parse_grep(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002926 break;
2927 case egrep:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002928 __first = __parse_egrep(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002929 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00002930#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002931 default:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002932 throw regex_error(regex_constants::__re_err_grammar);
Howard Hinnant324bb032010-08-22 00:02:43 +00002933#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002934 }
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002935 return __first;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002936}
2937
2938template <class _CharT, class _Traits>
2939template <class _ForwardIterator>
2940_ForwardIterator
2941basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
2942 _ForwardIterator __last)
2943{
2944 if (__first != __last)
2945 {
2946 if (*__first == '^')
2947 {
2948 __push_l_anchor();
2949 ++__first;
2950 }
2951 if (__first != __last)
2952 {
2953 __first = __parse_RE_expression(__first, __last);
2954 if (__first != __last)
2955 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00002956 _ForwardIterator __temp = _STD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002957 if (__temp == __last && *__first == '$')
2958 {
2959 __push_r_anchor();
2960 ++__first;
2961 }
2962 }
2963 }
Howard Hinnantd4444702010-08-11 17:04:31 +00002964#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002965 if (__first != __last)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002966 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00002967#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002968 }
2969 return __first;
2970}
2971
2972template <class _CharT, class _Traits>
2973template <class _ForwardIterator>
2974_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002975basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
2976 _ForwardIterator __last)
2977{
Howard Hinnantaa698082010-07-16 19:08:36 +00002978 __owns_one_state<_CharT>* __sa = __end_;
2979 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00002980#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa698082010-07-16 19:08:36 +00002981 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002982 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00002983#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa698082010-07-16 19:08:36 +00002984 __first = __temp;
2985 while (__first != __last && *__first == '|')
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002986 {
Howard Hinnantaa698082010-07-16 19:08:36 +00002987 __owns_one_state<_CharT>* __sb = __end_;
2988 __temp = __parse_ERE_branch(++__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00002989#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002990 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002991 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00002992#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa698082010-07-16 19:08:36 +00002993 __push_alternation(__sa, __sb);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002994 __first = __temp;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002995 }
2996 return __first;
2997}
2998
2999template <class _CharT, class _Traits>
3000template <class _ForwardIterator>
3001_ForwardIterator
3002basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
3003 _ForwardIterator __last)
3004{
3005 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003006#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003007 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00003008 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00003009#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003010 do
3011 {
3012 __first = __temp;
3013 __temp = __parse_ERE_expression(__first, __last);
3014 } while (__temp != __first);
3015 return __first;
3016}
3017
3018template <class _CharT, class _Traits>
3019template <class _ForwardIterator>
3020_ForwardIterator
3021basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
3022 _ForwardIterator __last)
3023{
Howard Hinnantaa698082010-07-16 19:08:36 +00003024 __owns_one_state<_CharT>* __e = __end_;
3025 unsigned __mexp_begin = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003026 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
3027 if (__temp == __first && __temp != __last)
3028 {
3029 switch (*__temp)
3030 {
3031 case '^':
3032 __push_l_anchor();
3033 ++__temp;
3034 break;
3035 case '$':
3036 __push_r_anchor();
3037 ++__temp;
3038 break;
3039 case '(':
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003040 __push_begin_marked_subexpression();
3041 unsigned __temp_count = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003042 ++__open_count_;
3043 __temp = __parse_extended_reg_exp(++__temp, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003044#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003045 if (__temp == __last || *__temp != ')')
3046 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00003047#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003048 __push_end_marked_subexpression(__temp_count);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003049 --__open_count_;
3050 ++__temp;
3051 break;
3052 }
3053 }
3054 if (__temp != __first)
Howard Hinnantaa698082010-07-16 19:08:36 +00003055 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
3056 __marked_count_+1);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003057 __first = __temp;
3058 return __first;
3059}
3060
3061template <class _CharT, class _Traits>
3062template <class _ForwardIterator>
3063_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003064basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
3065 _ForwardIterator __last)
3066{
3067 while (true)
3068 {
3069 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
3070 if (__temp == __first)
3071 break;
3072 __first = __temp;
3073 }
3074 return __first;
3075}
3076
3077template <class _CharT, class _Traits>
3078template <class _ForwardIterator>
3079_ForwardIterator
3080basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
3081 _ForwardIterator __last)
3082{
3083 if (__first != __last)
3084 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003085 __owns_one_state<_CharT>* __e = __end_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003086 unsigned __mexp_begin = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003087 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
3088 if (__temp != __first)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003089 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
3090 __mexp_begin+1, __marked_count_+1);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003091 }
3092 return __first;
3093}
3094
3095template <class _CharT, class _Traits>
3096template <class _ForwardIterator>
3097_ForwardIterator
3098basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
3099 _ForwardIterator __last)
3100{
3101 _ForwardIterator __temp = __first;
3102 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
3103 if (__temp == __first)
3104 {
3105 __temp = __parse_Back_open_paren(__first, __last);
3106 if (__temp != __first)
3107 {
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003108 __push_begin_marked_subexpression();
3109 unsigned __temp_count = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003110 __first = __parse_RE_expression(__temp, __last);
3111 __temp = __parse_Back_close_paren(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003112#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003113 if (__temp == __first)
3114 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00003115#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003116 __push_end_marked_subexpression(__temp_count);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003117 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003118 }
3119 else
3120 __first = __parse_BACKREF(__first, __last);
3121 }
3122 return __first;
3123}
3124
3125template <class _CharT, class _Traits>
3126template <class _ForwardIterator>
3127_ForwardIterator
3128basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
3129 _ForwardIterator __first,
3130 _ForwardIterator __last)
3131{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003132 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003133 if (__temp == __first)
3134 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003135 __temp = __parse_QUOTED_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003136 if (__temp == __first)
3137 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003138 if (__temp != __last && *__temp == '.')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003139 {
3140 __push_match_any();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003141 ++__temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003142 }
3143 else
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003144 __temp = __parse_bracket_expression(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003145 }
3146 }
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003147 __first = __temp;
3148 return __first;
3149}
3150
3151template <class _CharT, class _Traits>
3152template <class _ForwardIterator>
3153_ForwardIterator
3154basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
3155 _ForwardIterator __first,
3156 _ForwardIterator __last)
3157{
3158 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
3159 if (__temp == __first)
3160 {
3161 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
3162 if (__temp == __first)
3163 {
3164 if (__temp != __last && *__temp == '.')
3165 {
3166 __push_match_any();
3167 ++__temp;
3168 }
3169 else
3170 __temp = __parse_bracket_expression(__first, __last);
3171 }
3172 }
3173 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003174 return __first;
3175}
3176
3177template <class _CharT, class _Traits>
3178template <class _ForwardIterator>
3179_ForwardIterator
3180basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
3181 _ForwardIterator __last)
3182{
3183 if (__first != __last)
3184 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003185 _ForwardIterator __temp = _STD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003186 if (__temp != __last)
3187 {
3188 if (*__first == '\\' && *__temp == '(')
3189 __first = ++__temp;
3190 }
3191 }
3192 return __first;
3193}
3194
3195template <class _CharT, class _Traits>
3196template <class _ForwardIterator>
3197_ForwardIterator
3198basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
3199 _ForwardIterator __last)
3200{
3201 if (__first != __last)
3202 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003203 _ForwardIterator __temp = _STD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003204 if (__temp != __last)
3205 {
3206 if (*__first == '\\' && *__temp == ')')
3207 __first = ++__temp;
3208 }
3209 }
3210 return __first;
3211}
3212
3213template <class _CharT, class _Traits>
3214template <class _ForwardIterator>
3215_ForwardIterator
3216basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
3217 _ForwardIterator __last)
3218{
3219 if (__first != __last)
3220 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003221 _ForwardIterator __temp = _STD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003222 if (__temp != __last)
3223 {
3224 if (*__first == '\\' && *__temp == '{')
3225 __first = ++__temp;
3226 }
3227 }
3228 return __first;
3229}
3230
3231template <class _CharT, class _Traits>
3232template <class _ForwardIterator>
3233_ForwardIterator
3234basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
3235 _ForwardIterator __last)
3236{
3237 if (__first != __last)
3238 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003239 _ForwardIterator __temp = _STD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003240 if (__temp != __last)
3241 {
3242 if (*__first == '\\' && *__temp == '}')
3243 __first = ++__temp;
3244 }
3245 }
3246 return __first;
3247}
3248
3249template <class _CharT, class _Traits>
3250template <class _ForwardIterator>
3251_ForwardIterator
3252basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
3253 _ForwardIterator __last)
3254{
3255 if (__first != __last)
3256 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003257 _ForwardIterator __temp = _STD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003258 if (__temp != __last)
3259 {
3260 if (*__first == '\\' && '1' <= *__temp && *__temp <= '9')
3261 {
3262 __push_back_ref(*__temp - '0');
3263 __first = ++__temp;
3264 }
3265 }
3266 }
3267 return __first;
3268}
3269
3270template <class _CharT, class _Traits>
3271template <class _ForwardIterator>
3272_ForwardIterator
3273basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
3274 _ForwardIterator __last)
3275{
3276 if (__first != __last)
3277 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003278 _ForwardIterator __temp = _STD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003279 if (__temp == __last && *__first == '$')
3280 return __first;
3281 // Not called inside a bracket
3282 if (*__first == '.' || *__first == '\\' || *__first == '[')
3283 return __first;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003284 __push_char(*__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003285 ++__first;
3286 }
3287 return __first;
3288}
3289
3290template <class _CharT, class _Traits>
3291template <class _ForwardIterator>
3292_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003293basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
3294 _ForwardIterator __last)
3295{
3296 if (__first != __last)
3297 {
3298 switch (*__first)
3299 {
3300 case '^':
3301 case '.':
3302 case '[':
3303 case '$':
3304 case '(':
3305 case '|':
3306 case '*':
3307 case '+':
3308 case '?':
3309 case '{':
3310 case '\\':
3311 break;
3312 case ')':
3313 if (__open_count_ == 0)
3314 {
3315 __push_char(*__first);
3316 ++__first;
3317 }
3318 break;
3319 default:
3320 __push_char(*__first);
3321 ++__first;
3322 break;
3323 }
3324 }
3325 return __first;
3326}
3327
3328template <class _CharT, class _Traits>
3329template <class _ForwardIterator>
3330_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003331basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
3332 _ForwardIterator __last)
3333{
3334 if (__first != __last)
3335 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003336 _ForwardIterator __temp = _STD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003337 if (__temp != __last)
3338 {
3339 if (*__first == '\\')
3340 {
3341 switch (*__temp)
3342 {
3343 case '^':
3344 case '.':
3345 case '*':
3346 case '[':
3347 case '$':
3348 case '\\':
Howard Hinnant0de86b62010-06-25 20:56:08 +00003349 __push_char(*__temp);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003350 __first = ++__temp;
3351 break;
3352 }
3353 }
3354 }
3355 }
3356 return __first;
3357}
3358
3359template <class _CharT, class _Traits>
3360template <class _ForwardIterator>
3361_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003362basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
3363 _ForwardIterator __last)
3364{
3365 if (__first != __last)
3366 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003367 _ForwardIterator __temp = _STD::next(__first);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003368 if (__temp != __last)
3369 {
3370 if (*__first == '\\')
3371 {
3372 switch (*__temp)
3373 {
3374 case '^':
3375 case '.':
3376 case '*':
3377 case '[':
3378 case '$':
3379 case '\\':
3380 case '(':
3381 case ')':
3382 case '|':
3383 case '+':
3384 case '?':
3385 case '{':
3386 __push_char(*__temp);
3387 __first = ++__temp;
3388 break;
Howard Hinnant15476f32010-07-28 17:35:27 +00003389 default:
3390 if ((__flags_ & 0x1F0) == awk)
3391 __first = __parse_awk_escape(++__first, __last);
3392 break;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003393 }
3394 }
3395 }
3396 }
3397 return __first;
3398}
3399
3400template <class _CharT, class _Traits>
3401template <class _ForwardIterator>
3402_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003403basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003404 _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003405 __owns_one_state<_CharT>* __s,
3406 unsigned __mexp_begin,
3407 unsigned __mexp_end)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003408{
3409 if (__first != __last)
3410 {
Howard Hinnant0de86b62010-06-25 20:56:08 +00003411 if (*__first == '*')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003412 {
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003413 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003414 ++__first;
3415 }
3416 else
3417 {
3418 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3419 if (__temp != __first)
3420 {
3421 int __min = 0;
3422 __first = __temp;
3423 __temp = __parse_DUP_COUNT(__first, __last, __min);
Howard Hinnantd4444702010-08-11 17:04:31 +00003424#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003425 if (__temp == __first)
3426 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003427#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003428 __first = __temp;
Howard Hinnantd4444702010-08-11 17:04:31 +00003429#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003430 if (__first == __last)
3431 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003432#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003433 if (*__first != ',')
3434 {
3435 __temp = __parse_Back_close_brace(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003436#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003437 if (__temp == __first)
3438 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003439#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcba352d2010-07-12 18:16:05 +00003440 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
3441 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003442 __first = __temp;
3443 }
3444 else
3445 {
3446 ++__first; // consume ','
3447 int __max = -1;
3448 __first = __parse_DUP_COUNT(__first, __last, __max);
3449 __temp = __parse_Back_close_brace(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003450#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003451 if (__temp == __first)
3452 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003453#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003454 if (__max == -1)
Howard Hinnantaa698082010-07-16 19:08:36 +00003455 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003456 else
3457 {
Howard Hinnantd4444702010-08-11 17:04:31 +00003458#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003459 if (__max < __min)
3460 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003461#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcba352d2010-07-12 18:16:05 +00003462 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
3463 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003464 }
3465 __first = __temp;
3466 }
3467 }
3468 }
3469 }
3470 return __first;
3471}
3472
Howard Hinnant0de86b62010-06-25 20:56:08 +00003473template <class _CharT, class _Traits>
3474template <class _ForwardIterator>
3475_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003476basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantaa698082010-07-16 19:08:36 +00003477 _ForwardIterator __last,
3478 __owns_one_state<_CharT>* __s,
3479 unsigned __mexp_begin,
3480 unsigned __mexp_end)
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003481{
3482 if (__first != __last)
3483 {
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003484 unsigned __grammar = __flags_ & 0x1F0;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003485 switch (*__first)
3486 {
3487 case '*':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003488 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003489 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003490 {
3491 ++__first;
3492 __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3493 }
3494 else
3495 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003496 break;
3497 case '+':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003498 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003499 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003500 {
3501 ++__first;
3502 __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3503 }
3504 else
3505 __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003506 break;
3507 case '?':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003508 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003509 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003510 {
3511 ++__first;
3512 __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3513 }
3514 else
3515 __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003516 break;
3517 case '{':
3518 {
3519 int __min;
Howard Hinnantaa698082010-07-16 19:08:36 +00003520 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
Howard Hinnantd4444702010-08-11 17:04:31 +00003521#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003522 if (__temp == __first)
3523 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003524#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003525 __first = __temp;
Howard Hinnantd4444702010-08-11 17:04:31 +00003526#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003527 if (__first == __last)
3528 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003529#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003530 switch (*__first)
3531 {
3532 case '}':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003533 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003534 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003535 {
3536 ++__first;
3537 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3538 }
3539 else
3540 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003541 break;
3542 case ',':
Howard Hinnantd4444702010-08-11 17:04:31 +00003543 ++__first;
3544#ifndef _LIBCPP_NO_EXCEPTIONS
3545 if (__first == __last)
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003546 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003547#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003548 if (*__first == '}')
3549 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003550 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003551 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003552 {
3553 ++__first;
3554 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3555 }
3556 else
3557 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003558 }
3559 else
3560 {
Howard Hinnantaa698082010-07-16 19:08:36 +00003561 int __max = -1;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003562 __temp = __parse_DUP_COUNT(__first, __last, __max);
Howard Hinnantd4444702010-08-11 17:04:31 +00003563#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003564 if (__temp == __first)
3565 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003566#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003567 __first = __temp;
Howard Hinnantd4444702010-08-11 17:04:31 +00003568#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003569 if (__first == __last || *__first != '}')
3570 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003571#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003572 ++__first;
Howard Hinnantd4444702010-08-11 17:04:31 +00003573#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003574 if (__max < __min)
3575 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003576#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003577 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003578 {
3579 ++__first;
3580 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3581 }
3582 else
3583 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003584 }
Howard Hinnantaa698082010-07-16 19:08:36 +00003585 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00003586#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003587 default:
3588 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003589#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003590 }
3591 }
3592 break;
3593 }
3594 }
3595 return __first;
3596}
3597
3598template <class _CharT, class _Traits>
3599template <class _ForwardIterator>
3600_ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00003601basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
3602 _ForwardIterator __last)
3603{
3604 if (__first != __last && *__first == '[')
3605 {
Howard Hinnantd4444702010-08-11 17:04:31 +00003606 ++__first;
3607#ifndef _LIBCPP_NO_EXCEPTIONS
3608 if (__first == __last)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003609 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003610#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003611 bool __negate = false;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003612 if (*__first == '^')
3613 {
3614 ++__first;
Howard Hinnant173968a2010-07-13 21:48:06 +00003615 __negate = true;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003616 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003617 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3618 // __ml owned by *this
Howard Hinnantd4444702010-08-11 17:04:31 +00003619#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003620 if (__first == __last)
3621 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003622#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003623 if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']')
Howard Hinnant0de86b62010-06-25 20:56:08 +00003624 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003625 __ml->__add_char(']');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003626 ++__first;
3627 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003628 __first = __parse_follow_list(__first, __last, __ml);
Howard Hinnantd4444702010-08-11 17:04:31 +00003629#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003630 if (__first == __last)
3631 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003632#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003633 if (*__first == '-')
3634 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003635 __ml->__add_char('-');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003636 ++__first;
3637 }
Howard Hinnantd4444702010-08-11 17:04:31 +00003638#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003639 if (__first == __last || *__first != ']')
3640 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003641#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003642 ++__first;
3643 }
3644 return __first;
3645}
3646
3647template <class _CharT, class _Traits>
3648template <class _ForwardIterator>
3649_ForwardIterator
3650basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003651 _ForwardIterator __last,
3652 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003653{
3654 if (__first != __last)
3655 {
3656 while (true)
3657 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003658 _ForwardIterator __temp = __parse_expression_term(__first, __last,
3659 __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003660 if (__temp == __first)
3661 break;
3662 __first = __temp;
3663 }
3664 }
3665 return __first;
3666}
3667
3668template <class _CharT, class _Traits>
3669template <class _ForwardIterator>
3670_ForwardIterator
3671basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003672 _ForwardIterator __last,
3673 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003674{
3675 if (__first != __last && *__first != ']')
3676 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003677 _ForwardIterator __temp = _STD::next(__first);
Howard Hinnant173968a2010-07-13 21:48:06 +00003678 basic_string<_CharT> __start_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003679 if (__temp != __last && *__first == '[')
3680 {
3681 if (*__temp == '=')
Howard Hinnant173968a2010-07-13 21:48:06 +00003682 return __parse_equivalence_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003683 else if (*__temp == ':')
Howard Hinnant173968a2010-07-13 21:48:06 +00003684 return __parse_character_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003685 else if (*__temp == '.')
Howard Hinnant173968a2010-07-13 21:48:06 +00003686 __first = __parse_collating_symbol(++__temp, __last, __start_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003687 }
Howard Hinnant15476f32010-07-28 17:35:27 +00003688 unsigned __grammar = __flags_ & 0x1F0;
3689 if (__start_range.empty())
Howard Hinnant0de86b62010-06-25 20:56:08 +00003690 {
Howard Hinnant15476f32010-07-28 17:35:27 +00003691 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3692 {
3693 if (__grammar == ECMAScript)
3694 __first = __parse_class_escape(++__first, __last, __start_range, __ml);
3695 else
3696 __first = __parse_awk_escape(++__first, __last, &__start_range);
3697 }
3698 else
3699 {
3700 __start_range = *__first;
3701 ++__first;
3702 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003703 }
3704 if (__first != __last && *__first != ']')
3705 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003706 __temp = _STD::next(__first);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003707 if (__temp != __last && *__first == '-' && *__temp != ']')
3708 {
3709 // parse a range
Howard Hinnant173968a2010-07-13 21:48:06 +00003710 basic_string<_CharT> __end_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003711 __first = __temp;
3712 ++__temp;
3713 if (__temp != __last && *__first == '[' && *__temp == '.')
Howard Hinnant173968a2010-07-13 21:48:06 +00003714 __first = __parse_collating_symbol(++__temp, __last, __end_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003715 else
3716 {
Howard Hinnant15476f32010-07-28 17:35:27 +00003717 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3718 {
3719 if (__grammar == ECMAScript)
3720 __first = __parse_class_escape(++__first, __last,
3721 __end_range, __ml);
3722 else
3723 __first = __parse_awk_escape(++__first, __last,
3724 &__end_range);
3725 }
3726 else
3727 {
3728 __end_range = *__first;
3729 ++__first;
3730 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003731 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003732 __ml->__add_range(_STD::move(__start_range), _STD::move(__end_range));
Howard Hinnant0de86b62010-06-25 20:56:08 +00003733 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003734 else
3735 {
3736 if (__start_range.size() == 1)
3737 __ml->__add_char(__start_range[0]);
3738 else
3739 __ml->__add_digraph(__start_range[0], __start_range[1]);
3740 }
3741 }
3742 else
3743 {
3744 if (__start_range.size() == 1)
3745 __ml->__add_char(__start_range[0]);
3746 else
3747 __ml->__add_digraph(__start_range[0], __start_range[1]);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003748 }
3749 }
3750 return __first;
3751}
3752
3753template <class _CharT, class _Traits>
3754template <class _ForwardIterator>
3755_ForwardIterator
Howard Hinnant15476f32010-07-28 17:35:27 +00003756basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
3757 _ForwardIterator __last,
3758 basic_string<_CharT>& __str,
3759 __bracket_expression<_CharT, _Traits>* __ml)
3760{
Howard Hinnantd4444702010-08-11 17:04:31 +00003761#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003762 if (__first == __last)
3763 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00003764#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003765 switch (*__first)
3766 {
3767 case 0:
3768 __str = *__first;
3769 return ++__first;
3770 case 'b':
3771 __str = _CharT(8);
3772 return ++__first;
3773 case 'd':
3774 __ml->__add_class(ctype_base::digit);
3775 return ++__first;
3776 case 'D':
3777 __ml->__add_neg_class(ctype_base::digit);
3778 return ++__first;
3779 case 's':
3780 __ml->__add_class(ctype_base::space);
3781 return ++__first;
3782 case 'S':
3783 __ml->__add_neg_class(ctype_base::space);
3784 return ++__first;
3785 case 'w':
3786 __ml->__add_class(ctype_base::alnum);
3787 __ml->__add_char('_');
3788 return ++__first;
3789 case 'W':
3790 __ml->__add_neg_class(ctype_base::alnum);
3791 __ml->__add_neg_char('_');
3792 return ++__first;
3793 }
3794 __first = __parse_character_escape(__first, __last, &__str);
3795 return __first;
3796}
3797
3798template <class _CharT, class _Traits>
3799template <class _ForwardIterator>
3800_ForwardIterator
3801basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
3802 _ForwardIterator __last,
3803 basic_string<_CharT>* __str)
3804{
Howard Hinnantd4444702010-08-11 17:04:31 +00003805#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003806 if (__first == __last)
3807 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00003808#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003809 switch (*__first)
3810 {
3811 case '\\':
3812 case '"':
3813 case '/':
3814 if (__str)
3815 *__str = *__first;
3816 else
3817 __push_char(*__first);
3818 return ++__first;
3819 case 'a':
3820 if (__str)
3821 *__str = _CharT(7);
3822 else
3823 __push_char(_CharT(7));
3824 return ++__first;
3825 case 'b':
3826 if (__str)
3827 *__str = _CharT(8);
3828 else
3829 __push_char(_CharT(8));
3830 return ++__first;
3831 case 'f':
3832 if (__str)
3833 *__str = _CharT(0xC);
3834 else
3835 __push_char(_CharT(0xC));
3836 return ++__first;
3837 case 'n':
3838 if (__str)
3839 *__str = _CharT(0xA);
3840 else
3841 __push_char(_CharT(0xA));
3842 return ++__first;
3843 case 'r':
3844 if (__str)
3845 *__str = _CharT(0xD);
3846 else
3847 __push_char(_CharT(0xD));
3848 return ++__first;
3849 case 't':
3850 if (__str)
3851 *__str = _CharT(0x9);
3852 else
3853 __push_char(_CharT(0x9));
3854 return ++__first;
3855 case 'v':
3856 if (__str)
3857 *__str = _CharT(0xB);
3858 else
3859 __push_char(_CharT(0xB));
3860 return ++__first;
3861 }
3862 if ('0' <= *__first && *__first <= '7')
3863 {
3864 unsigned __val = *__first - '0';
3865 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3866 {
3867 __val = 8 * __val + *__first - '0';
3868 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3869 __val = 8 * __val + *__first - '0';
3870 }
3871 if (__str)
3872 *__str = _CharT(__val);
3873 else
3874 __push_char(_CharT(__val));
3875 }
Howard Hinnantd4444702010-08-11 17:04:31 +00003876#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003877 else
3878 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00003879#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003880 return __first;
3881}
3882
3883template <class _CharT, class _Traits>
3884template <class _ForwardIterator>
3885_ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00003886basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003887 _ForwardIterator __last,
3888 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003889{
3890 // Found [=
3891 // This means =] must exist
3892 value_type _Equal_close[2] = {'=', ']'};
3893 _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close,
3894 _Equal_close+2);
Howard Hinnantd4444702010-08-11 17:04:31 +00003895#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003896 if (__temp == __last)
3897 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003898#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003899 // [__first, __temp) contains all text in [= ... =]
3900 typedef typename _Traits::string_type string_type;
3901 string_type __collate_name =
3902 __traits_.lookup_collatename(__first, __temp);
Howard Hinnantd4444702010-08-11 17:04:31 +00003903#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003904 if (__collate_name.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003905 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00003906#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003907 string_type __equiv_name =
3908 __traits_.transform_primary(__collate_name.begin(),
3909 __collate_name.end());
3910 if (!__equiv_name.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003911 __ml->__add_equivalence(__equiv_name);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003912 else
Howard Hinnant173968a2010-07-13 21:48:06 +00003913 {
3914 switch (__collate_name.size())
3915 {
3916 case 1:
3917 __ml->__add_char(__collate_name[0]);
3918 break;
3919 case 2:
3920 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
3921 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00003922#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003923 default:
3924 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00003925#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003926 }
3927 }
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003928 __first = _STD::next(__temp, 2);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003929 return __first;
3930}
3931
3932template <class _CharT, class _Traits>
3933template <class _ForwardIterator>
3934_ForwardIterator
3935basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003936 _ForwardIterator __last,
3937 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003938{
3939 // Found [:
3940 // This means :] must exist
3941 value_type _Colon_close[2] = {':', ']'};
3942 _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close,
3943 _Colon_close+2);
Howard Hinnantd4444702010-08-11 17:04:31 +00003944#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003945 if (__temp == __last)
3946 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003947#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003948 // [__first, __temp) contains all text in [: ... :]
3949 typedef typename _Traits::char_class_type char_class_type;
3950 char_class_type __class_type =
3951 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
Howard Hinnantd4444702010-08-11 17:04:31 +00003952#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003953 if (__class_type == 0)
3954 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003955#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003956 __ml->__add_class(__class_type);
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003957 __first = _STD::next(__temp, 2);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003958 return __first;
3959}
3960
3961template <class _CharT, class _Traits>
3962template <class _ForwardIterator>
3963_ForwardIterator
3964basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003965 _ForwardIterator __last,
3966 basic_string<_CharT>& __col_sym)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003967{
3968 // Found [.
3969 // This means .] must exist
3970 value_type _Dot_close[2] = {'.', ']'};
3971 _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close,
3972 _Dot_close+2);
Howard Hinnantd4444702010-08-11 17:04:31 +00003973#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003974 if (__temp == __last)
3975 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003976#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003977 // [__first, __temp) contains all text in [. ... .]
3978 typedef typename _Traits::string_type string_type;
Howard Hinnant173968a2010-07-13 21:48:06 +00003979 __col_sym = __traits_.lookup_collatename(__first, __temp);
3980 switch (__col_sym.size())
3981 {
3982 case 1:
3983 case 2:
3984 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00003985#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003986 default:
3987 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00003988#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003989 }
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00003990 __first = _STD::next(__temp, 2);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003991 return __first;
3992}
3993
3994template <class _CharT, class _Traits>
3995template <class _ForwardIterator>
3996_ForwardIterator
3997basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
3998 _ForwardIterator __last,
3999 int& __c)
4000{
4001 if (__first != __last && '0' <= *__first && *__first <= '9')
4002 {
4003 __c = *__first - '0';
4004 for (++__first; __first != __last && '0' <= *__first && *__first <= '9';
4005 ++__first)
4006 {
4007 __c *= 10;
4008 __c += *__first - '0';
4009 }
4010 }
4011 return __first;
4012}
4013
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004014template <class _CharT, class _Traits>
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004015template <class _ForwardIterator>
4016_ForwardIterator
4017basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
4018 _ForwardIterator __last)
4019{
4020 __owns_one_state<_CharT>* __sa = __end_;
4021 _ForwardIterator __temp = __parse_alternative(__first, __last);
4022 if (__temp == __first)
4023 __push_empty();
4024 __first = __temp;
4025 while (__first != __last && *__first == '|')
4026 {
4027 __owns_one_state<_CharT>* __sb = __end_;
4028 __temp = __parse_alternative(++__first, __last);
4029 if (__temp == __first)
4030 __push_empty();
4031 __push_alternation(__sa, __sb);
4032 __first = __temp;
4033 }
4034 return __first;
4035}
4036
4037template <class _CharT, class _Traits>
4038template <class _ForwardIterator>
4039_ForwardIterator
4040basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
4041 _ForwardIterator __last)
4042{
4043 while (true)
4044 {
4045 _ForwardIterator __temp = __parse_term(__first, __last);
4046 if (__temp == __first)
4047 break;
4048 __first = __temp;
4049 }
4050 return __first;
4051}
4052
4053template <class _CharT, class _Traits>
4054template <class _ForwardIterator>
4055_ForwardIterator
4056basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
4057 _ForwardIterator __last)
4058{
4059 _ForwardIterator __temp = __parse_assertion(__first, __last);
4060 if (__temp == __first)
4061 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004062 __owns_one_state<_CharT>* __e = __end_;
4063 unsigned __mexp_begin = __marked_count_;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004064 __temp = __parse_atom(__first, __last);
4065 if (__temp != __first)
Howard Hinnant17615b02010-07-27 01:25:38 +00004066 __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
4067 __mexp_begin+1, __marked_count_+1);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004068 }
Howard Hinnant17615b02010-07-27 01:25:38 +00004069 else
4070 __first = __temp;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004071 return __first;
4072}
4073
4074template <class _CharT, class _Traits>
4075template <class _ForwardIterator>
4076_ForwardIterator
4077basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
4078 _ForwardIterator __last)
4079{
4080 if (__first != __last)
4081 {
4082 switch (*__first)
4083 {
4084 case '^':
4085 __push_l_anchor();
4086 ++__first;
4087 break;
4088 case '$':
4089 __push_r_anchor();
4090 ++__first;
4091 break;
4092 case '\\':
4093 {
4094 _ForwardIterator __temp = _STD::next(__first);
4095 if (__temp != __last)
4096 {
4097 if (*__temp == 'b')
4098 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004099 __push_word_boundary(false);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004100 __first = ++__temp;
4101 }
4102 else if (*__temp == 'B')
4103 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004104 __push_word_boundary(true);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004105 __first = ++__temp;
4106 }
4107 }
4108 }
4109 break;
4110 case '(':
4111 {
4112 _ForwardIterator __temp = _STD::next(__first);
4113 if (__temp != __last && *__temp == '?')
4114 {
4115 if (++__temp != __last)
4116 {
4117 switch (*__temp)
4118 {
4119 case '=':
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004120 {
4121 basic_regex __exp;
4122 __exp.__flags_ = __flags_;
4123 __temp = __exp.__parse(++__temp, __last);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004124 __push_lookahead(_STD::move(__exp), false);
Howard Hinnantd4444702010-08-11 17:04:31 +00004125#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004126 if (__temp == __last || *__temp != ')')
4127 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004128#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004129 __first = ++__temp;
4130 }
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004131 break;
4132 case '!':
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004133 {
4134 basic_regex __exp;
4135 __exp.__flags_ = __flags_;
4136 __temp = __exp.__parse(++__temp, __last);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004137 __push_lookahead(_STD::move(__exp), true);
Howard Hinnantd4444702010-08-11 17:04:31 +00004138#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004139 if (__temp == __last || *__temp != ')')
4140 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004141#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004142 __first = ++__temp;
4143 }
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004144 break;
4145 }
4146 }
4147 }
4148 }
4149 break;
4150 }
4151 }
4152 return __first;
4153}
4154
4155template <class _CharT, class _Traits>
4156template <class _ForwardIterator>
4157_ForwardIterator
4158basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
4159 _ForwardIterator __last)
4160{
Howard Hinnant17615b02010-07-27 01:25:38 +00004161 if (__first != __last)
4162 {
4163 switch (*__first)
4164 {
4165 case '.':
4166 __push_match_any_but_newline();
4167 ++__first;
4168 break;
4169 case '\\':
4170 __first = __parse_atom_escape(__first, __last);
4171 break;
4172 case '[':
4173 __first = __parse_bracket_expression(__first, __last);
4174 break;
4175 case '(':
4176 {
Howard Hinnantd4444702010-08-11 17:04:31 +00004177 ++__first;
4178#ifndef _LIBCPP_NO_EXCEPTIONS
4179 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004180 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004181#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004182 _ForwardIterator __temp = _STD::next(__first);
4183 if (__temp != __last && *__first == '?' && *__temp == ':')
4184 {
4185 ++__open_count_;
4186 __first = __parse_ecma_exp(++__temp, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00004187#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004188 if (__first == __last || *__first != ')')
4189 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004190#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004191 --__open_count_;
4192 ++__first;
4193 }
4194 else
4195 {
4196 __push_begin_marked_subexpression();
4197 unsigned __temp_count = __marked_count_;
4198 ++__open_count_;
4199 __first = __parse_ecma_exp(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00004200#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004201 if (__first == __last || *__first != ')')
4202 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004203#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004204 __push_end_marked_subexpression(__temp_count);
4205 --__open_count_;
4206 ++__first;
4207 }
4208 }
4209 break;
4210 default:
4211 __first = __parse_pattern_character(__first, __last);
4212 break;
4213 }
4214 }
4215 return __first;
4216}
4217
4218template <class _CharT, class _Traits>
4219template <class _ForwardIterator>
4220_ForwardIterator
4221basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
4222 _ForwardIterator __last)
4223{
4224 if (__first != __last && *__first == '\\')
4225 {
4226 _ForwardIterator __t1 = _STD::next(__first);
4227 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
4228 if (__t2 != __t1)
4229 __first = __t2;
4230 else
4231 {
4232 __t2 = __parse_character_class_escape(__t1, __last);
4233 if (__t2 != __t1)
4234 __first = __t2;
4235 else
4236 {
4237 __t2 = __parse_character_escape(__t1, __last);
4238 if (__t2 != __t1)
4239 __first = __t2;
4240 }
4241 }
4242 }
4243 return __first;
4244}
4245
4246template <class _CharT, class _Traits>
4247template <class _ForwardIterator>
4248_ForwardIterator
4249basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
4250 _ForwardIterator __last)
4251{
4252 if (__first != __last)
4253 {
4254 if (*__first == '0')
4255 {
4256 __push_char(_CharT());
4257 ++__first;
4258 }
4259 else if ('1' <= *__first && *__first <= '9')
4260 {
4261 unsigned __v = *__first - '0';
4262 for (++__first; '0' <= *__first && *__first <= '9'; ++__first)
4263 __v = 10 * __v + *__first - '0';
Howard Hinnantd4444702010-08-11 17:04:31 +00004264#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004265 if (__v > mark_count())
4266 throw regex_error(regex_constants::error_backref);
Howard Hinnant324bb032010-08-22 00:02:43 +00004267#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004268 __push_back_ref(__v);
4269 }
4270 }
4271 return __first;
4272}
4273
4274template <class _CharT, class _Traits>
4275template <class _ForwardIterator>
4276_ForwardIterator
4277basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
4278 _ForwardIterator __last)
4279{
4280 if (__first != __last)
4281 {
4282 __bracket_expression<_CharT, _Traits>* __ml;
4283 switch (*__first)
4284 {
4285 case 'd':
4286 __ml = __start_matching_list(false);
4287 __ml->__add_class(ctype_base::digit);
4288 ++__first;
4289 break;
4290 case 'D':
4291 __ml = __start_matching_list(true);
4292 __ml->__add_class(ctype_base::digit);
4293 ++__first;
4294 break;
4295 case 's':
4296 __ml = __start_matching_list(false);
4297 __ml->__add_class(ctype_base::space);
4298 ++__first;
4299 break;
4300 case 'S':
4301 __ml = __start_matching_list(true);
4302 __ml->__add_class(ctype_base::space);
4303 ++__first;
4304 break;
4305 case 'w':
4306 __ml = __start_matching_list(false);
4307 __ml->__add_class(ctype_base::alnum);
4308 __ml->__add_char('_');
4309 ++__first;
4310 break;
4311 case 'W':
4312 __ml = __start_matching_list(true);
4313 __ml->__add_class(ctype_base::alnum);
4314 __ml->__add_char('_');
4315 ++__first;
4316 break;
4317 }
4318 }
4319 return __first;
4320}
4321
4322template <class _CharT, class _Traits>
4323template <class _ForwardIterator>
4324_ForwardIterator
4325basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
Howard Hinnant15476f32010-07-28 17:35:27 +00004326 _ForwardIterator __last,
4327 basic_string<_CharT>* __str)
Howard Hinnant17615b02010-07-27 01:25:38 +00004328{
4329 if (__first != __last)
4330 {
4331 _ForwardIterator __t;
4332 unsigned __sum = 0;
4333 int __hd;
4334 switch (*__first)
4335 {
4336 case 'f':
Howard Hinnant15476f32010-07-28 17:35:27 +00004337 if (__str)
4338 *__str = _CharT(0xC);
4339 else
4340 __push_char(_CharT(0xC));
Howard Hinnant17615b02010-07-27 01:25:38 +00004341 ++__first;
4342 break;
4343 case 'n':
Howard Hinnant15476f32010-07-28 17:35:27 +00004344 if (__str)
4345 *__str = _CharT(0xA);
4346 else
4347 __push_char(_CharT(0xA));
Howard Hinnant17615b02010-07-27 01:25:38 +00004348 ++__first;
4349 break;
4350 case 'r':
Howard Hinnant15476f32010-07-28 17:35:27 +00004351 if (__str)
4352 *__str = _CharT(0xD);
4353 else
4354 __push_char(_CharT(0xD));
Howard Hinnant17615b02010-07-27 01:25:38 +00004355 ++__first;
4356 break;
4357 case 't':
Howard Hinnant15476f32010-07-28 17:35:27 +00004358 if (__str)
4359 *__str = _CharT(0x9);
4360 else
4361 __push_char(_CharT(0x9));
Howard Hinnant17615b02010-07-27 01:25:38 +00004362 ++__first;
4363 break;
4364 case 'v':
Howard Hinnant15476f32010-07-28 17:35:27 +00004365 if (__str)
4366 *__str = _CharT(0xB);
4367 else
4368 __push_char(_CharT(0xB));
Howard Hinnant17615b02010-07-27 01:25:38 +00004369 ++__first;
4370 break;
4371 case 'c':
4372 if ((__t = _STD::next(__first)) != __last)
4373 {
4374 if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z')
4375 {
Howard Hinnant15476f32010-07-28 17:35:27 +00004376 if (__str)
4377 *__str = _CharT(*__t % 32);
4378 else
4379 __push_char(_CharT(*__t % 32));
Howard Hinnant17615b02010-07-27 01:25:38 +00004380 __first = ++__t;
4381 }
4382 }
4383 break;
4384 case 'u':
Howard Hinnantd4444702010-08-11 17:04:31 +00004385 ++__first;
4386#ifndef _LIBCPP_NO_EXCEPTIONS
4387 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004388 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004389#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004390 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004391#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004392 if (__hd == -1)
4393 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004394#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004395 __sum = 16 * __sum + __hd;
Howard Hinnantd4444702010-08-11 17:04:31 +00004396 ++__first;
4397#ifndef _LIBCPP_NO_EXCEPTIONS
4398 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004399 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004400#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004401 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004402#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004403 if (__hd == -1)
4404 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004405#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004406 __sum = 16 * __sum + __hd;
4407 // drop through
4408 case 'x':
Howard Hinnantd4444702010-08-11 17:04:31 +00004409 ++__first;
4410#ifndef _LIBCPP_NO_EXCEPTIONS
4411 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004412 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004413#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004414 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004415#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004416 if (__hd == -1)
4417 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004418#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004419 __sum = 16 * __sum + __hd;
Howard Hinnantd4444702010-08-11 17:04:31 +00004420 ++__first;
4421#ifndef _LIBCPP_NO_EXCEPTIONS
4422 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004423 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004424#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004425 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004426#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004427 if (__hd == -1)
4428 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004429#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004430 __sum = 16 * __sum + __hd;
Howard Hinnant15476f32010-07-28 17:35:27 +00004431 if (__str)
4432 *__str = _CharT(__sum);
4433 else
4434 __push_char(_CharT(__sum));
Howard Hinnant17615b02010-07-27 01:25:38 +00004435 ++__first;
4436 break;
4437 default:
4438 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
4439 {
Howard Hinnant15476f32010-07-28 17:35:27 +00004440 if (__str)
4441 *__str = *__first;
4442 else
4443 __push_char(*__first);
Howard Hinnant17615b02010-07-27 01:25:38 +00004444 ++__first;
4445 }
Howard Hinnantd4444702010-08-11 17:04:31 +00004446#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00004447 else if (__str)
4448 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004449#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004450 break;
4451 }
4452 }
4453 return __first;
4454}
4455
4456template <class _CharT, class _Traits>
4457template <class _ForwardIterator>
4458_ForwardIterator
4459basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
4460 _ForwardIterator __last)
4461{
4462 if (__first != __last)
4463 {
4464 switch (*__first)
4465 {
4466 case '^':
4467 case '$':
4468 case '\\':
4469 case '.':
4470 case '*':
4471 case '+':
4472 case '?':
4473 case '(':
4474 case ')':
4475 case '[':
4476 case ']':
4477 case '{':
4478 case '}':
4479 case '|':
4480 break;
4481 default:
4482 __push_char(*__first);
4483 ++__first;
4484 break;
4485 }
4486 }
4487 return __first;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004488}
4489
4490template <class _CharT, class _Traits>
Howard Hinnant856846b2010-07-27 19:53:10 +00004491template <class _ForwardIterator>
4492_ForwardIterator
4493basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
4494 _ForwardIterator __last)
4495{
4496 __owns_one_state<_CharT>* __sa = __end_;
4497 _ForwardIterator __t1 = _STD::find(__first, __last, _CharT('\n'));
4498 if (__t1 != __first)
4499 __parse_basic_reg_exp(__first, __t1);
4500 else
4501 __push_empty();
4502 __first = __t1;
4503 if (__first != __last)
4504 ++__first;
4505 while (__first != __last)
4506 {
4507 __t1 = _STD::find(__first, __last, _CharT('\n'));
4508 __owns_one_state<_CharT>* __sb = __end_;
4509 if (__t1 != __first)
4510 __parse_basic_reg_exp(__first, __t1);
4511 else
4512 __push_empty();
4513 __push_alternation(__sa, __sb);
4514 __first = __t1;
4515 if (__first != __last)
4516 ++__first;
4517 }
4518 return __first;
4519}
4520
4521template <class _CharT, class _Traits>
4522template <class _ForwardIterator>
4523_ForwardIterator
4524basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
4525 _ForwardIterator __last)
4526{
4527 __owns_one_state<_CharT>* __sa = __end_;
4528 _ForwardIterator __t1 = _STD::find(__first, __last, _CharT('\n'));
4529 if (__t1 != __first)
4530 __parse_extended_reg_exp(__first, __t1);
4531 else
4532 __push_empty();
4533 __first = __t1;
4534 if (__first != __last)
4535 ++__first;
4536 while (__first != __last)
4537 {
4538 __t1 = _STD::find(__first, __last, _CharT('\n'));
4539 __owns_one_state<_CharT>* __sb = __end_;
4540 if (__t1 != __first)
4541 __parse_extended_reg_exp(__first, __t1);
4542 else
4543 __push_empty();
4544 __push_alternation(__sa, __sb);
4545 __first = __t1;
4546 if (__first != __last)
4547 ++__first;
4548 }
4549 return __first;
4550}
4551
4552template <class _CharT, class _Traits>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004553void
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004554basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
4555 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
4556 bool __greedy)
4557{
4558 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4559 __end_->first() = nullptr;
Howard Hinnantac303862010-07-12 15:51:17 +00004560 unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
4561 __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
4562 __min, __max));
4563 __s->first() = nullptr;
4564 __e1.release();
4565 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004566 __end_ = __e2->second();
Howard Hinnantac303862010-07-12 15:51:17 +00004567 __s->first() = __e2.release();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004568 ++__loop_count_;
4569}
4570
4571template <class _CharT, class _Traits>
4572void
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004573basic_regex<_CharT, _Traits>::__push_char(value_type __c)
4574{
Howard Hinnant173968a2010-07-13 21:48:06 +00004575 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004576 __end_->first() = new __match_char_icase<_CharT, _Traits>
4577 (__traits_, __c, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004578 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004579 __end_->first() = new __match_char_collate<_CharT, _Traits>
4580 (__traits_, __c, __end_->first());
4581 else
4582 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
Howard Hinnante77aa5e2010-07-08 17:43:58 +00004583 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004584}
4585
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004586template <class _CharT, class _Traits>
4587void
4588basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
4589{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004590 if (!(__flags_ & nosubs))
4591 {
4592 __end_->first() =
4593 new __begin_marked_subexpression<_CharT>(++__marked_count_,
4594 __end_->first());
4595 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4596 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004597}
4598
4599template <class _CharT, class _Traits>
4600void
4601basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
4602{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004603 if (!(__flags_ & nosubs))
4604 {
4605 __end_->first() =
4606 new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4607 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4608 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004609}
4610
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004611template <class _CharT, class _Traits>
4612void
Howard Hinnant41fb6e12011-03-26 20:02:27 +00004613basic_regex<_CharT, _Traits>::__push_l_anchor()
4614{
4615 __end_->first() = new __l_anchor<_CharT>(__end_->first());
4616 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4617}
4618
4619template <class _CharT, class _Traits>
4620void
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004621basic_regex<_CharT, _Traits>::__push_r_anchor()
4622{
4623 __end_->first() = new __r_anchor<_CharT>(__end_->first());
4624 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4625}
4626
Howard Hinnantac303862010-07-12 15:51:17 +00004627template <class _CharT, class _Traits>
4628void
4629basic_regex<_CharT, _Traits>::__push_match_any()
4630{
4631 __end_->first() = new __match_any<_CharT>(__end_->first());
4632 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4633}
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004634
Howard Hinnantcba352d2010-07-12 18:16:05 +00004635template <class _CharT, class _Traits>
4636void
Howard Hinnant17615b02010-07-27 01:25:38 +00004637basic_regex<_CharT, _Traits>::__push_match_any_but_newline()
4638{
4639 __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
4640 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4641}
4642
4643template <class _CharT, class _Traits>
4644void
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004645basic_regex<_CharT, _Traits>::__push_empty()
4646{
4647 __end_->first() = new __empty_state<_CharT>(__end_->first());
4648 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4649}
4650
4651template <class _CharT, class _Traits>
4652void
Howard Hinnant17615b02010-07-27 01:25:38 +00004653basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
4654{
4655 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
4656 __end_->first());
4657 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4658}
4659
4660template <class _CharT, class _Traits>
4661void
Howard Hinnantcba352d2010-07-12 18:16:05 +00004662basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
4663{
Howard Hinnant173968a2010-07-13 21:48:06 +00004664 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004665 __end_->first() = new __back_ref_icase<_CharT, _Traits>
4666 (__traits_, __i, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004667 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004668 __end_->first() = new __back_ref_collate<_CharT, _Traits>
4669 (__traits_, __i, __end_->first());
4670 else
4671 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
Howard Hinnantcba352d2010-07-12 18:16:05 +00004672 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4673}
4674
Howard Hinnant173968a2010-07-13 21:48:06 +00004675template <class _CharT, class _Traits>
Howard Hinnantaa698082010-07-16 19:08:36 +00004676void
4677basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
4678 __owns_one_state<_CharT>* __ea)
4679{
4680 __sa->first() = new __alternate<_CharT>(
4681 static_cast<__owns_one_state<_CharT>*>(__sa->first()),
4682 static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4683 __ea->first() = nullptr;
4684 __ea->first() = new __empty_state<_CharT>(__end_->first());
4685 __end_->first() = nullptr;
4686 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4687 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4688}
4689
4690template <class _CharT, class _Traits>
Howard Hinnant173968a2010-07-13 21:48:06 +00004691__bracket_expression<_CharT, _Traits>*
4692basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
4693{
4694 __bracket_expression<_CharT, _Traits>* __r =
4695 new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
4696 __negate, __flags_ & icase,
4697 __flags_ & collate);
4698 __end_->first() = __r;
4699 __end_ = __r;
4700 return __r;
4701}
4702
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004703template <class _CharT, class _Traits>
4704void
4705basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
4706 bool __invert)
4707{
4708 __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
4709 __end_->first());
4710 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4711}
4712
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00004713typedef basic_regex<char> regex;
4714typedef basic_regex<wchar_t> wregex;
4715
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004716// sub_match
4717
4718template <class _BidirectionalIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004719class _LIBCPP_VISIBLE sub_match
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004720 : public pair<_BidirectionalIterator, _BidirectionalIterator>
4721{
4722public:
4723 typedef _BidirectionalIterator iterator;
4724 typedef typename iterator_traits<iterator>::value_type value_type;
4725 typedef typename iterator_traits<iterator>::difference_type difference_type;
4726 typedef basic_string<value_type> string_type;
4727
4728 bool matched;
4729
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004730 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant31aaf552010-12-08 21:07:55 +00004731 /*constexpr*/ sub_match() : matched() {}
4732
4733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004734 difference_type length() const
4735 {return matched ? _STD::distance(this->first, this->second) : 0;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004736 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004737 string_type str() const
4738 {return matched ? string_type(this->first, this->second) : string_type();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004739 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004740 operator string_type() const
4741 {return str();}
4742
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004743 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004744 int compare(const sub_match& __s) const
4745 {return str().compare(__s.str());}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004746 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004747 int compare(const string_type& __s) const
4748 {return str().compare(__s);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004749 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004750 int compare(const value_type* __s) const
4751 {return str().compare(__s);}
4752};
4753
4754typedef sub_match<const char*> csub_match;
4755typedef sub_match<const wchar_t*> wcsub_match;
4756typedef sub_match<string::const_iterator> ssub_match;
4757typedef sub_match<wstring::const_iterator> wssub_match;
4758
4759template <class _BiIter>
4760inline _LIBCPP_INLINE_VISIBILITY
4761bool
4762operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4763{
4764 return __x.compare(__y) == 0;
4765}
4766
4767template <class _BiIter>
4768inline _LIBCPP_INLINE_VISIBILITY
4769bool
4770operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4771{
4772 return !(__x == __y);
4773}
4774
4775template <class _BiIter>
4776inline _LIBCPP_INLINE_VISIBILITY
4777bool
4778operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4779{
4780 return __x.compare(__y) < 0;
4781}
4782
4783template <class _BiIter>
4784inline _LIBCPP_INLINE_VISIBILITY
4785bool
4786operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4787{
4788 return !(__y < __x);
4789}
4790
4791template <class _BiIter>
4792inline _LIBCPP_INLINE_VISIBILITY
4793bool
4794operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4795{
4796 return !(__x < __y);
4797}
4798
4799template <class _BiIter>
4800inline _LIBCPP_INLINE_VISIBILITY
4801bool
4802operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4803{
4804 return __y < __x;
4805}
4806
4807template <class _BiIter, class _ST, class _SA>
4808inline _LIBCPP_INLINE_VISIBILITY
4809bool
4810operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4811 const sub_match<_BiIter>& __y)
4812{
4813 return __y.compare(__x.c_str()) == 0;
4814}
4815
4816template <class _BiIter, class _ST, class _SA>
4817inline _LIBCPP_INLINE_VISIBILITY
4818bool
4819operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4820 const sub_match<_BiIter>& __y)
4821{
4822 return !(__x == __y);
4823}
4824
4825template <class _BiIter, class _ST, class _SA>
4826inline _LIBCPP_INLINE_VISIBILITY
4827bool
4828operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4829 const sub_match<_BiIter>& __y)
4830{
4831 return __y.compare(__x.c_str()) > 0;
4832}
4833
4834template <class _BiIter, class _ST, class _SA>
4835inline _LIBCPP_INLINE_VISIBILITY
4836bool
4837operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4838 const sub_match<_BiIter>& __y)
4839{
4840 return __y < __x;
4841}
4842
4843template <class _BiIter, class _ST, class _SA>
4844inline _LIBCPP_INLINE_VISIBILITY
4845bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4846 const sub_match<_BiIter>& __y)
4847{
4848 return !(__x < __y);
4849}
4850
4851template <class _BiIter, class _ST, class _SA>
4852inline _LIBCPP_INLINE_VISIBILITY
4853bool
4854operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4855 const sub_match<_BiIter>& __y)
4856{
4857 return !(__y < __x);
4858}
4859
4860template <class _BiIter, class _ST, class _SA>
4861inline _LIBCPP_INLINE_VISIBILITY
4862bool
4863operator==(const sub_match<_BiIter>& __x,
4864 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4865{
4866 return __x.compare(__y.c_str()) == 0;
4867}
4868
4869template <class _BiIter, class _ST, class _SA>
4870inline _LIBCPP_INLINE_VISIBILITY
4871bool
4872operator!=(const sub_match<_BiIter>& __x,
4873 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4874{
4875 return !(__x == __y);
4876}
4877
4878template <class _BiIter, class _ST, class _SA>
4879inline _LIBCPP_INLINE_VISIBILITY
4880bool
4881operator<(const sub_match<_BiIter>& __x,
4882 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4883{
4884 return __x.compare(__y.c_str()) < 0;
4885}
4886
4887template <class _BiIter, class _ST, class _SA>
4888inline _LIBCPP_INLINE_VISIBILITY
4889bool operator>(const sub_match<_BiIter>& __x,
4890 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4891{
4892 return __y < __x;
4893}
4894
4895template <class _BiIter, class _ST, class _SA>
4896inline _LIBCPP_INLINE_VISIBILITY
4897bool
4898operator>=(const sub_match<_BiIter>& __x,
4899 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4900{
4901 return !(__x < __y);
4902}
4903
4904template <class _BiIter, class _ST, class _SA>
4905inline _LIBCPP_INLINE_VISIBILITY
4906bool
4907operator<=(const sub_match<_BiIter>& __x,
4908 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4909{
4910 return !(__y < __x);
4911}
4912
4913template <class _BiIter>
4914inline _LIBCPP_INLINE_VISIBILITY
4915bool
4916operator==(typename iterator_traits<_BiIter>::value_type const* __x,
4917 const sub_match<_BiIter>& __y)
4918{
4919 return __y.compare(__x) == 0;
4920}
4921
4922template <class _BiIter>
4923inline _LIBCPP_INLINE_VISIBILITY
4924bool
4925operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
4926 const sub_match<_BiIter>& __y)
4927{
4928 return !(__x == __y);
4929}
4930
4931template <class _BiIter>
4932inline _LIBCPP_INLINE_VISIBILITY
4933bool
4934operator<(typename iterator_traits<_BiIter>::value_type const* __x,
4935 const sub_match<_BiIter>& __y)
4936{
4937 return __y.compare(__x) > 0;
4938}
4939
4940template <class _BiIter>
4941inline _LIBCPP_INLINE_VISIBILITY
4942bool
4943operator>(typename iterator_traits<_BiIter>::value_type const* __x,
4944 const sub_match<_BiIter>& __y)
4945{
4946 return __y < __x;
4947}
4948
4949template <class _BiIter>
4950inline _LIBCPP_INLINE_VISIBILITY
4951bool
4952operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
4953 const sub_match<_BiIter>& __y)
4954{
4955 return !(__x < __y);
4956}
4957
4958template <class _BiIter>
4959inline _LIBCPP_INLINE_VISIBILITY
4960bool
4961operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
4962 const sub_match<_BiIter>& __y)
4963{
4964 return !(__y < __x);
4965}
4966
4967template <class _BiIter>
4968inline _LIBCPP_INLINE_VISIBILITY
4969bool
4970operator==(const sub_match<_BiIter>& __x,
4971 typename iterator_traits<_BiIter>::value_type const* __y)
4972{
4973 return __x.compare(__y) == 0;
4974}
4975
4976template <class _BiIter>
4977inline _LIBCPP_INLINE_VISIBILITY
4978bool
4979operator!=(const sub_match<_BiIter>& __x,
4980 typename iterator_traits<_BiIter>::value_type const* __y)
4981{
4982 return !(__x == __y);
4983}
4984
4985template <class _BiIter>
4986inline _LIBCPP_INLINE_VISIBILITY
4987bool
4988operator<(const sub_match<_BiIter>& __x,
4989 typename iterator_traits<_BiIter>::value_type const* __y)
4990{
4991 return __x.compare(__y) < 0;
4992}
4993
4994template <class _BiIter>
4995inline _LIBCPP_INLINE_VISIBILITY
4996bool
4997operator>(const sub_match<_BiIter>& __x,
4998 typename iterator_traits<_BiIter>::value_type const* __y)
4999{
5000 return __y < __x;
5001}
5002
5003template <class _BiIter>
5004inline _LIBCPP_INLINE_VISIBILITY
5005bool
5006operator>=(const sub_match<_BiIter>& __x,
5007 typename iterator_traits<_BiIter>::value_type const* __y)
5008{
5009 return !(__x < __y);
5010}
5011
5012template <class _BiIter>
5013inline _LIBCPP_INLINE_VISIBILITY
5014bool
5015operator<=(const sub_match<_BiIter>& __x,
5016 typename iterator_traits<_BiIter>::value_type const* __y)
5017{
5018 return !(__y < __x);
5019}
5020
5021template <class _BiIter>
5022inline _LIBCPP_INLINE_VISIBILITY
5023bool
5024operator==(typename iterator_traits<_BiIter>::value_type const& __x,
5025 const sub_match<_BiIter>& __y)
5026{
5027 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5028 return __y.compare(string_type(1, __x)) == 0;
5029}
5030
5031template <class _BiIter>
5032inline _LIBCPP_INLINE_VISIBILITY
5033bool
5034operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
5035 const sub_match<_BiIter>& __y)
5036{
5037 return !(__x == __y);
5038}
5039
5040template <class _BiIter>
5041inline _LIBCPP_INLINE_VISIBILITY
5042bool
5043operator<(typename iterator_traits<_BiIter>::value_type const& __x,
5044 const sub_match<_BiIter>& __y)
5045{
5046 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5047 return __y.compare(string_type(1, __x)) > 0;
5048}
5049
5050template <class _BiIter>
5051inline _LIBCPP_INLINE_VISIBILITY
5052bool
5053operator>(typename iterator_traits<_BiIter>::value_type const& __x,
5054 const sub_match<_BiIter>& __y)
5055{
5056 return __y < __x;
5057}
5058
5059template <class _BiIter>
5060inline _LIBCPP_INLINE_VISIBILITY
5061bool
5062operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
5063 const sub_match<_BiIter>& __y)
5064{
5065 return !(__x < __y);
5066}
5067
5068template <class _BiIter>
5069inline _LIBCPP_INLINE_VISIBILITY
5070bool
5071operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
5072 const sub_match<_BiIter>& __y)
5073{
5074 return !(__y < __x);
5075}
5076
5077template <class _BiIter>
5078inline _LIBCPP_INLINE_VISIBILITY
5079bool
5080operator==(const sub_match<_BiIter>& __x,
5081 typename iterator_traits<_BiIter>::value_type const& __y)
5082{
5083 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5084 return __x.compare(string_type(1, __y)) == 0;
5085}
5086
5087template <class _BiIter>
5088inline _LIBCPP_INLINE_VISIBILITY
5089bool
5090operator!=(const sub_match<_BiIter>& __x,
5091 typename iterator_traits<_BiIter>::value_type const& __y)
5092{
5093 return !(__x == __y);
5094}
5095
5096template <class _BiIter>
5097inline _LIBCPP_INLINE_VISIBILITY
5098bool
5099operator<(const sub_match<_BiIter>& __x,
5100 typename iterator_traits<_BiIter>::value_type const& __y)
5101{
5102 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5103 return __x.compare(string_type(1, __y)) < 0;
5104}
5105
5106template <class _BiIter>
5107inline _LIBCPP_INLINE_VISIBILITY
5108bool
5109operator>(const sub_match<_BiIter>& __x,
5110 typename iterator_traits<_BiIter>::value_type const& __y)
5111{
5112 return __y < __x;
5113}
5114
5115template <class _BiIter>
5116inline _LIBCPP_INLINE_VISIBILITY
5117bool
5118operator>=(const sub_match<_BiIter>& __x,
5119 typename iterator_traits<_BiIter>::value_type const& __y)
5120{
5121 return !(__x < __y);
5122}
5123
5124template <class _BiIter>
5125inline _LIBCPP_INLINE_VISIBILITY
5126bool
5127operator<=(const sub_match<_BiIter>& __x,
5128 typename iterator_traits<_BiIter>::value_type const& __y)
5129{
5130 return !(__y < __x);
5131}
5132
5133template <class _CharT, class _ST, class _BiIter>
5134inline _LIBCPP_INLINE_VISIBILITY
5135basic_ostream<_CharT, _ST>&
5136operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
5137{
5138 return __os << __m.str();
5139}
5140
Howard Hinnant17615b02010-07-27 01:25:38 +00005141template <class _BidirectionalIterator, class _Allocator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005142class _LIBCPP_VISIBLE match_results
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005143{
5144public:
5145 typedef _Allocator allocator_type;
5146 typedef sub_match<_BidirectionalIterator> value_type;
5147private:
5148 typedef vector<value_type, allocator_type> __container_type;
5149
5150 __container_type __matches_;
5151 value_type __unmatched_;
5152 value_type __prefix_;
5153 value_type __suffix_;
Howard Hinnant31aaf552010-12-08 21:07:55 +00005154 bool __ready_;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005155public:
Howard Hinnanta712c722010-08-16 20:21:16 +00005156 _BidirectionalIterator __position_start_;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005157 typedef const value_type& const_reference;
5158 typedef const_reference reference;
5159 typedef typename __container_type::const_iterator const_iterator;
5160 typedef const_iterator iterator;
5161 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
5162 typedef typename allocator_traits<allocator_type>::size_type size_type;
5163 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
5164 typedef basic_string<char_type> string_type;
5165
5166 // construct/copy/destroy:
5167 explicit match_results(const allocator_type& __a = allocator_type());
5168// match_results(const match_results&) = default;
5169// match_results& operator=(const match_results&) = default;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005170// match_results(match_results&& __m) = default;
5171// match_results& operator=(match_results&& __m) = default;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005172// ~match_results() = default;
5173
Howard Hinnant31aaf552010-12-08 21:07:55 +00005174 _LIBCPP_INLINE_VISIBILITY
5175 bool ready() const {return __ready_;}
5176
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005177 // size:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005178 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005179 size_type size() const {return __matches_.size();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005181 size_type max_size() const {return __matches_.max_size();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005182 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005183 bool empty() const {return size() == 0;}
5184
5185 // element access:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005187 difference_type length(size_type __sub = 0) const
5188 {return (*this)[__sub].length();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005189 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005190 difference_type position(size_type __sub = 0) const
Howard Hinnanta712c722010-08-16 20:21:16 +00005191 {return _STD::distance(__position_start_, (*this)[__sub].first);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005192 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005193 string_type str(size_type __sub = 0) const
5194 {return (*this)[__sub].str();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005195 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005196 const_reference operator[](size_type __n) const
5197 {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
5198
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005199 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005200 const_reference prefix() const {return __prefix_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005201 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005202 const_reference suffix() const {return __suffix_;}
5203
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005205 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005207 const_iterator end() const {return __matches_.end();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005209 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005210 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005211 const_iterator cend() const {return __matches_.end();}
5212
5213 // format:
5214 template <class _OutputIter>
5215 _OutputIter
5216 format(_OutputIter __out, const char_type* __fmt_first,
5217 const char_type* __fmt_last,
5218 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
5219 template <class _OutputIter, class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005221 _OutputIter
5222 format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005223 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5224 {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005225 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005226 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005227 basic_string<char_type, _ST, _SA>
5228 format(const basic_string<char_type, _ST, _SA>& __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005229 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5230 {
5231 basic_string<char_type, _ST, _SA> __r;
5232 format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
5233 __flags);
5234 return __r;
5235 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005237 string_type
5238 format(const char_type* __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005239 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5240 {
5241 string_type __r;
5242 format(back_inserter(__r), __fmt,
5243 __fmt + char_traits<char_type>::length(__fmt), __flags);
5244 return __r;
5245 }
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005246
5247 // allocator:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005249 allocator_type get_allocator() const {return __matches_.get_allocator();}
5250
5251 // swap:
5252 void swap(match_results& __m);
5253
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005254 template <class _B, class _A>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005256 void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
Howard Hinnanta712c722010-08-16 20:21:16 +00005257 const match_results<_B, _A>& __m, bool __no_update_pos)
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005258 {
5259 _B __mf = __m.prefix().first;
5260 __matches_.resize(__m.size());
5261 for (size_type __i = 0; __i < __matches_.size(); ++__i)
5262 {
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00005263 __matches_[__i].first = _STD::next(__f, _STD::distance(__mf, __m[__i].first));
5264 __matches_[__i].second = _STD::next(__f, _STD::distance(__mf, __m[__i].second));
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005265 __matches_[__i].matched = __m[__i].matched;
5266 }
5267 __unmatched_.first = __l;
5268 __unmatched_.second = __l;
5269 __unmatched_.matched = false;
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00005270 __prefix_.first = _STD::next(__f, _STD::distance(__mf, __m.prefix().first));
5271 __prefix_.second = _STD::next(__f, _STD::distance(__mf, __m.prefix().second));
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005272 __prefix_.matched = __m.prefix().matched;
Howard Hinnant6cf5d8c2011-02-14 19:12:38 +00005273 __suffix_.first = _STD::next(__f, _STD::distance(__mf, __m.suffix().first));
5274 __suffix_.second = _STD::next(__f, _STD::distance(__mf, __m.suffix().second));
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005275 __suffix_.matched = __m.suffix().matched;
Howard Hinnanta712c722010-08-16 20:21:16 +00005276 if (!__no_update_pos)
5277 __position_start_ = __prefix_.first;
Howard Hinnant31aaf552010-12-08 21:07:55 +00005278 __ready_ = __m.ready();
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005279 }
5280
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005281private:
5282 void __init(unsigned __s,
Howard Hinnanta712c722010-08-16 20:21:16 +00005283 _BidirectionalIterator __f, _BidirectionalIterator __l,
5284 bool __no_update_pos = false);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005285
5286 template <class, class> friend class basic_regex;
5287
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005288 template <class _B, class _A, class _C, class _T>
5289 friend
5290 bool
5291 regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
5292 regex_constants::match_flag_type);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00005293
Howard Hinnant27405f92010-08-14 18:14:02 +00005294 template <class _B, class _A>
5295 friend
5296 bool
5297 operator==(const match_results<_B, _A>&, const match_results<_B, _A>&);
5298
Howard Hinnante9de5ff2010-07-27 22:20:32 +00005299 template <class, class> friend class __lookahead;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005300};
5301
5302template <class _BidirectionalIterator, class _Allocator>
5303match_results<_BidirectionalIterator, _Allocator>::match_results(
5304 const allocator_type& __a)
5305 : __matches_(__a),
5306 __unmatched_(),
5307 __prefix_(),
Howard Hinnanta712c722010-08-16 20:21:16 +00005308 __suffix_(),
Howard Hinnant31aaf552010-12-08 21:07:55 +00005309 __position_start_(),
5310 __ready_(false)
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005311{
5312}
5313
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005314template <class _BidirectionalIterator, class _Allocator>
5315void
5316match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
Howard Hinnanta712c722010-08-16 20:21:16 +00005317 _BidirectionalIterator __f, _BidirectionalIterator __l,
5318 bool __no_update_pos)
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005319{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005320 __unmatched_.first = __l;
5321 __unmatched_.second = __l;
5322 __unmatched_.matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005323 __matches_.assign(__s, __unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005324 __prefix_.first = __f;
5325 __prefix_.second = __f;
5326 __prefix_.matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005327 __suffix_ = __unmatched_;
Howard Hinnanta712c722010-08-16 20:21:16 +00005328 if (!__no_update_pos)
5329 __position_start_ = __prefix_.first;
Howard Hinnant31aaf552010-12-08 21:07:55 +00005330 __ready_ = true;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005331}
5332
Howard Hinnant27405f92010-08-14 18:14:02 +00005333template <class _BidirectionalIterator, class _Allocator>
5334template <class _OutputIter>
5335_OutputIter
5336match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
5337 const char_type* __fmt_first, const char_type* __fmt_last,
5338 regex_constants::match_flag_type __flags) const
5339{
5340 if (__flags & regex_constants::format_sed)
5341 {
5342 for (; __fmt_first != __fmt_last; ++__fmt_first)
5343 {
5344 if (*__fmt_first == '&')
5345 __out = _STD::copy(__matches_[0].first, __matches_[0].second,
5346 __out);
5347 else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
5348 {
5349 ++__fmt_first;
5350 if ('0' <= *__fmt_first && *__fmt_first <= '9')
5351 {
5352 size_t __i = *__fmt_first - '0';
5353 __out = _STD::copy(__matches_[__i].first,
5354 __matches_[__i].second, __out);
5355 }
5356 else
5357 {
5358 *__out = *__fmt_first;
5359 ++__out;
5360 }
5361 }
5362 else
5363 {
5364 *__out = *__fmt_first;
5365 ++__out;
5366 }
5367 }
5368 }
5369 else
5370 {
5371 for (; __fmt_first != __fmt_last; ++__fmt_first)
5372 {
5373 if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
5374 {
5375 switch (__fmt_first[1])
5376 {
5377 case '$':
5378 *__out = *++__fmt_first;
5379 ++__out;
5380 break;
5381 case '&':
5382 ++__fmt_first;
5383 __out = _STD::copy(__matches_[0].first, __matches_[0].second,
5384 __out);
5385 break;
5386 case '`':
5387 ++__fmt_first;
5388 __out = _STD::copy(__prefix_.first, __prefix_.second, __out);
5389 break;
5390 case '\'':
5391 ++__fmt_first;
5392 __out = _STD::copy(__suffix_.first, __suffix_.second, __out);
5393 break;
5394 default:
5395 if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5396 {
5397 ++__fmt_first;
5398 size_t __i = *__fmt_first - '0';
5399 if (__fmt_first + 1 != __fmt_last &&
5400 '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5401 {
5402 ++__fmt_first;
5403 __i = 10 * __i + *__fmt_first - '0';
5404 }
5405 __out = _STD::copy(__matches_[__i].first,
5406 __matches_[__i].second, __out);
5407 }
5408 else
5409 {
5410 *__out = *__fmt_first;
5411 ++__out;
5412 }
5413 break;
5414 }
5415 }
5416 else
5417 {
5418 *__out = *__fmt_first;
5419 ++__out;
5420 }
5421 }
5422 }
5423 return __out;
5424}
5425
5426template <class _BidirectionalIterator, class _Allocator>
5427void
5428match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
5429{
5430 using _STD::swap;
5431 swap(__matches_, __m.__matches_);
5432 swap(__unmatched_, __m.__unmatched_);
5433 swap(__prefix_, __m.__prefix_);
5434 swap(__suffix_, __m.__suffix_);
Howard Hinnanta712c722010-08-16 20:21:16 +00005435 swap(__position_start_, __m.__position_start_);
Howard Hinnant31aaf552010-12-08 21:07:55 +00005436 swap(__ready_, __m.__ready_);
Howard Hinnant27405f92010-08-14 18:14:02 +00005437}
5438
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005439typedef match_results<const char*> cmatch;
5440typedef match_results<const wchar_t*> wcmatch;
5441typedef match_results<string::const_iterator> smatch;
5442typedef match_results<wstring::const_iterator> wsmatch;
5443
5444template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005445bool
5446operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
5447 const match_results<_BidirectionalIterator, _Allocator>& __y)
5448{
Howard Hinnant31aaf552010-12-08 21:07:55 +00005449 if (__x.__ready_ != __y.__ready_)
5450 return false;
5451 if (!__x.__ready_)
5452 return true;
Howard Hinnant27405f92010-08-14 18:14:02 +00005453 return __x.__matches_ == __y.__matches_ &&
5454 __x.__prefix_ == __y.__prefix_ &&
Howard Hinnant31aaf552010-12-08 21:07:55 +00005455 __x.__suffix_ == __y.__suffix_;
Howard Hinnant27405f92010-08-14 18:14:02 +00005456}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005457
5458template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005459inline _LIBCPP_INLINE_VISIBILITY
5460bool
5461operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
5462 const match_results<_BidirectionalIterator, _Allocator>& __y)
5463{
5464 return !(__x == __y);
5465}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005466
5467template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005468inline _LIBCPP_INLINE_VISIBILITY
5469void
5470swap(match_results<_BidirectionalIterator, _Allocator>& __x,
5471 match_results<_BidirectionalIterator, _Allocator>& __y)
5472{
5473 __x.swap(__y);
5474}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005475
5476// regex_search
5477
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005478template <class _CharT, class _Traits>
Howard Hinnant17615b02010-07-27 01:25:38 +00005479template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005480bool
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005481basic_regex<_CharT, _Traits>::__match_at_start_ecma(
Howard Hinnant17615b02010-07-27 01:25:38 +00005482 const _CharT* __first, const _CharT* __last,
5483 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005484 regex_constants::match_flag_type __flags, bool __at_first) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005485{
Howard Hinnant17615b02010-07-27 01:25:38 +00005486 vector<__state> __states;
5487 ptrdiff_t __j = 0;
5488 ptrdiff_t _N = _STD::distance(__first, __last);
5489 __node* __st = __start_.get();
5490 if (__st)
5491 {
5492 __states.push_back(__state());
5493 __states.back().__do_ = 0;
5494 __states.back().__first_ = __first;
5495 __states.back().__current_ = __first;
5496 __states.back().__last_ = __last;
5497 __states.back().__sub_matches_.resize(mark_count());
5498 __states.back().__loop_data_.resize(__loop_count());
5499 __states.back().__node_ = __st;
5500 __states.back().__flags_ = __flags;
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005501 __states.back().__at_first_ = __at_first;
Howard Hinnant17615b02010-07-27 01:25:38 +00005502 bool __matched = false;
5503 do
5504 {
5505 __state& __s = __states.back();
5506 if (__s.__node_)
5507 __s.__node_->__exec(__s);
5508 switch (__s.__do_)
5509 {
5510 case __state::__end_state:
5511 __m.__matches_[0].first = __first;
5512 __m.__matches_[0].second = _STD::next(__first, __s.__current_ - __first);
5513 __m.__matches_[0].matched = true;
5514 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
5515 __m.__matches_[__i+1] = __s.__sub_matches_[__i];
5516 return true;
5517 case __state::__accept_and_consume:
5518 case __state::__repeat:
5519 case __state::__accept_but_not_consume:
5520 break;
5521 case __state::__split:
5522 {
5523 __state __snext = __s;
5524 __s.__node_->__exec_split(true, __s);
5525 __snext.__node_->__exec_split(false, __snext);
5526 __states.push_back(_STD::move(__snext));
5527 }
5528 break;
5529 case __state::__reject:
5530 __states.pop_back();
5531 break;
5532 default:
Howard Hinnantd4444702010-08-11 17:04:31 +00005533#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005534 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnantd4444702010-08-11 17:04:31 +00005535#endif
Howard Hinnant17615b02010-07-27 01:25:38 +00005536 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00005537
Howard Hinnant17615b02010-07-27 01:25:38 +00005538 }
5539 } while (!__states.empty());
5540 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005541 return false;
5542}
5543
5544template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005545template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005546bool
5547basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
5548 const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005549 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005550 regex_constants::match_flag_type __flags, bool __at_first) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005551{
Howard Hinnantac303862010-07-12 15:51:17 +00005552 deque<__state> __states;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005553 ptrdiff_t __highest_j = 0;
5554 ptrdiff_t _N = _STD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00005555 __node* __st = __start_.get();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005556 if (__st)
5557 {
Howard Hinnantac303862010-07-12 15:51:17 +00005558 __states.push_back(__state());
Howard Hinnantac303862010-07-12 15:51:17 +00005559 __states.back().__do_ = 0;
5560 __states.back().__first_ = __first;
5561 __states.back().__current_ = __first;
5562 __states.back().__last_ = __last;
5563 __states.back().__loop_data_.resize(__loop_count());
5564 __states.back().__node_ = __st;
5565 __states.back().__flags_ = __flags;
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005566 __states.back().__at_first_ = __at_first;
Howard Hinnant68025ed2010-07-14 15:45:11 +00005567 bool __matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005568 do
5569 {
Howard Hinnantac303862010-07-12 15:51:17 +00005570 __state& __s = __states.back();
5571 if (__s.__node_)
5572 __s.__node_->__exec(__s);
5573 switch (__s.__do_)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005574 {
Howard Hinnantac303862010-07-12 15:51:17 +00005575 case __state::__end_state:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005576 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
Howard Hinnant68025ed2010-07-14 15:45:11 +00005577 __highest_j = __s.__current_ - __s.__first_;
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005578 __matched = true;
Howard Hinnantac303862010-07-12 15:51:17 +00005579 if (__highest_j == _N)
5580 __states.clear();
5581 else
5582 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005583 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005584 case __state::__consume_input:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005585 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005586 case __state::__accept_and_consume:
Howard Hinnantac303862010-07-12 15:51:17 +00005587 __states.push_front(_STD::move(__s));
5588 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005589 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005590 case __state::__repeat:
5591 case __state::__accept_but_not_consume:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005592 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005593 case __state::__split:
5594 {
5595 __state __snext = __s;
5596 __s.__node_->__exec_split(true, __s);
5597 __snext.__node_->__exec_split(false, __snext);
5598 __states.push_back(_STD::move(__snext));
5599 }
5600 break;
5601 case __state::__reject:
5602 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005603 break;
5604 default:
Howard Hinnantd4444702010-08-11 17:04:31 +00005605#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005606 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnantd4444702010-08-11 17:04:31 +00005607#endif
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005608 break;
5609 }
Howard Hinnantac303862010-07-12 15:51:17 +00005610 } while (!__states.empty());
Howard Hinnant68025ed2010-07-14 15:45:11 +00005611 if (__matched)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005612 {
5613 __m.__matches_[0].first = __first;
5614 __m.__matches_[0].second = _STD::next(__first, __highest_j);
5615 __m.__matches_[0].matched = true;
5616 return true;
5617 }
5618 }
5619 return false;
5620}
5621
5622template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005623template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005624bool
5625basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005626 const _CharT* __first, const _CharT* __last,
5627 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005628 regex_constants::match_flag_type __flags, bool __at_first) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005629{
Howard Hinnantac303862010-07-12 15:51:17 +00005630 vector<__state> __states;
Howard Hinnantac303862010-07-12 15:51:17 +00005631 __state __best_state;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005632 ptrdiff_t __j = 0;
5633 ptrdiff_t __highest_j = 0;
5634 ptrdiff_t _N = _STD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00005635 __node* __st = __start_.get();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005636 if (__st)
5637 {
Howard Hinnantac303862010-07-12 15:51:17 +00005638 __states.push_back(__state());
5639 __states.back().__do_ = 0;
5640 __states.back().__first_ = __first;
5641 __states.back().__current_ = __first;
5642 __states.back().__last_ = __last;
5643 __states.back().__sub_matches_.resize(mark_count());
5644 __states.back().__loop_data_.resize(__loop_count());
5645 __states.back().__node_ = __st;
5646 __states.back().__flags_ = __flags;
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005647 __states.back().__at_first_ = __at_first;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005648 const _CharT* __current = __first;
Howard Hinnantac303862010-07-12 15:51:17 +00005649 bool __matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005650 do
5651 {
Howard Hinnantac303862010-07-12 15:51:17 +00005652 __state& __s = __states.back();
5653 if (__s.__node_)
5654 __s.__node_->__exec(__s);
5655 switch (__s.__do_)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005656 {
Howard Hinnantac303862010-07-12 15:51:17 +00005657 case __state::__end_state:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005658 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005659 {
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005660 __highest_j = __s.__current_ - __s.__first_;
Howard Hinnantac303862010-07-12 15:51:17 +00005661 __best_state = __s;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005662 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005663 __matched = true;
5664 if (__highest_j == _N)
5665 __states.clear();
5666 else
5667 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005668 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005669 case __state::__accept_and_consume:
Howard Hinnantcba352d2010-07-12 18:16:05 +00005670 __j += __s.__current_ - __current;
5671 __current = __s.__current_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005672 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005673 case __state::__repeat:
5674 case __state::__accept_but_not_consume:
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005675 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005676 case __state::__split:
5677 {
5678 __state __snext = __s;
5679 __s.__node_->__exec_split(true, __s);
5680 __snext.__node_->__exec_split(false, __snext);
5681 __states.push_back(_STD::move(__snext));
5682 }
5683 break;
5684 case __state::__reject:
5685 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005686 break;
5687 default:
Howard Hinnantd4444702010-08-11 17:04:31 +00005688#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005689 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnantd4444702010-08-11 17:04:31 +00005690#endif
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005691 break;
5692 }
Howard Hinnantac303862010-07-12 15:51:17 +00005693 } while (!__states.empty());
5694 if (__matched)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005695 {
5696 __m.__matches_[0].first = __first;
5697 __m.__matches_[0].second = _STD::next(__first, __highest_j);
5698 __m.__matches_[0].matched = true;
Howard Hinnantac303862010-07-12 15:51:17 +00005699 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
5700 __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005701 return true;
5702 }
5703 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005704 return false;
5705}
5706
5707template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005708template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005709bool
5710basic_regex<_CharT, _Traits>::__match_at_start(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005711 const _CharT* __first, const _CharT* __last,
5712 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005713 regex_constants::match_flag_type __flags, bool __at_first) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005714{
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005715 if ((__flags_ & 0x1F0) == ECMAScript)
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005716 return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005717 if (mark_count() == 0)
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005718 return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
5719 return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005720}
5721
5722template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005723template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005724bool
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005725basic_regex<_CharT, _Traits>::__search(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005726 const _CharT* __first, const _CharT* __last,
5727 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005728 regex_constants::match_flag_type __flags) const
5729{
Howard Hinnanta712c722010-08-16 20:21:16 +00005730 __m.__init(1 + mark_count(), __first, __last,
5731 __flags & regex_constants::__no_update_pos);
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005732 if (__match_at_start(__first, __last, __m, __flags, true))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005733 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005734 __m.__prefix_.second = __m[0].first;
5735 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5736 __m.__suffix_.first = __m[0].second;
5737 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5738 return true;
5739 }
Howard Hinnant8daa7332010-07-29 01:15:27 +00005740 if (__first != __last && !(__flags & regex_constants::match_continuous))
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005741 {
Howard Hinnantf3dcca02010-07-29 15:17:28 +00005742 __flags |= regex_constants::match_prev_avail;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005743 for (++__first; __first != __last; ++__first)
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005744 {
Howard Hinnantf3dcca02010-07-29 15:17:28 +00005745 __m.__matches_.assign(__m.size(), __m.__unmatched_);
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005746 if (__match_at_start(__first, __last, __m, __flags, false))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005747 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005748 __m.__prefix_.second = __m[0].first;
5749 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5750 __m.__suffix_.first = __m[0].second;
5751 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5752 return true;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005753 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005754 __m.__matches_.assign(__m.size(), __m.__unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005755 }
5756 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005757 __m.__matches_.clear();
5758 return false;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005759}
5760
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005761template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005762inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005763bool
5764regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5765 match_results<_BidirectionalIterator, _Allocator>& __m,
5766 const basic_regex<_CharT, _Traits>& __e,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005767 regex_constants::match_flag_type __flags = regex_constants::match_default)
5768{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005769 basic_string<_CharT> __s(__first, __last);
5770 match_results<const _CharT*> __mc;
5771 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnanta712c722010-08-16 20:21:16 +00005772 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005773 return __r;
5774}
5775
5776template <class _Allocator, class _CharT, class _Traits>
5777inline _LIBCPP_INLINE_VISIBILITY
5778bool
5779regex_search(const _CharT* __first, const _CharT* __last,
5780 match_results<const _CharT*, _Allocator>& __m,
5781 const basic_regex<_CharT, _Traits>& __e,
5782 regex_constants::match_flag_type __flags = regex_constants::match_default)
5783{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005784 return __e.__search(__first, __last, __m, __flags);
5785}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005786
5787template <class _BidirectionalIterator, class _CharT, class _Traits>
5788inline _LIBCPP_INLINE_VISIBILITY
5789bool
5790regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5791 const basic_regex<_CharT, _Traits>& __e,
5792 regex_constants::match_flag_type __flags = regex_constants::match_default)
5793{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005794 basic_string<_CharT> __s(__first, __last);
5795 match_results<const _CharT*> __mc;
5796 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5797}
5798
5799template <class _CharT, class _Traits>
5800inline _LIBCPP_INLINE_VISIBILITY
5801bool
5802regex_search(const _CharT* __first, const _CharT* __last,
5803 const basic_regex<_CharT, _Traits>& __e,
5804 regex_constants::match_flag_type __flags = regex_constants::match_default)
5805{
5806 match_results<const _CharT*> __mc;
5807 return __e.__search(__first, __last, __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005808}
5809
5810template <class _CharT, class _Allocator, class _Traits>
5811inline _LIBCPP_INLINE_VISIBILITY
5812bool
5813regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5814 const basic_regex<_CharT, _Traits>& __e,
5815 regex_constants::match_flag_type __flags = regex_constants::match_default)
5816{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005817 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005818}
5819
5820template <class _CharT, class _Traits>
5821inline _LIBCPP_INLINE_VISIBILITY
5822bool
5823regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5824 regex_constants::match_flag_type __flags = regex_constants::match_default)
5825{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005826 match_results<const _CharT*> __m;
5827 return _STD::regex_search(__str, __m, __e, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005828}
5829
5830template <class _ST, class _SA, class _CharT, class _Traits>
5831inline _LIBCPP_INLINE_VISIBILITY
5832bool
5833regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5834 const basic_regex<_CharT, _Traits>& __e,
5835 regex_constants::match_flag_type __flags = regex_constants::match_default)
5836{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005837 match_results<const _CharT*> __mc;
5838 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005839}
5840
5841template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5842inline _LIBCPP_INLINE_VISIBILITY
5843bool
5844regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5845 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5846 const basic_regex<_CharT, _Traits>& __e,
5847 regex_constants::match_flag_type __flags = regex_constants::match_default)
5848{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005849 match_results<const _CharT*> __mc;
5850 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnanta712c722010-08-16 20:21:16 +00005851 __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005852 return __r;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005853}
5854
5855// regex_match
5856
5857template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5858bool
5859regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5860 match_results<_BidirectionalIterator, _Allocator>& __m,
5861 const basic_regex<_CharT, _Traits>& __e,
5862 regex_constants::match_flag_type __flags = regex_constants::match_default)
5863{
5864 bool __r = _STD::regex_search(__first, __last, __m, __e,
5865 __flags | regex_constants::match_continuous);
5866 if (__r)
5867 {
5868 __r = !__m.suffix().matched;
5869 if (!__r)
5870 __m.__matches_.clear();
5871 }
5872 return __r;
5873}
5874
5875template <class _BidirectionalIterator, class _CharT, class _Traits>
5876inline _LIBCPP_INLINE_VISIBILITY
5877bool
5878regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5879 const basic_regex<_CharT, _Traits>& __e,
5880 regex_constants::match_flag_type __flags = regex_constants::match_default)
5881{
5882 match_results<_BidirectionalIterator> __m;
5883 return _STD::regex_match(__first, __last, __m, __e, __flags);
5884}
5885
5886template <class _CharT, class _Allocator, class _Traits>
5887inline _LIBCPP_INLINE_VISIBILITY
5888bool
5889regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5890 const basic_regex<_CharT, _Traits>& __e,
5891 regex_constants::match_flag_type __flags = regex_constants::match_default)
5892{
5893 return _STD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
5894}
5895
5896template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5897inline _LIBCPP_INLINE_VISIBILITY
5898bool
5899regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5900 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5901 const basic_regex<_CharT, _Traits>& __e,
5902 regex_constants::match_flag_type __flags = regex_constants::match_default)
5903{
5904 return _STD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
5905}
5906
5907template <class _CharT, class _Traits>
5908inline _LIBCPP_INLINE_VISIBILITY
5909bool
5910regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5911 regex_constants::match_flag_type __flags = regex_constants::match_default)
5912{
5913 return _STD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
5914}
5915
5916template <class _ST, class _SA, class _CharT, class _Traits>
5917inline _LIBCPP_INLINE_VISIBILITY
5918bool
5919regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5920 const basic_regex<_CharT, _Traits>& __e,
5921 regex_constants::match_flag_type __flags = regex_constants::match_default)
5922{
5923 return _STD::regex_match(__s.begin(), __s.end(), __e, __flags);
5924}
5925
Howard Hinnanta712c722010-08-16 20:21:16 +00005926// regex_iterator
5927
5928template <class _BidirectionalIterator,
5929 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
5930 class _Traits = regex_traits<_CharT> >
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005931class _LIBCPP_VISIBLE regex_iterator
Howard Hinnanta712c722010-08-16 20:21:16 +00005932{
5933public:
5934 typedef basic_regex<_CharT, _Traits> regex_type;
5935 typedef match_results<_BidirectionalIterator> value_type;
5936 typedef ptrdiff_t difference_type;
5937 typedef const value_type* pointer;
5938 typedef const value_type& reference;
5939 typedef forward_iterator_tag iterator_category;
5940
5941private:
5942 _BidirectionalIterator __begin_;
5943 _BidirectionalIterator __end_;
5944 const regex_type* __pregex_;
5945 regex_constants::match_flag_type __flags_;
5946 value_type __match_;
5947
5948public:
5949 regex_iterator();
5950 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
5951 const regex_type& __re,
5952 regex_constants::match_flag_type __m = regex_constants::match_default);
5953
5954 bool operator==(const regex_iterator& __x) const;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005956 bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
5957
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005959 reference operator*() const {return __match_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005961 pointer operator->() const {return &__match_;}
5962
5963 regex_iterator& operator++();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005964 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005965 regex_iterator operator++(int)
5966 {
5967 regex_iterator __t(*this);
5968 ++(*this);
5969 return __t;
5970 }
5971};
5972
5973template <class _BidirectionalIterator, class _CharT, class _Traits>
5974regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
5975 : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
5976{
5977}
5978
5979template <class _BidirectionalIterator, class _CharT, class _Traits>
5980regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
5981 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
5982 const regex_type& __re, regex_constants::match_flag_type __m)
5983 : __begin_(__a),
5984 __end_(__b),
5985 __pregex_(&__re),
5986 __flags_(__m)
5987{
5988 _STD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
5989}
5990
5991template <class _BidirectionalIterator, class _CharT, class _Traits>
5992bool
5993regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
5994 operator==(const regex_iterator& __x) const
5995{
5996 if (__match_.empty() && __x.__match_.empty())
5997 return true;
5998 if (__match_.empty() || __x.__match_.empty())
5999 return false;
6000 return __begin_ == __x.__begin_ &&
6001 __end_ == __x.__end_ &&
6002 __pregex_ == __x.__pregex_ &&
6003 __flags_ == __x.__flags_ &&
6004 __match_[0] == __x.__match_[0];
6005}
6006
6007template <class _BidirectionalIterator, class _CharT, class _Traits>
6008regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
6009regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6010{
6011 __flags_ |= regex_constants::__no_update_pos;
6012 _BidirectionalIterator __start = __match_[0].second;
6013 if (__match_.length() == 0)
6014 {
6015 if (__start == __end_)
6016 {
6017 __match_ = value_type();
6018 return *this;
6019 }
6020 else if (_STD::regex_search(__start, __end_, __match_, *__pregex_,
6021 __flags_ | regex_constants::match_not_null |
6022 regex_constants::match_continuous))
6023 return *this;
6024 else
6025 ++__start;
6026 }
6027 __flags_ |= regex_constants::match_prev_avail;
6028 if (!_STD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
6029 __match_ = value_type();
6030 return *this;
6031}
6032
6033typedef regex_iterator<const char*> cregex_iterator;
6034typedef regex_iterator<const wchar_t*> wcregex_iterator;
6035typedef regex_iterator<string::const_iterator> sregex_iterator;
6036typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
6037
6038// regex_token_iterator
6039
6040template <class _BidirectionalIterator,
6041 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6042 class _Traits = regex_traits<_CharT> >
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006043class _LIBCPP_VISIBLE regex_token_iterator
Howard Hinnanta712c722010-08-16 20:21:16 +00006044{
6045public:
6046 typedef basic_regex<_CharT, _Traits> regex_type;
6047 typedef sub_match<_BidirectionalIterator> value_type;
6048 typedef ptrdiff_t difference_type;
6049 typedef const value_type* pointer;
6050 typedef const value_type& reference;
6051 typedef forward_iterator_tag iterator_category;
6052
Howard Hinnant262b7792010-08-17 20:42:03 +00006053private:
6054 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
6055
6056 _Position __position_;
6057 const value_type* __result_;
6058 value_type __suffix_;
6059 ptrdiff_t _N_;
6060 vector<int> __subs_;
6061
6062public:
Howard Hinnanta712c722010-08-16 20:21:16 +00006063 regex_token_iterator();
6064 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6065 const regex_type& __re, int __submatch = 0,
Howard Hinnant262b7792010-08-17 20:42:03 +00006066 regex_constants::match_flag_type __m =
6067 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006068 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6069 const regex_type& __re, const vector<int>& __submatches,
Howard Hinnant262b7792010-08-17 20:42:03 +00006070 regex_constants::match_flag_type __m =
6071 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006072 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
Howard Hinnant262b7792010-08-17 20:42:03 +00006073 const regex_type& __re,
6074 initializer_list<int> __submatches,
6075 regex_constants::match_flag_type __m =
6076 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006077 template <size_t _N>
Howard Hinnant262b7792010-08-17 20:42:03 +00006078 regex_token_iterator(_BidirectionalIterator __a,
6079 _BidirectionalIterator __b,
6080 const regex_type& __re,
6081 const int (&__submatches)[_N],
6082 regex_constants::match_flag_type __m =
6083 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006084 regex_token_iterator(const regex_token_iterator&);
6085 regex_token_iterator& operator=(const regex_token_iterator&);
6086
Howard Hinnant262b7792010-08-17 20:42:03 +00006087 bool operator==(const regex_token_iterator& __x) const;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006088 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006089 bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
Howard Hinnanta712c722010-08-16 20:21:16 +00006090
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006092 const value_type& operator*() const {return *__result_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006094 const value_type* operator->() const {return __result_;}
Howard Hinnanta712c722010-08-16 20:21:16 +00006095
6096 regex_token_iterator& operator++();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006097 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006098 regex_token_iterator operator++(int)
6099 {
6100 regex_token_iterator __t(*this);
6101 ++(*this);
6102 return __t;
6103 }
6104
6105private:
6106 void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
Howard Hinnanta712c722010-08-16 20:21:16 +00006107};
6108
Howard Hinnant262b7792010-08-17 20:42:03 +00006109template <class _BidirectionalIterator, class _CharT, class _Traits>
6110regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6111 regex_token_iterator()
6112 : __result_(nullptr),
6113 __suffix_(),
6114 _N_(0)
6115{
6116}
6117
6118template <class _BidirectionalIterator, class _CharT, class _Traits>
6119void
6120regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6121 __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
6122{
6123 if (__position_ != _Position())
6124 {
6125 if (__subs_[_N_] == -1)
6126 __result_ = &__position_->prefix();
6127 else
6128 __result_ = &(*__position_)[__subs_[_N_]];
6129 }
6130 else if (__subs_[_N_] == -1)
6131 {
6132 __suffix_.matched = true;
6133 __suffix_.first = __a;
6134 __suffix_.second = __b;
6135 __result_ = &__suffix_;
6136 }
6137 else
6138 __result_ = nullptr;
6139}
6140
6141template <class _BidirectionalIterator, class _CharT, class _Traits>
6142regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6143 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6144 const regex_type& __re, int __submatch,
6145 regex_constants::match_flag_type __m)
6146 : __position_(__a, __b, __re, __m),
6147 _N_(0),
6148 __subs_(1, __submatch)
6149{
6150 __init(__a, __b);
6151}
6152
6153template <class _BidirectionalIterator, class _CharT, class _Traits>
6154regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6155 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6156 const regex_type& __re, const vector<int>& __submatches,
6157 regex_constants::match_flag_type __m)
6158 : __position_(__a, __b, __re, __m),
6159 _N_(0),
6160 __subs_(__submatches)
6161{
6162 __init(__a, __b);
6163}
6164
6165template <class _BidirectionalIterator, class _CharT, class _Traits>
6166regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6167 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6168 const regex_type& __re,
6169 initializer_list<int> __submatches,
6170 regex_constants::match_flag_type __m)
6171 : __position_(__a, __b, __re, __m),
6172 _N_(0),
6173 __subs_(__submatches)
6174{
6175 __init(__a, __b);
6176}
6177
6178template <class _BidirectionalIterator, class _CharT, class _Traits>
6179template <size_t _N>
6180regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6181 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6182 const regex_type& __re,
6183 const int (&__submatches)[_N],
6184 regex_constants::match_flag_type __m)
6185 : __position_(__a, __b, __re, __m),
6186 _N_(0),
6187 __subs_(__submatches, __submatches + _N)
6188{
6189 __init(__a, __b);
6190}
6191
6192template <class _BidirectionalIterator, class _CharT, class _Traits>
6193regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6194 regex_token_iterator(const regex_token_iterator& __x)
6195 : __position_(__x.__position_),
6196 __result_(__x.__result_),
6197 __suffix_(__x.__suffix_),
6198 _N_(__x._N_),
6199 __subs_(__x.__subs_)
6200{
6201 if (__x.__result_ == &__x.__suffix_)
6202 __result_ == &__suffix_;
6203}
6204
6205template <class _BidirectionalIterator, class _CharT, class _Traits>
6206regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6207regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6208 operator=(const regex_token_iterator& __x)
6209{
6210 if (this != &__x)
6211 {
6212 __position_ = __x.__position_;
6213 if (__x.__result_ == &__x.__suffix_)
6214 __result_ == &__suffix_;
6215 else
6216 __result_ = __x.__result_;
6217 __suffix_ = __x.__suffix_;
6218 _N_ = __x._N_;
6219 __subs_ = __x.__subs_;
6220 }
6221 return *this;
6222}
6223
6224template <class _BidirectionalIterator, class _CharT, class _Traits>
6225bool
6226regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6227 operator==(const regex_token_iterator& __x) const
6228{
6229 if (__result_ == nullptr && __x.__result_ == nullptr)
6230 return true;
6231 if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
6232 __suffix_ == __x.__suffix_)
6233 return true;
6234 if (__result_ == nullptr || __x.__result_ == nullptr)
6235 return false;
6236 if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
6237 return false;
6238 return __position_ == __x.__position_ && _N_ == __x._N_ &&
6239 __subs_ == __x.__subs_;
6240}
6241
6242template <class _BidirectionalIterator, class _CharT, class _Traits>
6243regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6244regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6245{
6246 _Position __prev = __position_;
6247 if (__result_ == &__suffix_)
6248 __result_ = nullptr;
6249 else if (_N_ + 1 < __subs_.size())
6250 {
6251 ++_N_;
6252 if (__subs_[_N_] == -1)
6253 __result_ = &__position_->prefix();
6254 else
6255 __result_ = &(*__position_)[__subs_[_N_]];
6256 }
6257 else
6258 {
6259 _N_ = 0;
6260 ++__position_;
6261 if (__position_ != _Position())
6262 {
6263 if (__subs_[_N_] == -1)
6264 __result_ = &__position_->prefix();
6265 else
6266 __result_ = &(*__position_)[__subs_[_N_]];
6267 }
6268 else
6269 {
6270 if (_STD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
6271 && __prev->suffix().length() != 0)
6272 {
6273 __suffix_.matched = true;
6274 __suffix_.first = __prev->suffix().first;
6275 __suffix_.second = __prev->suffix().second;
6276 __result_ = &__suffix_;
6277 }
6278 else
6279 __result_ = nullptr;
6280 }
6281 }
6282 return *this;
6283}
6284
Howard Hinnanta712c722010-08-16 20:21:16 +00006285typedef regex_token_iterator<const char*> cregex_token_iterator;
6286typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
6287typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
6288typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
6289
Howard Hinnanta8d77592010-08-18 00:13:08 +00006290// regex_replace
6291
6292template <class _OutputIterator, class _BidirectionalIterator,
6293 class _Traits, class _CharT>
6294_OutputIterator
6295regex_replace(_OutputIterator __out,
6296 _BidirectionalIterator __first, _BidirectionalIterator __last,
6297 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6298 regex_constants::match_flag_type __flags = regex_constants::match_default)
6299{
6300 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
6301 _Iter __i(__first, __last, __e, __flags);
6302 _Iter __eof;
6303 if (__i == __eof)
6304 {
6305 if (!(__flags & regex_constants::format_no_copy))
6306 __out = _STD::copy(__first, __last, __out);
6307 }
6308 else
6309 {
6310 sub_match<_BidirectionalIterator> __lm;
6311 for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
6312 {
6313 if (!(__flags & regex_constants::format_no_copy))
6314 __out = _STD::copy(__i->prefix().first, __i->prefix().second, __out);
6315 __out = __i->format(__out, __fmt, __fmt + __len, __flags);
6316 __lm = __i->suffix();
6317 if (__flags & regex_constants::format_first_only)
6318 break;
6319 }
6320 if (!(__flags & regex_constants::format_no_copy))
6321 __out = _STD::copy(__lm.first, __lm.second, __out);
6322 }
6323 return __out;
6324}
6325
6326template <class _OutputIterator, class _BidirectionalIterator,
6327 class _Traits, class _CharT, class _ST, class _SA>
6328inline _LIBCPP_INLINE_VISIBILITY
6329_OutputIterator
6330regex_replace(_OutputIterator __out,
6331 _BidirectionalIterator __first, _BidirectionalIterator __last,
6332 const basic_regex<_CharT, _Traits>& __e,
6333 const basic_string<_CharT, _ST, _SA>& __fmt,
6334 regex_constants::match_flag_type __flags = regex_constants::match_default)
6335{
6336 return _STD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
6337}
6338
6339template <class _Traits, class _CharT, class _ST, class _SA, class _FST,
6340 class _FSA>
6341inline _LIBCPP_INLINE_VISIBILITY
6342basic_string<_CharT, _ST, _SA>
6343regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6344 const basic_regex<_CharT, _Traits>& __e,
6345 const basic_string<_CharT, _FST, _FSA>& __fmt,
6346 regex_constants::match_flag_type __flags = regex_constants::match_default)
6347{
6348 basic_string<_CharT, _ST, _SA> __r;
6349 _STD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6350 __fmt.c_str(), __flags);
6351 return __r;
6352}
6353
6354template <class _Traits, class _CharT, class _ST, class _SA>
6355inline _LIBCPP_INLINE_VISIBILITY
6356basic_string<_CharT, _ST, _SA>
6357regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6358 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6359 regex_constants::match_flag_type __flags = regex_constants::match_default)
6360{
6361 basic_string<_CharT, _ST, _SA> __r;
6362 _STD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6363 __fmt, __flags);
6364 return __r;
6365}
6366
6367template <class _Traits, class _CharT, class _ST, class _SA>
6368inline _LIBCPP_INLINE_VISIBILITY
6369basic_string<_CharT>
6370regex_replace(const _CharT* __s,
6371 const basic_regex<_CharT, _Traits>& __e,
6372 const basic_string<_CharT, _ST, _SA>& __fmt,
6373 regex_constants::match_flag_type __flags = regex_constants::match_default)
6374{
6375 basic_string<_CharT> __r;
6376 _STD::regex_replace(back_inserter(__r), __s,
6377 __s + char_traits<_CharT>::length(__s), __e,
6378 __fmt.c_str(), __flags);
6379 return __r;
6380}
6381
6382template <class _Traits, class _CharT>
6383inline _LIBCPP_INLINE_VISIBILITY
6384basic_string<_CharT>
6385regex_replace(const _CharT* __s,
6386 const basic_regex<_CharT, _Traits>& __e,
6387 const _CharT* __fmt,
6388 regex_constants::match_flag_type __flags = regex_constants::match_default)
6389{
6390 basic_string<_CharT> __r;
6391 _STD::regex_replace(back_inserter(__r), __s,
6392 __s + char_traits<_CharT>::length(__s), __e,
6393 __fmt, __flags);
6394 return __r;
6395}
6396
Howard Hinnant3257c982010-06-17 00:34:59 +00006397_LIBCPP_END_NAMESPACE_STD
6398
6399#endif // _LIBCPP_REGEX