blob: f851cb190fd0738e90285ff13a818d5bc4e792f4 [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 Hinnantf8ce4592010-07-07 19:14:52 +00001267
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001269 __state()
1270 : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
1271 __node_(nullptr), __flags_() {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001272};
1273
Howard Hinnantac303862010-07-12 15:51:17 +00001274// __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001275
1276template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001277class __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001278{
Howard Hinnantac303862010-07-12 15:51:17 +00001279 __node(const __node&);
1280 __node& operator=(const __node&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001281public:
Howard Hinnantac303862010-07-12 15:51:17 +00001282 typedef _STD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001283
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001285 __node() {}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001287 virtual ~__node() {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001288
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001289 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001290 virtual void __exec(__state&) const {};
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001292 virtual void __exec_split(bool, __state&) const {};
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001293};
1294
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001295// __end_state
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001296
1297template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001298class __end_state
Howard Hinnantac303862010-07-12 15:51:17 +00001299 : public __node<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001300{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001301public:
Howard Hinnantac303862010-07-12 15:51:17 +00001302 typedef _STD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001303
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001305 __end_state() {}
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001306
Howard Hinnantac303862010-07-12 15:51:17 +00001307 virtual void __exec(__state&) const;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001308};
1309
1310template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001311void
1312__end_state<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001313{
Howard Hinnantac303862010-07-12 15:51:17 +00001314 __s.__do_ = __state::__end_state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001315}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001316
1317// __has_one_state
1318
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001319template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001320class __has_one_state
Howard Hinnantac303862010-07-12 15:51:17 +00001321 : public __node<_CharT>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001322{
Howard Hinnantac303862010-07-12 15:51:17 +00001323 __node<_CharT>* __first_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001324
1325public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001327 explicit __has_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001328 : __first_(__s) {}
1329
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001330 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001331 __node<_CharT>* first() const {return __first_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001332 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001333 __node<_CharT>*& first() {return __first_;}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001334};
1335
1336// __owns_one_state
1337
1338template <class _CharT>
1339class __owns_one_state
1340 : public __has_one_state<_CharT>
1341{
1342 typedef __has_one_state<_CharT> base;
1343
1344public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001345 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001346 explicit __owns_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001347 : base(__s) {}
1348
1349 virtual ~__owns_one_state();
1350};
1351
1352template <class _CharT>
1353__owns_one_state<_CharT>::~__owns_one_state()
1354{
1355 delete this->first();
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001356}
1357
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001358// __empty_state
1359
1360template <class _CharT>
1361class __empty_state
1362 : public __owns_one_state<_CharT>
1363{
1364 typedef __owns_one_state<_CharT> base;
1365
1366public:
Howard Hinnantac303862010-07-12 15:51:17 +00001367 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001368
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001370 explicit __empty_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001371 : base(__s) {}
1372
Howard Hinnantac303862010-07-12 15:51:17 +00001373 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001374};
1375
1376template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001377void
1378__empty_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001379{
Howard Hinnantac303862010-07-12 15:51:17 +00001380 __s.__do_ = __state::__accept_but_not_consume;
1381 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001382}
1383
1384// __empty_non_own_state
1385
1386template <class _CharT>
1387class __empty_non_own_state
1388 : public __has_one_state<_CharT>
1389{
1390 typedef __has_one_state<_CharT> base;
1391
1392public:
Howard Hinnantac303862010-07-12 15:51:17 +00001393 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001394
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001395 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001396 explicit __empty_non_own_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001397 : base(__s) {}
1398
Howard Hinnantac303862010-07-12 15:51:17 +00001399 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001400};
1401
1402template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001403void
1404__empty_non_own_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001405{
Howard Hinnantac303862010-07-12 15:51:17 +00001406 __s.__do_ = __state::__accept_but_not_consume;
1407 __s.__node_ = this->first();
1408}
1409
1410// __repeat_one_loop
1411
1412template <class _CharT>
1413class __repeat_one_loop
1414 : public __has_one_state<_CharT>
1415{
1416 typedef __has_one_state<_CharT> base;
1417
1418public:
1419 typedef _STD::__state<_CharT> __state;
1420
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001422 explicit __repeat_one_loop(__node<_CharT>* __s)
1423 : base(__s) {}
1424
1425 virtual void __exec(__state&) const;
Howard Hinnantac303862010-07-12 15:51:17 +00001426};
1427
1428template <class _CharT>
1429void
1430__repeat_one_loop<_CharT>::__exec(__state& __s) const
1431{
1432 __s.__do_ = __state::__repeat;
1433 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001434}
1435
1436// __owns_two_states
1437
1438template <class _CharT>
1439class __owns_two_states
1440 : public __owns_one_state<_CharT>
1441{
1442 typedef __owns_one_state<_CharT> base;
1443
1444 base* __second_;
1445
1446public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001448 explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001449 : base(__s1), __second_(__s2) {}
1450
1451 virtual ~__owns_two_states();
1452
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001453 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001454 base* second() const {return __second_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001455 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001456 base*& second() {return __second_;}
1457};
1458
1459template <class _CharT>
1460__owns_two_states<_CharT>::~__owns_two_states()
1461{
1462 delete __second_;
1463}
1464
1465// __loop
1466
1467template <class _CharT>
1468class __loop
1469 : public __owns_two_states<_CharT>
1470{
1471 typedef __owns_two_states<_CharT> base;
1472
1473 size_t __min_;
1474 size_t __max_;
1475 unsigned __loop_id_;
Howard Hinnantac303862010-07-12 15:51:17 +00001476 unsigned __mexp_begin_;
1477 unsigned __mexp_end_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001478 bool __greedy_;
1479
1480public:
Howard Hinnantac303862010-07-12 15:51:17 +00001481 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001482
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001484 explicit __loop(unsigned __loop_id,
Howard Hinnantac303862010-07-12 15:51:17 +00001485 __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
1486 unsigned __mexp_begin, unsigned __mexp_end,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001487 bool __greedy = true,
1488 size_t __min = 0,
1489 size_t __max = numeric_limits<size_t>::max())
1490 : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
Howard Hinnantac303862010-07-12 15:51:17 +00001491 __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001492 __greedy_(__greedy) {}
1493
Howard Hinnantac303862010-07-12 15:51:17 +00001494 virtual void __exec(__state& __s) const;
1495 virtual void __exec_split(bool __second, __state& __s) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001496
Howard Hinnantac303862010-07-12 15:51:17 +00001497private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001499 void __init_repeat(__state& __s) const
1500 {
1501 __s.__loop_data_[__loop_id_].second = __s.__current_;
1502 for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
1503 {
1504 __s.__sub_matches_[__i].first = __s.__last_;
1505 __s.__sub_matches_[__i].second = __s.__last_;
1506 __s.__sub_matches_[__i].matched = false;
1507 }
1508 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001509};
1510
1511template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001512void
1513__loop<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001514{
Howard Hinnantac303862010-07-12 15:51:17 +00001515 if (__s.__do_ == __state::__repeat)
1516 {
1517 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1518 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1519 if (__do_repeat && __do_alt &&
1520 __s.__loop_data_[__loop_id_].second == __s.__current_)
1521 __do_repeat = false;
1522 if (__do_repeat && __do_alt)
1523 __s.__do_ = __state::__split;
1524 else if (__do_repeat)
1525 {
1526 __s.__do_ = __state::__accept_but_not_consume;
1527 __s.__node_ = this->first();
1528 __init_repeat(__s);
1529 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001530 else
Howard Hinnantac303862010-07-12 15:51:17 +00001531 {
1532 __s.__do_ = __state::__accept_but_not_consume;
1533 __s.__node_ = this->second();
1534 }
1535 }
1536 else
1537 {
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00001538 __s.__loop_data_[__loop_id_].first = 0;
1539 bool __do_repeat = 0 < __max_;
1540 bool __do_alt = 0 >= __min_;
1541 if (__do_repeat && __do_alt)
Howard Hinnantac303862010-07-12 15:51:17 +00001542 __s.__do_ = __state::__split;
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00001543 else if (__do_repeat)
1544 {
1545 __s.__do_ = __state::__accept_but_not_consume;
1546 __s.__node_ = this->first();
1547 __init_repeat(__s);
1548 }
Howard Hinnantac303862010-07-12 15:51:17 +00001549 else
1550 {
1551 __s.__do_ = __state::__accept_but_not_consume;
1552 __s.__node_ = this->second();
1553 }
1554 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001555}
1556
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001557template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001558void
1559__loop<_CharT>::__exec_split(bool __second, __state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001560{
Howard Hinnantac303862010-07-12 15:51:17 +00001561 __s.__do_ = __state::__accept_but_not_consume;
1562 if (__greedy_ != __second)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001563 {
Howard Hinnantac303862010-07-12 15:51:17 +00001564 __s.__node_ = this->first();
1565 __init_repeat(__s);
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001566 }
Howard Hinnantac303862010-07-12 15:51:17 +00001567 else
1568 __s.__node_ = this->second();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001569}
1570
Howard Hinnantaa698082010-07-16 19:08:36 +00001571// __alternate
1572
1573template <class _CharT>
1574class __alternate
1575 : public __owns_two_states<_CharT>
1576{
1577 typedef __owns_two_states<_CharT> base;
1578
1579public:
1580 typedef _STD::__state<_CharT> __state;
1581
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaa698082010-07-16 19:08:36 +00001583 explicit __alternate(__owns_one_state<_CharT>* __s1,
1584 __owns_one_state<_CharT>* __s2)
1585 : base(__s1, __s2) {}
1586
1587 virtual void __exec(__state& __s) const;
1588 virtual void __exec_split(bool __second, __state& __s) const;
Howard Hinnantaa698082010-07-16 19:08:36 +00001589};
1590
1591template <class _CharT>
1592void
1593__alternate<_CharT>::__exec(__state& __s) const
1594{
1595 __s.__do_ = __state::__split;
1596}
1597
1598template <class _CharT>
1599void
1600__alternate<_CharT>::__exec_split(bool __second, __state& __s) const
1601{
1602 __s.__do_ = __state::__accept_but_not_consume;
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001603 if (__second)
Howard Hinnantaa698082010-07-16 19:08:36 +00001604 __s.__node_ = this->second();
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001605 else
1606 __s.__node_ = this->first();
Howard Hinnantaa698082010-07-16 19:08:36 +00001607}
1608
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001609// __begin_marked_subexpression
1610
1611template <class _CharT>
1612class __begin_marked_subexpression
1613 : public __owns_one_state<_CharT>
1614{
1615 typedef __owns_one_state<_CharT> base;
1616
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001617 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001618public:
Howard Hinnantac303862010-07-12 15:51:17 +00001619 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001620
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001622 explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001623 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001624
Howard Hinnantac303862010-07-12 15:51:17 +00001625 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001626};
1627
1628template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001629void
1630__begin_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001631{
Howard Hinnantac303862010-07-12 15:51:17 +00001632 __s.__do_ = __state::__accept_but_not_consume;
1633 __s.__sub_matches_[__mexp_-1].first = __s.__current_;
1634 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001635}
1636
1637// __end_marked_subexpression
1638
1639template <class _CharT>
1640class __end_marked_subexpression
1641 : public __owns_one_state<_CharT>
1642{
1643 typedef __owns_one_state<_CharT> base;
1644
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001645 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001646public:
Howard Hinnantac303862010-07-12 15:51:17 +00001647 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001648
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001650 explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001651 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001652
Howard Hinnantac303862010-07-12 15:51:17 +00001653 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001654};
1655
1656template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001657void
1658__end_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001659{
Howard Hinnantac303862010-07-12 15:51:17 +00001660 __s.__do_ = __state::__accept_but_not_consume;
1661 __s.__sub_matches_[__mexp_-1].second = __s.__current_;
1662 __s.__sub_matches_[__mexp_-1].matched = true;
1663 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001664}
1665
Howard Hinnantcba352d2010-07-12 18:16:05 +00001666// __back_ref
1667
1668template <class _CharT>
1669class __back_ref
1670 : public __owns_one_state<_CharT>
1671{
1672 typedef __owns_one_state<_CharT> base;
1673
1674 unsigned __mexp_;
1675public:
1676 typedef _STD::__state<_CharT> __state;
1677
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcba352d2010-07-12 18:16:05 +00001679 explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
1680 : base(__s), __mexp_(__mexp) {}
1681
1682 virtual void __exec(__state&) const;
Howard Hinnantcba352d2010-07-12 18:16:05 +00001683};
1684
1685template <class _CharT>
1686void
1687__back_ref<_CharT>::__exec(__state& __s) const
1688{
1689 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1690 if (__sm.matched)
1691 {
1692 ptrdiff_t __len = __sm.second - __sm.first;
1693 if (__s.__last_ - __s.__current_ >= __len &&
1694 _STD::equal(__sm.first, __sm.second, __s.__current_))
1695 {
1696 __s.__do_ = __state::__accept_but_not_consume;
1697 __s.__current_ += __len;
1698 __s.__node_ = this->first();
1699 }
1700 else
1701 {
1702 __s.__do_ = __state::__reject;
1703 __s.__node_ = nullptr;
1704 }
1705 }
1706 else
1707 {
1708 __s.__do_ = __state::__reject;
1709 __s.__node_ = nullptr;
1710 }
1711}
1712
Howard Hinnante34f17d2010-07-12 19:11:27 +00001713// __back_ref_icase
1714
1715template <class _CharT, class _Traits>
1716class __back_ref_icase
1717 : public __owns_one_state<_CharT>
1718{
1719 typedef __owns_one_state<_CharT> base;
1720
1721 _Traits __traits_;
1722 unsigned __mexp_;
1723public:
1724 typedef _STD::__state<_CharT> __state;
1725
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001726 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00001727 explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
1728 __node<_CharT>* __s)
1729 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1730
1731 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00001732};
1733
1734template <class _CharT, class _Traits>
1735void
1736__back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
1737{
1738 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1739 if (__sm.matched)
1740 {
1741 ptrdiff_t __len = __sm.second - __sm.first;
1742 if (__s.__last_ - __s.__current_ >= __len)
1743 {
1744 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1745 {
1746 if (__traits_.translate_nocase(__sm.first[__i]) !=
1747 __traits_.translate_nocase(__s.__current_[__i]))
1748 goto __not_equal;
1749 }
1750 __s.__do_ = __state::__accept_but_not_consume;
1751 __s.__current_ += __len;
1752 __s.__node_ = this->first();
1753 }
1754 else
1755 {
1756 __s.__do_ = __state::__reject;
1757 __s.__node_ = nullptr;
1758 }
1759 }
1760 else
1761 {
1762__not_equal:
1763 __s.__do_ = __state::__reject;
1764 __s.__node_ = nullptr;
1765 }
1766}
1767
1768// __back_ref_collate
1769
1770template <class _CharT, class _Traits>
1771class __back_ref_collate
1772 : public __owns_one_state<_CharT>
1773{
1774 typedef __owns_one_state<_CharT> base;
1775
1776 _Traits __traits_;
1777 unsigned __mexp_;
1778public:
1779 typedef _STD::__state<_CharT> __state;
1780
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001781 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00001782 explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
1783 __node<_CharT>* __s)
1784 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1785
1786 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00001787};
1788
1789template <class _CharT, class _Traits>
1790void
1791__back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
1792{
1793 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1794 if (__sm.matched)
1795 {
1796 ptrdiff_t __len = __sm.second - __sm.first;
1797 if (__s.__last_ - __s.__current_ >= __len)
1798 {
1799 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1800 {
1801 if (__traits_.translate(__sm.first[__i]) !=
1802 __traits_.translate(__s.__current_[__i]))
1803 goto __not_equal;
1804 }
1805 __s.__do_ = __state::__accept_but_not_consume;
1806 __s.__current_ += __len;
1807 __s.__node_ = this->first();
1808 }
1809 else
1810 {
1811 __s.__do_ = __state::__reject;
1812 __s.__node_ = nullptr;
1813 }
1814 }
1815 else
1816 {
1817__not_equal:
1818 __s.__do_ = __state::__reject;
1819 __s.__node_ = nullptr;
1820 }
1821}
1822
Howard Hinnant17615b02010-07-27 01:25:38 +00001823// __word_boundary
1824
1825template <class _CharT, class _Traits>
1826class __word_boundary
1827 : public __owns_one_state<_CharT>
1828{
1829 typedef __owns_one_state<_CharT> base;
1830
1831 _Traits __traits_;
1832 bool __invert_;
1833public:
1834 typedef _STD::__state<_CharT> __state;
1835
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant17615b02010-07-27 01:25:38 +00001837 explicit __word_boundary(const _Traits& __traits, bool __invert,
1838 __node<_CharT>* __s)
1839 : base(__s), __traits_(__traits), __invert_(__invert) {}
1840
1841 virtual void __exec(__state&) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00001842};
1843
1844template <class _CharT, class _Traits>
1845void
1846__word_boundary<_CharT, _Traits>::__exec(__state& __s) const
1847{
1848 bool __is_word_b = false;
1849 if (__s.__first_ != __s.__last_)
1850 {
1851 if (__s.__current_ == __s.__last_)
1852 {
1853 if (!(__s.__flags_ & regex_constants::match_not_eow))
1854 {
1855 _CharT __c = __s.__current_[-1];
1856 __is_word_b = __c == '_' ||
1857 __traits_.isctype(__c, ctype_base::alnum);
1858 }
1859 }
Howard Hinnantf3dcca02010-07-29 15:17:28 +00001860 else if (__s.__current_ == __s.__first_ &&
1861 !(__s.__flags_ & regex_constants::match_prev_avail))
Howard Hinnant17615b02010-07-27 01:25:38 +00001862 {
1863 if (!(__s.__flags_ & regex_constants::match_not_bow))
1864 {
1865 _CharT __c = *__s.__current_;
1866 __is_word_b = __c == '_' ||
1867 __traits_.isctype(__c, ctype_base::alnum);
1868 }
1869 }
1870 else
1871 {
1872 _CharT __c1 = __s.__current_[-1];
1873 _CharT __c2 = *__s.__current_;
1874 bool __is_c1_b = __c1 == '_' ||
1875 __traits_.isctype(__c1, ctype_base::alnum);
1876 bool __is_c2_b = __c2 == '_' ||
1877 __traits_.isctype(__c2, ctype_base::alnum);
1878 __is_word_b = __is_c1_b != __is_c2_b;
1879 }
1880 }
1881 if (__is_word_b != __invert_)
1882 {
1883 __s.__do_ = __state::__accept_but_not_consume;
1884 __s.__node_ = this->first();
1885 }
1886 else
1887 {
1888 __s.__do_ = __state::__reject;
1889 __s.__node_ = nullptr;
1890 }
1891}
1892
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001893// __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001894
1895template <class _CharT>
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001896class __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001897 : public __owns_one_state<_CharT>
1898{
1899 typedef __owns_one_state<_CharT> base;
1900
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001901public:
Howard Hinnantac303862010-07-12 15:51:17 +00001902 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001903
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001905 __r_anchor(__node<_CharT>* __s)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001906 : base(__s) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001907
Howard Hinnantac303862010-07-12 15:51:17 +00001908 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001909};
1910
1911template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001912void
1913__r_anchor<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001914{
Howard Hinnantac303862010-07-12 15:51:17 +00001915 if (__s.__current_ == __s.__last_)
1916 {
1917 __s.__do_ = __state::__accept_but_not_consume;
1918 __s.__node_ = this->first();
1919 }
1920 else
1921 {
1922 __s.__do_ = __state::__reject;
1923 __s.__node_ = nullptr;
1924 }
1925}
1926
1927// __match_any
1928
1929template <class _CharT>
1930class __match_any
1931 : public __owns_one_state<_CharT>
1932{
1933 typedef __owns_one_state<_CharT> base;
1934
1935public:
1936 typedef _STD::__state<_CharT> __state;
1937
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001938 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001939 __match_any(__node<_CharT>* __s)
1940 : base(__s) {}
1941
1942 virtual void __exec(__state&) const;
Howard Hinnantac303862010-07-12 15:51:17 +00001943};
1944
1945template <class _CharT>
1946void
1947__match_any<_CharT>::__exec(__state& __s) const
1948{
1949 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
1950 {
1951 __s.__do_ = __state::__accept_and_consume;
1952 ++__s.__current_;
1953 __s.__node_ = this->first();
1954 }
1955 else
1956 {
1957 __s.__do_ = __state::__reject;
1958 __s.__node_ = nullptr;
1959 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001960}
1961
Howard Hinnant17615b02010-07-27 01:25:38 +00001962// __match_any_but_newline
1963
1964template <class _CharT>
1965class __match_any_but_newline
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 Hinnant17615b02010-07-27 01:25:38 +00001974 __match_any_but_newline(__node<_CharT>* __s)
1975 : base(__s) {}
1976
1977 virtual void __exec(__state&) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00001978};
1979
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001980// __match_char
1981
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001982template <class _CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001983class __match_char
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001984 : public __owns_one_state<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001985{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001986 typedef __owns_one_state<_CharT> base;
1987
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001988 _CharT __c_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001989
1990 __match_char(const __match_char&);
1991 __match_char& operator=(const __match_char&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001992public:
Howard Hinnantac303862010-07-12 15:51:17 +00001993 typedef _STD::__state<_CharT> __state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001994
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001996 __match_char(_CharT __c, __node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001997 : base(__s), __c_(__c) {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001998
Howard Hinnantac303862010-07-12 15:51:17 +00001999 virtual void __exec(__state&) const;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002000};
2001
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002002template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00002003void
2004__match_char<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002005{
Howard Hinnantac303862010-07-12 15:51:17 +00002006 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
2007 {
2008 __s.__do_ = __state::__accept_and_consume;
2009 ++__s.__current_;
2010 __s.__node_ = this->first();
2011 }
2012 else
2013 {
2014 __s.__do_ = __state::__reject;
2015 __s.__node_ = nullptr;
2016 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002017}
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002018
Howard Hinnante34f17d2010-07-12 19:11:27 +00002019// __match_char_icase
2020
2021template <class _CharT, class _Traits>
2022class __match_char_icase
2023 : public __owns_one_state<_CharT>
2024{
2025 typedef __owns_one_state<_CharT> base;
2026
2027 _Traits __traits_;
2028 _CharT __c_;
2029
2030 __match_char_icase(const __match_char_icase&);
2031 __match_char_icase& operator=(const __match_char_icase&);
2032public:
2033 typedef _STD::__state<_CharT> __state;
2034
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00002036 __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2037 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
2038
2039 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00002040};
2041
2042template <class _CharT, class _Traits>
2043void
2044__match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
2045{
2046 if (__s.__current_ != __s.__last_ &&
2047 __traits_.translate_nocase(*__s.__current_) == __c_)
2048 {
2049 __s.__do_ = __state::__accept_and_consume;
2050 ++__s.__current_;
2051 __s.__node_ = this->first();
2052 }
2053 else
2054 {
2055 __s.__do_ = __state::__reject;
2056 __s.__node_ = nullptr;
2057 }
2058}
2059
2060// __match_char_collate
2061
2062template <class _CharT, class _Traits>
2063class __match_char_collate
2064 : public __owns_one_state<_CharT>
2065{
2066 typedef __owns_one_state<_CharT> base;
2067
2068 _Traits __traits_;
2069 _CharT __c_;
2070
2071 __match_char_collate(const __match_char_collate&);
2072 __match_char_collate& operator=(const __match_char_collate&);
2073public:
2074 typedef _STD::__state<_CharT> __state;
2075
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00002077 __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2078 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2079
2080 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00002081};
2082
2083template <class _CharT, class _Traits>
2084void
2085__match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
2086{
2087 if (__s.__current_ != __s.__last_ &&
2088 __traits_.translate(*__s.__current_) == __c_)
2089 {
2090 __s.__do_ = __state::__accept_and_consume;
2091 ++__s.__current_;
2092 __s.__node_ = this->first();
2093 }
2094 else
2095 {
2096 __s.__do_ = __state::__reject;
2097 __s.__node_ = nullptr;
2098 }
2099}
2100
Howard Hinnant173968a2010-07-13 21:48:06 +00002101// __bracket_expression
2102
2103template <class _CharT, class _Traits>
2104class __bracket_expression
2105 : public __owns_one_state<_CharT>
2106{
2107 typedef __owns_one_state<_CharT> base;
2108 typedef typename _Traits::string_type string_type;
2109
2110 _Traits __traits_;
2111 vector<_CharT> __chars_;
Howard Hinnant15476f32010-07-28 17:35:27 +00002112 vector<_CharT> __neg_chars_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002113 vector<pair<string_type, string_type> > __ranges_;
2114 vector<pair<_CharT, _CharT> > __digraphs_;
2115 vector<string_type> __equivalences_;
2116 ctype_base::mask __mask_;
Howard Hinnant15476f32010-07-28 17:35:27 +00002117 ctype_base::mask __neg_mask_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002118 bool __negate_;
2119 bool __icase_;
2120 bool __collate_;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002121 bool __might_have_digraph_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002122
2123 __bracket_expression(const __bracket_expression&);
2124 __bracket_expression& operator=(const __bracket_expression&);
2125public:
2126 typedef _STD::__state<_CharT> __state;
2127
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002129 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
2130 bool __negate, bool __icase, bool __collate)
Howard Hinnant15476f32010-07-28 17:35:27 +00002131 : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
2132 __negate_(__negate), __icase_(__icase), __collate_(__collate),
Howard Hinnant68025ed2010-07-14 15:45:11 +00002133 __might_have_digraph_(__traits_.getloc().name() != "C") {}
Howard Hinnant173968a2010-07-13 21:48:06 +00002134
2135 virtual void __exec(__state&) const;
2136
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant15476f32010-07-28 17:35:27 +00002138 bool __negated() const {return __negate_;}
2139
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002141 void __add_char(_CharT __c)
2142 {
2143 if (__icase_)
2144 __chars_.push_back(__traits_.translate_nocase(__c));
2145 else if (__collate_)
2146 __chars_.push_back(__traits_.translate(__c));
2147 else
2148 __chars_.push_back(__c);
2149 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant15476f32010-07-28 17:35:27 +00002151 void __add_neg_char(_CharT __c)
2152 {
2153 if (__icase_)
2154 __neg_chars_.push_back(__traits_.translate_nocase(__c));
2155 else if (__collate_)
2156 __neg_chars_.push_back(__traits_.translate(__c));
2157 else
2158 __neg_chars_.push_back(__c);
2159 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002161 void __add_range(string_type __b, string_type __e)
2162 {
2163 if (__collate_)
2164 {
2165 if (__icase_)
2166 {
2167 for (size_t __i = 0; __i < __b.size(); ++__i)
2168 __b[__i] = __traits_.translate_nocase(__b[__i]);
2169 for (size_t __i = 0; __i < __e.size(); ++__i)
2170 __e[__i] = __traits_.translate_nocase(__e[__i]);
2171 }
2172 else
2173 {
2174 for (size_t __i = 0; __i < __b.size(); ++__i)
2175 __b[__i] = __traits_.translate(__b[__i]);
2176 for (size_t __i = 0; __i < __e.size(); ++__i)
2177 __e[__i] = __traits_.translate(__e[__i]);
2178 }
2179 __ranges_.push_back(make_pair(
2180 __traits_.transform(__b.begin(), __b.end()),
2181 __traits_.transform(__e.begin(), __e.end())));
2182 }
2183 else
2184 {
Howard Hinnantd4444702010-08-11 17:04:31 +00002185#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00002186 if (__b.size() != 1 || __e.size() != 1)
2187 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00002188#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00002189 if (__icase_)
2190 {
2191 __b[0] = __traits_.translate_nocase(__b[0]);
2192 __e[0] = __traits_.translate_nocase(__e[0]);
2193 }
2194 __ranges_.push_back(make_pair(_STD::move(__b), _STD::move(__e)));
2195 }
2196 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002197 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002198 void __add_digraph(_CharT __c1, _CharT __c2)
2199 {
2200 if (__icase_)
2201 __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
2202 __traits_.translate_nocase(__c2)));
2203 else if (__collate_)
2204 __digraphs_.push_back(make_pair(__traits_.translate(__c1),
2205 __traits_.translate(__c2)));
2206 else
2207 __digraphs_.push_back(make_pair(__c1, __c2));
2208 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002209 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002210 void __add_equivalence(const string_type& __s)
2211 {__equivalences_.push_back(__s);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002213 void __add_class(ctype_base::mask __mask)
2214 {__mask_ |= __mask;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant15476f32010-07-28 17:35:27 +00002216 void __add_neg_class(ctype_base::mask __mask)
2217 {__neg_mask_ |= __mask;}
Howard Hinnant173968a2010-07-13 21:48:06 +00002218};
2219
2220template <class _CharT, class _Traits>
2221void
2222__bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
2223{
2224 bool __found = false;
2225 unsigned __consumed = 0;
2226 if (__s.__current_ != __s.__last_)
2227 {
2228 ++__consumed;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002229 if (__might_have_digraph_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002230 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002231 const _CharT* __next = next(__s.__current_);
2232 if (__next != __s.__last_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002233 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002234 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2235 if (__icase_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002236 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002237 __ch2.first = __traits_.translate_nocase(__ch2.first);
2238 __ch2.second = __traits_.translate_nocase(__ch2.second);
2239 }
2240 else if (__collate_)
2241 {
2242 __ch2.first = __traits_.translate(__ch2.first);
2243 __ch2.second = __traits_.translate(__ch2.second);
2244 }
2245 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
2246 {
2247 // __ch2 is a digraph in this locale
2248 ++__consumed;
2249 for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
2250 {
2251 if (__ch2 == __digraphs_[__i])
2252 {
2253 __found = true;
2254 goto __exit;
2255 }
2256 }
2257 if (__collate_ && !__ranges_.empty())
2258 {
2259 string_type __s2 = __traits_.transform(&__ch2.first,
2260 &__ch2.first + 2);
2261 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2262 {
2263 if (__ranges_[__i].first <= __s2 &&
2264 __s2 <= __ranges_[__i].second)
2265 {
2266 __found = true;
2267 goto __exit;
2268 }
2269 }
2270 }
2271 if (!__equivalences_.empty())
2272 {
2273 string_type __s2 = __traits_.transform_primary(&__ch2.first,
2274 &__ch2.first + 2);
2275 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2276 {
2277 if (__s2 == __equivalences_[__i])
2278 {
2279 __found = true;
2280 goto __exit;
2281 }
2282 }
2283 }
2284 if (__traits_.isctype(__ch2.first, __mask_) &&
2285 __traits_.isctype(__ch2.second, __mask_))
Howard Hinnant173968a2010-07-13 21:48:06 +00002286 {
2287 __found = true;
2288 goto __exit;
2289 }
Howard Hinnant15476f32010-07-28 17:35:27 +00002290 if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
2291 !__traits_.isctype(__ch2.second, __neg_mask_))
2292 {
2293 __found = true;
2294 goto __exit;
2295 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002296 goto __exit;
2297 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002298 }
2299 }
2300 // test *__s.__current_ as not a digraph
2301 _CharT __ch = *__s.__current_;
2302 if (__icase_)
2303 __ch = __traits_.translate_nocase(__ch);
2304 else if (__collate_)
2305 __ch = __traits_.translate(__ch);
2306 for (size_t __i = 0; __i < __chars_.size(); ++__i)
2307 {
2308 if (__ch == __chars_[__i])
2309 {
2310 __found = true;
2311 goto __exit;
2312 }
2313 }
Howard Hinnant15476f32010-07-28 17:35:27 +00002314 if (!__neg_chars_.empty())
2315 {
2316 for (size_t __i = 0; __i < __neg_chars_.size(); ++__i)
2317 {
2318 if (__ch == __neg_chars_[__i])
2319 goto __is_neg_char;
2320 }
2321 __found = true;
2322 goto __exit;
2323 }
2324__is_neg_char:
Howard Hinnant173968a2010-07-13 21:48:06 +00002325 if (!__ranges_.empty())
2326 {
2327 string_type __s2 = __collate_ ?
2328 __traits_.transform(&__ch, &__ch + 1) :
2329 string_type(1, __ch);
2330 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2331 {
2332 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
2333 {
2334 __found = true;
2335 goto __exit;
2336 }
2337 }
2338 }
2339 if (!__equivalences_.empty())
2340 {
2341 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2342 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2343 {
2344 if (__s2 == __equivalences_[__i])
2345 {
2346 __found = true;
2347 goto __exit;
2348 }
2349 }
2350 }
2351 if (__traits_.isctype(__ch, __mask_))
Howard Hinnant15476f32010-07-28 17:35:27 +00002352 {
Howard Hinnant173968a2010-07-13 21:48:06 +00002353 __found = true;
Howard Hinnant15476f32010-07-28 17:35:27 +00002354 goto __exit;
2355 }
2356 if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_))
2357 {
2358 __found = true;
2359 goto __exit;
2360 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002361 }
2362 else
2363 __found = __negate_; // force reject
2364__exit:
2365 if (__found != __negate_)
2366 {
Howard Hinnant173968a2010-07-13 21:48:06 +00002367 __s.__do_ = __state::__accept_and_consume;
2368 __s.__current_ += __consumed;
2369 __s.__node_ = this->first();
2370 }
2371 else
2372 {
2373 __s.__do_ = __state::__reject;
2374 __s.__node_ = nullptr;
2375 }
2376}
2377
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002378template <class, class> class __lookahead;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002379
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002380template <class _CharT, class _Traits = regex_traits<_CharT> >
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002381class _LIBCPP_VISIBLE basic_regex
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002382{
2383public:
2384 // types:
2385 typedef _CharT value_type;
2386 typedef regex_constants::syntax_option_type flag_type;
2387 typedef typename _Traits::locale_type locale_type;
2388
2389private:
2390 _Traits __traits_;
2391 flag_type __flags_;
2392 unsigned __marked_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002393 unsigned __loop_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002394 int __open_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002395 shared_ptr<__empty_state<_CharT> > __start_;
2396 __owns_one_state<_CharT>* __end_;
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002397 bool __left_anchor_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002398
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002399 typedef _STD::__state<_CharT> __state;
Howard Hinnantac303862010-07-12 15:51:17 +00002400 typedef _STD::__node<_CharT> __node;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002401
2402public:
2403 // constants:
2404 static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase;
2405 static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2406 static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize;
2407 static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate;
2408 static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2409 static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic;
2410 static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended;
2411 static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk;
2412 static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep;
2413 static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep;
2414
2415 // construct/copy/destroy:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002416 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002417 basic_regex()
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002418 : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0),
2419 __end_(0), __left_anchor_(false)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002420 {}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002422 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002423 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2424 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002425 {__parse(__p, __p + __traits_.length(__p));}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002427 basic_regex(const value_type* __p, size_t __len, flag_type __f)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002428 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2429 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002430 {__parse(__p, __p + __len);}
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002431// basic_regex(const basic_regex&) = default;
2432// basic_regex(basic_regex&&) = default;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002433 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002435 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2436 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002437 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2438 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002439 {__parse(__p.begin(), __p.end());}
2440 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002441 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002442 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
2443 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002444 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2445 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002446 {__parse(__first, __last);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002448 basic_regex(initializer_list<value_type> __il,
2449 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002450 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2451 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002452 {__parse(__il.begin(), __il.end());}
2453
Howard Hinnant7026a172010-08-13 18:11:23 +00002454// ~basic_regex() = default;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002455
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002456// basic_regex& operator=(const basic_regex&) = default;
2457// basic_regex& operator=(basic_regex&&) = default;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002459 basic_regex& operator=(const value_type* __p)
2460 {return assign(__p);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002462 basic_regex& operator=(initializer_list<value_type> __il)
2463 {return assign(__il);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002464 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002466 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
2467 {return assign(__p);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002468
2469 // assign:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002470 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002471 basic_regex& assign(const basic_regex& __that)
2472 {return *this = __that;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002473 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002474 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2475 {return assign(__p, __p + __traits_.length(__p), __f);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002477 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f)
2478 {return assign(__p, __p + __len, __f);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002479 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002481 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
Howard Hinnant7026a172010-08-13 18:11:23 +00002482 flag_type __f = regex_constants::ECMAScript)
2483 {return assign(__s.begin(), __s.end(), __f);}
2484
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002485 template <class _InputIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002486 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002487 typename enable_if
2488 <
2489 __is_input_iterator <_InputIterator>::value &&
2490 !__is_forward_iterator<_InputIterator>::value,
2491 basic_regex&
2492 >::type
2493 assign(_InputIterator __first, _InputIterator __last,
2494 flag_type __f = regex_constants::ECMAScript)
2495 {
2496 basic_string<_CharT> __t(__first, __last);
2497 return assign(__t.begin(), __t.end(), __f);
2498 }
2499
2500private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002501 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002502 void __member_init(flag_type __f)
2503 {
2504 __flags_ = __f;
2505 __marked_count_ = 0;
2506 __loop_count_ = 0;
2507 __open_count_ = 0;
2508 __end_ = nullptr;
2509 __left_anchor_ = false;
2510 }
2511public:
2512
2513 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002514 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002515 typename enable_if
2516 <
2517 __is_forward_iterator<_ForwardIterator>::value,
2518 basic_regex&
2519 >::type
2520 assign(_ForwardIterator __first, _ForwardIterator __last,
2521 flag_type __f = regex_constants::ECMAScript)
2522 {
2523 __member_init(__f);
2524 __parse(__first, __last);
2525 }
2526
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002528 basic_regex& assign(initializer_list<value_type> __il,
Howard Hinnant7026a172010-08-13 18:11:23 +00002529 flag_type __f = regex_constants::ECMAScript)
2530 {return assign(__il.begin(), __il.end(), __f);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002531
2532 // const operations:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002534 unsigned mark_count() const {return __marked_count_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002536 flag_type flags() const {return __flags_;}
2537
2538 // locale:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002540 locale_type imbue(locale_type __loc)
2541 {
2542 __member_init(ECMAScript);
2543 __start_.reset();
2544 return __traits_.imbue(__loc);
2545 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002547 locale_type getloc() const {return __traits_.getloc();}
2548
2549 // swap:
Howard Hinnant7026a172010-08-13 18:11:23 +00002550 void swap(basic_regex& __r);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002551
2552private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002554 unsigned __loop_count() const {return __loop_count_;}
2555
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002556 template <class _ForwardIterator>
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002557 _ForwardIterator
2558 __parse(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002559 template <class _ForwardIterator>
2560 _ForwardIterator
2561 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2562 template <class _ForwardIterator>
2563 _ForwardIterator
2564 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2565 template <class _ForwardIterator>
2566 _ForwardIterator
2567 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2568 template <class _ForwardIterator>
2569 _ForwardIterator
2570 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2571 template <class _ForwardIterator>
2572 _ForwardIterator
2573 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2574 template <class _ForwardIterator>
2575 _ForwardIterator
2576 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2577 template <class _ForwardIterator>
2578 _ForwardIterator
2579 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2580 template <class _ForwardIterator>
2581 _ForwardIterator
2582 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2583 template <class _ForwardIterator>
2584 _ForwardIterator
2585 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2586 template <class _ForwardIterator>
2587 _ForwardIterator
2588 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2589 template <class _ForwardIterator>
2590 _ForwardIterator
2591 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2592 template <class _ForwardIterator>
2593 _ForwardIterator
2594 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2595 template <class _ForwardIterator>
2596 _ForwardIterator
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002597 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002598 __owns_one_state<_CharT>* __s,
2599 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002600 template <class _ForwardIterator>
2601 _ForwardIterator
Howard Hinnantaa698082010-07-16 19:08:36 +00002602 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2603 __owns_one_state<_CharT>* __s,
2604 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002605 template <class _ForwardIterator>
2606 _ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00002607 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2608 template <class _ForwardIterator>
2609 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002610 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
2611 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002612 template <class _ForwardIterator>
2613 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002614 __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
2615 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002616 template <class _ForwardIterator>
2617 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002618 __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
2619 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002620 template <class _ForwardIterator>
2621 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002622 __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
2623 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002624 template <class _ForwardIterator>
2625 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002626 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
2627 basic_string<_CharT>& __col_sym);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002628 template <class _ForwardIterator>
2629 _ForwardIterator
2630 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002631 template <class _ForwardIterator>
2632 _ForwardIterator
2633 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2634 template <class _ForwardIterator>
2635 _ForwardIterator
2636 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2637 template <class _ForwardIterator>
2638 _ForwardIterator
2639 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2640 template <class _ForwardIterator>
2641 _ForwardIterator
2642 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2643 template <class _ForwardIterator>
2644 _ForwardIterator
2645 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2646 template <class _ForwardIterator>
2647 _ForwardIterator
2648 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002649 template <class _ForwardIterator>
2650 _ForwardIterator
2651 __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2652 template <class _ForwardIterator>
2653 _ForwardIterator
2654 __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2655 template <class _ForwardIterator>
2656 _ForwardIterator
2657 __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2658 template <class _ForwardIterator>
2659 _ForwardIterator
2660 __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2661 template <class _ForwardIterator>
2662 _ForwardIterator
2663 __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2664 template <class _ForwardIterator>
2665 _ForwardIterator
Howard Hinnant17615b02010-07-27 01:25:38 +00002666 __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2667 template <class _ForwardIterator>
2668 _ForwardIterator
2669 __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2670 template <class _ForwardIterator>
2671 _ForwardIterator
2672 __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2673 template <class _ForwardIterator>
2674 _ForwardIterator
Howard Hinnant15476f32010-07-28 17:35:27 +00002675 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
2676 basic_string<_CharT>* __str = nullptr);
Howard Hinnant17615b02010-07-27 01:25:38 +00002677 template <class _ForwardIterator>
2678 _ForwardIterator
2679 __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant856846b2010-07-27 19:53:10 +00002680 template <class _ForwardIterator>
2681 _ForwardIterator
2682 __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
2683 template <class _ForwardIterator>
2684 _ForwardIterator
2685 __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant15476f32010-07-28 17:35:27 +00002686 template <class _ForwardIterator>
2687 _ForwardIterator
2688 __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
2689 basic_string<_CharT>& __str,
2690 __bracket_expression<_CharT, _Traits>* __ml);
2691 template <class _ForwardIterator>
2692 _ForwardIterator
2693 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
2694 basic_string<_CharT>* __str = nullptr);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002695
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002697 void __push_l_anchor() {__left_anchor_ = true;}
2698 void __push_r_anchor();
Howard Hinnantac303862010-07-12 15:51:17 +00002699 void __push_match_any();
Howard Hinnant17615b02010-07-27 01:25:38 +00002700 void __push_match_any_but_newline();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002701 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002702 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2703 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2704 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2705 __mexp_begin, __mexp_end);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant17615b02010-07-27 01:25:38 +00002707 void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2708 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2709 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2710 __mexp_begin, __mexp_end, false);}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002711 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2712 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2713 bool __greedy = true);
Howard Hinnant173968a2010-07-13 21:48:06 +00002714 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002715 void __push_char(value_type __c);
Howard Hinnantcba352d2010-07-12 18:16:05 +00002716 void __push_back_ref(int __i);
Howard Hinnantaa698082010-07-16 19:08:36 +00002717 void __push_alternation(__owns_one_state<_CharT>* __sa,
2718 __owns_one_state<_CharT>* __sb);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002719 void __push_begin_marked_subexpression();
2720 void __push_end_marked_subexpression(unsigned);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002721 void __push_empty();
Howard Hinnant17615b02010-07-27 01:25:38 +00002722 void __push_word_boundary(bool);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002723 void __push_lookahead(const basic_regex&, bool);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002724
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002725 template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002726 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002727 __search(const _CharT* __first, const _CharT* __last,
2728 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002729 regex_constants::match_flag_type __flags) const;
2730
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002731 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002732 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002733 __match_at_start(const _CharT* __first, const _CharT* __last,
2734 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002735 regex_constants::match_flag_type __flags) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00002736 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002737 bool
Howard Hinnant17615b02010-07-27 01:25:38 +00002738 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
2739 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002740 regex_constants::match_flag_type __flags) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002741 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002742 bool
2743 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002744 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002745 regex_constants::match_flag_type __flags) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002746 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002747 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002748 __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
2749 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002750 regex_constants::match_flag_type __flags) const;
2751
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002752 template <class _B, class _A, class _C, class _T>
2753 friend
2754 bool
2755 regex_search(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
2756 regex_constants::match_flag_type);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002757
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002758 template <class _A, class _C, class _T>
2759 friend
2760 bool
2761 regex_search(const _C*, const _C*, match_results<const _C*, _A>&,
2762 const basic_regex<_C, _T>&, regex_constants::match_flag_type);
2763
2764 template <class _B, class _C, class _T>
2765 friend
2766 bool
2767 regex_search(_B, _B, const basic_regex<_C, _T>&,
2768 regex_constants::match_flag_type);
2769
2770 template <class _C, class _T>
2771 friend
2772 bool
2773 regex_search(const _C*, const _C*,
2774 const basic_regex<_C, _T>&, regex_constants::match_flag_type);
2775
2776 template <class _C, class _A, class _T>
2777 friend
2778 bool
2779 regex_search(const _C*, match_results<const _C*, _A>&, const basic_regex<_C, _T>&,
2780 regex_constants::match_flag_type);
2781
2782 template <class _ST, class _SA, class _C, class _T>
2783 friend
2784 bool
2785 regex_search(const basic_string<_C, _ST, _SA>& __s,
2786 const basic_regex<_C, _T>& __e,
2787 regex_constants::match_flag_type __flags);
2788
2789 template <class _ST, class _SA, class _A, class _C, class _T>
2790 friend
2791 bool
2792 regex_search(const basic_string<_C, _ST, _SA>& __s,
Howard Hinnant324bb032010-08-22 00:02:43 +00002793 match_results<typename basic_string<_C, _ST, _SA>::const_iterator, _A>&,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002794 const basic_regex<_C, _T>& __e,
2795 regex_constants::match_flag_type __flags);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002796
2797 template <class, class> friend class __lookahead;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002798};
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002799
2800template <class _CharT, class _Traits>
Howard Hinnant7026a172010-08-13 18:11:23 +00002801void
2802basic_regex<_CharT, _Traits>::swap(basic_regex& __r)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002803{
Howard Hinnant7026a172010-08-13 18:11:23 +00002804 using _STD::swap;
2805 swap(__traits_, __r.__traits_);
2806 swap(__flags_, __r.__flags_);
2807 swap(__marked_count_, __r.__marked_count_);
2808 swap(__loop_count_, __r.__loop_count_);
2809 swap(__open_count_, __r.__open_count_);
2810 swap(__start_, __r.__start_);
2811 swap(__end_, __r.__end_);
2812 swap(__left_anchor_, __r.__left_anchor_);
2813}
2814
2815template <class _CharT, class _Traits>
2816inline _LIBCPP_INLINE_VISIBILITY
2817void
2818swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
2819{
2820 return __x.swap(__y);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002821}
2822
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002823// __lookahead
2824
2825template <class _CharT, class _Traits>
2826class __lookahead
2827 : public __owns_one_state<_CharT>
2828{
2829 typedef __owns_one_state<_CharT> base;
2830
2831 basic_regex<_CharT, _Traits> __exp_;
2832 bool __invert_;
2833
2834 __lookahead(const __lookahead&);
2835 __lookahead& operator=(const __lookahead&);
2836public:
2837 typedef _STD::__state<_CharT> __state;
2838
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002839 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002840 __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s)
2841 : base(__s), __exp_(__exp), __invert_(__invert) {}
2842
2843 virtual void __exec(__state&) const;
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002844};
2845
2846template <class _CharT, class _Traits>
2847void
2848__lookahead<_CharT, _Traits>::__exec(__state& __s) const
2849{
2850 match_results<const _CharT*> __m;
2851 __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
2852 bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
2853 __m, __s.__flags_);
2854 if (__matched != __invert_)
2855 {
2856 __s.__do_ = __state::__accept_but_not_consume;
2857 __s.__node_ = this->first();
2858 }
2859 else
2860 {
2861 __s.__do_ = __state::__reject;
2862 __s.__node_ = nullptr;
2863 }
2864}
2865
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002866template <class _CharT, class _Traits>
2867template <class _ForwardIterator>
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002868_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002869basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
2870 _ForwardIterator __last)
2871{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002872 {
Howard Hinnantac303862010-07-12 15:51:17 +00002873 unique_ptr<__node> __h(new __end_state<_CharT>);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002874 __start_.reset(new __empty_state<_CharT>(__h.get()));
2875 __h.release();
2876 __end_ = __start_.get();
2877 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002878 switch (__flags_ & 0x1F0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002879 {
2880 case ECMAScript:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002881 __first = __parse_ecma_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002882 break;
2883 case basic:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002884 __first = __parse_basic_reg_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002885 break;
2886 case extended:
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002887 case awk:
Howard Hinnant15476f32010-07-28 17:35:27 +00002888 __first = __parse_extended_reg_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002889 break;
2890 case grep:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002891 __first = __parse_grep(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002892 break;
2893 case egrep:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002894 __first = __parse_egrep(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002895 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00002896#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002897 default:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002898 throw regex_error(regex_constants::__re_err_grammar);
Howard Hinnant324bb032010-08-22 00:02:43 +00002899#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002900 }
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002901 return __first;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002902}
2903
2904template <class _CharT, class _Traits>
2905template <class _ForwardIterator>
2906_ForwardIterator
2907basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
2908 _ForwardIterator __last)
2909{
2910 if (__first != __last)
2911 {
2912 if (*__first == '^')
2913 {
2914 __push_l_anchor();
2915 ++__first;
2916 }
2917 if (__first != __last)
2918 {
2919 __first = __parse_RE_expression(__first, __last);
2920 if (__first != __last)
2921 {
2922 _ForwardIterator __temp = next(__first);
2923 if (__temp == __last && *__first == '$')
2924 {
2925 __push_r_anchor();
2926 ++__first;
2927 }
2928 }
2929 }
Howard Hinnantd4444702010-08-11 17:04:31 +00002930#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002931 if (__first != __last)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002932 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00002933#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002934 }
2935 return __first;
2936}
2937
2938template <class _CharT, class _Traits>
2939template <class _ForwardIterator>
2940_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002941basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
2942 _ForwardIterator __last)
2943{
Howard Hinnantaa698082010-07-16 19:08:36 +00002944 __owns_one_state<_CharT>* __sa = __end_;
2945 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00002946#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa698082010-07-16 19:08:36 +00002947 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002948 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00002949#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa698082010-07-16 19:08:36 +00002950 __first = __temp;
2951 while (__first != __last && *__first == '|')
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002952 {
Howard Hinnantaa698082010-07-16 19:08:36 +00002953 __owns_one_state<_CharT>* __sb = __end_;
2954 __temp = __parse_ERE_branch(++__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00002955#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002956 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002957 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00002958#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa698082010-07-16 19:08:36 +00002959 __push_alternation(__sa, __sb);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002960 __first = __temp;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002961 }
2962 return __first;
2963}
2964
2965template <class _CharT, class _Traits>
2966template <class _ForwardIterator>
2967_ForwardIterator
2968basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
2969 _ForwardIterator __last)
2970{
2971 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00002972#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002973 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002974 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00002975#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002976 do
2977 {
2978 __first = __temp;
2979 __temp = __parse_ERE_expression(__first, __last);
2980 } while (__temp != __first);
2981 return __first;
2982}
2983
2984template <class _CharT, class _Traits>
2985template <class _ForwardIterator>
2986_ForwardIterator
2987basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
2988 _ForwardIterator __last)
2989{
Howard Hinnantaa698082010-07-16 19:08:36 +00002990 __owns_one_state<_CharT>* __e = __end_;
2991 unsigned __mexp_begin = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002992 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
2993 if (__temp == __first && __temp != __last)
2994 {
2995 switch (*__temp)
2996 {
2997 case '^':
2998 __push_l_anchor();
2999 ++__temp;
3000 break;
3001 case '$':
3002 __push_r_anchor();
3003 ++__temp;
3004 break;
3005 case '(':
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003006 __push_begin_marked_subexpression();
3007 unsigned __temp_count = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003008 ++__open_count_;
3009 __temp = __parse_extended_reg_exp(++__temp, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003010#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003011 if (__temp == __last || *__temp != ')')
3012 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00003013#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003014 __push_end_marked_subexpression(__temp_count);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003015 --__open_count_;
3016 ++__temp;
3017 break;
3018 }
3019 }
3020 if (__temp != __first)
Howard Hinnantaa698082010-07-16 19:08:36 +00003021 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
3022 __marked_count_+1);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003023 __first = __temp;
3024 return __first;
3025}
3026
3027template <class _CharT, class _Traits>
3028template <class _ForwardIterator>
3029_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003030basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
3031 _ForwardIterator __last)
3032{
3033 while (true)
3034 {
3035 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
3036 if (__temp == __first)
3037 break;
3038 __first = __temp;
3039 }
3040 return __first;
3041}
3042
3043template <class _CharT, class _Traits>
3044template <class _ForwardIterator>
3045_ForwardIterator
3046basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
3047 _ForwardIterator __last)
3048{
3049 if (__first != __last)
3050 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003051 __owns_one_state<_CharT>* __e = __end_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003052 unsigned __mexp_begin = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003053 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
3054 if (__temp != __first)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003055 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
3056 __mexp_begin+1, __marked_count_+1);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003057 }
3058 return __first;
3059}
3060
3061template <class _CharT, class _Traits>
3062template <class _ForwardIterator>
3063_ForwardIterator
3064basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
3065 _ForwardIterator __last)
3066{
3067 _ForwardIterator __temp = __first;
3068 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
3069 if (__temp == __first)
3070 {
3071 __temp = __parse_Back_open_paren(__first, __last);
3072 if (__temp != __first)
3073 {
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003074 __push_begin_marked_subexpression();
3075 unsigned __temp_count = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003076 __first = __parse_RE_expression(__temp, __last);
3077 __temp = __parse_Back_close_paren(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003078#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003079 if (__temp == __first)
3080 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00003081#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003082 __push_end_marked_subexpression(__temp_count);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003083 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003084 }
3085 else
3086 __first = __parse_BACKREF(__first, __last);
3087 }
3088 return __first;
3089}
3090
3091template <class _CharT, class _Traits>
3092template <class _ForwardIterator>
3093_ForwardIterator
3094basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
3095 _ForwardIterator __first,
3096 _ForwardIterator __last)
3097{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003098 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003099 if (__temp == __first)
3100 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003101 __temp = __parse_QUOTED_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003102 if (__temp == __first)
3103 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003104 if (__temp != __last && *__temp == '.')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003105 {
3106 __push_match_any();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003107 ++__temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003108 }
3109 else
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003110 __temp = __parse_bracket_expression(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003111 }
3112 }
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003113 __first = __temp;
3114 return __first;
3115}
3116
3117template <class _CharT, class _Traits>
3118template <class _ForwardIterator>
3119_ForwardIterator
3120basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
3121 _ForwardIterator __first,
3122 _ForwardIterator __last)
3123{
3124 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
3125 if (__temp == __first)
3126 {
3127 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
3128 if (__temp == __first)
3129 {
3130 if (__temp != __last && *__temp == '.')
3131 {
3132 __push_match_any();
3133 ++__temp;
3134 }
3135 else
3136 __temp = __parse_bracket_expression(__first, __last);
3137 }
3138 }
3139 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003140 return __first;
3141}
3142
3143template <class _CharT, class _Traits>
3144template <class _ForwardIterator>
3145_ForwardIterator
3146basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
3147 _ForwardIterator __last)
3148{
3149 if (__first != __last)
3150 {
3151 _ForwardIterator __temp = next(__first);
3152 if (__temp != __last)
3153 {
3154 if (*__first == '\\' && *__temp == '(')
3155 __first = ++__temp;
3156 }
3157 }
3158 return __first;
3159}
3160
3161template <class _CharT, class _Traits>
3162template <class _ForwardIterator>
3163_ForwardIterator
3164basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
3165 _ForwardIterator __last)
3166{
3167 if (__first != __last)
3168 {
3169 _ForwardIterator __temp = next(__first);
3170 if (__temp != __last)
3171 {
3172 if (*__first == '\\' && *__temp == ')')
3173 __first = ++__temp;
3174 }
3175 }
3176 return __first;
3177}
3178
3179template <class _CharT, class _Traits>
3180template <class _ForwardIterator>
3181_ForwardIterator
3182basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
3183 _ForwardIterator __last)
3184{
3185 if (__first != __last)
3186 {
3187 _ForwardIterator __temp = next(__first);
3188 if (__temp != __last)
3189 {
3190 if (*__first == '\\' && *__temp == '{')
3191 __first = ++__temp;
3192 }
3193 }
3194 return __first;
3195}
3196
3197template <class _CharT, class _Traits>
3198template <class _ForwardIterator>
3199_ForwardIterator
3200basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
3201 _ForwardIterator __last)
3202{
3203 if (__first != __last)
3204 {
3205 _ForwardIterator __temp = next(__first);
3206 if (__temp != __last)
3207 {
3208 if (*__first == '\\' && *__temp == '}')
3209 __first = ++__temp;
3210 }
3211 }
3212 return __first;
3213}
3214
3215template <class _CharT, class _Traits>
3216template <class _ForwardIterator>
3217_ForwardIterator
3218basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
3219 _ForwardIterator __last)
3220{
3221 if (__first != __last)
3222 {
3223 _ForwardIterator __temp = next(__first);
3224 if (__temp != __last)
3225 {
3226 if (*__first == '\\' && '1' <= *__temp && *__temp <= '9')
3227 {
3228 __push_back_ref(*__temp - '0');
3229 __first = ++__temp;
3230 }
3231 }
3232 }
3233 return __first;
3234}
3235
3236template <class _CharT, class _Traits>
3237template <class _ForwardIterator>
3238_ForwardIterator
3239basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
3240 _ForwardIterator __last)
3241{
3242 if (__first != __last)
3243 {
3244 _ForwardIterator __temp = next(__first);
3245 if (__temp == __last && *__first == '$')
3246 return __first;
3247 // Not called inside a bracket
3248 if (*__first == '.' || *__first == '\\' || *__first == '[')
3249 return __first;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003250 __push_char(*__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003251 ++__first;
3252 }
3253 return __first;
3254}
3255
3256template <class _CharT, class _Traits>
3257template <class _ForwardIterator>
3258_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003259basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
3260 _ForwardIterator __last)
3261{
3262 if (__first != __last)
3263 {
3264 switch (*__first)
3265 {
3266 case '^':
3267 case '.':
3268 case '[':
3269 case '$':
3270 case '(':
3271 case '|':
3272 case '*':
3273 case '+':
3274 case '?':
3275 case '{':
3276 case '\\':
3277 break;
3278 case ')':
3279 if (__open_count_ == 0)
3280 {
3281 __push_char(*__first);
3282 ++__first;
3283 }
3284 break;
3285 default:
3286 __push_char(*__first);
3287 ++__first;
3288 break;
3289 }
3290 }
3291 return __first;
3292}
3293
3294template <class _CharT, class _Traits>
3295template <class _ForwardIterator>
3296_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003297basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
3298 _ForwardIterator __last)
3299{
3300 if (__first != __last)
3301 {
3302 _ForwardIterator __temp = next(__first);
3303 if (__temp != __last)
3304 {
3305 if (*__first == '\\')
3306 {
3307 switch (*__temp)
3308 {
3309 case '^':
3310 case '.':
3311 case '*':
3312 case '[':
3313 case '$':
3314 case '\\':
Howard Hinnant0de86b62010-06-25 20:56:08 +00003315 __push_char(*__temp);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003316 __first = ++__temp;
3317 break;
3318 }
3319 }
3320 }
3321 }
3322 return __first;
3323}
3324
3325template <class _CharT, class _Traits>
3326template <class _ForwardIterator>
3327_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003328basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
3329 _ForwardIterator __last)
3330{
3331 if (__first != __last)
3332 {
3333 _ForwardIterator __temp = next(__first);
3334 if (__temp != __last)
3335 {
3336 if (*__first == '\\')
3337 {
3338 switch (*__temp)
3339 {
3340 case '^':
3341 case '.':
3342 case '*':
3343 case '[':
3344 case '$':
3345 case '\\':
3346 case '(':
3347 case ')':
3348 case '|':
3349 case '+':
3350 case '?':
3351 case '{':
3352 __push_char(*__temp);
3353 __first = ++__temp;
3354 break;
Howard Hinnant15476f32010-07-28 17:35:27 +00003355 default:
3356 if ((__flags_ & 0x1F0) == awk)
3357 __first = __parse_awk_escape(++__first, __last);
3358 break;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003359 }
3360 }
3361 }
3362 }
3363 return __first;
3364}
3365
3366template <class _CharT, class _Traits>
3367template <class _ForwardIterator>
3368_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003369basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003370 _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003371 __owns_one_state<_CharT>* __s,
3372 unsigned __mexp_begin,
3373 unsigned __mexp_end)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003374{
3375 if (__first != __last)
3376 {
Howard Hinnant0de86b62010-06-25 20:56:08 +00003377 if (*__first == '*')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003378 {
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003379 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003380 ++__first;
3381 }
3382 else
3383 {
3384 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3385 if (__temp != __first)
3386 {
3387 int __min = 0;
3388 __first = __temp;
3389 __temp = __parse_DUP_COUNT(__first, __last, __min);
Howard Hinnantd4444702010-08-11 17:04:31 +00003390#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003391 if (__temp == __first)
3392 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003393#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003394 __first = __temp;
Howard Hinnantd4444702010-08-11 17:04:31 +00003395#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003396 if (__first == __last)
3397 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003398#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003399 if (*__first != ',')
3400 {
3401 __temp = __parse_Back_close_brace(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003402#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003403 if (__temp == __first)
3404 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003405#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcba352d2010-07-12 18:16:05 +00003406 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
3407 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003408 __first = __temp;
3409 }
3410 else
3411 {
3412 ++__first; // consume ','
3413 int __max = -1;
3414 __first = __parse_DUP_COUNT(__first, __last, __max);
3415 __temp = __parse_Back_close_brace(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003416#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003417 if (__temp == __first)
3418 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003419#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003420 if (__max == -1)
Howard Hinnantaa698082010-07-16 19:08:36 +00003421 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003422 else
3423 {
Howard Hinnantd4444702010-08-11 17:04:31 +00003424#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003425 if (__max < __min)
3426 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003427#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcba352d2010-07-12 18:16:05 +00003428 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
3429 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003430 }
3431 __first = __temp;
3432 }
3433 }
3434 }
3435 }
3436 return __first;
3437}
3438
Howard Hinnant0de86b62010-06-25 20:56:08 +00003439template <class _CharT, class _Traits>
3440template <class _ForwardIterator>
3441_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003442basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantaa698082010-07-16 19:08:36 +00003443 _ForwardIterator __last,
3444 __owns_one_state<_CharT>* __s,
3445 unsigned __mexp_begin,
3446 unsigned __mexp_end)
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003447{
3448 if (__first != __last)
3449 {
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003450 unsigned __grammar = __flags_ & 0x1F0;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003451 switch (*__first)
3452 {
3453 case '*':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003454 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003455 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003456 {
3457 ++__first;
3458 __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3459 }
3460 else
3461 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003462 break;
3463 case '+':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003464 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003465 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003466 {
3467 ++__first;
3468 __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3469 }
3470 else
3471 __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003472 break;
3473 case '?':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003474 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003475 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003476 {
3477 ++__first;
3478 __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3479 }
3480 else
3481 __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003482 break;
3483 case '{':
3484 {
3485 int __min;
Howard Hinnantaa698082010-07-16 19:08:36 +00003486 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
Howard Hinnantd4444702010-08-11 17:04:31 +00003487#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003488 if (__temp == __first)
3489 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003490#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003491 __first = __temp;
Howard Hinnantd4444702010-08-11 17:04:31 +00003492#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003493 if (__first == __last)
3494 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003495#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003496 switch (*__first)
3497 {
3498 case '}':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003499 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003500 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003501 {
3502 ++__first;
3503 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3504 }
3505 else
3506 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003507 break;
3508 case ',':
Howard Hinnantd4444702010-08-11 17:04:31 +00003509 ++__first;
3510#ifndef _LIBCPP_NO_EXCEPTIONS
3511 if (__first == __last)
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003512 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003513#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003514 if (*__first == '}')
3515 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003516 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003517 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003518 {
3519 ++__first;
3520 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3521 }
3522 else
3523 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003524 }
3525 else
3526 {
Howard Hinnantaa698082010-07-16 19:08:36 +00003527 int __max = -1;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003528 __temp = __parse_DUP_COUNT(__first, __last, __max);
Howard Hinnantd4444702010-08-11 17:04:31 +00003529#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003530 if (__temp == __first)
3531 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003532#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003533 __first = __temp;
Howard Hinnantd4444702010-08-11 17:04:31 +00003534#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003535 if (__first == __last || *__first != '}')
3536 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003537#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003538 ++__first;
Howard Hinnantd4444702010-08-11 17:04:31 +00003539#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003540 if (__max < __min)
3541 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003542#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003543 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003544 {
3545 ++__first;
3546 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3547 }
3548 else
3549 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003550 }
Howard Hinnantaa698082010-07-16 19:08:36 +00003551 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00003552#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003553 default:
3554 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003555#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003556 }
3557 }
3558 break;
3559 }
3560 }
3561 return __first;
3562}
3563
3564template <class _CharT, class _Traits>
3565template <class _ForwardIterator>
3566_ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00003567basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
3568 _ForwardIterator __last)
3569{
3570 if (__first != __last && *__first == '[')
3571 {
Howard Hinnantd4444702010-08-11 17:04:31 +00003572 ++__first;
3573#ifndef _LIBCPP_NO_EXCEPTIONS
3574 if (__first == __last)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003575 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003576#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003577 bool __negate = false;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003578 if (*__first == '^')
3579 {
3580 ++__first;
Howard Hinnant173968a2010-07-13 21:48:06 +00003581 __negate = true;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003582 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003583 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3584 // __ml owned by *this
Howard Hinnantd4444702010-08-11 17:04:31 +00003585#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003586 if (__first == __last)
3587 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003588#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003589 if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']')
Howard Hinnant0de86b62010-06-25 20:56:08 +00003590 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003591 __ml->__add_char(']');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003592 ++__first;
3593 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003594 __first = __parse_follow_list(__first, __last, __ml);
Howard Hinnantd4444702010-08-11 17:04:31 +00003595#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003596 if (__first == __last)
3597 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003598#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003599 if (*__first == '-')
3600 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003601 __ml->__add_char('-');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003602 ++__first;
3603 }
Howard Hinnantd4444702010-08-11 17:04:31 +00003604#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003605 if (__first == __last || *__first != ']')
3606 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003607#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003608 ++__first;
3609 }
3610 return __first;
3611}
3612
3613template <class _CharT, class _Traits>
3614template <class _ForwardIterator>
3615_ForwardIterator
3616basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003617 _ForwardIterator __last,
3618 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003619{
3620 if (__first != __last)
3621 {
3622 while (true)
3623 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003624 _ForwardIterator __temp = __parse_expression_term(__first, __last,
3625 __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003626 if (__temp == __first)
3627 break;
3628 __first = __temp;
3629 }
3630 }
3631 return __first;
3632}
3633
3634template <class _CharT, class _Traits>
3635template <class _ForwardIterator>
3636_ForwardIterator
3637basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003638 _ForwardIterator __last,
3639 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003640{
3641 if (__first != __last && *__first != ']')
3642 {
Howard Hinnant0de86b62010-06-25 20:56:08 +00003643 _ForwardIterator __temp = next(__first);
Howard Hinnant173968a2010-07-13 21:48:06 +00003644 basic_string<_CharT> __start_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003645 if (__temp != __last && *__first == '[')
3646 {
3647 if (*__temp == '=')
Howard Hinnant173968a2010-07-13 21:48:06 +00003648 return __parse_equivalence_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003649 else if (*__temp == ':')
Howard Hinnant173968a2010-07-13 21:48:06 +00003650 return __parse_character_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003651 else if (*__temp == '.')
Howard Hinnant173968a2010-07-13 21:48:06 +00003652 __first = __parse_collating_symbol(++__temp, __last, __start_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003653 }
Howard Hinnant15476f32010-07-28 17:35:27 +00003654 unsigned __grammar = __flags_ & 0x1F0;
3655 if (__start_range.empty())
Howard Hinnant0de86b62010-06-25 20:56:08 +00003656 {
Howard Hinnant15476f32010-07-28 17:35:27 +00003657 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3658 {
3659 if (__grammar == ECMAScript)
3660 __first = __parse_class_escape(++__first, __last, __start_range, __ml);
3661 else
3662 __first = __parse_awk_escape(++__first, __last, &__start_range);
3663 }
3664 else
3665 {
3666 __start_range = *__first;
3667 ++__first;
3668 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003669 }
3670 if (__first != __last && *__first != ']')
3671 {
3672 __temp = next(__first);
3673 if (__temp != __last && *__first == '-' && *__temp != ']')
3674 {
3675 // parse a range
Howard Hinnant173968a2010-07-13 21:48:06 +00003676 basic_string<_CharT> __end_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003677 __first = __temp;
3678 ++__temp;
3679 if (__temp != __last && *__first == '[' && *__temp == '.')
Howard Hinnant173968a2010-07-13 21:48:06 +00003680 __first = __parse_collating_symbol(++__temp, __last, __end_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003681 else
3682 {
Howard Hinnant15476f32010-07-28 17:35:27 +00003683 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3684 {
3685 if (__grammar == ECMAScript)
3686 __first = __parse_class_escape(++__first, __last,
3687 __end_range, __ml);
3688 else
3689 __first = __parse_awk_escape(++__first, __last,
3690 &__end_range);
3691 }
3692 else
3693 {
3694 __end_range = *__first;
3695 ++__first;
3696 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003697 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003698 __ml->__add_range(_STD::move(__start_range), _STD::move(__end_range));
Howard Hinnant0de86b62010-06-25 20:56:08 +00003699 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003700 else
3701 {
3702 if (__start_range.size() == 1)
3703 __ml->__add_char(__start_range[0]);
3704 else
3705 __ml->__add_digraph(__start_range[0], __start_range[1]);
3706 }
3707 }
3708 else
3709 {
3710 if (__start_range.size() == 1)
3711 __ml->__add_char(__start_range[0]);
3712 else
3713 __ml->__add_digraph(__start_range[0], __start_range[1]);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003714 }
3715 }
3716 return __first;
3717}
3718
3719template <class _CharT, class _Traits>
3720template <class _ForwardIterator>
3721_ForwardIterator
Howard Hinnant15476f32010-07-28 17:35:27 +00003722basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
3723 _ForwardIterator __last,
3724 basic_string<_CharT>& __str,
3725 __bracket_expression<_CharT, _Traits>* __ml)
3726{
Howard Hinnantd4444702010-08-11 17:04:31 +00003727#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003728 if (__first == __last)
3729 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00003730#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003731 switch (*__first)
3732 {
3733 case 0:
3734 __str = *__first;
3735 return ++__first;
3736 case 'b':
3737 __str = _CharT(8);
3738 return ++__first;
3739 case 'd':
3740 __ml->__add_class(ctype_base::digit);
3741 return ++__first;
3742 case 'D':
3743 __ml->__add_neg_class(ctype_base::digit);
3744 return ++__first;
3745 case 's':
3746 __ml->__add_class(ctype_base::space);
3747 return ++__first;
3748 case 'S':
3749 __ml->__add_neg_class(ctype_base::space);
3750 return ++__first;
3751 case 'w':
3752 __ml->__add_class(ctype_base::alnum);
3753 __ml->__add_char('_');
3754 return ++__first;
3755 case 'W':
3756 __ml->__add_neg_class(ctype_base::alnum);
3757 __ml->__add_neg_char('_');
3758 return ++__first;
3759 }
3760 __first = __parse_character_escape(__first, __last, &__str);
3761 return __first;
3762}
3763
3764template <class _CharT, class _Traits>
3765template <class _ForwardIterator>
3766_ForwardIterator
3767basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
3768 _ForwardIterator __last,
3769 basic_string<_CharT>* __str)
3770{
Howard Hinnantd4444702010-08-11 17:04:31 +00003771#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003772 if (__first == __last)
3773 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00003774#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003775 switch (*__first)
3776 {
3777 case '\\':
3778 case '"':
3779 case '/':
3780 if (__str)
3781 *__str = *__first;
3782 else
3783 __push_char(*__first);
3784 return ++__first;
3785 case 'a':
3786 if (__str)
3787 *__str = _CharT(7);
3788 else
3789 __push_char(_CharT(7));
3790 return ++__first;
3791 case 'b':
3792 if (__str)
3793 *__str = _CharT(8);
3794 else
3795 __push_char(_CharT(8));
3796 return ++__first;
3797 case 'f':
3798 if (__str)
3799 *__str = _CharT(0xC);
3800 else
3801 __push_char(_CharT(0xC));
3802 return ++__first;
3803 case 'n':
3804 if (__str)
3805 *__str = _CharT(0xA);
3806 else
3807 __push_char(_CharT(0xA));
3808 return ++__first;
3809 case 'r':
3810 if (__str)
3811 *__str = _CharT(0xD);
3812 else
3813 __push_char(_CharT(0xD));
3814 return ++__first;
3815 case 't':
3816 if (__str)
3817 *__str = _CharT(0x9);
3818 else
3819 __push_char(_CharT(0x9));
3820 return ++__first;
3821 case 'v':
3822 if (__str)
3823 *__str = _CharT(0xB);
3824 else
3825 __push_char(_CharT(0xB));
3826 return ++__first;
3827 }
3828 if ('0' <= *__first && *__first <= '7')
3829 {
3830 unsigned __val = *__first - '0';
3831 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3832 {
3833 __val = 8 * __val + *__first - '0';
3834 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3835 __val = 8 * __val + *__first - '0';
3836 }
3837 if (__str)
3838 *__str = _CharT(__val);
3839 else
3840 __push_char(_CharT(__val));
3841 }
Howard Hinnantd4444702010-08-11 17:04:31 +00003842#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003843 else
3844 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00003845#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003846 return __first;
3847}
3848
3849template <class _CharT, class _Traits>
3850template <class _ForwardIterator>
3851_ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00003852basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003853 _ForwardIterator __last,
3854 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003855{
3856 // Found [=
3857 // This means =] must exist
3858 value_type _Equal_close[2] = {'=', ']'};
3859 _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close,
3860 _Equal_close+2);
Howard Hinnantd4444702010-08-11 17:04:31 +00003861#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003862 if (__temp == __last)
3863 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003864#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003865 // [__first, __temp) contains all text in [= ... =]
3866 typedef typename _Traits::string_type string_type;
3867 string_type __collate_name =
3868 __traits_.lookup_collatename(__first, __temp);
Howard Hinnantd4444702010-08-11 17:04:31 +00003869#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003870 if (__collate_name.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003871 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00003872#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003873 string_type __equiv_name =
3874 __traits_.transform_primary(__collate_name.begin(),
3875 __collate_name.end());
3876 if (!__equiv_name.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003877 __ml->__add_equivalence(__equiv_name);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003878 else
Howard Hinnant173968a2010-07-13 21:48:06 +00003879 {
3880 switch (__collate_name.size())
3881 {
3882 case 1:
3883 __ml->__add_char(__collate_name[0]);
3884 break;
3885 case 2:
3886 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
3887 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00003888#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003889 default:
3890 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00003891#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003892 }
3893 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003894 __first = next(__temp, 2);
3895 return __first;
3896}
3897
3898template <class _CharT, class _Traits>
3899template <class _ForwardIterator>
3900_ForwardIterator
3901basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003902 _ForwardIterator __last,
3903 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003904{
3905 // Found [:
3906 // This means :] must exist
3907 value_type _Colon_close[2] = {':', ']'};
3908 _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close,
3909 _Colon_close+2);
Howard Hinnantd4444702010-08-11 17:04:31 +00003910#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003911 if (__temp == __last)
3912 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003913#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003914 // [__first, __temp) contains all text in [: ... :]
3915 typedef typename _Traits::char_class_type char_class_type;
3916 char_class_type __class_type =
3917 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
Howard Hinnantd4444702010-08-11 17:04:31 +00003918#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003919 if (__class_type == 0)
3920 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003921#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003922 __ml->__add_class(__class_type);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003923 __first = next(__temp, 2);
3924 return __first;
3925}
3926
3927template <class _CharT, class _Traits>
3928template <class _ForwardIterator>
3929_ForwardIterator
3930basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003931 _ForwardIterator __last,
3932 basic_string<_CharT>& __col_sym)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003933{
3934 // Found [.
3935 // This means .] must exist
3936 value_type _Dot_close[2] = {'.', ']'};
3937 _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close,
3938 _Dot_close+2);
Howard Hinnantd4444702010-08-11 17:04:31 +00003939#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003940 if (__temp == __last)
3941 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003942#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003943 // [__first, __temp) contains all text in [. ... .]
3944 typedef typename _Traits::string_type string_type;
Howard Hinnant173968a2010-07-13 21:48:06 +00003945 __col_sym = __traits_.lookup_collatename(__first, __temp);
3946 switch (__col_sym.size())
3947 {
3948 case 1:
3949 case 2:
3950 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00003951#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003952 default:
3953 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00003954#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003955 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003956 __first = next(__temp, 2);
3957 return __first;
3958}
3959
3960template <class _CharT, class _Traits>
3961template <class _ForwardIterator>
3962_ForwardIterator
3963basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
3964 _ForwardIterator __last,
3965 int& __c)
3966{
3967 if (__first != __last && '0' <= *__first && *__first <= '9')
3968 {
3969 __c = *__first - '0';
3970 for (++__first; __first != __last && '0' <= *__first && *__first <= '9';
3971 ++__first)
3972 {
3973 __c *= 10;
3974 __c += *__first - '0';
3975 }
3976 }
3977 return __first;
3978}
3979
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003980template <class _CharT, class _Traits>
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003981template <class _ForwardIterator>
3982_ForwardIterator
3983basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
3984 _ForwardIterator __last)
3985{
3986 __owns_one_state<_CharT>* __sa = __end_;
3987 _ForwardIterator __temp = __parse_alternative(__first, __last);
3988 if (__temp == __first)
3989 __push_empty();
3990 __first = __temp;
3991 while (__first != __last && *__first == '|')
3992 {
3993 __owns_one_state<_CharT>* __sb = __end_;
3994 __temp = __parse_alternative(++__first, __last);
3995 if (__temp == __first)
3996 __push_empty();
3997 __push_alternation(__sa, __sb);
3998 __first = __temp;
3999 }
4000 return __first;
4001}
4002
4003template <class _CharT, class _Traits>
4004template <class _ForwardIterator>
4005_ForwardIterator
4006basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
4007 _ForwardIterator __last)
4008{
4009 while (true)
4010 {
4011 _ForwardIterator __temp = __parse_term(__first, __last);
4012 if (__temp == __first)
4013 break;
4014 __first = __temp;
4015 }
4016 return __first;
4017}
4018
4019template <class _CharT, class _Traits>
4020template <class _ForwardIterator>
4021_ForwardIterator
4022basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
4023 _ForwardIterator __last)
4024{
4025 _ForwardIterator __temp = __parse_assertion(__first, __last);
4026 if (__temp == __first)
4027 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004028 __owns_one_state<_CharT>* __e = __end_;
4029 unsigned __mexp_begin = __marked_count_;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004030 __temp = __parse_atom(__first, __last);
4031 if (__temp != __first)
Howard Hinnant17615b02010-07-27 01:25:38 +00004032 __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
4033 __mexp_begin+1, __marked_count_+1);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004034 }
Howard Hinnant17615b02010-07-27 01:25:38 +00004035 else
4036 __first = __temp;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004037 return __first;
4038}
4039
4040template <class _CharT, class _Traits>
4041template <class _ForwardIterator>
4042_ForwardIterator
4043basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
4044 _ForwardIterator __last)
4045{
4046 if (__first != __last)
4047 {
4048 switch (*__first)
4049 {
4050 case '^':
4051 __push_l_anchor();
4052 ++__first;
4053 break;
4054 case '$':
4055 __push_r_anchor();
4056 ++__first;
4057 break;
4058 case '\\':
4059 {
4060 _ForwardIterator __temp = _STD::next(__first);
4061 if (__temp != __last)
4062 {
4063 if (*__temp == 'b')
4064 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004065 __push_word_boundary(false);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004066 __first = ++__temp;
4067 }
4068 else if (*__temp == 'B')
4069 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004070 __push_word_boundary(true);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004071 __first = ++__temp;
4072 }
4073 }
4074 }
4075 break;
4076 case '(':
4077 {
4078 _ForwardIterator __temp = _STD::next(__first);
4079 if (__temp != __last && *__temp == '?')
4080 {
4081 if (++__temp != __last)
4082 {
4083 switch (*__temp)
4084 {
4085 case '=':
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004086 {
4087 basic_regex __exp;
4088 __exp.__flags_ = __flags_;
4089 __temp = __exp.__parse(++__temp, __last);
4090 __exp.__push_l_anchor();
4091 __push_lookahead(_STD::move(__exp), false);
Howard Hinnantd4444702010-08-11 17:04:31 +00004092#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004093 if (__temp == __last || *__temp != ')')
4094 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004095#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004096 __first = ++__temp;
4097 }
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004098 break;
4099 case '!':
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004100 {
4101 basic_regex __exp;
4102 __exp.__flags_ = __flags_;
4103 __temp = __exp.__parse(++__temp, __last);
4104 __exp.__push_l_anchor();
4105 __push_lookahead(_STD::move(__exp), true);
Howard Hinnantd4444702010-08-11 17:04:31 +00004106#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004107 if (__temp == __last || *__temp != ')')
4108 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004109#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004110 __first = ++__temp;
4111 }
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004112 break;
4113 }
4114 }
4115 }
4116 }
4117 break;
4118 }
4119 }
4120 return __first;
4121}
4122
4123template <class _CharT, class _Traits>
4124template <class _ForwardIterator>
4125_ForwardIterator
4126basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
4127 _ForwardIterator __last)
4128{
Howard Hinnant17615b02010-07-27 01:25:38 +00004129 if (__first != __last)
4130 {
4131 switch (*__first)
4132 {
4133 case '.':
4134 __push_match_any_but_newline();
4135 ++__first;
4136 break;
4137 case '\\':
4138 __first = __parse_atom_escape(__first, __last);
4139 break;
4140 case '[':
4141 __first = __parse_bracket_expression(__first, __last);
4142 break;
4143 case '(':
4144 {
Howard Hinnantd4444702010-08-11 17:04:31 +00004145 ++__first;
4146#ifndef _LIBCPP_NO_EXCEPTIONS
4147 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004148 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004149#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004150 _ForwardIterator __temp = _STD::next(__first);
4151 if (__temp != __last && *__first == '?' && *__temp == ':')
4152 {
4153 ++__open_count_;
4154 __first = __parse_ecma_exp(++__temp, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00004155#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004156 if (__first == __last || *__first != ')')
4157 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004158#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004159 --__open_count_;
4160 ++__first;
4161 }
4162 else
4163 {
4164 __push_begin_marked_subexpression();
4165 unsigned __temp_count = __marked_count_;
4166 ++__open_count_;
4167 __first = __parse_ecma_exp(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00004168#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004169 if (__first == __last || *__first != ')')
4170 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004171#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004172 __push_end_marked_subexpression(__temp_count);
4173 --__open_count_;
4174 ++__first;
4175 }
4176 }
4177 break;
4178 default:
4179 __first = __parse_pattern_character(__first, __last);
4180 break;
4181 }
4182 }
4183 return __first;
4184}
4185
4186template <class _CharT, class _Traits>
4187template <class _ForwardIterator>
4188_ForwardIterator
4189basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
4190 _ForwardIterator __last)
4191{
4192 if (__first != __last && *__first == '\\')
4193 {
4194 _ForwardIterator __t1 = _STD::next(__first);
4195 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
4196 if (__t2 != __t1)
4197 __first = __t2;
4198 else
4199 {
4200 __t2 = __parse_character_class_escape(__t1, __last);
4201 if (__t2 != __t1)
4202 __first = __t2;
4203 else
4204 {
4205 __t2 = __parse_character_escape(__t1, __last);
4206 if (__t2 != __t1)
4207 __first = __t2;
4208 }
4209 }
4210 }
4211 return __first;
4212}
4213
4214template <class _CharT, class _Traits>
4215template <class _ForwardIterator>
4216_ForwardIterator
4217basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
4218 _ForwardIterator __last)
4219{
4220 if (__first != __last)
4221 {
4222 if (*__first == '0')
4223 {
4224 __push_char(_CharT());
4225 ++__first;
4226 }
4227 else if ('1' <= *__first && *__first <= '9')
4228 {
4229 unsigned __v = *__first - '0';
4230 for (++__first; '0' <= *__first && *__first <= '9'; ++__first)
4231 __v = 10 * __v + *__first - '0';
Howard Hinnantd4444702010-08-11 17:04:31 +00004232#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004233 if (__v > mark_count())
4234 throw regex_error(regex_constants::error_backref);
Howard Hinnant324bb032010-08-22 00:02:43 +00004235#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004236 __push_back_ref(__v);
4237 }
4238 }
4239 return __first;
4240}
4241
4242template <class _CharT, class _Traits>
4243template <class _ForwardIterator>
4244_ForwardIterator
4245basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
4246 _ForwardIterator __last)
4247{
4248 if (__first != __last)
4249 {
4250 __bracket_expression<_CharT, _Traits>* __ml;
4251 switch (*__first)
4252 {
4253 case 'd':
4254 __ml = __start_matching_list(false);
4255 __ml->__add_class(ctype_base::digit);
4256 ++__first;
4257 break;
4258 case 'D':
4259 __ml = __start_matching_list(true);
4260 __ml->__add_class(ctype_base::digit);
4261 ++__first;
4262 break;
4263 case 's':
4264 __ml = __start_matching_list(false);
4265 __ml->__add_class(ctype_base::space);
4266 ++__first;
4267 break;
4268 case 'S':
4269 __ml = __start_matching_list(true);
4270 __ml->__add_class(ctype_base::space);
4271 ++__first;
4272 break;
4273 case 'w':
4274 __ml = __start_matching_list(false);
4275 __ml->__add_class(ctype_base::alnum);
4276 __ml->__add_char('_');
4277 ++__first;
4278 break;
4279 case 'W':
4280 __ml = __start_matching_list(true);
4281 __ml->__add_class(ctype_base::alnum);
4282 __ml->__add_char('_');
4283 ++__first;
4284 break;
4285 }
4286 }
4287 return __first;
4288}
4289
4290template <class _CharT, class _Traits>
4291template <class _ForwardIterator>
4292_ForwardIterator
4293basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
Howard Hinnant15476f32010-07-28 17:35:27 +00004294 _ForwardIterator __last,
4295 basic_string<_CharT>* __str)
Howard Hinnant17615b02010-07-27 01:25:38 +00004296{
4297 if (__first != __last)
4298 {
4299 _ForwardIterator __t;
4300 unsigned __sum = 0;
4301 int __hd;
4302 switch (*__first)
4303 {
4304 case 'f':
Howard Hinnant15476f32010-07-28 17:35:27 +00004305 if (__str)
4306 *__str = _CharT(0xC);
4307 else
4308 __push_char(_CharT(0xC));
Howard Hinnant17615b02010-07-27 01:25:38 +00004309 ++__first;
4310 break;
4311 case 'n':
Howard Hinnant15476f32010-07-28 17:35:27 +00004312 if (__str)
4313 *__str = _CharT(0xA);
4314 else
4315 __push_char(_CharT(0xA));
Howard Hinnant17615b02010-07-27 01:25:38 +00004316 ++__first;
4317 break;
4318 case 'r':
Howard Hinnant15476f32010-07-28 17:35:27 +00004319 if (__str)
4320 *__str = _CharT(0xD);
4321 else
4322 __push_char(_CharT(0xD));
Howard Hinnant17615b02010-07-27 01:25:38 +00004323 ++__first;
4324 break;
4325 case 't':
Howard Hinnant15476f32010-07-28 17:35:27 +00004326 if (__str)
4327 *__str = _CharT(0x9);
4328 else
4329 __push_char(_CharT(0x9));
Howard Hinnant17615b02010-07-27 01:25:38 +00004330 ++__first;
4331 break;
4332 case 'v':
Howard Hinnant15476f32010-07-28 17:35:27 +00004333 if (__str)
4334 *__str = _CharT(0xB);
4335 else
4336 __push_char(_CharT(0xB));
Howard Hinnant17615b02010-07-27 01:25:38 +00004337 ++__first;
4338 break;
4339 case 'c':
4340 if ((__t = _STD::next(__first)) != __last)
4341 {
4342 if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z')
4343 {
Howard Hinnant15476f32010-07-28 17:35:27 +00004344 if (__str)
4345 *__str = _CharT(*__t % 32);
4346 else
4347 __push_char(_CharT(*__t % 32));
Howard Hinnant17615b02010-07-27 01:25:38 +00004348 __first = ++__t;
4349 }
4350 }
4351 break;
4352 case 'u':
Howard Hinnantd4444702010-08-11 17:04:31 +00004353 ++__first;
4354#ifndef _LIBCPP_NO_EXCEPTIONS
4355 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004356 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004357#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004358 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004359#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004360 if (__hd == -1)
4361 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004362#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004363 __sum = 16 * __sum + __hd;
Howard Hinnantd4444702010-08-11 17:04:31 +00004364 ++__first;
4365#ifndef _LIBCPP_NO_EXCEPTIONS
4366 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004367 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004368#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004369 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004370#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004371 if (__hd == -1)
4372 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004373#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004374 __sum = 16 * __sum + __hd;
4375 // drop through
4376 case 'x':
Howard Hinnantd4444702010-08-11 17:04:31 +00004377 ++__first;
4378#ifndef _LIBCPP_NO_EXCEPTIONS
4379 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004380 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004381#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004382 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004383#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004384 if (__hd == -1)
4385 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004386#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004387 __sum = 16 * __sum + __hd;
Howard Hinnantd4444702010-08-11 17:04:31 +00004388 ++__first;
4389#ifndef _LIBCPP_NO_EXCEPTIONS
4390 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004391 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004392#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004393 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004394#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004395 if (__hd == -1)
4396 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004397#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004398 __sum = 16 * __sum + __hd;
Howard Hinnant15476f32010-07-28 17:35:27 +00004399 if (__str)
4400 *__str = _CharT(__sum);
4401 else
4402 __push_char(_CharT(__sum));
Howard Hinnant17615b02010-07-27 01:25:38 +00004403 ++__first;
4404 break;
4405 default:
4406 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
4407 {
Howard Hinnant15476f32010-07-28 17:35:27 +00004408 if (__str)
4409 *__str = *__first;
4410 else
4411 __push_char(*__first);
Howard Hinnant17615b02010-07-27 01:25:38 +00004412 ++__first;
4413 }
Howard Hinnantd4444702010-08-11 17:04:31 +00004414#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00004415 else if (__str)
4416 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004417#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004418 break;
4419 }
4420 }
4421 return __first;
4422}
4423
4424template <class _CharT, class _Traits>
4425template <class _ForwardIterator>
4426_ForwardIterator
4427basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
4428 _ForwardIterator __last)
4429{
4430 if (__first != __last)
4431 {
4432 switch (*__first)
4433 {
4434 case '^':
4435 case '$':
4436 case '\\':
4437 case '.':
4438 case '*':
4439 case '+':
4440 case '?':
4441 case '(':
4442 case ')':
4443 case '[':
4444 case ']':
4445 case '{':
4446 case '}':
4447 case '|':
4448 break;
4449 default:
4450 __push_char(*__first);
4451 ++__first;
4452 break;
4453 }
4454 }
4455 return __first;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004456}
4457
4458template <class _CharT, class _Traits>
Howard Hinnant856846b2010-07-27 19:53:10 +00004459template <class _ForwardIterator>
4460_ForwardIterator
4461basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
4462 _ForwardIterator __last)
4463{
4464 __owns_one_state<_CharT>* __sa = __end_;
4465 _ForwardIterator __t1 = _STD::find(__first, __last, _CharT('\n'));
4466 if (__t1 != __first)
4467 __parse_basic_reg_exp(__first, __t1);
4468 else
4469 __push_empty();
4470 __first = __t1;
4471 if (__first != __last)
4472 ++__first;
4473 while (__first != __last)
4474 {
4475 __t1 = _STD::find(__first, __last, _CharT('\n'));
4476 __owns_one_state<_CharT>* __sb = __end_;
4477 if (__t1 != __first)
4478 __parse_basic_reg_exp(__first, __t1);
4479 else
4480 __push_empty();
4481 __push_alternation(__sa, __sb);
4482 __first = __t1;
4483 if (__first != __last)
4484 ++__first;
4485 }
4486 return __first;
4487}
4488
4489template <class _CharT, class _Traits>
4490template <class _ForwardIterator>
4491_ForwardIterator
4492basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
4493 _ForwardIterator __last)
4494{
4495 __owns_one_state<_CharT>* __sa = __end_;
4496 _ForwardIterator __t1 = _STD::find(__first, __last, _CharT('\n'));
4497 if (__t1 != __first)
4498 __parse_extended_reg_exp(__first, __t1);
4499 else
4500 __push_empty();
4501 __first = __t1;
4502 if (__first != __last)
4503 ++__first;
4504 while (__first != __last)
4505 {
4506 __t1 = _STD::find(__first, __last, _CharT('\n'));
4507 __owns_one_state<_CharT>* __sb = __end_;
4508 if (__t1 != __first)
4509 __parse_extended_reg_exp(__first, __t1);
4510 else
4511 __push_empty();
4512 __push_alternation(__sa, __sb);
4513 __first = __t1;
4514 if (__first != __last)
4515 ++__first;
4516 }
4517 return __first;
4518}
4519
4520template <class _CharT, class _Traits>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004521void
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004522basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
4523 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
4524 bool __greedy)
4525{
4526 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4527 __end_->first() = nullptr;
Howard Hinnantac303862010-07-12 15:51:17 +00004528 unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
4529 __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
4530 __min, __max));
4531 __s->first() = nullptr;
4532 __e1.release();
4533 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004534 __end_ = __e2->second();
Howard Hinnantac303862010-07-12 15:51:17 +00004535 __s->first() = __e2.release();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004536 ++__loop_count_;
4537}
4538
4539template <class _CharT, class _Traits>
4540void
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004541basic_regex<_CharT, _Traits>::__push_char(value_type __c)
4542{
Howard Hinnant173968a2010-07-13 21:48:06 +00004543 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004544 __end_->first() = new __match_char_icase<_CharT, _Traits>
4545 (__traits_, __c, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004546 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004547 __end_->first() = new __match_char_collate<_CharT, _Traits>
4548 (__traits_, __c, __end_->first());
4549 else
4550 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
Howard Hinnante77aa5e2010-07-08 17:43:58 +00004551 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004552}
4553
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004554template <class _CharT, class _Traits>
4555void
4556basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
4557{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004558 if (!(__flags_ & nosubs))
4559 {
4560 __end_->first() =
4561 new __begin_marked_subexpression<_CharT>(++__marked_count_,
4562 __end_->first());
4563 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4564 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004565}
4566
4567template <class _CharT, class _Traits>
4568void
4569basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
4570{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004571 if (!(__flags_ & nosubs))
4572 {
4573 __end_->first() =
4574 new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4575 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4576 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004577}
4578
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004579template <class _CharT, class _Traits>
4580void
4581basic_regex<_CharT, _Traits>::__push_r_anchor()
4582{
4583 __end_->first() = new __r_anchor<_CharT>(__end_->first());
4584 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4585}
4586
Howard Hinnantac303862010-07-12 15:51:17 +00004587template <class _CharT, class _Traits>
4588void
4589basic_regex<_CharT, _Traits>::__push_match_any()
4590{
4591 __end_->first() = new __match_any<_CharT>(__end_->first());
4592 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4593}
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004594
Howard Hinnantcba352d2010-07-12 18:16:05 +00004595template <class _CharT, class _Traits>
4596void
Howard Hinnant17615b02010-07-27 01:25:38 +00004597basic_regex<_CharT, _Traits>::__push_match_any_but_newline()
4598{
4599 __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
4600 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4601}
4602
4603template <class _CharT, class _Traits>
4604void
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004605basic_regex<_CharT, _Traits>::__push_empty()
4606{
4607 __end_->first() = new __empty_state<_CharT>(__end_->first());
4608 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4609}
4610
4611template <class _CharT, class _Traits>
4612void
Howard Hinnant17615b02010-07-27 01:25:38 +00004613basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
4614{
4615 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
4616 __end_->first());
4617 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4618}
4619
4620template <class _CharT, class _Traits>
4621void
Howard Hinnantcba352d2010-07-12 18:16:05 +00004622basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
4623{
Howard Hinnant173968a2010-07-13 21:48:06 +00004624 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004625 __end_->first() = new __back_ref_icase<_CharT, _Traits>
4626 (__traits_, __i, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004627 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004628 __end_->first() = new __back_ref_collate<_CharT, _Traits>
4629 (__traits_, __i, __end_->first());
4630 else
4631 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
Howard Hinnantcba352d2010-07-12 18:16:05 +00004632 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4633}
4634
Howard Hinnant173968a2010-07-13 21:48:06 +00004635template <class _CharT, class _Traits>
Howard Hinnantaa698082010-07-16 19:08:36 +00004636void
4637basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
4638 __owns_one_state<_CharT>* __ea)
4639{
4640 __sa->first() = new __alternate<_CharT>(
4641 static_cast<__owns_one_state<_CharT>*>(__sa->first()),
4642 static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4643 __ea->first() = nullptr;
4644 __ea->first() = new __empty_state<_CharT>(__end_->first());
4645 __end_->first() = nullptr;
4646 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4647 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4648}
4649
4650template <class _CharT, class _Traits>
Howard Hinnant173968a2010-07-13 21:48:06 +00004651__bracket_expression<_CharT, _Traits>*
4652basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
4653{
4654 __bracket_expression<_CharT, _Traits>* __r =
4655 new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
4656 __negate, __flags_ & icase,
4657 __flags_ & collate);
4658 __end_->first() = __r;
4659 __end_ = __r;
4660 return __r;
4661}
4662
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004663template <class _CharT, class _Traits>
4664void
4665basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
4666 bool __invert)
4667{
4668 __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
4669 __end_->first());
4670 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4671}
4672
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00004673typedef basic_regex<char> regex;
4674typedef basic_regex<wchar_t> wregex;
4675
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004676// sub_match
4677
4678template <class _BidirectionalIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004679class _LIBCPP_VISIBLE sub_match
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004680 : public pair<_BidirectionalIterator, _BidirectionalIterator>
4681{
4682public:
4683 typedef _BidirectionalIterator iterator;
4684 typedef typename iterator_traits<iterator>::value_type value_type;
4685 typedef typename iterator_traits<iterator>::difference_type difference_type;
4686 typedef basic_string<value_type> string_type;
4687
4688 bool matched;
4689
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant31aaf552010-12-08 21:07:55 +00004691 /*constexpr*/ sub_match() : matched() {}
4692
4693 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004694 difference_type length() const
4695 {return matched ? _STD::distance(this->first, this->second) : 0;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004697 string_type str() const
4698 {return matched ? string_type(this->first, this->second) : string_type();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004700 operator string_type() const
4701 {return str();}
4702
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004703 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004704 int compare(const sub_match& __s) const
4705 {return str().compare(__s.str());}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004707 int compare(const string_type& __s) const
4708 {return str().compare(__s);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004709 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004710 int compare(const value_type* __s) const
4711 {return str().compare(__s);}
4712};
4713
4714typedef sub_match<const char*> csub_match;
4715typedef sub_match<const wchar_t*> wcsub_match;
4716typedef sub_match<string::const_iterator> ssub_match;
4717typedef sub_match<wstring::const_iterator> wssub_match;
4718
4719template <class _BiIter>
4720inline _LIBCPP_INLINE_VISIBILITY
4721bool
4722operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4723{
4724 return __x.compare(__y) == 0;
4725}
4726
4727template <class _BiIter>
4728inline _LIBCPP_INLINE_VISIBILITY
4729bool
4730operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4731{
4732 return !(__x == __y);
4733}
4734
4735template <class _BiIter>
4736inline _LIBCPP_INLINE_VISIBILITY
4737bool
4738operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4739{
4740 return __x.compare(__y) < 0;
4741}
4742
4743template <class _BiIter>
4744inline _LIBCPP_INLINE_VISIBILITY
4745bool
4746operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4747{
4748 return !(__y < __x);
4749}
4750
4751template <class _BiIter>
4752inline _LIBCPP_INLINE_VISIBILITY
4753bool
4754operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4755{
4756 return !(__x < __y);
4757}
4758
4759template <class _BiIter>
4760inline _LIBCPP_INLINE_VISIBILITY
4761bool
4762operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4763{
4764 return __y < __x;
4765}
4766
4767template <class _BiIter, class _ST, class _SA>
4768inline _LIBCPP_INLINE_VISIBILITY
4769bool
4770operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4771 const sub_match<_BiIter>& __y)
4772{
4773 return __y.compare(__x.c_str()) == 0;
4774}
4775
4776template <class _BiIter, class _ST, class _SA>
4777inline _LIBCPP_INLINE_VISIBILITY
4778bool
4779operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4780 const sub_match<_BiIter>& __y)
4781{
4782 return !(__x == __y);
4783}
4784
4785template <class _BiIter, class _ST, class _SA>
4786inline _LIBCPP_INLINE_VISIBILITY
4787bool
4788operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4789 const sub_match<_BiIter>& __y)
4790{
4791 return __y.compare(__x.c_str()) > 0;
4792}
4793
4794template <class _BiIter, class _ST, class _SA>
4795inline _LIBCPP_INLINE_VISIBILITY
4796bool
4797operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4798 const sub_match<_BiIter>& __y)
4799{
4800 return __y < __x;
4801}
4802
4803template <class _BiIter, class _ST, class _SA>
4804inline _LIBCPP_INLINE_VISIBILITY
4805bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4806 const sub_match<_BiIter>& __y)
4807{
4808 return !(__x < __y);
4809}
4810
4811template <class _BiIter, class _ST, class _SA>
4812inline _LIBCPP_INLINE_VISIBILITY
4813bool
4814operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4815 const sub_match<_BiIter>& __y)
4816{
4817 return !(__y < __x);
4818}
4819
4820template <class _BiIter, class _ST, class _SA>
4821inline _LIBCPP_INLINE_VISIBILITY
4822bool
4823operator==(const sub_match<_BiIter>& __x,
4824 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4825{
4826 return __x.compare(__y.c_str()) == 0;
4827}
4828
4829template <class _BiIter, class _ST, class _SA>
4830inline _LIBCPP_INLINE_VISIBILITY
4831bool
4832operator!=(const sub_match<_BiIter>& __x,
4833 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4834{
4835 return !(__x == __y);
4836}
4837
4838template <class _BiIter, class _ST, class _SA>
4839inline _LIBCPP_INLINE_VISIBILITY
4840bool
4841operator<(const sub_match<_BiIter>& __x,
4842 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4843{
4844 return __x.compare(__y.c_str()) < 0;
4845}
4846
4847template <class _BiIter, class _ST, class _SA>
4848inline _LIBCPP_INLINE_VISIBILITY
4849bool operator>(const sub_match<_BiIter>& __x,
4850 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4851{
4852 return __y < __x;
4853}
4854
4855template <class _BiIter, class _ST, class _SA>
4856inline _LIBCPP_INLINE_VISIBILITY
4857bool
4858operator>=(const sub_match<_BiIter>& __x,
4859 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4860{
4861 return !(__x < __y);
4862}
4863
4864template <class _BiIter, class _ST, class _SA>
4865inline _LIBCPP_INLINE_VISIBILITY
4866bool
4867operator<=(const sub_match<_BiIter>& __x,
4868 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4869{
4870 return !(__y < __x);
4871}
4872
4873template <class _BiIter>
4874inline _LIBCPP_INLINE_VISIBILITY
4875bool
4876operator==(typename iterator_traits<_BiIter>::value_type const* __x,
4877 const sub_match<_BiIter>& __y)
4878{
4879 return __y.compare(__x) == 0;
4880}
4881
4882template <class _BiIter>
4883inline _LIBCPP_INLINE_VISIBILITY
4884bool
4885operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
4886 const sub_match<_BiIter>& __y)
4887{
4888 return !(__x == __y);
4889}
4890
4891template <class _BiIter>
4892inline _LIBCPP_INLINE_VISIBILITY
4893bool
4894operator<(typename iterator_traits<_BiIter>::value_type const* __x,
4895 const sub_match<_BiIter>& __y)
4896{
4897 return __y.compare(__x) > 0;
4898}
4899
4900template <class _BiIter>
4901inline _LIBCPP_INLINE_VISIBILITY
4902bool
4903operator>(typename iterator_traits<_BiIter>::value_type const* __x,
4904 const sub_match<_BiIter>& __y)
4905{
4906 return __y < __x;
4907}
4908
4909template <class _BiIter>
4910inline _LIBCPP_INLINE_VISIBILITY
4911bool
4912operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
4913 const sub_match<_BiIter>& __y)
4914{
4915 return !(__x < __y);
4916}
4917
4918template <class _BiIter>
4919inline _LIBCPP_INLINE_VISIBILITY
4920bool
4921operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
4922 const sub_match<_BiIter>& __y)
4923{
4924 return !(__y < __x);
4925}
4926
4927template <class _BiIter>
4928inline _LIBCPP_INLINE_VISIBILITY
4929bool
4930operator==(const sub_match<_BiIter>& __x,
4931 typename iterator_traits<_BiIter>::value_type const* __y)
4932{
4933 return __x.compare(__y) == 0;
4934}
4935
4936template <class _BiIter>
4937inline _LIBCPP_INLINE_VISIBILITY
4938bool
4939operator!=(const sub_match<_BiIter>& __x,
4940 typename iterator_traits<_BiIter>::value_type const* __y)
4941{
4942 return !(__x == __y);
4943}
4944
4945template <class _BiIter>
4946inline _LIBCPP_INLINE_VISIBILITY
4947bool
4948operator<(const sub_match<_BiIter>& __x,
4949 typename iterator_traits<_BiIter>::value_type const* __y)
4950{
4951 return __x.compare(__y) < 0;
4952}
4953
4954template <class _BiIter>
4955inline _LIBCPP_INLINE_VISIBILITY
4956bool
4957operator>(const sub_match<_BiIter>& __x,
4958 typename iterator_traits<_BiIter>::value_type const* __y)
4959{
4960 return __y < __x;
4961}
4962
4963template <class _BiIter>
4964inline _LIBCPP_INLINE_VISIBILITY
4965bool
4966operator>=(const sub_match<_BiIter>& __x,
4967 typename iterator_traits<_BiIter>::value_type const* __y)
4968{
4969 return !(__x < __y);
4970}
4971
4972template <class _BiIter>
4973inline _LIBCPP_INLINE_VISIBILITY
4974bool
4975operator<=(const sub_match<_BiIter>& __x,
4976 typename iterator_traits<_BiIter>::value_type const* __y)
4977{
4978 return !(__y < __x);
4979}
4980
4981template <class _BiIter>
4982inline _LIBCPP_INLINE_VISIBILITY
4983bool
4984operator==(typename iterator_traits<_BiIter>::value_type const& __x,
4985 const sub_match<_BiIter>& __y)
4986{
4987 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4988 return __y.compare(string_type(1, __x)) == 0;
4989}
4990
4991template <class _BiIter>
4992inline _LIBCPP_INLINE_VISIBILITY
4993bool
4994operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
4995 const sub_match<_BiIter>& __y)
4996{
4997 return !(__x == __y);
4998}
4999
5000template <class _BiIter>
5001inline _LIBCPP_INLINE_VISIBILITY
5002bool
5003operator<(typename iterator_traits<_BiIter>::value_type const& __x,
5004 const sub_match<_BiIter>& __y)
5005{
5006 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5007 return __y.compare(string_type(1, __x)) > 0;
5008}
5009
5010template <class _BiIter>
5011inline _LIBCPP_INLINE_VISIBILITY
5012bool
5013operator>(typename iterator_traits<_BiIter>::value_type const& __x,
5014 const sub_match<_BiIter>& __y)
5015{
5016 return __y < __x;
5017}
5018
5019template <class _BiIter>
5020inline _LIBCPP_INLINE_VISIBILITY
5021bool
5022operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
5023 const sub_match<_BiIter>& __y)
5024{
5025 return !(__x < __y);
5026}
5027
5028template <class _BiIter>
5029inline _LIBCPP_INLINE_VISIBILITY
5030bool
5031operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
5032 const sub_match<_BiIter>& __y)
5033{
5034 return !(__y < __x);
5035}
5036
5037template <class _BiIter>
5038inline _LIBCPP_INLINE_VISIBILITY
5039bool
5040operator==(const sub_match<_BiIter>& __x,
5041 typename iterator_traits<_BiIter>::value_type const& __y)
5042{
5043 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5044 return __x.compare(string_type(1, __y)) == 0;
5045}
5046
5047template <class _BiIter>
5048inline _LIBCPP_INLINE_VISIBILITY
5049bool
5050operator!=(const sub_match<_BiIter>& __x,
5051 typename iterator_traits<_BiIter>::value_type const& __y)
5052{
5053 return !(__x == __y);
5054}
5055
5056template <class _BiIter>
5057inline _LIBCPP_INLINE_VISIBILITY
5058bool
5059operator<(const sub_match<_BiIter>& __x,
5060 typename iterator_traits<_BiIter>::value_type const& __y)
5061{
5062 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5063 return __x.compare(string_type(1, __y)) < 0;
5064}
5065
5066template <class _BiIter>
5067inline _LIBCPP_INLINE_VISIBILITY
5068bool
5069operator>(const sub_match<_BiIter>& __x,
5070 typename iterator_traits<_BiIter>::value_type const& __y)
5071{
5072 return __y < __x;
5073}
5074
5075template <class _BiIter>
5076inline _LIBCPP_INLINE_VISIBILITY
5077bool
5078operator>=(const sub_match<_BiIter>& __x,
5079 typename iterator_traits<_BiIter>::value_type const& __y)
5080{
5081 return !(__x < __y);
5082}
5083
5084template <class _BiIter>
5085inline _LIBCPP_INLINE_VISIBILITY
5086bool
5087operator<=(const sub_match<_BiIter>& __x,
5088 typename iterator_traits<_BiIter>::value_type const& __y)
5089{
5090 return !(__y < __x);
5091}
5092
5093template <class _CharT, class _ST, class _BiIter>
5094inline _LIBCPP_INLINE_VISIBILITY
5095basic_ostream<_CharT, _ST>&
5096operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
5097{
5098 return __os << __m.str();
5099}
5100
Howard Hinnant17615b02010-07-27 01:25:38 +00005101template <class _BidirectionalIterator, class _Allocator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005102class _LIBCPP_VISIBLE match_results
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005103{
5104public:
5105 typedef _Allocator allocator_type;
5106 typedef sub_match<_BidirectionalIterator> value_type;
5107private:
5108 typedef vector<value_type, allocator_type> __container_type;
5109
5110 __container_type __matches_;
5111 value_type __unmatched_;
5112 value_type __prefix_;
5113 value_type __suffix_;
Howard Hinnant31aaf552010-12-08 21:07:55 +00005114 bool __ready_;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005115public:
Howard Hinnanta712c722010-08-16 20:21:16 +00005116 _BidirectionalIterator __position_start_;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005117 typedef const value_type& const_reference;
5118 typedef const_reference reference;
5119 typedef typename __container_type::const_iterator const_iterator;
5120 typedef const_iterator iterator;
5121 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
5122 typedef typename allocator_traits<allocator_type>::size_type size_type;
5123 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
5124 typedef basic_string<char_type> string_type;
5125
5126 // construct/copy/destroy:
5127 explicit match_results(const allocator_type& __a = allocator_type());
5128// match_results(const match_results&) = default;
5129// match_results& operator=(const match_results&) = default;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005130// match_results(match_results&& __m) = default;
5131// match_results& operator=(match_results&& __m) = default;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005132// ~match_results() = default;
5133
Howard Hinnant31aaf552010-12-08 21:07:55 +00005134 _LIBCPP_INLINE_VISIBILITY
5135 bool ready() const {return __ready_;}
5136
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005137 // size:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005139 size_type size() const {return __matches_.size();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005140 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005141 size_type max_size() const {return __matches_.max_size();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005142 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005143 bool empty() const {return size() == 0;}
5144
5145 // element access:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005147 difference_type length(size_type __sub = 0) const
5148 {return (*this)[__sub].length();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005149 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005150 difference_type position(size_type __sub = 0) const
Howard Hinnanta712c722010-08-16 20:21:16 +00005151 {return _STD::distance(__position_start_, (*this)[__sub].first);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005152 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005153 string_type str(size_type __sub = 0) const
5154 {return (*this)[__sub].str();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005156 const_reference operator[](size_type __n) const
5157 {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
5158
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005160 const_reference prefix() const {return __prefix_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005161 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005162 const_reference suffix() const {return __suffix_;}
5163
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005165 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005167 const_iterator end() const {return __matches_.end();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005169 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005170 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005171 const_iterator cend() const {return __matches_.end();}
5172
5173 // format:
5174 template <class _OutputIter>
5175 _OutputIter
5176 format(_OutputIter __out, const char_type* __fmt_first,
5177 const char_type* __fmt_last,
5178 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
5179 template <class _OutputIter, class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005181 _OutputIter
5182 format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005183 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5184 {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005185 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005186 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005187 basic_string<char_type, _ST, _SA>
5188 format(const basic_string<char_type, _ST, _SA>& __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005189 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5190 {
5191 basic_string<char_type, _ST, _SA> __r;
5192 format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
5193 __flags);
5194 return __r;
5195 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005196 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005197 string_type
5198 format(const char_type* __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005199 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5200 {
5201 string_type __r;
5202 format(back_inserter(__r), __fmt,
5203 __fmt + char_traits<char_type>::length(__fmt), __flags);
5204 return __r;
5205 }
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005206
5207 // allocator:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005209 allocator_type get_allocator() const {return __matches_.get_allocator();}
5210
5211 // swap:
5212 void swap(match_results& __m);
5213
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005214 template <class _B, class _A>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005215 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005216 void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
Howard Hinnanta712c722010-08-16 20:21:16 +00005217 const match_results<_B, _A>& __m, bool __no_update_pos)
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005218 {
5219 _B __mf = __m.prefix().first;
5220 __matches_.resize(__m.size());
5221 for (size_type __i = 0; __i < __matches_.size(); ++__i)
5222 {
5223 __matches_[__i].first = next(__f, _STD::distance(__mf, __m[__i].first));
5224 __matches_[__i].second = next(__f, _STD::distance(__mf, __m[__i].second));
5225 __matches_[__i].matched = __m[__i].matched;
5226 }
5227 __unmatched_.first = __l;
5228 __unmatched_.second = __l;
5229 __unmatched_.matched = false;
5230 __prefix_.first = next(__f, _STD::distance(__mf, __m.prefix().first));
5231 __prefix_.second = next(__f, _STD::distance(__mf, __m.prefix().second));
5232 __prefix_.matched = __m.prefix().matched;
5233 __suffix_.first = next(__f, _STD::distance(__mf, __m.suffix().first));
5234 __suffix_.second = next(__f, _STD::distance(__mf, __m.suffix().second));
5235 __suffix_.matched = __m.suffix().matched;
Howard Hinnanta712c722010-08-16 20:21:16 +00005236 if (!__no_update_pos)
5237 __position_start_ = __prefix_.first;
Howard Hinnant31aaf552010-12-08 21:07:55 +00005238 __ready_ = __m.ready();
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005239 }
5240
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005241private:
5242 void __init(unsigned __s,
Howard Hinnanta712c722010-08-16 20:21:16 +00005243 _BidirectionalIterator __f, _BidirectionalIterator __l,
5244 bool __no_update_pos = false);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005245
5246 template <class, class> friend class basic_regex;
5247
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005248 template <class _B, class _A, class _C, class _T>
5249 friend
5250 bool
5251 regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
5252 regex_constants::match_flag_type);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00005253
Howard Hinnant27405f92010-08-14 18:14:02 +00005254 template <class _B, class _A>
5255 friend
5256 bool
5257 operator==(const match_results<_B, _A>&, const match_results<_B, _A>&);
5258
Howard Hinnante9de5ff2010-07-27 22:20:32 +00005259 template <class, class> friend class __lookahead;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005260};
5261
5262template <class _BidirectionalIterator, class _Allocator>
5263match_results<_BidirectionalIterator, _Allocator>::match_results(
5264 const allocator_type& __a)
5265 : __matches_(__a),
5266 __unmatched_(),
5267 __prefix_(),
Howard Hinnanta712c722010-08-16 20:21:16 +00005268 __suffix_(),
Howard Hinnant31aaf552010-12-08 21:07:55 +00005269 __position_start_(),
5270 __ready_(false)
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005271{
5272}
5273
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005274template <class _BidirectionalIterator, class _Allocator>
5275void
5276match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
Howard Hinnanta712c722010-08-16 20:21:16 +00005277 _BidirectionalIterator __f, _BidirectionalIterator __l,
5278 bool __no_update_pos)
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005279{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005280 __unmatched_.first = __l;
5281 __unmatched_.second = __l;
5282 __unmatched_.matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005283 __matches_.assign(__s, __unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005284 __prefix_.first = __f;
5285 __prefix_.second = __f;
5286 __prefix_.matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005287 __suffix_ = __unmatched_;
Howard Hinnanta712c722010-08-16 20:21:16 +00005288 if (!__no_update_pos)
5289 __position_start_ = __prefix_.first;
Howard Hinnant31aaf552010-12-08 21:07:55 +00005290 __ready_ = true;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005291}
5292
Howard Hinnant27405f92010-08-14 18:14:02 +00005293template <class _BidirectionalIterator, class _Allocator>
5294template <class _OutputIter>
5295_OutputIter
5296match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
5297 const char_type* __fmt_first, const char_type* __fmt_last,
5298 regex_constants::match_flag_type __flags) const
5299{
5300 if (__flags & regex_constants::format_sed)
5301 {
5302 for (; __fmt_first != __fmt_last; ++__fmt_first)
5303 {
5304 if (*__fmt_first == '&')
5305 __out = _STD::copy(__matches_[0].first, __matches_[0].second,
5306 __out);
5307 else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
5308 {
5309 ++__fmt_first;
5310 if ('0' <= *__fmt_first && *__fmt_first <= '9')
5311 {
5312 size_t __i = *__fmt_first - '0';
5313 __out = _STD::copy(__matches_[__i].first,
5314 __matches_[__i].second, __out);
5315 }
5316 else
5317 {
5318 *__out = *__fmt_first;
5319 ++__out;
5320 }
5321 }
5322 else
5323 {
5324 *__out = *__fmt_first;
5325 ++__out;
5326 }
5327 }
5328 }
5329 else
5330 {
5331 for (; __fmt_first != __fmt_last; ++__fmt_first)
5332 {
5333 if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
5334 {
5335 switch (__fmt_first[1])
5336 {
5337 case '$':
5338 *__out = *++__fmt_first;
5339 ++__out;
5340 break;
5341 case '&':
5342 ++__fmt_first;
5343 __out = _STD::copy(__matches_[0].first, __matches_[0].second,
5344 __out);
5345 break;
5346 case '`':
5347 ++__fmt_first;
5348 __out = _STD::copy(__prefix_.first, __prefix_.second, __out);
5349 break;
5350 case '\'':
5351 ++__fmt_first;
5352 __out = _STD::copy(__suffix_.first, __suffix_.second, __out);
5353 break;
5354 default:
5355 if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5356 {
5357 ++__fmt_first;
5358 size_t __i = *__fmt_first - '0';
5359 if (__fmt_first + 1 != __fmt_last &&
5360 '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5361 {
5362 ++__fmt_first;
5363 __i = 10 * __i + *__fmt_first - '0';
5364 }
5365 __out = _STD::copy(__matches_[__i].first,
5366 __matches_[__i].second, __out);
5367 }
5368 else
5369 {
5370 *__out = *__fmt_first;
5371 ++__out;
5372 }
5373 break;
5374 }
5375 }
5376 else
5377 {
5378 *__out = *__fmt_first;
5379 ++__out;
5380 }
5381 }
5382 }
5383 return __out;
5384}
5385
5386template <class _BidirectionalIterator, class _Allocator>
5387void
5388match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
5389{
5390 using _STD::swap;
5391 swap(__matches_, __m.__matches_);
5392 swap(__unmatched_, __m.__unmatched_);
5393 swap(__prefix_, __m.__prefix_);
5394 swap(__suffix_, __m.__suffix_);
Howard Hinnanta712c722010-08-16 20:21:16 +00005395 swap(__position_start_, __m.__position_start_);
Howard Hinnant31aaf552010-12-08 21:07:55 +00005396 swap(__ready_, __m.__ready_);
Howard Hinnant27405f92010-08-14 18:14:02 +00005397}
5398
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005399typedef match_results<const char*> cmatch;
5400typedef match_results<const wchar_t*> wcmatch;
5401typedef match_results<string::const_iterator> smatch;
5402typedef match_results<wstring::const_iterator> wsmatch;
5403
5404template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005405bool
5406operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
5407 const match_results<_BidirectionalIterator, _Allocator>& __y)
5408{
Howard Hinnant31aaf552010-12-08 21:07:55 +00005409 if (__x.__ready_ != __y.__ready_)
5410 return false;
5411 if (!__x.__ready_)
5412 return true;
Howard Hinnant27405f92010-08-14 18:14:02 +00005413 return __x.__matches_ == __y.__matches_ &&
5414 __x.__prefix_ == __y.__prefix_ &&
Howard Hinnant31aaf552010-12-08 21:07:55 +00005415 __x.__suffix_ == __y.__suffix_;
Howard Hinnant27405f92010-08-14 18:14:02 +00005416}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005417
5418template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005419inline _LIBCPP_INLINE_VISIBILITY
5420bool
5421operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
5422 const match_results<_BidirectionalIterator, _Allocator>& __y)
5423{
5424 return !(__x == __y);
5425}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005426
5427template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005428inline _LIBCPP_INLINE_VISIBILITY
5429void
5430swap(match_results<_BidirectionalIterator, _Allocator>& __x,
5431 match_results<_BidirectionalIterator, _Allocator>& __y)
5432{
5433 __x.swap(__y);
5434}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005435
5436// regex_search
5437
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005438template <class _CharT, class _Traits>
Howard Hinnant17615b02010-07-27 01:25:38 +00005439template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005440bool
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005441basic_regex<_CharT, _Traits>::__match_at_start_ecma(
Howard Hinnant17615b02010-07-27 01:25:38 +00005442 const _CharT* __first, const _CharT* __last,
5443 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005444 regex_constants::match_flag_type __flags) const
5445{
Howard Hinnant17615b02010-07-27 01:25:38 +00005446 vector<__state> __states;
5447 ptrdiff_t __j = 0;
5448 ptrdiff_t _N = _STD::distance(__first, __last);
5449 __node* __st = __start_.get();
5450 if (__st)
5451 {
5452 __states.push_back(__state());
5453 __states.back().__do_ = 0;
5454 __states.back().__first_ = __first;
5455 __states.back().__current_ = __first;
5456 __states.back().__last_ = __last;
5457 __states.back().__sub_matches_.resize(mark_count());
5458 __states.back().__loop_data_.resize(__loop_count());
5459 __states.back().__node_ = __st;
5460 __states.back().__flags_ = __flags;
5461 bool __matched = false;
5462 do
5463 {
5464 __state& __s = __states.back();
5465 if (__s.__node_)
5466 __s.__node_->__exec(__s);
5467 switch (__s.__do_)
5468 {
5469 case __state::__end_state:
5470 __m.__matches_[0].first = __first;
5471 __m.__matches_[0].second = _STD::next(__first, __s.__current_ - __first);
5472 __m.__matches_[0].matched = true;
5473 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
5474 __m.__matches_[__i+1] = __s.__sub_matches_[__i];
5475 return true;
5476 case __state::__accept_and_consume:
5477 case __state::__repeat:
5478 case __state::__accept_but_not_consume:
5479 break;
5480 case __state::__split:
5481 {
5482 __state __snext = __s;
5483 __s.__node_->__exec_split(true, __s);
5484 __snext.__node_->__exec_split(false, __snext);
5485 __states.push_back(_STD::move(__snext));
5486 }
5487 break;
5488 case __state::__reject:
5489 __states.pop_back();
5490 break;
5491 default:
Howard Hinnantd4444702010-08-11 17:04:31 +00005492#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005493 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnantd4444702010-08-11 17:04:31 +00005494#endif
Howard Hinnant17615b02010-07-27 01:25:38 +00005495 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00005496
Howard Hinnant17615b02010-07-27 01:25:38 +00005497 }
5498 } while (!__states.empty());
5499 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005500 return false;
5501}
5502
5503template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005504template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005505bool
5506basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
5507 const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005508 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005509 regex_constants::match_flag_type __flags) const
5510{
Howard Hinnantac303862010-07-12 15:51:17 +00005511 deque<__state> __states;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005512 ptrdiff_t __highest_j = 0;
5513 ptrdiff_t _N = _STD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00005514 __node* __st = __start_.get();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005515 if (__st)
5516 {
Howard Hinnantac303862010-07-12 15:51:17 +00005517 __states.push_back(__state());
Howard Hinnantac303862010-07-12 15:51:17 +00005518 __states.back().__do_ = 0;
5519 __states.back().__first_ = __first;
5520 __states.back().__current_ = __first;
5521 __states.back().__last_ = __last;
5522 __states.back().__loop_data_.resize(__loop_count());
5523 __states.back().__node_ = __st;
5524 __states.back().__flags_ = __flags;
Howard Hinnant68025ed2010-07-14 15:45:11 +00005525 bool __matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005526 do
5527 {
Howard Hinnantac303862010-07-12 15:51:17 +00005528 __state& __s = __states.back();
5529 if (__s.__node_)
5530 __s.__node_->__exec(__s);
5531 switch (__s.__do_)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005532 {
Howard Hinnantac303862010-07-12 15:51:17 +00005533 case __state::__end_state:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005534 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
Howard Hinnant68025ed2010-07-14 15:45:11 +00005535 __highest_j = __s.__current_ - __s.__first_;
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005536 __matched = true;
Howard Hinnantac303862010-07-12 15:51:17 +00005537 if (__highest_j == _N)
5538 __states.clear();
5539 else
5540 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005541 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005542 case __state::__consume_input:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005543 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005544 case __state::__accept_and_consume:
Howard Hinnantac303862010-07-12 15:51:17 +00005545 __states.push_front(_STD::move(__s));
5546 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005547 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005548 case __state::__repeat:
5549 case __state::__accept_but_not_consume:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005550 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005551 case __state::__split:
5552 {
5553 __state __snext = __s;
5554 __s.__node_->__exec_split(true, __s);
5555 __snext.__node_->__exec_split(false, __snext);
5556 __states.push_back(_STD::move(__snext));
5557 }
5558 break;
5559 case __state::__reject:
5560 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005561 break;
5562 default:
Howard Hinnantd4444702010-08-11 17:04:31 +00005563#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005564 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnantd4444702010-08-11 17:04:31 +00005565#endif
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005566 break;
5567 }
Howard Hinnantac303862010-07-12 15:51:17 +00005568 } while (!__states.empty());
Howard Hinnant68025ed2010-07-14 15:45:11 +00005569 if (__matched)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005570 {
5571 __m.__matches_[0].first = __first;
5572 __m.__matches_[0].second = _STD::next(__first, __highest_j);
5573 __m.__matches_[0].matched = true;
5574 return true;
5575 }
5576 }
5577 return false;
5578}
5579
5580template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005581template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005582bool
5583basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005584 const _CharT* __first, const _CharT* __last,
5585 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005586 regex_constants::match_flag_type __flags) const
5587{
Howard Hinnantac303862010-07-12 15:51:17 +00005588 vector<__state> __states;
Howard Hinnantac303862010-07-12 15:51:17 +00005589 __state __best_state;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005590 ptrdiff_t __j = 0;
5591 ptrdiff_t __highest_j = 0;
5592 ptrdiff_t _N = _STD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00005593 __node* __st = __start_.get();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005594 if (__st)
5595 {
Howard Hinnantac303862010-07-12 15:51:17 +00005596 __states.push_back(__state());
5597 __states.back().__do_ = 0;
5598 __states.back().__first_ = __first;
5599 __states.back().__current_ = __first;
5600 __states.back().__last_ = __last;
5601 __states.back().__sub_matches_.resize(mark_count());
5602 __states.back().__loop_data_.resize(__loop_count());
5603 __states.back().__node_ = __st;
5604 __states.back().__flags_ = __flags;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005605 const _CharT* __current = __first;
Howard Hinnantac303862010-07-12 15:51:17 +00005606 bool __matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005607 do
5608 {
Howard Hinnantac303862010-07-12 15:51:17 +00005609 __state& __s = __states.back();
5610 if (__s.__node_)
5611 __s.__node_->__exec(__s);
5612 switch (__s.__do_)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005613 {
Howard Hinnantac303862010-07-12 15:51:17 +00005614 case __state::__end_state:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005615 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005616 {
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005617 __highest_j = __s.__current_ - __s.__first_;
Howard Hinnantac303862010-07-12 15:51:17 +00005618 __best_state = __s;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005619 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005620 __matched = true;
5621 if (__highest_j == _N)
5622 __states.clear();
5623 else
5624 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005625 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005626 case __state::__accept_and_consume:
Howard Hinnantcba352d2010-07-12 18:16:05 +00005627 __j += __s.__current_ - __current;
5628 __current = __s.__current_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005629 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005630 case __state::__repeat:
5631 case __state::__accept_but_not_consume:
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005632 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005633 case __state::__split:
5634 {
5635 __state __snext = __s;
5636 __s.__node_->__exec_split(true, __s);
5637 __snext.__node_->__exec_split(false, __snext);
5638 __states.push_back(_STD::move(__snext));
5639 }
5640 break;
5641 case __state::__reject:
5642 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005643 break;
5644 default:
Howard Hinnantd4444702010-08-11 17:04:31 +00005645#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005646 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnantd4444702010-08-11 17:04:31 +00005647#endif
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005648 break;
5649 }
Howard Hinnantac303862010-07-12 15:51:17 +00005650 } while (!__states.empty());
5651 if (__matched)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005652 {
5653 __m.__matches_[0].first = __first;
5654 __m.__matches_[0].second = _STD::next(__first, __highest_j);
5655 __m.__matches_[0].matched = true;
Howard Hinnantac303862010-07-12 15:51:17 +00005656 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
5657 __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005658 return true;
5659 }
5660 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005661 return false;
5662}
5663
5664template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005665template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005666bool
5667basic_regex<_CharT, _Traits>::__match_at_start(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005668 const _CharT* __first, const _CharT* __last,
5669 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005670 regex_constants::match_flag_type __flags) const
5671{
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005672 if ((__flags_ & 0x1F0) == ECMAScript)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005673 return __match_at_start_ecma(__first, __last, __m, __flags);
5674 if (mark_count() == 0)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005675 return __match_at_start_posix_nosubs(__first, __last, __m, __flags);
5676 return __match_at_start_posix_subs(__first, __last, __m, __flags);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005677}
5678
5679template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005680template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005681bool
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005682basic_regex<_CharT, _Traits>::__search(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005683 const _CharT* __first, const _CharT* __last,
5684 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005685 regex_constants::match_flag_type __flags) const
5686{
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00005687 if (__left_anchor_)
5688 __flags |= regex_constants::match_continuous;
Howard Hinnanta712c722010-08-16 20:21:16 +00005689 __m.__init(1 + mark_count(), __first, __last,
5690 __flags & regex_constants::__no_update_pos);
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005691 if (__match_at_start(__first, __last, __m, __flags))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005692 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005693 __m.__prefix_.second = __m[0].first;
5694 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5695 __m.__suffix_.first = __m[0].second;
5696 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5697 return true;
5698 }
Howard Hinnant8daa7332010-07-29 01:15:27 +00005699 if (__first != __last && !(__flags & regex_constants::match_continuous))
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005700 {
Howard Hinnantf3dcca02010-07-29 15:17:28 +00005701 __flags |= regex_constants::match_prev_avail;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005702 for (++__first; __first != __last; ++__first)
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005703 {
Howard Hinnantf3dcca02010-07-29 15:17:28 +00005704 __m.__matches_.assign(__m.size(), __m.__unmatched_);
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005705 if (__match_at_start(__first, __last, __m, __flags))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005706 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005707 __m.__prefix_.second = __m[0].first;
5708 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5709 __m.__suffix_.first = __m[0].second;
5710 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5711 return true;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005712 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005713 __m.__matches_.assign(__m.size(), __m.__unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005714 }
5715 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005716 __m.__matches_.clear();
5717 return false;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005718}
5719
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005720template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005721inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005722bool
5723regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5724 match_results<_BidirectionalIterator, _Allocator>& __m,
5725 const basic_regex<_CharT, _Traits>& __e,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005726 regex_constants::match_flag_type __flags = regex_constants::match_default)
5727{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005728 basic_string<_CharT> __s(__first, __last);
5729 match_results<const _CharT*> __mc;
5730 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnanta712c722010-08-16 20:21:16 +00005731 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005732 return __r;
5733}
5734
5735template <class _Allocator, class _CharT, class _Traits>
5736inline _LIBCPP_INLINE_VISIBILITY
5737bool
5738regex_search(const _CharT* __first, const _CharT* __last,
5739 match_results<const _CharT*, _Allocator>& __m,
5740 const basic_regex<_CharT, _Traits>& __e,
5741 regex_constants::match_flag_type __flags = regex_constants::match_default)
5742{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005743 return __e.__search(__first, __last, __m, __flags);
5744}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005745
5746template <class _BidirectionalIterator, class _CharT, class _Traits>
5747inline _LIBCPP_INLINE_VISIBILITY
5748bool
5749regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5750 const basic_regex<_CharT, _Traits>& __e,
5751 regex_constants::match_flag_type __flags = regex_constants::match_default)
5752{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005753 basic_string<_CharT> __s(__first, __last);
5754 match_results<const _CharT*> __mc;
5755 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5756}
5757
5758template <class _CharT, class _Traits>
5759inline _LIBCPP_INLINE_VISIBILITY
5760bool
5761regex_search(const _CharT* __first, const _CharT* __last,
5762 const basic_regex<_CharT, _Traits>& __e,
5763 regex_constants::match_flag_type __flags = regex_constants::match_default)
5764{
5765 match_results<const _CharT*> __mc;
5766 return __e.__search(__first, __last, __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005767}
5768
5769template <class _CharT, class _Allocator, class _Traits>
5770inline _LIBCPP_INLINE_VISIBILITY
5771bool
5772regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5773 const basic_regex<_CharT, _Traits>& __e,
5774 regex_constants::match_flag_type __flags = regex_constants::match_default)
5775{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005776 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005777}
5778
5779template <class _CharT, class _Traits>
5780inline _LIBCPP_INLINE_VISIBILITY
5781bool
5782regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5783 regex_constants::match_flag_type __flags = regex_constants::match_default)
5784{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005785 match_results<const _CharT*> __m;
5786 return _STD::regex_search(__str, __m, __e, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005787}
5788
5789template <class _ST, class _SA, class _CharT, class _Traits>
5790inline _LIBCPP_INLINE_VISIBILITY
5791bool
5792regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5793 const basic_regex<_CharT, _Traits>& __e,
5794 regex_constants::match_flag_type __flags = regex_constants::match_default)
5795{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005796 match_results<const _CharT*> __mc;
5797 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005798}
5799
5800template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5801inline _LIBCPP_INLINE_VISIBILITY
5802bool
5803regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5804 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5805 const basic_regex<_CharT, _Traits>& __e,
5806 regex_constants::match_flag_type __flags = regex_constants::match_default)
5807{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005808 match_results<const _CharT*> __mc;
5809 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnanta712c722010-08-16 20:21:16 +00005810 __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005811 return __r;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005812}
5813
5814// regex_match
5815
5816template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5817bool
5818regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5819 match_results<_BidirectionalIterator, _Allocator>& __m,
5820 const basic_regex<_CharT, _Traits>& __e,
5821 regex_constants::match_flag_type __flags = regex_constants::match_default)
5822{
5823 bool __r = _STD::regex_search(__first, __last, __m, __e,
5824 __flags | regex_constants::match_continuous);
5825 if (__r)
5826 {
5827 __r = !__m.suffix().matched;
5828 if (!__r)
5829 __m.__matches_.clear();
5830 }
5831 return __r;
5832}
5833
5834template <class _BidirectionalIterator, class _CharT, class _Traits>
5835inline _LIBCPP_INLINE_VISIBILITY
5836bool
5837regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5838 const basic_regex<_CharT, _Traits>& __e,
5839 regex_constants::match_flag_type __flags = regex_constants::match_default)
5840{
5841 match_results<_BidirectionalIterator> __m;
5842 return _STD::regex_match(__first, __last, __m, __e, __flags);
5843}
5844
5845template <class _CharT, class _Allocator, class _Traits>
5846inline _LIBCPP_INLINE_VISIBILITY
5847bool
5848regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5849 const basic_regex<_CharT, _Traits>& __e,
5850 regex_constants::match_flag_type __flags = regex_constants::match_default)
5851{
5852 return _STD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
5853}
5854
5855template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5856inline _LIBCPP_INLINE_VISIBILITY
5857bool
5858regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5859 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5860 const basic_regex<_CharT, _Traits>& __e,
5861 regex_constants::match_flag_type __flags = regex_constants::match_default)
5862{
5863 return _STD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
5864}
5865
5866template <class _CharT, class _Traits>
5867inline _LIBCPP_INLINE_VISIBILITY
5868bool
5869regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5870 regex_constants::match_flag_type __flags = regex_constants::match_default)
5871{
5872 return _STD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
5873}
5874
5875template <class _ST, class _SA, class _CharT, class _Traits>
5876inline _LIBCPP_INLINE_VISIBILITY
5877bool
5878regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5879 const basic_regex<_CharT, _Traits>& __e,
5880 regex_constants::match_flag_type __flags = regex_constants::match_default)
5881{
5882 return _STD::regex_match(__s.begin(), __s.end(), __e, __flags);
5883}
5884
Howard Hinnanta712c722010-08-16 20:21:16 +00005885// regex_iterator
5886
5887template <class _BidirectionalIterator,
5888 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
5889 class _Traits = regex_traits<_CharT> >
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005890class _LIBCPP_VISIBLE regex_iterator
Howard Hinnanta712c722010-08-16 20:21:16 +00005891{
5892public:
5893 typedef basic_regex<_CharT, _Traits> regex_type;
5894 typedef match_results<_BidirectionalIterator> value_type;
5895 typedef ptrdiff_t difference_type;
5896 typedef const value_type* pointer;
5897 typedef const value_type& reference;
5898 typedef forward_iterator_tag iterator_category;
5899
5900private:
5901 _BidirectionalIterator __begin_;
5902 _BidirectionalIterator __end_;
5903 const regex_type* __pregex_;
5904 regex_constants::match_flag_type __flags_;
5905 value_type __match_;
5906
5907public:
5908 regex_iterator();
5909 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
5910 const regex_type& __re,
5911 regex_constants::match_flag_type __m = regex_constants::match_default);
5912
5913 bool operator==(const regex_iterator& __x) const;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005915 bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
5916
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005918 reference operator*() const {return __match_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005920 pointer operator->() const {return &__match_;}
5921
5922 regex_iterator& operator++();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005924 regex_iterator operator++(int)
5925 {
5926 regex_iterator __t(*this);
5927 ++(*this);
5928 return __t;
5929 }
5930};
5931
5932template <class _BidirectionalIterator, class _CharT, class _Traits>
5933regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
5934 : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
5935{
5936}
5937
5938template <class _BidirectionalIterator, class _CharT, class _Traits>
5939regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
5940 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
5941 const regex_type& __re, regex_constants::match_flag_type __m)
5942 : __begin_(__a),
5943 __end_(__b),
5944 __pregex_(&__re),
5945 __flags_(__m)
5946{
5947 _STD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
5948}
5949
5950template <class _BidirectionalIterator, class _CharT, class _Traits>
5951bool
5952regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
5953 operator==(const regex_iterator& __x) const
5954{
5955 if (__match_.empty() && __x.__match_.empty())
5956 return true;
5957 if (__match_.empty() || __x.__match_.empty())
5958 return false;
5959 return __begin_ == __x.__begin_ &&
5960 __end_ == __x.__end_ &&
5961 __pregex_ == __x.__pregex_ &&
5962 __flags_ == __x.__flags_ &&
5963 __match_[0] == __x.__match_[0];
5964}
5965
5966template <class _BidirectionalIterator, class _CharT, class _Traits>
5967regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
5968regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
5969{
5970 __flags_ |= regex_constants::__no_update_pos;
5971 _BidirectionalIterator __start = __match_[0].second;
5972 if (__match_.length() == 0)
5973 {
5974 if (__start == __end_)
5975 {
5976 __match_ = value_type();
5977 return *this;
5978 }
5979 else if (_STD::regex_search(__start, __end_, __match_, *__pregex_,
5980 __flags_ | regex_constants::match_not_null |
5981 regex_constants::match_continuous))
5982 return *this;
5983 else
5984 ++__start;
5985 }
5986 __flags_ |= regex_constants::match_prev_avail;
5987 if (!_STD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
5988 __match_ = value_type();
5989 return *this;
5990}
5991
5992typedef regex_iterator<const char*> cregex_iterator;
5993typedef regex_iterator<const wchar_t*> wcregex_iterator;
5994typedef regex_iterator<string::const_iterator> sregex_iterator;
5995typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
5996
5997// regex_token_iterator
5998
5999template <class _BidirectionalIterator,
6000 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6001 class _Traits = regex_traits<_CharT> >
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006002class _LIBCPP_VISIBLE regex_token_iterator
Howard Hinnanta712c722010-08-16 20:21:16 +00006003{
6004public:
6005 typedef basic_regex<_CharT, _Traits> regex_type;
6006 typedef sub_match<_BidirectionalIterator> value_type;
6007 typedef ptrdiff_t difference_type;
6008 typedef const value_type* pointer;
6009 typedef const value_type& reference;
6010 typedef forward_iterator_tag iterator_category;
6011
Howard Hinnant262b7792010-08-17 20:42:03 +00006012private:
6013 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
6014
6015 _Position __position_;
6016 const value_type* __result_;
6017 value_type __suffix_;
6018 ptrdiff_t _N_;
6019 vector<int> __subs_;
6020
6021public:
Howard Hinnanta712c722010-08-16 20:21:16 +00006022 regex_token_iterator();
6023 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6024 const regex_type& __re, int __submatch = 0,
Howard Hinnant262b7792010-08-17 20:42:03 +00006025 regex_constants::match_flag_type __m =
6026 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006027 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6028 const regex_type& __re, const vector<int>& __submatches,
Howard Hinnant262b7792010-08-17 20:42:03 +00006029 regex_constants::match_flag_type __m =
6030 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006031 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
Howard Hinnant262b7792010-08-17 20:42:03 +00006032 const regex_type& __re,
6033 initializer_list<int> __submatches,
6034 regex_constants::match_flag_type __m =
6035 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006036 template <size_t _N>
Howard Hinnant262b7792010-08-17 20:42:03 +00006037 regex_token_iterator(_BidirectionalIterator __a,
6038 _BidirectionalIterator __b,
6039 const regex_type& __re,
6040 const int (&__submatches)[_N],
6041 regex_constants::match_flag_type __m =
6042 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006043 regex_token_iterator(const regex_token_iterator&);
6044 regex_token_iterator& operator=(const regex_token_iterator&);
6045
Howard Hinnant262b7792010-08-17 20:42:03 +00006046 bool operator==(const regex_token_iterator& __x) const;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006048 bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
Howard Hinnanta712c722010-08-16 20:21:16 +00006049
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006051 const value_type& operator*() const {return *__result_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006052 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006053 const value_type* operator->() const {return __result_;}
Howard Hinnanta712c722010-08-16 20:21:16 +00006054
6055 regex_token_iterator& operator++();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006057 regex_token_iterator operator++(int)
6058 {
6059 regex_token_iterator __t(*this);
6060 ++(*this);
6061 return __t;
6062 }
6063
6064private:
6065 void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
Howard Hinnanta712c722010-08-16 20:21:16 +00006066};
6067
Howard Hinnant262b7792010-08-17 20:42:03 +00006068template <class _BidirectionalIterator, class _CharT, class _Traits>
6069regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6070 regex_token_iterator()
6071 : __result_(nullptr),
6072 __suffix_(),
6073 _N_(0)
6074{
6075}
6076
6077template <class _BidirectionalIterator, class _CharT, class _Traits>
6078void
6079regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6080 __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
6081{
6082 if (__position_ != _Position())
6083 {
6084 if (__subs_[_N_] == -1)
6085 __result_ = &__position_->prefix();
6086 else
6087 __result_ = &(*__position_)[__subs_[_N_]];
6088 }
6089 else if (__subs_[_N_] == -1)
6090 {
6091 __suffix_.matched = true;
6092 __suffix_.first = __a;
6093 __suffix_.second = __b;
6094 __result_ = &__suffix_;
6095 }
6096 else
6097 __result_ = nullptr;
6098}
6099
6100template <class _BidirectionalIterator, class _CharT, class _Traits>
6101regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6102 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6103 const regex_type& __re, int __submatch,
6104 regex_constants::match_flag_type __m)
6105 : __position_(__a, __b, __re, __m),
6106 _N_(0),
6107 __subs_(1, __submatch)
6108{
6109 __init(__a, __b);
6110}
6111
6112template <class _BidirectionalIterator, class _CharT, class _Traits>
6113regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6114 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6115 const regex_type& __re, const vector<int>& __submatches,
6116 regex_constants::match_flag_type __m)
6117 : __position_(__a, __b, __re, __m),
6118 _N_(0),
6119 __subs_(__submatches)
6120{
6121 __init(__a, __b);
6122}
6123
6124template <class _BidirectionalIterator, class _CharT, class _Traits>
6125regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6126 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6127 const regex_type& __re,
6128 initializer_list<int> __submatches,
6129 regex_constants::match_flag_type __m)
6130 : __position_(__a, __b, __re, __m),
6131 _N_(0),
6132 __subs_(__submatches)
6133{
6134 __init(__a, __b);
6135}
6136
6137template <class _BidirectionalIterator, class _CharT, class _Traits>
6138template <size_t _N>
6139regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6140 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6141 const regex_type& __re,
6142 const int (&__submatches)[_N],
6143 regex_constants::match_flag_type __m)
6144 : __position_(__a, __b, __re, __m),
6145 _N_(0),
6146 __subs_(__submatches, __submatches + _N)
6147{
6148 __init(__a, __b);
6149}
6150
6151template <class _BidirectionalIterator, class _CharT, class _Traits>
6152regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6153 regex_token_iterator(const regex_token_iterator& __x)
6154 : __position_(__x.__position_),
6155 __result_(__x.__result_),
6156 __suffix_(__x.__suffix_),
6157 _N_(__x._N_),
6158 __subs_(__x.__subs_)
6159{
6160 if (__x.__result_ == &__x.__suffix_)
6161 __result_ == &__suffix_;
6162}
6163
6164template <class _BidirectionalIterator, class _CharT, class _Traits>
6165regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6166regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6167 operator=(const regex_token_iterator& __x)
6168{
6169 if (this != &__x)
6170 {
6171 __position_ = __x.__position_;
6172 if (__x.__result_ == &__x.__suffix_)
6173 __result_ == &__suffix_;
6174 else
6175 __result_ = __x.__result_;
6176 __suffix_ = __x.__suffix_;
6177 _N_ = __x._N_;
6178 __subs_ = __x.__subs_;
6179 }
6180 return *this;
6181}
6182
6183template <class _BidirectionalIterator, class _CharT, class _Traits>
6184bool
6185regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6186 operator==(const regex_token_iterator& __x) const
6187{
6188 if (__result_ == nullptr && __x.__result_ == nullptr)
6189 return true;
6190 if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
6191 __suffix_ == __x.__suffix_)
6192 return true;
6193 if (__result_ == nullptr || __x.__result_ == nullptr)
6194 return false;
6195 if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
6196 return false;
6197 return __position_ == __x.__position_ && _N_ == __x._N_ &&
6198 __subs_ == __x.__subs_;
6199}
6200
6201template <class _BidirectionalIterator, class _CharT, class _Traits>
6202regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6203regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6204{
6205 _Position __prev = __position_;
6206 if (__result_ == &__suffix_)
6207 __result_ = nullptr;
6208 else if (_N_ + 1 < __subs_.size())
6209 {
6210 ++_N_;
6211 if (__subs_[_N_] == -1)
6212 __result_ = &__position_->prefix();
6213 else
6214 __result_ = &(*__position_)[__subs_[_N_]];
6215 }
6216 else
6217 {
6218 _N_ = 0;
6219 ++__position_;
6220 if (__position_ != _Position())
6221 {
6222 if (__subs_[_N_] == -1)
6223 __result_ = &__position_->prefix();
6224 else
6225 __result_ = &(*__position_)[__subs_[_N_]];
6226 }
6227 else
6228 {
6229 if (_STD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
6230 && __prev->suffix().length() != 0)
6231 {
6232 __suffix_.matched = true;
6233 __suffix_.first = __prev->suffix().first;
6234 __suffix_.second = __prev->suffix().second;
6235 __result_ = &__suffix_;
6236 }
6237 else
6238 __result_ = nullptr;
6239 }
6240 }
6241 return *this;
6242}
6243
Howard Hinnanta712c722010-08-16 20:21:16 +00006244typedef regex_token_iterator<const char*> cregex_token_iterator;
6245typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
6246typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
6247typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
6248
Howard Hinnanta8d77592010-08-18 00:13:08 +00006249// regex_replace
6250
6251template <class _OutputIterator, class _BidirectionalIterator,
6252 class _Traits, class _CharT>
6253_OutputIterator
6254regex_replace(_OutputIterator __out,
6255 _BidirectionalIterator __first, _BidirectionalIterator __last,
6256 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6257 regex_constants::match_flag_type __flags = regex_constants::match_default)
6258{
6259 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
6260 _Iter __i(__first, __last, __e, __flags);
6261 _Iter __eof;
6262 if (__i == __eof)
6263 {
6264 if (!(__flags & regex_constants::format_no_copy))
6265 __out = _STD::copy(__first, __last, __out);
6266 }
6267 else
6268 {
6269 sub_match<_BidirectionalIterator> __lm;
6270 for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
6271 {
6272 if (!(__flags & regex_constants::format_no_copy))
6273 __out = _STD::copy(__i->prefix().first, __i->prefix().second, __out);
6274 __out = __i->format(__out, __fmt, __fmt + __len, __flags);
6275 __lm = __i->suffix();
6276 if (__flags & regex_constants::format_first_only)
6277 break;
6278 }
6279 if (!(__flags & regex_constants::format_no_copy))
6280 __out = _STD::copy(__lm.first, __lm.second, __out);
6281 }
6282 return __out;
6283}
6284
6285template <class _OutputIterator, class _BidirectionalIterator,
6286 class _Traits, class _CharT, class _ST, class _SA>
6287inline _LIBCPP_INLINE_VISIBILITY
6288_OutputIterator
6289regex_replace(_OutputIterator __out,
6290 _BidirectionalIterator __first, _BidirectionalIterator __last,
6291 const basic_regex<_CharT, _Traits>& __e,
6292 const basic_string<_CharT, _ST, _SA>& __fmt,
6293 regex_constants::match_flag_type __flags = regex_constants::match_default)
6294{
6295 return _STD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
6296}
6297
6298template <class _Traits, class _CharT, class _ST, class _SA, class _FST,
6299 class _FSA>
6300inline _LIBCPP_INLINE_VISIBILITY
6301basic_string<_CharT, _ST, _SA>
6302regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6303 const basic_regex<_CharT, _Traits>& __e,
6304 const basic_string<_CharT, _FST, _FSA>& __fmt,
6305 regex_constants::match_flag_type __flags = regex_constants::match_default)
6306{
6307 basic_string<_CharT, _ST, _SA> __r;
6308 _STD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6309 __fmt.c_str(), __flags);
6310 return __r;
6311}
6312
6313template <class _Traits, class _CharT, class _ST, class _SA>
6314inline _LIBCPP_INLINE_VISIBILITY
6315basic_string<_CharT, _ST, _SA>
6316regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6317 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6318 regex_constants::match_flag_type __flags = regex_constants::match_default)
6319{
6320 basic_string<_CharT, _ST, _SA> __r;
6321 _STD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6322 __fmt, __flags);
6323 return __r;
6324}
6325
6326template <class _Traits, class _CharT, class _ST, class _SA>
6327inline _LIBCPP_INLINE_VISIBILITY
6328basic_string<_CharT>
6329regex_replace(const _CharT* __s,
6330 const basic_regex<_CharT, _Traits>& __e,
6331 const basic_string<_CharT, _ST, _SA>& __fmt,
6332 regex_constants::match_flag_type __flags = regex_constants::match_default)
6333{
6334 basic_string<_CharT> __r;
6335 _STD::regex_replace(back_inserter(__r), __s,
6336 __s + char_traits<_CharT>::length(__s), __e,
6337 __fmt.c_str(), __flags);
6338 return __r;
6339}
6340
6341template <class _Traits, class _CharT>
6342inline _LIBCPP_INLINE_VISIBILITY
6343basic_string<_CharT>
6344regex_replace(const _CharT* __s,
6345 const basic_regex<_CharT, _Traits>& __e,
6346 const _CharT* __fmt,
6347 regex_constants::match_flag_type __flags = regex_constants::match_default)
6348{
6349 basic_string<_CharT> __r;
6350 _STD::regex_replace(back_inserter(__r), __s,
6351 __s + char_traits<_CharT>::length(__s), __e,
6352 __fmt, __flags);
6353 return __r;
6354}
6355
Howard Hinnant3257c982010-06-17 00:34:59 +00006356_LIBCPP_END_NAMESPACE_STD
6357
6358#endif // _LIBCPP_REGEX