blob: 7641a4a3cc0326b0cc15b0ede0e46936da85dea8 [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 Hinnante77aa5e2010-07-08 17:43:58 +0000720#include <sstream>
721#include <cassert>
722
Howard Hinnant3257c982010-06-17 00:34:59 +0000723#include <__config>
724#include <stdexcept>
725#include <__locale>
Howard Hinnant8c2c18d2010-06-24 21:28:00 +0000726#include <initializer_list>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +0000727#include <utility>
728#include <iterator>
729#include <string>
Howard Hinnant7e9d84b2010-06-30 00:21:42 +0000730#include <memory>
731#include <vector>
Howard Hinnantf8ce4592010-07-07 19:14:52 +0000732#include <__split_buffer>
Howard Hinnant3257c982010-06-17 00:34:59 +0000733
734#pragma GCC system_header
735
736_LIBCPP_BEGIN_NAMESPACE_STD
737
738namespace regex_constants
739{
740
741// syntax_option_type
742
743enum syntax_option_type
744{
745 icase = 1 << 0,
746 nosubs = 1 << 1,
747 optimize = 1 << 2,
748 collate = 1 << 3,
749 ECMAScript = 1 << 4,
750 basic = 1 << 5,
751 extended = 1 << 6,
752 awk = 1 << 7,
753 grep = 1 << 8,
754 egrep = 1 << 9
755};
756
757inline
758/*constexpr*/
759syntax_option_type
760operator~(syntax_option_type __x)
761{
762 return syntax_option_type(~int(__x));
763}
764
765inline
766/*constexpr*/
767syntax_option_type
768operator&(syntax_option_type __x, syntax_option_type __y)
769{
770 return syntax_option_type(int(__x) & int(__y));
771}
772
773inline
774/*constexpr*/
775syntax_option_type
776operator|(syntax_option_type __x, syntax_option_type __y)
777{
778 return syntax_option_type(int(__x) | int(__y));
779}
780
781inline
782/*constexpr*/
783syntax_option_type
784operator^(syntax_option_type __x, syntax_option_type __y)
785{
786 return syntax_option_type(int(__x) ^ int(__y));
787}
788
789inline
790/*constexpr*/
791syntax_option_type&
792operator&=(syntax_option_type& __x, syntax_option_type __y)
793{
794 __x = __x & __y;
795 return __x;
796}
797
798inline
799/*constexpr*/
800syntax_option_type&
801operator|=(syntax_option_type& __x, syntax_option_type __y)
802{
803 __x = __x | __y;
804 return __x;
805}
806
807inline
808/*constexpr*/
809syntax_option_type&
810operator^=(syntax_option_type& __x, syntax_option_type __y)
811{
812 __x = __x ^ __y;
813 return __x;
814}
815
816// match_flag_type
817
818enum match_flag_type
819{
820 match_default = 0,
821 match_not_bol = 1 << 0,
822 match_not_eol = 1 << 1,
823 match_not_bow = 1 << 2,
824 match_not_eow = 1 << 3,
825 match_any = 1 << 4,
826 match_not_null = 1 << 5,
827 match_continuous = 1 << 6,
828 match_prev_avail = 1 << 7,
829 format_default = 0,
830 format_sed = 1 << 8,
831 format_no_copy = 1 << 9,
832 format_first_only = 1 << 10
833};
834
835inline
836/*constexpr*/
837match_flag_type
838operator~(match_flag_type __x)
839{
840 return match_flag_type(~int(__x));
841}
842
843inline
844/*constexpr*/
845match_flag_type
846operator&(match_flag_type __x, match_flag_type __y)
847{
848 return match_flag_type(int(__x) & int(__y));
849}
850
851inline
852/*constexpr*/
853match_flag_type
854operator|(match_flag_type __x, match_flag_type __y)
855{
856 return match_flag_type(int(__x) | int(__y));
857}
858
859inline
860/*constexpr*/
861match_flag_type
862operator^(match_flag_type __x, match_flag_type __y)
863{
864 return match_flag_type(int(__x) ^ int(__y));
865}
866
867inline
868/*constexpr*/
869match_flag_type&
870operator&=(match_flag_type& __x, match_flag_type __y)
871{
872 __x = __x & __y;
873 return __x;
874}
875
876inline
877/*constexpr*/
878match_flag_type&
879operator|=(match_flag_type& __x, match_flag_type __y)
880{
881 __x = __x | __y;
882 return __x;
883}
884
885inline
886/*constexpr*/
887match_flag_type&
888operator^=(match_flag_type& __x, match_flag_type __y)
889{
890 __x = __x ^ __y;
891 return __x;
892}
893
894enum error_type
895{
896 error_collate = 1,
897 error_ctype,
898 error_escape,
899 error_backref,
900 error_brack,
901 error_paren,
902 error_brace,
903 error_badbrace,
904 error_range,
905 error_space,
906 error_badrepeat,
907 error_complexity,
Howard Hinnant8c2c18d2010-06-24 21:28:00 +0000908 error_stack,
909 error_temp
Howard Hinnant3257c982010-06-17 00:34:59 +0000910};
911
912} // regex_constants
913
914class _LIBCPP_EXCEPTION_ABI regex_error
915 : public runtime_error
916{
917 regex_constants::error_type __code_;
918public:
919 explicit regex_error(regex_constants::error_type __ecode);
920 virtual ~regex_error() throw();
921 regex_constants::error_type code() const {return __code_;}
922};
923
924template <class _CharT>
925struct regex_traits
926{
927public:
928 typedef _CharT char_type;
929 typedef basic_string<char_type> string_type;
930 typedef locale locale_type;
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000931 typedef ctype_base::mask char_class_type;
Howard Hinnant3257c982010-06-17 00:34:59 +0000932
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000933 static const char_class_type __regex_word = 0x80;
Howard Hinnant3257c982010-06-17 00:34:59 +0000934private:
935 locale __loc_;
936 const ctype<char_type>* __ct_;
937 const collate<char_type>* __col_;
938
939public:
940 regex_traits();
941
942 static size_t length(const char_type* __p)
943 {return char_traits<char_type>::length(__p);}
944 char_type translate(char_type __c) const {return __c;}
945 char_type translate_nocase(char_type __c) const;
946 template <class _ForwardIterator>
947 string_type
948 transform(_ForwardIterator __f, _ForwardIterator __l) const;
949 template <class _ForwardIterator>
950 string_type
951 transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
952 {return __transform_primary(__f, __l, char_type());}
953 template <class _ForwardIterator>
954 string_type
955 lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
956 {return __lookup_collatename(__f, __l, char_type());}
957 template <class _ForwardIterator>
958 char_class_type
959 lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000960 bool __icase = false) const
961 {return __lookup_classname(__f, __l, __icase, char_type());}
962 bool isctype(char_type __c, char_class_type __m) const;
963 int value(char_type __ch, int __radix) const
964 {return __value(__ch, __radix);}
Howard Hinnant3257c982010-06-17 00:34:59 +0000965 locale_type imbue(locale_type __l);
966 locale_type getloc()const {return __loc_;}
967
968private:
969 void __init();
970
971 template <class _ForwardIterator>
972 string_type
973 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
974 template <class _ForwardIterator>
975 string_type
976 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
977
978 template <class _ForwardIterator>
979 string_type
980 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
981 template <class _ForwardIterator>
982 string_type
983 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000984
985 template <class _ForwardIterator>
986 char_class_type
987 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
988 bool __icase, char) const;
989 template <class _ForwardIterator>
990 char_class_type
991 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
992 bool __icase, wchar_t) const;
993
994 static int __value(unsigned char __ch, int __radix);
995 int __value(char __ch, int __radix) const
996 {return __value(static_cast<unsigned char>(__ch), __radix);}
997 int __value(wchar_t __ch, int __radix) const;
Howard Hinnant3257c982010-06-17 00:34:59 +0000998};
999
1000template <class _CharT>
1001regex_traits<_CharT>::regex_traits()
1002{
1003 __init();
1004}
1005
1006template <class _CharT>
1007typename regex_traits<_CharT>::char_type
1008regex_traits<_CharT>::translate_nocase(char_type __c) const
1009{
1010 return __ct_->tolower(__c);
1011}
1012
1013template <class _CharT>
1014template <class _ForwardIterator>
1015typename regex_traits<_CharT>::string_type
1016regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
1017{
1018 string_type __s(__f, __l);
1019 return __col_->transform(__s.data(), __s.data() + __s.size());
1020}
1021
1022template <class _CharT>
1023void
1024regex_traits<_CharT>::__init()
1025{
1026 __ct_ = &use_facet<ctype<char_type> >(__loc_);
1027 __col_ = &use_facet<collate<char_type> >(__loc_);
1028}
1029
1030template <class _CharT>
1031typename regex_traits<_CharT>::locale_type
1032regex_traits<_CharT>::imbue(locale_type __l)
1033{
1034 locale __r = __loc_;
1035 __loc_ = __l;
1036 __init();
1037 return __r;
1038}
1039
1040// transform_primary is very FreeBSD-specific
1041
1042template <class _CharT>
1043template <class _ForwardIterator>
1044typename regex_traits<_CharT>::string_type
1045regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1046 _ForwardIterator __l, char) const
1047{
1048 const string_type __s(__f, __l);
1049 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1050 switch (__d.size())
1051 {
1052 case 1:
1053 break;
1054 case 12:
1055 __d[11] = __d[3];
1056 break;
1057 default:
1058 __d.clear();
1059 break;
1060 }
1061 return __d;
1062}
1063
1064template <class _CharT>
1065template <class _ForwardIterator>
1066typename regex_traits<_CharT>::string_type
1067regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1068 _ForwardIterator __l, wchar_t) const
1069{
1070 const string_type __s(__f, __l);
1071 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1072 switch (__d.size())
1073 {
1074 case 1:
1075 break;
1076 case 3:
1077 __d[2] = __d[0];
1078 break;
1079 default:
1080 __d.clear();
1081 break;
1082 }
1083 return __d;
1084}
1085
1086// lookup_collatename is very FreeBSD-specific
1087
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001088string __get_collation_name(const char* __s);
Howard Hinnant3257c982010-06-17 00:34:59 +00001089
1090template <class _CharT>
1091template <class _ForwardIterator>
1092typename regex_traits<_CharT>::string_type
1093regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1094 _ForwardIterator __l, char) const
1095{
1096 string_type __s(__f, __l);
1097 string_type __r;
1098 if (!__s.empty())
1099 {
1100 __r = __get_collation_name(__s.c_str());
1101 if (__r.empty() && __s.size() <= 2)
1102 {
1103 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1104 if (__r.size() == 1 || __r.size() == 12)
1105 __r = __s;
1106 else
1107 __r.clear();
1108 }
1109 }
1110 return __r;
1111}
1112
1113template <class _CharT>
1114template <class _ForwardIterator>
1115typename regex_traits<_CharT>::string_type
1116regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1117 _ForwardIterator __l, wchar_t) const
1118{
1119 string_type __s(__f, __l);
1120 string __n;
1121 __n.reserve(__s.size());
1122 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1123 __i != __e; ++__i)
1124 {
1125 if (static_cast<unsigned>(*__i) >= 127)
1126 return string_type();
1127 __n.push_back(char(*__i));
1128 }
1129 string_type __r;
1130 if (!__s.empty())
1131 {
1132 __n = __get_collation_name(__n.c_str());
1133 if (!__n.empty())
1134 __r.assign(__n.begin(), __n.end());
1135 else if (__s.size() <= 2)
1136 {
1137 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1138 if (__r.size() == 1 || __r.size() == 3)
1139 __r = __s;
1140 else
1141 __r.clear();
1142 }
1143 }
1144 return __r;
1145}
1146
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001147// lookup_classname
1148
1149ctype_base::mask __get_classname(const char* __s, bool __icase);
1150
1151template <class _CharT>
1152template <class _ForwardIterator>
1153typename regex_traits<_CharT>::char_class_type
1154regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1155 _ForwardIterator __l,
1156 bool __icase, char) const
1157{
1158 string_type __s(__f, __l);
1159 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1160 return __get_classname(__s.c_str(), __icase);
1161}
1162
1163template <class _CharT>
1164template <class _ForwardIterator>
1165typename regex_traits<_CharT>::char_class_type
1166regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1167 _ForwardIterator __l,
1168 bool __icase, wchar_t) const
1169{
1170 string_type __s(__f, __l);
1171 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1172 string __n;
1173 __n.reserve(__s.size());
1174 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1175 __i != __e; ++__i)
1176 {
1177 if (static_cast<unsigned>(*__i) >= 127)
1178 return char_class_type();
1179 __n.push_back(char(*__i));
1180 }
1181 return __get_classname(__n.c_str(), __icase);
1182}
1183
1184template <class _CharT>
1185bool
1186regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
1187{
1188 if (__ct_->is(__m, __c))
1189 return true;
1190 return (__c == '_' && (__m & __regex_word));
1191}
1192
1193template <class _CharT>
1194int
1195regex_traits<_CharT>::__value(unsigned char __ch, int __radix)
1196{
1197 if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
1198 return __ch - '0';
1199 if (__radix != 8)
1200 {
1201 if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
1202 return __ch - '0';
1203 if (__radix == 16)
1204 {
1205 __ch |= 0x20; // tolower
1206 if ('a' <= __ch && __ch <= 'f')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001207 return __ch - ('a' - 10);
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001208 }
1209 }
1210 return -1;
1211}
1212
1213template <class _CharT>
1214inline
1215int
1216regex_traits<_CharT>::__value(wchar_t __ch, int __radix) const
1217{
1218 return __value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
1219}
1220
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001221template <class _CharT> class __state;
1222
1223template <class _CharT>
1224struct __command
1225{
1226 enum
1227 {
1228 __end_state = -1000,
1229 __consume_input, // -999
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001230 __begin_marked_expr, // -998
1231 __end_marked_expr, // -997
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001232 __pop_state, // -996
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001233 __accept_and_consume, // -995
1234 __accept_but_not_consume, // -994
1235 __reject, // -993
1236 __zero_loop_count,
1237 __increment_loop_count,
1238 __zero_marked_exprs,
1239 };
1240
1241 typedef __state<_CharT> __state;
1242
1243 int __do_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001244 const __state* first;
1245 const __state* second;
1246
1247 __command() : __do_(__reject), first(nullptr), second(nullptr) {}
1248 explicit __command(int __do)
1249 : __do_(__do), first(nullptr), second(nullptr) {}
1250 __command(int __do, const __state* __s1, const __state* __s2 = nullptr)
1251 : __do_(__do), first(__s1), second(__s2) {}
1252 explicit __command(const __state* __s1, const __state* __s2 = nullptr)
1253 : __do_(0), first(__s1), second(__s2) {}
1254};
1255
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001256template <class _CharT>
1257ostream&
1258operator<<(ostream& os, const __command<_CharT>& c)
1259{
1260 os << c.__do_;
1261 if (c.first)
1262 os << ", " << c.first->speak();
1263 if (c.second)
1264 os << ", " << c.second->speak();
1265 return os;
1266}
1267
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001268template <class _BidirectionalIterator> class sub_match;
1269
1270// __state
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001271
1272template <class _CharT>
1273class __state
1274{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001275 __state(const __state&);
1276 __state& operator=(const __state&);
1277public:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001278 typedef __command<_CharT> __command;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001279
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001280 __state() {}
1281 virtual ~__state() {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001282
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001283 virtual __command __test(const _CharT* __first, const _CharT* __current,
1284 const _CharT* __last,
1285 vector<size_t>& __lc,
1286 sub_match<const _CharT*>* __m,
1287 regex_constants::match_flag_type __flags) const = 0;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001288
1289 virtual string speak() const = 0;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001290};
1291
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001292// __end_state
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001293
1294template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001295class __end_state
1296 : public __state<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001297{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001298public:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001299 typedef __command<_CharT> __command;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001300
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001301 __end_state() {}
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001302
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001303 virtual __command __test(const _CharT*, const _CharT*,
1304 const _CharT*,
1305 vector<size_t>&,
1306 sub_match<const _CharT*>*,
1307 regex_constants::match_flag_type) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001308
1309 virtual string speak() const {return "end state";}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001310};
1311
1312template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001313__command<_CharT>
1314__end_state<_CharT>::__test(const _CharT*, const _CharT*,
1315 const _CharT*,
1316 vector<size_t>&,
1317 sub_match<const _CharT*>*,
1318 regex_constants::match_flag_type) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001319{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001320 return __command(__command::__end_state);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001321}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001322
1323// __has_one_state
1324
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001325template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001326class __has_one_state
1327 : public __state<_CharT>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001328{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001329 __state<_CharT>* __first_;
1330
1331public:
1332 explicit __has_one_state(__state<_CharT>* __s)
1333 : __first_(__s) {}
1334
1335 __state<_CharT>* first() const {return __first_;}
1336 __state<_CharT>*& first() {return __first_;}
1337};
1338
1339// __owns_one_state
1340
1341template <class _CharT>
1342class __owns_one_state
1343 : public __has_one_state<_CharT>
1344{
1345 typedef __has_one_state<_CharT> base;
1346
1347public:
1348 explicit __owns_one_state(__state<_CharT>* __s)
1349 : base(__s) {}
1350
1351 virtual ~__owns_one_state();
1352};
1353
1354template <class _CharT>
1355__owns_one_state<_CharT>::~__owns_one_state()
1356{
1357 delete this->first();
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001358}
1359
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001360// __empty_state
1361
1362template <class _CharT>
1363class __empty_state
1364 : public __owns_one_state<_CharT>
1365{
1366 typedef __owns_one_state<_CharT> base;
1367
1368public:
1369 typedef __command<_CharT> __command;
1370
1371 explicit __empty_state(__state<_CharT>* __s)
1372 : base(__s) {}
1373
1374 virtual __command __test(const _CharT*, const _CharT*,
1375 const _CharT*,
1376 vector<size_t>&,
1377 sub_match<const _CharT*>*,
1378 regex_constants::match_flag_type) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001379
1380 virtual string speak() const {return "empty state";}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001381};
1382
1383template <class _CharT>
1384__command<_CharT>
1385__empty_state<_CharT>::__test(const _CharT*, const _CharT*, const _CharT*,
1386 vector<size_t>&,
1387 sub_match<const _CharT*>*,
1388 regex_constants::match_flag_type) const
1389{
1390 return __command(__command::__accept_but_not_consume, this->first());
1391}
1392
1393// __empty_non_own_state
1394
1395template <class _CharT>
1396class __empty_non_own_state
1397 : public __has_one_state<_CharT>
1398{
1399 typedef __has_one_state<_CharT> base;
1400
1401public:
1402 typedef __command<_CharT> __command;
1403
1404 explicit __empty_non_own_state(__state<_CharT>* __s)
1405 : base(__s) {}
1406
1407 virtual __command __test(const _CharT*, const _CharT*,
1408 const _CharT*,
1409 vector<size_t>&,
1410 sub_match<const _CharT*>*,
1411 regex_constants::match_flag_type) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001412
1413 virtual string speak() const {return "empty non-owning state";}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001414};
1415
1416template <class _CharT>
1417__command<_CharT>
1418__empty_non_own_state<_CharT>::__test(const _CharT*, const _CharT*, const _CharT*,
1419 vector<size_t>&,
1420 sub_match<const _CharT*>*,
1421 regex_constants::match_flag_type) const
1422{
1423 return __command(__command::__accept_but_not_consume, this->first());
1424}
1425
1426// __owns_two_states
1427
1428template <class _CharT>
1429class __owns_two_states
1430 : public __owns_one_state<_CharT>
1431{
1432 typedef __owns_one_state<_CharT> base;
1433
1434 base* __second_;
1435
1436public:
1437 explicit __owns_two_states(__state<_CharT>* __s1, base* __s2)
1438 : base(__s1), __second_(__s2) {}
1439
1440 virtual ~__owns_two_states();
1441
1442 base* second() const {return __second_;}
1443 base*& second() {return __second_;}
1444};
1445
1446template <class _CharT>
1447__owns_two_states<_CharT>::~__owns_two_states()
1448{
1449 delete __second_;
1450}
1451
1452// __loop
1453
1454template <class _CharT>
1455class __loop
1456 : public __owns_two_states<_CharT>
1457{
1458 typedef __owns_two_states<_CharT> base;
1459
1460 size_t __min_;
1461 size_t __max_;
1462 unsigned __loop_id_;
1463 bool __greedy_;
1464
1465public:
1466 typedef __command<_CharT> __command;
1467
1468 explicit __loop(unsigned __loop_id,
1469 __state<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
1470 bool __greedy = true,
1471 size_t __min = 0,
1472 size_t __max = numeric_limits<size_t>::max())
1473 : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
1474 __greedy_(__greedy) {}
1475
1476 virtual __command __test(const _CharT* __first, const _CharT* __current,
1477 const _CharT* __last,
1478 vector<size_t>&,
1479 sub_match<const _CharT*>*,
1480 regex_constants::match_flag_type __flags) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001481
1482 virtual string speak() const
1483 {
1484 ostringstream os;
1485 os << "loop {" << __min_ << ',' << __max_ << "}";
1486 if (!__greedy_)
1487 os << " not";
1488 os << " greedy";
1489 return os.str();
1490 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001491};
1492
1493template <class _CharT>
1494__command<_CharT>
1495__loop<_CharT>::__test(const _CharT* __first, const _CharT* __current,
1496 const _CharT* __last,
1497 vector<size_t>& __lc,
1498 sub_match<const _CharT*>* __m,
1499 regex_constants::match_flag_type __flags) const
1500{
1501 size_t __count = __lc[__loop_id_];
1502 if (__min_ <= __count && __count < __max_)
1503 if (__greedy_)
1504 return __command(__command::__accept_but_not_consume, this->first(),
1505 this->second());
1506 else
1507 return __command(__command::__accept_but_not_consume, this->second(),
1508 this->first());
1509 if (__min_ <= __count)
1510 return __command(__command::__accept_but_not_consume, this->second());
1511 if (__count < __max_)
1512 return __command(__command::__accept_but_not_consume, this->first());
1513 throw regex_error(regex_constants::error_temp);
1514}
1515
1516// __zero_loop_count
1517
1518template <class _CharT>
1519class __zero_loop_count
1520 : public __owns_one_state<_CharT>
1521{
1522 typedef __owns_one_state<_CharT> base;
1523
1524 size_t __loop_id_;
1525
1526public:
1527 typedef __command<_CharT> __command;
1528
1529 explicit __zero_loop_count(size_t __loop_id,
1530 __state<_CharT>* __s1)
1531 : base(__s1), __loop_id_(__loop_id) {}
1532
1533 virtual __command __test(const _CharT*, const _CharT*, const _CharT*,
1534 vector<size_t>& __lc,
1535 sub_match<const _CharT*>*,
1536 regex_constants::match_flag_type) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001537
1538 virtual string speak() const
1539 {
1540 ostringstream os;
1541 os << "zero loop " << __loop_id_;
1542 return os.str();
1543 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001544};
1545
1546template <class _CharT>
1547__command<_CharT>
1548__zero_loop_count<_CharT>::__test(const _CharT*, const _CharT*, const _CharT*,
1549 vector<size_t>& __lc,
1550 sub_match<const _CharT*>*,
1551 regex_constants::match_flag_type) const
1552{
1553 __lc[__loop_id_] = 0;
1554 return __command(__command::__accept_but_not_consume, this->first());
1555}
1556
1557// __increment_loop_count
1558
1559template <class _CharT>
1560class __increment_loop_count
1561 : public __has_one_state<_CharT>
1562{
1563 typedef __has_one_state<_CharT> base;
1564
1565 size_t __loop_id_;
1566
1567public:
1568 typedef __command<_CharT> __command;
1569
1570 explicit __increment_loop_count(size_t __loop_id,
1571 __state<_CharT>* __s1)
1572 : base(__s1), __loop_id_(__loop_id) {}
1573
1574 virtual __command __test(const _CharT*, const _CharT*, const _CharT*,
1575 vector<size_t>& __lc,
1576 sub_match<const _CharT*>*,
1577 regex_constants::match_flag_type) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001578
1579 virtual string speak() const
1580 {
1581 ostringstream os;
1582 os << "increment loop " << __loop_id_;
1583 return os.str();
1584 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001585};
1586
1587template <class _CharT>
1588__command<_CharT>
1589__increment_loop_count<_CharT>::__test(const _CharT*, const _CharT*, const _CharT*,
1590 vector<size_t>& __lc,
1591 sub_match<const _CharT*>*,
1592 regex_constants::match_flag_type) const
1593{
1594 ++__lc[__loop_id_];
1595 return __command(__command::__accept_but_not_consume, this->first());
1596}
1597
1598// __zero_marked_exprs
1599
1600template <class _CharT>
1601class __zero_marked_exprs
1602 : public __owns_one_state<_CharT>
1603{
1604 typedef __owns_one_state<_CharT> base;
1605
1606 size_t __begin_;
1607 size_t __end_;
1608
1609public:
1610 typedef __command<_CharT> __command;
1611
1612 explicit __zero_marked_exprs(size_t __begin, size_t __end,
1613 __state<_CharT>* __s1)
1614 : base(__s1), __begin_(__begin), __end_(__end) {}
1615
1616 virtual __command __test(const _CharT*, const _CharT*, const _CharT*,
1617 vector<size_t>&,
1618 sub_match<const _CharT*>* __sm,
1619 regex_constants::match_flag_type) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001620
1621 virtual string speak() const
1622 {
1623 ostringstream os;
1624 os << "zero marked exprs [" << __begin_ << ',' << __end_ << ')';
1625 return os.str();
1626 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001627};
1628
1629template <class _CharT>
1630__command<_CharT>
1631__zero_marked_exprs<_CharT>::__test(const _CharT*, const _CharT*,
1632 const _CharT* __last,
1633 vector<size_t>&,
1634 sub_match<const _CharT*>* __sm,
1635 regex_constants::match_flag_type) const
1636{
1637 for (size_t __i = __begin_; __i != __end_; ++__i)
1638 {
1639 __sm[__i].first = __last;
1640 __sm[__i].second = __last;
1641 __sm[__i].matched = false;
1642 }
1643 return __command(__command::__accept_but_not_consume, this->first());
1644}
1645
1646// __begin_marked_subexpression
1647
1648template <class _CharT>
1649class __begin_marked_subexpression
1650 : public __owns_one_state<_CharT>
1651{
1652 typedef __owns_one_state<_CharT> base;
1653
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001654 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001655public:
1656 typedef __command<_CharT> __command;
1657
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001658 explicit __begin_marked_subexpression(unsigned __mexp, __state<_CharT>* __s)
1659 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001660
1661 virtual __command __test(const _CharT*, const _CharT*,
1662 const _CharT*,
1663 vector<size_t>&,
1664 sub_match<const _CharT*>*,
1665 regex_constants::match_flag_type) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001666
1667 virtual string speak() const
1668 {
1669 ostringstream os;
1670 os << "begin marked expr " << __mexp_;
1671 return os.str();
1672 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001673};
1674
1675template <class _CharT>
1676__command<_CharT>
1677__begin_marked_subexpression<_CharT>::__test(const _CharT*, const _CharT* __c, const _CharT*,
1678 vector<size_t>&,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001679 sub_match<const _CharT*>* __s,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001680 regex_constants::match_flag_type) const
1681{
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001682 __s[__mexp_].first = __c;
1683 return __command(__command::__accept_but_not_consume, this->first());
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001684}
1685
1686// __end_marked_subexpression
1687
1688template <class _CharT>
1689class __end_marked_subexpression
1690 : public __owns_one_state<_CharT>
1691{
1692 typedef __owns_one_state<_CharT> base;
1693
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001694 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001695public:
1696 typedef __command<_CharT> __command;
1697
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001698 explicit __end_marked_subexpression(unsigned __mexp, __state<_CharT>* __s)
1699 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001700
1701 virtual __command __test(const _CharT*, const _CharT*,
1702 const _CharT*,
1703 vector<size_t>&,
1704 sub_match<const _CharT*>*,
1705 regex_constants::match_flag_type) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001706
1707 virtual string speak() const
1708 {
1709 ostringstream os;
1710 os << "end marked expr " << __mexp_;
1711 return os.str();
1712 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001713};
1714
1715template <class _CharT>
1716__command<_CharT>
1717__end_marked_subexpression<_CharT>::__test(const _CharT*, const _CharT* __c, const _CharT*,
1718 vector<size_t>&,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001719 sub_match<const _CharT*>* __s,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001720 regex_constants::match_flag_type) const
1721{
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001722 __s[__mexp_].second = __c;
1723 __s[__mexp_].matched = true;
1724 return __command(__command::__accept_but_not_consume, this->first());
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001725}
1726
1727// __state_arg
1728
1729template <class _CharT>
1730class __state_arg
1731 : public __owns_one_state<_CharT>
1732{
1733 typedef __owns_one_state<_CharT> base;
1734
1735 unsigned __arg_;
1736
1737 __state_arg(const __state_arg&);
1738 __state_arg& operator=(const __state_arg&);
1739public:
1740 typedef __command<_CharT> __command;
1741
1742 __state_arg(unsigned __a, __state<_CharT>* __s)
1743 : base(__s), __arg_(__a) {}
1744
1745 virtual __command __test(const _CharT*, const _CharT*,
1746 const _CharT*,
1747 vector<size_t>&,
1748 sub_match<const _CharT*>*,
1749 regex_constants::match_flag_type) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001750
1751 virtual string speak() const
1752 {
1753 ostringstream os;
1754 os << "state arg " << __arg_;
1755 return os.str();
1756 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001757};
1758
1759template <class _CharT>
1760__command<_CharT>
1761__state_arg<_CharT>::__test(const _CharT*, const _CharT* __c, const _CharT*,
1762 vector<size_t>&,
1763 sub_match<const _CharT*>*,
1764 regex_constants::match_flag_type) const
1765{
1766 return __command(__arg_, this->first());
1767}
1768
1769// __match_char
1770
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001771template <class _CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001772class __match_char
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001773 : public __owns_one_state<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001774{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001775 typedef __owns_one_state<_CharT> base;
1776
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001777 _CharT __c_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001778
1779 __match_char(const __match_char&);
1780 __match_char& operator=(const __match_char&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001781public:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001782 typedef __command<_CharT> __command;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001783
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001784 __match_char(_CharT __c, __state<_CharT>* __s)
1785 : base(__s), __c_(__c) {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001786
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001787 virtual __command __test(const _CharT*, const _CharT* __c,
1788 const _CharT*,
1789 vector<size_t>&,
1790 sub_match<const _CharT*>*,
1791 regex_constants::match_flag_type) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001792
1793 virtual string speak() const
1794 {
1795 ostringstream os;
1796 os << "match char " << __c_;
1797 return os.str();
1798 }
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001799};
1800
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001801template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001802__command<_CharT>
1803__match_char<_CharT>::__test(const _CharT*, const _CharT* __c,
1804 const _CharT*,
1805 vector<size_t>&,
1806 sub_match<const _CharT*>*,
1807 regex_constants::match_flag_type) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001808{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001809 return __c_ == *__c ?
1810 __command(__command::__accept_and_consume, this->first()) : __command();
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001811}
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001812
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001813template <class, class> class match_results;
1814
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001815template <class _CharT, class _Traits = regex_traits<_CharT> >
1816class basic_regex
1817{
1818public:
1819 // types:
1820 typedef _CharT value_type;
1821 typedef regex_constants::syntax_option_type flag_type;
1822 typedef typename _Traits::locale_type locale_type;
1823
1824private:
1825 _Traits __traits_;
1826 flag_type __flags_;
1827 unsigned __marked_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001828 unsigned __loop_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001829 int __open_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001830 shared_ptr<__empty_state<_CharT> > __start_;
1831 __owns_one_state<_CharT>* __end_;
1832
1833 typedef __command<_CharT> __command;
1834 typedef __state<_CharT> __state;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001835
1836public:
1837 // constants:
1838 static const/*expr*/ regex_constants::syntax_option_type icase = regex_constants::icase;
1839 static const/*expr*/ regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
1840 static const/*expr*/ regex_constants::syntax_option_type optimize = regex_constants::optimize;
1841 static const/*expr*/ regex_constants::syntax_option_type collate = regex_constants::collate;
1842 static const/*expr*/ regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
1843 static const/*expr*/ regex_constants::syntax_option_type basic = regex_constants::basic;
1844 static const/*expr*/ regex_constants::syntax_option_type extended = regex_constants::extended;
1845 static const/*expr*/ regex_constants::syntax_option_type awk = regex_constants::awk;
1846 static const/*expr*/ regex_constants::syntax_option_type grep = regex_constants::grep;
1847 static const/*expr*/ regex_constants::syntax_option_type egrep = regex_constants::egrep;
1848
1849 // construct/copy/destroy:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001850 basic_regex()
1851 : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0)
1852 {}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001853 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001854 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001855 {__parse(__p, __p + __traits_.length(__p));}
1856 basic_regex(const value_type* __p, size_t __len, flag_type __f)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001857 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001858 {__parse(__p, __p + __len);}
1859 basic_regex(const basic_regex&);
1860#ifdef _LIBCPP_MOVE
1861 basic_regex(basic_regex&&);
1862#endif
1863 template <class _ST, class _SA>
1864 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
1865 flag_type __f = regex_constants::ECMAScript)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001866 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001867 {__parse(__p.begin(), __p.end());}
1868 template <class _ForwardIterator>
1869 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
1870 flag_type __f = regex_constants::ECMAScript)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001871 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001872 {__parse(__first, __last);}
1873 basic_regex(initializer_list<value_type> __il,
1874 flag_type __f = regex_constants::ECMAScript)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001875 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001876 {__parse(__il.begin(), __il.end());}
1877
1878 ~basic_regex();
1879
1880 basic_regex& operator=(const basic_regex&);
1881#ifdef _LIBCPP_MOVE
1882 basic_regex& operator=(basic_regex&&);
1883#endif
1884 basic_regex& operator=(const value_type* __p);
1885 basic_regex& operator=(initializer_list<value_type> __il);
1886 template <class _ST, class _SA>
1887 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p);
1888
1889 // assign:
1890 basic_regex& assign(const basic_regex& __that);
1891#ifdef _LIBCPP_MOVE
1892 basic_regex& assign(basic_regex&& __that);
1893#endif
1894 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript);
1895 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f);
1896 template <class _ST, class _SA>
1897 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
1898 flag_type __f = regex_constants::ECMAScript);
1899 template <class _InputIterator>
1900 basic_regex& assign(_InputIterator __first, _InputIterator __last,
1901 flag_type __f = regex_constants::ECMAScript);
1902 basic_regex& assign(initializer_list<value_type> __il,
1903 flag_type = regex_constants::ECMAScript);
1904
1905 // const operations:
1906 unsigned mark_count() const {return __marked_count_;}
1907 flag_type flags() const {return __flags_;}
1908
1909 // locale:
1910 locale_type imbue(locale_type __loc) {return __traits_.imbue(__loc);}
1911 locale_type getloc() const {return __traits_.getloc();}
1912
1913 // swap:
1914 void swap(basic_regex&);
1915
1916private:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001917 unsigned __loop_count() const {return __loop_count_;}
1918
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001919 template <class _ForwardIterator>
1920 void __parse(_ForwardIterator __first, _ForwardIterator __last);
1921 template <class _ForwardIterator>
1922 _ForwardIterator
1923 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
1924 template <class _ForwardIterator>
1925 _ForwardIterator
1926 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
1927 template <class _ForwardIterator>
1928 _ForwardIterator
1929 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
1930 template <class _ForwardIterator>
1931 _ForwardIterator
1932 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
1933 template <class _ForwardIterator>
1934 _ForwardIterator
1935 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
1936 template <class _ForwardIterator>
1937 _ForwardIterator
1938 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
1939 template <class _ForwardIterator>
1940 _ForwardIterator
1941 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
1942 template <class _ForwardIterator>
1943 _ForwardIterator
1944 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
1945 template <class _ForwardIterator>
1946 _ForwardIterator
1947 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
1948 template <class _ForwardIterator>
1949 _ForwardIterator
1950 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
1951 template <class _ForwardIterator>
1952 _ForwardIterator
1953 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
1954 template <class _ForwardIterator>
1955 _ForwardIterator
1956 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
1957 template <class _ForwardIterator>
1958 _ForwardIterator
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001959 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001960 __owns_one_state<_CharT>* __s,
1961 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnant0de86b62010-06-25 20:56:08 +00001962 template <class _ForwardIterator>
1963 _ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001964 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last);
1965 template <class _ForwardIterator>
1966 _ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00001967 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
1968 template <class _ForwardIterator>
1969 _ForwardIterator
1970 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last);
1971 template <class _ForwardIterator>
1972 _ForwardIterator
1973 __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last);
1974 template <class _ForwardIterator>
1975 _ForwardIterator
1976 __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last);
1977 template <class _ForwardIterator>
1978 _ForwardIterator
1979 __parse_character_class(_ForwardIterator __first, _ForwardIterator __last);
1980 template <class _ForwardIterator>
1981 _ForwardIterator
1982 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last);
1983 template <class _ForwardIterator>
1984 _ForwardIterator
1985 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001986 template <class _ForwardIterator>
1987 _ForwardIterator
1988 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
1989 template <class _ForwardIterator>
1990 _ForwardIterator
1991 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
1992 template <class _ForwardIterator>
1993 _ForwardIterator
1994 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
1995 template <class _ForwardIterator>
1996 _ForwardIterator
1997 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
1998 template <class _ForwardIterator>
1999 _ForwardIterator
2000 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2001 template <class _ForwardIterator>
2002 _ForwardIterator
2003 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002004
Howard Hinnant0de86b62010-06-25 20:56:08 +00002005 void __push_l_anchor() {}
2006 void __push_r_anchor() {}
2007 void __push_match_any() {}
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002008 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2009 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2010 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2011 __mexp_begin, __mexp_end);}
Howard Hinnant0de86b62010-06-25 20:56:08 +00002012 void __push_exact_repeat(int __count) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002013 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2014 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2015 bool __greedy = true);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002016 void __start_nonmatching_list() {}
2017 void __start_matching_list() {}
2018 void __end_nonmatching_list() {}
2019 void __end_matching_list() {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002020 void __push_char(value_type __c);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002021 void __push_char(const typename _Traits::string_type& __c) {}
2022 void __push_range() {}
2023 void __push_class_type(typename _Traits::char_class_type) {}
2024 void __push_back_ref(int __i) {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002025 void __push_alternation() {}
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002026 void __push_begin_marked_subexpression();
2027 void __push_end_marked_subexpression(unsigned);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002028
2029 template <class _BidirectionalIterator, class _Allocator>
2030 bool
2031 __search(_BidirectionalIterator __first, _BidirectionalIterator __last,
2032 match_results<_BidirectionalIterator, _Allocator>& __m,
2033 regex_constants::match_flag_type __flags) const;
2034
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002035 template <class _BidirectionalIterator, class _Allocator>
2036 bool
2037 __match_at_start(_BidirectionalIterator __first, _BidirectionalIterator __last,
2038 match_results<_BidirectionalIterator, _Allocator>& __m,
2039 vector<size_t>& __lc,
2040 regex_constants::match_flag_type __flags) const;
2041 template <class _BidirectionalIterator, class _Allocator>
2042 bool
2043 __match_at_start_ecma(_BidirectionalIterator __first, _BidirectionalIterator __last,
2044 match_results<_BidirectionalIterator, _Allocator>& __m,
2045 regex_constants::match_flag_type __flags) const;
2046 template <class _BidirectionalIterator, class _Allocator>
2047 bool
2048 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
2049 match_results<_BidirectionalIterator, _Allocator>& __m,
2050 vector<size_t>& __lc,
2051 regex_constants::match_flag_type __flags) const;
2052 template <class _BidirectionalIterator, class _Allocator>
2053 bool
2054 __match_at_start_posix_subs(_BidirectionalIterator __first, _BidirectionalIterator __last,
2055 match_results<_BidirectionalIterator, _Allocator>& __m,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002056 vector<size_t>& __lc,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002057 regex_constants::match_flag_type __flags) const;
2058
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002059 template <class _B, class _A, class _C, class _T>
2060 friend
2061 bool
2062 regex_search(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
2063 regex_constants::match_flag_type);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002064
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002065};
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002066
2067template <class _CharT, class _Traits>
2068basic_regex<_CharT, _Traits>::~basic_regex()
2069{
2070}
2071
2072template <class _CharT, class _Traits>
2073template <class _ForwardIterator>
2074void
2075basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
2076 _ForwardIterator __last)
2077{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002078 {
2079 unique_ptr<__state> __h(new __end_state<_CharT>);
2080 __start_.reset(new __empty_state<_CharT>(__h.get()));
2081 __h.release();
2082 __end_ = __start_.get();
2083 }
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002084 switch (__flags_ & 0x3F0)
2085 {
2086 case ECMAScript:
2087 break;
2088 case basic:
2089 __parse_basic_reg_exp(__first, __last);
2090 break;
2091 case extended:
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002092 __parse_extended_reg_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002093 break;
2094 case awk:
2095 break;
2096 case grep:
2097 break;
2098 case egrep:
2099 break;
2100 default:
2101 throw regex_error(regex_constants::error_temp);
2102 }
2103}
2104
2105template <class _CharT, class _Traits>
2106template <class _ForwardIterator>
2107_ForwardIterator
2108basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
2109 _ForwardIterator __last)
2110{
2111 if (__first != __last)
2112 {
2113 if (*__first == '^')
2114 {
2115 __push_l_anchor();
2116 ++__first;
2117 }
2118 if (__first != __last)
2119 {
2120 __first = __parse_RE_expression(__first, __last);
2121 if (__first != __last)
2122 {
2123 _ForwardIterator __temp = next(__first);
2124 if (__temp == __last && *__first == '$')
2125 {
2126 __push_r_anchor();
2127 ++__first;
2128 }
2129 }
2130 }
2131 if (__first != __last)
2132 throw regex_error(regex_constants::error_temp);
2133 }
2134 return __first;
2135}
2136
2137template <class _CharT, class _Traits>
2138template <class _ForwardIterator>
2139_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002140basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
2141 _ForwardIterator __last)
2142{
2143 while (true)
2144 {
2145 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
2146 if (__temp == __first)
2147 throw regex_error(regex_constants::error_temp);
2148 __first = __temp;
2149 if (__first == __last)
2150 break;
2151 if (*__first != '|')
2152 throw regex_error(regex_constants::error_temp);
2153 __push_alternation();
2154 ++__first;
2155 }
2156 return __first;
2157}
2158
2159template <class _CharT, class _Traits>
2160template <class _ForwardIterator>
2161_ForwardIterator
2162basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
2163 _ForwardIterator __last)
2164{
2165 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
2166 if (__temp == __first)
2167 throw regex_error(regex_constants::error_temp);
2168 do
2169 {
2170 __first = __temp;
2171 __temp = __parse_ERE_expression(__first, __last);
2172 } while (__temp != __first);
2173 return __first;
2174}
2175
2176template <class _CharT, class _Traits>
2177template <class _ForwardIterator>
2178_ForwardIterator
2179basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
2180 _ForwardIterator __last)
2181{
2182 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
2183 if (__temp == __first && __temp != __last)
2184 {
2185 switch (*__temp)
2186 {
2187 case '^':
2188 __push_l_anchor();
2189 ++__temp;
2190 break;
2191 case '$':
2192 __push_r_anchor();
2193 ++__temp;
2194 break;
2195 case '(':
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002196 __push_begin_marked_subexpression();
2197 unsigned __temp_count = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002198 ++__open_count_;
2199 __temp = __parse_extended_reg_exp(++__temp, __last);
2200 if (__temp == __last || *__temp != ')')
2201 throw regex_error(regex_constants::error_paren);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002202 __push_end_marked_subexpression(__temp_count);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002203 --__open_count_;
2204 ++__temp;
2205 break;
2206 }
2207 }
2208 if (__temp != __first)
2209 __temp = __parse_ERE_dupl_symbol(__temp, __last);
2210 __first = __temp;
2211 return __first;
2212}
2213
2214template <class _CharT, class _Traits>
2215template <class _ForwardIterator>
2216_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002217basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
2218 _ForwardIterator __last)
2219{
2220 while (true)
2221 {
2222 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
2223 if (__temp == __first)
2224 break;
2225 __first = __temp;
2226 }
2227 return __first;
2228}
2229
2230template <class _CharT, class _Traits>
2231template <class _ForwardIterator>
2232_ForwardIterator
2233basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
2234 _ForwardIterator __last)
2235{
2236 if (__first != __last)
2237 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002238 __owns_one_state<_CharT>* __e = __end_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002239 unsigned __mexp_begin = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002240 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
2241 if (__temp != __first)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002242 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
2243 __mexp_begin+1, __marked_count_+1);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002244 }
2245 return __first;
2246}
2247
2248template <class _CharT, class _Traits>
2249template <class _ForwardIterator>
2250_ForwardIterator
2251basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
2252 _ForwardIterator __last)
2253{
2254 _ForwardIterator __temp = __first;
2255 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
2256 if (__temp == __first)
2257 {
2258 __temp = __parse_Back_open_paren(__first, __last);
2259 if (__temp != __first)
2260 {
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002261 __push_begin_marked_subexpression();
2262 unsigned __temp_count = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002263 __first = __parse_RE_expression(__temp, __last);
2264 __temp = __parse_Back_close_paren(__first, __last);
2265 if (__temp == __first)
2266 throw regex_error(regex_constants::error_paren);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002267 __push_end_marked_subexpression(__temp_count);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002268 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002269 }
2270 else
2271 __first = __parse_BACKREF(__first, __last);
2272 }
2273 return __first;
2274}
2275
2276template <class _CharT, class _Traits>
2277template <class _ForwardIterator>
2278_ForwardIterator
2279basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
2280 _ForwardIterator __first,
2281 _ForwardIterator __last)
2282{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002283 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002284 if (__temp == __first)
2285 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002286 __temp = __parse_QUOTED_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002287 if (__temp == __first)
2288 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002289 if (__temp != __last && *__temp == '.')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002290 {
2291 __push_match_any();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002292 ++__temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002293 }
2294 else
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002295 __temp = __parse_bracket_expression(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002296 }
2297 }
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002298 __first = __temp;
2299 return __first;
2300}
2301
2302template <class _CharT, class _Traits>
2303template <class _ForwardIterator>
2304_ForwardIterator
2305basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
2306 _ForwardIterator __first,
2307 _ForwardIterator __last)
2308{
2309 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
2310 if (__temp == __first)
2311 {
2312 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
2313 if (__temp == __first)
2314 {
2315 if (__temp != __last && *__temp == '.')
2316 {
2317 __push_match_any();
2318 ++__temp;
2319 }
2320 else
2321 __temp = __parse_bracket_expression(__first, __last);
2322 }
2323 }
2324 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002325 return __first;
2326}
2327
2328template <class _CharT, class _Traits>
2329template <class _ForwardIterator>
2330_ForwardIterator
2331basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
2332 _ForwardIterator __last)
2333{
2334 if (__first != __last)
2335 {
2336 _ForwardIterator __temp = next(__first);
2337 if (__temp != __last)
2338 {
2339 if (*__first == '\\' && *__temp == '(')
2340 __first = ++__temp;
2341 }
2342 }
2343 return __first;
2344}
2345
2346template <class _CharT, class _Traits>
2347template <class _ForwardIterator>
2348_ForwardIterator
2349basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
2350 _ForwardIterator __last)
2351{
2352 if (__first != __last)
2353 {
2354 _ForwardIterator __temp = next(__first);
2355 if (__temp != __last)
2356 {
2357 if (*__first == '\\' && *__temp == ')')
2358 __first = ++__temp;
2359 }
2360 }
2361 return __first;
2362}
2363
2364template <class _CharT, class _Traits>
2365template <class _ForwardIterator>
2366_ForwardIterator
2367basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
2368 _ForwardIterator __last)
2369{
2370 if (__first != __last)
2371 {
2372 _ForwardIterator __temp = next(__first);
2373 if (__temp != __last)
2374 {
2375 if (*__first == '\\' && *__temp == '{')
2376 __first = ++__temp;
2377 }
2378 }
2379 return __first;
2380}
2381
2382template <class _CharT, class _Traits>
2383template <class _ForwardIterator>
2384_ForwardIterator
2385basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
2386 _ForwardIterator __last)
2387{
2388 if (__first != __last)
2389 {
2390 _ForwardIterator __temp = next(__first);
2391 if (__temp != __last)
2392 {
2393 if (*__first == '\\' && *__temp == '}')
2394 __first = ++__temp;
2395 }
2396 }
2397 return __first;
2398}
2399
2400template <class _CharT, class _Traits>
2401template <class _ForwardIterator>
2402_ForwardIterator
2403basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
2404 _ForwardIterator __last)
2405{
2406 if (__first != __last)
2407 {
2408 _ForwardIterator __temp = next(__first);
2409 if (__temp != __last)
2410 {
2411 if (*__first == '\\' && '1' <= *__temp && *__temp <= '9')
2412 {
2413 __push_back_ref(*__temp - '0');
2414 __first = ++__temp;
2415 }
2416 }
2417 }
2418 return __first;
2419}
2420
2421template <class _CharT, class _Traits>
2422template <class _ForwardIterator>
2423_ForwardIterator
2424basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
2425 _ForwardIterator __last)
2426{
2427 if (__first != __last)
2428 {
2429 _ForwardIterator __temp = next(__first);
2430 if (__temp == __last && *__first == '$')
2431 return __first;
2432 // Not called inside a bracket
2433 if (*__first == '.' || *__first == '\\' || *__first == '[')
2434 return __first;
Howard Hinnant0de86b62010-06-25 20:56:08 +00002435 __push_char(*__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002436 ++__first;
2437 }
2438 return __first;
2439}
2440
2441template <class _CharT, class _Traits>
2442template <class _ForwardIterator>
2443_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002444basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
2445 _ForwardIterator __last)
2446{
2447 if (__first != __last)
2448 {
2449 switch (*__first)
2450 {
2451 case '^':
2452 case '.':
2453 case '[':
2454 case '$':
2455 case '(':
2456 case '|':
2457 case '*':
2458 case '+':
2459 case '?':
2460 case '{':
2461 case '\\':
2462 break;
2463 case ')':
2464 if (__open_count_ == 0)
2465 {
2466 __push_char(*__first);
2467 ++__first;
2468 }
2469 break;
2470 default:
2471 __push_char(*__first);
2472 ++__first;
2473 break;
2474 }
2475 }
2476 return __first;
2477}
2478
2479template <class _CharT, class _Traits>
2480template <class _ForwardIterator>
2481_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002482basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
2483 _ForwardIterator __last)
2484{
2485 if (__first != __last)
2486 {
2487 _ForwardIterator __temp = next(__first);
2488 if (__temp != __last)
2489 {
2490 if (*__first == '\\')
2491 {
2492 switch (*__temp)
2493 {
2494 case '^':
2495 case '.':
2496 case '*':
2497 case '[':
2498 case '$':
2499 case '\\':
Howard Hinnant0de86b62010-06-25 20:56:08 +00002500 __push_char(*__temp);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002501 __first = ++__temp;
2502 break;
2503 }
2504 }
2505 }
2506 }
2507 return __first;
2508}
2509
2510template <class _CharT, class _Traits>
2511template <class _ForwardIterator>
2512_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002513basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
2514 _ForwardIterator __last)
2515{
2516 if (__first != __last)
2517 {
2518 _ForwardIterator __temp = next(__first);
2519 if (__temp != __last)
2520 {
2521 if (*__first == '\\')
2522 {
2523 switch (*__temp)
2524 {
2525 case '^':
2526 case '.':
2527 case '*':
2528 case '[':
2529 case '$':
2530 case '\\':
2531 case '(':
2532 case ')':
2533 case '|':
2534 case '+':
2535 case '?':
2536 case '{':
2537 __push_char(*__temp);
2538 __first = ++__temp;
2539 break;
2540 }
2541 }
2542 }
2543 }
2544 return __first;
2545}
2546
2547template <class _CharT, class _Traits>
2548template <class _ForwardIterator>
2549_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002550basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002551 _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002552 __owns_one_state<_CharT>* __s,
2553 unsigned __mexp_begin,
2554 unsigned __mexp_end)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002555{
2556 if (__first != __last)
2557 {
Howard Hinnant0de86b62010-06-25 20:56:08 +00002558 if (*__first == '*')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002559 {
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002560 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002561 ++__first;
2562 }
2563 else
2564 {
2565 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
2566 if (__temp != __first)
2567 {
2568 int __min = 0;
2569 __first = __temp;
2570 __temp = __parse_DUP_COUNT(__first, __last, __min);
2571 if (__temp == __first)
2572 throw regex_error(regex_constants::error_badbrace);
2573 __first = __temp;
2574 if (__first == __last)
2575 throw regex_error(regex_constants::error_brace);
2576 if (*__first != ',')
2577 {
2578 __temp = __parse_Back_close_brace(__first, __last);
2579 if (__temp == __first)
2580 throw regex_error(regex_constants::error_brace);
2581 __push_exact_repeat(__min);
2582 __first = __temp;
2583 }
2584 else
2585 {
2586 ++__first; // consume ','
2587 int __max = -1;
2588 __first = __parse_DUP_COUNT(__first, __last, __max);
2589 __temp = __parse_Back_close_brace(__first, __last);
2590 if (__temp == __first)
2591 throw regex_error(regex_constants::error_brace);
2592 if (__max == -1)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002593 __push_greedy_inf_repeat(__min, __s, __mexp_end, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002594 else
2595 {
2596 if (__max < __min)
2597 throw regex_error(regex_constants::error_badbrace);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002598 __push_loop(__min, __max, __s);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002599 }
2600 __first = __temp;
2601 }
2602 }
2603 }
2604 }
2605 return __first;
2606}
2607
Howard Hinnant0de86b62010-06-25 20:56:08 +00002608template <class _CharT, class _Traits>
2609template <class _ForwardIterator>
2610_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002611basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
2612 _ForwardIterator __last)
2613{
2614 if (__first != __last)
2615 {
2616 switch (*__first)
2617 {
2618 case '*':
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002619 __push_greedy_inf_repeat(0, nullptr);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002620 ++__first;
2621 break;
2622 case '+':
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002623 __push_greedy_inf_repeat(1, nullptr);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002624 ++__first;
2625 break;
2626 case '?':
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002627 __push_loop(0, 1, nullptr);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002628 ++__first;
2629 break;
2630 case '{':
2631 {
2632 int __min;
2633 _ForwardIterator __temp = __parse_DUP_COUNT(__first, __last, __min);
2634 if (__temp == __first)
2635 throw regex_error(regex_constants::error_badbrace);
2636 __first = __temp;
2637 if (__first == __last)
2638 throw regex_error(regex_constants::error_brace);
2639 switch (*__first)
2640 {
2641 case '}':
2642 __push_exact_repeat(__min);
2643 ++__first;
2644 break;
2645 case ',':
2646 if (++__first == __last)
2647 throw regex_error(regex_constants::error_badbrace);
2648 if (*__first == '}')
2649 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002650 __push_greedy_inf_repeat(__min, nullptr);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002651 ++__first;
2652 }
2653 else
2654 {
2655 int __max;
2656 __temp = __parse_DUP_COUNT(__first, __last, __max);
2657 if (__temp == __first)
2658 throw regex_error(regex_constants::error_brace);
2659 __first = __temp;
2660 if (__first == __last || *__first != '}')
2661 throw regex_error(regex_constants::error_brace);
2662 ++__first;
2663 if (__max < __min)
2664 throw regex_error(regex_constants::error_badbrace);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002665 __push_loop(__min, __max, nullptr);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002666 }
2667 default:
2668 throw regex_error(regex_constants::error_badbrace);
2669 }
2670 }
2671 break;
2672 }
2673 }
2674 return __first;
2675}
2676
2677template <class _CharT, class _Traits>
2678template <class _ForwardIterator>
2679_ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00002680basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
2681 _ForwardIterator __last)
2682{
2683 if (__first != __last && *__first == '[')
2684 {
2685 if (++__first == __last)
2686 throw regex_error(regex_constants::error_brack);
2687 bool __non_matching = false;
2688 if (*__first == '^')
2689 {
2690 ++__first;
2691 __non_matching = true;
2692 __start_nonmatching_list();
2693 }
2694 else
2695 __start_matching_list();
2696 if (__first == __last)
2697 throw regex_error(regex_constants::error_brack);
2698 if (*__first == ']')
2699 {
2700 __push_char(']');
2701 ++__first;
2702 }
2703 __first = __parse_follow_list(__first, __last);
2704 if (__first == __last)
2705 throw regex_error(regex_constants::error_brack);
2706 if (*__first == '-')
2707 {
2708 __push_char('-');
2709 ++__first;
2710 }
2711 if (__first == __last || *__first != ']')
2712 throw regex_error(regex_constants::error_brack);
2713 if (__non_matching)
2714 __end_nonmatching_list();
2715 else
2716 __end_matching_list();
2717 ++__first;
2718 }
2719 return __first;
2720}
2721
2722template <class _CharT, class _Traits>
2723template <class _ForwardIterator>
2724_ForwardIterator
2725basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
2726 _ForwardIterator __last)
2727{
2728 if (__first != __last)
2729 {
2730 while (true)
2731 {
2732 _ForwardIterator __temp = __parse_expression_term(__first, __last);
2733 if (__temp == __first)
2734 break;
2735 __first = __temp;
2736 }
2737 }
2738 return __first;
2739}
2740
2741template <class _CharT, class _Traits>
2742template <class _ForwardIterator>
2743_ForwardIterator
2744basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
2745 _ForwardIterator __last)
2746{
2747 if (__first != __last && *__first != ']')
2748 {
2749 bool __parsed_one = false;
2750 _ForwardIterator __temp = next(__first);
2751 if (__temp != __last && *__first == '[')
2752 {
2753 if (*__temp == '=')
2754 return __parse_equivalence_class(++__temp, __last);
2755 else if (*__temp == ':')
2756 return __parse_character_class(++__temp, __last);
2757 else if (*__temp == '.')
2758 {
2759 __first = __parse_collating_symbol(++__temp, __last);
2760 __parsed_one = true;
2761 }
2762 }
2763 if (!__parsed_one)
2764 {
2765 __push_char(*__first);
2766 ++__first;
2767 }
2768 if (__first != __last && *__first != ']')
2769 {
2770 __temp = next(__first);
2771 if (__temp != __last && *__first == '-' && *__temp != ']')
2772 {
2773 // parse a range
2774 __first = __temp;
2775 ++__temp;
2776 if (__temp != __last && *__first == '[' && *__temp == '.')
2777 __first = __parse_collating_symbol(++__temp, __last);
2778 else
2779 {
2780 __push_char(*__first);
2781 ++__first;
2782 }
2783 __push_range();
2784 }
2785 }
2786 }
2787 return __first;
2788}
2789
2790template <class _CharT, class _Traits>
2791template <class _ForwardIterator>
2792_ForwardIterator
2793basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
2794 _ForwardIterator __last)
2795{
2796 // Found [=
2797 // This means =] must exist
2798 value_type _Equal_close[2] = {'=', ']'};
2799 _ForwardIterator __temp = _STD::search(__first, __last, _Equal_close,
2800 _Equal_close+2);
2801 if (__temp == __last)
2802 throw regex_error(regex_constants::error_brack);
2803 // [__first, __temp) contains all text in [= ... =]
2804 typedef typename _Traits::string_type string_type;
2805 string_type __collate_name =
2806 __traits_.lookup_collatename(__first, __temp);
2807 if (__collate_name.empty())
2808 throw regex_error(regex_constants::error_brack);
2809 string_type __equiv_name =
2810 __traits_.transform_primary(__collate_name.begin(),
2811 __collate_name.end());
2812 if (!__equiv_name.empty())
2813 __push_char(__equiv_name);
2814 else
2815 __push_char(__collate_name);
2816 __first = next(__temp, 2);
2817 return __first;
2818}
2819
2820template <class _CharT, class _Traits>
2821template <class _ForwardIterator>
2822_ForwardIterator
2823basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
2824 _ForwardIterator __last)
2825{
2826 // Found [:
2827 // This means :] must exist
2828 value_type _Colon_close[2] = {':', ']'};
2829 _ForwardIterator __temp = _STD::search(__first, __last, _Colon_close,
2830 _Colon_close+2);
2831 if (__temp == __last)
2832 throw regex_error(regex_constants::error_brack);
2833 // [__first, __temp) contains all text in [: ... :]
2834 typedef typename _Traits::char_class_type char_class_type;
2835 char_class_type __class_type =
2836 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
2837 if (__class_type == 0)
2838 throw regex_error(regex_constants::error_brack);
2839 __push_class_type(__class_type);
2840 __first = next(__temp, 2);
2841 return __first;
2842}
2843
2844template <class _CharT, class _Traits>
2845template <class _ForwardIterator>
2846_ForwardIterator
2847basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
2848 _ForwardIterator __last)
2849{
2850 // Found [.
2851 // This means .] must exist
2852 value_type _Dot_close[2] = {'.', ']'};
2853 _ForwardIterator __temp = _STD::search(__first, __last, _Dot_close,
2854 _Dot_close+2);
2855 if (__temp == __last)
2856 throw regex_error(regex_constants::error_brack);
2857 // [__first, __temp) contains all text in [. ... .]
2858 typedef typename _Traits::string_type string_type;
2859 string_type __collate_name =
2860 __traits_.lookup_collatename(__first, __temp);
2861 if (__collate_name.empty())
2862 throw regex_error(regex_constants::error_brack);
2863 __push_char(__collate_name);
2864 __first = next(__temp, 2);
2865 return __first;
2866}
2867
2868template <class _CharT, class _Traits>
2869template <class _ForwardIterator>
2870_ForwardIterator
2871basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
2872 _ForwardIterator __last,
2873 int& __c)
2874{
2875 if (__first != __last && '0' <= *__first && *__first <= '9')
2876 {
2877 __c = *__first - '0';
2878 for (++__first; __first != __last && '0' <= *__first && *__first <= '9';
2879 ++__first)
2880 {
2881 __c *= 10;
2882 __c += *__first - '0';
2883 }
2884 }
2885 return __first;
2886}
2887
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002888template <class _CharT, class _Traits>
2889void
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002890basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
2891 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
2892 bool __greedy)
2893{
2894 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
2895 __end_->first() = nullptr;
2896 unique_ptr<__loop<_CharT> > __e2;
2897 if (__mexp_begin != __mexp_end)
2898 {
2899 unique_ptr<__zero_marked_exprs<_CharT> >
2900 __e3(new __zero_marked_exprs<_CharT>(__mexp_begin, __mexp_end,
2901 __s->first()));
2902 __s->first() = nullptr;
2903 __e2.reset(new __loop<_CharT>(__loop_count_, __e3.get(), __e1.get(),
2904 __greedy, __min, __max));
2905 __e3.release();
2906 __e1.release();
2907 }
2908 else
2909 {
2910 __e2.reset(new __loop<_CharT>(__loop_count_, __s->first(), __e1.get(),
2911 __greedy, __min, __max));
2912 __s->first() = nullptr;
2913 __e1.release();
2914 }
2915 __end_->first() = new __increment_loop_count<_CharT>(__loop_count_, __e2.get());
2916 __end_ = __e2->second();
2917 __s->first() = new __zero_loop_count<_CharT>(__loop_count_, __e2.get());
2918 __e2.release();
2919 ++__loop_count_;
2920}
2921
2922template <class _CharT, class _Traits>
2923void
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002924basic_regex<_CharT, _Traits>::__push_char(value_type __c)
2925{
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002926 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
2927 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002928}
2929
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002930template <class _CharT, class _Traits>
2931void
2932basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
2933{
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002934 __end_->first() = new __begin_marked_subexpression<_CharT>(++__marked_count_,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002935 __end_->first());
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002936 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002937}
2938
2939template <class _CharT, class _Traits>
2940void
2941basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
2942{
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002943 __end_->first() = new __end_marked_subexpression<_CharT>(__sub,
2944 __end_->first());
2945 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002946}
2947
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002948typedef basic_regex<char> regex;
2949typedef basic_regex<wchar_t> wregex;
2950
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002951// sub_match
2952
2953template <class _BidirectionalIterator>
2954class sub_match
2955 : public pair<_BidirectionalIterator, _BidirectionalIterator>
2956{
2957public:
2958 typedef _BidirectionalIterator iterator;
2959 typedef typename iterator_traits<iterator>::value_type value_type;
2960 typedef typename iterator_traits<iterator>::difference_type difference_type;
2961 typedef basic_string<value_type> string_type;
2962
2963 bool matched;
2964
2965 difference_type length() const
2966 {return matched ? _STD::distance(this->first, this->second) : 0;}
2967 string_type str() const
2968 {return matched ? string_type(this->first, this->second) : string_type();}
2969 operator string_type() const
2970 {return str();}
2971
2972 int compare(const sub_match& __s) const
2973 {return str().compare(__s.str());}
2974 int compare(const string_type& __s) const
2975 {return str().compare(__s);}
2976 int compare(const value_type* __s) const
2977 {return str().compare(__s);}
2978};
2979
2980typedef sub_match<const char*> csub_match;
2981typedef sub_match<const wchar_t*> wcsub_match;
2982typedef sub_match<string::const_iterator> ssub_match;
2983typedef sub_match<wstring::const_iterator> wssub_match;
2984
2985template <class _BiIter>
2986inline _LIBCPP_INLINE_VISIBILITY
2987bool
2988operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
2989{
2990 return __x.compare(__y) == 0;
2991}
2992
2993template <class _BiIter>
2994inline _LIBCPP_INLINE_VISIBILITY
2995bool
2996operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
2997{
2998 return !(__x == __y);
2999}
3000
3001template <class _BiIter>
3002inline _LIBCPP_INLINE_VISIBILITY
3003bool
3004operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
3005{
3006 return __x.compare(__y) < 0;
3007}
3008
3009template <class _BiIter>
3010inline _LIBCPP_INLINE_VISIBILITY
3011bool
3012operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
3013{
3014 return !(__y < __x);
3015}
3016
3017template <class _BiIter>
3018inline _LIBCPP_INLINE_VISIBILITY
3019bool
3020operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
3021{
3022 return !(__x < __y);
3023}
3024
3025template <class _BiIter>
3026inline _LIBCPP_INLINE_VISIBILITY
3027bool
3028operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
3029{
3030 return __y < __x;
3031}
3032
3033template <class _BiIter, class _ST, class _SA>
3034inline _LIBCPP_INLINE_VISIBILITY
3035bool
3036operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
3037 const sub_match<_BiIter>& __y)
3038{
3039 return __y.compare(__x.c_str()) == 0;
3040}
3041
3042template <class _BiIter, class _ST, class _SA>
3043inline _LIBCPP_INLINE_VISIBILITY
3044bool
3045operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
3046 const sub_match<_BiIter>& __y)
3047{
3048 return !(__x == __y);
3049}
3050
3051template <class _BiIter, class _ST, class _SA>
3052inline _LIBCPP_INLINE_VISIBILITY
3053bool
3054operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
3055 const sub_match<_BiIter>& __y)
3056{
3057 return __y.compare(__x.c_str()) > 0;
3058}
3059
3060template <class _BiIter, class _ST, class _SA>
3061inline _LIBCPP_INLINE_VISIBILITY
3062bool
3063operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
3064 const sub_match<_BiIter>& __y)
3065{
3066 return __y < __x;
3067}
3068
3069template <class _BiIter, class _ST, class _SA>
3070inline _LIBCPP_INLINE_VISIBILITY
3071bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
3072 const sub_match<_BiIter>& __y)
3073{
3074 return !(__x < __y);
3075}
3076
3077template <class _BiIter, class _ST, class _SA>
3078inline _LIBCPP_INLINE_VISIBILITY
3079bool
3080operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
3081 const sub_match<_BiIter>& __y)
3082{
3083 return !(__y < __x);
3084}
3085
3086template <class _BiIter, class _ST, class _SA>
3087inline _LIBCPP_INLINE_VISIBILITY
3088bool
3089operator==(const sub_match<_BiIter>& __x,
3090 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
3091{
3092 return __x.compare(__y.c_str()) == 0;
3093}
3094
3095template <class _BiIter, class _ST, class _SA>
3096inline _LIBCPP_INLINE_VISIBILITY
3097bool
3098operator!=(const sub_match<_BiIter>& __x,
3099 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
3100{
3101 return !(__x == __y);
3102}
3103
3104template <class _BiIter, class _ST, class _SA>
3105inline _LIBCPP_INLINE_VISIBILITY
3106bool
3107operator<(const sub_match<_BiIter>& __x,
3108 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
3109{
3110 return __x.compare(__y.c_str()) < 0;
3111}
3112
3113template <class _BiIter, class _ST, class _SA>
3114inline _LIBCPP_INLINE_VISIBILITY
3115bool operator>(const sub_match<_BiIter>& __x,
3116 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
3117{
3118 return __y < __x;
3119}
3120
3121template <class _BiIter, class _ST, class _SA>
3122inline _LIBCPP_INLINE_VISIBILITY
3123bool
3124operator>=(const sub_match<_BiIter>& __x,
3125 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
3126{
3127 return !(__x < __y);
3128}
3129
3130template <class _BiIter, class _ST, class _SA>
3131inline _LIBCPP_INLINE_VISIBILITY
3132bool
3133operator<=(const sub_match<_BiIter>& __x,
3134 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
3135{
3136 return !(__y < __x);
3137}
3138
3139template <class _BiIter>
3140inline _LIBCPP_INLINE_VISIBILITY
3141bool
3142operator==(typename iterator_traits<_BiIter>::value_type const* __x,
3143 const sub_match<_BiIter>& __y)
3144{
3145 return __y.compare(__x) == 0;
3146}
3147
3148template <class _BiIter>
3149inline _LIBCPP_INLINE_VISIBILITY
3150bool
3151operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
3152 const sub_match<_BiIter>& __y)
3153{
3154 return !(__x == __y);
3155}
3156
3157template <class _BiIter>
3158inline _LIBCPP_INLINE_VISIBILITY
3159bool
3160operator<(typename iterator_traits<_BiIter>::value_type const* __x,
3161 const sub_match<_BiIter>& __y)
3162{
3163 return __y.compare(__x) > 0;
3164}
3165
3166template <class _BiIter>
3167inline _LIBCPP_INLINE_VISIBILITY
3168bool
3169operator>(typename iterator_traits<_BiIter>::value_type const* __x,
3170 const sub_match<_BiIter>& __y)
3171{
3172 return __y < __x;
3173}
3174
3175template <class _BiIter>
3176inline _LIBCPP_INLINE_VISIBILITY
3177bool
3178operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
3179 const sub_match<_BiIter>& __y)
3180{
3181 return !(__x < __y);
3182}
3183
3184template <class _BiIter>
3185inline _LIBCPP_INLINE_VISIBILITY
3186bool
3187operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
3188 const sub_match<_BiIter>& __y)
3189{
3190 return !(__y < __x);
3191}
3192
3193template <class _BiIter>
3194inline _LIBCPP_INLINE_VISIBILITY
3195bool
3196operator==(const sub_match<_BiIter>& __x,
3197 typename iterator_traits<_BiIter>::value_type const* __y)
3198{
3199 return __x.compare(__y) == 0;
3200}
3201
3202template <class _BiIter>
3203inline _LIBCPP_INLINE_VISIBILITY
3204bool
3205operator!=(const sub_match<_BiIter>& __x,
3206 typename iterator_traits<_BiIter>::value_type const* __y)
3207{
3208 return !(__x == __y);
3209}
3210
3211template <class _BiIter>
3212inline _LIBCPP_INLINE_VISIBILITY
3213bool
3214operator<(const sub_match<_BiIter>& __x,
3215 typename iterator_traits<_BiIter>::value_type const* __y)
3216{
3217 return __x.compare(__y) < 0;
3218}
3219
3220template <class _BiIter>
3221inline _LIBCPP_INLINE_VISIBILITY
3222bool
3223operator>(const sub_match<_BiIter>& __x,
3224 typename iterator_traits<_BiIter>::value_type const* __y)
3225{
3226 return __y < __x;
3227}
3228
3229template <class _BiIter>
3230inline _LIBCPP_INLINE_VISIBILITY
3231bool
3232operator>=(const sub_match<_BiIter>& __x,
3233 typename iterator_traits<_BiIter>::value_type const* __y)
3234{
3235 return !(__x < __y);
3236}
3237
3238template <class _BiIter>
3239inline _LIBCPP_INLINE_VISIBILITY
3240bool
3241operator<=(const sub_match<_BiIter>& __x,
3242 typename iterator_traits<_BiIter>::value_type const* __y)
3243{
3244 return !(__y < __x);
3245}
3246
3247template <class _BiIter>
3248inline _LIBCPP_INLINE_VISIBILITY
3249bool
3250operator==(typename iterator_traits<_BiIter>::value_type const& __x,
3251 const sub_match<_BiIter>& __y)
3252{
3253 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
3254 return __y.compare(string_type(1, __x)) == 0;
3255}
3256
3257template <class _BiIter>
3258inline _LIBCPP_INLINE_VISIBILITY
3259bool
3260operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
3261 const sub_match<_BiIter>& __y)
3262{
3263 return !(__x == __y);
3264}
3265
3266template <class _BiIter>
3267inline _LIBCPP_INLINE_VISIBILITY
3268bool
3269operator<(typename iterator_traits<_BiIter>::value_type const& __x,
3270 const sub_match<_BiIter>& __y)
3271{
3272 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
3273 return __y.compare(string_type(1, __x)) > 0;
3274}
3275
3276template <class _BiIter>
3277inline _LIBCPP_INLINE_VISIBILITY
3278bool
3279operator>(typename iterator_traits<_BiIter>::value_type const& __x,
3280 const sub_match<_BiIter>& __y)
3281{
3282 return __y < __x;
3283}
3284
3285template <class _BiIter>
3286inline _LIBCPP_INLINE_VISIBILITY
3287bool
3288operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
3289 const sub_match<_BiIter>& __y)
3290{
3291 return !(__x < __y);
3292}
3293
3294template <class _BiIter>
3295inline _LIBCPP_INLINE_VISIBILITY
3296bool
3297operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
3298 const sub_match<_BiIter>& __y)
3299{
3300 return !(__y < __x);
3301}
3302
3303template <class _BiIter>
3304inline _LIBCPP_INLINE_VISIBILITY
3305bool
3306operator==(const sub_match<_BiIter>& __x,
3307 typename iterator_traits<_BiIter>::value_type const& __y)
3308{
3309 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
3310 return __x.compare(string_type(1, __y)) == 0;
3311}
3312
3313template <class _BiIter>
3314inline _LIBCPP_INLINE_VISIBILITY
3315bool
3316operator!=(const sub_match<_BiIter>& __x,
3317 typename iterator_traits<_BiIter>::value_type const& __y)
3318{
3319 return !(__x == __y);
3320}
3321
3322template <class _BiIter>
3323inline _LIBCPP_INLINE_VISIBILITY
3324bool
3325operator<(const sub_match<_BiIter>& __x,
3326 typename iterator_traits<_BiIter>::value_type const& __y)
3327{
3328 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
3329 return __x.compare(string_type(1, __y)) < 0;
3330}
3331
3332template <class _BiIter>
3333inline _LIBCPP_INLINE_VISIBILITY
3334bool
3335operator>(const sub_match<_BiIter>& __x,
3336 typename iterator_traits<_BiIter>::value_type const& __y)
3337{
3338 return __y < __x;
3339}
3340
3341template <class _BiIter>
3342inline _LIBCPP_INLINE_VISIBILITY
3343bool
3344operator>=(const sub_match<_BiIter>& __x,
3345 typename iterator_traits<_BiIter>::value_type const& __y)
3346{
3347 return !(__x < __y);
3348}
3349
3350template <class _BiIter>
3351inline _LIBCPP_INLINE_VISIBILITY
3352bool
3353operator<=(const sub_match<_BiIter>& __x,
3354 typename iterator_traits<_BiIter>::value_type const& __y)
3355{
3356 return !(__y < __x);
3357}
3358
3359template <class _CharT, class _ST, class _BiIter>
3360inline _LIBCPP_INLINE_VISIBILITY
3361basic_ostream<_CharT, _ST>&
3362operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
3363{
3364 return __os << __m.str();
3365}
3366
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00003367template <class _BidirectionalIterator,
3368 class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
3369class match_results
3370{
3371public:
3372 typedef _Allocator allocator_type;
3373 typedef sub_match<_BidirectionalIterator> value_type;
3374private:
3375 typedef vector<value_type, allocator_type> __container_type;
3376
3377 __container_type __matches_;
3378 value_type __unmatched_;
3379 value_type __prefix_;
3380 value_type __suffix_;
3381public:
3382 typedef const value_type& const_reference;
3383 typedef const_reference reference;
3384 typedef typename __container_type::const_iterator const_iterator;
3385 typedef const_iterator iterator;
3386 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
3387 typedef typename allocator_traits<allocator_type>::size_type size_type;
3388 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
3389 typedef basic_string<char_type> string_type;
3390
3391 // construct/copy/destroy:
3392 explicit match_results(const allocator_type& __a = allocator_type());
3393// match_results(const match_results&) = default;
3394// match_results& operator=(const match_results&) = default;
3395#ifdef _LIBCPP_MOVE
3396// match_results(match_results&& __m) = default;
3397// match_results& operator=(match_results&& __m) = default;
3398#endif
3399// ~match_results() = default;
3400
3401 // size:
3402 size_type size() const {return __matches_.size();}
3403 size_type max_size() const {return __matches_.max_size();}
3404 bool empty() const {return size() == 0;}
3405
3406 // element access:
3407 difference_type length(size_type __sub = 0) const
3408 {return (*this)[__sub].length();}
3409 difference_type position(size_type __sub = 0) const
3410 {return _STD::distance(__prefix_.first, (*this)[__sub].first);}
3411 string_type str(size_type __sub = 0) const
3412 {return (*this)[__sub].str();}
3413 const_reference operator[](size_type __n) const
3414 {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
3415
3416 const_reference prefix() const {return __prefix_;}
3417 const_reference suffix() const {return __suffix_;}
3418
3419 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
3420 const_iterator end() const {return __matches_.end();}
3421 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin() + 1;}
3422 const_iterator cend() const {return __matches_.end();}
3423
3424 // format:
3425 template <class _OutputIter>
3426 _OutputIter
3427 format(_OutputIter __out, const char_type* __fmt_first,
3428 const char_type* __fmt_last,
3429 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
3430 template <class _OutputIter, class _ST, class _SA>
3431 _OutputIter
3432 format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt,
3433 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
3434 template <class _ST, class _SA>
3435 basic_string<char_type, _ST, _SA>
3436 format(const basic_string<char_type, _ST, _SA>& __fmt,
3437 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
3438 string_type
3439 format(const char_type* __fmt,
3440 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
3441
3442 // allocator:
3443 allocator_type get_allocator() const {return __matches_.get_allocator();}
3444
3445 // swap:
3446 void swap(match_results& __m);
3447
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003448private:
3449 void __init(unsigned __s,
3450 _BidirectionalIterator __f, _BidirectionalIterator __l);
3451
3452 template <class, class> friend class basic_regex;
3453
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00003454 template <class _B, class _A, class _C, class _T>
3455 friend
3456 bool
3457 regex_match(_B, _B, match_results<_B, _A>&, const basic_regex<_C, _T>&,
3458 regex_constants::match_flag_type);
3459};
3460
3461template <class _BidirectionalIterator, class _Allocator>
3462match_results<_BidirectionalIterator, _Allocator>::match_results(
3463 const allocator_type& __a)
3464 : __matches_(__a),
3465 __unmatched_(),
3466 __prefix_(),
3467 __suffix_()
3468{
3469}
3470
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003471template <class _BidirectionalIterator, class _Allocator>
3472void
3473match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
3474 _BidirectionalIterator __f, _BidirectionalIterator __l)
3475{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003476 __unmatched_.first = __l;
3477 __unmatched_.second = __l;
3478 __unmatched_.matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003479 __matches_.assign(__s, __unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003480 __prefix_.first = __f;
3481 __prefix_.second = __f;
3482 __prefix_.matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003483 __suffix_ = __unmatched_;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003484}
3485
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00003486typedef match_results<const char*> cmatch;
3487typedef match_results<const wchar_t*> wcmatch;
3488typedef match_results<string::const_iterator> smatch;
3489typedef match_results<wstring::const_iterator> wsmatch;
3490
3491template <class _BidirectionalIterator, class _Allocator>
3492 bool
3493 operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
3494 const match_results<_BidirectionalIterator, _Allocator>& __y);
3495
3496template <class _BidirectionalIterator, class _Allocator>
3497 bool
3498 operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
3499 const match_results<_BidirectionalIterator, _Allocator>& __y);
3500
3501template <class _BidirectionalIterator, class _Allocator>
3502 void
3503 swap(match_results<_BidirectionalIterator, _Allocator>& __x,
3504 match_results<_BidirectionalIterator, _Allocator>& __y);
3505
3506// regex_search
3507
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003508template <class _CharT, class _Traits>
3509template <class _BidirectionalIterator, class _Allocator>
3510bool
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003511basic_regex<_CharT, _Traits>::__match_at_start_ecma(
3512 _BidirectionalIterator __first, _BidirectionalIterator __last,
3513 match_results<_BidirectionalIterator, _Allocator>& __m,
3514 regex_constants::match_flag_type __flags) const
3515{
3516 return false;
3517}
3518
3519template <class _CharT, class _Traits>
3520template <class _BidirectionalIterator, class _Allocator>
3521bool
3522basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
3523 const _CharT* __first, const _CharT* __last,
3524 match_results<_BidirectionalIterator, _Allocator>& __m,
3525 vector<size_t>& __lc,
3526 regex_constants::match_flag_type __flags) const
3527{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003528 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
3529 __split_buffer<__command> __commands;
3530 difference_type __j = 0;
3531 difference_type __highest_j = 0;
3532 difference_type _N = _STD::distance(__first, __last);
3533 __state* __st = __start_.get();
3534 if (__st)
3535 {
3536 __commands.push_front(__command(__st));
3537 __commands.push_front(__command(__command::__consume_input));
3538 _BidirectionalIterator __current = __first;
3539 do
3540 {
3541 __command __cmd = __commands.back();
3542 __commands.pop_back();
3543 if (__cmd.first != nullptr)
3544 __cmd = __cmd.first->__test(__first, __current, __last, __lc,
3545 __m.__matches_.data(), __flags);
3546 switch (__cmd.__do_)
3547 {
3548 case __command::__end_state:
3549 __highest_j = _STD::max(__highest_j, __j);
3550 break;
3551 case __command::__consume_input:
3552 if (__j == _N)
3553 return false;
3554 ++__current;
3555 if (++__j != _N && !__commands.empty())
3556 __commands.push_front(__command(__command::__consume_input));
3557 break;
3558 case __command::__accept_and_consume:
3559 __commands.push_front(__command(__cmd.first));
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003560 break;
3561 case __command::__accept_but_not_consume:
3562 __commands.push_back(__command(__cmd.first));
3563 if (__cmd.second != nullptr)
3564 __commands.push_back(__command(__cmd.second));
3565 break;
3566 case __command::__reject:
3567 break;
3568 default:
3569 throw regex_error(regex_constants::error_temp);
3570 break;
3571 }
3572 } while (!__commands.empty());
3573 if (__highest_j != 0)
3574 {
3575 __m.__matches_[0].first = __first;
3576 __m.__matches_[0].second = _STD::next(__first, __highest_j);
3577 __m.__matches_[0].matched = true;
3578 return true;
3579 }
3580 }
3581 return false;
3582}
3583
3584template <class _CharT, class _Traits>
3585template <class _BidirectionalIterator, class _Allocator>
3586bool
3587basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
3588 _BidirectionalIterator __first, _BidirectionalIterator __last,
3589 match_results<_BidirectionalIterator, _Allocator>& __m,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003590 vector<size_t>& __lc,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003591 regex_constants::match_flag_type __flags) const
3592{
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003593 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
3594 vector<__command> __commands;
3595 vector<_BidirectionalIterator> __current_stack;
3596 vector<sub_match<_BidirectionalIterator> > __saved_matches;
3597 vector<sub_match<_BidirectionalIterator> > __best_matches;
3598 difference_type __j = 0;
3599 difference_type __highest_j = 0;
3600 difference_type _N = _STD::distance(__first, __last);
3601 __state* __st = __start_.get();
3602 if (__st)
3603 {
3604 __commands.push_back(__command(__st));
3605 _BidirectionalIterator __current = __first;
3606 do
3607 {
3608 __command __cmd = __commands.back();
3609 __commands.pop_back();
3610 if (__cmd.first != nullptr)
3611 __cmd = __cmd.first->__test(__first, __current, __last, __lc,
3612 __m.__matches_.data(), __flags);
3613 switch (__cmd.__do_)
3614 {
3615 case __command::__end_state:
3616 if (__highest_j < __j)
3617 {
3618 __highest_j = __j;
3619 for (unsigned __i = 1; __i < __m.__matches_.size(); ++__i)
3620 __best_matches.push_back(__m.__matches_[__i]);
3621 }
3622 break;
3623 case __command::__pop_state:
3624 for (unsigned __i = __m.__matches_.size(); __i > 1;)
3625 {
3626 assert(!__saved_matches.empty());
3627 __m.__matches_[--__i] = __saved_matches.back();
3628 __saved_matches.pop_back();
3629 }
3630 assert(!__current_stack.empty());
3631 __current = __current_stack.back();
3632 __current_stack.pop_back();
3633 break;
3634 case __command::__accept_and_consume:
3635 __commands.push_back(__command(__cmd.first));
3636 if (__current != __last)
3637 {
3638 ++__current;
3639 ++__j;
3640 }
3641 break;
3642 case __command::__accept_but_not_consume:
3643 if (__cmd.second != nullptr)
3644 {
3645 __commands.push_back(__command(__cmd.second));
3646 __commands.push_back(__command(__command::__pop_state));
3647 __current_stack.push_back(__current);
3648 for (unsigned __i = 1; __i < __m.__matches_.size(); ++__i)
3649 __saved_matches.push_back(__m.__matches_[__i]);
3650 }
3651 __commands.push_back(__command(__cmd.first));
3652 break;
3653 case __command::__reject:
3654 break;
3655 default:
3656 throw regex_error(regex_constants::error_temp);
3657 break;
3658 }
3659 } while (!__commands.empty());
3660 if (__highest_j != 0)
3661 {
3662 __m.__matches_[0].first = __first;
3663 __m.__matches_[0].second = _STD::next(__first, __highest_j);
3664 __m.__matches_[0].matched = true;
3665 for (unsigned __i = __m.__matches_.size(); __i > 1;)
3666 {
3667 assert(!__best_matches.empty());
3668 __m.__matches_[--__i] = __best_matches.back();
3669 __best_matches.pop_back();
3670 }
3671 return true;
3672 }
3673 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003674 return false;
3675}
3676
3677template <class _CharT, class _Traits>
3678template <class _BidirectionalIterator, class _Allocator>
3679bool
3680basic_regex<_CharT, _Traits>::__match_at_start(
3681 _BidirectionalIterator __first, _BidirectionalIterator __last,
3682 match_results<_BidirectionalIterator, _Allocator>& __m,
3683 vector<size_t>& __lc,
3684 regex_constants::match_flag_type __flags) const
3685{
3686 if (__flags_ & ECMAScript)
3687 return __match_at_start_ecma(__first, __last, __m, __flags);
3688 if (mark_count() == 0)
3689 return __match_at_start_posix_nosubs(__first, __last, __m, __lc, __flags);
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003690 return __match_at_start_posix_subs(__first, __last, __m, __lc, __flags);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003691}
3692
3693template <class _CharT, class _Traits>
3694template <class _BidirectionalIterator, class _Allocator>
3695bool
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003696basic_regex<_CharT, _Traits>::__search(
3697 _BidirectionalIterator __first, _BidirectionalIterator __last,
3698 match_results<_BidirectionalIterator, _Allocator>& __m,
3699 regex_constants::match_flag_type __flags) const
3700{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003701 __m.__init(1 + mark_count(), __first, __last);
3702 vector<size_t> __lc(__loop_count());
3703 if (__match_at_start(__first, __last, __m, __lc, __flags))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003704 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003705 __m.__prefix_.second = __m[0].first;
3706 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
3707 __m.__suffix_.first = __m[0].second;
3708 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
3709 return true;
3710 }
3711 if (!(__flags & regex_constants::match_continuous))
3712 {
3713 __m.__matches_.assign(__m.size(), __m.__unmatched_);
3714 for (++__first; __first != __last; ++__first)
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003715 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003716 if (__match_at_start(__first, __last, __m, __lc, __flags))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003717 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003718 __m.__prefix_.second = __m[0].first;
3719 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
3720 __m.__suffix_.first = __m[0].second;
3721 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
3722 return true;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003723 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003724 __m.__matches_.assign(__m.size(), __m.__unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003725 }
3726 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003727 __m.__matches_.clear();
3728 return false;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003729}
3730
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00003731template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003732inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00003733bool
3734regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
3735 match_results<_BidirectionalIterator, _Allocator>& __m,
3736 const basic_regex<_CharT, _Traits>& __e,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00003737 regex_constants::match_flag_type __flags = regex_constants::match_default)
3738{
3739 return __e.__search(__first, __last, __m, __flags);
3740}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00003741
3742template <class _BidirectionalIterator, class _CharT, class _Traits>
3743inline _LIBCPP_INLINE_VISIBILITY
3744bool
3745regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
3746 const basic_regex<_CharT, _Traits>& __e,
3747 regex_constants::match_flag_type __flags = regex_constants::match_default)
3748{
3749 match_results<_BidirectionalIterator> __m;
3750 return _STD::regex_search(__first, __last, __m, __e, __flags);
3751}
3752
3753template <class _CharT, class _Allocator, class _Traits>
3754inline _LIBCPP_INLINE_VISIBILITY
3755bool
3756regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
3757 const basic_regex<_CharT, _Traits>& __e,
3758 regex_constants::match_flag_type __flags = regex_constants::match_default)
3759{
3760 return _STD::regex_search(__str, __str + _Traits::length(__str), __m, __e, __flags);
3761}
3762
3763template <class _CharT, class _Traits>
3764inline _LIBCPP_INLINE_VISIBILITY
3765bool
3766regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
3767 regex_constants::match_flag_type __flags = regex_constants::match_default)
3768{
3769 return _STD::regex_search(__str, __str + _Traits::length(__str), __e, __flags);
3770}
3771
3772template <class _ST, class _SA, class _CharT, class _Traits>
3773inline _LIBCPP_INLINE_VISIBILITY
3774bool
3775regex_search(const basic_string<_CharT, _ST, _SA>& __s,
3776 const basic_regex<_CharT, _Traits>& __e,
3777 regex_constants::match_flag_type __flags = regex_constants::match_default)
3778{
3779 return _STD::regex_search(__s.begin(), __s.end(), __e, __flags);
3780}
3781
3782template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
3783inline _LIBCPP_INLINE_VISIBILITY
3784bool
3785regex_search(const basic_string<_CharT, _ST, _SA>& __s,
3786 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
3787 const basic_regex<_CharT, _Traits>& __e,
3788 regex_constants::match_flag_type __flags = regex_constants::match_default)
3789{
3790 return _STD::regex_search(__s.begin(), __s.end(), __m, __e, __flags);
3791}
3792
3793// regex_match
3794
3795template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
3796bool
3797regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
3798 match_results<_BidirectionalIterator, _Allocator>& __m,
3799 const basic_regex<_CharT, _Traits>& __e,
3800 regex_constants::match_flag_type __flags = regex_constants::match_default)
3801{
3802 bool __r = _STD::regex_search(__first, __last, __m, __e,
3803 __flags | regex_constants::match_continuous);
3804 if (__r)
3805 {
3806 __r = !__m.suffix().matched;
3807 if (!__r)
3808 __m.__matches_.clear();
3809 }
3810 return __r;
3811}
3812
3813template <class _BidirectionalIterator, class _CharT, class _Traits>
3814inline _LIBCPP_INLINE_VISIBILITY
3815bool
3816regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
3817 const basic_regex<_CharT, _Traits>& __e,
3818 regex_constants::match_flag_type __flags = regex_constants::match_default)
3819{
3820 match_results<_BidirectionalIterator> __m;
3821 return _STD::regex_match(__first, __last, __m, __e, __flags);
3822}
3823
3824template <class _CharT, class _Allocator, class _Traits>
3825inline _LIBCPP_INLINE_VISIBILITY
3826bool
3827regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
3828 const basic_regex<_CharT, _Traits>& __e,
3829 regex_constants::match_flag_type __flags = regex_constants::match_default)
3830{
3831 return _STD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
3832}
3833
3834template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
3835inline _LIBCPP_INLINE_VISIBILITY
3836bool
3837regex_match(const basic_string<_CharT, _ST, _SA>& __s,
3838 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
3839 const basic_regex<_CharT, _Traits>& __e,
3840 regex_constants::match_flag_type __flags = regex_constants::match_default)
3841{
3842 return _STD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
3843}
3844
3845template <class _CharT, class _Traits>
3846inline _LIBCPP_INLINE_VISIBILITY
3847bool
3848regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
3849 regex_constants::match_flag_type __flags = regex_constants::match_default)
3850{
3851 return _STD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
3852}
3853
3854template <class _ST, class _SA, class _CharT, class _Traits>
3855inline _LIBCPP_INLINE_VISIBILITY
3856bool
3857regex_match(const basic_string<_CharT, _ST, _SA>& __s,
3858 const basic_regex<_CharT, _Traits>& __e,
3859 regex_constants::match_flag_type __flags = regex_constants::match_default)
3860{
3861 return _STD::regex_match(__s.begin(), __s.end(), __e, __flags);
3862}
3863
Howard Hinnant3257c982010-06-17 00:34:59 +00003864_LIBCPP_END_NAMESPACE_STD
3865
3866#endif // _LIBCPP_REGEX