blob: 4d132a129fb7d29f8e906319b3d89c6cf7001114 [file] [log] [blame]
Howard Hinnant3257c982010-06-17 00:34:59 +00001// -*- C++ -*-
2//===--------------------------- regex ------------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_REGEX
12#define _LIBCPP_REGEX
13
14/*
15 regex synopsis
16
17#include <initializer_list>
18
19namespace std
20{
21
22namespace regex_constants
23{
24
25emum syntax_option_type
26{
27 icase = unspecified,
28 nosubs = unspecified,
29 optimize = unspecified,
30 collate = unspecified,
31 ECMAScript = unspecified,
32 basic = unspecified,
33 extended = unspecified,
34 awk = unspecified,
35 grep = unspecified,
36 egrep = unspecified
37};
38
39constexpr syntax_option_type operator~(syntax_option_type f);
40constexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs);
41constexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs);
42
43enum match_flag_type
44{
45 match_default = 0,
46 match_not_bol = unspecified,
47 match_not_eol = unspecified,
48 match_not_bow = unspecified,
49 match_not_eow = unspecified,
50 match_any = unspecified,
51 match_not_null = unspecified,
52 match_continuous = unspecified,
53 match_prev_avail = unspecified,
54 format_default = 0,
55 format_sed = unspecified,
56 format_no_copy = unspecified,
57 format_first_only = unspecified
58};
59
60constexpr match_flag_type operator~(match_flag_type f);
61constexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs);
62constexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs);
63
64enum error_type
65{
66 error_collate = unspecified,
67 error_ctype = unspecified,
68 error_escape = unspecified,
69 error_backref = unspecified,
70 error_brack = unspecified,
71 error_paren = unspecified,
72 error_brace = unspecified,
73 error_badbrace = unspecified,
74 error_range = unspecified,
75 error_space = unspecified,
76 error_badrepeat = unspecified,
77 error_complexity = unspecified,
78 error_stack = unspecified
79};
80
81} // regex_constants
82
83class regex_error
84 : public runtime_error
85{
86public:
87 explicit regex_error(regex_constants::error_type ecode);
88 regex_constants::error_type code() const;
89};
90
91template <class charT>
92struct regex_traits
93{
94public:
95 typedef charT char_type;
96 typedef basic_string<char_type> string_type;
97 typedef locale locale_type;
98 typedef /bitmask_type/ char_class_type;
99
100 regex_traits();
101
102 static size_t length(const char_type* p);
103 charT translate(charT c) const;
104 charT translate_nocase(charT c) const;
105 template <class ForwardIterator>
106 string_type
107 transform(ForwardIterator first, ForwardIterator last) const;
108 template <class ForwardIterator>
109 string_type
110 transform_primary( ForwardIterator first, ForwardIterator last) const;
111 template <class ForwardIterator>
112 string_type
113 lookup_collatename(ForwardIterator first, ForwardIterator last) const;
114 template <class ForwardIterator>
115 char_class_type
116 lookup_classname(ForwardIterator first, ForwardIterator last,
117 bool icase = false) const;
118 bool isctype(charT c, char_class_type f) const;
119 int value(charT ch, int radix) const;
120 locale_type imbue(locale_type l);
121 locale_type getloc()const;
122};
123
124template <class charT, class traits = regex_traits<charT>>
125class basic_regex
126{
127public:
128 // types:
129 typedef charT value_type;
130 typedef regex_constants::syntax_option_type flag_type;
131 typedef typename traits::locale_type locale_type;
132
133 // constants:
134 static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
135 static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
136 static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
137 static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
138 static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
139 static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
140 static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
141 static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
142 static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
143 static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
144
145 // construct/copy/destroy:
146 basic_regex();
147 explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
148 basic_regex(const charT* p, size_t len, flag_type f);
149 basic_regex(const basic_regex&);
150 basic_regex(basic_regex&&);
151 template <class ST, class SA>
152 explicit basic_regex(const basic_string<charT, ST, SA>& p,
153 flag_type f = regex_constants::ECMAScript);
154 template <class ForwardIterator>
155 basic_regex(ForwardIterator first, ForwardIterator last,
156 flag_type f = regex_constants::ECMAScript);
157 basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
158
159 ~basic_regex();
160
161 basic_regex& operator=(const basic_regex&);
162 basic_regex& operator=(basic_regex&&);
163 basic_regex& operator=(const charT* ptr);
164 basic_regex& operator=(initializer_list<charT> il);
165 template <class ST, class SA>
166 basic_regex& operator=(const basic_string<charT, ST, SA>& p);
167
168 // assign:
169 basic_regex& assign(const basic_regex& that);
170 basic_regex& assign(basic_regex&& that);
171 basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
172 basic_regex& assign(const charT* p, size_t len, flag_type f);
173 template <class string_traits, class A>
174 basic_regex& assign(const basic_string<charT, string_traits, A>& s,
175 flag_type f = regex_constants::ECMAScript);
176 template <class InputIterator>
177 basic_regex& assign(InputIterator first, InputIterator last,
178 flag_type f = regex_constants::ECMAScript);
179 basic_regex& assign(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
180
181 // const operations:
182 unsigned mark_count() const;
183 flag_type flags() const;
184
185 // locale:
186 locale_type imbue(locale_type loc);
187 locale_type getloc() const;
188
189 // swap:
190 void swap(basic_regex&);
191};
192
193typedef basic_regex<char> regex;
194typedef basic_regex<wchar_t> wregex;
195
196template <class charT, class traits>
197 void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
198
199template <class BidirectionalIterator>
200class sub_match
201 : public pair<BidirectionalIterator, BidirectionalIterator>
202{
203public:
204 typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
205 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
206 typedef BidirectionalIterator iterator;
207 typedef basic_string<value_type> string_type;
208
209 bool matched;
210
211 difference_type length() const;
212 operator string_type() const;
213 string_type str() const;
214
215 int compare(const sub_match& s) const;
216 int compare(const string_type& s) const;
217 int compare(const value_type* s) const;
218};
219
220typedef sub_match<const char*> csub_match;
221typedef sub_match<const wchar_t*> wcsub_match;
222typedef sub_match<string::const_iterator> ssub_match;
223typedef sub_match<wstring::const_iterator> wssub_match;
224
225template <class BiIter>
226 bool
227 operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
228
229template <class BiIter>
230 bool
231 operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
232
233template <class BiIter>
234 bool
235 operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
236
237template <class BiIter>
238 bool
239 operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
240
241template <class BiIter>
242 bool
243 operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
244
245template <class BiIter>
246 bool
247 operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
248
249template <class BiIter, class ST, class SA>
250 bool
251 operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
252 const sub_match<BiIter>& rhs);
253
254template <class BiIter, class ST, class SA>
255 bool
256 operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
257 const sub_match<BiIter>& rhs);
258
259template <class BiIter, class ST, class SA>
260 bool
261 operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
262 const sub_match<BiIter>& rhs);
263
264template <class BiIter, class ST, class SA>
265 bool
266 operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
267 const sub_match<BiIter>& rhs);
268
269template <class BiIter, class ST, class SA>
270 bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
271 const sub_match<BiIter>& rhs);
272
273template <class BiIter, class ST, class SA>
274 bool
275 operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
276 const sub_match<BiIter>& rhs);
277
278template <class BiIter, class ST, class SA>
279 bool
280 operator==(const sub_match<BiIter>& lhs,
281 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
282
283template <class BiIter, class ST, class SA>
284 bool
285 operator!=(const sub_match<BiIter>& lhs,
286 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
287
288template <class BiIter, class ST, class SA>
289 bool
290 operator<(const sub_match<BiIter>& lhs,
291 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
292
293template <class BiIter, class ST, class SA>
294 bool operator>(const sub_match<BiIter>& lhs,
295 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
296
297template <class BiIter, class ST, class SA>
298 bool
299 operator>=(const sub_match<BiIter>& lhs,
300 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
301
302template <class BiIter, class ST, class SA>
303 bool
304 operator<=(const sub_match<BiIter>& lhs,
305 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
306
307template <class BiIter>
308 bool
309 operator==(typename iterator_traits<BiIter>::value_type const* lhs,
310 const sub_match<BiIter>& rhs);
311
312template <class BiIter>
313 bool
314 operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
315 const sub_match<BiIter>& rhs);
316
317template <class BiIter>
318 bool
319 operator<(typename iterator_traits<BiIter>::value_type const* lhs,
320 const sub_match<BiIter>& rhs);
321
322template <class BiIter>
323 bool
324 operator>(typename iterator_traits<BiIter>::value_type const* lhs,
325 const sub_match<BiIter>& rhs);
326
327template <class BiIter>
328 bool
329 operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
330 const sub_match<BiIter>& rhs);
331
332template <class BiIter>
333 bool
334 operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
335 const sub_match<BiIter>& rhs);
336
337template <class BiIter>
338 bool
339 operator==(const sub_match<BiIter>& lhs,
340 typename iterator_traits<BiIter>::value_type const* rhs);
341
342template <class BiIter>
343 bool
344 operator!=(const sub_match<BiIter>& lhs,
345 typename iterator_traits<BiIter>::value_type const* rhs);
346
347template <class BiIter>
348 bool
349 operator<(const sub_match<BiIter>& lhs,
350 typename iterator_traits<BiIter>::value_type const* rhs);
351
352template <class BiIter>
353 bool
354 operator>(const sub_match<BiIter>& lhs,
355 typename iterator_traits<BiIter>::value_type const* rhs);
356
357template <class BiIter>
358 bool
359 operator>=(const sub_match<BiIter>& lhs,
360 typename iterator_traits<BiIter>::value_type const* rhs);
361
362template <class BiIter>
363 bool
364 operator<=(const sub_match<BiIter>& lhs,
365 typename iterator_traits<BiIter>::value_type const* rhs);
366
367template <class BiIter>
368 bool
369 operator==(typename iterator_traits<BiIter>::value_type const& lhs,
370 const sub_match<BiIter>& rhs);
371
372template <class BiIter>
373 bool
374 operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
375 const sub_match<BiIter>& rhs);
376
377template <class BiIter>
378 bool
379 operator<(typename iterator_traits<BiIter>::value_type const& lhs,
380 const sub_match<BiIter>& rhs);
381
382template <class BiIter>
383 bool
384 operator>(typename iterator_traits<BiIter>::value_type const& lhs,
385 const sub_match<BiIter>& rhs);
386
387template <class BiIter>
388 bool
389 operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
390 const sub_match<BiIter>& rhs);
391
392template <class BiIter>
393 bool
394 operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
395 const sub_match<BiIter>& rhs);
396
397template <class BiIter>
398 bool
399 operator==(const sub_match<BiIter>& lhs,
400 typename iterator_traits<BiIter>::value_type const& rhs);
401
402template <class BiIter>
403 bool
404 operator!=(const sub_match<BiIter>& lhs,
405 typename iterator_traits<BiIter>::value_type const& rhs);
406
407template <class BiIter>
408 bool
409 operator<(const sub_match<BiIter>& lhs,
410 typename iterator_traits<BiIter>::value_type const& rhs);
411
412template <class BiIter>
413 bool
414 operator>(const sub_match<BiIter>& lhs,
415 typename iterator_traits<BiIter>::value_type const& rhs);
416
417template <class BiIter>
418 bool
419 operator>=(const sub_match<BiIter>& lhs,
420 typename iterator_traits<BiIter>::value_type const& rhs);
421
422template <class BiIter>
423 bool
424 operator<=(const sub_match<BiIter>& lhs,
425 typename iterator_traits<BiIter>::value_type const& rhs);
426
427template <class charT, class ST, class BiIter>
428 basic_ostream<charT, ST>&
429 operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
430
431template <class BidirectionalIterator,
432 class Allocator = allocator<sub_match<BidirectionalIterator>>>
433class match_results
434{
435public:
436 typedef sub_match<BidirectionalIterator> value_type;
437 typedef const value_type& const_reference;
438 typedef const_reference reference;
439 typedef /implementation-defined/ const_iterator;
440 typedef const_iterator iterator;
441 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
442 typedef typename allocator_traits<Allocator>::size_type size_type;
443 typedef Allocator allocator_type;
444 typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
445 typedef basic_string<char_type> string_type;
446
447 // construct/copy/destroy:
448 explicit match_results(const Allocator& a = Allocator());
449 match_results(const match_results& m);
450 match_results(match_results&& m);
451 match_results& operator=(const match_results& m);
452 match_results& operator=(match_results&& m);
453 ~match_results();
454
455 // size:
456 size_type size() const;
457 size_type max_size() const;
458 bool empty() const;
459
460 // element access:
461 difference_type length(size_type sub = 0) const;
462 difference_type position(size_type sub = 0) const;
463 string_type str(size_type sub = 0) const;
464 const_reference operator[](size_type n) const;
465
466 const_reference prefix() const;
467 const_reference suffix() const;
468
469 const_iterator begin() const;
470 const_iterator end() const;
471 const_iterator cbegin() const;
472 const_iterator cend() const;
473
474 // format:
475 template <class OutputIter>
476 OutputIter
477 format(OutputIter out, const char_type* fmt_first,
478 const char_type* fmt_last,
479 regex_constants::match_flag_type flags = regex_constants::format_default) const;
480 template <class OutputIter, class ST, class SA>
481 OutputIter
482 format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
483 regex_constants::match_flag_type flags = regex_constants::format_default) const;
484 template <class ST, class SA>
485 basic_string<char_type, ST, SA>
486 format(const basic_string<char_type, ST, SA>& fmt,
487 regex_constants::match_flag_type flags = regex_constants::format_default) const;
488 string_type
489 format(const char_type* fmt,
490 regex_constants::match_flag_type flags = regex_constants::format_default) const;
491
492 // allocator:
493 allocator_type get_allocator() const;
494
495 // swap:
496 void swap(match_results& that);
497};
498
499typedef match_results<const char*> cmatch;
500typedef match_results<const wchar_t*> wcmatch;
501typedef match_results<string::const_iterator> smatch;
502typedef match_results<wstring::const_iterator> wsmatch;
503
504template <class BidirectionalIterator, class Allocator>
505 bool
506 operator==(const match_results<BidirectionalIterator, Allocator>& m1,
507 const match_results<BidirectionalIterator, Allocator>& m2);
508
509template <class BidirectionalIterator, class Allocator>
510 bool
511 operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
512 const match_results<BidirectionalIterator, Allocator>& m2);
513
514template <class BidirectionalIterator, class Allocator>
515 void
516 swap(match_results<BidirectionalIterator, Allocator>& m1,
517 match_results<BidirectionalIterator, Allocator>& m2);
518
519template <class BidirectionalIterator, class Allocator, class charT, class traits>
520 bool
521 regex_match(BidirectionalIterator first, BidirectionalIterator last,
522 match_results<BidirectionalIterator, Allocator>& m,
523 const basic_regex<charT, traits>& e,
524 regex_constants::match_flag_type flags = regex_constants::match_default);
525
526template <class BidirectionalIterator, class charT, class traits>
527 bool
528 regex_match(BidirectionalIterator first, BidirectionalIterator last,
529 const basic_regex<charT, traits>& e,
530 regex_constants::match_flag_type flags = regex_constants::match_default);
531
532template <class charT, class Allocator, class traits>
533 bool
534 regex_match(const charT* str, match_results<const charT*, Allocator>& m,
535 const basic_regex<charT, traits>& e,
536 regex_constants::match_flag_type flags = regex_constants::match_default);
537
538template <class ST, class SA, class Allocator, class charT, class traits>
539 bool
540 regex_match(const basic_string<charT, ST, SA>& s,
541 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
542 const basic_regex<charT, traits>& e,
543 regex_constants::match_flag_type flags = regex_constants::match_default);
544
545template <class charT, class traits>
546 bool
547 regex_match(const charT* str, const basic_regex<charT, traits>& e,
548 regex_constants::match_flag_type flags = regex_constants::match_default);
549
550template <class ST, class SA, class charT, class traits>
551 bool
552 regex_match(const basic_string<charT, ST, SA>& s,
553 const basic_regex<charT, traits>& e,
554 regex_constants::match_flag_type flags = regex_constants::match_default);
555
556template <class BidirectionalIterator, class Allocator, class charT, class traits>
557 bool
558 regex_search(BidirectionalIterator first, BidirectionalIterator last,
559 match_results<BidirectionalIterator, Allocator>& m,
560 const basic_regex<charT, traits>& e,
561 regex_constants::match_flag_type flags = regex_constants::match_default);
562
563template <class BidirectionalIterator, class charT, class traits>
564 bool
565 regex_search(BidirectionalIterator first, BidirectionalIterator last,
566 const basic_regex<charT, traits>& e,
567 regex_constants::match_flag_type flags = regex_constants::match_default);
568
569template <class charT, class Allocator, class traits>
570 bool
571 regex_search(const charT* str, match_results<const charT*, Allocator>& m,
572 const basic_regex<charT, traits>& e,
573 regex_constants::match_flag_type flags = regex_constants::match_default);
574
575template <class charT, class traits>
576 bool
577 regex_search(const charT* str, const basic_regex<charT, traits>& e,
578 regex_constants::match_flag_type flags = regex_constants::match_default);
579
580template <class ST, class SA, class charT, class traits>
581 bool
582 regex_search(const basic_string<charT, ST, SA>& s,
583 const basic_regex<charT, traits>& e,
584 regex_constants::match_flag_type flags = regex_constants::match_default);
585
586template <class ST, class SA, class Allocator, class charT, class traits>
587 bool
588 regex_search(const basic_string<charT, ST, SA>& s,
589 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
590 const basic_regex<charT, traits>& e,
591 regex_constants::match_flag_type flags = regex_constants::match_default);
592
593template <class OutputIterator, class BidirectionalIterator,
594 class traits, class charT, class ST, class SA>
595 OutputIterator
596 regex_replace(OutputIterator out,
597 BidirectionalIterator first, BidirectionalIterator last,
598 const basic_regex<charT, traits>& e,
599 const basic_string<charT, ST, SA>& fmt,
600 regex_constants::match_flag_type flags = regex_constants::match_default);
601
602template <class OutputIterator, class BidirectionalIterator,
603 class traits, class charT>
604 OutputIterator
605 regex_replace(OutputIterator out,
606 BidirectionalIterator first, BidirectionalIterator last,
607 const basic_regex<charT, traits>& e, const charT* fmt,
608 regex_constants::match_flag_type flags = regex_constants::match_default);
609
610template <class traits, class charT, class ST, class SA, class FST, class FSA>>
611 basic_string<charT, ST, SA>
612 regex_replace(const basic_string<charT, ST, SA>& s,
613 const basic_regex<charT, traits>& e,
614 const basic_string<charT, FST, FSA>& fmt,
615 regex_constants::match_flag_type flags = regex_constants::match_default);
616
617template <class traits, class charT, class ST, class SA>
618 basic_string<charT, ST, SA>
619 regex_replace(const basic_string<charT, ST, SA>& s,
620 const basic_regex<charT, traits>& e, const charT* fmt,
621 regex_constants::match_flag_type flags = regex_constants::match_default);
622
623template <class traits, class charT, class ST, class SA>
624 basic_string<charT>
625 regex_replace(const charT* s,
626 const basic_regex<charT, traits>& e,
627 const basic_string<charT, ST, SA>& fmt,
628 regex_constants::match_flag_type flags = regex_constants::match_default);
629
630template <class traits, class charT>
631 basic_string<charT>
632 regex_replace(const charT* s,
633 const basic_regex<charT, traits>& e,
634 const charT* fmt,
635 regex_constants::match_flag_type flags = regex_constants::match_default);
636
637template <class BidirectionalIterator,
638 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
639 class traits = regex_traits<charT>>
640class regex_iterator
641{
642public:
643 typedef basic_regex<charT, traits> regex_type;
644 typedef match_results<BidirectionalIterator> value_type;
645 typedef ptrdiff_t difference_type;
646 typedef const value_type* pointer;
647 typedef const value_type& reference;
648 typedef forward_iterator_tag iterator_category;
649
650 regex_iterator();
651 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
652 const regex_type& re,
653 regex_constants::match_flag_type m = regex_constants::match_default);
654 regex_iterator(const regex_iterator&);
655 regex_iterator& operator=(const regex_iterator&);
656
657 bool operator==(const regex_iterator&) const;
658 bool operator!=(const regex_iterator&) const;
659
660 const value_type& operator*() const;
661 const value_type* operator->() const;
662
663 regex_iterator& operator++();
664 regex_iterator operator++(int);
665};
666
667typedef regex_iterator<const char*> cregex_iterator;
668typedef regex_iterator<const wchar_t*> wcregex_iterator;
669typedef regex_iterator<string::const_iterator> sregex_iterator;
670typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
671
672template <class BidirectionalIterator,
673 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
674 class traits = regex_traits<charT>>
675class regex_token_iterator
676{
677public:
678 typedef basic_regex<charT, traits> regex_type;
679 typedef sub_match<BidirectionalIterator> value_type;
680 typedef ptrdiff_t difference_type;
681 typedef const value_type* pointer;
682 typedef const value_type& reference;
683 typedef forward_iterator_tag iterator_category;
684
685 regex_token_iterator();
686 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
687 const regex_type& re, int submatch = 0,
688 regex_constants::match_flag_type m = regex_constants::match_default);
689 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
690 const regex_type& re, const vector<int>& submatches,
691 regex_constants::match_flag_type m = regex_constants::match_default);
692 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
693 const regex_type& re, initializer_list<int> submatches,
694 regex_constants::match_flag_type m = regex_constants::match_default);
695 template <size_t N>
696 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
697 const regex_type& re, const int (&submatches)[N],
698 regex_constants::match_flag_type m = regex_constants::match_default);
699 regex_token_iterator(const regex_token_iterator&);
700 regex_token_iterator& operator=(const regex_token_iterator&);
701
702 bool operator==(const regex_token_iterator&) const;
703 bool operator!=(const regex_token_iterator&) const;
704
705 const value_type& operator*() const;
706 const value_type* operator->() const;
707
708 regex_token_iterator& operator++();
709 regex_token_iterator operator++(int);
710};
711
712typedef regex_token_iterator<const char*> cregex_token_iterator;
713typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
714typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
715typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
716
717} // std
718*/
719
Howard Hinnantac303862010-07-12 15:51:17 +0000720// temporary!
Howard Hinnante77aa5e2010-07-08 17:43:58 +0000721#include <sstream>
722#include <cassert>
723
Howard Hinnant3257c982010-06-17 00:34:59 +0000724#include <__config>
725#include <stdexcept>
726#include <__locale>
Howard Hinnant8c2c18d2010-06-24 21:28:00 +0000727#include <initializer_list>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +0000728#include <utility>
729#include <iterator>
730#include <string>
Howard Hinnant7e9d84b2010-06-30 00:21:42 +0000731#include <memory>
732#include <vector>
Howard Hinnantac303862010-07-12 15:51:17 +0000733#include <deque>
Howard Hinnant3257c982010-06-17 00:34:59 +0000734
735#pragma GCC system_header
736
737_LIBCPP_BEGIN_NAMESPACE_STD
738
739namespace regex_constants
740{
741
742// syntax_option_type
743
744enum syntax_option_type
745{
746 icase = 1 << 0,
747 nosubs = 1 << 1,
748 optimize = 1 << 2,
749 collate = 1 << 3,
Howard Hinnantad2a7ab2010-07-27 17:24:17 +0000750 ECMAScript = 0,
751 basic = 1 << 4,
752 extended = 1 << 5,
753 awk = 1 << 6,
754 grep = 1 << 7,
755 egrep = 1 << 8
Howard Hinnant3257c982010-06-17 00:34:59 +0000756};
757
758inline
759/*constexpr*/
760syntax_option_type
761operator~(syntax_option_type __x)
762{
763 return syntax_option_type(~int(__x));
764}
765
766inline
767/*constexpr*/
768syntax_option_type
769operator&(syntax_option_type __x, syntax_option_type __y)
770{
771 return syntax_option_type(int(__x) & int(__y));
772}
773
774inline
775/*constexpr*/
776syntax_option_type
777operator|(syntax_option_type __x, syntax_option_type __y)
778{
779 return syntax_option_type(int(__x) | int(__y));
780}
781
782inline
783/*constexpr*/
784syntax_option_type
785operator^(syntax_option_type __x, syntax_option_type __y)
786{
787 return syntax_option_type(int(__x) ^ int(__y));
788}
789
790inline
791/*constexpr*/
792syntax_option_type&
793operator&=(syntax_option_type& __x, syntax_option_type __y)
794{
795 __x = __x & __y;
796 return __x;
797}
798
799inline
800/*constexpr*/
801syntax_option_type&
802operator|=(syntax_option_type& __x, syntax_option_type __y)
803{
804 __x = __x | __y;
805 return __x;
806}
807
808inline
809/*constexpr*/
810syntax_option_type&
811operator^=(syntax_option_type& __x, syntax_option_type __y)
812{
813 __x = __x ^ __y;
814 return __x;
815}
816
817// match_flag_type
818
819enum match_flag_type
820{
821 match_default = 0,
822 match_not_bol = 1 << 0,
823 match_not_eol = 1 << 1,
824 match_not_bow = 1 << 2,
825 match_not_eow = 1 << 3,
826 match_any = 1 << 4,
827 match_not_null = 1 << 5,
828 match_continuous = 1 << 6,
829 match_prev_avail = 1 << 7,
830 format_default = 0,
831 format_sed = 1 << 8,
832 format_no_copy = 1 << 9,
833 format_first_only = 1 << 10
834};
835
836inline
837/*constexpr*/
838match_flag_type
839operator~(match_flag_type __x)
840{
841 return match_flag_type(~int(__x));
842}
843
844inline
845/*constexpr*/
846match_flag_type
847operator&(match_flag_type __x, match_flag_type __y)
848{
849 return match_flag_type(int(__x) & int(__y));
850}
851
852inline
853/*constexpr*/
854match_flag_type
855operator|(match_flag_type __x, match_flag_type __y)
856{
857 return match_flag_type(int(__x) | int(__y));
858}
859
860inline
861/*constexpr*/
862match_flag_type
863operator^(match_flag_type __x, match_flag_type __y)
864{
865 return match_flag_type(int(__x) ^ int(__y));
866}
867
868inline
869/*constexpr*/
870match_flag_type&
871operator&=(match_flag_type& __x, match_flag_type __y)
872{
873 __x = __x & __y;
874 return __x;
875}
876
877inline
878/*constexpr*/
879match_flag_type&
880operator|=(match_flag_type& __x, match_flag_type __y)
881{
882 __x = __x | __y;
883 return __x;
884}
885
886inline
887/*constexpr*/
888match_flag_type&
889operator^=(match_flag_type& __x, match_flag_type __y)
890{
891 __x = __x ^ __y;
892 return __x;
893}
894
895enum error_type
896{
897 error_collate = 1,
898 error_ctype,
899 error_escape,
900 error_backref,
901 error_brack,
902 error_paren,
903 error_brace,
904 error_badbrace,
905 error_range,
906 error_space,
907 error_badrepeat,
908 error_complexity,
Howard Hinnant8c2c18d2010-06-24 21:28:00 +0000909 error_stack,
Howard Hinnantad2a7ab2010-07-27 17:24:17 +0000910 __re_err_grammar,
911 __re_err_empty,
912 __re_err_unknown
Howard Hinnant3257c982010-06-17 00:34:59 +0000913};
914
915} // regex_constants
916
917class _LIBCPP_EXCEPTION_ABI regex_error
918 : public runtime_error
919{
920 regex_constants::error_type __code_;
921public:
922 explicit regex_error(regex_constants::error_type __ecode);
923 virtual ~regex_error() throw();
924 regex_constants::error_type code() const {return __code_;}
925};
926
927template <class _CharT>
928struct regex_traits
929{
930public:
931 typedef _CharT char_type;
932 typedef basic_string<char_type> string_type;
933 typedef locale locale_type;
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000934 typedef ctype_base::mask char_class_type;
Howard Hinnant3257c982010-06-17 00:34:59 +0000935
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000936 static const char_class_type __regex_word = 0x80;
Howard Hinnant3257c982010-06-17 00:34:59 +0000937private:
938 locale __loc_;
939 const ctype<char_type>* __ct_;
940 const collate<char_type>* __col_;
941
942public:
943 regex_traits();
944
945 static size_t length(const char_type* __p)
946 {return char_traits<char_type>::length(__p);}
947 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>
953 string_type
954 transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
955 {return __transform_primary(__f, __l, char_type());}
956 template <class _ForwardIterator>
957 string_type
958 lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
959 {return __lookup_collatename(__f, __l, char_type());}
960 template <class _ForwardIterator>
961 char_class_type
962 lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000963 bool __icase = false) const
964 {return __lookup_classname(__f, __l, __icase, char_type());}
965 bool isctype(char_type __c, char_class_type __m) const;
966 int value(char_type __ch, int __radix) const
967 {return __value(__ch, __radix);}
Howard Hinnant3257c982010-06-17 00:34:59 +0000968 locale_type imbue(locale_type __l);
969 locale_type getloc()const {return __loc_;}
970
971private:
972 void __init();
973
974 template <class _ForwardIterator>
975 string_type
976 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
977 template <class _ForwardIterator>
978 string_type
979 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
980
981 template <class _ForwardIterator>
982 string_type
983 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
984 template <class _ForwardIterator>
985 string_type
986 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000987
988 template <class _ForwardIterator>
989 char_class_type
990 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
991 bool __icase, char) const;
992 template <class _ForwardIterator>
993 char_class_type
994 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
995 bool __icase, wchar_t) const;
996
997 static int __value(unsigned char __ch, int __radix);
998 int __value(char __ch, int __radix) const
999 {return __value(static_cast<unsigned char>(__ch), __radix);}
1000 int __value(wchar_t __ch, int __radix) const;
Howard Hinnant3257c982010-06-17 00:34:59 +00001001};
1002
1003template <class _CharT>
1004regex_traits<_CharT>::regex_traits()
1005{
1006 __init();
1007}
1008
1009template <class _CharT>
1010typename regex_traits<_CharT>::char_type
1011regex_traits<_CharT>::translate_nocase(char_type __c) const
1012{
1013 return __ct_->tolower(__c);
1014}
1015
1016template <class _CharT>
1017template <class _ForwardIterator>
1018typename regex_traits<_CharT>::string_type
1019regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
1020{
1021 string_type __s(__f, __l);
1022 return __col_->transform(__s.data(), __s.data() + __s.size());
1023}
1024
1025template <class _CharT>
1026void
1027regex_traits<_CharT>::__init()
1028{
1029 __ct_ = &use_facet<ctype<char_type> >(__loc_);
1030 __col_ = &use_facet<collate<char_type> >(__loc_);
1031}
1032
1033template <class _CharT>
1034typename regex_traits<_CharT>::locale_type
1035regex_traits<_CharT>::imbue(locale_type __l)
1036{
1037 locale __r = __loc_;
1038 __loc_ = __l;
1039 __init();
1040 return __r;
1041}
1042
1043// transform_primary is very FreeBSD-specific
1044
1045template <class _CharT>
1046template <class _ForwardIterator>
1047typename regex_traits<_CharT>::string_type
1048regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1049 _ForwardIterator __l, char) const
1050{
1051 const string_type __s(__f, __l);
1052 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1053 switch (__d.size())
1054 {
1055 case 1:
1056 break;
1057 case 12:
1058 __d[11] = __d[3];
1059 break;
1060 default:
1061 __d.clear();
1062 break;
1063 }
1064 return __d;
1065}
1066
1067template <class _CharT>
1068template <class _ForwardIterator>
1069typename regex_traits<_CharT>::string_type
1070regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1071 _ForwardIterator __l, wchar_t) const
1072{
1073 const string_type __s(__f, __l);
1074 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1075 switch (__d.size())
1076 {
1077 case 1:
1078 break;
1079 case 3:
1080 __d[2] = __d[0];
1081 break;
1082 default:
1083 __d.clear();
1084 break;
1085 }
1086 return __d;
1087}
1088
1089// lookup_collatename is very FreeBSD-specific
1090
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001091string __get_collation_name(const char* __s);
Howard Hinnant3257c982010-06-17 00:34:59 +00001092
1093template <class _CharT>
1094template <class _ForwardIterator>
1095typename regex_traits<_CharT>::string_type
1096regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1097 _ForwardIterator __l, char) const
1098{
1099 string_type __s(__f, __l);
1100 string_type __r;
1101 if (!__s.empty())
1102 {
1103 __r = __get_collation_name(__s.c_str());
1104 if (__r.empty() && __s.size() <= 2)
1105 {
1106 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1107 if (__r.size() == 1 || __r.size() == 12)
1108 __r = __s;
1109 else
1110 __r.clear();
1111 }
1112 }
1113 return __r;
1114}
1115
1116template <class _CharT>
1117template <class _ForwardIterator>
1118typename regex_traits<_CharT>::string_type
1119regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1120 _ForwardIterator __l, wchar_t) const
1121{
1122 string_type __s(__f, __l);
1123 string __n;
1124 __n.reserve(__s.size());
1125 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1126 __i != __e; ++__i)
1127 {
1128 if (static_cast<unsigned>(*__i) >= 127)
1129 return string_type();
1130 __n.push_back(char(*__i));
1131 }
1132 string_type __r;
1133 if (!__s.empty())
1134 {
1135 __n = __get_collation_name(__n.c_str());
1136 if (!__n.empty())
1137 __r.assign(__n.begin(), __n.end());
1138 else if (__s.size() <= 2)
1139 {
1140 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1141 if (__r.size() == 1 || __r.size() == 3)
1142 __r = __s;
1143 else
1144 __r.clear();
1145 }
1146 }
1147 return __r;
1148}
1149
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001150// lookup_classname
1151
1152ctype_base::mask __get_classname(const char* __s, bool __icase);
1153
1154template <class _CharT>
1155template <class _ForwardIterator>
1156typename regex_traits<_CharT>::char_class_type
1157regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1158 _ForwardIterator __l,
1159 bool __icase, char) const
1160{
1161 string_type __s(__f, __l);
1162 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1163 return __get_classname(__s.c_str(), __icase);
1164}
1165
1166template <class _CharT>
1167template <class _ForwardIterator>
1168typename regex_traits<_CharT>::char_class_type
1169regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1170 _ForwardIterator __l,
1171 bool __icase, wchar_t) const
1172{
1173 string_type __s(__f, __l);
1174 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1175 string __n;
1176 __n.reserve(__s.size());
1177 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1178 __i != __e; ++__i)
1179 {
1180 if (static_cast<unsigned>(*__i) >= 127)
1181 return char_class_type();
1182 __n.push_back(char(*__i));
1183 }
1184 return __get_classname(__n.c_str(), __icase);
1185}
1186
1187template <class _CharT>
1188bool
1189regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
1190{
1191 if (__ct_->is(__m, __c))
1192 return true;
1193 return (__c == '_' && (__m & __regex_word));
1194}
1195
1196template <class _CharT>
1197int
1198regex_traits<_CharT>::__value(unsigned char __ch, int __radix)
1199{
1200 if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
1201 return __ch - '0';
1202 if (__radix != 8)
1203 {
1204 if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
1205 return __ch - '0';
1206 if (__radix == 16)
1207 {
1208 __ch |= 0x20; // tolower
1209 if ('a' <= __ch && __ch <= 'f')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001210 return __ch - ('a' - 10);
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001211 }
1212 }
1213 return -1;
1214}
1215
1216template <class _CharT>
1217inline
1218int
1219regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const
1220{
1221 return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
1222}
1223
Howard Hinnantac303862010-07-12 15:51:17 +00001224template <class _CharT> class __node;
1225
1226template <class _BidirectionalIterator> class sub_match;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001227
Howard Hinnant17615b02010-07-27 01:25:38 +00001228template <class _BidirectionalIterator,
1229 class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1230class match_results;
1231
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001232template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001233struct __state
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001234{
1235 enum
1236 {
1237 __end_state = -1000,
1238 __consume_input, // -999
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001239 __begin_marked_expr, // -998
1240 __end_marked_expr, // -997
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001241 __pop_state, // -996
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001242 __accept_and_consume, // -995
1243 __accept_but_not_consume, // -994
1244 __reject, // -993
Howard Hinnantac303862010-07-12 15:51:17 +00001245 __split,
1246 __repeat
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001247 };
1248
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001249 int __do_;
Howard Hinnantac303862010-07-12 15:51:17 +00001250 const _CharT* __first_;
1251 const _CharT* __current_;
1252 const _CharT* __last_;
1253 vector<sub_match<const _CharT*> > __sub_matches_;
1254 vector<pair<size_t, const _CharT*> > __loop_data_;
1255 const __node<_CharT>* __node_;
1256 regex_constants::match_flag_type __flags_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001257
Howard Hinnantac303862010-07-12 15:51:17 +00001258 __state()
1259 : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
1260 __node_(nullptr), __flags_() {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001261};
1262
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001263template <class _CharT>
1264ostream&
Howard Hinnantac303862010-07-12 15:51:17 +00001265operator<<(ostream& os, const __state<_CharT>& c)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001266{
1267 os << c.__do_;
Howard Hinnantac303862010-07-12 15:51:17 +00001268 if (c.__node_)
1269 os << ", " << c.__node_->speak();
1270else
1271 os << ", null";
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001272 return os;
1273}
1274
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001275
Howard Hinnantac303862010-07-12 15:51:17 +00001276// __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001277
1278template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001279class __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001280{
Howard Hinnantac303862010-07-12 15:51:17 +00001281 __node(const __node&);
1282 __node& operator=(const __node&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001283public:
Howard Hinnantac303862010-07-12 15:51:17 +00001284 typedef _STD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001285
Howard Hinnantac303862010-07-12 15:51:17 +00001286 __node() {}
1287 virtual ~__node() {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001288
Howard Hinnantac303862010-07-12 15:51:17 +00001289 virtual void __exec(__state&) const {};
1290 virtual void __exec_split(bool, __state&) const {};
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001291
Howard Hinnantac303862010-07-12 15:51:17 +00001292 virtual string speak() const {return "__node";}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001293};
1294
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001295// __end_state
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001296
1297template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001298class __end_state
Howard Hinnantac303862010-07-12 15:51:17 +00001299 : public __node<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001300{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001301public:
Howard Hinnantac303862010-07-12 15:51:17 +00001302 typedef _STD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001303
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001304 __end_state() {}
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001305
Howard Hinnantac303862010-07-12 15:51:17 +00001306 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001307
1308 virtual string speak() const {return "end state";}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001309};
1310
1311template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001312void
1313__end_state<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001314{
Howard Hinnantac303862010-07-12 15:51:17 +00001315 __s.__do_ = __state::__end_state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001316}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001317
1318// __has_one_state
1319
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001320template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001321class __has_one_state
Howard Hinnantac303862010-07-12 15:51:17 +00001322 : public __node<_CharT>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001323{
Howard Hinnantac303862010-07-12 15:51:17 +00001324 __node<_CharT>* __first_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001325
1326public:
Howard Hinnantac303862010-07-12 15:51:17 +00001327 explicit __has_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001328 : __first_(__s) {}
1329
Howard Hinnantac303862010-07-12 15:51:17 +00001330 __node<_CharT>* first() const {return __first_;}
1331 __node<_CharT>*& first() {return __first_;}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001332};
1333
1334// __owns_one_state
1335
1336template <class _CharT>
1337class __owns_one_state
1338 : public __has_one_state<_CharT>
1339{
1340 typedef __has_one_state<_CharT> base;
1341
1342public:
Howard Hinnantac303862010-07-12 15:51:17 +00001343 explicit __owns_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001344 : base(__s) {}
1345
1346 virtual ~__owns_one_state();
1347};
1348
1349template <class _CharT>
1350__owns_one_state<_CharT>::~__owns_one_state()
1351{
1352 delete this->first();
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001353}
1354
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001355// __empty_state
1356
1357template <class _CharT>
1358class __empty_state
1359 : public __owns_one_state<_CharT>
1360{
1361 typedef __owns_one_state<_CharT> base;
1362
1363public:
Howard Hinnantac303862010-07-12 15:51:17 +00001364 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001365
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 Hinnante77aa5e2010-07-08 17:43:58 +00001370
1371 virtual string speak() const {return "empty state";}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001372};
1373
1374template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001375void
1376__empty_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001377{
Howard Hinnantac303862010-07-12 15:51:17 +00001378 __s.__do_ = __state::__accept_but_not_consume;
1379 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001380}
1381
1382// __empty_non_own_state
1383
1384template <class _CharT>
1385class __empty_non_own_state
1386 : public __has_one_state<_CharT>
1387{
1388 typedef __has_one_state<_CharT> base;
1389
1390public:
Howard Hinnantac303862010-07-12 15:51:17 +00001391 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001392
Howard Hinnantac303862010-07-12 15:51:17 +00001393 explicit __empty_non_own_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001394 : base(__s) {}
1395
Howard Hinnantac303862010-07-12 15:51:17 +00001396 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001397
1398 virtual string speak() const {return "empty non-owning state";}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001399};
1400
1401template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001402void
1403__empty_non_own_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001404{
Howard Hinnantac303862010-07-12 15:51:17 +00001405 __s.__do_ = __state::__accept_but_not_consume;
1406 __s.__node_ = this->first();
1407}
1408
1409// __repeat_one_loop
1410
1411template <class _CharT>
1412class __repeat_one_loop
1413 : public __has_one_state<_CharT>
1414{
1415 typedef __has_one_state<_CharT> base;
1416
1417public:
1418 typedef _STD::__state<_CharT> __state;
1419
1420 explicit __repeat_one_loop(__node<_CharT>* __s)
1421 : base(__s) {}
1422
1423 virtual void __exec(__state&) const;
1424
1425 virtual string speak() const {return "repeat loop";}
1426};
1427
1428template <class _CharT>
1429void
1430__repeat_one_loop<_CharT>::__exec(__state& __s) const
1431{
1432 __s.__do_ = __state::__repeat;
1433 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001434}
1435
1436// __owns_two_states
1437
1438template <class _CharT>
1439class __owns_two_states
1440 : public __owns_one_state<_CharT>
1441{
1442 typedef __owns_one_state<_CharT> base;
1443
1444 base* __second_;
1445
1446public:
Howard Hinnantac303862010-07-12 15:51:17 +00001447 explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001448 : base(__s1), __second_(__s2) {}
1449
1450 virtual ~__owns_two_states();
1451
1452 base* second() const {return __second_;}
1453 base*& second() {return __second_;}
1454};
1455
1456template <class _CharT>
1457__owns_two_states<_CharT>::~__owns_two_states()
1458{
1459 delete __second_;
1460}
1461
1462// __loop
1463
1464template <class _CharT>
1465class __loop
1466 : public __owns_two_states<_CharT>
1467{
1468 typedef __owns_two_states<_CharT> base;
1469
1470 size_t __min_;
1471 size_t __max_;
1472 unsigned __loop_id_;
Howard Hinnantac303862010-07-12 15:51:17 +00001473 unsigned __mexp_begin_;
1474 unsigned __mexp_end_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001475 bool __greedy_;
1476
1477public:
Howard Hinnantac303862010-07-12 15:51:17 +00001478 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001479
1480 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
1493 virtual string speak() const
1494 {
1495 ostringstream os;
Howard Hinnantac303862010-07-12 15:51:17 +00001496 os << "loop "<< __loop_id_ << " {" << __min_ << ',' << __max_ << "}";
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001497 if (!__greedy_)
1498 os << " not";
1499 os << " greedy";
1500 return os.str();
1501 }
Howard Hinnantac303862010-07-12 15:51:17 +00001502
1503private:
1504 void __init_repeat(__state& __s) const
1505 {
1506 __s.__loop_data_[__loop_id_].second = __s.__current_;
1507 for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
1508 {
1509 __s.__sub_matches_[__i].first = __s.__last_;
1510 __s.__sub_matches_[__i].second = __s.__last_;
1511 __s.__sub_matches_[__i].matched = false;
1512 }
1513 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001514};
1515
1516template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001517void
1518__loop<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001519{
Howard Hinnantac303862010-07-12 15:51:17 +00001520 if (__s.__do_ == __state::__repeat)
1521 {
1522 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1523 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1524 if (__do_repeat && __do_alt &&
1525 __s.__loop_data_[__loop_id_].second == __s.__current_)
1526 __do_repeat = false;
1527 if (__do_repeat && __do_alt)
1528 __s.__do_ = __state::__split;
1529 else if (__do_repeat)
1530 {
1531 __s.__do_ = __state::__accept_but_not_consume;
1532 __s.__node_ = this->first();
1533 __init_repeat(__s);
1534 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001535 else
Howard Hinnantac303862010-07-12 15:51:17 +00001536 {
1537 __s.__do_ = __state::__accept_but_not_consume;
1538 __s.__node_ = this->second();
1539 }
1540 }
1541 else
1542 {
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00001543 __s.__loop_data_[__loop_id_].first = 0;
1544 bool __do_repeat = 0 < __max_;
1545 bool __do_alt = 0 >= __min_;
1546 if (__do_repeat && __do_alt)
Howard Hinnantac303862010-07-12 15:51:17 +00001547 __s.__do_ = __state::__split;
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00001548 else if (__do_repeat)
1549 {
1550 __s.__do_ = __state::__accept_but_not_consume;
1551 __s.__node_ = this->first();
1552 __init_repeat(__s);
1553 }
Howard Hinnantac303862010-07-12 15:51:17 +00001554 else
1555 {
1556 __s.__do_ = __state::__accept_but_not_consume;
1557 __s.__node_ = this->second();
1558 }
1559 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001560}
1561
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001562template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001563void
1564__loop<_CharT>::__exec_split(bool __second, __state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001565{
Howard Hinnantac303862010-07-12 15:51:17 +00001566 __s.__do_ = __state::__accept_but_not_consume;
1567 if (__greedy_ != __second)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001568 {
Howard Hinnantac303862010-07-12 15:51:17 +00001569 __s.__node_ = this->first();
1570 __init_repeat(__s);
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001571 }
Howard Hinnantac303862010-07-12 15:51:17 +00001572 else
1573 __s.__node_ = this->second();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001574}
1575
Howard Hinnantaa698082010-07-16 19:08:36 +00001576// __alternate
1577
1578template <class _CharT>
1579class __alternate
1580 : public __owns_two_states<_CharT>
1581{
1582 typedef __owns_two_states<_CharT> base;
1583
1584public:
1585 typedef _STD::__state<_CharT> __state;
1586
1587 explicit __alternate(__owns_one_state<_CharT>* __s1,
1588 __owns_one_state<_CharT>* __s2)
1589 : base(__s1, __s2) {}
1590
1591 virtual void __exec(__state& __s) const;
1592 virtual void __exec_split(bool __second, __state& __s) const;
1593
1594 virtual string speak() const
1595 {
1596 ostringstream os;
1597 os << "__alternate";
1598 return os.str();
1599 }
1600};
1601
1602template <class _CharT>
1603void
1604__alternate<_CharT>::__exec(__state& __s) const
1605{
1606 __s.__do_ = __state::__split;
1607}
1608
1609template <class _CharT>
1610void
1611__alternate<_CharT>::__exec_split(bool __second, __state& __s) const
1612{
1613 __s.__do_ = __state::__accept_but_not_consume;
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001614 if (__second)
Howard Hinnantaa698082010-07-16 19:08:36 +00001615 __s.__node_ = this->second();
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001616 else
1617 __s.__node_ = this->first();
Howard Hinnantaa698082010-07-16 19:08:36 +00001618}
1619
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001620// __begin_marked_subexpression
1621
1622template <class _CharT>
1623class __begin_marked_subexpression
1624 : public __owns_one_state<_CharT>
1625{
1626 typedef __owns_one_state<_CharT> base;
1627
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001628 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001629public:
Howard Hinnantac303862010-07-12 15:51:17 +00001630 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001631
Howard Hinnantac303862010-07-12 15:51:17 +00001632 explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001633 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001634
Howard Hinnantac303862010-07-12 15:51:17 +00001635 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001636
1637 virtual string speak() const
1638 {
1639 ostringstream os;
1640 os << "begin marked expr " << __mexp_;
1641 return os.str();
1642 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001643};
1644
1645template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001646void
1647__begin_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001648{
Howard Hinnantac303862010-07-12 15:51:17 +00001649 __s.__do_ = __state::__accept_but_not_consume;
1650 __s.__sub_matches_[__mexp_-1].first = __s.__current_;
1651 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001652}
1653
1654// __end_marked_subexpression
1655
1656template <class _CharT>
1657class __end_marked_subexpression
1658 : public __owns_one_state<_CharT>
1659{
1660 typedef __owns_one_state<_CharT> base;
1661
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001662 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001663public:
Howard Hinnantac303862010-07-12 15:51:17 +00001664 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001665
Howard Hinnantac303862010-07-12 15:51:17 +00001666 explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001667 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001668
Howard Hinnantac303862010-07-12 15:51:17 +00001669 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001670
1671 virtual string speak() const
1672 {
1673 ostringstream os;
1674 os << "end marked expr " << __mexp_;
1675 return os.str();
1676 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001677};
1678
1679template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001680void
1681__end_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001682{
Howard Hinnantac303862010-07-12 15:51:17 +00001683 __s.__do_ = __state::__accept_but_not_consume;
1684 __s.__sub_matches_[__mexp_-1].second = __s.__current_;
1685 __s.__sub_matches_[__mexp_-1].matched = true;
1686 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001687}
1688
Howard Hinnantcba352d2010-07-12 18:16:05 +00001689// __back_ref
1690
1691template <class _CharT>
1692class __back_ref
1693 : public __owns_one_state<_CharT>
1694{
1695 typedef __owns_one_state<_CharT> base;
1696
1697 unsigned __mexp_;
1698public:
1699 typedef _STD::__state<_CharT> __state;
1700
1701 explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
1702 : base(__s), __mexp_(__mexp) {}
1703
1704 virtual void __exec(__state&) const;
1705
1706 virtual string speak() const
1707 {
1708 ostringstream os;
1709 os << "__back_ref " << __mexp_;
1710 return os.str();
1711 }
1712};
1713
1714template <class _CharT>
1715void
1716__back_ref<_CharT>::__exec(__state& __s) const
1717{
1718 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1719 if (__sm.matched)
1720 {
1721 ptrdiff_t __len = __sm.second - __sm.first;
1722 if (__s.__last_ - __s.__current_ >= __len &&
1723 _STD::equal(__sm.first, __sm.second, __s.__current_))
1724 {
1725 __s.__do_ = __state::__accept_but_not_consume;
1726 __s.__current_ += __len;
1727 __s.__node_ = this->first();
1728 }
1729 else
1730 {
1731 __s.__do_ = __state::__reject;
1732 __s.__node_ = nullptr;
1733 }
1734 }
1735 else
1736 {
1737 __s.__do_ = __state::__reject;
1738 __s.__node_ = nullptr;
1739 }
1740}
1741
Howard Hinnante34f17d2010-07-12 19:11:27 +00001742// __back_ref_icase
1743
1744template <class _CharT, class _Traits>
1745class __back_ref_icase
1746 : public __owns_one_state<_CharT>
1747{
1748 typedef __owns_one_state<_CharT> base;
1749
1750 _Traits __traits_;
1751 unsigned __mexp_;
1752public:
1753 typedef _STD::__state<_CharT> __state;
1754
1755 explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
1756 __node<_CharT>* __s)
1757 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1758
1759 virtual void __exec(__state&) const;
1760
1761 virtual string speak() const
1762 {
1763 ostringstream os;
1764 os << "__back_ref_icase " << __mexp_;
1765 return os.str();
1766 }
1767};
1768
1769template <class _CharT, class _Traits>
1770void
1771__back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
1772{
1773 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1774 if (__sm.matched)
1775 {
1776 ptrdiff_t __len = __sm.second - __sm.first;
1777 if (__s.__last_ - __s.__current_ >= __len)
1778 {
1779 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1780 {
1781 if (__traits_.translate_nocase(__sm.first[__i]) !=
1782 __traits_.translate_nocase(__s.__current_[__i]))
1783 goto __not_equal;
1784 }
1785 __s.__do_ = __state::__accept_but_not_consume;
1786 __s.__current_ += __len;
1787 __s.__node_ = this->first();
1788 }
1789 else
1790 {
1791 __s.__do_ = __state::__reject;
1792 __s.__node_ = nullptr;
1793 }
1794 }
1795 else
1796 {
1797__not_equal:
1798 __s.__do_ = __state::__reject;
1799 __s.__node_ = nullptr;
1800 }
1801}
1802
1803// __back_ref_collate
1804
1805template <class _CharT, class _Traits>
1806class __back_ref_collate
1807 : public __owns_one_state<_CharT>
1808{
1809 typedef __owns_one_state<_CharT> base;
1810
1811 _Traits __traits_;
1812 unsigned __mexp_;
1813public:
1814 typedef _STD::__state<_CharT> __state;
1815
1816 explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
1817 __node<_CharT>* __s)
1818 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1819
1820 virtual void __exec(__state&) const;
1821
1822 virtual string speak() const
1823 {
1824 ostringstream os;
1825 os << "__back_ref_collate " << __mexp_;
1826 return os.str();
1827 }
1828};
1829
1830template <class _CharT, class _Traits>
1831void
1832__back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
1833{
1834 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1835 if (__sm.matched)
1836 {
1837 ptrdiff_t __len = __sm.second - __sm.first;
1838 if (__s.__last_ - __s.__current_ >= __len)
1839 {
1840 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1841 {
1842 if (__traits_.translate(__sm.first[__i]) !=
1843 __traits_.translate(__s.__current_[__i]))
1844 goto __not_equal;
1845 }
1846 __s.__do_ = __state::__accept_but_not_consume;
1847 __s.__current_ += __len;
1848 __s.__node_ = this->first();
1849 }
1850 else
1851 {
1852 __s.__do_ = __state::__reject;
1853 __s.__node_ = nullptr;
1854 }
1855 }
1856 else
1857 {
1858__not_equal:
1859 __s.__do_ = __state::__reject;
1860 __s.__node_ = nullptr;
1861 }
1862}
1863
Howard Hinnant17615b02010-07-27 01:25:38 +00001864// __word_boundary
1865
1866template <class _CharT, class _Traits>
1867class __word_boundary
1868 : public __owns_one_state<_CharT>
1869{
1870 typedef __owns_one_state<_CharT> base;
1871
1872 _Traits __traits_;
1873 bool __invert_;
1874public:
1875 typedef _STD::__state<_CharT> __state;
1876
1877 explicit __word_boundary(const _Traits& __traits, bool __invert,
1878 __node<_CharT>* __s)
1879 : base(__s), __traits_(__traits), __invert_(__invert) {}
1880
1881 virtual void __exec(__state&) const;
1882
1883 virtual string speak() const
1884 {
1885 ostringstream os;
1886 if (__invert_)
1887 os << "__word_boundary";
1888 else
1889 os << "not __word_boundary";
1890 return os.str();
1891 }
1892};
1893
1894template <class _CharT, class _Traits>
1895void
1896__word_boundary<_CharT, _Traits>::__exec(__state& __s) const
1897{
1898 bool __is_word_b = false;
1899 if (__s.__first_ != __s.__last_)
1900 {
1901 if (__s.__current_ == __s.__last_)
1902 {
1903 if (!(__s.__flags_ & regex_constants::match_not_eow))
1904 {
1905 _CharT __c = __s.__current_[-1];
1906 __is_word_b = __c == '_' ||
1907 __traits_.isctype(__c, ctype_base::alnum);
1908 }
1909 }
1910 else if (__s.__current_ == __s.__first_)
1911 {
1912 if (!(__s.__flags_ & regex_constants::match_not_bow))
1913 {
1914 _CharT __c = *__s.__current_;
1915 __is_word_b = __c == '_' ||
1916 __traits_.isctype(__c, ctype_base::alnum);
1917 }
1918 }
1919 else
1920 {
1921 _CharT __c1 = __s.__current_[-1];
1922 _CharT __c2 = *__s.__current_;
1923 bool __is_c1_b = __c1 == '_' ||
1924 __traits_.isctype(__c1, ctype_base::alnum);
1925 bool __is_c2_b = __c2 == '_' ||
1926 __traits_.isctype(__c2, ctype_base::alnum);
1927 __is_word_b = __is_c1_b != __is_c2_b;
1928 }
1929 }
1930 if (__is_word_b != __invert_)
1931 {
1932 __s.__do_ = __state::__accept_but_not_consume;
1933 __s.__node_ = this->first();
1934 }
1935 else
1936 {
1937 __s.__do_ = __state::__reject;
1938 __s.__node_ = nullptr;
1939 }
1940}
1941
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001942// __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001943
1944template <class _CharT>
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001945class __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001946 : public __owns_one_state<_CharT>
1947{
1948 typedef __owns_one_state<_CharT> base;
1949
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001950public:
Howard Hinnantac303862010-07-12 15:51:17 +00001951 typedef _STD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001952
Howard Hinnantac303862010-07-12 15:51:17 +00001953 __r_anchor(__node<_CharT>* __s)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001954 : base(__s) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001955
Howard Hinnantac303862010-07-12 15:51:17 +00001956 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001957
1958 virtual string speak() const
1959 {
1960 ostringstream os;
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001961 os << "right anchor";
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001962 return os.str();
1963 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001964};
1965
1966template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001967void
1968__r_anchor<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001969{
Howard Hinnantac303862010-07-12 15:51:17 +00001970 if (__s.__current_ == __s.__last_)
1971 {
1972 __s.__do_ = __state::__accept_but_not_consume;
1973 __s.__node_ = this->first();
1974 }
1975 else
1976 {
1977 __s.__do_ = __state::__reject;
1978 __s.__node_ = nullptr;
1979 }
1980}
1981
1982// __match_any
1983
1984template <class _CharT>
1985class __match_any
1986 : public __owns_one_state<_CharT>
1987{
1988 typedef __owns_one_state<_CharT> base;
1989
1990public:
1991 typedef _STD::__state<_CharT> __state;
1992
1993 __match_any(__node<_CharT>* __s)
1994 : base(__s) {}
1995
1996 virtual void __exec(__state&) const;
1997
1998 virtual string speak() const
1999 {
2000 ostringstream os;
2001 os << "match any";
2002 return os.str();
2003 }
2004};
2005
2006template <class _CharT>
2007void
2008__match_any<_CharT>::__exec(__state& __s) const
2009{
2010 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
2011 {
2012 __s.__do_ = __state::__accept_and_consume;
2013 ++__s.__current_;
2014 __s.__node_ = this->first();
2015 }
2016 else
2017 {
2018 __s.__do_ = __state::__reject;
2019 __s.__node_ = nullptr;
2020 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002021}
2022
Howard Hinnant17615b02010-07-27 01:25:38 +00002023// __match_any_but_newline
2024
2025template <class _CharT>
2026class __match_any_but_newline
2027 : public __owns_one_state<_CharT>
2028{
2029 typedef __owns_one_state<_CharT> base;
2030
2031public:
2032 typedef _STD::__state<_CharT> __state;
2033
2034 __match_any_but_newline(__node<_CharT>* __s)
2035 : base(__s) {}
2036
2037 virtual void __exec(__state&) const;
2038
2039 virtual string speak() const
2040 {
2041 ostringstream os;
2042 os << "match any but newline";
2043 return os.str();
2044 }
2045};
2046
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002047// __match_char
2048
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002049template <class _CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002050class __match_char
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002051 : public __owns_one_state<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002052{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002053 typedef __owns_one_state<_CharT> base;
2054
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002055 _CharT __c_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002056
2057 __match_char(const __match_char&);
2058 __match_char& operator=(const __match_char&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002059public:
Howard Hinnantac303862010-07-12 15:51:17 +00002060 typedef _STD::__state<_CharT> __state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002061
Howard Hinnantac303862010-07-12 15:51:17 +00002062 __match_char(_CharT __c, __node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002063 : base(__s), __c_(__c) {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002064
Howard Hinnantac303862010-07-12 15:51:17 +00002065 virtual void __exec(__state&) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002066
2067 virtual string speak() const
2068 {
2069 ostringstream os;
2070 os << "match char " << __c_;
2071 return os.str();
2072 }
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002073};
2074
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002075template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00002076void
2077__match_char<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002078{
Howard Hinnantac303862010-07-12 15:51:17 +00002079 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
2080 {
2081 __s.__do_ = __state::__accept_and_consume;
2082 ++__s.__current_;
2083 __s.__node_ = this->first();
2084 }
2085 else
2086 {
2087 __s.__do_ = __state::__reject;
2088 __s.__node_ = nullptr;
2089 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002090}
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002091
Howard Hinnante34f17d2010-07-12 19:11:27 +00002092// __match_char_icase
2093
2094template <class _CharT, class _Traits>
2095class __match_char_icase
2096 : public __owns_one_state<_CharT>
2097{
2098 typedef __owns_one_state<_CharT> base;
2099
2100 _Traits __traits_;
2101 _CharT __c_;
2102
2103 __match_char_icase(const __match_char_icase&);
2104 __match_char_icase& operator=(const __match_char_icase&);
2105public:
2106 typedef _STD::__state<_CharT> __state;
2107
2108 __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2109 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
2110
2111 virtual void __exec(__state&) const;
2112
2113 virtual string speak() const
2114 {
2115 ostringstream os;
2116 os << "match char icase " << __c_;
2117 return os.str();
2118 }
2119};
2120
2121template <class _CharT, class _Traits>
2122void
2123__match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
2124{
2125 if (__s.__current_ != __s.__last_ &&
2126 __traits_.translate_nocase(*__s.__current_) == __c_)
2127 {
2128 __s.__do_ = __state::__accept_and_consume;
2129 ++__s.__current_;
2130 __s.__node_ = this->first();
2131 }
2132 else
2133 {
2134 __s.__do_ = __state::__reject;
2135 __s.__node_ = nullptr;
2136 }
2137}
2138
2139// __match_char_collate
2140
2141template <class _CharT, class _Traits>
2142class __match_char_collate
2143 : public __owns_one_state<_CharT>
2144{
2145 typedef __owns_one_state<_CharT> base;
2146
2147 _Traits __traits_;
2148 _CharT __c_;
2149
2150 __match_char_collate(const __match_char_collate&);
2151 __match_char_collate& operator=(const __match_char_collate&);
2152public:
2153 typedef _STD::__state<_CharT> __state;
2154
2155 __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2156 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2157
2158 virtual void __exec(__state&) const;
2159
2160 virtual string speak() const
2161 {
2162 ostringstream os;
2163 os << "match char icase " << __c_;
2164 return os.str();
2165 }
2166};
2167
2168template <class _CharT, class _Traits>
2169void
2170__match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
2171{
2172 if (__s.__current_ != __s.__last_ &&
2173 __traits_.translate(*__s.__current_) == __c_)
2174 {
2175 __s.__do_ = __state::__accept_and_consume;
2176 ++__s.__current_;
2177 __s.__node_ = this->first();
2178 }
2179 else
2180 {
2181 __s.__do_ = __state::__reject;
2182 __s.__node_ = nullptr;
2183 }
2184}
2185
Howard Hinnant173968a2010-07-13 21:48:06 +00002186// __bracket_expression
2187
2188template <class _CharT, class _Traits>
2189class __bracket_expression
2190 : public __owns_one_state<_CharT>
2191{
2192 typedef __owns_one_state<_CharT> base;
2193 typedef typename _Traits::string_type string_type;
2194
2195 _Traits __traits_;
2196 vector<_CharT> __chars_;
2197 vector<pair<string_type, string_type> > __ranges_;
2198 vector<pair<_CharT, _CharT> > __digraphs_;
2199 vector<string_type> __equivalences_;
2200 ctype_base::mask __mask_;
2201 bool __negate_;
2202 bool __icase_;
2203 bool __collate_;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002204 bool __might_have_digraph_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002205
2206 __bracket_expression(const __bracket_expression&);
2207 __bracket_expression& operator=(const __bracket_expression&);
2208public:
2209 typedef _STD::__state<_CharT> __state;
2210
2211 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
2212 bool __negate, bool __icase, bool __collate)
2213 : base(__s), __traits_(__traits), __mask_(), __negate_(__negate),
Howard Hinnant68025ed2010-07-14 15:45:11 +00002214 __icase_(__icase), __collate_(__collate),
2215 __might_have_digraph_(__traits_.getloc().name() != "C") {}
Howard Hinnant173968a2010-07-13 21:48:06 +00002216
2217 virtual void __exec(__state&) const;
2218
2219 void __add_char(_CharT __c)
2220 {
2221 if (__icase_)
2222 __chars_.push_back(__traits_.translate_nocase(__c));
2223 else if (__collate_)
2224 __chars_.push_back(__traits_.translate(__c));
2225 else
2226 __chars_.push_back(__c);
2227 }
2228 void __add_range(string_type __b, string_type __e)
2229 {
2230 if (__collate_)
2231 {
2232 if (__icase_)
2233 {
2234 for (size_t __i = 0; __i < __b.size(); ++__i)
2235 __b[__i] = __traits_.translate_nocase(__b[__i]);
2236 for (size_t __i = 0; __i < __e.size(); ++__i)
2237 __e[__i] = __traits_.translate_nocase(__e[__i]);
2238 }
2239 else
2240 {
2241 for (size_t __i = 0; __i < __b.size(); ++__i)
2242 __b[__i] = __traits_.translate(__b[__i]);
2243 for (size_t __i = 0; __i < __e.size(); ++__i)
2244 __e[__i] = __traits_.translate(__e[__i]);
2245 }
2246 __ranges_.push_back(make_pair(
2247 __traits_.transform(__b.begin(), __b.end()),
2248 __traits_.transform(__e.begin(), __e.end())));
2249 }
2250 else
2251 {
2252 if (__b.size() != 1 || __e.size() != 1)
2253 throw regex_error(regex_constants::error_collate);
2254 if (__icase_)
2255 {
2256 __b[0] = __traits_.translate_nocase(__b[0]);
2257 __e[0] = __traits_.translate_nocase(__e[0]);
2258 }
2259 __ranges_.push_back(make_pair(_STD::move(__b), _STD::move(__e)));
2260 }
2261 }
2262 void __add_digraph(_CharT __c1, _CharT __c2)
2263 {
2264 if (__icase_)
2265 __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
2266 __traits_.translate_nocase(__c2)));
2267 else if (__collate_)
2268 __digraphs_.push_back(make_pair(__traits_.translate(__c1),
2269 __traits_.translate(__c2)));
2270 else
2271 __digraphs_.push_back(make_pair(__c1, __c2));
2272 }
2273 void __add_equivalence(const string_type& __s)
2274 {__equivalences_.push_back(__s);}
2275 void __add_class(ctype_base::mask __mask)
2276 {__mask_ |= __mask;}
2277
2278 virtual string speak() const
2279 {
2280 ostringstream os;
2281 os << "__bracket_expression ";
2282 return os.str();
2283 }
2284};
2285
2286template <class _CharT, class _Traits>
2287void
2288__bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
2289{
2290 bool __found = false;
2291 unsigned __consumed = 0;
2292 if (__s.__current_ != __s.__last_)
2293 {
2294 ++__consumed;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002295 if (__might_have_digraph_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002296 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002297 const _CharT* __next = next(__s.__current_);
2298 if (__next != __s.__last_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002299 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002300 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2301 if (__icase_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002302 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002303 __ch2.first = __traits_.translate_nocase(__ch2.first);
2304 __ch2.second = __traits_.translate_nocase(__ch2.second);
2305 }
2306 else if (__collate_)
2307 {
2308 __ch2.first = __traits_.translate(__ch2.first);
2309 __ch2.second = __traits_.translate(__ch2.second);
2310 }
2311 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
2312 {
2313 // __ch2 is a digraph in this locale
2314 ++__consumed;
2315 for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
2316 {
2317 if (__ch2 == __digraphs_[__i])
2318 {
2319 __found = true;
2320 goto __exit;
2321 }
2322 }
2323 if (__collate_ && !__ranges_.empty())
2324 {
2325 string_type __s2 = __traits_.transform(&__ch2.first,
2326 &__ch2.first + 2);
2327 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2328 {
2329 if (__ranges_[__i].first <= __s2 &&
2330 __s2 <= __ranges_[__i].second)
2331 {
2332 __found = true;
2333 goto __exit;
2334 }
2335 }
2336 }
2337 if (!__equivalences_.empty())
2338 {
2339 string_type __s2 = __traits_.transform_primary(&__ch2.first,
2340 &__ch2.first + 2);
2341 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2342 {
2343 if (__s2 == __equivalences_[__i])
2344 {
2345 __found = true;
2346 goto __exit;
2347 }
2348 }
2349 }
2350 if (__traits_.isctype(__ch2.first, __mask_) &&
2351 __traits_.isctype(__ch2.second, __mask_))
Howard Hinnant173968a2010-07-13 21:48:06 +00002352 {
2353 __found = true;
2354 goto __exit;
2355 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002356 goto __exit;
2357 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002358 }
2359 }
2360 // test *__s.__current_ as not a digraph
2361 _CharT __ch = *__s.__current_;
2362 if (__icase_)
2363 __ch = __traits_.translate_nocase(__ch);
2364 else if (__collate_)
2365 __ch = __traits_.translate(__ch);
2366 for (size_t __i = 0; __i < __chars_.size(); ++__i)
2367 {
2368 if (__ch == __chars_[__i])
2369 {
2370 __found = true;
2371 goto __exit;
2372 }
2373 }
2374 if (!__ranges_.empty())
2375 {
2376 string_type __s2 = __collate_ ?
2377 __traits_.transform(&__ch, &__ch + 1) :
2378 string_type(1, __ch);
2379 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2380 {
2381 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
2382 {
2383 __found = true;
2384 goto __exit;
2385 }
2386 }
2387 }
2388 if (!__equivalences_.empty())
2389 {
2390 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2391 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2392 {
2393 if (__s2 == __equivalences_[__i])
2394 {
2395 __found = true;
2396 goto __exit;
2397 }
2398 }
2399 }
2400 if (__traits_.isctype(__ch, __mask_))
2401 __found = true;
2402 }
2403 else
2404 __found = __negate_; // force reject
2405__exit:
2406 if (__found != __negate_)
2407 {
Howard Hinnant173968a2010-07-13 21:48:06 +00002408 __s.__do_ = __state::__accept_and_consume;
2409 __s.__current_ += __consumed;
2410 __s.__node_ = this->first();
2411 }
2412 else
2413 {
2414 __s.__do_ = __state::__reject;
2415 __s.__node_ = nullptr;
2416 }
2417}
2418
Howard Hinnant17615b02010-07-27 01:25:38 +00002419// __lookahead
2420
2421template <class _CharT, class _Traits>
2422class __lookahead
2423 : public __owns_one_state<_CharT>
2424{
2425 typedef __owns_one_state<_CharT> base;
2426
2427 _Traits __traits_;
2428 bool __invert_;
2429
2430 __lookahead(const __lookahead&);
2431 __lookahead& operator=(const __lookahead&);
2432public:
2433 typedef _STD::__state<_CharT> __state;
2434
2435 __lookahead(const _Traits& __traits, bool __invert, __node<_CharT>* __s)
2436 : base(__s), __traits_(__traits), __invert_(__invert) {}
2437
2438 virtual void __exec(__state&) const;
2439
2440 virtual string speak() const
2441 {
2442 ostringstream os;
2443 if (__invert_)
2444 os << "lookahead";
2445 else
2446 os << "not lookahead";
2447 return os.str();
2448 }
2449};
2450
2451template <class _CharT, class _Traits>
2452void
2453__lookahead<_CharT, _Traits>::__exec(__state& __s) const
2454{
2455// match_results<const _CharT*> __m;
2456// __m.__init(1 + mark_count(), __s.__current_, __s.__last_);
2457// bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
2458// __m, __s.__flags_);
2459// if (__matched != __invert_)
2460// {
2461// __s.__do_ = __state::__accept_but_not_consume;
2462// __s.__node_ = this->first();
2463// }
2464// else
2465// {
2466// __s.__do_ = __state::__reject;
2467// __s.__node_ = nullptr;
2468// }
2469}
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002470
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002471template <class _CharT, class _Traits = regex_traits<_CharT> >
2472class basic_regex
2473{
2474public:
2475 // types:
2476 typedef _CharT value_type;
2477 typedef regex_constants::syntax_option_type flag_type;
2478 typedef typename _Traits::locale_type locale_type;
2479
2480private:
2481 _Traits __traits_;
2482 flag_type __flags_;
2483 unsigned __marked_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002484 unsigned __loop_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002485 int __open_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002486 shared_ptr<__empty_state<_CharT> > __start_;
2487 __owns_one_state<_CharT>* __end_;
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002488 bool __left_anchor_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002489
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002490 typedef _STD::__state<_CharT> __state;
Howard Hinnantac303862010-07-12 15:51:17 +00002491 typedef _STD::__node<_CharT> __node;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002492
2493public:
2494 // constants:
2495 static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase;
2496 static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2497 static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize;
2498 static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate;
2499 static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2500 static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic;
2501 static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended;
2502 static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk;
2503 static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep;
2504 static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep;
2505
2506 // construct/copy/destroy:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002507 basic_regex()
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002508 : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0),
2509 __end_(0), __left_anchor_(false)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002510 {}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002511 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002512 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2513 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002514 {__parse(__p, __p + __traits_.length(__p));}
2515 basic_regex(const value_type* __p, size_t __len, flag_type __f)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002516 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2517 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002518 {__parse(__p, __p + __len);}
2519 basic_regex(const basic_regex&);
2520#ifdef _LIBCPP_MOVE
2521 basic_regex(basic_regex&&);
2522#endif
2523 template <class _ST, class _SA>
2524 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2525 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002526 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2527 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002528 {__parse(__p.begin(), __p.end());}
2529 template <class _ForwardIterator>
2530 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
2531 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002532 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2533 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002534 {__parse(__first, __last);}
2535 basic_regex(initializer_list<value_type> __il,
2536 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002537 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2538 __end_(0), __left_anchor_(false)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002539 {__parse(__il.begin(), __il.end());}
2540
2541 ~basic_regex();
2542
2543 basic_regex& operator=(const basic_regex&);
2544#ifdef _LIBCPP_MOVE
2545 basic_regex& operator=(basic_regex&&);
2546#endif
2547 basic_regex& operator=(const value_type* __p);
2548 basic_regex& operator=(initializer_list<value_type> __il);
2549 template <class _ST, class _SA>
2550 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p);
2551
2552 // assign:
2553 basic_regex& assign(const basic_regex& __that);
2554#ifdef _LIBCPP_MOVE
2555 basic_regex& assign(basic_regex&& __that);
2556#endif
2557 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript);
2558 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f);
2559 template <class _ST, class _SA>
2560 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
2561 flag_type __f = regex_constants::ECMAScript);
2562 template <class _InputIterator>
2563 basic_regex& assign(_InputIterator __first, _InputIterator __last,
2564 flag_type __f = regex_constants::ECMAScript);
2565 basic_regex& assign(initializer_list<value_type> __il,
2566 flag_type = regex_constants::ECMAScript);
2567
2568 // const operations:
2569 unsigned mark_count() const {return __marked_count_;}
2570 flag_type flags() const {return __flags_;}
2571
2572 // locale:
2573 locale_type imbue(locale_type __loc) {return __traits_.imbue(__loc);}
2574 locale_type getloc() const {return __traits_.getloc();}
2575
2576 // swap:
2577 void swap(basic_regex&);
2578
2579private:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002580 unsigned __loop_count() const {return __loop_count_;}
2581
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002582 template <class _ForwardIterator>
2583 void __parse(_ForwardIterator __first, _ForwardIterator __last);
2584 template <class _ForwardIterator>
2585 _ForwardIterator
2586 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2587 template <class _ForwardIterator>
2588 _ForwardIterator
2589 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2590 template <class _ForwardIterator>
2591 _ForwardIterator
2592 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2593 template <class _ForwardIterator>
2594 _ForwardIterator
2595 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2596 template <class _ForwardIterator>
2597 _ForwardIterator
2598 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2599 template <class _ForwardIterator>
2600 _ForwardIterator
2601 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2602 template <class _ForwardIterator>
2603 _ForwardIterator
2604 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2605 template <class _ForwardIterator>
2606 _ForwardIterator
2607 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2608 template <class _ForwardIterator>
2609 _ForwardIterator
2610 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2611 template <class _ForwardIterator>
2612 _ForwardIterator
2613 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2614 template <class _ForwardIterator>
2615 _ForwardIterator
2616 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2617 template <class _ForwardIterator>
2618 _ForwardIterator
2619 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2620 template <class _ForwardIterator>
2621 _ForwardIterator
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002622 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002623 __owns_one_state<_CharT>* __s,
2624 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002625 template <class _ForwardIterator>
2626 _ForwardIterator
Howard Hinnantaa698082010-07-16 19:08:36 +00002627 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2628 __owns_one_state<_CharT>* __s,
2629 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002630 template <class _ForwardIterator>
2631 _ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00002632 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2633 template <class _ForwardIterator>
2634 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002635 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
2636 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002637 template <class _ForwardIterator>
2638 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002639 __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
2640 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002641 template <class _ForwardIterator>
2642 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002643 __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
2644 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002645 template <class _ForwardIterator>
2646 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002647 __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
2648 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002649 template <class _ForwardIterator>
2650 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002651 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
2652 basic_string<_CharT>& __col_sym);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002653 template <class _ForwardIterator>
2654 _ForwardIterator
2655 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002656 template <class _ForwardIterator>
2657 _ForwardIterator
2658 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2659 template <class _ForwardIterator>
2660 _ForwardIterator
2661 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2662 template <class _ForwardIterator>
2663 _ForwardIterator
2664 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2665 template <class _ForwardIterator>
2666 _ForwardIterator
2667 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2668 template <class _ForwardIterator>
2669 _ForwardIterator
2670 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2671 template <class _ForwardIterator>
2672 _ForwardIterator
2673 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002674 template <class _ForwardIterator>
2675 _ForwardIterator
2676 __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2677 template <class _ForwardIterator>
2678 _ForwardIterator
2679 __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2680 template <class _ForwardIterator>
2681 _ForwardIterator
2682 __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2683 template <class _ForwardIterator>
2684 _ForwardIterator
2685 __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2686 template <class _ForwardIterator>
2687 _ForwardIterator
2688 __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2689 template <class _ForwardIterator>
2690 _ForwardIterator
Howard Hinnant17615b02010-07-27 01:25:38 +00002691 __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2692 template <class _ForwardIterator>
2693 _ForwardIterator
2694 __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2695 template <class _ForwardIterator>
2696 _ForwardIterator
2697 __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2698 template <class _ForwardIterator>
2699 _ForwardIterator
2700 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last);
2701 template <class _ForwardIterator>
2702 _ForwardIterator
2703 __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant856846b2010-07-27 19:53:10 +00002704 template <class _ForwardIterator>
2705 _ForwardIterator
2706 __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
2707 template <class _ForwardIterator>
2708 _ForwardIterator
2709 __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002710
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002711 void __push_l_anchor() {__left_anchor_ = true;}
2712 void __push_r_anchor();
Howard Hinnantac303862010-07-12 15:51:17 +00002713 void __push_match_any();
Howard Hinnant17615b02010-07-27 01:25:38 +00002714 void __push_match_any_but_newline();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002715 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2716 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2717 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2718 __mexp_begin, __mexp_end);}
Howard Hinnant17615b02010-07-27 01:25:38 +00002719 void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2720 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2721 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2722 __mexp_begin, __mexp_end, false);}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002723 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2724 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2725 bool __greedy = true);
Howard Hinnant173968a2010-07-13 21:48:06 +00002726 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002727 void __push_char(value_type __c);
Howard Hinnantcba352d2010-07-12 18:16:05 +00002728 void __push_back_ref(int __i);
Howard Hinnantaa698082010-07-16 19:08:36 +00002729 void __push_alternation(__owns_one_state<_CharT>* __sa,
2730 __owns_one_state<_CharT>* __sb);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002731 void __push_begin_marked_subexpression();
2732 void __push_end_marked_subexpression(unsigned);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002733 void __push_empty();
Howard Hinnant17615b02010-07-27 01:25:38 +00002734 void __push_word_boundary(bool);
2735 void __push_lookahead(bool) {}
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002736
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002737 template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002738 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002739 __search(const _CharT* __first, const _CharT* __last,
2740 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002741 regex_constants::match_flag_type __flags) const;
2742
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002743 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002744 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002745 __match_at_start(const _CharT* __first, const _CharT* __last,
2746 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002747 regex_constants::match_flag_type __flags) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00002748 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002749 bool
Howard Hinnant17615b02010-07-27 01:25:38 +00002750 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
2751 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002752 regex_constants::match_flag_type __flags) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002753 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002754 bool
2755 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002756 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002757 regex_constants::match_flag_type __flags) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002758 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002759 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002760 __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
2761 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002762 regex_constants::match_flag_type __flags) const;
2763
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002764 template <class _B, class _A, class _C, class _T>
2765 friend
2766 bool
2767 regex_search(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
2768 regex_constants::match_flag_type);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002769
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002770 template <class _A, class _C, class _T>
2771 friend
2772 bool
2773 regex_search(const _C*, const _C*, match_results<const _C*, _A>&,
2774 const basic_regex<_C, _T>&, regex_constants::match_flag_type);
2775
2776 template <class _B, class _C, class _T>
2777 friend
2778 bool
2779 regex_search(_B, _B, const basic_regex<_C, _T>&,
2780 regex_constants::match_flag_type);
2781
2782 template <class _C, class _T>
2783 friend
2784 bool
2785 regex_search(const _C*, const _C*,
2786 const basic_regex<_C, _T>&, regex_constants::match_flag_type);
2787
2788 template <class _C, class _A, class _T>
2789 friend
2790 bool
2791 regex_search(const _C*, match_results<const _C*, _A>&, const basic_regex<_C, _T>&,
2792 regex_constants::match_flag_type);
2793
2794 template <class _ST, class _SA, class _C, class _T>
2795 friend
2796 bool
2797 regex_search(const basic_string<_C, _ST, _SA>& __s,
2798 const basic_regex<_C, _T>& __e,
2799 regex_constants::match_flag_type __flags);
2800
2801 template <class _ST, class _SA, class _A, class _C, class _T>
2802 friend
2803 bool
2804 regex_search(const basic_string<_C, _ST, _SA>& __s,
2805 match_results<typename basic_string<_C, _ST, _SA>::const_iterator, _A>&,
2806 const basic_regex<_C, _T>& __e,
2807 regex_constants::match_flag_type __flags);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002808};
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002809
2810template <class _CharT, class _Traits>
2811basic_regex<_CharT, _Traits>::~basic_regex()
2812{
2813}
2814
2815template <class _CharT, class _Traits>
2816template <class _ForwardIterator>
2817void
2818basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
2819 _ForwardIterator __last)
2820{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002821 {
Howard Hinnantac303862010-07-12 15:51:17 +00002822 unique_ptr<__node> __h(new __end_state<_CharT>);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002823 __start_.reset(new __empty_state<_CharT>(__h.get()));
2824 __h.release();
2825 __end_ = __start_.get();
2826 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002827 switch (__flags_ & 0x1F0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002828 {
2829 case ECMAScript:
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002830 __parse_ecma_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002831 break;
2832 case basic:
2833 __parse_basic_reg_exp(__first, __last);
2834 break;
2835 case extended:
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002836 __parse_extended_reg_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002837 break;
2838 case awk:
2839 break;
2840 case grep:
Howard Hinnant856846b2010-07-27 19:53:10 +00002841 __parse_grep(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002842 break;
2843 case egrep:
Howard Hinnant856846b2010-07-27 19:53:10 +00002844 __parse_egrep(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002845 break;
2846 default:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002847 throw regex_error(regex_constants::__re_err_grammar);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002848 }
2849}
2850
2851template <class _CharT, class _Traits>
2852template <class _ForwardIterator>
2853_ForwardIterator
2854basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
2855 _ForwardIterator __last)
2856{
2857 if (__first != __last)
2858 {
2859 if (*__first == '^')
2860 {
2861 __push_l_anchor();
2862 ++__first;
2863 }
2864 if (__first != __last)
2865 {
2866 __first = __parse_RE_expression(__first, __last);
2867 if (__first != __last)
2868 {
2869 _ForwardIterator __temp = next(__first);
2870 if (__temp == __last && *__first == '$')
2871 {
2872 __push_r_anchor();
2873 ++__first;
2874 }
2875 }
2876 }
2877 if (__first != __last)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002878 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002879 }
2880 return __first;
2881}
2882
2883template <class _CharT, class _Traits>
2884template <class _ForwardIterator>
2885_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002886basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
2887 _ForwardIterator __last)
2888{
Howard Hinnantaa698082010-07-16 19:08:36 +00002889 __owns_one_state<_CharT>* __sa = __end_;
2890 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
2891 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002892 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnantaa698082010-07-16 19:08:36 +00002893 __first = __temp;
2894 while (__first != __last && *__first == '|')
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002895 {
Howard Hinnantaa698082010-07-16 19:08:36 +00002896 __owns_one_state<_CharT>* __sb = __end_;
2897 __temp = __parse_ERE_branch(++__first, __last);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002898 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002899 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnantaa698082010-07-16 19:08:36 +00002900 __push_alternation(__sa, __sb);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002901 __first = __temp;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002902 }
2903 return __first;
2904}
2905
2906template <class _CharT, class _Traits>
2907template <class _ForwardIterator>
2908_ForwardIterator
2909basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
2910 _ForwardIterator __last)
2911{
2912 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
2913 if (__temp == __first)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00002914 throw regex_error(regex_constants::__re_err_empty);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002915 do
2916 {
2917 __first = __temp;
2918 __temp = __parse_ERE_expression(__first, __last);
2919 } while (__temp != __first);
2920 return __first;
2921}
2922
2923template <class _CharT, class _Traits>
2924template <class _ForwardIterator>
2925_ForwardIterator
2926basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
2927 _ForwardIterator __last)
2928{
Howard Hinnantaa698082010-07-16 19:08:36 +00002929 __owns_one_state<_CharT>* __e = __end_;
2930 unsigned __mexp_begin = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002931 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
2932 if (__temp == __first && __temp != __last)
2933 {
2934 switch (*__temp)
2935 {
2936 case '^':
2937 __push_l_anchor();
2938 ++__temp;
2939 break;
2940 case '$':
2941 __push_r_anchor();
2942 ++__temp;
2943 break;
2944 case '(':
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002945 __push_begin_marked_subexpression();
2946 unsigned __temp_count = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002947 ++__open_count_;
2948 __temp = __parse_extended_reg_exp(++__temp, __last);
2949 if (__temp == __last || *__temp != ')')
2950 throw regex_error(regex_constants::error_paren);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002951 __push_end_marked_subexpression(__temp_count);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002952 --__open_count_;
2953 ++__temp;
2954 break;
2955 }
2956 }
2957 if (__temp != __first)
Howard Hinnantaa698082010-07-16 19:08:36 +00002958 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
2959 __marked_count_+1);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002960 __first = __temp;
2961 return __first;
2962}
2963
2964template <class _CharT, class _Traits>
2965template <class _ForwardIterator>
2966_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002967basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
2968 _ForwardIterator __last)
2969{
2970 while (true)
2971 {
2972 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
2973 if (__temp == __first)
2974 break;
2975 __first = __temp;
2976 }
2977 return __first;
2978}
2979
2980template <class _CharT, class _Traits>
2981template <class _ForwardIterator>
2982_ForwardIterator
2983basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
2984 _ForwardIterator __last)
2985{
2986 if (__first != __last)
2987 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002988 __owns_one_state<_CharT>* __e = __end_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002989 unsigned __mexp_begin = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002990 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
2991 if (__temp != __first)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002992 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
2993 __mexp_begin+1, __marked_count_+1);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002994 }
2995 return __first;
2996}
2997
2998template <class _CharT, class _Traits>
2999template <class _ForwardIterator>
3000_ForwardIterator
3001basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
3002 _ForwardIterator __last)
3003{
3004 _ForwardIterator __temp = __first;
3005 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
3006 if (__temp == __first)
3007 {
3008 __temp = __parse_Back_open_paren(__first, __last);
3009 if (__temp != __first)
3010 {
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003011 __push_begin_marked_subexpression();
3012 unsigned __temp_count = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003013 __first = __parse_RE_expression(__temp, __last);
3014 __temp = __parse_Back_close_paren(__first, __last);
3015 if (__temp == __first)
3016 throw regex_error(regex_constants::error_paren);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003017 __push_end_marked_subexpression(__temp_count);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003018 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003019 }
3020 else
3021 __first = __parse_BACKREF(__first, __last);
3022 }
3023 return __first;
3024}
3025
3026template <class _CharT, class _Traits>
3027template <class _ForwardIterator>
3028_ForwardIterator
3029basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
3030 _ForwardIterator __first,
3031 _ForwardIterator __last)
3032{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003033 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003034 if (__temp == __first)
3035 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003036 __temp = __parse_QUOTED_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003037 if (__temp == __first)
3038 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003039 if (__temp != __last && *__temp == '.')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003040 {
3041 __push_match_any();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003042 ++__temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003043 }
3044 else
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003045 __temp = __parse_bracket_expression(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003046 }
3047 }
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003048 __first = __temp;
3049 return __first;
3050}
3051
3052template <class _CharT, class _Traits>
3053template <class _ForwardIterator>
3054_ForwardIterator
3055basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
3056 _ForwardIterator __first,
3057 _ForwardIterator __last)
3058{
3059 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
3060 if (__temp == __first)
3061 {
3062 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
3063 if (__temp == __first)
3064 {
3065 if (__temp != __last && *__temp == '.')
3066 {
3067 __push_match_any();
3068 ++__temp;
3069 }
3070 else
3071 __temp = __parse_bracket_expression(__first, __last);
3072 }
3073 }
3074 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003075 return __first;
3076}
3077
3078template <class _CharT, class _Traits>
3079template <class _ForwardIterator>
3080_ForwardIterator
3081basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
3082 _ForwardIterator __last)
3083{
3084 if (__first != __last)
3085 {
3086 _ForwardIterator __temp = next(__first);
3087 if (__temp != __last)
3088 {
3089 if (*__first == '\\' && *__temp == '(')
3090 __first = ++__temp;
3091 }
3092 }
3093 return __first;
3094}
3095
3096template <class _CharT, class _Traits>
3097template <class _ForwardIterator>
3098_ForwardIterator
3099basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
3100 _ForwardIterator __last)
3101{
3102 if (__first != __last)
3103 {
3104 _ForwardIterator __temp = next(__first);
3105 if (__temp != __last)
3106 {
3107 if (*__first == '\\' && *__temp == ')')
3108 __first = ++__temp;
3109 }
3110 }
3111 return __first;
3112}
3113
3114template <class _CharT, class _Traits>
3115template <class _ForwardIterator>
3116_ForwardIterator
3117basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
3118 _ForwardIterator __last)
3119{
3120 if (__first != __last)
3121 {
3122 _ForwardIterator __temp = next(__first);
3123 if (__temp != __last)
3124 {
3125 if (*__first == '\\' && *__temp == '{')
3126 __first = ++__temp;
3127 }
3128 }
3129 return __first;
3130}
3131
3132template <class _CharT, class _Traits>
3133template <class _ForwardIterator>
3134_ForwardIterator
3135basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
3136 _ForwardIterator __last)
3137{
3138 if (__first != __last)
3139 {
3140 _ForwardIterator __temp = next(__first);
3141 if (__temp != __last)
3142 {
3143 if (*__first == '\\' && *__temp == '}')
3144 __first = ++__temp;
3145 }
3146 }
3147 return __first;
3148}
3149
3150template <class _CharT, class _Traits>
3151template <class _ForwardIterator>
3152_ForwardIterator
3153basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
3154 _ForwardIterator __last)
3155{
3156 if (__first != __last)
3157 {
3158 _ForwardIterator __temp = next(__first);
3159 if (__temp != __last)
3160 {
3161 if (*__first == '\\' && '1' <= *__temp && *__temp <= '9')
3162 {
3163 __push_back_ref(*__temp - '0');
3164 __first = ++__temp;
3165 }
3166 }
3167 }
3168 return __first;
3169}
3170
3171template <class _CharT, class _Traits>
3172template <class _ForwardIterator>
3173_ForwardIterator
3174basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
3175 _ForwardIterator __last)
3176{
3177 if (__first != __last)
3178 {
3179 _ForwardIterator __temp = next(__first);
3180 if (__temp == __last && *__first == '$')
3181 return __first;
3182 // Not called inside a bracket
3183 if (*__first == '.' || *__first == '\\' || *__first == '[')
3184 return __first;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003185 __push_char(*__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003186 ++__first;
3187 }
3188 return __first;
3189}
3190
3191template <class _CharT, class _Traits>
3192template <class _ForwardIterator>
3193_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003194basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
3195 _ForwardIterator __last)
3196{
3197 if (__first != __last)
3198 {
3199 switch (*__first)
3200 {
3201 case '^':
3202 case '.':
3203 case '[':
3204 case '$':
3205 case '(':
3206 case '|':
3207 case '*':
3208 case '+':
3209 case '?':
3210 case '{':
3211 case '\\':
3212 break;
3213 case ')':
3214 if (__open_count_ == 0)
3215 {
3216 __push_char(*__first);
3217 ++__first;
3218 }
3219 break;
3220 default:
3221 __push_char(*__first);
3222 ++__first;
3223 break;
3224 }
3225 }
3226 return __first;
3227}
3228
3229template <class _CharT, class _Traits>
3230template <class _ForwardIterator>
3231_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003232basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
3233 _ForwardIterator __last)
3234{
3235 if (__first != __last)
3236 {
3237 _ForwardIterator __temp = next(__first);
3238 if (__temp != __last)
3239 {
3240 if (*__first == '\\')
3241 {
3242 switch (*__temp)
3243 {
3244 case '^':
3245 case '.':
3246 case '*':
3247 case '[':
3248 case '$':
3249 case '\\':
Howard Hinnant0de86b62010-06-25 20:56:08 +00003250 __push_char(*__temp);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003251 __first = ++__temp;
3252 break;
3253 }
3254 }
3255 }
3256 }
3257 return __first;
3258}
3259
3260template <class _CharT, class _Traits>
3261template <class _ForwardIterator>
3262_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003263basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
3264 _ForwardIterator __last)
3265{
3266 if (__first != __last)
3267 {
3268 _ForwardIterator __temp = next(__first);
3269 if (__temp != __last)
3270 {
3271 if (*__first == '\\')
3272 {
3273 switch (*__temp)
3274 {
3275 case '^':
3276 case '.':
3277 case '*':
3278 case '[':
3279 case '$':
3280 case '\\':
3281 case '(':
3282 case ')':
3283 case '|':
3284 case '+':
3285 case '?':
3286 case '{':
3287 __push_char(*__temp);
3288 __first = ++__temp;
3289 break;
3290 }
3291 }
3292 }
3293 }
3294 return __first;
3295}
3296
3297template <class _CharT, class _Traits>
3298template <class _ForwardIterator>
3299_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003300basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003301 _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003302 __owns_one_state<_CharT>* __s,
3303 unsigned __mexp_begin,
3304 unsigned __mexp_end)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003305{
3306 if (__first != __last)
3307 {
Howard Hinnant0de86b62010-06-25 20:56:08 +00003308 if (*__first == '*')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003309 {
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003310 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003311 ++__first;
3312 }
3313 else
3314 {
3315 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3316 if (__temp != __first)
3317 {
3318 int __min = 0;
3319 __first = __temp;
3320 __temp = __parse_DUP_COUNT(__first, __last, __min);
3321 if (__temp == __first)
3322 throw regex_error(regex_constants::error_badbrace);
3323 __first = __temp;
3324 if (__first == __last)
3325 throw regex_error(regex_constants::error_brace);
3326 if (*__first != ',')
3327 {
3328 __temp = __parse_Back_close_brace(__first, __last);
3329 if (__temp == __first)
3330 throw regex_error(regex_constants::error_brace);
Howard Hinnantcba352d2010-07-12 18:16:05 +00003331 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
3332 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003333 __first = __temp;
3334 }
3335 else
3336 {
3337 ++__first; // consume ','
3338 int __max = -1;
3339 __first = __parse_DUP_COUNT(__first, __last, __max);
3340 __temp = __parse_Back_close_brace(__first, __last);
3341 if (__temp == __first)
3342 throw regex_error(regex_constants::error_brace);
3343 if (__max == -1)
Howard Hinnantaa698082010-07-16 19:08:36 +00003344 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003345 else
3346 {
3347 if (__max < __min)
3348 throw regex_error(regex_constants::error_badbrace);
Howard Hinnantcba352d2010-07-12 18:16:05 +00003349 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
3350 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003351 }
3352 __first = __temp;
3353 }
3354 }
3355 }
3356 }
3357 return __first;
3358}
3359
Howard Hinnant0de86b62010-06-25 20:56:08 +00003360template <class _CharT, class _Traits>
3361template <class _ForwardIterator>
3362_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003363basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantaa698082010-07-16 19:08:36 +00003364 _ForwardIterator __last,
3365 __owns_one_state<_CharT>* __s,
3366 unsigned __mexp_begin,
3367 unsigned __mexp_end)
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003368{
3369 if (__first != __last)
3370 {
3371 switch (*__first)
3372 {
3373 case '*':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003374 ++__first;
Howard Hinnant17615b02010-07-27 01:25:38 +00003375 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3376 {
3377 ++__first;
3378 __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3379 }
3380 else
3381 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003382 break;
3383 case '+':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003384 ++__first;
Howard Hinnant17615b02010-07-27 01:25:38 +00003385 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3386 {
3387 ++__first;
3388 __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3389 }
3390 else
3391 __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003392 break;
3393 case '?':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003394 ++__first;
Howard Hinnant17615b02010-07-27 01:25:38 +00003395 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3396 {
3397 ++__first;
3398 __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3399 }
3400 else
3401 __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003402 break;
3403 case '{':
3404 {
3405 int __min;
Howard Hinnantaa698082010-07-16 19:08:36 +00003406 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003407 if (__temp == __first)
3408 throw regex_error(regex_constants::error_badbrace);
3409 __first = __temp;
3410 if (__first == __last)
3411 throw regex_error(regex_constants::error_brace);
3412 switch (*__first)
3413 {
3414 case '}':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003415 ++__first;
Howard Hinnant17615b02010-07-27 01:25:38 +00003416 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3417 {
3418 ++__first;
3419 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3420 }
3421 else
3422 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003423 break;
3424 case ',':
3425 if (++__first == __last)
3426 throw regex_error(regex_constants::error_badbrace);
3427 if (*__first == '}')
3428 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003429 ++__first;
Howard Hinnant17615b02010-07-27 01:25:38 +00003430 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3431 {
3432 ++__first;
3433 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3434 }
3435 else
3436 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003437 }
3438 else
3439 {
Howard Hinnantaa698082010-07-16 19:08:36 +00003440 int __max = -1;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003441 __temp = __parse_DUP_COUNT(__first, __last, __max);
3442 if (__temp == __first)
3443 throw regex_error(regex_constants::error_brace);
3444 __first = __temp;
3445 if (__first == __last || *__first != '}')
3446 throw regex_error(regex_constants::error_brace);
3447 ++__first;
3448 if (__max < __min)
3449 throw regex_error(regex_constants::error_badbrace);
Howard Hinnant17615b02010-07-27 01:25:38 +00003450 if ((__flags_ & ECMAScript) && __first != __last && *__first == '?')
3451 {
3452 ++__first;
3453 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3454 }
3455 else
3456 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003457 }
Howard Hinnantaa698082010-07-16 19:08:36 +00003458 break;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003459 default:
3460 throw regex_error(regex_constants::error_badbrace);
3461 }
3462 }
3463 break;
3464 }
3465 }
3466 return __first;
3467}
3468
3469template <class _CharT, class _Traits>
3470template <class _ForwardIterator>
3471_ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00003472basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
3473 _ForwardIterator __last)
3474{
3475 if (__first != __last && *__first == '[')
3476 {
3477 if (++__first == __last)
3478 throw regex_error(regex_constants::error_brack);
Howard Hinnant173968a2010-07-13 21:48:06 +00003479 bool __negate = false;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003480 if (*__first == '^')
3481 {
3482 ++__first;
Howard Hinnant173968a2010-07-13 21:48:06 +00003483 __negate = true;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003484 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003485 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3486 // __ml owned by *this
Howard Hinnant0de86b62010-06-25 20:56:08 +00003487 if (__first == __last)
3488 throw regex_error(regex_constants::error_brack);
3489 if (*__first == ']')
3490 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003491 __ml->__add_char(']');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003492 ++__first;
3493 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003494 __first = __parse_follow_list(__first, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003495 if (__first == __last)
3496 throw regex_error(regex_constants::error_brack);
3497 if (*__first == '-')
3498 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003499 __ml->__add_char('-');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003500 ++__first;
3501 }
3502 if (__first == __last || *__first != ']')
3503 throw regex_error(regex_constants::error_brack);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003504 ++__first;
3505 }
3506 return __first;
3507}
3508
3509template <class _CharT, class _Traits>
3510template <class _ForwardIterator>
3511_ForwardIterator
3512basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003513 _ForwardIterator __last,
3514 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003515{
3516 if (__first != __last)
3517 {
3518 while (true)
3519 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003520 _ForwardIterator __temp = __parse_expression_term(__first, __last,
3521 __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003522 if (__temp == __first)
3523 break;
3524 __first = __temp;
3525 }
3526 }
3527 return __first;
3528}
3529
3530template <class _CharT, class _Traits>
3531template <class _ForwardIterator>
3532_ForwardIterator
3533basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003534 _ForwardIterator __last,
3535 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003536{
3537 if (__first != __last && *__first != ']')
3538 {
3539 bool __parsed_one = false;
3540 _ForwardIterator __temp = next(__first);
Howard Hinnant173968a2010-07-13 21:48:06 +00003541 basic_string<_CharT> __start_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003542 if (__temp != __last && *__first == '[')
3543 {
3544 if (*__temp == '=')
Howard Hinnant173968a2010-07-13 21:48:06 +00003545 return __parse_equivalence_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003546 else if (*__temp == ':')
Howard Hinnant173968a2010-07-13 21:48:06 +00003547 return __parse_character_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003548 else if (*__temp == '.')
3549 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003550 __first = __parse_collating_symbol(++__temp, __last, __start_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003551 __parsed_one = true;
3552 }
3553 }
3554 if (!__parsed_one)
3555 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003556 __start_range = *__first;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003557 ++__first;
3558 }
3559 if (__first != __last && *__first != ']')
3560 {
3561 __temp = next(__first);
3562 if (__temp != __last && *__first == '-' && *__temp != ']')
3563 {
3564 // parse a range
Howard Hinnant173968a2010-07-13 21:48:06 +00003565 basic_string<_CharT> __end_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003566 __first = __temp;
3567 ++__temp;
3568 if (__temp != __last && *__first == '[' && *__temp == '.')
Howard Hinnant173968a2010-07-13 21:48:06 +00003569 __first = __parse_collating_symbol(++__temp, __last, __end_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003570 else
3571 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003572 __end_range = *__first;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003573 ++__first;
3574 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003575 __ml->__add_range(_STD::move(__start_range), _STD::move(__end_range));
Howard Hinnant0de86b62010-06-25 20:56:08 +00003576 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003577 else
3578 {
3579 if (__start_range.size() == 1)
3580 __ml->__add_char(__start_range[0]);
3581 else
3582 __ml->__add_digraph(__start_range[0], __start_range[1]);
3583 }
3584 }
3585 else
3586 {
3587 if (__start_range.size() == 1)
3588 __ml->__add_char(__start_range[0]);
3589 else
3590 __ml->__add_digraph(__start_range[0], __start_range[1]);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003591 }
3592 }
3593 return __first;
3594}
3595
3596template <class _CharT, class _Traits>
3597template <class _ForwardIterator>
3598_ForwardIterator
3599basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003600 _ForwardIterator __last,
3601 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003602{
3603 // Found [=
3604 // This means =] must exist
3605 value_type _Equal_close[2] = {'=', ']'};
3606 _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close,
3607 _Equal_close+2);
3608 if (__temp == __last)
3609 throw regex_error(regex_constants::error_brack);
3610 // [__first, __temp) contains all text in [= ... =]
3611 typedef typename _Traits::string_type string_type;
3612 string_type __collate_name =
3613 __traits_.lookup_collatename(__first, __temp);
3614 if (__collate_name.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003615 throw regex_error(regex_constants::error_collate);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003616 string_type __equiv_name =
3617 __traits_.transform_primary(__collate_name.begin(),
3618 __collate_name.end());
3619 if (!__equiv_name.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003620 __ml->__add_equivalence(__equiv_name);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003621 else
Howard Hinnant173968a2010-07-13 21:48:06 +00003622 {
3623 switch (__collate_name.size())
3624 {
3625 case 1:
3626 __ml->__add_char(__collate_name[0]);
3627 break;
3628 case 2:
3629 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
3630 break;
3631 default:
3632 throw regex_error(regex_constants::error_collate);
3633 }
3634 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003635 __first = next(__temp, 2);
3636 return __first;
3637}
3638
3639template <class _CharT, class _Traits>
3640template <class _ForwardIterator>
3641_ForwardIterator
3642basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003643 _ForwardIterator __last,
3644 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003645{
3646 // Found [:
3647 // This means :] must exist
3648 value_type _Colon_close[2] = {':', ']'};
3649 _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close,
3650 _Colon_close+2);
3651 if (__temp == __last)
3652 throw regex_error(regex_constants::error_brack);
3653 // [__first, __temp) contains all text in [: ... :]
3654 typedef typename _Traits::char_class_type char_class_type;
3655 char_class_type __class_type =
3656 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
3657 if (__class_type == 0)
3658 throw regex_error(regex_constants::error_brack);
Howard Hinnant173968a2010-07-13 21:48:06 +00003659 __ml->__add_class(__class_type);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003660 __first = next(__temp, 2);
3661 return __first;
3662}
3663
3664template <class _CharT, class _Traits>
3665template <class _ForwardIterator>
3666_ForwardIterator
3667basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003668 _ForwardIterator __last,
3669 basic_string<_CharT>& __col_sym)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003670{
3671 // Found [.
3672 // This means .] must exist
3673 value_type _Dot_close[2] = {'.', ']'};
3674 _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close,
3675 _Dot_close+2);
3676 if (__temp == __last)
3677 throw regex_error(regex_constants::error_brack);
3678 // [__first, __temp) contains all text in [. ... .]
3679 typedef typename _Traits::string_type string_type;
Howard Hinnant173968a2010-07-13 21:48:06 +00003680 __col_sym = __traits_.lookup_collatename(__first, __temp);
3681 switch (__col_sym.size())
3682 {
3683 case 1:
3684 case 2:
3685 break;
3686 default:
3687 throw regex_error(regex_constants::error_collate);
3688 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003689 __first = next(__temp, 2);
3690 return __first;
3691}
3692
3693template <class _CharT, class _Traits>
3694template <class _ForwardIterator>
3695_ForwardIterator
3696basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
3697 _ForwardIterator __last,
3698 int& __c)
3699{
3700 if (__first != __last && '0' <= *__first && *__first <= '9')
3701 {
3702 __c = *__first - '0';
3703 for (++__first; __first != __last && '0' <= *__first && *__first <= '9';
3704 ++__first)
3705 {
3706 __c *= 10;
3707 __c += *__first - '0';
3708 }
3709 }
3710 return __first;
3711}
3712
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003713template <class _CharT, class _Traits>
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003714template <class _ForwardIterator>
3715_ForwardIterator
3716basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
3717 _ForwardIterator __last)
3718{
3719 __owns_one_state<_CharT>* __sa = __end_;
3720 _ForwardIterator __temp = __parse_alternative(__first, __last);
3721 if (__temp == __first)
3722 __push_empty();
3723 __first = __temp;
3724 while (__first != __last && *__first == '|')
3725 {
3726 __owns_one_state<_CharT>* __sb = __end_;
3727 __temp = __parse_alternative(++__first, __last);
3728 if (__temp == __first)
3729 __push_empty();
3730 __push_alternation(__sa, __sb);
3731 __first = __temp;
3732 }
3733 return __first;
3734}
3735
3736template <class _CharT, class _Traits>
3737template <class _ForwardIterator>
3738_ForwardIterator
3739basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
3740 _ForwardIterator __last)
3741{
3742 while (true)
3743 {
3744 _ForwardIterator __temp = __parse_term(__first, __last);
3745 if (__temp == __first)
3746 break;
3747 __first = __temp;
3748 }
3749 return __first;
3750}
3751
3752template <class _CharT, class _Traits>
3753template <class _ForwardIterator>
3754_ForwardIterator
3755basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
3756 _ForwardIterator __last)
3757{
3758 _ForwardIterator __temp = __parse_assertion(__first, __last);
3759 if (__temp == __first)
3760 {
Howard Hinnant17615b02010-07-27 01:25:38 +00003761 __owns_one_state<_CharT>* __e = __end_;
3762 unsigned __mexp_begin = __marked_count_;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003763 __temp = __parse_atom(__first, __last);
3764 if (__temp != __first)
Howard Hinnant17615b02010-07-27 01:25:38 +00003765 __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
3766 __mexp_begin+1, __marked_count_+1);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003767 }
Howard Hinnant17615b02010-07-27 01:25:38 +00003768 else
3769 __first = __temp;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003770 return __first;
3771}
3772
3773template <class _CharT, class _Traits>
3774template <class _ForwardIterator>
3775_ForwardIterator
3776basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
3777 _ForwardIterator __last)
3778{
3779 if (__first != __last)
3780 {
3781 switch (*__first)
3782 {
3783 case '^':
3784 __push_l_anchor();
3785 ++__first;
3786 break;
3787 case '$':
3788 __push_r_anchor();
3789 ++__first;
3790 break;
3791 case '\\':
3792 {
3793 _ForwardIterator __temp = _STD::next(__first);
3794 if (__temp != __last)
3795 {
3796 if (*__temp == 'b')
3797 {
Howard Hinnant17615b02010-07-27 01:25:38 +00003798 __push_word_boundary(false);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003799 __first = ++__temp;
3800 }
3801 else if (*__temp == 'B')
3802 {
Howard Hinnant17615b02010-07-27 01:25:38 +00003803 __push_word_boundary(true);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003804 __first = ++__temp;
3805 }
3806 }
3807 }
3808 break;
3809 case '(':
3810 {
3811 _ForwardIterator __temp = _STD::next(__first);
3812 if (__temp != __last && *__temp == '?')
3813 {
3814 if (++__temp != __last)
3815 {
3816 switch (*__temp)
3817 {
3818 case '=':
Howard Hinnant17615b02010-07-27 01:25:38 +00003819 __push_lookahead(false);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003820 __temp = __parse_ecma_exp(++__temp, __last);
3821 if (__temp == __last || *__temp != ')')
3822 throw regex_error(regex_constants::error_paren);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003823 __first = ++__temp;
3824 break;
3825 case '!':
Howard Hinnant17615b02010-07-27 01:25:38 +00003826 __push_lookahead(true);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003827 __temp = __parse_ecma_exp(++__temp, __last);
3828 if (__temp == __last || *__temp != ')')
3829 throw regex_error(regex_constants::error_paren);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00003830 __first = ++__temp;
3831 break;
3832 }
3833 }
3834 }
3835 }
3836 break;
3837 }
3838 }
3839 return __first;
3840}
3841
3842template <class _CharT, class _Traits>
3843template <class _ForwardIterator>
3844_ForwardIterator
3845basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
3846 _ForwardIterator __last)
3847{
Howard Hinnant17615b02010-07-27 01:25:38 +00003848 if (__first != __last)
3849 {
3850 switch (*__first)
3851 {
3852 case '.':
3853 __push_match_any_but_newline();
3854 ++__first;
3855 break;
3856 case '\\':
3857 __first = __parse_atom_escape(__first, __last);
3858 break;
3859 case '[':
3860 __first = __parse_bracket_expression(__first, __last);
3861 break;
3862 case '(':
3863 {
3864 if (++__first == __last)
3865 throw regex_error(regex_constants::error_paren);
3866 _ForwardIterator __temp = _STD::next(__first);
3867 if (__temp != __last && *__first == '?' && *__temp == ':')
3868 {
3869 ++__open_count_;
3870 __first = __parse_ecma_exp(++__temp, __last);
3871 if (__first == __last || *__first != ')')
3872 throw regex_error(regex_constants::error_paren);
3873 --__open_count_;
3874 ++__first;
3875 }
3876 else
3877 {
3878 __push_begin_marked_subexpression();
3879 unsigned __temp_count = __marked_count_;
3880 ++__open_count_;
3881 __first = __parse_ecma_exp(__first, __last);
3882 if (__first == __last || *__first != ')')
3883 throw regex_error(regex_constants::error_paren);
3884 __push_end_marked_subexpression(__temp_count);
3885 --__open_count_;
3886 ++__first;
3887 }
3888 }
3889 break;
3890 default:
3891 __first = __parse_pattern_character(__first, __last);
3892 break;
3893 }
3894 }
3895 return __first;
3896}
3897
3898template <class _CharT, class _Traits>
3899template <class _ForwardIterator>
3900_ForwardIterator
3901basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
3902 _ForwardIterator __last)
3903{
3904 if (__first != __last && *__first == '\\')
3905 {
3906 _ForwardIterator __t1 = _STD::next(__first);
3907 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
3908 if (__t2 != __t1)
3909 __first = __t2;
3910 else
3911 {
3912 __t2 = __parse_character_class_escape(__t1, __last);
3913 if (__t2 != __t1)
3914 __first = __t2;
3915 else
3916 {
3917 __t2 = __parse_character_escape(__t1, __last);
3918 if (__t2 != __t1)
3919 __first = __t2;
3920 }
3921 }
3922 }
3923 return __first;
3924}
3925
3926template <class _CharT, class _Traits>
3927template <class _ForwardIterator>
3928_ForwardIterator
3929basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
3930 _ForwardIterator __last)
3931{
3932 if (__first != __last)
3933 {
3934 if (*__first == '0')
3935 {
3936 __push_char(_CharT());
3937 ++__first;
3938 }
3939 else if ('1' <= *__first && *__first <= '9')
3940 {
3941 unsigned __v = *__first - '0';
3942 for (++__first; '0' <= *__first && *__first <= '9'; ++__first)
3943 __v = 10 * __v + *__first - '0';
3944 if (__v > mark_count())
3945 throw regex_error(regex_constants::error_backref);
3946 __push_back_ref(__v);
3947 }
3948 }
3949 return __first;
3950}
3951
3952template <class _CharT, class _Traits>
3953template <class _ForwardIterator>
3954_ForwardIterator
3955basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
3956 _ForwardIterator __last)
3957{
3958 if (__first != __last)
3959 {
3960 __bracket_expression<_CharT, _Traits>* __ml;
3961 switch (*__first)
3962 {
3963 case 'd':
3964 __ml = __start_matching_list(false);
3965 __ml->__add_class(ctype_base::digit);
3966 ++__first;
3967 break;
3968 case 'D':
3969 __ml = __start_matching_list(true);
3970 __ml->__add_class(ctype_base::digit);
3971 ++__first;
3972 break;
3973 case 's':
3974 __ml = __start_matching_list(false);
3975 __ml->__add_class(ctype_base::space);
3976 ++__first;
3977 break;
3978 case 'S':
3979 __ml = __start_matching_list(true);
3980 __ml->__add_class(ctype_base::space);
3981 ++__first;
3982 break;
3983 case 'w':
3984 __ml = __start_matching_list(false);
3985 __ml->__add_class(ctype_base::alnum);
3986 __ml->__add_char('_');
3987 ++__first;
3988 break;
3989 case 'W':
3990 __ml = __start_matching_list(true);
3991 __ml->__add_class(ctype_base::alnum);
3992 __ml->__add_char('_');
3993 ++__first;
3994 break;
3995 }
3996 }
3997 return __first;
3998}
3999
4000template <class _CharT, class _Traits>
4001template <class _ForwardIterator>
4002_ForwardIterator
4003basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
4004 _ForwardIterator __last)
4005{
4006 if (__first != __last)
4007 {
4008 _ForwardIterator __t;
4009 unsigned __sum = 0;
4010 int __hd;
4011 switch (*__first)
4012 {
4013 case 'f':
4014 __push_char(_CharT(0xC));
4015 ++__first;
4016 break;
4017 case 'n':
4018 __push_char(_CharT(0xA));
4019 ++__first;
4020 break;
4021 case 'r':
4022 __push_char(_CharT(0xD));
4023 ++__first;
4024 break;
4025 case 't':
4026 __push_char(_CharT(0x9));
4027 ++__first;
4028 break;
4029 case 'v':
4030 __push_char(_CharT(0xB));
4031 ++__first;
4032 break;
4033 case 'c':
4034 if ((__t = _STD::next(__first)) != __last)
4035 {
4036 if ('A' <= *__t <= 'Z' || 'a' <= *__t <= 'z')
4037 {
4038 __push_char(_CharT(*__t % 32));
4039 __first = ++__t;
4040 }
4041 }
4042 break;
4043 case 'u':
4044 if (++__first == __last)
4045 throw regex_error(regex_constants::error_escape);
4046 __hd = __traits_.value(*__first, 16);
4047 if (__hd == -1)
4048 throw regex_error(regex_constants::error_escape);
4049 __sum = 16 * __sum + __hd;
4050 if (++__first == __last)
4051 throw regex_error(regex_constants::error_escape);
4052 __hd = __traits_.value(*__first, 16);
4053 if (__hd == -1)
4054 throw regex_error(regex_constants::error_escape);
4055 __sum = 16 * __sum + __hd;
4056 // drop through
4057 case 'x':
4058 if (++__first == __last)
4059 throw regex_error(regex_constants::error_escape);
4060 __hd = __traits_.value(*__first, 16);
4061 if (__hd == -1)
4062 throw regex_error(regex_constants::error_escape);
4063 __sum = 16 * __sum + __hd;
4064 if (++__first == __last)
4065 throw regex_error(regex_constants::error_escape);
4066 __hd = __traits_.value(*__first, 16);
4067 if (__hd == -1)
4068 throw regex_error(regex_constants::error_escape);
4069 __sum = 16 * __sum + __hd;
4070 __push_char(_CharT(__sum));
4071 ++__first;
4072 break;
4073 default:
4074 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
4075 {
4076 __push_char(*__first);
4077 ++__first;
4078 }
4079 break;
4080 }
4081 }
4082 return __first;
4083}
4084
4085template <class _CharT, class _Traits>
4086template <class _ForwardIterator>
4087_ForwardIterator
4088basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
4089 _ForwardIterator __last)
4090{
4091 if (__first != __last)
4092 {
4093 switch (*__first)
4094 {
4095 case '^':
4096 case '$':
4097 case '\\':
4098 case '.':
4099 case '*':
4100 case '+':
4101 case '?':
4102 case '(':
4103 case ')':
4104 case '[':
4105 case ']':
4106 case '{':
4107 case '}':
4108 case '|':
4109 break;
4110 default:
4111 __push_char(*__first);
4112 ++__first;
4113 break;
4114 }
4115 }
4116 return __first;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004117}
4118
4119template <class _CharT, class _Traits>
Howard Hinnant856846b2010-07-27 19:53:10 +00004120template <class _ForwardIterator>
4121_ForwardIterator
4122basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
4123 _ForwardIterator __last)
4124{
4125 __owns_one_state<_CharT>* __sa = __end_;
4126 _ForwardIterator __t1 = _STD::find(__first, __last, _CharT('\n'));
4127 if (__t1 != __first)
4128 __parse_basic_reg_exp(__first, __t1);
4129 else
4130 __push_empty();
4131 __first = __t1;
4132 if (__first != __last)
4133 ++__first;
4134 while (__first != __last)
4135 {
4136 __t1 = _STD::find(__first, __last, _CharT('\n'));
4137 __owns_one_state<_CharT>* __sb = __end_;
4138 if (__t1 != __first)
4139 __parse_basic_reg_exp(__first, __t1);
4140 else
4141 __push_empty();
4142 __push_alternation(__sa, __sb);
4143 __first = __t1;
4144 if (__first != __last)
4145 ++__first;
4146 }
4147 return __first;
4148}
4149
4150template <class _CharT, class _Traits>
4151template <class _ForwardIterator>
4152_ForwardIterator
4153basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
4154 _ForwardIterator __last)
4155{
4156 __owns_one_state<_CharT>* __sa = __end_;
4157 _ForwardIterator __t1 = _STD::find(__first, __last, _CharT('\n'));
4158 if (__t1 != __first)
4159 __parse_extended_reg_exp(__first, __t1);
4160 else
4161 __push_empty();
4162 __first = __t1;
4163 if (__first != __last)
4164 ++__first;
4165 while (__first != __last)
4166 {
4167 __t1 = _STD::find(__first, __last, _CharT('\n'));
4168 __owns_one_state<_CharT>* __sb = __end_;
4169 if (__t1 != __first)
4170 __parse_extended_reg_exp(__first, __t1);
4171 else
4172 __push_empty();
4173 __push_alternation(__sa, __sb);
4174 __first = __t1;
4175 if (__first != __last)
4176 ++__first;
4177 }
4178 return __first;
4179}
4180
4181template <class _CharT, class _Traits>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004182void
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004183basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
4184 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
4185 bool __greedy)
4186{
4187 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4188 __end_->first() = nullptr;
Howard Hinnantac303862010-07-12 15:51:17 +00004189 unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
4190 __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
4191 __min, __max));
4192 __s->first() = nullptr;
4193 __e1.release();
4194 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004195 __end_ = __e2->second();
Howard Hinnantac303862010-07-12 15:51:17 +00004196 __s->first() = __e2.release();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004197 ++__loop_count_;
4198}
4199
4200template <class _CharT, class _Traits>
4201void
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004202basic_regex<_CharT, _Traits>::__push_char(value_type __c)
4203{
Howard Hinnant173968a2010-07-13 21:48:06 +00004204 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004205 __end_->first() = new __match_char_icase<_CharT, _Traits>
4206 (__traits_, __c, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004207 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004208 __end_->first() = new __match_char_collate<_CharT, _Traits>
4209 (__traits_, __c, __end_->first());
4210 else
4211 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
Howard Hinnante77aa5e2010-07-08 17:43:58 +00004212 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004213}
4214
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004215template <class _CharT, class _Traits>
4216void
4217basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
4218{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004219 if (!(__flags_ & nosubs))
4220 {
4221 __end_->first() =
4222 new __begin_marked_subexpression<_CharT>(++__marked_count_,
4223 __end_->first());
4224 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4225 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004226}
4227
4228template <class _CharT, class _Traits>
4229void
4230basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
4231{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004232 if (!(__flags_ & nosubs))
4233 {
4234 __end_->first() =
4235 new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4236 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4237 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004238}
4239
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004240template <class _CharT, class _Traits>
4241void
4242basic_regex<_CharT, _Traits>::__push_r_anchor()
4243{
4244 __end_->first() = new __r_anchor<_CharT>(__end_->first());
4245 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4246}
4247
Howard Hinnantac303862010-07-12 15:51:17 +00004248template <class _CharT, class _Traits>
4249void
4250basic_regex<_CharT, _Traits>::__push_match_any()
4251{
4252 __end_->first() = new __match_any<_CharT>(__end_->first());
4253 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4254}
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004255
Howard Hinnantcba352d2010-07-12 18:16:05 +00004256template <class _CharT, class _Traits>
4257void
Howard Hinnant17615b02010-07-27 01:25:38 +00004258basic_regex<_CharT, _Traits>::__push_match_any_but_newline()
4259{
4260 __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
4261 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4262}
4263
4264template <class _CharT, class _Traits>
4265void
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004266basic_regex<_CharT, _Traits>::__push_empty()
4267{
4268 __end_->first() = new __empty_state<_CharT>(__end_->first());
4269 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4270}
4271
4272template <class _CharT, class _Traits>
4273void
Howard Hinnant17615b02010-07-27 01:25:38 +00004274basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
4275{
4276 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
4277 __end_->first());
4278 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4279}
4280
4281template <class _CharT, class _Traits>
4282void
Howard Hinnantcba352d2010-07-12 18:16:05 +00004283basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
4284{
Howard Hinnant173968a2010-07-13 21:48:06 +00004285 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004286 __end_->first() = new __back_ref_icase<_CharT, _Traits>
4287 (__traits_, __i, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004288 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004289 __end_->first() = new __back_ref_collate<_CharT, _Traits>
4290 (__traits_, __i, __end_->first());
4291 else
4292 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
Howard Hinnantcba352d2010-07-12 18:16:05 +00004293 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4294}
4295
Howard Hinnant173968a2010-07-13 21:48:06 +00004296template <class _CharT, class _Traits>
Howard Hinnantaa698082010-07-16 19:08:36 +00004297void
4298basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
4299 __owns_one_state<_CharT>* __ea)
4300{
4301 __sa->first() = new __alternate<_CharT>(
4302 static_cast<__owns_one_state<_CharT>*>(__sa->first()),
4303 static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4304 __ea->first() = nullptr;
4305 __ea->first() = new __empty_state<_CharT>(__end_->first());
4306 __end_->first() = nullptr;
4307 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4308 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4309}
4310
4311template <class _CharT, class _Traits>
Howard Hinnant173968a2010-07-13 21:48:06 +00004312__bracket_expression<_CharT, _Traits>*
4313basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
4314{
4315 __bracket_expression<_CharT, _Traits>* __r =
4316 new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
4317 __negate, __flags_ & icase,
4318 __flags_ & collate);
4319 __end_->first() = __r;
4320 __end_ = __r;
4321 return __r;
4322}
4323
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00004324typedef basic_regex<char> regex;
4325typedef basic_regex<wchar_t> wregex;
4326
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004327// sub_match
4328
4329template <class _BidirectionalIterator>
4330class sub_match
4331 : public pair<_BidirectionalIterator, _BidirectionalIterator>
4332{
4333public:
4334 typedef _BidirectionalIterator iterator;
4335 typedef typename iterator_traits<iterator>::value_type value_type;
4336 typedef typename iterator_traits<iterator>::difference_type difference_type;
4337 typedef basic_string<value_type> string_type;
4338
4339 bool matched;
4340
4341 difference_type length() const
4342 {return matched ? _STD::distance(this->first, this->second) : 0;}
4343 string_type str() const
4344 {return matched ? string_type(this->first, this->second) : string_type();}
4345 operator string_type() const
4346 {return str();}
4347
4348 int compare(const sub_match& __s) const
4349 {return str().compare(__s.str());}
4350 int compare(const string_type& __s) const
4351 {return str().compare(__s);}
4352 int compare(const value_type* __s) const
4353 {return str().compare(__s);}
4354};
4355
4356typedef sub_match<const char*> csub_match;
4357typedef sub_match<const wchar_t*> wcsub_match;
4358typedef sub_match<string::const_iterator> ssub_match;
4359typedef sub_match<wstring::const_iterator> wssub_match;
4360
4361template <class _BiIter>
4362inline _LIBCPP_INLINE_VISIBILITY
4363bool
4364operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4365{
4366 return __x.compare(__y) == 0;
4367}
4368
4369template <class _BiIter>
4370inline _LIBCPP_INLINE_VISIBILITY
4371bool
4372operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4373{
4374 return !(__x == __y);
4375}
4376
4377template <class _BiIter>
4378inline _LIBCPP_INLINE_VISIBILITY
4379bool
4380operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4381{
4382 return __x.compare(__y) < 0;
4383}
4384
4385template <class _BiIter>
4386inline _LIBCPP_INLINE_VISIBILITY
4387bool
4388operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4389{
4390 return !(__y < __x);
4391}
4392
4393template <class _BiIter>
4394inline _LIBCPP_INLINE_VISIBILITY
4395bool
4396operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4397{
4398 return !(__x < __y);
4399}
4400
4401template <class _BiIter>
4402inline _LIBCPP_INLINE_VISIBILITY
4403bool
4404operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4405{
4406 return __y < __x;
4407}
4408
4409template <class _BiIter, class _ST, class _SA>
4410inline _LIBCPP_INLINE_VISIBILITY
4411bool
4412operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4413 const sub_match<_BiIter>& __y)
4414{
4415 return __y.compare(__x.c_str()) == 0;
4416}
4417
4418template <class _BiIter, class _ST, class _SA>
4419inline _LIBCPP_INLINE_VISIBILITY
4420bool
4421operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4422 const sub_match<_BiIter>& __y)
4423{
4424 return !(__x == __y);
4425}
4426
4427template <class _BiIter, class _ST, class _SA>
4428inline _LIBCPP_INLINE_VISIBILITY
4429bool
4430operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4431 const sub_match<_BiIter>& __y)
4432{
4433 return __y.compare(__x.c_str()) > 0;
4434}
4435
4436template <class _BiIter, class _ST, class _SA>
4437inline _LIBCPP_INLINE_VISIBILITY
4438bool
4439operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4440 const sub_match<_BiIter>& __y)
4441{
4442 return __y < __x;
4443}
4444
4445template <class _BiIter, class _ST, class _SA>
4446inline _LIBCPP_INLINE_VISIBILITY
4447bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4448 const sub_match<_BiIter>& __y)
4449{
4450 return !(__x < __y);
4451}
4452
4453template <class _BiIter, class _ST, class _SA>
4454inline _LIBCPP_INLINE_VISIBILITY
4455bool
4456operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4457 const sub_match<_BiIter>& __y)
4458{
4459 return !(__y < __x);
4460}
4461
4462template <class _BiIter, class _ST, class _SA>
4463inline _LIBCPP_INLINE_VISIBILITY
4464bool
4465operator==(const sub_match<_BiIter>& __x,
4466 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4467{
4468 return __x.compare(__y.c_str()) == 0;
4469}
4470
4471template <class _BiIter, class _ST, class _SA>
4472inline _LIBCPP_INLINE_VISIBILITY
4473bool
4474operator!=(const sub_match<_BiIter>& __x,
4475 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4476{
4477 return !(__x == __y);
4478}
4479
4480template <class _BiIter, class _ST, class _SA>
4481inline _LIBCPP_INLINE_VISIBILITY
4482bool
4483operator<(const sub_match<_BiIter>& __x,
4484 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4485{
4486 return __x.compare(__y.c_str()) < 0;
4487}
4488
4489template <class _BiIter, class _ST, class _SA>
4490inline _LIBCPP_INLINE_VISIBILITY
4491bool operator>(const sub_match<_BiIter>& __x,
4492 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4493{
4494 return __y < __x;
4495}
4496
4497template <class _BiIter, class _ST, class _SA>
4498inline _LIBCPP_INLINE_VISIBILITY
4499bool
4500operator>=(const sub_match<_BiIter>& __x,
4501 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4502{
4503 return !(__x < __y);
4504}
4505
4506template <class _BiIter, class _ST, class _SA>
4507inline _LIBCPP_INLINE_VISIBILITY
4508bool
4509operator<=(const sub_match<_BiIter>& __x,
4510 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4511{
4512 return !(__y < __x);
4513}
4514
4515template <class _BiIter>
4516inline _LIBCPP_INLINE_VISIBILITY
4517bool
4518operator==(typename iterator_traits<_BiIter>::value_type const* __x,
4519 const sub_match<_BiIter>& __y)
4520{
4521 return __y.compare(__x) == 0;
4522}
4523
4524template <class _BiIter>
4525inline _LIBCPP_INLINE_VISIBILITY
4526bool
4527operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
4528 const sub_match<_BiIter>& __y)
4529{
4530 return !(__x == __y);
4531}
4532
4533template <class _BiIter>
4534inline _LIBCPP_INLINE_VISIBILITY
4535bool
4536operator<(typename iterator_traits<_BiIter>::value_type const* __x,
4537 const sub_match<_BiIter>& __y)
4538{
4539 return __y.compare(__x) > 0;
4540}
4541
4542template <class _BiIter>
4543inline _LIBCPP_INLINE_VISIBILITY
4544bool
4545operator>(typename iterator_traits<_BiIter>::value_type const* __x,
4546 const sub_match<_BiIter>& __y)
4547{
4548 return __y < __x;
4549}
4550
4551template <class _BiIter>
4552inline _LIBCPP_INLINE_VISIBILITY
4553bool
4554operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
4555 const sub_match<_BiIter>& __y)
4556{
4557 return !(__x < __y);
4558}
4559
4560template <class _BiIter>
4561inline _LIBCPP_INLINE_VISIBILITY
4562bool
4563operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
4564 const sub_match<_BiIter>& __y)
4565{
4566 return !(__y < __x);
4567}
4568
4569template <class _BiIter>
4570inline _LIBCPP_INLINE_VISIBILITY
4571bool
4572operator==(const sub_match<_BiIter>& __x,
4573 typename iterator_traits<_BiIter>::value_type const* __y)
4574{
4575 return __x.compare(__y) == 0;
4576}
4577
4578template <class _BiIter>
4579inline _LIBCPP_INLINE_VISIBILITY
4580bool
4581operator!=(const sub_match<_BiIter>& __x,
4582 typename iterator_traits<_BiIter>::value_type const* __y)
4583{
4584 return !(__x == __y);
4585}
4586
4587template <class _BiIter>
4588inline _LIBCPP_INLINE_VISIBILITY
4589bool
4590operator<(const sub_match<_BiIter>& __x,
4591 typename iterator_traits<_BiIter>::value_type const* __y)
4592{
4593 return __x.compare(__y) < 0;
4594}
4595
4596template <class _BiIter>
4597inline _LIBCPP_INLINE_VISIBILITY
4598bool
4599operator>(const sub_match<_BiIter>& __x,
4600 typename iterator_traits<_BiIter>::value_type const* __y)
4601{
4602 return __y < __x;
4603}
4604
4605template <class _BiIter>
4606inline _LIBCPP_INLINE_VISIBILITY
4607bool
4608operator>=(const sub_match<_BiIter>& __x,
4609 typename iterator_traits<_BiIter>::value_type const* __y)
4610{
4611 return !(__x < __y);
4612}
4613
4614template <class _BiIter>
4615inline _LIBCPP_INLINE_VISIBILITY
4616bool
4617operator<=(const sub_match<_BiIter>& __x,
4618 typename iterator_traits<_BiIter>::value_type const* __y)
4619{
4620 return !(__y < __x);
4621}
4622
4623template <class _BiIter>
4624inline _LIBCPP_INLINE_VISIBILITY
4625bool
4626operator==(typename iterator_traits<_BiIter>::value_type const& __x,
4627 const sub_match<_BiIter>& __y)
4628{
4629 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4630 return __y.compare(string_type(1, __x)) == 0;
4631}
4632
4633template <class _BiIter>
4634inline _LIBCPP_INLINE_VISIBILITY
4635bool
4636operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
4637 const sub_match<_BiIter>& __y)
4638{
4639 return !(__x == __y);
4640}
4641
4642template <class _BiIter>
4643inline _LIBCPP_INLINE_VISIBILITY
4644bool
4645operator<(typename iterator_traits<_BiIter>::value_type const& __x,
4646 const sub_match<_BiIter>& __y)
4647{
4648 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4649 return __y.compare(string_type(1, __x)) > 0;
4650}
4651
4652template <class _BiIter>
4653inline _LIBCPP_INLINE_VISIBILITY
4654bool
4655operator>(typename iterator_traits<_BiIter>::value_type const& __x,
4656 const sub_match<_BiIter>& __y)
4657{
4658 return __y < __x;
4659}
4660
4661template <class _BiIter>
4662inline _LIBCPP_INLINE_VISIBILITY
4663bool
4664operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
4665 const sub_match<_BiIter>& __y)
4666{
4667 return !(__x < __y);
4668}
4669
4670template <class _BiIter>
4671inline _LIBCPP_INLINE_VISIBILITY
4672bool
4673operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
4674 const sub_match<_BiIter>& __y)
4675{
4676 return !(__y < __x);
4677}
4678
4679template <class _BiIter>
4680inline _LIBCPP_INLINE_VISIBILITY
4681bool
4682operator==(const sub_match<_BiIter>& __x,
4683 typename iterator_traits<_BiIter>::value_type const& __y)
4684{
4685 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4686 return __x.compare(string_type(1, __y)) == 0;
4687}
4688
4689template <class _BiIter>
4690inline _LIBCPP_INLINE_VISIBILITY
4691bool
4692operator!=(const sub_match<_BiIter>& __x,
4693 typename iterator_traits<_BiIter>::value_type const& __y)
4694{
4695 return !(__x == __y);
4696}
4697
4698template <class _BiIter>
4699inline _LIBCPP_INLINE_VISIBILITY
4700bool
4701operator<(const sub_match<_BiIter>& __x,
4702 typename iterator_traits<_BiIter>::value_type const& __y)
4703{
4704 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4705 return __x.compare(string_type(1, __y)) < 0;
4706}
4707
4708template <class _BiIter>
4709inline _LIBCPP_INLINE_VISIBILITY
4710bool
4711operator>(const sub_match<_BiIter>& __x,
4712 typename iterator_traits<_BiIter>::value_type const& __y)
4713{
4714 return __y < __x;
4715}
4716
4717template <class _BiIter>
4718inline _LIBCPP_INLINE_VISIBILITY
4719bool
4720operator>=(const sub_match<_BiIter>& __x,
4721 typename iterator_traits<_BiIter>::value_type const& __y)
4722{
4723 return !(__x < __y);
4724}
4725
4726template <class _BiIter>
4727inline _LIBCPP_INLINE_VISIBILITY
4728bool
4729operator<=(const sub_match<_BiIter>& __x,
4730 typename iterator_traits<_BiIter>::value_type const& __y)
4731{
4732 return !(__y < __x);
4733}
4734
4735template <class _CharT, class _ST, class _BiIter>
4736inline _LIBCPP_INLINE_VISIBILITY
4737basic_ostream<_CharT, _ST>&
4738operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
4739{
4740 return __os << __m.str();
4741}
4742
Howard Hinnant17615b02010-07-27 01:25:38 +00004743template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00004744class match_results
4745{
4746public:
4747 typedef _Allocator allocator_type;
4748 typedef sub_match<_BidirectionalIterator> value_type;
4749private:
4750 typedef vector<value_type, allocator_type> __container_type;
4751
4752 __container_type __matches_;
4753 value_type __unmatched_;
4754 value_type __prefix_;
4755 value_type __suffix_;
4756public:
4757 typedef const value_type& const_reference;
4758 typedef const_reference reference;
4759 typedef typename __container_type::const_iterator const_iterator;
4760 typedef const_iterator iterator;
4761 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
4762 typedef typename allocator_traits<allocator_type>::size_type size_type;
4763 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
4764 typedef basic_string<char_type> string_type;
4765
4766 // construct/copy/destroy:
4767 explicit match_results(const allocator_type& __a = allocator_type());
4768// match_results(const match_results&) = default;
4769// match_results& operator=(const match_results&) = default;
4770#ifdef _LIBCPP_MOVE
4771// match_results(match_results&& __m) = default;
4772// match_results& operator=(match_results&& __m) = default;
4773#endif
4774// ~match_results() = default;
4775
4776 // size:
4777 size_type size() const {return __matches_.size();}
4778 size_type max_size() const {return __matches_.max_size();}
4779 bool empty() const {return size() == 0;}
4780
4781 // element access:
4782 difference_type length(size_type __sub = 0) const
4783 {return (*this)[__sub].length();}
4784 difference_type position(size_type __sub = 0) const
4785 {return _STD::distance(__prefix_.first, (*this)[__sub].first);}
4786 string_type str(size_type __sub = 0) const
4787 {return (*this)[__sub].str();}
4788 const_reference operator[](size_type __n) const
4789 {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
4790
4791 const_reference prefix() const {return __prefix_;}
4792 const_reference suffix() const {return __suffix_;}
4793
4794 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
4795 const_iterator end() const {return __matches_.end();}
4796 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
4797 const_iterator cend() const {return __matches_.end();}
4798
4799 // format:
4800 template <class _OutputIter>
4801 _OutputIter
4802 format(_OutputIter __out, const char_type* __fmt_first,
4803 const char_type* __fmt_last,
4804 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
4805 template <class _OutputIter, class _ST, class _SA>
4806 _OutputIter
4807 format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt,
4808 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
4809 template <class _ST, class _SA>
4810 basic_string<char_type, _ST, _SA>
4811 format(const basic_string<char_type, _ST, _SA>& __fmt,
4812 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
4813 string_type
4814 format(const char_type* __fmt,
4815 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
4816
4817 // allocator:
4818 allocator_type get_allocator() const {return __matches_.get_allocator();}
4819
4820 // swap:
4821 void swap(match_results& __m);
4822
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004823 template <class _B, class _A>
4824 void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
4825 const match_results<_B, _A>& __m)
4826 {
4827 _B __mf = __m.prefix().first;
4828 __matches_.resize(__m.size());
4829 for (size_type __i = 0; __i < __matches_.size(); ++__i)
4830 {
4831 __matches_[__i].first = next(__f, _STD::distance(__mf, __m[__i].first));
4832 __matches_[__i].second = next(__f, _STD::distance(__mf, __m[__i].second));
4833 __matches_[__i].matched = __m[__i].matched;
4834 }
4835 __unmatched_.first = __l;
4836 __unmatched_.second = __l;
4837 __unmatched_.matched = false;
4838 __prefix_.first = next(__f, _STD::distance(__mf, __m.prefix().first));
4839 __prefix_.second = next(__f, _STD::distance(__mf, __m.prefix().second));
4840 __prefix_.matched = __m.prefix().matched;
4841 __suffix_.first = next(__f, _STD::distance(__mf, __m.suffix().first));
4842 __suffix_.second = next(__f, _STD::distance(__mf, __m.suffix().second));
4843 __suffix_.matched = __m.suffix().matched;
4844 }
4845
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004846private:
4847 void __init(unsigned __s,
4848 _BidirectionalIterator __f, _BidirectionalIterator __l);
4849
4850 template <class, class> friend class basic_regex;
4851
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00004852 template <class _B, class _A, class _C, class _T>
4853 friend
4854 bool
4855 regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
4856 regex_constants::match_flag_type);
4857};
4858
4859template <class _BidirectionalIterator, class _Allocator>
4860match_results<_BidirectionalIterator, _Allocator>::match_results(
4861 const allocator_type& __a)
4862 : __matches_(__a),
4863 __unmatched_(),
4864 __prefix_(),
4865 __suffix_()
4866{
4867}
4868
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004869template <class _BidirectionalIterator, class _Allocator>
4870void
4871match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
4872 _BidirectionalIterator __f, _BidirectionalIterator __l)
4873{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004874 __unmatched_.first = __l;
4875 __unmatched_.second = __l;
4876 __unmatched_.matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004877 __matches_.assign(__s, __unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004878 __prefix_.first = __f;
4879 __prefix_.second = __f;
4880 __prefix_.matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00004881 __suffix_ = __unmatched_;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004882}
4883
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00004884typedef match_results<const char*> cmatch;
4885typedef match_results<const wchar_t*> wcmatch;
4886typedef match_results<string::const_iterator> smatch;
4887typedef match_results<wstring::const_iterator> wsmatch;
4888
4889template <class _BidirectionalIterator, class _Allocator>
4890 bool
4891 operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
4892 const match_results<_BidirectionalIterator, _Allocator>& __y);
4893
4894template <class _BidirectionalIterator, class _Allocator>
4895 bool
4896 operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
4897 const match_results<_BidirectionalIterator, _Allocator>& __y);
4898
4899template <class _BidirectionalIterator, class _Allocator>
4900 void
4901 swap(match_results<_BidirectionalIterator, _Allocator>& __x,
4902 match_results<_BidirectionalIterator, _Allocator>& __y);
4903
4904// regex_search
4905
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004906template <class _CharT, class _Traits>
Howard Hinnant17615b02010-07-27 01:25:38 +00004907template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00004908bool
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004909basic_regex<_CharT, _Traits>::__match_at_start_ecma(
Howard Hinnant17615b02010-07-27 01:25:38 +00004910 const _CharT* __first, const _CharT* __last,
4911 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004912 regex_constants::match_flag_type __flags) const
4913{
Howard Hinnant17615b02010-07-27 01:25:38 +00004914 vector<__state> __states;
4915 ptrdiff_t __j = 0;
4916 ptrdiff_t _N = _STD::distance(__first, __last);
4917 __node* __st = __start_.get();
4918 if (__st)
4919 {
4920 __states.push_back(__state());
4921 __states.back().__do_ = 0;
4922 __states.back().__first_ = __first;
4923 __states.back().__current_ = __first;
4924 __states.back().__last_ = __last;
4925 __states.back().__sub_matches_.resize(mark_count());
4926 __states.back().__loop_data_.resize(__loop_count());
4927 __states.back().__node_ = __st;
4928 __states.back().__flags_ = __flags;
4929 bool __matched = false;
4930 do
4931 {
4932 __state& __s = __states.back();
4933 if (__s.__node_)
4934 __s.__node_->__exec(__s);
4935 switch (__s.__do_)
4936 {
4937 case __state::__end_state:
4938 __m.__matches_[0].first = __first;
4939 __m.__matches_[0].second = _STD::next(__first, __s.__current_ - __first);
4940 __m.__matches_[0].matched = true;
4941 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
4942 __m.__matches_[__i+1] = __s.__sub_matches_[__i];
4943 return true;
4944 case __state::__accept_and_consume:
4945 case __state::__repeat:
4946 case __state::__accept_but_not_consume:
4947 break;
4948 case __state::__split:
4949 {
4950 __state __snext = __s;
4951 __s.__node_->__exec_split(true, __s);
4952 __snext.__node_->__exec_split(false, __snext);
4953 __states.push_back(_STD::move(__snext));
4954 }
4955 break;
4956 case __state::__reject:
4957 __states.pop_back();
4958 break;
4959 default:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00004960 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnant17615b02010-07-27 01:25:38 +00004961 break;
4962 }
4963 } while (!__states.empty());
4964 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004965 return false;
4966}
4967
4968template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004969template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004970bool
4971basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
4972 const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004973 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004974 regex_constants::match_flag_type __flags) const
4975{
Howard Hinnantac303862010-07-12 15:51:17 +00004976 deque<__state> __states;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00004977 ptrdiff_t __highest_j = 0;
4978 ptrdiff_t _N = _STD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00004979 __node* __st = __start_.get();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004980 if (__st)
4981 {
Howard Hinnantac303862010-07-12 15:51:17 +00004982 __states.push_back(__state());
Howard Hinnantac303862010-07-12 15:51:17 +00004983 __states.back().__do_ = 0;
4984 __states.back().__first_ = __first;
4985 __states.back().__current_ = __first;
4986 __states.back().__last_ = __last;
4987 __states.back().__loop_data_.resize(__loop_count());
4988 __states.back().__node_ = __st;
4989 __states.back().__flags_ = __flags;
Howard Hinnant68025ed2010-07-14 15:45:11 +00004990 bool __matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004991 do
4992 {
Howard Hinnantac303862010-07-12 15:51:17 +00004993 __state& __s = __states.back();
4994 if (__s.__node_)
4995 __s.__node_->__exec(__s);
4996 switch (__s.__do_)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004997 {
Howard Hinnantac303862010-07-12 15:51:17 +00004998 case __state::__end_state:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00004999 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
Howard Hinnant68025ed2010-07-14 15:45:11 +00005000 __highest_j = __s.__current_ - __s.__first_;
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005001 __matched = true;
Howard Hinnantac303862010-07-12 15:51:17 +00005002 if (__highest_j == _N)
5003 __states.clear();
5004 else
5005 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005006 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005007 case __state::__consume_input:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005008 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005009 case __state::__accept_and_consume:
Howard Hinnantac303862010-07-12 15:51:17 +00005010 __states.push_front(_STD::move(__s));
5011 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005012 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005013 case __state::__repeat:
5014 case __state::__accept_but_not_consume:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005015 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005016 case __state::__split:
5017 {
5018 __state __snext = __s;
5019 __s.__node_->__exec_split(true, __s);
5020 __snext.__node_->__exec_split(false, __snext);
5021 __states.push_back(_STD::move(__snext));
5022 }
5023 break;
5024 case __state::__reject:
5025 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005026 break;
5027 default:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005028 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005029 break;
5030 }
Howard Hinnantac303862010-07-12 15:51:17 +00005031 } while (!__states.empty());
Howard Hinnant68025ed2010-07-14 15:45:11 +00005032 if (__matched)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005033 {
5034 __m.__matches_[0].first = __first;
5035 __m.__matches_[0].second = _STD::next(__first, __highest_j);
5036 __m.__matches_[0].matched = true;
5037 return true;
5038 }
5039 }
5040 return false;
5041}
5042
5043template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005044template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005045bool
5046basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005047 const _CharT* __first, const _CharT* __last,
5048 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005049 regex_constants::match_flag_type __flags) const
5050{
Howard Hinnantac303862010-07-12 15:51:17 +00005051 vector<__state> __states;
Howard Hinnantac303862010-07-12 15:51:17 +00005052 __state __best_state;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005053 ptrdiff_t __j = 0;
5054 ptrdiff_t __highest_j = 0;
5055 ptrdiff_t _N = _STD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00005056 __node* __st = __start_.get();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005057 if (__st)
5058 {
Howard Hinnantac303862010-07-12 15:51:17 +00005059 __states.push_back(__state());
5060 __states.back().__do_ = 0;
5061 __states.back().__first_ = __first;
5062 __states.back().__current_ = __first;
5063 __states.back().__last_ = __last;
5064 __states.back().__sub_matches_.resize(mark_count());
5065 __states.back().__loop_data_.resize(__loop_count());
5066 __states.back().__node_ = __st;
5067 __states.back().__flags_ = __flags;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005068 const _CharT* __current = __first;
Howard Hinnantac303862010-07-12 15:51:17 +00005069 bool __matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005070 do
5071 {
Howard Hinnantac303862010-07-12 15:51:17 +00005072 __state& __s = __states.back();
5073 if (__s.__node_)
5074 __s.__node_->__exec(__s);
5075 switch (__s.__do_)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005076 {
Howard Hinnantac303862010-07-12 15:51:17 +00005077 case __state::__end_state:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005078 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005079 {
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005080 __highest_j = __s.__current_ - __s.__first_;
Howard Hinnantac303862010-07-12 15:51:17 +00005081 __best_state = __s;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005082 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005083 __matched = true;
5084 if (__highest_j == _N)
5085 __states.clear();
5086 else
5087 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005088 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005089 case __state::__accept_and_consume:
Howard Hinnantcba352d2010-07-12 18:16:05 +00005090 __j += __s.__current_ - __current;
5091 __current = __s.__current_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005092 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005093 case __state::__repeat:
5094 case __state::__accept_but_not_consume:
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005095 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005096 case __state::__split:
5097 {
5098 __state __snext = __s;
5099 __s.__node_->__exec_split(true, __s);
5100 __snext.__node_->__exec_split(false, __snext);
5101 __states.push_back(_STD::move(__snext));
5102 }
5103 break;
5104 case __state::__reject:
5105 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005106 break;
5107 default:
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005108 throw regex_error(regex_constants::__re_err_unknown);
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005109 break;
5110 }
Howard Hinnantac303862010-07-12 15:51:17 +00005111 } while (!__states.empty());
5112 if (__matched)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005113 {
5114 __m.__matches_[0].first = __first;
5115 __m.__matches_[0].second = _STD::next(__first, __highest_j);
5116 __m.__matches_[0].matched = true;
Howard Hinnantac303862010-07-12 15:51:17 +00005117 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
5118 __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005119 return true;
5120 }
5121 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005122 return false;
5123}
5124
5125template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005126template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005127bool
5128basic_regex<_CharT, _Traits>::__match_at_start(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005129 const _CharT* __first, const _CharT* __last,
5130 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005131 regex_constants::match_flag_type __flags) const
5132{
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005133 if ((__flags_ & 0x1F0) == ECMAScript)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005134 return __match_at_start_ecma(__first, __last, __m, __flags);
5135 if (mark_count() == 0)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005136 return __match_at_start_posix_nosubs(__first, __last, __m, __flags);
5137 return __match_at_start_posix_subs(__first, __last, __m, __flags);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005138}
5139
5140template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005141template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005142bool
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005143basic_regex<_CharT, _Traits>::__search(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005144 const _CharT* __first, const _CharT* __last,
5145 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005146 regex_constants::match_flag_type __flags) const
5147{
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00005148 if (__left_anchor_)
5149 __flags |= regex_constants::match_continuous;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005150 __m.__init(1 + mark_count(), __first, __last);
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005151 if (__match_at_start(__first, __last, __m, __flags))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005152 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005153 __m.__prefix_.second = __m[0].first;
5154 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5155 __m.__suffix_.first = __m[0].second;
5156 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5157 return true;
5158 }
5159 if (!(__flags & regex_constants::match_continuous))
5160 {
5161 __m.__matches_.assign(__m.size(), __m.__unmatched_);
5162 for (++__first; __first != __last; ++__first)
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005163 {
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005164 if (__match_at_start(__first, __last, __m, __flags))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005165 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005166 __m.__prefix_.second = __m[0].first;
5167 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5168 __m.__suffix_.first = __m[0].second;
5169 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5170 return true;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005171 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005172 __m.__matches_.assign(__m.size(), __m.__unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005173 }
5174 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005175 __m.__matches_.clear();
5176 return false;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005177}
5178
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005179template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005180inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005181bool
5182regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5183 match_results<_BidirectionalIterator, _Allocator>& __m,
5184 const basic_regex<_CharT, _Traits>& __e,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005185 regex_constants::match_flag_type __flags = regex_constants::match_default)
5186{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005187 basic_string<_CharT> __s(__first, __last);
5188 match_results<const _CharT*> __mc;
5189 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5190 __m.__assign(__first, __last, __mc);
5191 return __r;
5192}
5193
5194template <class _Allocator, class _CharT, class _Traits>
5195inline _LIBCPP_INLINE_VISIBILITY
5196bool
5197regex_search(const _CharT* __first, const _CharT* __last,
5198 match_results<const _CharT*, _Allocator>& __m,
5199 const basic_regex<_CharT, _Traits>& __e,
5200 regex_constants::match_flag_type __flags = regex_constants::match_default)
5201{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005202 return __e.__search(__first, __last, __m, __flags);
5203}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005204
5205template <class _BidirectionalIterator, class _CharT, class _Traits>
5206inline _LIBCPP_INLINE_VISIBILITY
5207bool
5208regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5209 const basic_regex<_CharT, _Traits>& __e,
5210 regex_constants::match_flag_type __flags = regex_constants::match_default)
5211{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005212 basic_string<_CharT> __s(__first, __last);
5213 match_results<const _CharT*> __mc;
5214 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5215}
5216
5217template <class _CharT, class _Traits>
5218inline _LIBCPP_INLINE_VISIBILITY
5219bool
5220regex_search(const _CharT* __first, const _CharT* __last,
5221 const basic_regex<_CharT, _Traits>& __e,
5222 regex_constants::match_flag_type __flags = regex_constants::match_default)
5223{
5224 match_results<const _CharT*> __mc;
5225 return __e.__search(__first, __last, __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005226}
5227
5228template <class _CharT, class _Allocator, class _Traits>
5229inline _LIBCPP_INLINE_VISIBILITY
5230bool
5231regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5232 const basic_regex<_CharT, _Traits>& __e,
5233 regex_constants::match_flag_type __flags = regex_constants::match_default)
5234{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005235 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005236}
5237
5238template <class _CharT, class _Traits>
5239inline _LIBCPP_INLINE_VISIBILITY
5240bool
5241regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5242 regex_constants::match_flag_type __flags = regex_constants::match_default)
5243{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005244 match_results<const _CharT*> __m;
5245 return _STD::regex_search(__str, __m, __e, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005246}
5247
5248template <class _ST, class _SA, class _CharT, class _Traits>
5249inline _LIBCPP_INLINE_VISIBILITY
5250bool
5251regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5252 const basic_regex<_CharT, _Traits>& __e,
5253 regex_constants::match_flag_type __flags = regex_constants::match_default)
5254{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005255 match_results<const _CharT*> __mc;
5256 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005257}
5258
5259template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5260inline _LIBCPP_INLINE_VISIBILITY
5261bool
5262regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5263 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5264 const basic_regex<_CharT, _Traits>& __e,
5265 regex_constants::match_flag_type __flags = regex_constants::match_default)
5266{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005267 match_results<const _CharT*> __mc;
5268 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5269 __m.__assign(__s.begin(), __s.end(), __mc);
5270 return __r;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005271}
5272
5273// regex_match
5274
5275template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5276bool
5277regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5278 match_results<_BidirectionalIterator, _Allocator>& __m,
5279 const basic_regex<_CharT, _Traits>& __e,
5280 regex_constants::match_flag_type __flags = regex_constants::match_default)
5281{
5282 bool __r = _STD::regex_search(__first, __last, __m, __e,
5283 __flags | regex_constants::match_continuous);
5284 if (__r)
5285 {
5286 __r = !__m.suffix().matched;
5287 if (!__r)
5288 __m.__matches_.clear();
5289 }
5290 return __r;
5291}
5292
5293template <class _BidirectionalIterator, class _CharT, class _Traits>
5294inline _LIBCPP_INLINE_VISIBILITY
5295bool
5296regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5297 const basic_regex<_CharT, _Traits>& __e,
5298 regex_constants::match_flag_type __flags = regex_constants::match_default)
5299{
5300 match_results<_BidirectionalIterator> __m;
5301 return _STD::regex_match(__first, __last, __m, __e, __flags);
5302}
5303
5304template <class _CharT, class _Allocator, class _Traits>
5305inline _LIBCPP_INLINE_VISIBILITY
5306bool
5307regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5308 const basic_regex<_CharT, _Traits>& __e,
5309 regex_constants::match_flag_type __flags = regex_constants::match_default)
5310{
5311 return _STD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
5312}
5313
5314template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5315inline _LIBCPP_INLINE_VISIBILITY
5316bool
5317regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5318 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5319 const basic_regex<_CharT, _Traits>& __e,
5320 regex_constants::match_flag_type __flags = regex_constants::match_default)
5321{
5322 return _STD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
5323}
5324
5325template <class _CharT, class _Traits>
5326inline _LIBCPP_INLINE_VISIBILITY
5327bool
5328regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5329 regex_constants::match_flag_type __flags = regex_constants::match_default)
5330{
5331 return _STD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
5332}
5333
5334template <class _ST, class _SA, class _CharT, class _Traits>
5335inline _LIBCPP_INLINE_VISIBILITY
5336bool
5337regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5338 const basic_regex<_CharT, _Traits>& __e,
5339 regex_constants::match_flag_type __flags = regex_constants::match_default)
5340{
5341 return _STD::regex_match(__s.begin(), __s.end(), __e, __flags);
5342}
5343
Howard Hinnant3257c982010-06-17 00:34:59 +00005344_LIBCPP_END_NAMESPACE_STD
5345
5346#endif // _LIBCPP_REGEX