blob: 418cdaa87d79442f77b34d153c95a6a669f2f24f [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
211 difference_type length() const;
212 operator string_type() const;
213 string_type str() const;
214
215 int compare(const sub_match& s) const;
216 int compare(const string_type& s) const;
217 int compare(const value_type* s) const;
218};
219
220typedef sub_match<const char*> csub_match;
221typedef sub_match<const wchar_t*> wcsub_match;
222typedef sub_match<string::const_iterator> ssub_match;
223typedef sub_match<wstring::const_iterator> wssub_match;
224
225template <class BiIter>
226 bool
227 operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
228
229template <class BiIter>
230 bool
231 operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
232
233template <class BiIter>
234 bool
235 operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
236
237template <class BiIter>
238 bool
239 operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
240
241template <class BiIter>
242 bool
243 operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
244
245template <class BiIter>
246 bool
247 operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
248
249template <class BiIter, class ST, class SA>
250 bool
251 operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
252 const sub_match<BiIter>& rhs);
253
254template <class BiIter, class ST, class SA>
255 bool
256 operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
257 const sub_match<BiIter>& rhs);
258
259template <class BiIter, class ST, class SA>
260 bool
261 operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
262 const sub_match<BiIter>& rhs);
263
264template <class BiIter, class ST, class SA>
265 bool
266 operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
267 const sub_match<BiIter>& rhs);
268
269template <class BiIter, class ST, class SA>
270 bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
271 const sub_match<BiIter>& rhs);
272
273template <class BiIter, class ST, class SA>
274 bool
275 operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
276 const sub_match<BiIter>& rhs);
277
278template <class BiIter, class ST, class SA>
279 bool
280 operator==(const sub_match<BiIter>& lhs,
281 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
282
283template <class BiIter, class ST, class SA>
284 bool
285 operator!=(const sub_match<BiIter>& lhs,
286 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
287
288template <class BiIter, class ST, class SA>
289 bool
290 operator<(const sub_match<BiIter>& lhs,
291 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
292
293template <class BiIter, class ST, class SA>
294 bool operator>(const sub_match<BiIter>& lhs,
295 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
296
297template <class BiIter, class ST, class SA>
298 bool
299 operator>=(const sub_match<BiIter>& lhs,
300 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
301
302template <class BiIter, class ST, class SA>
303 bool
304 operator<=(const sub_match<BiIter>& lhs,
305 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
306
307template <class BiIter>
308 bool
309 operator==(typename iterator_traits<BiIter>::value_type const* lhs,
310 const sub_match<BiIter>& rhs);
311
312template <class BiIter>
313 bool
314 operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
315 const sub_match<BiIter>& rhs);
316
317template <class BiIter>
318 bool
319 operator<(typename iterator_traits<BiIter>::value_type const* lhs,
320 const sub_match<BiIter>& rhs);
321
322template <class BiIter>
323 bool
324 operator>(typename iterator_traits<BiIter>::value_type const* lhs,
325 const sub_match<BiIter>& rhs);
326
327template <class BiIter>
328 bool
329 operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
330 const sub_match<BiIter>& rhs);
331
332template <class BiIter>
333 bool
334 operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
335 const sub_match<BiIter>& rhs);
336
337template <class BiIter>
338 bool
339 operator==(const sub_match<BiIter>& lhs,
340 typename iterator_traits<BiIter>::value_type const* rhs);
341
342template <class BiIter>
343 bool
344 operator!=(const sub_match<BiIter>& lhs,
345 typename iterator_traits<BiIter>::value_type const* rhs);
346
347template <class BiIter>
348 bool
349 operator<(const sub_match<BiIter>& lhs,
350 typename iterator_traits<BiIter>::value_type const* rhs);
351
352template <class BiIter>
353 bool
354 operator>(const sub_match<BiIter>& lhs,
355 typename iterator_traits<BiIter>::value_type const* rhs);
356
357template <class BiIter>
358 bool
359 operator>=(const sub_match<BiIter>& lhs,
360 typename iterator_traits<BiIter>::value_type const* rhs);
361
362template <class BiIter>
363 bool
364 operator<=(const sub_match<BiIter>& lhs,
365 typename iterator_traits<BiIter>::value_type const* rhs);
366
367template <class BiIter>
368 bool
369 operator==(typename iterator_traits<BiIter>::value_type const& lhs,
370 const sub_match<BiIter>& rhs);
371
372template <class BiIter>
373 bool
374 operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
375 const sub_match<BiIter>& rhs);
376
377template <class BiIter>
378 bool
379 operator<(typename iterator_traits<BiIter>::value_type const& lhs,
380 const sub_match<BiIter>& rhs);
381
382template <class BiIter>
383 bool
384 operator>(typename iterator_traits<BiIter>::value_type const& lhs,
385 const sub_match<BiIter>& rhs);
386
387template <class BiIter>
388 bool
389 operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
390 const sub_match<BiIter>& rhs);
391
392template <class BiIter>
393 bool
394 operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
395 const sub_match<BiIter>& rhs);
396
397template <class BiIter>
398 bool
399 operator==(const sub_match<BiIter>& lhs,
400 typename iterator_traits<BiIter>::value_type const& rhs);
401
402template <class BiIter>
403 bool
404 operator!=(const sub_match<BiIter>& lhs,
405 typename iterator_traits<BiIter>::value_type const& rhs);
406
407template <class BiIter>
408 bool
409 operator<(const sub_match<BiIter>& lhs,
410 typename iterator_traits<BiIter>::value_type const& rhs);
411
412template <class BiIter>
413 bool
414 operator>(const sub_match<BiIter>& lhs,
415 typename iterator_traits<BiIter>::value_type const& rhs);
416
417template <class BiIter>
418 bool
419 operator>=(const sub_match<BiIter>& lhs,
420 typename iterator_traits<BiIter>::value_type const& rhs);
421
422template <class BiIter>
423 bool
424 operator<=(const sub_match<BiIter>& lhs,
425 typename iterator_traits<BiIter>::value_type const& rhs);
426
427template <class charT, class ST, class BiIter>
428 basic_ostream<charT, ST>&
429 operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
430
431template <class BidirectionalIterator,
432 class Allocator = allocator<sub_match<BidirectionalIterator>>>
433class match_results
434{
435public:
436 typedef sub_match<BidirectionalIterator> value_type;
437 typedef const value_type& const_reference;
438 typedef const_reference reference;
439 typedef /implementation-defined/ const_iterator;
440 typedef const_iterator iterator;
441 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
442 typedef typename allocator_traits<Allocator>::size_type size_type;
443 typedef Allocator allocator_type;
444 typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
445 typedef basic_string<char_type> string_type;
446
447 // construct/copy/destroy:
448 explicit match_results(const Allocator& a = Allocator());
449 match_results(const match_results& m);
450 match_results(match_results&& m);
451 match_results& operator=(const match_results& m);
452 match_results& operator=(match_results&& m);
453 ~match_results();
454
455 // size:
456 size_type size() const;
457 size_type max_size() const;
458 bool empty() const;
459
460 // element access:
461 difference_type length(size_type sub = 0) const;
462 difference_type position(size_type sub = 0) const;
463 string_type str(size_type sub = 0) const;
464 const_reference operator[](size_type n) const;
465
466 const_reference prefix() const;
467 const_reference suffix() const;
468
469 const_iterator begin() const;
470 const_iterator end() const;
471 const_iterator cbegin() const;
472 const_iterator cend() const;
473
474 // format:
475 template <class OutputIter>
476 OutputIter
477 format(OutputIter out, const char_type* fmt_first,
478 const char_type* fmt_last,
479 regex_constants::match_flag_type flags = regex_constants::format_default) const;
480 template <class OutputIter, class ST, class SA>
481 OutputIter
482 format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
483 regex_constants::match_flag_type flags = regex_constants::format_default) const;
484 template <class ST, class SA>
485 basic_string<char_type, ST, SA>
486 format(const basic_string<char_type, ST, SA>& fmt,
487 regex_constants::match_flag_type flags = regex_constants::format_default) const;
488 string_type
489 format(const char_type* fmt,
490 regex_constants::match_flag_type flags = regex_constants::format_default) const;
491
492 // allocator:
493 allocator_type get_allocator() const;
494
495 // swap:
496 void swap(match_results& that);
497};
498
499typedef match_results<const char*> cmatch;
500typedef match_results<const wchar_t*> wcmatch;
501typedef match_results<string::const_iterator> smatch;
502typedef match_results<wstring::const_iterator> wsmatch;
503
504template <class BidirectionalIterator, class Allocator>
505 bool
506 operator==(const match_results<BidirectionalIterator, Allocator>& m1,
507 const match_results<BidirectionalIterator, Allocator>& m2);
508
509template <class BidirectionalIterator, class Allocator>
510 bool
511 operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
512 const match_results<BidirectionalIterator, Allocator>& m2);
513
514template <class BidirectionalIterator, class Allocator>
515 void
516 swap(match_results<BidirectionalIterator, Allocator>& m1,
517 match_results<BidirectionalIterator, Allocator>& m2);
518
519template <class BidirectionalIterator, class Allocator, class charT, class traits>
520 bool
521 regex_match(BidirectionalIterator first, BidirectionalIterator last,
522 match_results<BidirectionalIterator, Allocator>& m,
523 const basic_regex<charT, traits>& e,
524 regex_constants::match_flag_type flags = regex_constants::match_default);
525
526template <class BidirectionalIterator, class charT, class traits>
527 bool
528 regex_match(BidirectionalIterator first, BidirectionalIterator last,
529 const basic_regex<charT, traits>& e,
530 regex_constants::match_flag_type flags = regex_constants::match_default);
531
532template <class charT, class Allocator, class traits>
533 bool
534 regex_match(const charT* str, match_results<const charT*, Allocator>& m,
535 const basic_regex<charT, traits>& e,
536 regex_constants::match_flag_type flags = regex_constants::match_default);
537
538template <class ST, class SA, class Allocator, class charT, class traits>
539 bool
540 regex_match(const basic_string<charT, ST, SA>& s,
541 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
542 const basic_regex<charT, traits>& e,
543 regex_constants::match_flag_type flags = regex_constants::match_default);
544
545template <class charT, class traits>
546 bool
547 regex_match(const charT* str, const basic_regex<charT, traits>& e,
548 regex_constants::match_flag_type flags = regex_constants::match_default);
549
550template <class ST, class SA, class charT, class traits>
551 bool
552 regex_match(const basic_string<charT, ST, SA>& s,
553 const basic_regex<charT, traits>& e,
554 regex_constants::match_flag_type flags = regex_constants::match_default);
555
556template <class BidirectionalIterator, class Allocator, class charT, class traits>
557 bool
558 regex_search(BidirectionalIterator first, BidirectionalIterator last,
559 match_results<BidirectionalIterator, Allocator>& m,
560 const basic_regex<charT, traits>& e,
561 regex_constants::match_flag_type flags = regex_constants::match_default);
562
563template <class BidirectionalIterator, class charT, class traits>
564 bool
565 regex_search(BidirectionalIterator first, BidirectionalIterator last,
566 const basic_regex<charT, traits>& e,
567 regex_constants::match_flag_type flags = regex_constants::match_default);
568
569template <class charT, class Allocator, class traits>
570 bool
571 regex_search(const charT* str, match_results<const charT*, Allocator>& m,
572 const basic_regex<charT, traits>& e,
573 regex_constants::match_flag_type flags = regex_constants::match_default);
574
575template <class charT, class traits>
576 bool
577 regex_search(const charT* str, const basic_regex<charT, traits>& e,
578 regex_constants::match_flag_type flags = regex_constants::match_default);
579
580template <class ST, class SA, class charT, class traits>
581 bool
582 regex_search(const basic_string<charT, ST, SA>& s,
583 const basic_regex<charT, traits>& e,
584 regex_constants::match_flag_type flags = regex_constants::match_default);
585
586template <class ST, class SA, class Allocator, class charT, class traits>
587 bool
588 regex_search(const basic_string<charT, ST, SA>& s,
589 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
590 const basic_regex<charT, traits>& e,
591 regex_constants::match_flag_type flags = regex_constants::match_default);
592
593template <class OutputIterator, class BidirectionalIterator,
594 class traits, class charT, class ST, class SA>
595 OutputIterator
596 regex_replace(OutputIterator out,
597 BidirectionalIterator first, BidirectionalIterator last,
598 const basic_regex<charT, traits>& e,
599 const basic_string<charT, ST, SA>& fmt,
600 regex_constants::match_flag_type flags = regex_constants::match_default);
601
602template <class OutputIterator, class BidirectionalIterator,
603 class traits, class charT>
604 OutputIterator
605 regex_replace(OutputIterator out,
606 BidirectionalIterator first, BidirectionalIterator last,
607 const basic_regex<charT, traits>& e, const charT* fmt,
608 regex_constants::match_flag_type flags = regex_constants::match_default);
609
610template <class traits, class charT, class ST, class SA, class FST, class FSA>>
611 basic_string<charT, ST, SA>
612 regex_replace(const basic_string<charT, ST, SA>& s,
613 const basic_regex<charT, traits>& e,
614 const basic_string<charT, FST, FSA>& fmt,
615 regex_constants::match_flag_type flags = regex_constants::match_default);
616
617template <class traits, class charT, class ST, class SA>
618 basic_string<charT, ST, SA>
619 regex_replace(const basic_string<charT, ST, SA>& s,
620 const basic_regex<charT, traits>& e, const charT* fmt,
621 regex_constants::match_flag_type flags = regex_constants::match_default);
622
623template <class traits, class charT, class ST, class SA>
624 basic_string<charT>
625 regex_replace(const charT* s,
626 const basic_regex<charT, traits>& e,
627 const basic_string<charT, ST, SA>& fmt,
628 regex_constants::match_flag_type flags = regex_constants::match_default);
629
630template <class traits, class charT>
631 basic_string<charT>
632 regex_replace(const charT* s,
633 const basic_regex<charT, traits>& e,
634 const charT* fmt,
635 regex_constants::match_flag_type flags = regex_constants::match_default);
636
637template <class BidirectionalIterator,
638 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
639 class traits = regex_traits<charT>>
640class regex_iterator
641{
642public:
643 typedef basic_regex<charT, traits> regex_type;
644 typedef match_results<BidirectionalIterator> value_type;
645 typedef ptrdiff_t difference_type;
646 typedef const value_type* pointer;
647 typedef const value_type& reference;
648 typedef forward_iterator_tag iterator_category;
649
650 regex_iterator();
651 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
652 const regex_type& re,
653 regex_constants::match_flag_type m = regex_constants::match_default);
654 regex_iterator(const regex_iterator&);
655 regex_iterator& operator=(const regex_iterator&);
656
657 bool operator==(const regex_iterator&) const;
658 bool operator!=(const regex_iterator&) const;
659
660 const value_type& operator*() const;
661 const value_type* operator->() const;
662
663 regex_iterator& operator++();
664 regex_iterator operator++(int);
665};
666
667typedef regex_iterator<const char*> cregex_iterator;
668typedef regex_iterator<const wchar_t*> wcregex_iterator;
669typedef regex_iterator<string::const_iterator> sregex_iterator;
670typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
671
672template <class BidirectionalIterator,
673 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
674 class traits = regex_traits<charT>>
675class regex_token_iterator
676{
677public:
678 typedef basic_regex<charT, traits> regex_type;
679 typedef sub_match<BidirectionalIterator> value_type;
680 typedef ptrdiff_t difference_type;
681 typedef const value_type* pointer;
682 typedef const value_type& reference;
683 typedef forward_iterator_tag iterator_category;
684
685 regex_token_iterator();
686 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
687 const regex_type& re, int submatch = 0,
688 regex_constants::match_flag_type m = regex_constants::match_default);
689 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
690 const regex_type& re, const vector<int>& submatches,
691 regex_constants::match_flag_type m = regex_constants::match_default);
692 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
693 const regex_type& re, initializer_list<int> submatches,
694 regex_constants::match_flag_type m = regex_constants::match_default);
695 template <size_t N>
696 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
697 const regex_type& re, const int (&submatches)[N],
698 regex_constants::match_flag_type m = regex_constants::match_default);
699 regex_token_iterator(const regex_token_iterator&);
700 regex_token_iterator& operator=(const regex_token_iterator&);
701
702 bool operator==(const regex_token_iterator&) const;
703 bool operator!=(const regex_token_iterator&) const;
704
705 const value_type& operator*() const;
706 const value_type* operator->() const;
707
708 regex_token_iterator& operator++();
709 regex_token_iterator operator++(int);
710};
711
712typedef regex_token_iterator<const char*> cregex_token_iterator;
713typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
714typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
715typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
716
717} // std
718*/
719
720#include <__config>
721#include <stdexcept>
722#include <__locale>
Howard Hinnant8c2c18d2010-06-24 21:28:00 +0000723#include <initializer_list>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +0000724#include <utility>
725#include <iterator>
726#include <string>
Howard Hinnant7e9d84b2010-06-30 00:21:42 +0000727#include <memory>
728#include <vector>
Howard Hinnantac303862010-07-12 15:51:17 +0000729#include <deque>
Howard Hinnant3257c982010-06-17 00:34:59 +0000730
731#pragma GCC system_header
732
733_LIBCPP_BEGIN_NAMESPACE_STD
734
735namespace regex_constants
736{
737
738// syntax_option_type
739
740enum syntax_option_type
741{
742 icase = 1 << 0,
743 nosubs = 1 << 1,
744 optimize = 1 << 2,
745 collate = 1 << 3,
Howard Hinnantad2a7ab2010-07-27 17:24:17 +0000746 ECMAScript = 0,
747 basic = 1 << 4,
748 extended = 1 << 5,
749 awk = 1 << 6,
750 grep = 1 << 7,
751 egrep = 1 << 8
Howard Hinnant3257c982010-06-17 00:34:59 +0000752};
753
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000754inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000755/*constexpr*/
756syntax_option_type
757operator~(syntax_option_type __x)
758{
759 return syntax_option_type(~int(__x));
760}
761
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000762inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000763/*constexpr*/
764syntax_option_type
765operator&(syntax_option_type __x, syntax_option_type __y)
766{
767 return syntax_option_type(int(__x) & int(__y));
768}
769
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000770inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000771/*constexpr*/
772syntax_option_type
773operator|(syntax_option_type __x, syntax_option_type __y)
774{
775 return syntax_option_type(int(__x) | int(__y));
776}
777
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000778inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000779/*constexpr*/
780syntax_option_type
781operator^(syntax_option_type __x, syntax_option_type __y)
782{
783 return syntax_option_type(int(__x) ^ int(__y));
784}
785
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000786inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000787/*constexpr*/
788syntax_option_type&
789operator&=(syntax_option_type& __x, syntax_option_type __y)
790{
791 __x = __x & __y;
792 return __x;
793}
794
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000795inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000796/*constexpr*/
797syntax_option_type&
798operator|=(syntax_option_type& __x, syntax_option_type __y)
799{
800 __x = __x | __y;
801 return __x;
802}
803
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000804inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000805/*constexpr*/
806syntax_option_type&
807operator^=(syntax_option_type& __x, syntax_option_type __y)
808{
809 __x = __x ^ __y;
810 return __x;
811}
812
813// match_flag_type
814
815enum match_flag_type
816{
817 match_default = 0,
818 match_not_bol = 1 << 0,
819 match_not_eol = 1 << 1,
820 match_not_bow = 1 << 2,
821 match_not_eow = 1 << 3,
822 match_any = 1 << 4,
823 match_not_null = 1 << 5,
824 match_continuous = 1 << 6,
825 match_prev_avail = 1 << 7,
826 format_default = 0,
827 format_sed = 1 << 8,
828 format_no_copy = 1 << 9,
Howard Hinnanta712c722010-08-16 20:21:16 +0000829 format_first_only = 1 << 10,
830 __no_update_pos = 1 << 11
Howard Hinnant3257c982010-06-17 00:34:59 +0000831};
832
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000833inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000834/*constexpr*/
835match_flag_type
836operator~(match_flag_type __x)
837{
838 return match_flag_type(~int(__x));
839}
840
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000841inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000842/*constexpr*/
843match_flag_type
844operator&(match_flag_type __x, match_flag_type __y)
845{
846 return match_flag_type(int(__x) & int(__y));
847}
848
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000849inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000850/*constexpr*/
851match_flag_type
852operator|(match_flag_type __x, match_flag_type __y)
853{
854 return match_flag_type(int(__x) | int(__y));
855}
856
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000857inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000858/*constexpr*/
859match_flag_type
860operator^(match_flag_type __x, match_flag_type __y)
861{
862 return match_flag_type(int(__x) ^ int(__y));
863}
864
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000865inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000866/*constexpr*/
867match_flag_type&
868operator&=(match_flag_type& __x, match_flag_type __y)
869{
870 __x = __x & __y;
871 return __x;
872}
873
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000874inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000875/*constexpr*/
876match_flag_type&
877operator|=(match_flag_type& __x, match_flag_type __y)
878{
879 __x = __x | __y;
880 return __x;
881}
882
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000883inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000884/*constexpr*/
885match_flag_type&
886operator^=(match_flag_type& __x, match_flag_type __y)
887{
888 __x = __x ^ __y;
889 return __x;
890}
891
892enum error_type
893{
894 error_collate = 1,
895 error_ctype,
896 error_escape,
897 error_backref,
898 error_brack,
899 error_paren,
900 error_brace,
901 error_badbrace,
902 error_range,
903 error_space,
904 error_badrepeat,
905 error_complexity,
Howard Hinnant8c2c18d2010-06-24 21:28:00 +0000906 error_stack,
Howard Hinnantad2a7ab2010-07-27 17:24:17 +0000907 __re_err_grammar,
908 __re_err_empty,
909 __re_err_unknown
Howard Hinnant3257c982010-06-17 00:34:59 +0000910};
911
912} // regex_constants
913
914class _LIBCPP_EXCEPTION_ABI regex_error
915 : public runtime_error
916{
917 regex_constants::error_type __code_;
918public:
919 explicit regex_error(regex_constants::error_type __ecode);
920 virtual ~regex_error() throw();
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000922 regex_constants::error_type code() const {return __code_;}
923};
924
925template <class _CharT>
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000926struct _LIBCPP_VISIBLE regex_traits
Howard Hinnant3257c982010-06-17 00:34:59 +0000927{
928public:
929 typedef _CharT char_type;
930 typedef basic_string<char_type> string_type;
931 typedef locale locale_type;
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000932 typedef ctype_base::mask char_class_type;
Howard Hinnant3257c982010-06-17 00:34:59 +0000933
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000934 static const char_class_type __regex_word = 0x80;
Howard Hinnant3257c982010-06-17 00:34:59 +0000935private:
936 locale __loc_;
937 const ctype<char_type>* __ct_;
938 const collate<char_type>* __col_;
939
940public:
941 regex_traits();
942
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000943 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000944 static size_t length(const char_type* __p)
945 {return char_traits<char_type>::length(__p);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000946 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000947 char_type translate(char_type __c) const {return __c;}
948 char_type translate_nocase(char_type __c) const;
949 template <class _ForwardIterator>
950 string_type
951 transform(_ForwardIterator __f, _ForwardIterator __l) const;
952 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000953 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000954 string_type
955 transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
956 {return __transform_primary(__f, __l, char_type());}
957 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000958 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000959 string_type
960 lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
961 {return __lookup_collatename(__f, __l, char_type());}
962 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000963 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000964 char_class_type
965 lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000966 bool __icase = false) const
967 {return __lookup_classname(__f, __l, __icase, char_type());}
968 bool isctype(char_type __c, char_class_type __m) const;
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000970 int value(char_type __ch, int __radix) const
971 {return __value(__ch, __radix);}
Howard Hinnant3257c982010-06-17 00:34:59 +0000972 locale_type imbue(locale_type __l);
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000974 locale_type getloc()const {return __loc_;}
975
976private:
977 void __init();
978
979 template <class _ForwardIterator>
980 string_type
981 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
982 template <class _ForwardIterator>
983 string_type
984 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
985
986 template <class _ForwardIterator>
987 string_type
988 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
989 template <class _ForwardIterator>
990 string_type
991 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000992
993 template <class _ForwardIterator>
994 char_class_type
995 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
996 bool __icase, char) const;
997 template <class _ForwardIterator>
998 char_class_type
999 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1000 bool __icase, wchar_t) const;
1001
1002 static int __value(unsigned char __ch, int __radix);
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001003 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001004 int __value(char __ch, int __radix) const
1005 {return __value(static_cast<unsigned char>(__ch), __radix);}
1006 int __value(wchar_t __ch, int __radix) const;
Howard Hinnant3257c982010-06-17 00:34:59 +00001007};
1008
1009template <class _CharT>
1010regex_traits<_CharT>::regex_traits()
1011{
1012 __init();
1013}
1014
1015template <class _CharT>
1016typename regex_traits<_CharT>::char_type
1017regex_traits<_CharT>::translate_nocase(char_type __c) const
1018{
1019 return __ct_->tolower(__c);
1020}
1021
1022template <class _CharT>
1023template <class _ForwardIterator>
1024typename regex_traits<_CharT>::string_type
1025regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
1026{
1027 string_type __s(__f, __l);
1028 return __col_->transform(__s.data(), __s.data() + __s.size());
1029}
1030
1031template <class _CharT>
1032void
1033regex_traits<_CharT>::__init()
1034{
1035 __ct_ = &use_facet<ctype<char_type> >(__loc_);
1036 __col_ = &use_facet<collate<char_type> >(__loc_);
1037}
1038
1039template <class _CharT>
1040typename regex_traits<_CharT>::locale_type
1041regex_traits<_CharT>::imbue(locale_type __l)
1042{
1043 locale __r = __loc_;
1044 __loc_ = __l;
1045 __init();
1046 return __r;
1047}
1048
1049// transform_primary is very FreeBSD-specific
1050
1051template <class _CharT>
1052template <class _ForwardIterator>
1053typename regex_traits<_CharT>::string_type
1054regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1055 _ForwardIterator __l, char) const
1056{
1057 const string_type __s(__f, __l);
1058 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1059 switch (__d.size())
1060 {
1061 case 1:
1062 break;
1063 case 12:
1064 __d[11] = __d[3];
1065 break;
1066 default:
1067 __d.clear();
1068 break;
1069 }
1070 return __d;
1071}
1072
1073template <class _CharT>
1074template <class _ForwardIterator>
1075typename regex_traits<_CharT>::string_type
1076regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1077 _ForwardIterator __l, wchar_t) const
1078{
1079 const string_type __s(__f, __l);
1080 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1081 switch (__d.size())
1082 {
1083 case 1:
1084 break;
1085 case 3:
1086 __d[2] = __d[0];
1087 break;
1088 default:
1089 __d.clear();
1090 break;
1091 }
1092 return __d;
1093}
1094
1095// lookup_collatename is very FreeBSD-specific
1096
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001097string __get_collation_name(const char* __s);
Howard Hinnant3257c982010-06-17 00:34:59 +00001098
1099template <class _CharT>
1100template <class _ForwardIterator>
1101typename regex_traits<_CharT>::string_type
1102regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1103 _ForwardIterator __l, char) const
1104{
1105 string_type __s(__f, __l);
1106 string_type __r;
1107 if (!__s.empty())
1108 {
1109 __r = __get_collation_name(__s.c_str());
1110 if (__r.empty() && __s.size() <= 2)
1111 {
1112 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1113 if (__r.size() == 1 || __r.size() == 12)
1114 __r = __s;
1115 else
1116 __r.clear();
1117 }
1118 }
1119 return __r;
1120}
1121
1122template <class _CharT>
1123template <class _ForwardIterator>
1124typename regex_traits<_CharT>::string_type
1125regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1126 _ForwardIterator __l, wchar_t) const
1127{
1128 string_type __s(__f, __l);
1129 string __n;
1130 __n.reserve(__s.size());
1131 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1132 __i != __e; ++__i)
1133 {
1134 if (static_cast<unsigned>(*__i) >= 127)
1135 return string_type();
1136 __n.push_back(char(*__i));
1137 }
1138 string_type __r;
1139 if (!__s.empty())
1140 {
1141 __n = __get_collation_name(__n.c_str());
1142 if (!__n.empty())
1143 __r.assign(__n.begin(), __n.end());
1144 else if (__s.size() <= 2)
1145 {
1146 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1147 if (__r.size() == 1 || __r.size() == 3)
1148 __r = __s;
1149 else
1150 __r.clear();
1151 }
1152 }
1153 return __r;
1154}
1155
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001156// lookup_classname
1157
1158ctype_base::mask __get_classname(const char* __s, bool __icase);
1159
1160template <class _CharT>
1161template <class _ForwardIterator>
1162typename regex_traits<_CharT>::char_class_type
1163regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1164 _ForwardIterator __l,
1165 bool __icase, char) const
1166{
1167 string_type __s(__f, __l);
1168 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1169 return __get_classname(__s.c_str(), __icase);
1170}
1171
1172template <class _CharT>
1173template <class _ForwardIterator>
1174typename regex_traits<_CharT>::char_class_type
1175regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1176 _ForwardIterator __l,
1177 bool __icase, wchar_t) const
1178{
1179 string_type __s(__f, __l);
1180 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1181 string __n;
1182 __n.reserve(__s.size());
1183 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1184 __i != __e; ++__i)
1185 {
1186 if (static_cast<unsigned>(*__i) >= 127)
1187 return char_class_type();
1188 __n.push_back(char(*__i));
1189 }
1190 return __get_classname(__n.c_str(), __icase);
1191}
1192
1193template <class _CharT>
1194bool
1195regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
1196{
1197 if (__ct_->is(__m, __c))
1198 return true;
1199 return (__c == '_' && (__m & __regex_word));
1200}
1201
1202template <class _CharT>
1203int
1204regex_traits<_CharT>::__value(unsigned char __ch, int __radix)
1205{
1206 if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
1207 return __ch - '0';
1208 if (__radix != 8)
1209 {
1210 if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
1211 return __ch - '0';
1212 if (__radix == 16)
1213 {
1214 __ch |= 0x20; // tolower
1215 if ('a' <= __ch && __ch <= 'f')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001216 return __ch - ('a' - 10);
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001217 }
1218 }
1219 return -1;
1220}
1221
1222template <class _CharT>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001223inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001224int
1225regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const
1226{
1227 return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
1228}
1229
Howard Hinnantac303862010-07-12 15:51:17 +00001230template <class _CharT> class __node;
1231
1232template <class _BidirectionalIterator> class sub_match;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001233
Howard Hinnant17615b02010-07-27 01:25:38 +00001234template <class _BidirectionalIterator,
1235 class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1236class match_results;
1237
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001238template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001239struct __state
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001240{
1241 enum
1242 {
1243 __end_state = -1000,
1244 __consume_input, // -999
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001245 __begin_marked_expr, // -998
1246 __end_marked_expr, // -997
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001247 __pop_state, // -996
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001248 __accept_and_consume, // -995
1249 __accept_but_not_consume, // -994
1250 __reject, // -993
Howard Hinnantac303862010-07-12 15:51:17 +00001251 __split,
1252 __repeat
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001253 };
1254
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001255 int __do_;
Howard Hinnantac303862010-07-12 15:51:17 +00001256 const _CharT* __first_;
1257 const _CharT* __current_;
1258 const _CharT* __last_;
1259 vector<sub_match<const _CharT*> > __sub_matches_;
1260 vector<pair<size_t, const _CharT*> > __loop_data_;
1261 const __node<_CharT>* __node_;
1262 regex_constants::match_flag_type __flags_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001263
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001265 __state()
1266 : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
1267 __node_(nullptr), __flags_() {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001268};
1269
Howard Hinnantac303862010-07-12 15:51:17 +00001270// __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001271
1272template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001273class __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001274{
Howard Hinnantac303862010-07-12 15:51:17 +00001275 __node(const __node&);
1276 __node& operator=(const __node&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001277public:
Howard Hinnantac303862010-07-12 15:51:17 +00001278 typedef _STD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001279
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001281 __node() {}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001283 virtual ~__node() {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001284
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001286 virtual void __exec(__state&) const {};
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001288 virtual void __exec_split(bool, __state&) const {};
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001289};
1290
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001291// __end_state
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001292
1293template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001294class __end_state
Howard Hinnantac303862010-07-12 15:51:17 +00001295 : public __node<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001296{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001297public:
Howard Hinnantac303862010-07-12 15:51:17 +00001298 typedef _STD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001299
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001301 __end_state() {}
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001302
Howard Hinnantac303862010-07-12 15:51:17 +00001303 virtual void __exec(__state&) const;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001304};
1305
1306template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001307void
1308__end_state<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001309{
Howard Hinnantac303862010-07-12 15:51:17 +00001310 __s.__do_ = __state::__end_state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001311}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001312
1313// __has_one_state
1314
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001315template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001316class __has_one_state
Howard Hinnantac303862010-07-12 15:51:17 +00001317 : public __node<_CharT>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001318{
Howard Hinnantac303862010-07-12 15:51:17 +00001319 __node<_CharT>* __first_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001320
1321public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001322 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001323 explicit __has_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001324 : __first_(__s) {}
1325
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001327 __node<_CharT>* first() const {return __first_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001329 __node<_CharT>*& first() {return __first_;}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001330};
1331
1332// __owns_one_state
1333
1334template <class _CharT>
1335class __owns_one_state
1336 : public __has_one_state<_CharT>
1337{
1338 typedef __has_one_state<_CharT> base;
1339
1340public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001341 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001342 explicit __owns_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001343 : base(__s) {}
1344
1345 virtual ~__owns_one_state();
1346};
1347
1348template <class _CharT>
1349__owns_one_state<_CharT>::~__owns_one_state()
1350{
1351 delete this->first();
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001352}
1353
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001354// __empty_state
1355
1356template <class _CharT>
1357class __empty_state
1358 : public __owns_one_state<_CharT>
1359{
1360 typedef __owns_one_state<_CharT> base;
1361
1362public:
Howard Hinnantac303862010-07-12 15:51:17 +00001363 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001364
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001366 explicit __empty_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001367 : base(__s) {}
1368
Howard Hinnantac303862010-07-12 15:51:17 +00001369 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001370};
1371
1372template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001373void
1374__empty_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001375{
Howard Hinnantac303862010-07-12 15:51:17 +00001376 __s.__do_ = __state::__accept_but_not_consume;
1377 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001378}
1379
1380// __empty_non_own_state
1381
1382template <class _CharT>
1383class __empty_non_own_state
1384 : public __has_one_state<_CharT>
1385{
1386 typedef __has_one_state<_CharT> base;
1387
1388public:
Howard Hinnantac303862010-07-12 15:51:17 +00001389 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001390
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001392 explicit __empty_non_own_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001393 : base(__s) {}
1394
Howard Hinnantac303862010-07-12 15:51:17 +00001395 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001396};
1397
1398template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001399void
1400__empty_non_own_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001401{
Howard Hinnantac303862010-07-12 15:51:17 +00001402 __s.__do_ = __state::__accept_but_not_consume;
1403 __s.__node_ = this->first();
1404}
1405
1406// __repeat_one_loop
1407
1408template <class _CharT>
1409class __repeat_one_loop
1410 : public __has_one_state<_CharT>
1411{
1412 typedef __has_one_state<_CharT> base;
1413
1414public:
1415 typedef _STD::__state<_CharT> __state;
1416
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001418 explicit __repeat_one_loop(__node<_CharT>* __s)
1419 : base(__s) {}
1420
1421 virtual void __exec(__state&) const;
Howard Hinnantac303862010-07-12 15:51:17 +00001422};
1423
1424template <class _CharT>
1425void
1426__repeat_one_loop<_CharT>::__exec(__state& __s) const
1427{
1428 __s.__do_ = __state::__repeat;
1429 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001430}
1431
1432// __owns_two_states
1433
1434template <class _CharT>
1435class __owns_two_states
1436 : public __owns_one_state<_CharT>
1437{
1438 typedef __owns_one_state<_CharT> base;
1439
1440 base* __second_;
1441
1442public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001444 explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001445 : base(__s1), __second_(__s2) {}
1446
1447 virtual ~__owns_two_states();
1448
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001450 base* second() const {return __second_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001452 base*& second() {return __second_;}
1453};
1454
1455template <class _CharT>
1456__owns_two_states<_CharT>::~__owns_two_states()
1457{
1458 delete __second_;
1459}
1460
1461// __loop
1462
1463template <class _CharT>
1464class __loop
1465 : public __owns_two_states<_CharT>
1466{
1467 typedef __owns_two_states<_CharT> base;
1468
1469 size_t __min_;
1470 size_t __max_;
1471 unsigned __loop_id_;
Howard Hinnantac303862010-07-12 15:51:17 +00001472 unsigned __mexp_begin_;
1473 unsigned __mexp_end_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001474 bool __greedy_;
1475
1476public:
Howard Hinnantac303862010-07-12 15:51:17 +00001477 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001478
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001480 explicit __loop(unsigned __loop_id,
Howard Hinnantac303862010-07-12 15:51:17 +00001481 __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
1482 unsigned __mexp_begin, unsigned __mexp_end,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001483 bool __greedy = true,
1484 size_t __min = 0,
1485 size_t __max = numeric_limits<size_t>::max())
1486 : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
Howard Hinnantac303862010-07-12 15:51:17 +00001487 __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001488 __greedy_(__greedy) {}
1489
Howard Hinnantac303862010-07-12 15:51:17 +00001490 virtual void __exec(__state& __s) const;
1491 virtual void __exec_split(bool __second, __state& __s) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001492
Howard Hinnantac303862010-07-12 15:51:17 +00001493private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001495 void __init_repeat(__state& __s) const
1496 {
1497 __s.__loop_data_[__loop_id_].second = __s.__current_;
1498 for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
1499 {
1500 __s.__sub_matches_[__i].first = __s.__last_;
1501 __s.__sub_matches_[__i].second = __s.__last_;
1502 __s.__sub_matches_[__i].matched = false;
1503 }
1504 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001505};
1506
1507template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001508void
1509__loop<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001510{
Howard Hinnantac303862010-07-12 15:51:17 +00001511 if (__s.__do_ == __state::__repeat)
1512 {
1513 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1514 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1515 if (__do_repeat && __do_alt &&
1516 __s.__loop_data_[__loop_id_].second == __s.__current_)
1517 __do_repeat = false;
1518 if (__do_repeat && __do_alt)
1519 __s.__do_ = __state::__split;
1520 else if (__do_repeat)
1521 {
1522 __s.__do_ = __state::__accept_but_not_consume;
1523 __s.__node_ = this->first();
1524 __init_repeat(__s);
1525 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001526 else
Howard Hinnantac303862010-07-12 15:51:17 +00001527 {
1528 __s.__do_ = __state::__accept_but_not_consume;
1529 __s.__node_ = this->second();
1530 }
1531 }
1532 else
1533 {
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00001534 __s.__loop_data_[__loop_id_].first = 0;
1535 bool __do_repeat = 0 < __max_;
1536 bool __do_alt = 0 >= __min_;
1537 if (__do_repeat && __do_alt)
Howard Hinnantac303862010-07-12 15:51:17 +00001538 __s.__do_ = __state::__split;
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00001539 else if (__do_repeat)
1540 {
1541 __s.__do_ = __state::__accept_but_not_consume;
1542 __s.__node_ = this->first();
1543 __init_repeat(__s);
1544 }
Howard Hinnantac303862010-07-12 15:51:17 +00001545 else
1546 {
1547 __s.__do_ = __state::__accept_but_not_consume;
1548 __s.__node_ = this->second();
1549 }
1550 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001551}
1552
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001553template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001554void
1555__loop<_CharT>::__exec_split(bool __second, __state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001556{
Howard Hinnantac303862010-07-12 15:51:17 +00001557 __s.__do_ = __state::__accept_but_not_consume;
1558 if (__greedy_ != __second)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001559 {
Howard Hinnantac303862010-07-12 15:51:17 +00001560 __s.__node_ = this->first();
1561 __init_repeat(__s);
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001562 }
Howard Hinnantac303862010-07-12 15:51:17 +00001563 else
1564 __s.__node_ = this->second();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001565}
1566
Howard Hinnantaa698082010-07-16 19:08:36 +00001567// __alternate
1568
1569template <class _CharT>
1570class __alternate
1571 : public __owns_two_states<_CharT>
1572{
1573 typedef __owns_two_states<_CharT> base;
1574
1575public:
1576 typedef _STD::__state<_CharT> __state;
1577
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001578 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaa698082010-07-16 19:08:36 +00001579 explicit __alternate(__owns_one_state<_CharT>* __s1,
1580 __owns_one_state<_CharT>* __s2)
1581 : base(__s1, __s2) {}
1582
1583 virtual void __exec(__state& __s) const;
1584 virtual void __exec_split(bool __second, __state& __s) const;
Howard Hinnantaa698082010-07-16 19:08:36 +00001585};
1586
1587template <class _CharT>
1588void
1589__alternate<_CharT>::__exec(__state& __s) const
1590{
1591 __s.__do_ = __state::__split;
1592}
1593
1594template <class _CharT>
1595void
1596__alternate<_CharT>::__exec_split(bool __second, __state& __s) const
1597{
1598 __s.__do_ = __state::__accept_but_not_consume;
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001599 if (__second)
Howard Hinnantaa698082010-07-16 19:08:36 +00001600 __s.__node_ = this->second();
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001601 else
1602 __s.__node_ = this->first();
Howard Hinnantaa698082010-07-16 19:08:36 +00001603}
1604
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001605// __begin_marked_subexpression
1606
1607template <class _CharT>
1608class __begin_marked_subexpression
1609 : public __owns_one_state<_CharT>
1610{
1611 typedef __owns_one_state<_CharT> base;
1612
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001613 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001614public:
Howard Hinnantac303862010-07-12 15:51:17 +00001615 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001616
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001618 explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001619 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001620
Howard Hinnantac303862010-07-12 15:51:17 +00001621 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001622};
1623
1624template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001625void
1626__begin_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001627{
Howard Hinnantac303862010-07-12 15:51:17 +00001628 __s.__do_ = __state::__accept_but_not_consume;
1629 __s.__sub_matches_[__mexp_-1].first = __s.__current_;
1630 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001631}
1632
1633// __end_marked_subexpression
1634
1635template <class _CharT>
1636class __end_marked_subexpression
1637 : public __owns_one_state<_CharT>
1638{
1639 typedef __owns_one_state<_CharT> base;
1640
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001641 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001642public:
Howard Hinnantac303862010-07-12 15:51:17 +00001643 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001644
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001646 explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001647 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001648
Howard Hinnantac303862010-07-12 15:51:17 +00001649 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001650};
1651
1652template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001653void
1654__end_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001655{
Howard Hinnantac303862010-07-12 15:51:17 +00001656 __s.__do_ = __state::__accept_but_not_consume;
1657 __s.__sub_matches_[__mexp_-1].second = __s.__current_;
1658 __s.__sub_matches_[__mexp_-1].matched = true;
1659 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001660}
1661
Howard Hinnantcba352d2010-07-12 18:16:05 +00001662// __back_ref
1663
1664template <class _CharT>
1665class __back_ref
1666 : public __owns_one_state<_CharT>
1667{
1668 typedef __owns_one_state<_CharT> base;
1669
1670 unsigned __mexp_;
1671public:
1672 typedef _STD::__state<_CharT> __state;
1673
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcba352d2010-07-12 18:16:05 +00001675 explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
1676 : base(__s), __mexp_(__mexp) {}
1677
1678 virtual void __exec(__state&) const;
Howard Hinnantcba352d2010-07-12 18:16:05 +00001679};
1680
1681template <class _CharT>
1682void
1683__back_ref<_CharT>::__exec(__state& __s) const
1684{
1685 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1686 if (__sm.matched)
1687 {
1688 ptrdiff_t __len = __sm.second - __sm.first;
1689 if (__s.__last_ - __s.__current_ >= __len &&
1690 _STD::equal(__sm.first, __sm.second, __s.__current_))
1691 {
1692 __s.__do_ = __state::__accept_but_not_consume;
1693 __s.__current_ += __len;
1694 __s.__node_ = this->first();
1695 }
1696 else
1697 {
1698 __s.__do_ = __state::__reject;
1699 __s.__node_ = nullptr;
1700 }
1701 }
1702 else
1703 {
1704 __s.__do_ = __state::__reject;
1705 __s.__node_ = nullptr;
1706 }
1707}
1708
Howard Hinnante34f17d2010-07-12 19:11:27 +00001709// __back_ref_icase
1710
1711template <class _CharT, class _Traits>
1712class __back_ref_icase
1713 : public __owns_one_state<_CharT>
1714{
1715 typedef __owns_one_state<_CharT> base;
1716
1717 _Traits __traits_;
1718 unsigned __mexp_;
1719public:
1720 typedef _STD::__state<_CharT> __state;
1721
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001722 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00001723 explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
1724 __node<_CharT>* __s)
1725 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1726
1727 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00001728};
1729
1730template <class _CharT, class _Traits>
1731void
1732__back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
1733{
1734 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1735 if (__sm.matched)
1736 {
1737 ptrdiff_t __len = __sm.second - __sm.first;
1738 if (__s.__last_ - __s.__current_ >= __len)
1739 {
1740 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1741 {
1742 if (__traits_.translate_nocase(__sm.first[__i]) !=
1743 __traits_.translate_nocase(__s.__current_[__i]))
1744 goto __not_equal;
1745 }
1746 __s.__do_ = __state::__accept_but_not_consume;
1747 __s.__current_ += __len;
1748 __s.__node_ = this->first();
1749 }
1750 else
1751 {
1752 __s.__do_ = __state::__reject;
1753 __s.__node_ = nullptr;
1754 }
1755 }
1756 else
1757 {
1758__not_equal:
1759 __s.__do_ = __state::__reject;
1760 __s.__node_ = nullptr;
1761 }
1762}
1763
1764// __back_ref_collate
1765
1766template <class _CharT, class _Traits>
1767class __back_ref_collate
1768 : public __owns_one_state<_CharT>
1769{
1770 typedef __owns_one_state<_CharT> base;
1771
1772 _Traits __traits_;
1773 unsigned __mexp_;
1774public:
1775 typedef _STD::__state<_CharT> __state;
1776
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001777 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00001778 explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
1779 __node<_CharT>* __s)
1780 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1781
1782 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00001783};
1784
1785template <class _CharT, class _Traits>
1786void
1787__back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
1788{
1789 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1790 if (__sm.matched)
1791 {
1792 ptrdiff_t __len = __sm.second - __sm.first;
1793 if (__s.__last_ - __s.__current_ >= __len)
1794 {
1795 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1796 {
1797 if (__traits_.translate(__sm.first[__i]) !=
1798 __traits_.translate(__s.__current_[__i]))
1799 goto __not_equal;
1800 }
1801 __s.__do_ = __state::__accept_but_not_consume;
1802 __s.__current_ += __len;
1803 __s.__node_ = this->first();
1804 }
1805 else
1806 {
1807 __s.__do_ = __state::__reject;
1808 __s.__node_ = nullptr;
1809 }
1810 }
1811 else
1812 {
1813__not_equal:
1814 __s.__do_ = __state::__reject;
1815 __s.__node_ = nullptr;
1816 }
1817}
1818
Howard Hinnant17615b02010-07-27 01:25:38 +00001819// __word_boundary
1820
1821template <class _CharT, class _Traits>
1822class __word_boundary
1823 : public __owns_one_state<_CharT>
1824{
1825 typedef __owns_one_state<_CharT> base;
1826
1827 _Traits __traits_;
1828 bool __invert_;
1829public:
1830 typedef _STD::__state<_CharT> __state;
1831
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant17615b02010-07-27 01:25:38 +00001833 explicit __word_boundary(const _Traits& __traits, bool __invert,
1834 __node<_CharT>* __s)
1835 : base(__s), __traits_(__traits), __invert_(__invert) {}
1836
1837 virtual void __exec(__state&) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00001838};
1839
1840template <class _CharT, class _Traits>
1841void
1842__word_boundary<_CharT, _Traits>::__exec(__state& __s) const
1843{
1844 bool __is_word_b = false;
1845 if (__s.__first_ != __s.__last_)
1846 {
1847 if (__s.__current_ == __s.__last_)
1848 {
1849 if (!(__s.__flags_ & regex_constants::match_not_eow))
1850 {
1851 _CharT __c = __s.__current_[-1];
1852 __is_word_b = __c == '_' ||
1853 __traits_.isctype(__c, ctype_base::alnum);
1854 }
1855 }
Howard Hinnantf3dcca02010-07-29 15:17:28 +00001856 else if (__s.__current_ == __s.__first_ &&
1857 !(__s.__flags_ & regex_constants::match_prev_avail))
Howard Hinnant17615b02010-07-27 01:25:38 +00001858 {
1859 if (!(__s.__flags_ & regex_constants::match_not_bow))
1860 {
1861 _CharT __c = *__s.__current_;
1862 __is_word_b = __c == '_' ||
1863 __traits_.isctype(__c, ctype_base::alnum);
1864 }
1865 }
1866 else
1867 {
1868 _CharT __c1 = __s.__current_[-1];
1869 _CharT __c2 = *__s.__current_;
1870 bool __is_c1_b = __c1 == '_' ||
1871 __traits_.isctype(__c1, ctype_base::alnum);
1872 bool __is_c2_b = __c2 == '_' ||
1873 __traits_.isctype(__c2, ctype_base::alnum);
1874 __is_word_b = __is_c1_b != __is_c2_b;
1875 }
1876 }
1877 if (__is_word_b != __invert_)
1878 {
1879 __s.__do_ = __state::__accept_but_not_consume;
1880 __s.__node_ = this->first();
1881 }
1882 else
1883 {
1884 __s.__do_ = __state::__reject;
1885 __s.__node_ = nullptr;
1886 }
1887}
1888
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001889// __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001890
1891template <class _CharT>
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001892class __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001893 : public __owns_one_state<_CharT>
1894{
1895 typedef __owns_one_state<_CharT> base;
1896
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001897public:
Howard Hinnantac303862010-07-12 15:51:17 +00001898 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001899
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001901 __r_anchor(__node<_CharT>* __s)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001902 : base(__s) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001903
Howard Hinnantac303862010-07-12 15:51:17 +00001904 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001905};
1906
1907template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001908void
1909__r_anchor<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001910{
Howard Hinnantac303862010-07-12 15:51:17 +00001911 if (__s.__current_ == __s.__last_)
1912 {
1913 __s.__do_ = __state::__accept_but_not_consume;
1914 __s.__node_ = this->first();
1915 }
1916 else
1917 {
1918 __s.__do_ = __state::__reject;
1919 __s.__node_ = nullptr;
1920 }
1921}
1922
1923// __match_any
1924
1925template <class _CharT>
1926class __match_any
1927 : public __owns_one_state<_CharT>
1928{
1929 typedef __owns_one_state<_CharT> base;
1930
1931public:
1932 typedef _STD::__state<_CharT> __state;
1933
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001934 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001935 __match_any(__node<_CharT>* __s)
1936 : base(__s) {}
1937
1938 virtual void __exec(__state&) const;
Howard Hinnantac303862010-07-12 15:51:17 +00001939};
1940
1941template <class _CharT>
1942void
1943__match_any<_CharT>::__exec(__state& __s) const
1944{
1945 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
1946 {
1947 __s.__do_ = __state::__accept_and_consume;
1948 ++__s.__current_;
1949 __s.__node_ = this->first();
1950 }
1951 else
1952 {
1953 __s.__do_ = __state::__reject;
1954 __s.__node_ = nullptr;
1955 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001956}
1957
Howard Hinnant17615b02010-07-27 01:25:38 +00001958// __match_any_but_newline
1959
1960template <class _CharT>
1961class __match_any_but_newline
1962 : public __owns_one_state<_CharT>
1963{
1964 typedef __owns_one_state<_CharT> base;
1965
1966public:
1967 typedef _STD::__state<_CharT> __state;
1968
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant17615b02010-07-27 01:25:38 +00001970 __match_any_but_newline(__node<_CharT>* __s)
1971 : base(__s) {}
1972
1973 virtual void __exec(__state&) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00001974};
1975
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001976// __match_char
1977
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001978template <class _CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001979class __match_char
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001980 : public __owns_one_state<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001981{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001982 typedef __owns_one_state<_CharT> base;
1983
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001984 _CharT __c_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001985
1986 __match_char(const __match_char&);
1987 __match_char& operator=(const __match_char&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001988public:
Howard Hinnantac303862010-07-12 15:51:17 +00001989 typedef _STD::__state<_CharT> __state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001990
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001991 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001992 __match_char(_CharT __c, __node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001993 : base(__s), __c_(__c) {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001994
Howard Hinnantac303862010-07-12 15:51:17 +00001995 virtual void __exec(__state&) const;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001996};
1997
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001998template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001999void
2000__match_char<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002001{
Howard Hinnantac303862010-07-12 15:51:17 +00002002 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
2003 {
2004 __s.__do_ = __state::__accept_and_consume;
2005 ++__s.__current_;
2006 __s.__node_ = this->first();
2007 }
2008 else
2009 {
2010 __s.__do_ = __state::__reject;
2011 __s.__node_ = nullptr;
2012 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002013}
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002014
Howard Hinnante34f17d2010-07-12 19:11:27 +00002015// __match_char_icase
2016
2017template <class _CharT, class _Traits>
2018class __match_char_icase
2019 : public __owns_one_state<_CharT>
2020{
2021 typedef __owns_one_state<_CharT> base;
2022
2023 _Traits __traits_;
2024 _CharT __c_;
2025
2026 __match_char_icase(const __match_char_icase&);
2027 __match_char_icase& operator=(const __match_char_icase&);
2028public:
2029 typedef _STD::__state<_CharT> __state;
2030
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002031 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00002032 __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2033 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
2034
2035 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00002036};
2037
2038template <class _CharT, class _Traits>
2039void
2040__match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
2041{
2042 if (__s.__current_ != __s.__last_ &&
2043 __traits_.translate_nocase(*__s.__current_) == __c_)
2044 {
2045 __s.__do_ = __state::__accept_and_consume;
2046 ++__s.__current_;
2047 __s.__node_ = this->first();
2048 }
2049 else
2050 {
2051 __s.__do_ = __state::__reject;
2052 __s.__node_ = nullptr;
2053 }
2054}
2055
2056// __match_char_collate
2057
2058template <class _CharT, class _Traits>
2059class __match_char_collate
2060 : public __owns_one_state<_CharT>
2061{
2062 typedef __owns_one_state<_CharT> base;
2063
2064 _Traits __traits_;
2065 _CharT __c_;
2066
2067 __match_char_collate(const __match_char_collate&);
2068 __match_char_collate& operator=(const __match_char_collate&);
2069public:
2070 typedef _STD::__state<_CharT> __state;
2071
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002072 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00002073 __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2074 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2075
2076 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00002077};
2078
2079template <class _CharT, class _Traits>
2080void
2081__match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
2082{
2083 if (__s.__current_ != __s.__last_ &&
2084 __traits_.translate(*__s.__current_) == __c_)
2085 {
2086 __s.__do_ = __state::__accept_and_consume;
2087 ++__s.__current_;
2088 __s.__node_ = this->first();
2089 }
2090 else
2091 {
2092 __s.__do_ = __state::__reject;
2093 __s.__node_ = nullptr;
2094 }
2095}
2096
Howard Hinnant173968a2010-07-13 21:48:06 +00002097// __bracket_expression
2098
2099template <class _CharT, class _Traits>
2100class __bracket_expression
2101 : public __owns_one_state<_CharT>
2102{
2103 typedef __owns_one_state<_CharT> base;
2104 typedef typename _Traits::string_type string_type;
2105
2106 _Traits __traits_;
2107 vector<_CharT> __chars_;
Howard Hinnant15476f32010-07-28 17:35:27 +00002108 vector<_CharT> __neg_chars_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002109 vector<pair<string_type, string_type> > __ranges_;
2110 vector<pair<_CharT, _CharT> > __digraphs_;
2111 vector<string_type> __equivalences_;
2112 ctype_base::mask __mask_;
Howard Hinnant15476f32010-07-28 17:35:27 +00002113 ctype_base::mask __neg_mask_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002114 bool __negate_;
2115 bool __icase_;
2116 bool __collate_;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002117 bool __might_have_digraph_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002118
2119 __bracket_expression(const __bracket_expression&);
2120 __bracket_expression& operator=(const __bracket_expression&);
2121public:
2122 typedef _STD::__state<_CharT> __state;
2123
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002125 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
2126 bool __negate, bool __icase, bool __collate)
Howard Hinnant15476f32010-07-28 17:35:27 +00002127 : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
2128 __negate_(__negate), __icase_(__icase), __collate_(__collate),
Howard Hinnant68025ed2010-07-14 15:45:11 +00002129 __might_have_digraph_(__traits_.getloc().name() != "C") {}
Howard Hinnant173968a2010-07-13 21:48:06 +00002130
2131 virtual void __exec(__state&) const;
2132
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002133 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant15476f32010-07-28 17:35:27 +00002134 bool __negated() const {return __negate_;}
2135
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002136 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002137 void __add_char(_CharT __c)
2138 {
2139 if (__icase_)
2140 __chars_.push_back(__traits_.translate_nocase(__c));
2141 else if (__collate_)
2142 __chars_.push_back(__traits_.translate(__c));
2143 else
2144 __chars_.push_back(__c);
2145 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002146 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant15476f32010-07-28 17:35:27 +00002147 void __add_neg_char(_CharT __c)
2148 {
2149 if (__icase_)
2150 __neg_chars_.push_back(__traits_.translate_nocase(__c));
2151 else if (__collate_)
2152 __neg_chars_.push_back(__traits_.translate(__c));
2153 else
2154 __neg_chars_.push_back(__c);
2155 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002156 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002157 void __add_range(string_type __b, string_type __e)
2158 {
2159 if (__collate_)
2160 {
2161 if (__icase_)
2162 {
2163 for (size_t __i = 0; __i < __b.size(); ++__i)
2164 __b[__i] = __traits_.translate_nocase(__b[__i]);
2165 for (size_t __i = 0; __i < __e.size(); ++__i)
2166 __e[__i] = __traits_.translate_nocase(__e[__i]);
2167 }
2168 else
2169 {
2170 for (size_t __i = 0; __i < __b.size(); ++__i)
2171 __b[__i] = __traits_.translate(__b[__i]);
2172 for (size_t __i = 0; __i < __e.size(); ++__i)
2173 __e[__i] = __traits_.translate(__e[__i]);
2174 }
2175 __ranges_.push_back(make_pair(
2176 __traits_.transform(__b.begin(), __b.end()),
2177 __traits_.transform(__e.begin(), __e.end())));
2178 }
2179 else
2180 {
Howard Hinnantd4444702010-08-11 17:04:31 +00002181#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00002182 if (__b.size() != 1 || __e.size() != 1)
2183 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00002184#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00002185 if (__icase_)
2186 {
2187 __b[0] = __traits_.translate_nocase(__b[0]);
2188 __e[0] = __traits_.translate_nocase(__e[0]);
2189 }
2190 __ranges_.push_back(make_pair(_STD::move(__b), _STD::move(__e)));
2191 }
2192 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002193 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002194 void __add_digraph(_CharT __c1, _CharT __c2)
2195 {
2196 if (__icase_)
2197 __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
2198 __traits_.translate_nocase(__c2)));
2199 else if (__collate_)
2200 __digraphs_.push_back(make_pair(__traits_.translate(__c1),
2201 __traits_.translate(__c2)));
2202 else
2203 __digraphs_.push_back(make_pair(__c1, __c2));
2204 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002205 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002206 void __add_equivalence(const string_type& __s)
2207 {__equivalences_.push_back(__s);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002209 void __add_class(ctype_base::mask __mask)
2210 {__mask_ |= __mask;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002211 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant15476f32010-07-28 17:35:27 +00002212 void __add_neg_class(ctype_base::mask __mask)
2213 {__neg_mask_ |= __mask;}
Howard Hinnant173968a2010-07-13 21:48:06 +00002214};
2215
2216template <class _CharT, class _Traits>
2217void
2218__bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
2219{
2220 bool __found = false;
2221 unsigned __consumed = 0;
2222 if (__s.__current_ != __s.__last_)
2223 {
2224 ++__consumed;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002225 if (__might_have_digraph_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002226 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002227 const _CharT* __next = next(__s.__current_);
2228 if (__next != __s.__last_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002229 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002230 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2231 if (__icase_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002232 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002233 __ch2.first = __traits_.translate_nocase(__ch2.first);
2234 __ch2.second = __traits_.translate_nocase(__ch2.second);
2235 }
2236 else if (__collate_)
2237 {
2238 __ch2.first = __traits_.translate(__ch2.first);
2239 __ch2.second = __traits_.translate(__ch2.second);
2240 }
2241 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
2242 {
2243 // __ch2 is a digraph in this locale
2244 ++__consumed;
2245 for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
2246 {
2247 if (__ch2 == __digraphs_[__i])
2248 {
2249 __found = true;
2250 goto __exit;
2251 }
2252 }
2253 if (__collate_ && !__ranges_.empty())
2254 {
2255 string_type __s2 = __traits_.transform(&__ch2.first,
2256 &__ch2.first + 2);
2257 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2258 {
2259 if (__ranges_[__i].first <= __s2 &&
2260 __s2 <= __ranges_[__i].second)
2261 {
2262 __found = true;
2263 goto __exit;
2264 }
2265 }
2266 }
2267 if (!__equivalences_.empty())
2268 {
2269 string_type __s2 = __traits_.transform_primary(&__ch2.first,
2270 &__ch2.first + 2);
2271 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2272 {
2273 if (__s2 == __equivalences_[__i])
2274 {
2275 __found = true;
2276 goto __exit;
2277 }
2278 }
2279 }
2280 if (__traits_.isctype(__ch2.first, __mask_) &&
2281 __traits_.isctype(__ch2.second, __mask_))
Howard Hinnant173968a2010-07-13 21:48:06 +00002282 {
2283 __found = true;
2284 goto __exit;
2285 }
Howard Hinnant15476f32010-07-28 17:35:27 +00002286 if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
2287 !__traits_.isctype(__ch2.second, __neg_mask_))
2288 {
2289 __found = true;
2290 goto __exit;
2291 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002292 goto __exit;
2293 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002294 }
2295 }
2296 // test *__s.__current_ as not a digraph
2297 _CharT __ch = *__s.__current_;
2298 if (__icase_)
2299 __ch = __traits_.translate_nocase(__ch);
2300 else if (__collate_)
2301 __ch = __traits_.translate(__ch);
2302 for (size_t __i = 0; __i < __chars_.size(); ++__i)
2303 {
2304 if (__ch == __chars_[__i])
2305 {
2306 __found = true;
2307 goto __exit;
2308 }
2309 }
Howard Hinnant15476f32010-07-28 17:35:27 +00002310 if (!__neg_chars_.empty())
2311 {
2312 for (size_t __i = 0; __i < __neg_chars_.size(); ++__i)
2313 {
2314 if (__ch == __neg_chars_[__i])
2315 goto __is_neg_char;
2316 }
2317 __found = true;
2318 goto __exit;
2319 }
2320__is_neg_char:
Howard Hinnant173968a2010-07-13 21:48:06 +00002321 if (!__ranges_.empty())
2322 {
2323 string_type __s2 = __collate_ ?
2324 __traits_.transform(&__ch, &__ch + 1) :
2325 string_type(1, __ch);
2326 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2327 {
2328 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
2329 {
2330 __found = true;
2331 goto __exit;
2332 }
2333 }
2334 }
2335 if (!__equivalences_.empty())
2336 {
2337 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2338 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2339 {
2340 if (__s2 == __equivalences_[__i])
2341 {
2342 __found = true;
2343 goto __exit;
2344 }
2345 }
2346 }
2347 if (__traits_.isctype(__ch, __mask_))
Howard Hinnant15476f32010-07-28 17:35:27 +00002348 {
Howard Hinnant173968a2010-07-13 21:48:06 +00002349 __found = true;
Howard Hinnant15476f32010-07-28 17:35:27 +00002350 goto __exit;
2351 }
2352 if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_))
2353 {
2354 __found = true;
2355 goto __exit;
2356 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002357 }
2358 else
2359 __found = __negate_; // force reject
2360__exit:
2361 if (__found != __negate_)
2362 {
Howard Hinnant173968a2010-07-13 21:48:06 +00002363 __s.__do_ = __state::__accept_and_consume;
2364 __s.__current_ += __consumed;
2365 __s.__node_ = this->first();
2366 }
2367 else
2368 {
2369 __s.__do_ = __state::__reject;
2370 __s.__node_ = nullptr;
2371 }
2372}
2373
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002374template <class, class> class __lookahead;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002375
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002376template <class _CharT, class _Traits = regex_traits<_CharT> >
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002377class _LIBCPP_VISIBLE basic_regex
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002378{
2379public:
2380 // types:
2381 typedef _CharT value_type;
2382 typedef regex_constants::syntax_option_type flag_type;
2383 typedef typename _Traits::locale_type locale_type;
2384
2385private:
2386 _Traits __traits_;
2387 flag_type __flags_;
2388 unsigned __marked_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002389 unsigned __loop_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002390 int __open_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002391 shared_ptr<__empty_state<_CharT> > __start_;
2392 __owns_one_state<_CharT>* __end_;
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002393 bool __left_anchor_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002394
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002395 typedef _STD::__state<_CharT> __state;
Howard Hinnantac303862010-07-12 15:51:17 +00002396 typedef _STD::__node<_CharT> __node;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002397
2398public:
2399 // constants:
2400 static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase;
2401 static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2402 static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize;
2403 static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate;
2404 static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2405 static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic;
2406 static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended;
2407 static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk;
2408 static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep;
2409 static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep;
2410
2411 // construct/copy/destroy:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002413 basic_regex()
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002414 : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0),
2415 __end_(0), __left_anchor_(false)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002416 {}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002418 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002419 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2420 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002421 {__parse(__p, __p + __traits_.length(__p));}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002423 basic_regex(const value_type* __p, size_t __len, flag_type __f)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002424 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2425 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002426 {__parse(__p, __p + __len);}
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002427// basic_regex(const basic_regex&) = default;
2428// basic_regex(basic_regex&&) = default;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002429 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002430 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002431 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2432 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002433 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2434 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002435 {__parse(__p.begin(), __p.end());}
2436 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002437 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002438 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
2439 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002440 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2441 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002442 {__parse(__first, __last);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002444 basic_regex(initializer_list<value_type> __il,
2445 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002446 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2447 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002448 {__parse(__il.begin(), __il.end());}
2449
Howard Hinnant7026a172010-08-13 18:11:23 +00002450// ~basic_regex() = default;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002451
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002452// basic_regex& operator=(const basic_regex&) = default;
2453// basic_regex& operator=(basic_regex&&) = default;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002455 basic_regex& operator=(const value_type* __p)
2456 {return assign(__p);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002458 basic_regex& operator=(initializer_list<value_type> __il)
2459 {return assign(__il);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002460 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002462 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
2463 {return assign(__p);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002464
2465 // assign:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002467 basic_regex& assign(const basic_regex& __that)
2468 {return *this = __that;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002469 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002470 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2471 {return assign(__p, __p + __traits_.length(__p), __f);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002472 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002473 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f)
2474 {return assign(__p, __p + __len, __f);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002475 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002477 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
Howard Hinnant7026a172010-08-13 18:11:23 +00002478 flag_type __f = regex_constants::ECMAScript)
2479 {return assign(__s.begin(), __s.end(), __f);}
2480
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002481 template <class _InputIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002483 typename enable_if
2484 <
2485 __is_input_iterator <_InputIterator>::value &&
2486 !__is_forward_iterator<_InputIterator>::value,
2487 basic_regex&
2488 >::type
2489 assign(_InputIterator __first, _InputIterator __last,
2490 flag_type __f = regex_constants::ECMAScript)
2491 {
2492 basic_string<_CharT> __t(__first, __last);
2493 return assign(__t.begin(), __t.end(), __f);
2494 }
2495
2496private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002498 void __member_init(flag_type __f)
2499 {
2500 __flags_ = __f;
2501 __marked_count_ = 0;
2502 __loop_count_ = 0;
2503 __open_count_ = 0;
2504 __end_ = nullptr;
2505 __left_anchor_ = false;
2506 }
2507public:
2508
2509 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002511 typename enable_if
2512 <
2513 __is_forward_iterator<_ForwardIterator>::value,
2514 basic_regex&
2515 >::type
2516 assign(_ForwardIterator __first, _ForwardIterator __last,
2517 flag_type __f = regex_constants::ECMAScript)
2518 {
2519 __member_init(__f);
2520 __parse(__first, __last);
2521 }
2522
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002523 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002524 basic_regex& assign(initializer_list<value_type> __il,
Howard Hinnant7026a172010-08-13 18:11:23 +00002525 flag_type __f = regex_constants::ECMAScript)
2526 {return assign(__il.begin(), __il.end(), __f);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002527
2528 // const operations:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002530 unsigned mark_count() const {return __marked_count_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002532 flag_type flags() const {return __flags_;}
2533
2534 // locale:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002536 locale_type imbue(locale_type __loc)
2537 {
2538 __member_init(ECMAScript);
2539 __start_.reset();
2540 return __traits_.imbue(__loc);
2541 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002542 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002543 locale_type getloc() const {return __traits_.getloc();}
2544
2545 // swap:
Howard Hinnant7026a172010-08-13 18:11:23 +00002546 void swap(basic_regex& __r);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002547
2548private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002550 unsigned __loop_count() const {return __loop_count_;}
2551
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002552 template <class _ForwardIterator>
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002553 _ForwardIterator
2554 __parse(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002555 template <class _ForwardIterator>
2556 _ForwardIterator
2557 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2558 template <class _ForwardIterator>
2559 _ForwardIterator
2560 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2561 template <class _ForwardIterator>
2562 _ForwardIterator
2563 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2564 template <class _ForwardIterator>
2565 _ForwardIterator
2566 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2567 template <class _ForwardIterator>
2568 _ForwardIterator
2569 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2570 template <class _ForwardIterator>
2571 _ForwardIterator
2572 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2573 template <class _ForwardIterator>
2574 _ForwardIterator
2575 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2576 template <class _ForwardIterator>
2577 _ForwardIterator
2578 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2579 template <class _ForwardIterator>
2580 _ForwardIterator
2581 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2582 template <class _ForwardIterator>
2583 _ForwardIterator
2584 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2585 template <class _ForwardIterator>
2586 _ForwardIterator
2587 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2588 template <class _ForwardIterator>
2589 _ForwardIterator
2590 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2591 template <class _ForwardIterator>
2592 _ForwardIterator
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002593 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002594 __owns_one_state<_CharT>* __s,
2595 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002596 template <class _ForwardIterator>
2597 _ForwardIterator
Howard Hinnantaa698082010-07-16 19:08:36 +00002598 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2599 __owns_one_state<_CharT>* __s,
2600 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002601 template <class _ForwardIterator>
2602 _ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00002603 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2604 template <class _ForwardIterator>
2605 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002606 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
2607 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002608 template <class _ForwardIterator>
2609 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002610 __parse_expression_term(_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_equivalence_class(_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_character_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_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
2623 basic_string<_CharT>& __col_sym);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002624 template <class _ForwardIterator>
2625 _ForwardIterator
2626 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002627 template <class _ForwardIterator>
2628 _ForwardIterator
2629 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2630 template <class _ForwardIterator>
2631 _ForwardIterator
2632 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2633 template <class _ForwardIterator>
2634 _ForwardIterator
2635 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2636 template <class _ForwardIterator>
2637 _ForwardIterator
2638 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2639 template <class _ForwardIterator>
2640 _ForwardIterator
2641 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2642 template <class _ForwardIterator>
2643 _ForwardIterator
2644 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002645 template <class _ForwardIterator>
2646 _ForwardIterator
2647 __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2648 template <class _ForwardIterator>
2649 _ForwardIterator
2650 __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2651 template <class _ForwardIterator>
2652 _ForwardIterator
2653 __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2654 template <class _ForwardIterator>
2655 _ForwardIterator
2656 __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2657 template <class _ForwardIterator>
2658 _ForwardIterator
2659 __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2660 template <class _ForwardIterator>
2661 _ForwardIterator
Howard Hinnant17615b02010-07-27 01:25:38 +00002662 __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2663 template <class _ForwardIterator>
2664 _ForwardIterator
2665 __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2666 template <class _ForwardIterator>
2667 _ForwardIterator
2668 __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2669 template <class _ForwardIterator>
2670 _ForwardIterator
Howard Hinnant15476f32010-07-28 17:35:27 +00002671 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
2672 basic_string<_CharT>* __str = nullptr);
Howard Hinnant17615b02010-07-27 01:25:38 +00002673 template <class _ForwardIterator>
2674 _ForwardIterator
2675 __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant856846b2010-07-27 19:53:10 +00002676 template <class _ForwardIterator>
2677 _ForwardIterator
2678 __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
2679 template <class _ForwardIterator>
2680 _ForwardIterator
2681 __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant15476f32010-07-28 17:35:27 +00002682 template <class _ForwardIterator>
2683 _ForwardIterator
2684 __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
2685 basic_string<_CharT>& __str,
2686 __bracket_expression<_CharT, _Traits>* __ml);
2687 template <class _ForwardIterator>
2688 _ForwardIterator
2689 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
2690 basic_string<_CharT>* __str = nullptr);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002691
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002693 void __push_l_anchor() {__left_anchor_ = true;}
2694 void __push_r_anchor();
Howard Hinnantac303862010-07-12 15:51:17 +00002695 void __push_match_any();
Howard Hinnant17615b02010-07-27 01:25:38 +00002696 void __push_match_any_but_newline();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002697 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002698 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2699 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2700 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2701 __mexp_begin, __mexp_end);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant17615b02010-07-27 01:25:38 +00002703 void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2704 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2705 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2706 __mexp_begin, __mexp_end, false);}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002707 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2708 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2709 bool __greedy = true);
Howard Hinnant173968a2010-07-13 21:48:06 +00002710 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002711 void __push_char(value_type __c);
Howard Hinnantcba352d2010-07-12 18:16:05 +00002712 void __push_back_ref(int __i);
Howard Hinnantaa698082010-07-16 19:08:36 +00002713 void __push_alternation(__owns_one_state<_CharT>* __sa,
2714 __owns_one_state<_CharT>* __sb);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002715 void __push_begin_marked_subexpression();
2716 void __push_end_marked_subexpression(unsigned);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002717 void __push_empty();
Howard Hinnant17615b02010-07-27 01:25:38 +00002718 void __push_word_boundary(bool);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002719 void __push_lookahead(const basic_regex&, bool);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002720
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002721 template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002722 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002723 __search(const _CharT* __first, const _CharT* __last,
2724 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002725 regex_constants::match_flag_type __flags) const;
2726
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002727 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002728 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002729 __match_at_start(const _CharT* __first, const _CharT* __last,
2730 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002731 regex_constants::match_flag_type __flags) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00002732 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002733 bool
Howard Hinnant17615b02010-07-27 01:25:38 +00002734 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
2735 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002736 regex_constants::match_flag_type __flags) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002737 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002738 bool
2739 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002740 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002741 regex_constants::match_flag_type __flags) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002742 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002743 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002744 __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
2745 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002746 regex_constants::match_flag_type __flags) const;
2747
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002748 template <class _B, class _A, class _C, class _T>
2749 friend
2750 bool
2751 regex_search(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
2752 regex_constants::match_flag_type);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002753
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002754 template <class _A, class _C, class _T>
2755 friend
2756 bool
2757 regex_search(const _C*, const _C*, match_results<const _C*, _A>&,
2758 const basic_regex<_C, _T>&, regex_constants::match_flag_type);
2759
2760 template <class _B, class _C, class _T>
2761 friend
2762 bool
2763 regex_search(_B, _B, const basic_regex<_C, _T>&,
2764 regex_constants::match_flag_type);
2765
2766 template <class _C, class _T>
2767 friend
2768 bool
2769 regex_search(const _C*, const _C*,
2770 const basic_regex<_C, _T>&, regex_constants::match_flag_type);
2771
2772 template <class _C, class _A, class _T>
2773 friend
2774 bool
2775 regex_search(const _C*, match_results<const _C*, _A>&, const basic_regex<_C, _T>&,
2776 regex_constants::match_flag_type);
2777
2778 template <class _ST, class _SA, class _C, class _T>
2779 friend
2780 bool
2781 regex_search(const basic_string<_C, _ST, _SA>& __s,
2782 const basic_regex<_C, _T>& __e,
2783 regex_constants::match_flag_type __flags);
2784
2785 template <class _ST, class _SA, class _A, class _C, class _T>
2786 friend
2787 bool
2788 regex_search(const basic_string<_C, _ST, _SA>& __s,
Howard Hinnant324bb032010-08-22 00:02:43 +00002789 match_results<typename basic_string<_C, _ST, _SA>::const_iterator, _A>&,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002790 const basic_regex<_C, _T>& __e,
2791 regex_constants::match_flag_type __flags);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002792
2793 template <class, class> friend class __lookahead;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002794};
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002795
2796template <class _CharT, class _Traits>
Howard Hinnant7026a172010-08-13 18:11:23 +00002797void
2798basic_regex<_CharT, _Traits>::swap(basic_regex& __r)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002799{
Howard Hinnant7026a172010-08-13 18:11:23 +00002800 using _STD::swap;
2801 swap(__traits_, __r.__traits_);
2802 swap(__flags_, __r.__flags_);
2803 swap(__marked_count_, __r.__marked_count_);
2804 swap(__loop_count_, __r.__loop_count_);
2805 swap(__open_count_, __r.__open_count_);
2806 swap(__start_, __r.__start_);
2807 swap(__end_, __r.__end_);
2808 swap(__left_anchor_, __r.__left_anchor_);
2809}
2810
2811template <class _CharT, class _Traits>
2812inline _LIBCPP_INLINE_VISIBILITY
2813void
2814swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
2815{
2816 return __x.swap(__y);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002817}
2818
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002819// __lookahead
2820
2821template <class _CharT, class _Traits>
2822class __lookahead
2823 : public __owns_one_state<_CharT>
2824{
2825 typedef __owns_one_state<_CharT> base;
2826
2827 basic_regex<_CharT, _Traits> __exp_;
2828 bool __invert_;
2829
2830 __lookahead(const __lookahead&);
2831 __lookahead& operator=(const __lookahead&);
2832public:
2833 typedef _STD::__state<_CharT> __state;
2834
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002835 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002836 __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s)
2837 : base(__s), __exp_(__exp), __invert_(__invert) {}
2838
2839 virtual void __exec(__state&) const;
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002840};
2841
2842template <class _CharT, class _Traits>
2843void
2844__lookahead<_CharT, _Traits>::__exec(__state& __s) const
2845{
2846 match_results<const _CharT*> __m;
2847 __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
2848 bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
2849 __m, __s.__flags_);
2850 if (__matched != __invert_)
2851 {
2852 __s.__do_ = __state::__accept_but_not_consume;
2853 __s.__node_ = this->first();
2854 }
2855 else
2856 {
2857 __s.__do_ = __state::__reject;
2858 __s.__node_ = nullptr;
2859 }
2860}
2861
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002862template <class _CharT, class _Traits>
2863template <class _ForwardIterator>
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002864_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002865basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
2866 _ForwardIterator __last)
2867{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002868 {
Howard Hinnantac303862010-07-12 15:51:17 +00002869 unique_ptr<__node> __h(new __end_state<_CharT>);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002870 __start_.reset(new __empty_state<_CharT>(__h.get()));
2871 __h.release();
2872 __end_ = __start_.get();
2873 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002874 switch (__flags_ & 0x1F0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002875 {
2876 case ECMAScript:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002877 __first = __parse_ecma_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002878 break;
2879 case basic:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002880 __first = __parse_basic_reg_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002881 break;
2882 case extended:
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002883 case awk:
Howard Hinnant15476f32010-07-28 17:35:27 +00002884 __first = __parse_extended_reg_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002885 break;
2886 case grep:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002887 __first = __parse_grep(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002888 break;
2889 case egrep:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002890 __first = __parse_egrep(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002891 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00002892#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002893 default:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002894 throw regex_error(regex_constants::__re_err_grammar);
Howard Hinnant324bb032010-08-22 00:02:43 +00002895#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002896 }
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002897 return __first;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002898}
2899
2900template <class _CharT, class _Traits>
2901template <class _ForwardIterator>
2902_ForwardIterator
2903basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
2904 _ForwardIterator __last)
2905{
2906 if (__first != __last)
2907 {
2908 if (*__first == '^')
2909 {
2910 __push_l_anchor();
2911 ++__first;
2912 }
2913 if (__first != __last)
2914 {
2915 __first = __parse_RE_expression(__first, __last);
2916 if (__first != __last)
2917 {
2918 _ForwardIterator __temp = next(__first);
2919 if (__temp == __last && *__first == '$')
2920 {
2921 __push_r_anchor();
2922 ++__first;
2923 }
2924 }
2925 }
Howard Hinnantd4444702010-08-11 17:04:31 +00002926#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002927 if (__first != __last)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002928 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00002929#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002930 }
2931 return __first;
2932}
2933
2934template <class _CharT, class _Traits>
2935template <class _ForwardIterator>
2936_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002937basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
2938 _ForwardIterator __last)
2939{
Howard Hinnantaa698082010-07-16 19:08:36 +00002940 __owns_one_state<_CharT>* __sa = __end_;
2941 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00002942#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa698082010-07-16 19:08:36 +00002943 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002944 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00002945#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa698082010-07-16 19:08:36 +00002946 __first = __temp;
2947 while (__first != __last && *__first == '|')
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002948 {
Howard Hinnantaa698082010-07-16 19:08:36 +00002949 __owns_one_state<_CharT>* __sb = __end_;
2950 __temp = __parse_ERE_branch(++__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00002951#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002952 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002953 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00002954#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantaa698082010-07-16 19:08:36 +00002955 __push_alternation(__sa, __sb);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002956 __first = __temp;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002957 }
2958 return __first;
2959}
2960
2961template <class _CharT, class _Traits>
2962template <class _ForwardIterator>
2963_ForwardIterator
2964basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
2965 _ForwardIterator __last)
2966{
2967 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00002968#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002969 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002970 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant324bb032010-08-22 00:02:43 +00002971#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002972 do
2973 {
2974 __first = __temp;
2975 __temp = __parse_ERE_expression(__first, __last);
2976 } while (__temp != __first);
2977 return __first;
2978}
2979
2980template <class _CharT, class _Traits>
2981template <class _ForwardIterator>
2982_ForwardIterator
2983basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
2984 _ForwardIterator __last)
2985{
Howard Hinnantaa698082010-07-16 19:08:36 +00002986 __owns_one_state<_CharT>* __e = __end_;
2987 unsigned __mexp_begin = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002988 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
2989 if (__temp == __first && __temp != __last)
2990 {
2991 switch (*__temp)
2992 {
2993 case '^':
2994 __push_l_anchor();
2995 ++__temp;
2996 break;
2997 case '$':
2998 __push_r_anchor();
2999 ++__temp;
3000 break;
3001 case '(':
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003002 __push_begin_marked_subexpression();
3003 unsigned __temp_count = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003004 ++__open_count_;
3005 __temp = __parse_extended_reg_exp(++__temp, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003006#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003007 if (__temp == __last || *__temp != ')')
3008 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00003009#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003010 __push_end_marked_subexpression(__temp_count);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003011 --__open_count_;
3012 ++__temp;
3013 break;
3014 }
3015 }
3016 if (__temp != __first)
Howard Hinnantaa698082010-07-16 19:08:36 +00003017 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
3018 __marked_count_+1);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003019 __first = __temp;
3020 return __first;
3021}
3022
3023template <class _CharT, class _Traits>
3024template <class _ForwardIterator>
3025_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003026basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
3027 _ForwardIterator __last)
3028{
3029 while (true)
3030 {
3031 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
3032 if (__temp == __first)
3033 break;
3034 __first = __temp;
3035 }
3036 return __first;
3037}
3038
3039template <class _CharT, class _Traits>
3040template <class _ForwardIterator>
3041_ForwardIterator
3042basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
3043 _ForwardIterator __last)
3044{
3045 if (__first != __last)
3046 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003047 __owns_one_state<_CharT>* __e = __end_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003048 unsigned __mexp_begin = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003049 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
3050 if (__temp != __first)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003051 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
3052 __mexp_begin+1, __marked_count_+1);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003053 }
3054 return __first;
3055}
3056
3057template <class _CharT, class _Traits>
3058template <class _ForwardIterator>
3059_ForwardIterator
3060basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
3061 _ForwardIterator __last)
3062{
3063 _ForwardIterator __temp = __first;
3064 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
3065 if (__temp == __first)
3066 {
3067 __temp = __parse_Back_open_paren(__first, __last);
3068 if (__temp != __first)
3069 {
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003070 __push_begin_marked_subexpression();
3071 unsigned __temp_count = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003072 __first = __parse_RE_expression(__temp, __last);
3073 __temp = __parse_Back_close_paren(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003074#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003075 if (__temp == __first)
3076 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00003077#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003078 __push_end_marked_subexpression(__temp_count);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003079 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003080 }
3081 else
3082 __first = __parse_BACKREF(__first, __last);
3083 }
3084 return __first;
3085}
3086
3087template <class _CharT, class _Traits>
3088template <class _ForwardIterator>
3089_ForwardIterator
3090basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
3091 _ForwardIterator __first,
3092 _ForwardIterator __last)
3093{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003094 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003095 if (__temp == __first)
3096 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003097 __temp = __parse_QUOTED_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003098 if (__temp == __first)
3099 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003100 if (__temp != __last && *__temp == '.')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003101 {
3102 __push_match_any();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003103 ++__temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003104 }
3105 else
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003106 __temp = __parse_bracket_expression(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003107 }
3108 }
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003109 __first = __temp;
3110 return __first;
3111}
3112
3113template <class _CharT, class _Traits>
3114template <class _ForwardIterator>
3115_ForwardIterator
3116basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
3117 _ForwardIterator __first,
3118 _ForwardIterator __last)
3119{
3120 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
3121 if (__temp == __first)
3122 {
3123 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
3124 if (__temp == __first)
3125 {
3126 if (__temp != __last && *__temp == '.')
3127 {
3128 __push_match_any();
3129 ++__temp;
3130 }
3131 else
3132 __temp = __parse_bracket_expression(__first, __last);
3133 }
3134 }
3135 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003136 return __first;
3137}
3138
3139template <class _CharT, class _Traits>
3140template <class _ForwardIterator>
3141_ForwardIterator
3142basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
3143 _ForwardIterator __last)
3144{
3145 if (__first != __last)
3146 {
3147 _ForwardIterator __temp = next(__first);
3148 if (__temp != __last)
3149 {
3150 if (*__first == '\\' && *__temp == '(')
3151 __first = ++__temp;
3152 }
3153 }
3154 return __first;
3155}
3156
3157template <class _CharT, class _Traits>
3158template <class _ForwardIterator>
3159_ForwardIterator
3160basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
3161 _ForwardIterator __last)
3162{
3163 if (__first != __last)
3164 {
3165 _ForwardIterator __temp = next(__first);
3166 if (__temp != __last)
3167 {
3168 if (*__first == '\\' && *__temp == ')')
3169 __first = ++__temp;
3170 }
3171 }
3172 return __first;
3173}
3174
3175template <class _CharT, class _Traits>
3176template <class _ForwardIterator>
3177_ForwardIterator
3178basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
3179 _ForwardIterator __last)
3180{
3181 if (__first != __last)
3182 {
3183 _ForwardIterator __temp = next(__first);
3184 if (__temp != __last)
3185 {
3186 if (*__first == '\\' && *__temp == '{')
3187 __first = ++__temp;
3188 }
3189 }
3190 return __first;
3191}
3192
3193template <class _CharT, class _Traits>
3194template <class _ForwardIterator>
3195_ForwardIterator
3196basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
3197 _ForwardIterator __last)
3198{
3199 if (__first != __last)
3200 {
3201 _ForwardIterator __temp = next(__first);
3202 if (__temp != __last)
3203 {
3204 if (*__first == '\\' && *__temp == '}')
3205 __first = ++__temp;
3206 }
3207 }
3208 return __first;
3209}
3210
3211template <class _CharT, class _Traits>
3212template <class _ForwardIterator>
3213_ForwardIterator
3214basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
3215 _ForwardIterator __last)
3216{
3217 if (__first != __last)
3218 {
3219 _ForwardIterator __temp = next(__first);
3220 if (__temp != __last)
3221 {
3222 if (*__first == '\\' && '1' <= *__temp && *__temp <= '9')
3223 {
3224 __push_back_ref(*__temp - '0');
3225 __first = ++__temp;
3226 }
3227 }
3228 }
3229 return __first;
3230}
3231
3232template <class _CharT, class _Traits>
3233template <class _ForwardIterator>
3234_ForwardIterator
3235basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
3236 _ForwardIterator __last)
3237{
3238 if (__first != __last)
3239 {
3240 _ForwardIterator __temp = next(__first);
3241 if (__temp == __last && *__first == '$')
3242 return __first;
3243 // Not called inside a bracket
3244 if (*__first == '.' || *__first == '\\' || *__first == '[')
3245 return __first;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003246 __push_char(*__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003247 ++__first;
3248 }
3249 return __first;
3250}
3251
3252template <class _CharT, class _Traits>
3253template <class _ForwardIterator>
3254_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003255basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
3256 _ForwardIterator __last)
3257{
3258 if (__first != __last)
3259 {
3260 switch (*__first)
3261 {
3262 case '^':
3263 case '.':
3264 case '[':
3265 case '$':
3266 case '(':
3267 case '|':
3268 case '*':
3269 case '+':
3270 case '?':
3271 case '{':
3272 case '\\':
3273 break;
3274 case ')':
3275 if (__open_count_ == 0)
3276 {
3277 __push_char(*__first);
3278 ++__first;
3279 }
3280 break;
3281 default:
3282 __push_char(*__first);
3283 ++__first;
3284 break;
3285 }
3286 }
3287 return __first;
3288}
3289
3290template <class _CharT, class _Traits>
3291template <class _ForwardIterator>
3292_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003293basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
3294 _ForwardIterator __last)
3295{
3296 if (__first != __last)
3297 {
3298 _ForwardIterator __temp = next(__first);
3299 if (__temp != __last)
3300 {
3301 if (*__first == '\\')
3302 {
3303 switch (*__temp)
3304 {
3305 case '^':
3306 case '.':
3307 case '*':
3308 case '[':
3309 case '$':
3310 case '\\':
Howard Hinnant0de86b62010-06-25 20:56:08 +00003311 __push_char(*__temp);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003312 __first = ++__temp;
3313 break;
3314 }
3315 }
3316 }
3317 }
3318 return __first;
3319}
3320
3321template <class _CharT, class _Traits>
3322template <class _ForwardIterator>
3323_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003324basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
3325 _ForwardIterator __last)
3326{
3327 if (__first != __last)
3328 {
3329 _ForwardIterator __temp = next(__first);
3330 if (__temp != __last)
3331 {
3332 if (*__first == '\\')
3333 {
3334 switch (*__temp)
3335 {
3336 case '^':
3337 case '.':
3338 case '*':
3339 case '[':
3340 case '$':
3341 case '\\':
3342 case '(':
3343 case ')':
3344 case '|':
3345 case '+':
3346 case '?':
3347 case '{':
3348 __push_char(*__temp);
3349 __first = ++__temp;
3350 break;
Howard Hinnant15476f32010-07-28 17:35:27 +00003351 default:
3352 if ((__flags_ & 0x1F0) == awk)
3353 __first = __parse_awk_escape(++__first, __last);
3354 break;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003355 }
3356 }
3357 }
3358 }
3359 return __first;
3360}
3361
3362template <class _CharT, class _Traits>
3363template <class _ForwardIterator>
3364_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003365basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003366 _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003367 __owns_one_state<_CharT>* __s,
3368 unsigned __mexp_begin,
3369 unsigned __mexp_end)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003370{
3371 if (__first != __last)
3372 {
Howard Hinnant0de86b62010-06-25 20:56:08 +00003373 if (*__first == '*')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003374 {
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003375 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003376 ++__first;
3377 }
3378 else
3379 {
3380 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3381 if (__temp != __first)
3382 {
3383 int __min = 0;
3384 __first = __temp;
3385 __temp = __parse_DUP_COUNT(__first, __last, __min);
Howard Hinnantd4444702010-08-11 17:04:31 +00003386#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003387 if (__temp == __first)
3388 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003389#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003390 __first = __temp;
Howard Hinnantd4444702010-08-11 17:04:31 +00003391#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003392 if (__first == __last)
3393 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003394#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003395 if (*__first != ',')
3396 {
3397 __temp = __parse_Back_close_brace(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003398#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003399 if (__temp == __first)
3400 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003401#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcba352d2010-07-12 18:16:05 +00003402 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
3403 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003404 __first = __temp;
3405 }
3406 else
3407 {
3408 ++__first; // consume ','
3409 int __max = -1;
3410 __first = __parse_DUP_COUNT(__first, __last, __max);
3411 __temp = __parse_Back_close_brace(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00003412#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003413 if (__temp == __first)
3414 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003415#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003416 if (__max == -1)
Howard Hinnantaa698082010-07-16 19:08:36 +00003417 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003418 else
3419 {
Howard Hinnantd4444702010-08-11 17:04:31 +00003420#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003421 if (__max < __min)
3422 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003423#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcba352d2010-07-12 18:16:05 +00003424 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
3425 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003426 }
3427 __first = __temp;
3428 }
3429 }
3430 }
3431 }
3432 return __first;
3433}
3434
Howard Hinnant0de86b62010-06-25 20:56:08 +00003435template <class _CharT, class _Traits>
3436template <class _ForwardIterator>
3437_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003438basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantaa698082010-07-16 19:08:36 +00003439 _ForwardIterator __last,
3440 __owns_one_state<_CharT>* __s,
3441 unsigned __mexp_begin,
3442 unsigned __mexp_end)
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003443{
3444 if (__first != __last)
3445 {
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003446 unsigned __grammar = __flags_ & 0x1F0;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003447 switch (*__first)
3448 {
3449 case '*':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003450 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003451 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003452 {
3453 ++__first;
3454 __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3455 }
3456 else
3457 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003458 break;
3459 case '+':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003460 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003461 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003462 {
3463 ++__first;
3464 __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3465 }
3466 else
3467 __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003468 break;
3469 case '?':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003470 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003471 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003472 {
3473 ++__first;
3474 __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3475 }
3476 else
3477 __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003478 break;
3479 case '{':
3480 {
3481 int __min;
Howard Hinnantaa698082010-07-16 19:08:36 +00003482 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
Howard Hinnantd4444702010-08-11 17:04:31 +00003483#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003484 if (__temp == __first)
3485 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003486#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003487 __first = __temp;
Howard Hinnantd4444702010-08-11 17:04:31 +00003488#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003489 if (__first == __last)
3490 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003491#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003492 switch (*__first)
3493 {
3494 case '}':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003495 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003496 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003497 {
3498 ++__first;
3499 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3500 }
3501 else
3502 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003503 break;
3504 case ',':
Howard Hinnantd4444702010-08-11 17:04:31 +00003505 ++__first;
3506#ifndef _LIBCPP_NO_EXCEPTIONS
3507 if (__first == __last)
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003508 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003509#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003510 if (*__first == '}')
3511 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003512 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003513 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003514 {
3515 ++__first;
3516 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3517 }
3518 else
3519 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003520 }
3521 else
3522 {
Howard Hinnantaa698082010-07-16 19:08:36 +00003523 int __max = -1;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003524 __temp = __parse_DUP_COUNT(__first, __last, __max);
Howard Hinnantd4444702010-08-11 17:04:31 +00003525#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003526 if (__temp == __first)
3527 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003528#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003529 __first = __temp;
Howard Hinnantd4444702010-08-11 17:04:31 +00003530#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003531 if (__first == __last || *__first != '}')
3532 throw regex_error(regex_constants::error_brace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003533#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003534 ++__first;
Howard Hinnantd4444702010-08-11 17:04:31 +00003535#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003536 if (__max < __min)
3537 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003538#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003539 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003540 {
3541 ++__first;
3542 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3543 }
3544 else
3545 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003546 }
Howard Hinnantaa698082010-07-16 19:08:36 +00003547 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00003548#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003549 default:
3550 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant324bb032010-08-22 00:02:43 +00003551#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003552 }
3553 }
3554 break;
3555 }
3556 }
3557 return __first;
3558}
3559
3560template <class _CharT, class _Traits>
3561template <class _ForwardIterator>
3562_ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00003563basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
3564 _ForwardIterator __last)
3565{
3566 if (__first != __last && *__first == '[')
3567 {
Howard Hinnantd4444702010-08-11 17:04:31 +00003568 ++__first;
3569#ifndef _LIBCPP_NO_EXCEPTIONS
3570 if (__first == __last)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003571 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003572#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003573 bool __negate = false;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003574 if (*__first == '^')
3575 {
3576 ++__first;
Howard Hinnant173968a2010-07-13 21:48:06 +00003577 __negate = true;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003578 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003579 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3580 // __ml owned by *this
Howard Hinnantd4444702010-08-11 17:04:31 +00003581#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003582 if (__first == __last)
3583 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003584#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003585 if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']')
Howard Hinnant0de86b62010-06-25 20:56:08 +00003586 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003587 __ml->__add_char(']');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003588 ++__first;
3589 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003590 __first = __parse_follow_list(__first, __last, __ml);
Howard Hinnantd4444702010-08-11 17:04:31 +00003591#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003592 if (__first == __last)
3593 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003594#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003595 if (*__first == '-')
3596 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003597 __ml->__add_char('-');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003598 ++__first;
3599 }
Howard Hinnantd4444702010-08-11 17:04:31 +00003600#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003601 if (__first == __last || *__first != ']')
3602 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003603#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003604 ++__first;
3605 }
3606 return __first;
3607}
3608
3609template <class _CharT, class _Traits>
3610template <class _ForwardIterator>
3611_ForwardIterator
3612basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003613 _ForwardIterator __last,
3614 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003615{
3616 if (__first != __last)
3617 {
3618 while (true)
3619 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003620 _ForwardIterator __temp = __parse_expression_term(__first, __last,
3621 __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003622 if (__temp == __first)
3623 break;
3624 __first = __temp;
3625 }
3626 }
3627 return __first;
3628}
3629
3630template <class _CharT, class _Traits>
3631template <class _ForwardIterator>
3632_ForwardIterator
3633basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003634 _ForwardIterator __last,
3635 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003636{
3637 if (__first != __last && *__first != ']')
3638 {
Howard Hinnant0de86b62010-06-25 20:56:08 +00003639 _ForwardIterator __temp = next(__first);
Howard Hinnant173968a2010-07-13 21:48:06 +00003640 basic_string<_CharT> __start_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003641 if (__temp != __last && *__first == '[')
3642 {
3643 if (*__temp == '=')
Howard Hinnant173968a2010-07-13 21:48:06 +00003644 return __parse_equivalence_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003645 else if (*__temp == ':')
Howard Hinnant173968a2010-07-13 21:48:06 +00003646 return __parse_character_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003647 else if (*__temp == '.')
Howard Hinnant173968a2010-07-13 21:48:06 +00003648 __first = __parse_collating_symbol(++__temp, __last, __start_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003649 }
Howard Hinnant15476f32010-07-28 17:35:27 +00003650 unsigned __grammar = __flags_ & 0x1F0;
3651 if (__start_range.empty())
Howard Hinnant0de86b62010-06-25 20:56:08 +00003652 {
Howard Hinnant15476f32010-07-28 17:35:27 +00003653 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3654 {
3655 if (__grammar == ECMAScript)
3656 __first = __parse_class_escape(++__first, __last, __start_range, __ml);
3657 else
3658 __first = __parse_awk_escape(++__first, __last, &__start_range);
3659 }
3660 else
3661 {
3662 __start_range = *__first;
3663 ++__first;
3664 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003665 }
3666 if (__first != __last && *__first != ']')
3667 {
3668 __temp = next(__first);
3669 if (__temp != __last && *__first == '-' && *__temp != ']')
3670 {
3671 // parse a range
Howard Hinnant173968a2010-07-13 21:48:06 +00003672 basic_string<_CharT> __end_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003673 __first = __temp;
3674 ++__temp;
3675 if (__temp != __last && *__first == '[' && *__temp == '.')
Howard Hinnant173968a2010-07-13 21:48:06 +00003676 __first = __parse_collating_symbol(++__temp, __last, __end_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003677 else
3678 {
Howard Hinnant15476f32010-07-28 17:35:27 +00003679 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3680 {
3681 if (__grammar == ECMAScript)
3682 __first = __parse_class_escape(++__first, __last,
3683 __end_range, __ml);
3684 else
3685 __first = __parse_awk_escape(++__first, __last,
3686 &__end_range);
3687 }
3688 else
3689 {
3690 __end_range = *__first;
3691 ++__first;
3692 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003693 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003694 __ml->__add_range(_STD::move(__start_range), _STD::move(__end_range));
Howard Hinnant0de86b62010-06-25 20:56:08 +00003695 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003696 else
3697 {
3698 if (__start_range.size() == 1)
3699 __ml->__add_char(__start_range[0]);
3700 else
3701 __ml->__add_digraph(__start_range[0], __start_range[1]);
3702 }
3703 }
3704 else
3705 {
3706 if (__start_range.size() == 1)
3707 __ml->__add_char(__start_range[0]);
3708 else
3709 __ml->__add_digraph(__start_range[0], __start_range[1]);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003710 }
3711 }
3712 return __first;
3713}
3714
3715template <class _CharT, class _Traits>
3716template <class _ForwardIterator>
3717_ForwardIterator
Howard Hinnant15476f32010-07-28 17:35:27 +00003718basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
3719 _ForwardIterator __last,
3720 basic_string<_CharT>& __str,
3721 __bracket_expression<_CharT, _Traits>* __ml)
3722{
Howard Hinnantd4444702010-08-11 17:04:31 +00003723#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003724 if (__first == __last)
3725 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00003726#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003727 switch (*__first)
3728 {
3729 case 0:
3730 __str = *__first;
3731 return ++__first;
3732 case 'b':
3733 __str = _CharT(8);
3734 return ++__first;
3735 case 'd':
3736 __ml->__add_class(ctype_base::digit);
3737 return ++__first;
3738 case 'D':
3739 __ml->__add_neg_class(ctype_base::digit);
3740 return ++__first;
3741 case 's':
3742 __ml->__add_class(ctype_base::space);
3743 return ++__first;
3744 case 'S':
3745 __ml->__add_neg_class(ctype_base::space);
3746 return ++__first;
3747 case 'w':
3748 __ml->__add_class(ctype_base::alnum);
3749 __ml->__add_char('_');
3750 return ++__first;
3751 case 'W':
3752 __ml->__add_neg_class(ctype_base::alnum);
3753 __ml->__add_neg_char('_');
3754 return ++__first;
3755 }
3756 __first = __parse_character_escape(__first, __last, &__str);
3757 return __first;
3758}
3759
3760template <class _CharT, class _Traits>
3761template <class _ForwardIterator>
3762_ForwardIterator
3763basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
3764 _ForwardIterator __last,
3765 basic_string<_CharT>* __str)
3766{
Howard Hinnantd4444702010-08-11 17:04:31 +00003767#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003768 if (__first == __last)
3769 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00003770#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003771 switch (*__first)
3772 {
3773 case '\\':
3774 case '"':
3775 case '/':
3776 if (__str)
3777 *__str = *__first;
3778 else
3779 __push_char(*__first);
3780 return ++__first;
3781 case 'a':
3782 if (__str)
3783 *__str = _CharT(7);
3784 else
3785 __push_char(_CharT(7));
3786 return ++__first;
3787 case 'b':
3788 if (__str)
3789 *__str = _CharT(8);
3790 else
3791 __push_char(_CharT(8));
3792 return ++__first;
3793 case 'f':
3794 if (__str)
3795 *__str = _CharT(0xC);
3796 else
3797 __push_char(_CharT(0xC));
3798 return ++__first;
3799 case 'n':
3800 if (__str)
3801 *__str = _CharT(0xA);
3802 else
3803 __push_char(_CharT(0xA));
3804 return ++__first;
3805 case 'r':
3806 if (__str)
3807 *__str = _CharT(0xD);
3808 else
3809 __push_char(_CharT(0xD));
3810 return ++__first;
3811 case 't':
3812 if (__str)
3813 *__str = _CharT(0x9);
3814 else
3815 __push_char(_CharT(0x9));
3816 return ++__first;
3817 case 'v':
3818 if (__str)
3819 *__str = _CharT(0xB);
3820 else
3821 __push_char(_CharT(0xB));
3822 return ++__first;
3823 }
3824 if ('0' <= *__first && *__first <= '7')
3825 {
3826 unsigned __val = *__first - '0';
3827 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3828 {
3829 __val = 8 * __val + *__first - '0';
3830 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3831 __val = 8 * __val + *__first - '0';
3832 }
3833 if (__str)
3834 *__str = _CharT(__val);
3835 else
3836 __push_char(_CharT(__val));
3837 }
Howard Hinnantd4444702010-08-11 17:04:31 +00003838#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003839 else
3840 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00003841#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00003842 return __first;
3843}
3844
3845template <class _CharT, class _Traits>
3846template <class _ForwardIterator>
3847_ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00003848basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003849 _ForwardIterator __last,
3850 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003851{
3852 // Found [=
3853 // This means =] must exist
3854 value_type _Equal_close[2] = {'=', ']'};
3855 _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close,
3856 _Equal_close+2);
Howard Hinnantd4444702010-08-11 17:04:31 +00003857#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003858 if (__temp == __last)
3859 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003860#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003861 // [__first, __temp) contains all text in [= ... =]
3862 typedef typename _Traits::string_type string_type;
3863 string_type __collate_name =
3864 __traits_.lookup_collatename(__first, __temp);
Howard Hinnantd4444702010-08-11 17:04:31 +00003865#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003866 if (__collate_name.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003867 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00003868#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003869 string_type __equiv_name =
3870 __traits_.transform_primary(__collate_name.begin(),
3871 __collate_name.end());
3872 if (!__equiv_name.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003873 __ml->__add_equivalence(__equiv_name);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003874 else
Howard Hinnant173968a2010-07-13 21:48:06 +00003875 {
3876 switch (__collate_name.size())
3877 {
3878 case 1:
3879 __ml->__add_char(__collate_name[0]);
3880 break;
3881 case 2:
3882 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
3883 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00003884#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003885 default:
3886 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00003887#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003888 }
3889 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003890 __first = next(__temp, 2);
3891 return __first;
3892}
3893
3894template <class _CharT, class _Traits>
3895template <class _ForwardIterator>
3896_ForwardIterator
3897basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003898 _ForwardIterator __last,
3899 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003900{
3901 // Found [:
3902 // This means :] must exist
3903 value_type _Colon_close[2] = {':', ']'};
3904 _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close,
3905 _Colon_close+2);
Howard Hinnantd4444702010-08-11 17:04:31 +00003906#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003907 if (__temp == __last)
3908 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003909#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003910 // [__first, __temp) contains all text in [: ... :]
3911 typedef typename _Traits::char_class_type char_class_type;
3912 char_class_type __class_type =
3913 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
Howard Hinnantd4444702010-08-11 17:04:31 +00003914#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003915 if (__class_type == 0)
3916 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003917#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003918 __ml->__add_class(__class_type);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003919 __first = next(__temp, 2);
3920 return __first;
3921}
3922
3923template <class _CharT, class _Traits>
3924template <class _ForwardIterator>
3925_ForwardIterator
3926basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003927 _ForwardIterator __last,
3928 basic_string<_CharT>& __col_sym)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003929{
3930 // Found [.
3931 // This means .] must exist
3932 value_type _Dot_close[2] = {'.', ']'};
3933 _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close,
3934 _Dot_close+2);
Howard Hinnantd4444702010-08-11 17:04:31 +00003935#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003936 if (__temp == __last)
3937 throw regex_error(regex_constants::error_brack);
Howard Hinnant324bb032010-08-22 00:02:43 +00003938#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0de86b62010-06-25 20:56:08 +00003939 // [__first, __temp) contains all text in [. ... .]
3940 typedef typename _Traits::string_type string_type;
Howard Hinnant173968a2010-07-13 21:48:06 +00003941 __col_sym = __traits_.lookup_collatename(__first, __temp);
3942 switch (__col_sym.size())
3943 {
3944 case 1:
3945 case 2:
3946 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00003947#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003948 default:
3949 throw regex_error(regex_constants::error_collate);
Howard Hinnant324bb032010-08-22 00:02:43 +00003950#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant173968a2010-07-13 21:48:06 +00003951 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003952 __first = next(__temp, 2);
3953 return __first;
3954}
3955
3956template <class _CharT, class _Traits>
3957template <class _ForwardIterator>
3958_ForwardIterator
3959basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
3960 _ForwardIterator __last,
3961 int& __c)
3962{
3963 if (__first != __last && '0' <= *__first && *__first <= '9')
3964 {
3965 __c = *__first - '0';
3966 for (++__first; __first != __last && '0' <= *__first && *__first <= '9';
3967 ++__first)
3968 {
3969 __c *= 10;
3970 __c += *__first - '0';
3971 }
3972 }
3973 return __first;
3974}
3975
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003976template <class _CharT, class _Traits>
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003977template <class _ForwardIterator>
3978_ForwardIterator
3979basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
3980 _ForwardIterator __last)
3981{
3982 __owns_one_state<_CharT>* __sa = __end_;
3983 _ForwardIterator __temp = __parse_alternative(__first, __last);
3984 if (__temp == __first)
3985 __push_empty();
3986 __first = __temp;
3987 while (__first != __last && *__first == '|')
3988 {
3989 __owns_one_state<_CharT>* __sb = __end_;
3990 __temp = __parse_alternative(++__first, __last);
3991 if (__temp == __first)
3992 __push_empty();
3993 __push_alternation(__sa, __sb);
3994 __first = __temp;
3995 }
3996 return __first;
3997}
3998
3999template <class _CharT, class _Traits>
4000template <class _ForwardIterator>
4001_ForwardIterator
4002basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
4003 _ForwardIterator __last)
4004{
4005 while (true)
4006 {
4007 _ForwardIterator __temp = __parse_term(__first, __last);
4008 if (__temp == __first)
4009 break;
4010 __first = __temp;
4011 }
4012 return __first;
4013}
4014
4015template <class _CharT, class _Traits>
4016template <class _ForwardIterator>
4017_ForwardIterator
4018basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
4019 _ForwardIterator __last)
4020{
4021 _ForwardIterator __temp = __parse_assertion(__first, __last);
4022 if (__temp == __first)
4023 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004024 __owns_one_state<_CharT>* __e = __end_;
4025 unsigned __mexp_begin = __marked_count_;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004026 __temp = __parse_atom(__first, __last);
4027 if (__temp != __first)
Howard Hinnant17615b02010-07-27 01:25:38 +00004028 __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
4029 __mexp_begin+1, __marked_count_+1);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004030 }
Howard Hinnant17615b02010-07-27 01:25:38 +00004031 else
4032 __first = __temp;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004033 return __first;
4034}
4035
4036template <class _CharT, class _Traits>
4037template <class _ForwardIterator>
4038_ForwardIterator
4039basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
4040 _ForwardIterator __last)
4041{
4042 if (__first != __last)
4043 {
4044 switch (*__first)
4045 {
4046 case '^':
4047 __push_l_anchor();
4048 ++__first;
4049 break;
4050 case '$':
4051 __push_r_anchor();
4052 ++__first;
4053 break;
4054 case '\\':
4055 {
4056 _ForwardIterator __temp = _STD::next(__first);
4057 if (__temp != __last)
4058 {
4059 if (*__temp == 'b')
4060 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004061 __push_word_boundary(false);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004062 __first = ++__temp;
4063 }
4064 else if (*__temp == 'B')
4065 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004066 __push_word_boundary(true);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004067 __first = ++__temp;
4068 }
4069 }
4070 }
4071 break;
4072 case '(':
4073 {
4074 _ForwardIterator __temp = _STD::next(__first);
4075 if (__temp != __last && *__temp == '?')
4076 {
4077 if (++__temp != __last)
4078 {
4079 switch (*__temp)
4080 {
4081 case '=':
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004082 {
4083 basic_regex __exp;
4084 __exp.__flags_ = __flags_;
4085 __temp = __exp.__parse(++__temp, __last);
4086 __exp.__push_l_anchor();
4087 __push_lookahead(_STD::move(__exp), false);
Howard Hinnantd4444702010-08-11 17:04:31 +00004088#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004089 if (__temp == __last || *__temp != ')')
4090 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004091#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004092 __first = ++__temp;
4093 }
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004094 break;
4095 case '!':
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004096 {
4097 basic_regex __exp;
4098 __exp.__flags_ = __flags_;
4099 __temp = __exp.__parse(++__temp, __last);
4100 __exp.__push_l_anchor();
4101 __push_lookahead(_STD::move(__exp), true);
Howard Hinnantd4444702010-08-11 17:04:31 +00004102#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004103 if (__temp == __last || *__temp != ')')
4104 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004105#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004106 __first = ++__temp;
4107 }
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004108 break;
4109 }
4110 }
4111 }
4112 }
4113 break;
4114 }
4115 }
4116 return __first;
4117}
4118
4119template <class _CharT, class _Traits>
4120template <class _ForwardIterator>
4121_ForwardIterator
4122basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
4123 _ForwardIterator __last)
4124{
Howard Hinnant17615b02010-07-27 01:25:38 +00004125 if (__first != __last)
4126 {
4127 switch (*__first)
4128 {
4129 case '.':
4130 __push_match_any_but_newline();
4131 ++__first;
4132 break;
4133 case '\\':
4134 __first = __parse_atom_escape(__first, __last);
4135 break;
4136 case '[':
4137 __first = __parse_bracket_expression(__first, __last);
4138 break;
4139 case '(':
4140 {
Howard Hinnantd4444702010-08-11 17:04:31 +00004141 ++__first;
4142#ifndef _LIBCPP_NO_EXCEPTIONS
4143 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004144 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004145#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004146 _ForwardIterator __temp = _STD::next(__first);
4147 if (__temp != __last && *__first == '?' && *__temp == ':')
4148 {
4149 ++__open_count_;
4150 __first = __parse_ecma_exp(++__temp, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00004151#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004152 if (__first == __last || *__first != ')')
4153 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004154#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004155 --__open_count_;
4156 ++__first;
4157 }
4158 else
4159 {
4160 __push_begin_marked_subexpression();
4161 unsigned __temp_count = __marked_count_;
4162 ++__open_count_;
4163 __first = __parse_ecma_exp(__first, __last);
Howard Hinnantd4444702010-08-11 17:04:31 +00004164#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004165 if (__first == __last || *__first != ')')
4166 throw regex_error(regex_constants::error_paren);
Howard Hinnant324bb032010-08-22 00:02:43 +00004167#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004168 __push_end_marked_subexpression(__temp_count);
4169 --__open_count_;
4170 ++__first;
4171 }
4172 }
4173 break;
4174 default:
4175 __first = __parse_pattern_character(__first, __last);
4176 break;
4177 }
4178 }
4179 return __first;
4180}
4181
4182template <class _CharT, class _Traits>
4183template <class _ForwardIterator>
4184_ForwardIterator
4185basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
4186 _ForwardIterator __last)
4187{
4188 if (__first != __last && *__first == '\\')
4189 {
4190 _ForwardIterator __t1 = _STD::next(__first);
4191 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
4192 if (__t2 != __t1)
4193 __first = __t2;
4194 else
4195 {
4196 __t2 = __parse_character_class_escape(__t1, __last);
4197 if (__t2 != __t1)
4198 __first = __t2;
4199 else
4200 {
4201 __t2 = __parse_character_escape(__t1, __last);
4202 if (__t2 != __t1)
4203 __first = __t2;
4204 }
4205 }
4206 }
4207 return __first;
4208}
4209
4210template <class _CharT, class _Traits>
4211template <class _ForwardIterator>
4212_ForwardIterator
4213basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
4214 _ForwardIterator __last)
4215{
4216 if (__first != __last)
4217 {
4218 if (*__first == '0')
4219 {
4220 __push_char(_CharT());
4221 ++__first;
4222 }
4223 else if ('1' <= *__first && *__first <= '9')
4224 {
4225 unsigned __v = *__first - '0';
4226 for (++__first; '0' <= *__first && *__first <= '9'; ++__first)
4227 __v = 10 * __v + *__first - '0';
Howard Hinnantd4444702010-08-11 17:04:31 +00004228#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004229 if (__v > mark_count())
4230 throw regex_error(regex_constants::error_backref);
Howard Hinnant324bb032010-08-22 00:02:43 +00004231#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004232 __push_back_ref(__v);
4233 }
4234 }
4235 return __first;
4236}
4237
4238template <class _CharT, class _Traits>
4239template <class _ForwardIterator>
4240_ForwardIterator
4241basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
4242 _ForwardIterator __last)
4243{
4244 if (__first != __last)
4245 {
4246 __bracket_expression<_CharT, _Traits>* __ml;
4247 switch (*__first)
4248 {
4249 case 'd':
4250 __ml = __start_matching_list(false);
4251 __ml->__add_class(ctype_base::digit);
4252 ++__first;
4253 break;
4254 case 'D':
4255 __ml = __start_matching_list(true);
4256 __ml->__add_class(ctype_base::digit);
4257 ++__first;
4258 break;
4259 case 's':
4260 __ml = __start_matching_list(false);
4261 __ml->__add_class(ctype_base::space);
4262 ++__first;
4263 break;
4264 case 'S':
4265 __ml = __start_matching_list(true);
4266 __ml->__add_class(ctype_base::space);
4267 ++__first;
4268 break;
4269 case 'w':
4270 __ml = __start_matching_list(false);
4271 __ml->__add_class(ctype_base::alnum);
4272 __ml->__add_char('_');
4273 ++__first;
4274 break;
4275 case 'W':
4276 __ml = __start_matching_list(true);
4277 __ml->__add_class(ctype_base::alnum);
4278 __ml->__add_char('_');
4279 ++__first;
4280 break;
4281 }
4282 }
4283 return __first;
4284}
4285
4286template <class _CharT, class _Traits>
4287template <class _ForwardIterator>
4288_ForwardIterator
4289basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
Howard Hinnant15476f32010-07-28 17:35:27 +00004290 _ForwardIterator __last,
4291 basic_string<_CharT>* __str)
Howard Hinnant17615b02010-07-27 01:25:38 +00004292{
4293 if (__first != __last)
4294 {
4295 _ForwardIterator __t;
4296 unsigned __sum = 0;
4297 int __hd;
4298 switch (*__first)
4299 {
4300 case 'f':
Howard Hinnant15476f32010-07-28 17:35:27 +00004301 if (__str)
4302 *__str = _CharT(0xC);
4303 else
4304 __push_char(_CharT(0xC));
Howard Hinnant17615b02010-07-27 01:25:38 +00004305 ++__first;
4306 break;
4307 case 'n':
Howard Hinnant15476f32010-07-28 17:35:27 +00004308 if (__str)
4309 *__str = _CharT(0xA);
4310 else
4311 __push_char(_CharT(0xA));
Howard Hinnant17615b02010-07-27 01:25:38 +00004312 ++__first;
4313 break;
4314 case 'r':
Howard Hinnant15476f32010-07-28 17:35:27 +00004315 if (__str)
4316 *__str = _CharT(0xD);
4317 else
4318 __push_char(_CharT(0xD));
Howard Hinnant17615b02010-07-27 01:25:38 +00004319 ++__first;
4320 break;
4321 case 't':
Howard Hinnant15476f32010-07-28 17:35:27 +00004322 if (__str)
4323 *__str = _CharT(0x9);
4324 else
4325 __push_char(_CharT(0x9));
Howard Hinnant17615b02010-07-27 01:25:38 +00004326 ++__first;
4327 break;
4328 case 'v':
Howard Hinnant15476f32010-07-28 17:35:27 +00004329 if (__str)
4330 *__str = _CharT(0xB);
4331 else
4332 __push_char(_CharT(0xB));
Howard Hinnant17615b02010-07-27 01:25:38 +00004333 ++__first;
4334 break;
4335 case 'c':
4336 if ((__t = _STD::next(__first)) != __last)
4337 {
4338 if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z')
4339 {
Howard Hinnant15476f32010-07-28 17:35:27 +00004340 if (__str)
4341 *__str = _CharT(*__t % 32);
4342 else
4343 __push_char(_CharT(*__t % 32));
Howard Hinnant17615b02010-07-27 01:25:38 +00004344 __first = ++__t;
4345 }
4346 }
4347 break;
4348 case 'u':
Howard Hinnantd4444702010-08-11 17:04:31 +00004349 ++__first;
4350#ifndef _LIBCPP_NO_EXCEPTIONS
4351 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004352 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004353#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004354 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004355#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004356 if (__hd == -1)
4357 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004358#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004359 __sum = 16 * __sum + __hd;
Howard Hinnantd4444702010-08-11 17:04:31 +00004360 ++__first;
4361#ifndef _LIBCPP_NO_EXCEPTIONS
4362 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004363 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004364#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004365 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004366#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004367 if (__hd == -1)
4368 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004369#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004370 __sum = 16 * __sum + __hd;
4371 // drop through
4372 case 'x':
Howard Hinnantd4444702010-08-11 17:04:31 +00004373 ++__first;
4374#ifndef _LIBCPP_NO_EXCEPTIONS
4375 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004376 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004377#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004378 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004379#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004380 if (__hd == -1)
4381 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004382#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004383 __sum = 16 * __sum + __hd;
Howard Hinnantd4444702010-08-11 17:04:31 +00004384 ++__first;
4385#ifndef _LIBCPP_NO_EXCEPTIONS
4386 if (__first == __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004387 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004388#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004389 __hd = __traits_.value(*__first, 16);
Howard Hinnantd4444702010-08-11 17:04:31 +00004390#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004391 if (__hd == -1)
4392 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004393#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004394 __sum = 16 * __sum + __hd;
Howard Hinnant15476f32010-07-28 17:35:27 +00004395 if (__str)
4396 *__str = _CharT(__sum);
4397 else
4398 __push_char(_CharT(__sum));
Howard Hinnant17615b02010-07-27 01:25:38 +00004399 ++__first;
4400 break;
4401 default:
4402 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
4403 {
Howard Hinnant15476f32010-07-28 17:35:27 +00004404 if (__str)
4405 *__str = *__first;
4406 else
4407 __push_char(*__first);
Howard Hinnant17615b02010-07-27 01:25:38 +00004408 ++__first;
4409 }
Howard Hinnantd4444702010-08-11 17:04:31 +00004410#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnant15476f32010-07-28 17:35:27 +00004411 else if (__str)
4412 throw regex_error(regex_constants::error_escape);
Howard Hinnant324bb032010-08-22 00:02:43 +00004413#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant17615b02010-07-27 01:25:38 +00004414 break;
4415 }
4416 }
4417 return __first;
4418}
4419
4420template <class _CharT, class _Traits>
4421template <class _ForwardIterator>
4422_ForwardIterator
4423basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
4424 _ForwardIterator __last)
4425{
4426 if (__first != __last)
4427 {
4428 switch (*__first)
4429 {
4430 case '^':
4431 case '$':
4432 case '\\':
4433 case '.':
4434 case '*':
4435 case '+':
4436 case '?':
4437 case '(':
4438 case ')':
4439 case '[':
4440 case ']':
4441 case '{':
4442 case '}':
4443 case '|':
4444 break;
4445 default:
4446 __push_char(*__first);
4447 ++__first;
4448 break;
4449 }
4450 }
4451 return __first;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004452}
4453
4454template <class _CharT, class _Traits>
Howard Hinnant856846b2010-07-27 19:53:10 +00004455template <class _ForwardIterator>
4456_ForwardIterator
4457basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
4458 _ForwardIterator __last)
4459{
4460 __owns_one_state<_CharT>* __sa = __end_;
4461 _ForwardIterator __t1 = _STD::find(__first, __last, _CharT('\n'));
4462 if (__t1 != __first)
4463 __parse_basic_reg_exp(__first, __t1);
4464 else
4465 __push_empty();
4466 __first = __t1;
4467 if (__first != __last)
4468 ++__first;
4469 while (__first != __last)
4470 {
4471 __t1 = _STD::find(__first, __last, _CharT('\n'));
4472 __owns_one_state<_CharT>* __sb = __end_;
4473 if (__t1 != __first)
4474 __parse_basic_reg_exp(__first, __t1);
4475 else
4476 __push_empty();
4477 __push_alternation(__sa, __sb);
4478 __first = __t1;
4479 if (__first != __last)
4480 ++__first;
4481 }
4482 return __first;
4483}
4484
4485template <class _CharT, class _Traits>
4486template <class _ForwardIterator>
4487_ForwardIterator
4488basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
4489 _ForwardIterator __last)
4490{
4491 __owns_one_state<_CharT>* __sa = __end_;
4492 _ForwardIterator __t1 = _STD::find(__first, __last, _CharT('\n'));
4493 if (__t1 != __first)
4494 __parse_extended_reg_exp(__first, __t1);
4495 else
4496 __push_empty();
4497 __first = __t1;
4498 if (__first != __last)
4499 ++__first;
4500 while (__first != __last)
4501 {
4502 __t1 = _STD::find(__first, __last, _CharT('\n'));
4503 __owns_one_state<_CharT>* __sb = __end_;
4504 if (__t1 != __first)
4505 __parse_extended_reg_exp(__first, __t1);
4506 else
4507 __push_empty();
4508 __push_alternation(__sa, __sb);
4509 __first = __t1;
4510 if (__first != __last)
4511 ++__first;
4512 }
4513 return __first;
4514}
4515
4516template <class _CharT, class _Traits>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004517void
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004518basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
4519 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
4520 bool __greedy)
4521{
4522 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4523 __end_->first() = nullptr;
Howard Hinnantac303862010-07-12 15:51:17 +00004524 unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
4525 __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
4526 __min, __max));
4527 __s->first() = nullptr;
4528 __e1.release();
4529 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004530 __end_ = __e2->second();
Howard Hinnantac303862010-07-12 15:51:17 +00004531 __s->first() = __e2.release();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004532 ++__loop_count_;
4533}
4534
4535template <class _CharT, class _Traits>
4536void
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004537basic_regex<_CharT, _Traits>::__push_char(value_type __c)
4538{
Howard Hinnant173968a2010-07-13 21:48:06 +00004539 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004540 __end_->first() = new __match_char_icase<_CharT, _Traits>
4541 (__traits_, __c, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004542 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004543 __end_->first() = new __match_char_collate<_CharT, _Traits>
4544 (__traits_, __c, __end_->first());
4545 else
4546 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
Howard Hinnante77aa5e2010-07-08 17:43:58 +00004547 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004548}
4549
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004550template <class _CharT, class _Traits>
4551void
4552basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
4553{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004554 if (!(__flags_ & nosubs))
4555 {
4556 __end_->first() =
4557 new __begin_marked_subexpression<_CharT>(++__marked_count_,
4558 __end_->first());
4559 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4560 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004561}
4562
4563template <class _CharT, class _Traits>
4564void
4565basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
4566{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004567 if (!(__flags_ & nosubs))
4568 {
4569 __end_->first() =
4570 new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4571 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4572 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004573}
4574
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004575template <class _CharT, class _Traits>
4576void
4577basic_regex<_CharT, _Traits>::__push_r_anchor()
4578{
4579 __end_->first() = new __r_anchor<_CharT>(__end_->first());
4580 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4581}
4582
Howard Hinnantac303862010-07-12 15:51:17 +00004583template <class _CharT, class _Traits>
4584void
4585basic_regex<_CharT, _Traits>::__push_match_any()
4586{
4587 __end_->first() = new __match_any<_CharT>(__end_->first());
4588 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4589}
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004590
Howard Hinnantcba352d2010-07-12 18:16:05 +00004591template <class _CharT, class _Traits>
4592void
Howard Hinnant17615b02010-07-27 01:25:38 +00004593basic_regex<_CharT, _Traits>::__push_match_any_but_newline()
4594{
4595 __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
4596 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4597}
4598
4599template <class _CharT, class _Traits>
4600void
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004601basic_regex<_CharT, _Traits>::__push_empty()
4602{
4603 __end_->first() = new __empty_state<_CharT>(__end_->first());
4604 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4605}
4606
4607template <class _CharT, class _Traits>
4608void
Howard Hinnant17615b02010-07-27 01:25:38 +00004609basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
4610{
4611 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
4612 __end_->first());
4613 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4614}
4615
4616template <class _CharT, class _Traits>
4617void
Howard Hinnantcba352d2010-07-12 18:16:05 +00004618basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
4619{
Howard Hinnant173968a2010-07-13 21:48:06 +00004620 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004621 __end_->first() = new __back_ref_icase<_CharT, _Traits>
4622 (__traits_, __i, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004623 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004624 __end_->first() = new __back_ref_collate<_CharT, _Traits>
4625 (__traits_, __i, __end_->first());
4626 else
4627 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
Howard Hinnantcba352d2010-07-12 18:16:05 +00004628 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4629}
4630
Howard Hinnant173968a2010-07-13 21:48:06 +00004631template <class _CharT, class _Traits>
Howard Hinnantaa698082010-07-16 19:08:36 +00004632void
4633basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
4634 __owns_one_state<_CharT>* __ea)
4635{
4636 __sa->first() = new __alternate<_CharT>(
4637 static_cast<__owns_one_state<_CharT>*>(__sa->first()),
4638 static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4639 __ea->first() = nullptr;
4640 __ea->first() = new __empty_state<_CharT>(__end_->first());
4641 __end_->first() = nullptr;
4642 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4643 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4644}
4645
4646template <class _CharT, class _Traits>
Howard Hinnant173968a2010-07-13 21:48:06 +00004647__bracket_expression<_CharT, _Traits>*
4648basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
4649{
4650 __bracket_expression<_CharT, _Traits>* __r =
4651 new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
4652 __negate, __flags_ & icase,
4653 __flags_ & collate);
4654 __end_->first() = __r;
4655 __end_ = __r;
4656 return __r;
4657}
4658
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004659template <class _CharT, class _Traits>
4660void
4661basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
4662 bool __invert)
4663{
4664 __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
4665 __end_->first());
4666 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4667}
4668
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00004669typedef basic_regex<char> regex;
4670typedef basic_regex<wchar_t> wregex;
4671
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004672// sub_match
4673
4674template <class _BidirectionalIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004675class _LIBCPP_VISIBLE sub_match
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004676 : public pair<_BidirectionalIterator, _BidirectionalIterator>
4677{
4678public:
4679 typedef _BidirectionalIterator iterator;
4680 typedef typename iterator_traits<iterator>::value_type value_type;
4681 typedef typename iterator_traits<iterator>::difference_type difference_type;
4682 typedef basic_string<value_type> string_type;
4683
4684 bool matched;
4685
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004686 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004687 difference_type length() const
4688 {return matched ? _STD::distance(this->first, this->second) : 0;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004689 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004690 string_type str() const
4691 {return matched ? string_type(this->first, this->second) : string_type();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004693 operator string_type() const
4694 {return str();}
4695
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004696 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004697 int compare(const sub_match& __s) const
4698 {return str().compare(__s.str());}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004699 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004700 int compare(const string_type& __s) const
4701 {return str().compare(__s);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004702 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004703 int compare(const value_type* __s) const
4704 {return str().compare(__s);}
4705};
4706
4707typedef sub_match<const char*> csub_match;
4708typedef sub_match<const wchar_t*> wcsub_match;
4709typedef sub_match<string::const_iterator> ssub_match;
4710typedef sub_match<wstring::const_iterator> wssub_match;
4711
4712template <class _BiIter>
4713inline _LIBCPP_INLINE_VISIBILITY
4714bool
4715operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4716{
4717 return __x.compare(__y) == 0;
4718}
4719
4720template <class _BiIter>
4721inline _LIBCPP_INLINE_VISIBILITY
4722bool
4723operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4724{
4725 return !(__x == __y);
4726}
4727
4728template <class _BiIter>
4729inline _LIBCPP_INLINE_VISIBILITY
4730bool
4731operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4732{
4733 return __x.compare(__y) < 0;
4734}
4735
4736template <class _BiIter>
4737inline _LIBCPP_INLINE_VISIBILITY
4738bool
4739operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4740{
4741 return !(__y < __x);
4742}
4743
4744template <class _BiIter>
4745inline _LIBCPP_INLINE_VISIBILITY
4746bool
4747operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4748{
4749 return !(__x < __y);
4750}
4751
4752template <class _BiIter>
4753inline _LIBCPP_INLINE_VISIBILITY
4754bool
4755operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4756{
4757 return __y < __x;
4758}
4759
4760template <class _BiIter, class _ST, class _SA>
4761inline _LIBCPP_INLINE_VISIBILITY
4762bool
4763operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4764 const sub_match<_BiIter>& __y)
4765{
4766 return __y.compare(__x.c_str()) == 0;
4767}
4768
4769template <class _BiIter, class _ST, class _SA>
4770inline _LIBCPP_INLINE_VISIBILITY
4771bool
4772operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4773 const sub_match<_BiIter>& __y)
4774{
4775 return !(__x == __y);
4776}
4777
4778template <class _BiIter, class _ST, class _SA>
4779inline _LIBCPP_INLINE_VISIBILITY
4780bool
4781operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4782 const sub_match<_BiIter>& __y)
4783{
4784 return __y.compare(__x.c_str()) > 0;
4785}
4786
4787template <class _BiIter, class _ST, class _SA>
4788inline _LIBCPP_INLINE_VISIBILITY
4789bool
4790operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4791 const sub_match<_BiIter>& __y)
4792{
4793 return __y < __x;
4794}
4795
4796template <class _BiIter, class _ST, class _SA>
4797inline _LIBCPP_INLINE_VISIBILITY
4798bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4799 const sub_match<_BiIter>& __y)
4800{
4801 return !(__x < __y);
4802}
4803
4804template <class _BiIter, class _ST, class _SA>
4805inline _LIBCPP_INLINE_VISIBILITY
4806bool
4807operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4808 const sub_match<_BiIter>& __y)
4809{
4810 return !(__y < __x);
4811}
4812
4813template <class _BiIter, class _ST, class _SA>
4814inline _LIBCPP_INLINE_VISIBILITY
4815bool
4816operator==(const sub_match<_BiIter>& __x,
4817 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4818{
4819 return __x.compare(__y.c_str()) == 0;
4820}
4821
4822template <class _BiIter, class _ST, class _SA>
4823inline _LIBCPP_INLINE_VISIBILITY
4824bool
4825operator!=(const sub_match<_BiIter>& __x,
4826 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4827{
4828 return !(__x == __y);
4829}
4830
4831template <class _BiIter, class _ST, class _SA>
4832inline _LIBCPP_INLINE_VISIBILITY
4833bool
4834operator<(const sub_match<_BiIter>& __x,
4835 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4836{
4837 return __x.compare(__y.c_str()) < 0;
4838}
4839
4840template <class _BiIter, class _ST, class _SA>
4841inline _LIBCPP_INLINE_VISIBILITY
4842bool operator>(const sub_match<_BiIter>& __x,
4843 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4844{
4845 return __y < __x;
4846}
4847
4848template <class _BiIter, class _ST, class _SA>
4849inline _LIBCPP_INLINE_VISIBILITY
4850bool
4851operator>=(const sub_match<_BiIter>& __x,
4852 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4853{
4854 return !(__x < __y);
4855}
4856
4857template <class _BiIter, class _ST, class _SA>
4858inline _LIBCPP_INLINE_VISIBILITY
4859bool
4860operator<=(const sub_match<_BiIter>& __x,
4861 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4862{
4863 return !(__y < __x);
4864}
4865
4866template <class _BiIter>
4867inline _LIBCPP_INLINE_VISIBILITY
4868bool
4869operator==(typename iterator_traits<_BiIter>::value_type const* __x,
4870 const sub_match<_BiIter>& __y)
4871{
4872 return __y.compare(__x) == 0;
4873}
4874
4875template <class _BiIter>
4876inline _LIBCPP_INLINE_VISIBILITY
4877bool
4878operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
4879 const sub_match<_BiIter>& __y)
4880{
4881 return !(__x == __y);
4882}
4883
4884template <class _BiIter>
4885inline _LIBCPP_INLINE_VISIBILITY
4886bool
4887operator<(typename iterator_traits<_BiIter>::value_type const* __x,
4888 const sub_match<_BiIter>& __y)
4889{
4890 return __y.compare(__x) > 0;
4891}
4892
4893template <class _BiIter>
4894inline _LIBCPP_INLINE_VISIBILITY
4895bool
4896operator>(typename iterator_traits<_BiIter>::value_type const* __x,
4897 const sub_match<_BiIter>& __y)
4898{
4899 return __y < __x;
4900}
4901
4902template <class _BiIter>
4903inline _LIBCPP_INLINE_VISIBILITY
4904bool
4905operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
4906 const sub_match<_BiIter>& __y)
4907{
4908 return !(__x < __y);
4909}
4910
4911template <class _BiIter>
4912inline _LIBCPP_INLINE_VISIBILITY
4913bool
4914operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
4915 const sub_match<_BiIter>& __y)
4916{
4917 return !(__y < __x);
4918}
4919
4920template <class _BiIter>
4921inline _LIBCPP_INLINE_VISIBILITY
4922bool
4923operator==(const sub_match<_BiIter>& __x,
4924 typename iterator_traits<_BiIter>::value_type const* __y)
4925{
4926 return __x.compare(__y) == 0;
4927}
4928
4929template <class _BiIter>
4930inline _LIBCPP_INLINE_VISIBILITY
4931bool
4932operator!=(const sub_match<_BiIter>& __x,
4933 typename iterator_traits<_BiIter>::value_type const* __y)
4934{
4935 return !(__x == __y);
4936}
4937
4938template <class _BiIter>
4939inline _LIBCPP_INLINE_VISIBILITY
4940bool
4941operator<(const sub_match<_BiIter>& __x,
4942 typename iterator_traits<_BiIter>::value_type const* __y)
4943{
4944 return __x.compare(__y) < 0;
4945}
4946
4947template <class _BiIter>
4948inline _LIBCPP_INLINE_VISIBILITY
4949bool
4950operator>(const sub_match<_BiIter>& __x,
4951 typename iterator_traits<_BiIter>::value_type const* __y)
4952{
4953 return __y < __x;
4954}
4955
4956template <class _BiIter>
4957inline _LIBCPP_INLINE_VISIBILITY
4958bool
4959operator>=(const sub_match<_BiIter>& __x,
4960 typename iterator_traits<_BiIter>::value_type const* __y)
4961{
4962 return !(__x < __y);
4963}
4964
4965template <class _BiIter>
4966inline _LIBCPP_INLINE_VISIBILITY
4967bool
4968operator<=(const sub_match<_BiIter>& __x,
4969 typename iterator_traits<_BiIter>::value_type const* __y)
4970{
4971 return !(__y < __x);
4972}
4973
4974template <class _BiIter>
4975inline _LIBCPP_INLINE_VISIBILITY
4976bool
4977operator==(typename iterator_traits<_BiIter>::value_type const& __x,
4978 const sub_match<_BiIter>& __y)
4979{
4980 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4981 return __y.compare(string_type(1, __x)) == 0;
4982}
4983
4984template <class _BiIter>
4985inline _LIBCPP_INLINE_VISIBILITY
4986bool
4987operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
4988 const sub_match<_BiIter>& __y)
4989{
4990 return !(__x == __y);
4991}
4992
4993template <class _BiIter>
4994inline _LIBCPP_INLINE_VISIBILITY
4995bool
4996operator<(typename iterator_traits<_BiIter>::value_type const& __x,
4997 const sub_match<_BiIter>& __y)
4998{
4999 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5000 return __y.compare(string_type(1, __x)) > 0;
5001}
5002
5003template <class _BiIter>
5004inline _LIBCPP_INLINE_VISIBILITY
5005bool
5006operator>(typename iterator_traits<_BiIter>::value_type const& __x,
5007 const sub_match<_BiIter>& __y)
5008{
5009 return __y < __x;
5010}
5011
5012template <class _BiIter>
5013inline _LIBCPP_INLINE_VISIBILITY
5014bool
5015operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
5016 const sub_match<_BiIter>& __y)
5017{
5018 return !(__x < __y);
5019}
5020
5021template <class _BiIter>
5022inline _LIBCPP_INLINE_VISIBILITY
5023bool
5024operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
5025 const sub_match<_BiIter>& __y)
5026{
5027 return !(__y < __x);
5028}
5029
5030template <class _BiIter>
5031inline _LIBCPP_INLINE_VISIBILITY
5032bool
5033operator==(const sub_match<_BiIter>& __x,
5034 typename iterator_traits<_BiIter>::value_type const& __y)
5035{
5036 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5037 return __x.compare(string_type(1, __y)) == 0;
5038}
5039
5040template <class _BiIter>
5041inline _LIBCPP_INLINE_VISIBILITY
5042bool
5043operator!=(const sub_match<_BiIter>& __x,
5044 typename iterator_traits<_BiIter>::value_type const& __y)
5045{
5046 return !(__x == __y);
5047}
5048
5049template <class _BiIter>
5050inline _LIBCPP_INLINE_VISIBILITY
5051bool
5052operator<(const sub_match<_BiIter>& __x,
5053 typename iterator_traits<_BiIter>::value_type const& __y)
5054{
5055 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5056 return __x.compare(string_type(1, __y)) < 0;
5057}
5058
5059template <class _BiIter>
5060inline _LIBCPP_INLINE_VISIBILITY
5061bool
5062operator>(const sub_match<_BiIter>& __x,
5063 typename iterator_traits<_BiIter>::value_type const& __y)
5064{
5065 return __y < __x;
5066}
5067
5068template <class _BiIter>
5069inline _LIBCPP_INLINE_VISIBILITY
5070bool
5071operator>=(const sub_match<_BiIter>& __x,
5072 typename iterator_traits<_BiIter>::value_type const& __y)
5073{
5074 return !(__x < __y);
5075}
5076
5077template <class _BiIter>
5078inline _LIBCPP_INLINE_VISIBILITY
5079bool
5080operator<=(const sub_match<_BiIter>& __x,
5081 typename iterator_traits<_BiIter>::value_type const& __y)
5082{
5083 return !(__y < __x);
5084}
5085
5086template <class _CharT, class _ST, class _BiIter>
5087inline _LIBCPP_INLINE_VISIBILITY
5088basic_ostream<_CharT, _ST>&
5089operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
5090{
5091 return __os << __m.str();
5092}
5093
Howard Hinnant17615b02010-07-27 01:25:38 +00005094template <class _BidirectionalIterator, class _Allocator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005095class _LIBCPP_VISIBLE match_results
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005096{
5097public:
5098 typedef _Allocator allocator_type;
5099 typedef sub_match<_BidirectionalIterator> value_type;
5100private:
5101 typedef vector<value_type, allocator_type> __container_type;
5102
5103 __container_type __matches_;
5104 value_type __unmatched_;
5105 value_type __prefix_;
5106 value_type __suffix_;
5107public:
Howard Hinnanta712c722010-08-16 20:21:16 +00005108 _BidirectionalIterator __position_start_;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005109 typedef const value_type& const_reference;
5110 typedef const_reference reference;
5111 typedef typename __container_type::const_iterator const_iterator;
5112 typedef const_iterator iterator;
5113 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
5114 typedef typename allocator_traits<allocator_type>::size_type size_type;
5115 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
5116 typedef basic_string<char_type> string_type;
5117
5118 // construct/copy/destroy:
5119 explicit match_results(const allocator_type& __a = allocator_type());
5120// match_results(const match_results&) = default;
5121// match_results& operator=(const match_results&) = default;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005122// match_results(match_results&& __m) = default;
5123// match_results& operator=(match_results&& __m) = default;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005124// ~match_results() = default;
5125
5126 // size:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005127 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005128 size_type size() const {return __matches_.size();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005129 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005130 size_type max_size() const {return __matches_.max_size();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005132 bool empty() const {return size() == 0;}
5133
5134 // element access:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005135 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005136 difference_type length(size_type __sub = 0) const
5137 {return (*this)[__sub].length();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005138 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005139 difference_type position(size_type __sub = 0) const
Howard Hinnanta712c722010-08-16 20:21:16 +00005140 {return _STD::distance(__position_start_, (*this)[__sub].first);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005141 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005142 string_type str(size_type __sub = 0) const
5143 {return (*this)[__sub].str();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005144 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005145 const_reference operator[](size_type __n) const
5146 {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
5147
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005149 const_reference prefix() const {return __prefix_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005151 const_reference suffix() const {return __suffix_;}
5152
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005154 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005156 const_iterator end() const {return __matches_.end();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005157 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005158 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005160 const_iterator cend() const {return __matches_.end();}
5161
5162 // format:
5163 template <class _OutputIter>
5164 _OutputIter
5165 format(_OutputIter __out, const char_type* __fmt_first,
5166 const char_type* __fmt_last,
5167 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
5168 template <class _OutputIter, class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005170 _OutputIter
5171 format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005172 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5173 {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005174 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005175 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005176 basic_string<char_type, _ST, _SA>
5177 format(const basic_string<char_type, _ST, _SA>& __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005178 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5179 {
5180 basic_string<char_type, _ST, _SA> __r;
5181 format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
5182 __flags);
5183 return __r;
5184 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005185 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005186 string_type
5187 format(const char_type* __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005188 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5189 {
5190 string_type __r;
5191 format(back_inserter(__r), __fmt,
5192 __fmt + char_traits<char_type>::length(__fmt), __flags);
5193 return __r;
5194 }
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005195
5196 // allocator:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005197 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005198 allocator_type get_allocator() const {return __matches_.get_allocator();}
5199
5200 // swap:
5201 void swap(match_results& __m);
5202
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005203 template <class _B, class _A>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005205 void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
Howard Hinnanta712c722010-08-16 20:21:16 +00005206 const match_results<_B, _A>& __m, bool __no_update_pos)
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005207 {
5208 _B __mf = __m.prefix().first;
5209 __matches_.resize(__m.size());
5210 for (size_type __i = 0; __i < __matches_.size(); ++__i)
5211 {
5212 __matches_[__i].first = next(__f, _STD::distance(__mf, __m[__i].first));
5213 __matches_[__i].second = next(__f, _STD::distance(__mf, __m[__i].second));
5214 __matches_[__i].matched = __m[__i].matched;
5215 }
5216 __unmatched_.first = __l;
5217 __unmatched_.second = __l;
5218 __unmatched_.matched = false;
5219 __prefix_.first = next(__f, _STD::distance(__mf, __m.prefix().first));
5220 __prefix_.second = next(__f, _STD::distance(__mf, __m.prefix().second));
5221 __prefix_.matched = __m.prefix().matched;
5222 __suffix_.first = next(__f, _STD::distance(__mf, __m.suffix().first));
5223 __suffix_.second = next(__f, _STD::distance(__mf, __m.suffix().second));
5224 __suffix_.matched = __m.suffix().matched;
Howard Hinnanta712c722010-08-16 20:21:16 +00005225 if (!__no_update_pos)
5226 __position_start_ = __prefix_.first;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005227 }
5228
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005229private:
5230 void __init(unsigned __s,
Howard Hinnanta712c722010-08-16 20:21:16 +00005231 _BidirectionalIterator __f, _BidirectionalIterator __l,
5232 bool __no_update_pos = false);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005233
5234 template <class, class> friend class basic_regex;
5235
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005236 template <class _B, class _A, class _C, class _T>
5237 friend
5238 bool
5239 regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
5240 regex_constants::match_flag_type);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00005241
Howard Hinnant27405f92010-08-14 18:14:02 +00005242 template <class _B, class _A>
5243 friend
5244 bool
5245 operator==(const match_results<_B, _A>&, const match_results<_B, _A>&);
5246
Howard Hinnante9de5ff2010-07-27 22:20:32 +00005247 template <class, class> friend class __lookahead;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005248};
5249
5250template <class _BidirectionalIterator, class _Allocator>
5251match_results<_BidirectionalIterator, _Allocator>::match_results(
5252 const allocator_type& __a)
5253 : __matches_(__a),
5254 __unmatched_(),
5255 __prefix_(),
Howard Hinnanta712c722010-08-16 20:21:16 +00005256 __suffix_(),
5257 __position_start_()
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005258{
5259}
5260
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005261template <class _BidirectionalIterator, class _Allocator>
5262void
5263match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
Howard Hinnanta712c722010-08-16 20:21:16 +00005264 _BidirectionalIterator __f, _BidirectionalIterator __l,
5265 bool __no_update_pos)
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005266{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005267 __unmatched_.first = __l;
5268 __unmatched_.second = __l;
5269 __unmatched_.matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005270 __matches_.assign(__s, __unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005271 __prefix_.first = __f;
5272 __prefix_.second = __f;
5273 __prefix_.matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005274 __suffix_ = __unmatched_;
Howard Hinnanta712c722010-08-16 20:21:16 +00005275 if (!__no_update_pos)
5276 __position_start_ = __prefix_.first;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005277}
5278
Howard Hinnant27405f92010-08-14 18:14:02 +00005279template <class _BidirectionalIterator, class _Allocator>
5280template <class _OutputIter>
5281_OutputIter
5282match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
5283 const char_type* __fmt_first, const char_type* __fmt_last,
5284 regex_constants::match_flag_type __flags) const
5285{
5286 if (__flags & regex_constants::format_sed)
5287 {
5288 for (; __fmt_first != __fmt_last; ++__fmt_first)
5289 {
5290 if (*__fmt_first == '&')
5291 __out = _STD::copy(__matches_[0].first, __matches_[0].second,
5292 __out);
5293 else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
5294 {
5295 ++__fmt_first;
5296 if ('0' <= *__fmt_first && *__fmt_first <= '9')
5297 {
5298 size_t __i = *__fmt_first - '0';
5299 __out = _STD::copy(__matches_[__i].first,
5300 __matches_[__i].second, __out);
5301 }
5302 else
5303 {
5304 *__out = *__fmt_first;
5305 ++__out;
5306 }
5307 }
5308 else
5309 {
5310 *__out = *__fmt_first;
5311 ++__out;
5312 }
5313 }
5314 }
5315 else
5316 {
5317 for (; __fmt_first != __fmt_last; ++__fmt_first)
5318 {
5319 if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
5320 {
5321 switch (__fmt_first[1])
5322 {
5323 case '$':
5324 *__out = *++__fmt_first;
5325 ++__out;
5326 break;
5327 case '&':
5328 ++__fmt_first;
5329 __out = _STD::copy(__matches_[0].first, __matches_[0].second,
5330 __out);
5331 break;
5332 case '`':
5333 ++__fmt_first;
5334 __out = _STD::copy(__prefix_.first, __prefix_.second, __out);
5335 break;
5336 case '\'':
5337 ++__fmt_first;
5338 __out = _STD::copy(__suffix_.first, __suffix_.second, __out);
5339 break;
5340 default:
5341 if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5342 {
5343 ++__fmt_first;
5344 size_t __i = *__fmt_first - '0';
5345 if (__fmt_first + 1 != __fmt_last &&
5346 '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5347 {
5348 ++__fmt_first;
5349 __i = 10 * __i + *__fmt_first - '0';
5350 }
5351 __out = _STD::copy(__matches_[__i].first,
5352 __matches_[__i].second, __out);
5353 }
5354 else
5355 {
5356 *__out = *__fmt_first;
5357 ++__out;
5358 }
5359 break;
5360 }
5361 }
5362 else
5363 {
5364 *__out = *__fmt_first;
5365 ++__out;
5366 }
5367 }
5368 }
5369 return __out;
5370}
5371
5372template <class _BidirectionalIterator, class _Allocator>
5373void
5374match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
5375{
5376 using _STD::swap;
5377 swap(__matches_, __m.__matches_);
5378 swap(__unmatched_, __m.__unmatched_);
5379 swap(__prefix_, __m.__prefix_);
5380 swap(__suffix_, __m.__suffix_);
Howard Hinnanta712c722010-08-16 20:21:16 +00005381 swap(__position_start_, __m.__position_start_);
Howard Hinnant27405f92010-08-14 18:14:02 +00005382}
5383
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005384typedef match_results<const char*> cmatch;
5385typedef match_results<const wchar_t*> wcmatch;
5386typedef match_results<string::const_iterator> smatch;
5387typedef match_results<wstring::const_iterator> wsmatch;
5388
5389template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005390bool
5391operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
5392 const match_results<_BidirectionalIterator, _Allocator>& __y)
5393{
5394 return __x.__matches_ == __y.__matches_ &&
5395 __x.__prefix_ == __y.__prefix_ &&
Howard Hinnanta712c722010-08-16 20:21:16 +00005396 __x.__suffix_ == __y.__suffix_ &&
5397 __x.__position_start_ == __y.__position_start_;
Howard Hinnant27405f92010-08-14 18:14:02 +00005398}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005399
5400template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005401inline _LIBCPP_INLINE_VISIBILITY
5402bool
5403operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
5404 const match_results<_BidirectionalIterator, _Allocator>& __y)
5405{
5406 return !(__x == __y);
5407}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005408
5409template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005410inline _LIBCPP_INLINE_VISIBILITY
5411void
5412swap(match_results<_BidirectionalIterator, _Allocator>& __x,
5413 match_results<_BidirectionalIterator, _Allocator>& __y)
5414{
5415 __x.swap(__y);
5416}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005417
5418// regex_search
5419
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005420template <class _CharT, class _Traits>
Howard Hinnant17615b02010-07-27 01:25:38 +00005421template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005422bool
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005423basic_regex<_CharT, _Traits>::__match_at_start_ecma(
Howard Hinnant17615b02010-07-27 01:25:38 +00005424 const _CharT* __first, const _CharT* __last,
5425 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005426 regex_constants::match_flag_type __flags) const
5427{
Howard Hinnant17615b02010-07-27 01:25:38 +00005428 vector<__state> __states;
5429 ptrdiff_t __j = 0;
5430 ptrdiff_t _N = _STD::distance(__first, __last);
5431 __node* __st = __start_.get();
5432 if (__st)
5433 {
5434 __states.push_back(__state());
5435 __states.back().__do_ = 0;
5436 __states.back().__first_ = __first;
5437 __states.back().__current_ = __first;
5438 __states.back().__last_ = __last;
5439 __states.back().__sub_matches_.resize(mark_count());
5440 __states.back().__loop_data_.resize(__loop_count());
5441 __states.back().__node_ = __st;
5442 __states.back().__flags_ = __flags;
5443 bool __matched = false;
5444 do
5445 {
5446 __state& __s = __states.back();
5447 if (__s.__node_)
5448 __s.__node_->__exec(__s);
5449 switch (__s.__do_)
5450 {
5451 case __state::__end_state:
5452 __m.__matches_[0].first = __first;
5453 __m.__matches_[0].second = _STD::next(__first, __s.__current_ - __first);
5454 __m.__matches_[0].matched = true;
5455 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
5456 __m.__matches_[__i+1] = __s.__sub_matches_[__i];
5457 return true;
5458 case __state::__accept_and_consume:
5459 case __state::__repeat:
5460 case __state::__accept_but_not_consume:
5461 break;
5462 case __state::__split:
5463 {
5464 __state __snext = __s;
5465 __s.__node_->__exec_split(true, __s);
5466 __snext.__node_->__exec_split(false, __snext);
5467 __states.push_back(_STD::move(__snext));
5468 }
5469 break;
5470 case __state::__reject:
5471 __states.pop_back();
5472 break;
5473 default:
Howard Hinnantd4444702010-08-11 17:04:31 +00005474#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005475 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnantd4444702010-08-11 17:04:31 +00005476#endif
Howard Hinnant17615b02010-07-27 01:25:38 +00005477 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00005478
Howard Hinnant17615b02010-07-27 01:25:38 +00005479 }
5480 } while (!__states.empty());
5481 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005482 return false;
5483}
5484
5485template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005486template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005487bool
5488basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
5489 const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005490 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005491 regex_constants::match_flag_type __flags) const
5492{
Howard Hinnantac303862010-07-12 15:51:17 +00005493 deque<__state> __states;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005494 ptrdiff_t __highest_j = 0;
5495 ptrdiff_t _N = _STD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00005496 __node* __st = __start_.get();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005497 if (__st)
5498 {
Howard Hinnantac303862010-07-12 15:51:17 +00005499 __states.push_back(__state());
Howard Hinnantac303862010-07-12 15:51:17 +00005500 __states.back().__do_ = 0;
5501 __states.back().__first_ = __first;
5502 __states.back().__current_ = __first;
5503 __states.back().__last_ = __last;
5504 __states.back().__loop_data_.resize(__loop_count());
5505 __states.back().__node_ = __st;
5506 __states.back().__flags_ = __flags;
Howard Hinnant68025ed2010-07-14 15:45:11 +00005507 bool __matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005508 do
5509 {
Howard Hinnantac303862010-07-12 15:51:17 +00005510 __state& __s = __states.back();
5511 if (__s.__node_)
5512 __s.__node_->__exec(__s);
5513 switch (__s.__do_)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005514 {
Howard Hinnantac303862010-07-12 15:51:17 +00005515 case __state::__end_state:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005516 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
Howard Hinnant68025ed2010-07-14 15:45:11 +00005517 __highest_j = __s.__current_ - __s.__first_;
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005518 __matched = true;
Howard Hinnantac303862010-07-12 15:51:17 +00005519 if (__highest_j == _N)
5520 __states.clear();
5521 else
5522 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005523 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005524 case __state::__consume_input:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005525 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005526 case __state::__accept_and_consume:
Howard Hinnantac303862010-07-12 15:51:17 +00005527 __states.push_front(_STD::move(__s));
5528 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005529 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005530 case __state::__repeat:
5531 case __state::__accept_but_not_consume:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005532 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005533 case __state::__split:
5534 {
5535 __state __snext = __s;
5536 __s.__node_->__exec_split(true, __s);
5537 __snext.__node_->__exec_split(false, __snext);
5538 __states.push_back(_STD::move(__snext));
5539 }
5540 break;
5541 case __state::__reject:
5542 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005543 break;
5544 default:
Howard Hinnantd4444702010-08-11 17:04:31 +00005545#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005546 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnantd4444702010-08-11 17:04:31 +00005547#endif
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005548 break;
5549 }
Howard Hinnantac303862010-07-12 15:51:17 +00005550 } while (!__states.empty());
Howard Hinnant68025ed2010-07-14 15:45:11 +00005551 if (__matched)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005552 {
5553 __m.__matches_[0].first = __first;
5554 __m.__matches_[0].second = _STD::next(__first, __highest_j);
5555 __m.__matches_[0].matched = true;
5556 return true;
5557 }
5558 }
5559 return false;
5560}
5561
5562template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005563template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005564bool
5565basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005566 const _CharT* __first, const _CharT* __last,
5567 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005568 regex_constants::match_flag_type __flags) const
5569{
Howard Hinnantac303862010-07-12 15:51:17 +00005570 vector<__state> __states;
Howard Hinnantac303862010-07-12 15:51:17 +00005571 __state __best_state;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005572 ptrdiff_t __j = 0;
5573 ptrdiff_t __highest_j = 0;
5574 ptrdiff_t _N = _STD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00005575 __node* __st = __start_.get();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005576 if (__st)
5577 {
Howard Hinnantac303862010-07-12 15:51:17 +00005578 __states.push_back(__state());
5579 __states.back().__do_ = 0;
5580 __states.back().__first_ = __first;
5581 __states.back().__current_ = __first;
5582 __states.back().__last_ = __last;
5583 __states.back().__sub_matches_.resize(mark_count());
5584 __states.back().__loop_data_.resize(__loop_count());
5585 __states.back().__node_ = __st;
5586 __states.back().__flags_ = __flags;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005587 const _CharT* __current = __first;
Howard Hinnantac303862010-07-12 15:51:17 +00005588 bool __matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005589 do
5590 {
Howard Hinnantac303862010-07-12 15:51:17 +00005591 __state& __s = __states.back();
5592 if (__s.__node_)
5593 __s.__node_->__exec(__s);
5594 switch (__s.__do_)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005595 {
Howard Hinnantac303862010-07-12 15:51:17 +00005596 case __state::__end_state:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005597 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005598 {
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005599 __highest_j = __s.__current_ - __s.__first_;
Howard Hinnantac303862010-07-12 15:51:17 +00005600 __best_state = __s;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005601 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005602 __matched = true;
5603 if (__highest_j == _N)
5604 __states.clear();
5605 else
5606 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005607 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005608 case __state::__accept_and_consume:
Howard Hinnantcba352d2010-07-12 18:16:05 +00005609 __j += __s.__current_ - __current;
5610 __current = __s.__current_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005611 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005612 case __state::__repeat:
5613 case __state::__accept_but_not_consume:
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005614 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005615 case __state::__split:
5616 {
5617 __state __snext = __s;
5618 __s.__node_->__exec_split(true, __s);
5619 __snext.__node_->__exec_split(false, __snext);
5620 __states.push_back(_STD::move(__snext));
5621 }
5622 break;
5623 case __state::__reject:
5624 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005625 break;
5626 default:
Howard Hinnantd4444702010-08-11 17:04:31 +00005627#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005628 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnantd4444702010-08-11 17:04:31 +00005629#endif
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005630 break;
5631 }
Howard Hinnantac303862010-07-12 15:51:17 +00005632 } while (!__states.empty());
5633 if (__matched)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005634 {
5635 __m.__matches_[0].first = __first;
5636 __m.__matches_[0].second = _STD::next(__first, __highest_j);
5637 __m.__matches_[0].matched = true;
Howard Hinnantac303862010-07-12 15:51:17 +00005638 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
5639 __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005640 return true;
5641 }
5642 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005643 return false;
5644}
5645
5646template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005647template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005648bool
5649basic_regex<_CharT, _Traits>::__match_at_start(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005650 const _CharT* __first, const _CharT* __last,
5651 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005652 regex_constants::match_flag_type __flags) const
5653{
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005654 if ((__flags_ & 0x1F0) == ECMAScript)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005655 return __match_at_start_ecma(__first, __last, __m, __flags);
5656 if (mark_count() == 0)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005657 return __match_at_start_posix_nosubs(__first, __last, __m, __flags);
5658 return __match_at_start_posix_subs(__first, __last, __m, __flags);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005659}
5660
5661template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005662template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005663bool
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005664basic_regex<_CharT, _Traits>::__search(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005665 const _CharT* __first, const _CharT* __last,
5666 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005667 regex_constants::match_flag_type __flags) const
5668{
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00005669 if (__left_anchor_)
5670 __flags |= regex_constants::match_continuous;
Howard Hinnanta712c722010-08-16 20:21:16 +00005671 __m.__init(1 + mark_count(), __first, __last,
5672 __flags & regex_constants::__no_update_pos);
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005673 if (__match_at_start(__first, __last, __m, __flags))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005674 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005675 __m.__prefix_.second = __m[0].first;
5676 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5677 __m.__suffix_.first = __m[0].second;
5678 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5679 return true;
5680 }
Howard Hinnant8daa7332010-07-29 01:15:27 +00005681 if (__first != __last && !(__flags & regex_constants::match_continuous))
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005682 {
Howard Hinnantf3dcca02010-07-29 15:17:28 +00005683 __flags |= regex_constants::match_prev_avail;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005684 for (++__first; __first != __last; ++__first)
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005685 {
Howard Hinnantf3dcca02010-07-29 15:17:28 +00005686 __m.__matches_.assign(__m.size(), __m.__unmatched_);
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005687 if (__match_at_start(__first, __last, __m, __flags))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005688 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005689 __m.__prefix_.second = __m[0].first;
5690 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5691 __m.__suffix_.first = __m[0].second;
5692 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5693 return true;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005694 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005695 __m.__matches_.assign(__m.size(), __m.__unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005696 }
5697 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005698 __m.__matches_.clear();
5699 return false;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005700}
5701
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005702template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005703inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005704bool
5705regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5706 match_results<_BidirectionalIterator, _Allocator>& __m,
5707 const basic_regex<_CharT, _Traits>& __e,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005708 regex_constants::match_flag_type __flags = regex_constants::match_default)
5709{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005710 basic_string<_CharT> __s(__first, __last);
5711 match_results<const _CharT*> __mc;
5712 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnanta712c722010-08-16 20:21:16 +00005713 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005714 return __r;
5715}
5716
5717template <class _Allocator, class _CharT, class _Traits>
5718inline _LIBCPP_INLINE_VISIBILITY
5719bool
5720regex_search(const _CharT* __first, const _CharT* __last,
5721 match_results<const _CharT*, _Allocator>& __m,
5722 const basic_regex<_CharT, _Traits>& __e,
5723 regex_constants::match_flag_type __flags = regex_constants::match_default)
5724{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005725 return __e.__search(__first, __last, __m, __flags);
5726}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005727
5728template <class _BidirectionalIterator, class _CharT, class _Traits>
5729inline _LIBCPP_INLINE_VISIBILITY
5730bool
5731regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5732 const basic_regex<_CharT, _Traits>& __e,
5733 regex_constants::match_flag_type __flags = regex_constants::match_default)
5734{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005735 basic_string<_CharT> __s(__first, __last);
5736 match_results<const _CharT*> __mc;
5737 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5738}
5739
5740template <class _CharT, class _Traits>
5741inline _LIBCPP_INLINE_VISIBILITY
5742bool
5743regex_search(const _CharT* __first, const _CharT* __last,
5744 const basic_regex<_CharT, _Traits>& __e,
5745 regex_constants::match_flag_type __flags = regex_constants::match_default)
5746{
5747 match_results<const _CharT*> __mc;
5748 return __e.__search(__first, __last, __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005749}
5750
5751template <class _CharT, class _Allocator, class _Traits>
5752inline _LIBCPP_INLINE_VISIBILITY
5753bool
5754regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5755 const basic_regex<_CharT, _Traits>& __e,
5756 regex_constants::match_flag_type __flags = regex_constants::match_default)
5757{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005758 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005759}
5760
5761template <class _CharT, class _Traits>
5762inline _LIBCPP_INLINE_VISIBILITY
5763bool
5764regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5765 regex_constants::match_flag_type __flags = regex_constants::match_default)
5766{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005767 match_results<const _CharT*> __m;
5768 return _STD::regex_search(__str, __m, __e, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005769}
5770
5771template <class _ST, class _SA, class _CharT, class _Traits>
5772inline _LIBCPP_INLINE_VISIBILITY
5773bool
5774regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5775 const basic_regex<_CharT, _Traits>& __e,
5776 regex_constants::match_flag_type __flags = regex_constants::match_default)
5777{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005778 match_results<const _CharT*> __mc;
5779 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005780}
5781
5782template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5783inline _LIBCPP_INLINE_VISIBILITY
5784bool
5785regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5786 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5787 const basic_regex<_CharT, _Traits>& __e,
5788 regex_constants::match_flag_type __flags = regex_constants::match_default)
5789{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005790 match_results<const _CharT*> __mc;
5791 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnanta712c722010-08-16 20:21:16 +00005792 __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005793 return __r;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005794}
5795
5796// regex_match
5797
5798template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5799bool
5800regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5801 match_results<_BidirectionalIterator, _Allocator>& __m,
5802 const basic_regex<_CharT, _Traits>& __e,
5803 regex_constants::match_flag_type __flags = regex_constants::match_default)
5804{
5805 bool __r = _STD::regex_search(__first, __last, __m, __e,
5806 __flags | regex_constants::match_continuous);
5807 if (__r)
5808 {
5809 __r = !__m.suffix().matched;
5810 if (!__r)
5811 __m.__matches_.clear();
5812 }
5813 return __r;
5814}
5815
5816template <class _BidirectionalIterator, class _CharT, class _Traits>
5817inline _LIBCPP_INLINE_VISIBILITY
5818bool
5819regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5820 const basic_regex<_CharT, _Traits>& __e,
5821 regex_constants::match_flag_type __flags = regex_constants::match_default)
5822{
5823 match_results<_BidirectionalIterator> __m;
5824 return _STD::regex_match(__first, __last, __m, __e, __flags);
5825}
5826
5827template <class _CharT, class _Allocator, class _Traits>
5828inline _LIBCPP_INLINE_VISIBILITY
5829bool
5830regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5831 const basic_regex<_CharT, _Traits>& __e,
5832 regex_constants::match_flag_type __flags = regex_constants::match_default)
5833{
5834 return _STD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
5835}
5836
5837template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5838inline _LIBCPP_INLINE_VISIBILITY
5839bool
5840regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5841 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5842 const basic_regex<_CharT, _Traits>& __e,
5843 regex_constants::match_flag_type __flags = regex_constants::match_default)
5844{
5845 return _STD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
5846}
5847
5848template <class _CharT, class _Traits>
5849inline _LIBCPP_INLINE_VISIBILITY
5850bool
5851regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5852 regex_constants::match_flag_type __flags = regex_constants::match_default)
5853{
5854 return _STD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
5855}
5856
5857template <class _ST, class _SA, class _CharT, class _Traits>
5858inline _LIBCPP_INLINE_VISIBILITY
5859bool
5860regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5861 const basic_regex<_CharT, _Traits>& __e,
5862 regex_constants::match_flag_type __flags = regex_constants::match_default)
5863{
5864 return _STD::regex_match(__s.begin(), __s.end(), __e, __flags);
5865}
5866
Howard Hinnanta712c722010-08-16 20:21:16 +00005867// regex_iterator
5868
5869template <class _BidirectionalIterator,
5870 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
5871 class _Traits = regex_traits<_CharT> >
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005872class _LIBCPP_VISIBLE regex_iterator
Howard Hinnanta712c722010-08-16 20:21:16 +00005873{
5874public:
5875 typedef basic_regex<_CharT, _Traits> regex_type;
5876 typedef match_results<_BidirectionalIterator> value_type;
5877 typedef ptrdiff_t difference_type;
5878 typedef const value_type* pointer;
5879 typedef const value_type& reference;
5880 typedef forward_iterator_tag iterator_category;
5881
5882private:
5883 _BidirectionalIterator __begin_;
5884 _BidirectionalIterator __end_;
5885 const regex_type* __pregex_;
5886 regex_constants::match_flag_type __flags_;
5887 value_type __match_;
5888
5889public:
5890 regex_iterator();
5891 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
5892 const regex_type& __re,
5893 regex_constants::match_flag_type __m = regex_constants::match_default);
5894
5895 bool operator==(const regex_iterator& __x) const;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005897 bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
5898
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005900 reference operator*() const {return __match_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005902 pointer operator->() const {return &__match_;}
5903
5904 regex_iterator& operator++();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00005906 regex_iterator operator++(int)
5907 {
5908 regex_iterator __t(*this);
5909 ++(*this);
5910 return __t;
5911 }
5912};
5913
5914template <class _BidirectionalIterator, class _CharT, class _Traits>
5915regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
5916 : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
5917{
5918}
5919
5920template <class _BidirectionalIterator, class _CharT, class _Traits>
5921regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
5922 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
5923 const regex_type& __re, regex_constants::match_flag_type __m)
5924 : __begin_(__a),
5925 __end_(__b),
5926 __pregex_(&__re),
5927 __flags_(__m)
5928{
5929 _STD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
5930}
5931
5932template <class _BidirectionalIterator, class _CharT, class _Traits>
5933bool
5934regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
5935 operator==(const regex_iterator& __x) const
5936{
5937 if (__match_.empty() && __x.__match_.empty())
5938 return true;
5939 if (__match_.empty() || __x.__match_.empty())
5940 return false;
5941 return __begin_ == __x.__begin_ &&
5942 __end_ == __x.__end_ &&
5943 __pregex_ == __x.__pregex_ &&
5944 __flags_ == __x.__flags_ &&
5945 __match_[0] == __x.__match_[0];
5946}
5947
5948template <class _BidirectionalIterator, class _CharT, class _Traits>
5949regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
5950regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
5951{
5952 __flags_ |= regex_constants::__no_update_pos;
5953 _BidirectionalIterator __start = __match_[0].second;
5954 if (__match_.length() == 0)
5955 {
5956 if (__start == __end_)
5957 {
5958 __match_ = value_type();
5959 return *this;
5960 }
5961 else if (_STD::regex_search(__start, __end_, __match_, *__pregex_,
5962 __flags_ | regex_constants::match_not_null |
5963 regex_constants::match_continuous))
5964 return *this;
5965 else
5966 ++__start;
5967 }
5968 __flags_ |= regex_constants::match_prev_avail;
5969 if (!_STD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
5970 __match_ = value_type();
5971 return *this;
5972}
5973
5974typedef regex_iterator<const char*> cregex_iterator;
5975typedef regex_iterator<const wchar_t*> wcregex_iterator;
5976typedef regex_iterator<string::const_iterator> sregex_iterator;
5977typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
5978
5979// regex_token_iterator
5980
5981template <class _BidirectionalIterator,
5982 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
5983 class _Traits = regex_traits<_CharT> >
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005984class _LIBCPP_VISIBLE regex_token_iterator
Howard Hinnanta712c722010-08-16 20:21:16 +00005985{
5986public:
5987 typedef basic_regex<_CharT, _Traits> regex_type;
5988 typedef sub_match<_BidirectionalIterator> value_type;
5989 typedef ptrdiff_t difference_type;
5990 typedef const value_type* pointer;
5991 typedef const value_type& reference;
5992 typedef forward_iterator_tag iterator_category;
5993
Howard Hinnant262b7792010-08-17 20:42:03 +00005994private:
5995 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
5996
5997 _Position __position_;
5998 const value_type* __result_;
5999 value_type __suffix_;
6000 ptrdiff_t _N_;
6001 vector<int> __subs_;
6002
6003public:
Howard Hinnanta712c722010-08-16 20:21:16 +00006004 regex_token_iterator();
6005 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6006 const regex_type& __re, int __submatch = 0,
Howard Hinnant262b7792010-08-17 20:42:03 +00006007 regex_constants::match_flag_type __m =
6008 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006009 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6010 const regex_type& __re, const vector<int>& __submatches,
Howard Hinnant262b7792010-08-17 20:42:03 +00006011 regex_constants::match_flag_type __m =
6012 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006013 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
Howard Hinnant262b7792010-08-17 20:42:03 +00006014 const regex_type& __re,
6015 initializer_list<int> __submatches,
6016 regex_constants::match_flag_type __m =
6017 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006018 template <size_t _N>
Howard Hinnant262b7792010-08-17 20:42:03 +00006019 regex_token_iterator(_BidirectionalIterator __a,
6020 _BidirectionalIterator __b,
6021 const regex_type& __re,
6022 const int (&__submatches)[_N],
6023 regex_constants::match_flag_type __m =
6024 regex_constants::match_default);
Howard Hinnanta712c722010-08-16 20:21:16 +00006025 regex_token_iterator(const regex_token_iterator&);
6026 regex_token_iterator& operator=(const regex_token_iterator&);
6027
Howard Hinnant262b7792010-08-17 20:42:03 +00006028 bool operator==(const regex_token_iterator& __x) const;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006029 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006030 bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
Howard Hinnanta712c722010-08-16 20:21:16 +00006031
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006033 const value_type& operator*() const {return *__result_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006035 const value_type* operator->() const {return __result_;}
Howard Hinnanta712c722010-08-16 20:21:16 +00006036
6037 regex_token_iterator& operator++();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006038 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006039 regex_token_iterator operator++(int)
6040 {
6041 regex_token_iterator __t(*this);
6042 ++(*this);
6043 return __t;
6044 }
6045
6046private:
6047 void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
Howard Hinnanta712c722010-08-16 20:21:16 +00006048};
6049
Howard Hinnant262b7792010-08-17 20:42:03 +00006050template <class _BidirectionalIterator, class _CharT, class _Traits>
6051regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6052 regex_token_iterator()
6053 : __result_(nullptr),
6054 __suffix_(),
6055 _N_(0)
6056{
6057}
6058
6059template <class _BidirectionalIterator, class _CharT, class _Traits>
6060void
6061regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6062 __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
6063{
6064 if (__position_ != _Position())
6065 {
6066 if (__subs_[_N_] == -1)
6067 __result_ = &__position_->prefix();
6068 else
6069 __result_ = &(*__position_)[__subs_[_N_]];
6070 }
6071 else if (__subs_[_N_] == -1)
6072 {
6073 __suffix_.matched = true;
6074 __suffix_.first = __a;
6075 __suffix_.second = __b;
6076 __result_ = &__suffix_;
6077 }
6078 else
6079 __result_ = nullptr;
6080}
6081
6082template <class _BidirectionalIterator, class _CharT, class _Traits>
6083regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6084 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6085 const regex_type& __re, int __submatch,
6086 regex_constants::match_flag_type __m)
6087 : __position_(__a, __b, __re, __m),
6088 _N_(0),
6089 __subs_(1, __submatch)
6090{
6091 __init(__a, __b);
6092}
6093
6094template <class _BidirectionalIterator, class _CharT, class _Traits>
6095regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6096 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6097 const regex_type& __re, const vector<int>& __submatches,
6098 regex_constants::match_flag_type __m)
6099 : __position_(__a, __b, __re, __m),
6100 _N_(0),
6101 __subs_(__submatches)
6102{
6103 __init(__a, __b);
6104}
6105
6106template <class _BidirectionalIterator, class _CharT, class _Traits>
6107regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6108 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6109 const regex_type& __re,
6110 initializer_list<int> __submatches,
6111 regex_constants::match_flag_type __m)
6112 : __position_(__a, __b, __re, __m),
6113 _N_(0),
6114 __subs_(__submatches)
6115{
6116 __init(__a, __b);
6117}
6118
6119template <class _BidirectionalIterator, class _CharT, class _Traits>
6120template <size_t _N>
6121regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6122 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6123 const regex_type& __re,
6124 const int (&__submatches)[_N],
6125 regex_constants::match_flag_type __m)
6126 : __position_(__a, __b, __re, __m),
6127 _N_(0),
6128 __subs_(__submatches, __submatches + _N)
6129{
6130 __init(__a, __b);
6131}
6132
6133template <class _BidirectionalIterator, class _CharT, class _Traits>
6134regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6135 regex_token_iterator(const regex_token_iterator& __x)
6136 : __position_(__x.__position_),
6137 __result_(__x.__result_),
6138 __suffix_(__x.__suffix_),
6139 _N_(__x._N_),
6140 __subs_(__x.__subs_)
6141{
6142 if (__x.__result_ == &__x.__suffix_)
6143 __result_ == &__suffix_;
6144}
6145
6146template <class _BidirectionalIterator, class _CharT, class _Traits>
6147regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6148regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6149 operator=(const regex_token_iterator& __x)
6150{
6151 if (this != &__x)
6152 {
6153 __position_ = __x.__position_;
6154 if (__x.__result_ == &__x.__suffix_)
6155 __result_ == &__suffix_;
6156 else
6157 __result_ = __x.__result_;
6158 __suffix_ = __x.__suffix_;
6159 _N_ = __x._N_;
6160 __subs_ = __x.__subs_;
6161 }
6162 return *this;
6163}
6164
6165template <class _BidirectionalIterator, class _CharT, class _Traits>
6166bool
6167regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6168 operator==(const regex_token_iterator& __x) const
6169{
6170 if (__result_ == nullptr && __x.__result_ == nullptr)
6171 return true;
6172 if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
6173 __suffix_ == __x.__suffix_)
6174 return true;
6175 if (__result_ == nullptr || __x.__result_ == nullptr)
6176 return false;
6177 if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
6178 return false;
6179 return __position_ == __x.__position_ && _N_ == __x._N_ &&
6180 __subs_ == __x.__subs_;
6181}
6182
6183template <class _BidirectionalIterator, class _CharT, class _Traits>
6184regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6185regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6186{
6187 _Position __prev = __position_;
6188 if (__result_ == &__suffix_)
6189 __result_ = nullptr;
6190 else if (_N_ + 1 < __subs_.size())
6191 {
6192 ++_N_;
6193 if (__subs_[_N_] == -1)
6194 __result_ = &__position_->prefix();
6195 else
6196 __result_ = &(*__position_)[__subs_[_N_]];
6197 }
6198 else
6199 {
6200 _N_ = 0;
6201 ++__position_;
6202 if (__position_ != _Position())
6203 {
6204 if (__subs_[_N_] == -1)
6205 __result_ = &__position_->prefix();
6206 else
6207 __result_ = &(*__position_)[__subs_[_N_]];
6208 }
6209 else
6210 {
6211 if (_STD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
6212 && __prev->suffix().length() != 0)
6213 {
6214 __suffix_.matched = true;
6215 __suffix_.first = __prev->suffix().first;
6216 __suffix_.second = __prev->suffix().second;
6217 __result_ = &__suffix_;
6218 }
6219 else
6220 __result_ = nullptr;
6221 }
6222 }
6223 return *this;
6224}
6225
Howard Hinnanta712c722010-08-16 20:21:16 +00006226typedef regex_token_iterator<const char*> cregex_token_iterator;
6227typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
6228typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
6229typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
6230
Howard Hinnanta8d77592010-08-18 00:13:08 +00006231// regex_replace
6232
6233template <class _OutputIterator, class _BidirectionalIterator,
6234 class _Traits, class _CharT>
6235_OutputIterator
6236regex_replace(_OutputIterator __out,
6237 _BidirectionalIterator __first, _BidirectionalIterator __last,
6238 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6239 regex_constants::match_flag_type __flags = regex_constants::match_default)
6240{
6241 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
6242 _Iter __i(__first, __last, __e, __flags);
6243 _Iter __eof;
6244 if (__i == __eof)
6245 {
6246 if (!(__flags & regex_constants::format_no_copy))
6247 __out = _STD::copy(__first, __last, __out);
6248 }
6249 else
6250 {
6251 sub_match<_BidirectionalIterator> __lm;
6252 for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
6253 {
6254 if (!(__flags & regex_constants::format_no_copy))
6255 __out = _STD::copy(__i->prefix().first, __i->prefix().second, __out);
6256 __out = __i->format(__out, __fmt, __fmt + __len, __flags);
6257 __lm = __i->suffix();
6258 if (__flags & regex_constants::format_first_only)
6259 break;
6260 }
6261 if (!(__flags & regex_constants::format_no_copy))
6262 __out = _STD::copy(__lm.first, __lm.second, __out);
6263 }
6264 return __out;
6265}
6266
6267template <class _OutputIterator, class _BidirectionalIterator,
6268 class _Traits, class _CharT, class _ST, class _SA>
6269inline _LIBCPP_INLINE_VISIBILITY
6270_OutputIterator
6271regex_replace(_OutputIterator __out,
6272 _BidirectionalIterator __first, _BidirectionalIterator __last,
6273 const basic_regex<_CharT, _Traits>& __e,
6274 const basic_string<_CharT, _ST, _SA>& __fmt,
6275 regex_constants::match_flag_type __flags = regex_constants::match_default)
6276{
6277 return _STD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
6278}
6279
6280template <class _Traits, class _CharT, class _ST, class _SA, class _FST,
6281 class _FSA>
6282inline _LIBCPP_INLINE_VISIBILITY
6283basic_string<_CharT, _ST, _SA>
6284regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6285 const basic_regex<_CharT, _Traits>& __e,
6286 const basic_string<_CharT, _FST, _FSA>& __fmt,
6287 regex_constants::match_flag_type __flags = regex_constants::match_default)
6288{
6289 basic_string<_CharT, _ST, _SA> __r;
6290 _STD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6291 __fmt.c_str(), __flags);
6292 return __r;
6293}
6294
6295template <class _Traits, class _CharT, class _ST, class _SA>
6296inline _LIBCPP_INLINE_VISIBILITY
6297basic_string<_CharT, _ST, _SA>
6298regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6299 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6300 regex_constants::match_flag_type __flags = regex_constants::match_default)
6301{
6302 basic_string<_CharT, _ST, _SA> __r;
6303 _STD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6304 __fmt, __flags);
6305 return __r;
6306}
6307
6308template <class _Traits, class _CharT, class _ST, class _SA>
6309inline _LIBCPP_INLINE_VISIBILITY
6310basic_string<_CharT>
6311regex_replace(const _CharT* __s,
6312 const basic_regex<_CharT, _Traits>& __e,
6313 const basic_string<_CharT, _ST, _SA>& __fmt,
6314 regex_constants::match_flag_type __flags = regex_constants::match_default)
6315{
6316 basic_string<_CharT> __r;
6317 _STD::regex_replace(back_inserter(__r), __s,
6318 __s + char_traits<_CharT>::length(__s), __e,
6319 __fmt.c_str(), __flags);
6320 return __r;
6321}
6322
6323template <class _Traits, class _CharT>
6324inline _LIBCPP_INLINE_VISIBILITY
6325basic_string<_CharT>
6326regex_replace(const _CharT* __s,
6327 const basic_regex<_CharT, _Traits>& __e,
6328 const _CharT* __fmt,
6329 regex_constants::match_flag_type __flags = regex_constants::match_default)
6330{
6331 basic_string<_CharT> __r;
6332 _STD::regex_replace(back_inserter(__r), __s,
6333 __s + char_traits<_CharT>::length(__s), __e,
6334 __fmt, __flags);
6335 return __r;
6336}
6337
Howard Hinnant3257c982010-06-17 00:34:59 +00006338_LIBCPP_END_NAMESPACE_STD
6339
6340#endif // _LIBCPP_REGEX