2 //===--------------------------- regex ------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
17 #include <initializer_list>
22 namespace regex_constants
25 emum syntax_option_type
29 optimize = unspecified,
30 collate = unspecified,
31 ECMAScript = unspecified,
33 extended = unspecified,
39 constexpr syntax_option_type operator~(syntax_option_type f);
40 constexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs);
41 constexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs);
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,
55 format_sed = unspecified,
56 format_no_copy = unspecified,
57 format_first_only = unspecified
60 constexpr match_flag_type operator~(match_flag_type f);
61 constexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs);
62 constexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs);
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
84 : public runtime_error
87 explicit regex_error(regex_constants::error_type ecode);
88 regex_constants::error_type code() const;
91 template <class charT>
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;
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>
107 transform(ForwardIterator first, ForwardIterator last) const;
108 template <class ForwardIterator>
110 transform_primary( ForwardIterator first, ForwardIterator last) const;
111 template <class ForwardIterator>
113 lookup_collatename(ForwardIterator first, ForwardIterator last) const;
114 template <class ForwardIterator>
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;
124 template <class charT, class traits = regex_traits<charT>>
129 typedef charT value_type;
130 typedef regex_constants::syntax_option_type flag_type;
131 typedef typename traits::locale_type locale_type;
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;
145 // construct/copy/destroy:
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&&) noexcept;
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);
161 basic_regex& operator=(const basic_regex&);
162 basic_regex& operator=(basic_regex&&) noexcept;
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);
169 basic_regex& assign(const basic_regex& that);
170 basic_regex& assign(basic_regex&& that) noexcept;
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);
182 unsigned mark_count() const;
183 flag_type flags() const;
186 locale_type imbue(locale_type loc);
187 locale_type getloc() const;
190 void swap(basic_regex&);
193 typedef basic_regex<char> regex;
194 typedef basic_regex<wchar_t> wregex;
196 template <class charT, class traits>
197 void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
199 template <class BidirectionalIterator>
201 : public pair<BidirectionalIterator, BidirectionalIterator>
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;
211 constexpr sub_match();
213 difference_type length() const;
214 operator string_type() const;
215 string_type str() const;
217 int compare(const sub_match& s) const;
218 int compare(const string_type& s) const;
219 int compare(const value_type* s) const;
222 typedef sub_match<const char*> csub_match;
223 typedef sub_match<const wchar_t*> wcsub_match;
224 typedef sub_match<string::const_iterator> ssub_match;
225 typedef sub_match<wstring::const_iterator> wssub_match;
227 template <class BiIter>
229 operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
231 template <class BiIter>
233 operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
235 template <class BiIter>
237 operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
239 template <class BiIter>
241 operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
243 template <class BiIter>
245 operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
247 template <class BiIter>
249 operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
251 template <class BiIter, class ST, class SA>
253 operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
254 const sub_match<BiIter>& rhs);
256 template <class BiIter, class ST, class SA>
258 operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
259 const sub_match<BiIter>& rhs);
261 template <class BiIter, class ST, class SA>
263 operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
264 const sub_match<BiIter>& rhs);
266 template <class BiIter, class ST, class SA>
268 operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
269 const sub_match<BiIter>& rhs);
271 template <class BiIter, class ST, class SA>
272 bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
273 const sub_match<BiIter>& rhs);
275 template <class BiIter, class ST, class SA>
277 operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
278 const sub_match<BiIter>& rhs);
280 template <class BiIter, class ST, class SA>
282 operator==(const sub_match<BiIter>& lhs,
283 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
285 template <class BiIter, class ST, class SA>
287 operator!=(const sub_match<BiIter>& lhs,
288 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
290 template <class BiIter, class ST, class SA>
292 operator<(const sub_match<BiIter>& lhs,
293 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
295 template <class BiIter, class ST, class SA>
296 bool operator>(const sub_match<BiIter>& lhs,
297 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
299 template <class BiIter, class ST, class SA>
301 operator>=(const sub_match<BiIter>& lhs,
302 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
304 template <class BiIter, class ST, class SA>
306 operator<=(const sub_match<BiIter>& lhs,
307 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
309 template <class BiIter>
311 operator==(typename iterator_traits<BiIter>::value_type const* lhs,
312 const sub_match<BiIter>& rhs);
314 template <class BiIter>
316 operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
317 const sub_match<BiIter>& rhs);
319 template <class BiIter>
321 operator<(typename iterator_traits<BiIter>::value_type const* lhs,
322 const sub_match<BiIter>& rhs);
324 template <class BiIter>
326 operator>(typename iterator_traits<BiIter>::value_type const* lhs,
327 const sub_match<BiIter>& rhs);
329 template <class BiIter>
331 operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
332 const sub_match<BiIter>& rhs);
334 template <class BiIter>
336 operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
337 const sub_match<BiIter>& rhs);
339 template <class BiIter>
341 operator==(const sub_match<BiIter>& lhs,
342 typename iterator_traits<BiIter>::value_type const* rhs);
344 template <class BiIter>
346 operator!=(const sub_match<BiIter>& lhs,
347 typename iterator_traits<BiIter>::value_type const* rhs);
349 template <class BiIter>
351 operator<(const sub_match<BiIter>& lhs,
352 typename iterator_traits<BiIter>::value_type const* rhs);
354 template <class BiIter>
356 operator>(const sub_match<BiIter>& lhs,
357 typename iterator_traits<BiIter>::value_type const* rhs);
359 template <class BiIter>
361 operator>=(const sub_match<BiIter>& lhs,
362 typename iterator_traits<BiIter>::value_type const* rhs);
364 template <class BiIter>
366 operator<=(const sub_match<BiIter>& lhs,
367 typename iterator_traits<BiIter>::value_type const* rhs);
369 template <class BiIter>
371 operator==(typename iterator_traits<BiIter>::value_type const& lhs,
372 const sub_match<BiIter>& rhs);
374 template <class BiIter>
376 operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
377 const sub_match<BiIter>& rhs);
379 template <class BiIter>
381 operator<(typename iterator_traits<BiIter>::value_type const& lhs,
382 const sub_match<BiIter>& rhs);
384 template <class BiIter>
386 operator>(typename iterator_traits<BiIter>::value_type const& lhs,
387 const sub_match<BiIter>& rhs);
389 template <class BiIter>
391 operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
392 const sub_match<BiIter>& rhs);
394 template <class BiIter>
396 operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
397 const sub_match<BiIter>& rhs);
399 template <class BiIter>
401 operator==(const sub_match<BiIter>& lhs,
402 typename iterator_traits<BiIter>::value_type const& rhs);
404 template <class BiIter>
406 operator!=(const sub_match<BiIter>& lhs,
407 typename iterator_traits<BiIter>::value_type const& rhs);
409 template <class BiIter>
411 operator<(const sub_match<BiIter>& lhs,
412 typename iterator_traits<BiIter>::value_type const& rhs);
414 template <class BiIter>
416 operator>(const sub_match<BiIter>& lhs,
417 typename iterator_traits<BiIter>::value_type const& rhs);
419 template <class BiIter>
421 operator>=(const sub_match<BiIter>& lhs,
422 typename iterator_traits<BiIter>::value_type const& rhs);
424 template <class BiIter>
426 operator<=(const sub_match<BiIter>& lhs,
427 typename iterator_traits<BiIter>::value_type const& rhs);
429 template <class charT, class ST, class BiIter>
430 basic_ostream<charT, ST>&
431 operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
433 template <class BidirectionalIterator,
434 class Allocator = allocator<sub_match<BidirectionalIterator>>>
438 typedef sub_match<BidirectionalIterator> value_type;
439 typedef const value_type& const_reference;
440 typedef const_reference reference;
441 typedef /implementation-defined/ const_iterator;
442 typedef const_iterator iterator;
443 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
444 typedef typename allocator_traits<Allocator>::size_type size_type;
445 typedef Allocator allocator_type;
446 typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
447 typedef basic_string<char_type> string_type;
449 // construct/copy/destroy:
450 explicit match_results(const Allocator& a = Allocator());
451 match_results(const match_results& m);
452 match_results(match_results&& m) noexcept;
453 match_results& operator=(const match_results& m);
454 match_results& operator=(match_results&& m);
460 size_type size() const;
461 size_type max_size() const;
465 difference_type length(size_type sub = 0) const;
466 difference_type position(size_type sub = 0) const;
467 string_type str(size_type sub = 0) const;
468 const_reference operator[](size_type n) const;
470 const_reference prefix() const;
471 const_reference suffix() const;
473 const_iterator begin() const;
474 const_iterator end() const;
475 const_iterator cbegin() const;
476 const_iterator cend() const;
479 template <class OutputIter>
481 format(OutputIter out, const char_type* fmt_first,
482 const char_type* fmt_last,
483 regex_constants::match_flag_type flags = regex_constants::format_default) const;
484 template <class OutputIter, class ST, class SA>
486 format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
487 regex_constants::match_flag_type flags = regex_constants::format_default) const;
488 template <class ST, class SA>
489 basic_string<char_type, ST, SA>
490 format(const basic_string<char_type, ST, SA>& fmt,
491 regex_constants::match_flag_type flags = regex_constants::format_default) const;
493 format(const char_type* fmt,
494 regex_constants::match_flag_type flags = regex_constants::format_default) const;
497 allocator_type get_allocator() const;
500 void swap(match_results& that);
503 typedef match_results<const char*> cmatch;
504 typedef match_results<const wchar_t*> wcmatch;
505 typedef match_results<string::const_iterator> smatch;
506 typedef match_results<wstring::const_iterator> wsmatch;
508 template <class BidirectionalIterator, class Allocator>
510 operator==(const match_results<BidirectionalIterator, Allocator>& m1,
511 const match_results<BidirectionalIterator, Allocator>& m2);
513 template <class BidirectionalIterator, class Allocator>
515 operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
516 const match_results<BidirectionalIterator, Allocator>& m2);
518 template <class BidirectionalIterator, class Allocator>
520 swap(match_results<BidirectionalIterator, Allocator>& m1,
521 match_results<BidirectionalIterator, Allocator>& m2);
523 template <class BidirectionalIterator, class Allocator, class charT, class traits>
525 regex_match(BidirectionalIterator first, BidirectionalIterator last,
526 match_results<BidirectionalIterator, Allocator>& m,
527 const basic_regex<charT, traits>& e,
528 regex_constants::match_flag_type flags = regex_constants::match_default);
530 template <class BidirectionalIterator, class charT, class traits>
532 regex_match(BidirectionalIterator first, BidirectionalIterator last,
533 const basic_regex<charT, traits>& e,
534 regex_constants::match_flag_type flags = regex_constants::match_default);
536 template <class charT, class Allocator, class traits>
538 regex_match(const charT* str, match_results<const charT*, Allocator>& m,
539 const basic_regex<charT, traits>& e,
540 regex_constants::match_flag_type flags = regex_constants::match_default);
542 template <class ST, class SA, class Allocator, class charT, class traits>
544 regex_match(const basic_string<charT, ST, SA>& s,
545 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
546 const basic_regex<charT, traits>& e,
547 regex_constants::match_flag_type flags = regex_constants::match_default);
549 template <class charT, class traits>
551 regex_match(const charT* str, const basic_regex<charT, traits>& e,
552 regex_constants::match_flag_type flags = regex_constants::match_default);
554 template <class ST, class SA, class charT, class traits>
556 regex_match(const basic_string<charT, ST, SA>& s,
557 const basic_regex<charT, traits>& e,
558 regex_constants::match_flag_type flags = regex_constants::match_default);
560 template <class BidirectionalIterator, class Allocator, class charT, class traits>
562 regex_search(BidirectionalIterator first, BidirectionalIterator last,
563 match_results<BidirectionalIterator, Allocator>& m,
564 const basic_regex<charT, traits>& e,
565 regex_constants::match_flag_type flags = regex_constants::match_default);
567 template <class BidirectionalIterator, class charT, class traits>
569 regex_search(BidirectionalIterator first, BidirectionalIterator last,
570 const basic_regex<charT, traits>& e,
571 regex_constants::match_flag_type flags = regex_constants::match_default);
573 template <class charT, class Allocator, class traits>
575 regex_search(const charT* str, match_results<const charT*, Allocator>& m,
576 const basic_regex<charT, traits>& e,
577 regex_constants::match_flag_type flags = regex_constants::match_default);
579 template <class charT, class traits>
581 regex_search(const charT* str, const basic_regex<charT, traits>& e,
582 regex_constants::match_flag_type flags = regex_constants::match_default);
584 template <class ST, class SA, class charT, class traits>
586 regex_search(const basic_string<charT, ST, SA>& s,
587 const basic_regex<charT, traits>& e,
588 regex_constants::match_flag_type flags = regex_constants::match_default);
590 template <class ST, class SA, class Allocator, class charT, class traits>
592 regex_search(const basic_string<charT, ST, SA>& s,
593 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
594 const basic_regex<charT, traits>& e,
595 regex_constants::match_flag_type flags = regex_constants::match_default);
597 template <class OutputIterator, class BidirectionalIterator,
598 class traits, class charT, class ST, class SA>
600 regex_replace(OutputIterator out,
601 BidirectionalIterator first, BidirectionalIterator last,
602 const basic_regex<charT, traits>& e,
603 const basic_string<charT, ST, SA>& fmt,
604 regex_constants::match_flag_type flags = regex_constants::match_default);
606 template <class OutputIterator, class BidirectionalIterator,
607 class traits, class charT>
609 regex_replace(OutputIterator out,
610 BidirectionalIterator first, BidirectionalIterator last,
611 const basic_regex<charT, traits>& e, const charT* fmt,
612 regex_constants::match_flag_type flags = regex_constants::match_default);
614 template <class traits, class charT, class ST, class SA, class FST, class FSA>>
615 basic_string<charT, ST, SA>
616 regex_replace(const basic_string<charT, ST, SA>& s,
617 const basic_regex<charT, traits>& e,
618 const basic_string<charT, FST, FSA>& fmt,
619 regex_constants::match_flag_type flags = regex_constants::match_default);
621 template <class traits, class charT, class ST, class SA>
622 basic_string<charT, ST, SA>
623 regex_replace(const basic_string<charT, ST, SA>& s,
624 const basic_regex<charT, traits>& e, const charT* fmt,
625 regex_constants::match_flag_type flags = regex_constants::match_default);
627 template <class traits, class charT, class ST, class SA>
629 regex_replace(const charT* s,
630 const basic_regex<charT, traits>& e,
631 const basic_string<charT, ST, SA>& fmt,
632 regex_constants::match_flag_type flags = regex_constants::match_default);
634 template <class traits, class charT>
636 regex_replace(const charT* s,
637 const basic_regex<charT, traits>& e,
639 regex_constants::match_flag_type flags = regex_constants::match_default);
641 template <class BidirectionalIterator,
642 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
643 class traits = regex_traits<charT>>
647 typedef basic_regex<charT, traits> regex_type;
648 typedef match_results<BidirectionalIterator> value_type;
649 typedef ptrdiff_t difference_type;
650 typedef const value_type* pointer;
651 typedef const value_type& reference;
652 typedef forward_iterator_tag iterator_category;
655 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
656 const regex_type& re,
657 regex_constants::match_flag_type m = regex_constants::match_default);
658 regex_iterator(const regex_iterator&);
659 regex_iterator& operator=(const regex_iterator&);
661 bool operator==(const regex_iterator&) const;
662 bool operator!=(const regex_iterator&) const;
664 const value_type& operator*() const;
665 const value_type* operator->() const;
667 regex_iterator& operator++();
668 regex_iterator operator++(int);
671 typedef regex_iterator<const char*> cregex_iterator;
672 typedef regex_iterator<const wchar_t*> wcregex_iterator;
673 typedef regex_iterator<string::const_iterator> sregex_iterator;
674 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
676 template <class BidirectionalIterator,
677 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
678 class traits = regex_traits<charT>>
679 class regex_token_iterator
682 typedef basic_regex<charT, traits> regex_type;
683 typedef sub_match<BidirectionalIterator> value_type;
684 typedef ptrdiff_t difference_type;
685 typedef const value_type* pointer;
686 typedef const value_type& reference;
687 typedef forward_iterator_tag iterator_category;
689 regex_token_iterator();
690 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
691 const regex_type& re, int submatch = 0,
692 regex_constants::match_flag_type m = regex_constants::match_default);
693 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
694 const regex_type& re, const vector<int>& submatches,
695 regex_constants::match_flag_type m = regex_constants::match_default);
696 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
697 const regex_type& re, initializer_list<int> submatches,
698 regex_constants::match_flag_type m = regex_constants::match_default);
700 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
701 const regex_type& re, const int (&submatches)[N],
702 regex_constants::match_flag_type m = regex_constants::match_default);
703 regex_token_iterator(const regex_token_iterator&);
704 regex_token_iterator& operator=(const regex_token_iterator&);
706 bool operator==(const regex_token_iterator&) const;
707 bool operator!=(const regex_token_iterator&) const;
709 const value_type& operator*() const;
710 const value_type* operator->() const;
712 regex_token_iterator& operator++();
713 regex_token_iterator operator++(int);
716 typedef regex_token_iterator<const char*> cregex_token_iterator;
717 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
718 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
719 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
727 #include <initializer_list>
735 #include <__undef_min_max>
737 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
738 #pragma GCC system_header
741 _LIBCPP_BEGIN_NAMESPACE_STD
743 namespace regex_constants
746 // syntax_option_type
748 enum syntax_option_type
762 inline _LIBCPP_INLINE_VISIBILITY
765 operator~(syntax_option_type __x)
767 return syntax_option_type(~int(__x) & 0x1FF);
770 inline _LIBCPP_INLINE_VISIBILITY
773 operator&(syntax_option_type __x, syntax_option_type __y)
775 return syntax_option_type(int(__x) & int(__y));
778 inline _LIBCPP_INLINE_VISIBILITY
781 operator|(syntax_option_type __x, syntax_option_type __y)
783 return syntax_option_type(int(__x) | int(__y));
786 inline _LIBCPP_INLINE_VISIBILITY
789 operator^(syntax_option_type __x, syntax_option_type __y)
791 return syntax_option_type(int(__x) ^ int(__y));
794 inline _LIBCPP_INLINE_VISIBILITY
796 operator&=(syntax_option_type& __x, syntax_option_type __y)
802 inline _LIBCPP_INLINE_VISIBILITY
804 operator|=(syntax_option_type& __x, syntax_option_type __y)
810 inline _LIBCPP_INLINE_VISIBILITY
812 operator^=(syntax_option_type& __x, syntax_option_type __y)
823 match_not_bol = 1 << 0,
824 match_not_eol = 1 << 1,
825 match_not_bow = 1 << 2,
826 match_not_eow = 1 << 3,
828 match_not_null = 1 << 5,
829 match_continuous = 1 << 6,
830 match_prev_avail = 1 << 7,
833 format_no_copy = 1 << 9,
834 format_first_only = 1 << 10,
835 __no_update_pos = 1 << 11
838 inline _LIBCPP_INLINE_VISIBILITY
841 operator~(match_flag_type __x)
843 return match_flag_type(~int(__x) & 0x0FFF);
846 inline _LIBCPP_INLINE_VISIBILITY
849 operator&(match_flag_type __x, match_flag_type __y)
851 return match_flag_type(int(__x) & int(__y));
854 inline _LIBCPP_INLINE_VISIBILITY
857 operator|(match_flag_type __x, match_flag_type __y)
859 return match_flag_type(int(__x) | int(__y));
862 inline _LIBCPP_INLINE_VISIBILITY
865 operator^(match_flag_type __x, match_flag_type __y)
867 return match_flag_type(int(__x) ^ int(__y));
870 inline _LIBCPP_INLINE_VISIBILITY
872 operator&=(match_flag_type& __x, match_flag_type __y)
878 inline _LIBCPP_INLINE_VISIBILITY
880 operator|=(match_flag_type& __x, match_flag_type __y)
886 inline _LIBCPP_INLINE_VISIBILITY
888 operator^=(match_flag_type& __x, match_flag_type __y)
916 class _LIBCPP_EXCEPTION_ABI regex_error
917 : public runtime_error
919 regex_constants::error_type __code_;
921 explicit regex_error(regex_constants::error_type __ecode);
922 virtual ~regex_error() throw();
923 _LIBCPP_INLINE_VISIBILITY
924 regex_constants::error_type code() const {return __code_;}
927 template <class _CharT>
928 struct _LIBCPP_TYPE_VIS_ONLY regex_traits
931 typedef _CharT char_type;
932 typedef basic_string<char_type> string_type;
933 typedef locale locale_type;
934 typedef ctype_base::mask char_class_type;
936 static const char_class_type __regex_word = 0x80;
939 const ctype<char_type>* __ct_;
940 const collate<char_type>* __col_;
945 _LIBCPP_INLINE_VISIBILITY
946 static size_t length(const char_type* __p)
947 {return char_traits<char_type>::length(__p);}
948 _LIBCPP_INLINE_VISIBILITY
949 char_type translate(char_type __c) const {return __c;}
950 char_type translate_nocase(char_type __c) const;
951 template <class _ForwardIterator>
953 transform(_ForwardIterator __f, _ForwardIterator __l) const;
954 template <class _ForwardIterator>
955 _LIBCPP_INLINE_VISIBILITY
957 transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
958 {return __transform_primary(__f, __l, char_type());}
959 template <class _ForwardIterator>
960 _LIBCPP_INLINE_VISIBILITY
962 lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
963 {return __lookup_collatename(__f, __l, char_type());}
964 template <class _ForwardIterator>
965 _LIBCPP_INLINE_VISIBILITY
967 lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
968 bool __icase = false) const
969 {return __lookup_classname(__f, __l, __icase, char_type());}
970 bool isctype(char_type __c, char_class_type __m) const;
971 _LIBCPP_INLINE_VISIBILITY
972 int value(char_type __ch, int __radix) const
973 {return __regex_traits_value(__ch, __radix);}
974 locale_type imbue(locale_type __l);
975 _LIBCPP_INLINE_VISIBILITY
976 locale_type getloc()const {return __loc_;}
981 template <class _ForwardIterator>
983 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
984 template <class _ForwardIterator>
986 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
988 template <class _ForwardIterator>
990 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
991 template <class _ForwardIterator>
993 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
995 template <class _ForwardIterator>
997 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
998 bool __icase, char) const;
999 template <class _ForwardIterator>
1001 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1002 bool __icase, wchar_t) const;
1004 static int __regex_traits_value(unsigned char __ch, int __radix);
1005 _LIBCPP_INLINE_VISIBILITY
1006 int __regex_traits_value(char __ch, int __radix) const
1007 {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
1008 int __regex_traits_value(wchar_t __ch, int __radix) const;
1011 template <class _CharT>
1012 const typename regex_traits<_CharT>::char_class_type
1013 regex_traits<_CharT>::__regex_word;
1015 template <class _CharT>
1016 regex_traits<_CharT>::regex_traits()
1021 template <class _CharT>
1022 typename regex_traits<_CharT>::char_type
1023 regex_traits<_CharT>::translate_nocase(char_type __c) const
1025 return __ct_->tolower(__c);
1028 template <class _CharT>
1029 template <class _ForwardIterator>
1030 typename regex_traits<_CharT>::string_type
1031 regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
1033 string_type __s(__f, __l);
1034 return __col_->transform(__s.data(), __s.data() + __s.size());
1037 template <class _CharT>
1039 regex_traits<_CharT>::__init()
1041 __ct_ = &use_facet<ctype<char_type> >(__loc_);
1042 __col_ = &use_facet<collate<char_type> >(__loc_);
1045 template <class _CharT>
1046 typename regex_traits<_CharT>::locale_type
1047 regex_traits<_CharT>::imbue(locale_type __l)
1049 locale __r = __loc_;
1055 // transform_primary is very FreeBSD-specific
1057 template <class _CharT>
1058 template <class _ForwardIterator>
1059 typename regex_traits<_CharT>::string_type
1060 regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1061 _ForwardIterator __l, char) const
1063 const string_type __s(__f, __l);
1064 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1079 template <class _CharT>
1080 template <class _ForwardIterator>
1081 typename regex_traits<_CharT>::string_type
1082 regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1083 _ForwardIterator __l, wchar_t) const
1085 const string_type __s(__f, __l);
1086 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1101 // lookup_collatename is very FreeBSD-specific
1103 _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s);
1105 template <class _CharT>
1106 template <class _ForwardIterator>
1107 typename regex_traits<_CharT>::string_type
1108 regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1109 _ForwardIterator __l, char) const
1111 string_type __s(__f, __l);
1115 __r = __get_collation_name(__s.c_str());
1116 if (__r.empty() && __s.size() <= 2)
1118 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1119 if (__r.size() == 1 || __r.size() == 12)
1128 template <class _CharT>
1129 template <class _ForwardIterator>
1130 typename regex_traits<_CharT>::string_type
1131 regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1132 _ForwardIterator __l, wchar_t) const
1134 string_type __s(__f, __l);
1136 __n.reserve(__s.size());
1137 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1140 if (static_cast<unsigned>(*__i) >= 127)
1141 return string_type();
1142 __n.push_back(char(*__i));
1147 __n = __get_collation_name(__n.c_str());
1149 __r.assign(__n.begin(), __n.end());
1150 else if (__s.size() <= 2)
1152 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1153 if (__r.size() == 1 || __r.size() == 3)
1164 ctype_base::mask _LIBCPP_FUNC_VIS __get_classname(const char* __s, bool __icase);
1166 template <class _CharT>
1167 template <class _ForwardIterator>
1168 typename regex_traits<_CharT>::char_class_type
1169 regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1170 _ForwardIterator __l,
1171 bool __icase, char) const
1173 string_type __s(__f, __l);
1174 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1175 return __get_classname(__s.c_str(), __icase);
1178 template <class _CharT>
1179 template <class _ForwardIterator>
1180 typename regex_traits<_CharT>::char_class_type
1181 regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1182 _ForwardIterator __l,
1183 bool __icase, wchar_t) const
1185 string_type __s(__f, __l);
1186 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1188 __n.reserve(__s.size());
1189 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1192 if (static_cast<unsigned>(*__i) >= 127)
1193 return char_class_type();
1194 __n.push_back(char(*__i));
1196 return __get_classname(__n.c_str(), __icase);
1199 template <class _CharT>
1201 regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
1203 if (__ct_->is(__m, __c))
1205 return (__c == '_' && (__m & __regex_word));
1208 template <class _CharT>
1210 regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
1212 if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
1216 if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
1220 __ch |= 0x20; // tolower
1221 if ('a' <= __ch && __ch <= 'f')
1222 return __ch - ('a' - 10);
1228 template <class _CharT>
1229 inline _LIBCPP_INLINE_VISIBILITY
1231 regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
1233 return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
1236 template <class _CharT> class __node;
1238 template <class _BidirectionalIterator> class _LIBCPP_TYPE_VIS_ONLY sub_match;
1240 template <class _BidirectionalIterator,
1241 class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1242 class _LIBCPP_TYPE_VIS_ONLY match_results;
1244 template <class _CharT>
1249 __end_state = -1000,
1250 __consume_input, // -999
1251 __begin_marked_expr, // -998
1252 __end_marked_expr, // -997
1253 __pop_state, // -996
1254 __accept_and_consume, // -995
1255 __accept_but_not_consume, // -994
1262 const _CharT* __first_;
1263 const _CharT* __current_;
1264 const _CharT* __last_;
1265 vector<sub_match<const _CharT*> > __sub_matches_;
1266 vector<pair<size_t, const _CharT*> > __loop_data_;
1267 const __node<_CharT>* __node_;
1268 regex_constants::match_flag_type __flags_;
1271 _LIBCPP_INLINE_VISIBILITY
1273 : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
1274 __node_(nullptr), __flags_() {}
1279 template <class _CharT>
1282 __node(const __node&);
1283 __node& operator=(const __node&);
1285 typedef _VSTD::__state<_CharT> __state;
1287 _LIBCPP_INLINE_VISIBILITY
1289 _LIBCPP_INLINE_VISIBILITY
1290 virtual ~__node() {}
1292 _LIBCPP_INLINE_VISIBILITY
1293 virtual void __exec(__state&) const {};
1294 _LIBCPP_INLINE_VISIBILITY
1295 virtual void __exec_split(bool, __state&) const {};
1300 template <class _CharT>
1302 : public __node<_CharT>
1305 typedef _VSTD::__state<_CharT> __state;
1307 _LIBCPP_INLINE_VISIBILITY
1310 virtual void __exec(__state&) const;
1313 template <class _CharT>
1315 __end_state<_CharT>::__exec(__state& __s) const
1317 __s.__do_ = __state::__end_state;
1322 template <class _CharT>
1323 class __has_one_state
1324 : public __node<_CharT>
1326 __node<_CharT>* __first_;
1329 _LIBCPP_INLINE_VISIBILITY
1330 explicit __has_one_state(__node<_CharT>* __s)
1333 _LIBCPP_INLINE_VISIBILITY
1334 __node<_CharT>* first() const {return __first_;}
1335 _LIBCPP_INLINE_VISIBILITY
1336 __node<_CharT>*& first() {return __first_;}
1341 template <class _CharT>
1342 class __owns_one_state
1343 : public __has_one_state<_CharT>
1345 typedef __has_one_state<_CharT> base;
1348 _LIBCPP_INLINE_VISIBILITY
1349 explicit __owns_one_state(__node<_CharT>* __s)
1352 virtual ~__owns_one_state();
1355 template <class _CharT>
1356 __owns_one_state<_CharT>::~__owns_one_state()
1358 delete this->first();
1363 template <class _CharT>
1365 : public __owns_one_state<_CharT>
1367 typedef __owns_one_state<_CharT> base;
1370 typedef _VSTD::__state<_CharT> __state;
1372 _LIBCPP_INLINE_VISIBILITY
1373 explicit __empty_state(__node<_CharT>* __s)
1376 virtual void __exec(__state&) const;
1379 template <class _CharT>
1381 __empty_state<_CharT>::__exec(__state& __s) const
1383 __s.__do_ = __state::__accept_but_not_consume;
1384 __s.__node_ = this->first();
1387 // __empty_non_own_state
1389 template <class _CharT>
1390 class __empty_non_own_state
1391 : public __has_one_state<_CharT>
1393 typedef __has_one_state<_CharT> base;
1396 typedef _VSTD::__state<_CharT> __state;
1398 _LIBCPP_INLINE_VISIBILITY
1399 explicit __empty_non_own_state(__node<_CharT>* __s)
1402 virtual void __exec(__state&) const;
1405 template <class _CharT>
1407 __empty_non_own_state<_CharT>::__exec(__state& __s) const
1409 __s.__do_ = __state::__accept_but_not_consume;
1410 __s.__node_ = this->first();
1413 // __repeat_one_loop
1415 template <class _CharT>
1416 class __repeat_one_loop
1417 : public __has_one_state<_CharT>
1419 typedef __has_one_state<_CharT> base;
1422 typedef _VSTD::__state<_CharT> __state;
1424 _LIBCPP_INLINE_VISIBILITY
1425 explicit __repeat_one_loop(__node<_CharT>* __s)
1428 virtual void __exec(__state&) const;
1431 template <class _CharT>
1433 __repeat_one_loop<_CharT>::__exec(__state& __s) const
1435 __s.__do_ = __state::__repeat;
1436 __s.__node_ = this->first();
1439 // __owns_two_states
1441 template <class _CharT>
1442 class __owns_two_states
1443 : public __owns_one_state<_CharT>
1445 typedef __owns_one_state<_CharT> base;
1450 _LIBCPP_INLINE_VISIBILITY
1451 explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
1452 : base(__s1), __second_(__s2) {}
1454 virtual ~__owns_two_states();
1456 _LIBCPP_INLINE_VISIBILITY
1457 base* second() const {return __second_;}
1458 _LIBCPP_INLINE_VISIBILITY
1459 base*& second() {return __second_;}
1462 template <class _CharT>
1463 __owns_two_states<_CharT>::~__owns_two_states()
1470 template <class _CharT>
1472 : public __owns_two_states<_CharT>
1474 typedef __owns_two_states<_CharT> base;
1478 unsigned __loop_id_;
1479 unsigned __mexp_begin_;
1480 unsigned __mexp_end_;
1484 typedef _VSTD::__state<_CharT> __state;
1486 _LIBCPP_INLINE_VISIBILITY
1487 explicit __loop(unsigned __loop_id,
1488 __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
1489 unsigned __mexp_begin, unsigned __mexp_end,
1490 bool __greedy = true,
1492 size_t __max = numeric_limits<size_t>::max())
1493 : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
1494 __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
1495 __greedy_(__greedy) {}
1497 virtual void __exec(__state& __s) const;
1498 virtual void __exec_split(bool __second, __state& __s) const;
1501 _LIBCPP_INLINE_VISIBILITY
1502 void __init_repeat(__state& __s) const
1504 __s.__loop_data_[__loop_id_].second = __s.__current_;
1505 for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
1507 __s.__sub_matches_[__i].first = __s.__last_;
1508 __s.__sub_matches_[__i].second = __s.__last_;
1509 __s.__sub_matches_[__i].matched = false;
1514 template <class _CharT>
1516 __loop<_CharT>::__exec(__state& __s) const
1518 if (__s.__do_ == __state::__repeat)
1520 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1521 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1522 if (__do_repeat && __do_alt &&
1523 __s.__loop_data_[__loop_id_].second == __s.__current_)
1524 __do_repeat = false;
1525 if (__do_repeat && __do_alt)
1526 __s.__do_ = __state::__split;
1527 else if (__do_repeat)
1529 __s.__do_ = __state::__accept_but_not_consume;
1530 __s.__node_ = this->first();
1535 __s.__do_ = __state::__accept_but_not_consume;
1536 __s.__node_ = this->second();
1541 __s.__loop_data_[__loop_id_].first = 0;
1542 bool __do_repeat = 0 < __max_;
1543 bool __do_alt = 0 >= __min_;
1544 if (__do_repeat && __do_alt)
1545 __s.__do_ = __state::__split;
1546 else if (__do_repeat)
1548 __s.__do_ = __state::__accept_but_not_consume;
1549 __s.__node_ = this->first();
1554 __s.__do_ = __state::__accept_but_not_consume;
1555 __s.__node_ = this->second();
1560 template <class _CharT>
1562 __loop<_CharT>::__exec_split(bool __second, __state& __s) const
1564 __s.__do_ = __state::__accept_but_not_consume;
1565 if (__greedy_ != __second)
1567 __s.__node_ = this->first();
1571 __s.__node_ = this->second();
1576 template <class _CharT>
1578 : public __owns_two_states<_CharT>
1580 typedef __owns_two_states<_CharT> base;
1583 typedef _VSTD::__state<_CharT> __state;
1585 _LIBCPP_INLINE_VISIBILITY
1586 explicit __alternate(__owns_one_state<_CharT>* __s1,
1587 __owns_one_state<_CharT>* __s2)
1588 : base(__s1, __s2) {}
1590 virtual void __exec(__state& __s) const;
1591 virtual void __exec_split(bool __second, __state& __s) const;
1594 template <class _CharT>
1596 __alternate<_CharT>::__exec(__state& __s) const
1598 __s.__do_ = __state::__split;
1601 template <class _CharT>
1603 __alternate<_CharT>::__exec_split(bool __second, __state& __s) const
1605 __s.__do_ = __state::__accept_but_not_consume;
1607 __s.__node_ = this->second();
1609 __s.__node_ = this->first();
1612 // __begin_marked_subexpression
1614 template <class _CharT>
1615 class __begin_marked_subexpression
1616 : public __owns_one_state<_CharT>
1618 typedef __owns_one_state<_CharT> base;
1622 typedef _VSTD::__state<_CharT> __state;
1624 _LIBCPP_INLINE_VISIBILITY
1625 explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1626 : base(__s), __mexp_(__mexp) {}
1628 virtual void __exec(__state&) const;
1631 template <class _CharT>
1633 __begin_marked_subexpression<_CharT>::__exec(__state& __s) const
1635 __s.__do_ = __state::__accept_but_not_consume;
1636 __s.__sub_matches_[__mexp_-1].first = __s.__current_;
1637 __s.__node_ = this->first();
1640 // __end_marked_subexpression
1642 template <class _CharT>
1643 class __end_marked_subexpression
1644 : public __owns_one_state<_CharT>
1646 typedef __owns_one_state<_CharT> base;
1650 typedef _VSTD::__state<_CharT> __state;
1652 _LIBCPP_INLINE_VISIBILITY
1653 explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1654 : base(__s), __mexp_(__mexp) {}
1656 virtual void __exec(__state&) const;
1659 template <class _CharT>
1661 __end_marked_subexpression<_CharT>::__exec(__state& __s) const
1663 __s.__do_ = __state::__accept_but_not_consume;
1664 __s.__sub_matches_[__mexp_-1].second = __s.__current_;
1665 __s.__sub_matches_[__mexp_-1].matched = true;
1666 __s.__node_ = this->first();
1671 template <class _CharT>
1673 : public __owns_one_state<_CharT>
1675 typedef __owns_one_state<_CharT> base;
1679 typedef _VSTD::__state<_CharT> __state;
1681 _LIBCPP_INLINE_VISIBILITY
1682 explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
1683 : base(__s), __mexp_(__mexp) {}
1685 virtual void __exec(__state&) const;
1688 template <class _CharT>
1690 __back_ref<_CharT>::__exec(__state& __s) const
1692 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1695 ptrdiff_t __len = __sm.second - __sm.first;
1696 if (__s.__last_ - __s.__current_ >= __len &&
1697 _VSTD::equal(__sm.first, __sm.second, __s.__current_))
1699 __s.__do_ = __state::__accept_but_not_consume;
1700 __s.__current_ += __len;
1701 __s.__node_ = this->first();
1705 __s.__do_ = __state::__reject;
1706 __s.__node_ = nullptr;
1711 __s.__do_ = __state::__reject;
1712 __s.__node_ = nullptr;
1718 template <class _CharT, class _Traits>
1719 class __back_ref_icase
1720 : public __owns_one_state<_CharT>
1722 typedef __owns_one_state<_CharT> base;
1727 typedef _VSTD::__state<_CharT> __state;
1729 _LIBCPP_INLINE_VISIBILITY
1730 explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
1731 __node<_CharT>* __s)
1732 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1734 virtual void __exec(__state&) const;
1737 template <class _CharT, class _Traits>
1739 __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
1741 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1744 ptrdiff_t __len = __sm.second - __sm.first;
1745 if (__s.__last_ - __s.__current_ >= __len)
1747 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1749 if (__traits_.translate_nocase(__sm.first[__i]) !=
1750 __traits_.translate_nocase(__s.__current_[__i]))
1753 __s.__do_ = __state::__accept_but_not_consume;
1754 __s.__current_ += __len;
1755 __s.__node_ = this->first();
1759 __s.__do_ = __state::__reject;
1760 __s.__node_ = nullptr;
1766 __s.__do_ = __state::__reject;
1767 __s.__node_ = nullptr;
1771 // __back_ref_collate
1773 template <class _CharT, class _Traits>
1774 class __back_ref_collate
1775 : public __owns_one_state<_CharT>
1777 typedef __owns_one_state<_CharT> base;
1782 typedef _VSTD::__state<_CharT> __state;
1784 _LIBCPP_INLINE_VISIBILITY
1785 explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
1786 __node<_CharT>* __s)
1787 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1789 virtual void __exec(__state&) const;
1792 template <class _CharT, class _Traits>
1794 __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
1796 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1799 ptrdiff_t __len = __sm.second - __sm.first;
1800 if (__s.__last_ - __s.__current_ >= __len)
1802 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1804 if (__traits_.translate(__sm.first[__i]) !=
1805 __traits_.translate(__s.__current_[__i]))
1808 __s.__do_ = __state::__accept_but_not_consume;
1809 __s.__current_ += __len;
1810 __s.__node_ = this->first();
1814 __s.__do_ = __state::__reject;
1815 __s.__node_ = nullptr;
1821 __s.__do_ = __state::__reject;
1822 __s.__node_ = nullptr;
1828 template <class _CharT, class _Traits>
1829 class __word_boundary
1830 : public __owns_one_state<_CharT>
1832 typedef __owns_one_state<_CharT> base;
1837 typedef _VSTD::__state<_CharT> __state;
1839 _LIBCPP_INLINE_VISIBILITY
1840 explicit __word_boundary(const _Traits& __traits, bool __invert,
1841 __node<_CharT>* __s)
1842 : base(__s), __traits_(__traits), __invert_(__invert) {}
1844 virtual void __exec(__state&) const;
1847 template <class _CharT, class _Traits>
1849 __word_boundary<_CharT, _Traits>::__exec(__state& __s) const
1851 bool __is_word_b = false;
1852 if (__s.__first_ != __s.__last_)
1854 if (__s.__current_ == __s.__last_)
1856 if (!(__s.__flags_ & regex_constants::match_not_eow))
1858 _CharT __c = __s.__current_[-1];
1859 __is_word_b = __c == '_' ||
1860 __traits_.isctype(__c, ctype_base::alnum);
1863 else if (__s.__current_ == __s.__first_ &&
1864 !(__s.__flags_ & regex_constants::match_prev_avail))
1866 if (!(__s.__flags_ & regex_constants::match_not_bow))
1868 _CharT __c = *__s.__current_;
1869 __is_word_b = __c == '_' ||
1870 __traits_.isctype(__c, ctype_base::alnum);
1875 _CharT __c1 = __s.__current_[-1];
1876 _CharT __c2 = *__s.__current_;
1877 bool __is_c1_b = __c1 == '_' ||
1878 __traits_.isctype(__c1, ctype_base::alnum);
1879 bool __is_c2_b = __c2 == '_' ||
1880 __traits_.isctype(__c2, ctype_base::alnum);
1881 __is_word_b = __is_c1_b != __is_c2_b;
1884 if (__is_word_b != __invert_)
1886 __s.__do_ = __state::__accept_but_not_consume;
1887 __s.__node_ = this->first();
1891 __s.__do_ = __state::__reject;
1892 __s.__node_ = nullptr;
1898 template <class _CharT>
1900 : public __owns_one_state<_CharT>
1902 typedef __owns_one_state<_CharT> base;
1905 typedef _VSTD::__state<_CharT> __state;
1907 _LIBCPP_INLINE_VISIBILITY
1908 __l_anchor(__node<_CharT>* __s)
1911 virtual void __exec(__state&) const;
1914 template <class _CharT>
1916 __l_anchor<_CharT>::__exec(__state& __s) const
1918 if (__s.__at_first_ && __s.__current_ == __s.__first_)
1920 __s.__do_ = __state::__accept_but_not_consume;
1921 __s.__node_ = this->first();
1925 __s.__do_ = __state::__reject;
1926 __s.__node_ = nullptr;
1932 template <class _CharT>
1934 : public __owns_one_state<_CharT>
1936 typedef __owns_one_state<_CharT> base;
1939 typedef _VSTD::__state<_CharT> __state;
1941 _LIBCPP_INLINE_VISIBILITY
1942 __r_anchor(__node<_CharT>* __s)
1945 virtual void __exec(__state&) const;
1948 template <class _CharT>
1950 __r_anchor<_CharT>::__exec(__state& __s) const
1952 if (__s.__current_ == __s.__last_)
1954 __s.__do_ = __state::__accept_but_not_consume;
1955 __s.__node_ = this->first();
1959 __s.__do_ = __state::__reject;
1960 __s.__node_ = nullptr;
1966 template <class _CharT>
1968 : public __owns_one_state<_CharT>
1970 typedef __owns_one_state<_CharT> base;
1973 typedef _VSTD::__state<_CharT> __state;
1975 _LIBCPP_INLINE_VISIBILITY
1976 __match_any(__node<_CharT>* __s)
1979 virtual void __exec(__state&) const;
1982 template <class _CharT>
1984 __match_any<_CharT>::__exec(__state& __s) const
1986 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
1988 __s.__do_ = __state::__accept_and_consume;
1990 __s.__node_ = this->first();
1994 __s.__do_ = __state::__reject;
1995 __s.__node_ = nullptr;
1999 // __match_any_but_newline
2001 template <class _CharT>
2002 class __match_any_but_newline
2003 : public __owns_one_state<_CharT>
2005 typedef __owns_one_state<_CharT> base;
2008 typedef _VSTD::__state<_CharT> __state;
2010 _LIBCPP_INLINE_VISIBILITY
2011 __match_any_but_newline(__node<_CharT>* __s)
2014 virtual void __exec(__state&) const;
2017 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
2018 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
2022 template <class _CharT>
2024 : public __owns_one_state<_CharT>
2026 typedef __owns_one_state<_CharT> base;
2030 __match_char(const __match_char&);
2031 __match_char& operator=(const __match_char&);
2033 typedef _VSTD::__state<_CharT> __state;
2035 _LIBCPP_INLINE_VISIBILITY
2036 __match_char(_CharT __c, __node<_CharT>* __s)
2037 : base(__s), __c_(__c) {}
2039 virtual void __exec(__state&) const;
2042 template <class _CharT>
2044 __match_char<_CharT>::__exec(__state& __s) const
2046 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
2048 __s.__do_ = __state::__accept_and_consume;
2050 __s.__node_ = this->first();
2054 __s.__do_ = __state::__reject;
2055 __s.__node_ = nullptr;
2059 // __match_char_icase
2061 template <class _CharT, class _Traits>
2062 class __match_char_icase
2063 : public __owns_one_state<_CharT>
2065 typedef __owns_one_state<_CharT> base;
2070 __match_char_icase(const __match_char_icase&);
2071 __match_char_icase& operator=(const __match_char_icase&);
2073 typedef _VSTD::__state<_CharT> __state;
2075 _LIBCPP_INLINE_VISIBILITY
2076 __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2077 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
2079 virtual void __exec(__state&) const;
2082 template <class _CharT, class _Traits>
2084 __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
2086 if (__s.__current_ != __s.__last_ &&
2087 __traits_.translate_nocase(*__s.__current_) == __c_)
2089 __s.__do_ = __state::__accept_and_consume;
2091 __s.__node_ = this->first();
2095 __s.__do_ = __state::__reject;
2096 __s.__node_ = nullptr;
2100 // __match_char_collate
2102 template <class _CharT, class _Traits>
2103 class __match_char_collate
2104 : public __owns_one_state<_CharT>
2106 typedef __owns_one_state<_CharT> base;
2111 __match_char_collate(const __match_char_collate&);
2112 __match_char_collate& operator=(const __match_char_collate&);
2114 typedef _VSTD::__state<_CharT> __state;
2116 _LIBCPP_INLINE_VISIBILITY
2117 __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2118 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2120 virtual void __exec(__state&) const;
2123 template <class _CharT, class _Traits>
2125 __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
2127 if (__s.__current_ != __s.__last_ &&
2128 __traits_.translate(*__s.__current_) == __c_)
2130 __s.__do_ = __state::__accept_and_consume;
2132 __s.__node_ = this->first();
2136 __s.__do_ = __state::__reject;
2137 __s.__node_ = nullptr;
2141 // __bracket_expression
2143 template <class _CharT, class _Traits>
2144 class __bracket_expression
2145 : public __owns_one_state<_CharT>
2147 typedef __owns_one_state<_CharT> base;
2148 typedef typename _Traits::string_type string_type;
2151 vector<_CharT> __chars_;
2152 vector<_CharT> __neg_chars_;
2153 vector<pair<string_type, string_type> > __ranges_;
2154 vector<pair<_CharT, _CharT> > __digraphs_;
2155 vector<string_type> __equivalences_;
2156 ctype_base::mask __mask_;
2157 ctype_base::mask __neg_mask_;
2161 bool __might_have_digraph_;
2163 __bracket_expression(const __bracket_expression&);
2164 __bracket_expression& operator=(const __bracket_expression&);
2166 typedef _VSTD::__state<_CharT> __state;
2168 _LIBCPP_INLINE_VISIBILITY
2169 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
2170 bool __negate, bool __icase, bool __collate)
2171 : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
2172 __negate_(__negate), __icase_(__icase), __collate_(__collate),
2173 __might_have_digraph_(__traits_.getloc().name() != "C") {}
2175 virtual void __exec(__state&) const;
2177 _LIBCPP_INLINE_VISIBILITY
2178 bool __negated() const {return __negate_;}
2180 _LIBCPP_INLINE_VISIBILITY
2181 void __add_char(_CharT __c)
2184 __chars_.push_back(__traits_.translate_nocase(__c));
2185 else if (__collate_)
2186 __chars_.push_back(__traits_.translate(__c));
2188 __chars_.push_back(__c);
2190 _LIBCPP_INLINE_VISIBILITY
2191 void __add_neg_char(_CharT __c)
2194 __neg_chars_.push_back(__traits_.translate_nocase(__c));
2195 else if (__collate_)
2196 __neg_chars_.push_back(__traits_.translate(__c));
2198 __neg_chars_.push_back(__c);
2200 _LIBCPP_INLINE_VISIBILITY
2201 void __add_range(string_type __b, string_type __e)
2207 for (size_t __i = 0; __i < __b.size(); ++__i)
2208 __b[__i] = __traits_.translate_nocase(__b[__i]);
2209 for (size_t __i = 0; __i < __e.size(); ++__i)
2210 __e[__i] = __traits_.translate_nocase(__e[__i]);
2214 for (size_t __i = 0; __i < __b.size(); ++__i)
2215 __b[__i] = __traits_.translate(__b[__i]);
2216 for (size_t __i = 0; __i < __e.size(); ++__i)
2217 __e[__i] = __traits_.translate(__e[__i]);
2219 __ranges_.push_back(make_pair(
2220 __traits_.transform(__b.begin(), __b.end()),
2221 __traits_.transform(__e.begin(), __e.end())));
2225 #ifndef _LIBCPP_NO_EXCEPTIONS
2226 if (__b.size() != 1 || __e.size() != 1)
2227 throw regex_error(regex_constants::error_collate);
2228 #endif // _LIBCPP_NO_EXCEPTIONS
2231 __b[0] = __traits_.translate_nocase(__b[0]);
2232 __e[0] = __traits_.translate_nocase(__e[0]);
2234 __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e)));
2237 _LIBCPP_INLINE_VISIBILITY
2238 void __add_digraph(_CharT __c1, _CharT __c2)
2241 __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
2242 __traits_.translate_nocase(__c2)));
2243 else if (__collate_)
2244 __digraphs_.push_back(make_pair(__traits_.translate(__c1),
2245 __traits_.translate(__c2)));
2247 __digraphs_.push_back(make_pair(__c1, __c2));
2249 _LIBCPP_INLINE_VISIBILITY
2250 void __add_equivalence(const string_type& __s)
2251 {__equivalences_.push_back(__s);}
2252 _LIBCPP_INLINE_VISIBILITY
2253 void __add_class(ctype_base::mask __mask)
2254 {__mask_ |= __mask;}
2255 _LIBCPP_INLINE_VISIBILITY
2256 void __add_neg_class(ctype_base::mask __mask)
2257 {__neg_mask_ |= __mask;}
2260 template <class _CharT, class _Traits>
2262 __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
2264 bool __found = false;
2265 unsigned __consumed = 0;
2266 if (__s.__current_ != __s.__last_)
2269 if (__might_have_digraph_)
2271 const _CharT* __next = _VSTD::next(__s.__current_);
2272 if (__next != __s.__last_)
2274 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2277 __ch2.first = __traits_.translate_nocase(__ch2.first);
2278 __ch2.second = __traits_.translate_nocase(__ch2.second);
2280 else if (__collate_)
2282 __ch2.first = __traits_.translate(__ch2.first);
2283 __ch2.second = __traits_.translate(__ch2.second);
2285 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
2287 // __ch2 is a digraph in this locale
2289 for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
2291 if (__ch2 == __digraphs_[__i])
2297 if (__collate_ && !__ranges_.empty())
2299 string_type __s2 = __traits_.transform(&__ch2.first,
2301 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2303 if (__ranges_[__i].first <= __s2 &&
2304 __s2 <= __ranges_[__i].second)
2311 if (!__equivalences_.empty())
2313 string_type __s2 = __traits_.transform_primary(&__ch2.first,
2315 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2317 if (__s2 == __equivalences_[__i])
2324 if (__traits_.isctype(__ch2.first, __mask_) &&
2325 __traits_.isctype(__ch2.second, __mask_))
2330 if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
2331 !__traits_.isctype(__ch2.second, __neg_mask_))
2340 // test *__s.__current_ as not a digraph
2341 _CharT __ch = *__s.__current_;
2343 __ch = __traits_.translate_nocase(__ch);
2344 else if (__collate_)
2345 __ch = __traits_.translate(__ch);
2346 for (size_t __i = 0; __i < __chars_.size(); ++__i)
2348 if (__ch == __chars_[__i])
2354 if (!__neg_chars_.empty())
2356 for (size_t __i = 0; __i < __neg_chars_.size(); ++__i)
2358 if (__ch == __neg_chars_[__i])
2365 if (!__ranges_.empty())
2367 string_type __s2 = __collate_ ?
2368 __traits_.transform(&__ch, &__ch + 1) :
2369 string_type(1, __ch);
2370 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2372 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
2379 if (!__equivalences_.empty())
2381 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2382 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2384 if (__s2 == __equivalences_[__i])
2391 if (__traits_.isctype(__ch, __mask_))
2396 if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_))
2403 __found = __negate_; // force reject
2405 if (__found != __negate_)
2407 __s.__do_ = __state::__accept_and_consume;
2408 __s.__current_ += __consumed;
2409 __s.__node_ = this->first();
2413 __s.__do_ = __state::__reject;
2414 __s.__node_ = nullptr;
2418 template <class _CharT, class _Traits> class __lookahead;
2420 template <class _CharT, class _Traits = regex_traits<_CharT> >
2421 class _LIBCPP_TYPE_VIS_ONLY basic_regex
2425 typedef _CharT value_type;
2426 typedef regex_constants::syntax_option_type flag_type;
2427 typedef typename _Traits::locale_type locale_type;
2432 unsigned __marked_count_;
2433 unsigned __loop_count_;
2435 shared_ptr<__empty_state<_CharT> > __start_;
2436 __owns_one_state<_CharT>* __end_;
2438 typedef _VSTD::__state<_CharT> __state;
2439 typedef _VSTD::__node<_CharT> __node;
2443 static const regex_constants::syntax_option_type icase = regex_constants::icase;
2444 static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2445 static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
2446 static const regex_constants::syntax_option_type collate = regex_constants::collate;
2447 static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2448 static const regex_constants::syntax_option_type basic = regex_constants::basic;
2449 static const regex_constants::syntax_option_type extended = regex_constants::extended;
2450 static const regex_constants::syntax_option_type awk = regex_constants::awk;
2451 static const regex_constants::syntax_option_type grep = regex_constants::grep;
2452 static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
2454 // construct/copy/destroy:
2455 _LIBCPP_INLINE_VISIBILITY
2457 : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0),
2460 _LIBCPP_INLINE_VISIBILITY
2461 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2462 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2464 {__parse(__p, __p + __traits_.length(__p));}
2465 _LIBCPP_INLINE_VISIBILITY
2466 basic_regex(const value_type* __p, size_t __len, flag_type __f)
2467 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2469 {__parse(__p, __p + __len);}
2470 // basic_regex(const basic_regex&) = default;
2471 // basic_regex(basic_regex&&) = default;
2472 template <class _ST, class _SA>
2473 _LIBCPP_INLINE_VISIBILITY
2474 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2475 flag_type __f = regex_constants::ECMAScript)
2476 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2478 {__parse(__p.begin(), __p.end());}
2479 template <class _ForwardIterator>
2480 _LIBCPP_INLINE_VISIBILITY
2481 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
2482 flag_type __f = regex_constants::ECMAScript)
2483 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2485 {__parse(__first, __last);}
2486 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2487 _LIBCPP_INLINE_VISIBILITY
2488 basic_regex(initializer_list<value_type> __il,
2489 flag_type __f = regex_constants::ECMAScript)
2490 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2492 {__parse(__il.begin(), __il.end());}
2493 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2495 // ~basic_regex() = default;
2497 // basic_regex& operator=(const basic_regex&) = default;
2498 // basic_regex& operator=(basic_regex&&) = default;
2499 _LIBCPP_INLINE_VISIBILITY
2500 basic_regex& operator=(const value_type* __p)
2501 {return assign(__p);}
2502 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2503 _LIBCPP_INLINE_VISIBILITY
2504 basic_regex& operator=(initializer_list<value_type> __il)
2505 {return assign(__il);}
2506 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2507 template <class _ST, class _SA>
2508 _LIBCPP_INLINE_VISIBILITY
2509 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
2510 {return assign(__p);}
2513 _LIBCPP_INLINE_VISIBILITY
2514 basic_regex& assign(const basic_regex& __that)
2515 {return *this = __that;}
2516 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2517 _LIBCPP_INLINE_VISIBILITY
2518 basic_regex& assign(basic_regex&& __that) _NOEXCEPT
2519 {return *this = _VSTD::move(__that);}
2521 _LIBCPP_INLINE_VISIBILITY
2522 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2523 {return assign(__p, __p + __traits_.length(__p), __f);}
2524 _LIBCPP_INLINE_VISIBILITY
2525 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f)
2526 {return assign(__p, __p + __len, __f);}
2527 template <class _ST, class _SA>
2528 _LIBCPP_INLINE_VISIBILITY
2529 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
2530 flag_type __f = regex_constants::ECMAScript)
2531 {return assign(__s.begin(), __s.end(), __f);}
2533 template <class _InputIterator>
2534 _LIBCPP_INLINE_VISIBILITY
2537 __is_input_iterator <_InputIterator>::value &&
2538 !__is_forward_iterator<_InputIterator>::value,
2541 assign(_InputIterator __first, _InputIterator __last,
2542 flag_type __f = regex_constants::ECMAScript)
2544 basic_string<_CharT> __t(__first, __last);
2545 return assign(__t.begin(), __t.end(), __f);
2549 _LIBCPP_INLINE_VISIBILITY
2550 void __member_init(flag_type __f)
2553 __marked_count_ = 0;
2560 template <class _ForwardIterator>
2561 _LIBCPP_INLINE_VISIBILITY
2564 __is_forward_iterator<_ForwardIterator>::value,
2567 assign(_ForwardIterator __first, _ForwardIterator __last,
2568 flag_type __f = regex_constants::ECMAScript)
2571 __parse(__first, __last);
2575 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2577 _LIBCPP_INLINE_VISIBILITY
2578 basic_regex& assign(initializer_list<value_type> __il,
2579 flag_type __f = regex_constants::ECMAScript)
2580 {return assign(__il.begin(), __il.end(), __f);}
2582 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2584 // const operations:
2585 _LIBCPP_INLINE_VISIBILITY
2586 unsigned mark_count() const {return __marked_count_;}
2587 _LIBCPP_INLINE_VISIBILITY
2588 flag_type flags() const {return __flags_;}
2591 _LIBCPP_INLINE_VISIBILITY
2592 locale_type imbue(locale_type __loc)
2594 __member_init(ECMAScript);
2596 return __traits_.imbue(__loc);
2598 _LIBCPP_INLINE_VISIBILITY
2599 locale_type getloc() const {return __traits_.getloc();}
2602 void swap(basic_regex& __r);
2605 _LIBCPP_INLINE_VISIBILITY
2606 unsigned __loop_count() const {return __loop_count_;}
2608 template <class _ForwardIterator>
2610 __parse(_ForwardIterator __first, _ForwardIterator __last);
2611 template <class _ForwardIterator>
2613 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2614 template <class _ForwardIterator>
2616 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2617 template <class _ForwardIterator>
2619 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2620 template <class _ForwardIterator>
2622 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2623 template <class _ForwardIterator>
2625 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2626 template <class _ForwardIterator>
2628 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2629 template <class _ForwardIterator>
2631 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2632 template <class _ForwardIterator>
2634 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2635 template <class _ForwardIterator>
2637 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2638 template <class _ForwardIterator>
2640 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2641 template <class _ForwardIterator>
2643 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2644 template <class _ForwardIterator>
2646 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2647 template <class _ForwardIterator>
2649 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2650 __owns_one_state<_CharT>* __s,
2651 unsigned __mexp_begin, unsigned __mexp_end);
2652 template <class _ForwardIterator>
2654 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2655 __owns_one_state<_CharT>* __s,
2656 unsigned __mexp_begin, unsigned __mexp_end);
2657 template <class _ForwardIterator>
2659 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2660 template <class _ForwardIterator>
2662 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
2663 __bracket_expression<_CharT, _Traits>* __ml);
2664 template <class _ForwardIterator>
2666 __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
2667 __bracket_expression<_CharT, _Traits>* __ml);
2668 template <class _ForwardIterator>
2670 __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
2671 __bracket_expression<_CharT, _Traits>* __ml);
2672 template <class _ForwardIterator>
2674 __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
2675 __bracket_expression<_CharT, _Traits>* __ml);
2676 template <class _ForwardIterator>
2678 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
2679 basic_string<_CharT>& __col_sym);
2680 template <class _ForwardIterator>
2682 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
2683 template <class _ForwardIterator>
2685 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2686 template <class _ForwardIterator>
2688 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2689 template <class _ForwardIterator>
2691 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2692 template <class _ForwardIterator>
2694 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2695 template <class _ForwardIterator>
2697 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2698 template <class _ForwardIterator>
2700 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2701 template <class _ForwardIterator>
2703 __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2704 template <class _ForwardIterator>
2706 __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2707 template <class _ForwardIterator>
2709 __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2710 template <class _ForwardIterator>
2712 __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2713 template <class _ForwardIterator>
2715 __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2716 template <class _ForwardIterator>
2718 __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2719 template <class _ForwardIterator>
2721 __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2722 template <class _ForwardIterator>
2724 __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2725 template <class _ForwardIterator>
2727 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
2728 basic_string<_CharT>* __str = nullptr);
2729 template <class _ForwardIterator>
2731 __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
2732 template <class _ForwardIterator>
2734 __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
2735 template <class _ForwardIterator>
2737 __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
2738 template <class _ForwardIterator>
2740 __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
2741 basic_string<_CharT>& __str,
2742 __bracket_expression<_CharT, _Traits>* __ml);
2743 template <class _ForwardIterator>
2745 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
2746 basic_string<_CharT>* __str = nullptr);
2748 _LIBCPP_INLINE_VISIBILITY
2749 void __push_l_anchor();
2750 void __push_r_anchor();
2751 void __push_match_any();
2752 void __push_match_any_but_newline();
2753 _LIBCPP_INLINE_VISIBILITY
2754 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2755 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2756 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2757 __mexp_begin, __mexp_end);}
2758 _LIBCPP_INLINE_VISIBILITY
2759 void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2760 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2761 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2762 __mexp_begin, __mexp_end, false);}
2763 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2764 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2765 bool __greedy = true);
2766 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
2767 void __push_char(value_type __c);
2768 void __push_back_ref(int __i);
2769 void __push_alternation(__owns_one_state<_CharT>* __sa,
2770 __owns_one_state<_CharT>* __sb);
2771 void __push_begin_marked_subexpression();
2772 void __push_end_marked_subexpression(unsigned);
2773 void __push_empty();
2774 void __push_word_boundary(bool);
2775 void __push_lookahead(const basic_regex&, bool, unsigned);
2777 template <class _Allocator>
2779 __search(const _CharT* __first, const _CharT* __last,
2780 match_results<const _CharT*, _Allocator>& __m,
2781 regex_constants::match_flag_type __flags) const;
2783 template <class _Allocator>
2785 __match_at_start(const _CharT* __first, const _CharT* __last,
2786 match_results<const _CharT*, _Allocator>& __m,
2787 regex_constants::match_flag_type __flags, bool) const;
2788 template <class _Allocator>
2790 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
2791 match_results<const _CharT*, _Allocator>& __m,
2792 regex_constants::match_flag_type __flags, bool) const;
2793 template <class _Allocator>
2795 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
2796 match_results<const _CharT*, _Allocator>& __m,
2797 regex_constants::match_flag_type __flags, bool) const;
2798 template <class _Allocator>
2800 __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
2801 match_results<const _CharT*, _Allocator>& __m,
2802 regex_constants::match_flag_type __flags, bool) const;
2804 template <class _Bp, class _Ap, class _Cp, class _Tp>
2807 regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
2808 regex_constants::match_flag_type);
2810 template <class _Ap, class _Cp, class _Tp>
2813 regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&,
2814 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
2816 template <class _Bp, class _Cp, class _Tp>
2819 regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&,
2820 regex_constants::match_flag_type);
2822 template <class _Cp, class _Tp>
2825 regex_search(const _Cp*, const _Cp*,
2826 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
2828 template <class _Cp, class _Ap, class _Tp>
2831 regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&,
2832 regex_constants::match_flag_type);
2834 template <class _ST, class _SA, class _Cp, class _Tp>
2837 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
2838 const basic_regex<_Cp, _Tp>& __e,
2839 regex_constants::match_flag_type __flags);
2841 template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
2844 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
2845 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
2846 const basic_regex<_Cp, _Tp>& __e,
2847 regex_constants::match_flag_type __flags);
2849 template <class _Iter, class _Ap, class _Cp, class _Tp>
2852 regex_search(__wrap_iter<_Iter> __first,
2853 __wrap_iter<_Iter> __last,
2854 match_results<__wrap_iter<_Iter>, _Ap>& __m,
2855 const basic_regex<_Cp, _Tp>& __e,
2856 regex_constants::match_flag_type __flags);
2858 template <class, class> friend class __lookahead;
2861 template <class _CharT, class _Traits>
2862 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
2863 template <class _CharT, class _Traits>
2864 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
2865 template <class _CharT, class _Traits>
2866 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
2867 template <class _CharT, class _Traits>
2868 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
2869 template <class _CharT, class _Traits>
2870 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
2871 template <class _CharT, class _Traits>
2872 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
2873 template <class _CharT, class _Traits>
2874 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
2875 template <class _CharT, class _Traits>
2876 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
2877 template <class _CharT, class _Traits>
2878 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
2879 template <class _CharT, class _Traits>
2880 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
2882 template <class _CharT, class _Traits>
2884 basic_regex<_CharT, _Traits>::swap(basic_regex& __r)
2887 swap(__traits_, __r.__traits_);
2888 swap(__flags_, __r.__flags_);
2889 swap(__marked_count_, __r.__marked_count_);
2890 swap(__loop_count_, __r.__loop_count_);
2891 swap(__open_count_, __r.__open_count_);
2892 swap(__start_, __r.__start_);
2893 swap(__end_, __r.__end_);
2896 template <class _CharT, class _Traits>
2897 inline _LIBCPP_INLINE_VISIBILITY
2899 swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
2901 return __x.swap(__y);
2906 template <class _CharT, class _Traits>
2908 : public __owns_one_state<_CharT>
2910 typedef __owns_one_state<_CharT> base;
2912 basic_regex<_CharT, _Traits> __exp_;
2916 __lookahead(const __lookahead&);
2917 __lookahead& operator=(const __lookahead&);
2919 typedef _VSTD::__state<_CharT> __state;
2921 _LIBCPP_INLINE_VISIBILITY
2922 __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
2923 : base(__s), __exp_(__exp), __invert_(__invert), __mexp_(__mexp) {}
2925 virtual void __exec(__state&) const;
2928 template <class _CharT, class _Traits>
2930 __lookahead<_CharT, _Traits>::__exec(__state& __s) const
2932 match_results<const _CharT*> __m;
2933 __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
2934 bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
2936 __s.__flags_ | regex_constants::match_continuous,
2937 __s.__at_first_ && __s.__current_ == __s.__first_);
2938 if (__matched != __invert_)
2940 __s.__do_ = __state::__accept_but_not_consume;
2941 __s.__node_ = this->first();
2942 for (unsigned __i = 1; __i < __m.size(); ++__i) {
2943 __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
2948 __s.__do_ = __state::__reject;
2949 __s.__node_ = nullptr;
2953 template <class _CharT, class _Traits>
2954 template <class _ForwardIterator>
2956 basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
2957 _ForwardIterator __last)
2960 unique_ptr<__node> __h(new __end_state<_CharT>);
2961 __start_.reset(new __empty_state<_CharT>(__h.get()));
2963 __end_ = __start_.get();
2965 switch (__flags_ & 0x1F0)
2968 __first = __parse_ecma_exp(__first, __last);
2971 __first = __parse_basic_reg_exp(__first, __last);
2975 __first = __parse_extended_reg_exp(__first, __last);
2978 __first = __parse_grep(__first, __last);
2981 __first = __parse_egrep(__first, __last);
2983 #ifndef _LIBCPP_NO_EXCEPTIONS
2985 throw regex_error(regex_constants::__re_err_grammar);
2986 #endif // _LIBCPP_NO_EXCEPTIONS
2991 template <class _CharT, class _Traits>
2992 template <class _ForwardIterator>
2994 basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
2995 _ForwardIterator __last)
2997 if (__first != __last)
2999 if (*__first == '^')
3004 if (__first != __last)
3006 __first = __parse_RE_expression(__first, __last);
3007 if (__first != __last)
3009 _ForwardIterator __temp = _VSTD::next(__first);
3010 if (__temp == __last && *__first == '$')
3017 #ifndef _LIBCPP_NO_EXCEPTIONS
3018 if (__first != __last)
3019 throw regex_error(regex_constants::__re_err_empty);
3020 #endif // _LIBCPP_NO_EXCEPTIONS
3025 template <class _CharT, class _Traits>
3026 template <class _ForwardIterator>
3028 basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
3029 _ForwardIterator __last)
3031 __owns_one_state<_CharT>* __sa = __end_;
3032 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
3033 #ifndef _LIBCPP_NO_EXCEPTIONS
3034 if (__temp == __first)
3035 throw regex_error(regex_constants::__re_err_empty);
3036 #endif // _LIBCPP_NO_EXCEPTIONS
3038 while (__first != __last && *__first == '|')
3040 __owns_one_state<_CharT>* __sb = __end_;
3041 __temp = __parse_ERE_branch(++__first, __last);
3042 #ifndef _LIBCPP_NO_EXCEPTIONS
3043 if (__temp == __first)
3044 throw regex_error(regex_constants::__re_err_empty);
3045 #endif // _LIBCPP_NO_EXCEPTIONS
3046 __push_alternation(__sa, __sb);
3052 template <class _CharT, class _Traits>
3053 template <class _ForwardIterator>
3055 basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
3056 _ForwardIterator __last)
3058 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
3059 #ifndef _LIBCPP_NO_EXCEPTIONS
3060 if (__temp == __first)
3061 throw regex_error(regex_constants::__re_err_empty);
3062 #endif // _LIBCPP_NO_EXCEPTIONS
3066 __temp = __parse_ERE_expression(__first, __last);
3067 } while (__temp != __first);
3071 template <class _CharT, class _Traits>
3072 template <class _ForwardIterator>
3074 basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
3075 _ForwardIterator __last)
3077 __owns_one_state<_CharT>* __e = __end_;
3078 unsigned __mexp_begin = __marked_count_;
3079 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
3080 if (__temp == __first && __temp != __last)
3093 __push_begin_marked_subexpression();
3094 unsigned __temp_count = __marked_count_;
3096 __temp = __parse_extended_reg_exp(++__temp, __last);
3097 #ifndef _LIBCPP_NO_EXCEPTIONS
3098 if (__temp == __last || *__temp != ')')
3099 throw regex_error(regex_constants::error_paren);
3100 #endif // _LIBCPP_NO_EXCEPTIONS
3101 __push_end_marked_subexpression(__temp_count);
3107 if (__temp != __first)
3108 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
3114 template <class _CharT, class _Traits>
3115 template <class _ForwardIterator>
3117 basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
3118 _ForwardIterator __last)
3122 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
3123 if (__temp == __first)
3130 template <class _CharT, class _Traits>
3131 template <class _ForwardIterator>
3133 basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
3134 _ForwardIterator __last)
3136 if (__first != __last)
3138 __owns_one_state<_CharT>* __e = __end_;
3139 unsigned __mexp_begin = __marked_count_;
3140 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
3141 if (__temp != __first)
3142 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
3143 __mexp_begin+1, __marked_count_+1);
3148 template <class _CharT, class _Traits>
3149 template <class _ForwardIterator>
3151 basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
3152 _ForwardIterator __last)
3154 _ForwardIterator __temp = __first;
3155 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
3156 if (__temp == __first)
3158 __temp = __parse_Back_open_paren(__first, __last);
3159 if (__temp != __first)
3161 __push_begin_marked_subexpression();
3162 unsigned __temp_count = __marked_count_;
3163 __first = __parse_RE_expression(__temp, __last);
3164 __temp = __parse_Back_close_paren(__first, __last);
3165 #ifndef _LIBCPP_NO_EXCEPTIONS
3166 if (__temp == __first)
3167 throw regex_error(regex_constants::error_paren);
3168 #endif // _LIBCPP_NO_EXCEPTIONS
3169 __push_end_marked_subexpression(__temp_count);
3173 __first = __parse_BACKREF(__first, __last);
3178 template <class _CharT, class _Traits>
3179 template <class _ForwardIterator>
3181 basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
3182 _ForwardIterator __first,
3183 _ForwardIterator __last)
3185 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
3186 if (__temp == __first)
3188 __temp = __parse_QUOTED_CHAR(__first, __last);
3189 if (__temp == __first)
3191 if (__temp != __last && *__temp == '.')
3197 __temp = __parse_bracket_expression(__first, __last);
3204 template <class _CharT, class _Traits>
3205 template <class _ForwardIterator>
3207 basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
3208 _ForwardIterator __first,
3209 _ForwardIterator __last)
3211 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
3212 if (__temp == __first)
3214 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
3215 if (__temp == __first)
3217 if (__temp != __last && *__temp == '.')
3223 __temp = __parse_bracket_expression(__first, __last);
3230 template <class _CharT, class _Traits>
3231 template <class _ForwardIterator>
3233 basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
3234 _ForwardIterator __last)
3236 if (__first != __last)
3238 _ForwardIterator __temp = _VSTD::next(__first);
3239 if (__temp != __last)
3241 if (*__first == '\\' && *__temp == '(')
3248 template <class _CharT, class _Traits>
3249 template <class _ForwardIterator>
3251 basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
3252 _ForwardIterator __last)
3254 if (__first != __last)
3256 _ForwardIterator __temp = _VSTD::next(__first);
3257 if (__temp != __last)
3259 if (*__first == '\\' && *__temp == ')')
3266 template <class _CharT, class _Traits>
3267 template <class _ForwardIterator>
3269 basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
3270 _ForwardIterator __last)
3272 if (__first != __last)
3274 _ForwardIterator __temp = _VSTD::next(__first);
3275 if (__temp != __last)
3277 if (*__first == '\\' && *__temp == '{')
3284 template <class _CharT, class _Traits>
3285 template <class _ForwardIterator>
3287 basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
3288 _ForwardIterator __last)
3290 if (__first != __last)
3292 _ForwardIterator __temp = _VSTD::next(__first);
3293 if (__temp != __last)
3295 if (*__first == '\\' && *__temp == '}')
3302 template <class _CharT, class _Traits>
3303 template <class _ForwardIterator>
3305 basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
3306 _ForwardIterator __last)
3308 if (__first != __last)
3310 _ForwardIterator __temp = _VSTD::next(__first);
3311 if (__temp != __last)
3313 if (*__first == '\\' && '1' <= *__temp && *__temp <= '9')
3315 __push_back_ref(*__temp - '0');
3323 template <class _CharT, class _Traits>
3324 template <class _ForwardIterator>
3326 basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
3327 _ForwardIterator __last)
3329 if (__first != __last)
3331 _ForwardIterator __temp = _VSTD::next(__first);
3332 if (__temp == __last && *__first == '$')
3334 // Not called inside a bracket
3335 if (*__first == '.' || *__first == '\\' || *__first == '[')
3337 __push_char(*__first);
3343 template <class _CharT, class _Traits>
3344 template <class _ForwardIterator>
3346 basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
3347 _ForwardIterator __last)
3349 if (__first != __last)
3366 if (__open_count_ == 0)
3368 __push_char(*__first);
3373 __push_char(*__first);
3381 template <class _CharT, class _Traits>
3382 template <class _ForwardIterator>
3384 basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
3385 _ForwardIterator __last)
3387 if (__first != __last)
3389 _ForwardIterator __temp = _VSTD::next(__first);
3390 if (__temp != __last)
3392 if (*__first == '\\')
3402 __push_char(*__temp);
3412 template <class _CharT, class _Traits>
3413 template <class _ForwardIterator>
3415 basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
3416 _ForwardIterator __last)
3418 if (__first != __last)
3420 _ForwardIterator __temp = _VSTD::next(__first);
3421 if (__temp != __last)
3423 if (*__first == '\\')
3440 __push_char(*__temp);
3444 if ((__flags_ & 0x1F0) == awk)
3445 __first = __parse_awk_escape(++__first, __last);
3454 template <class _CharT, class _Traits>
3455 template <class _ForwardIterator>
3457 basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
3458 _ForwardIterator __last,
3459 __owns_one_state<_CharT>* __s,
3460 unsigned __mexp_begin,
3461 unsigned __mexp_end)
3463 if (__first != __last)
3465 if (*__first == '*')
3467 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3472 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3473 if (__temp != __first)
3477 __temp = __parse_DUP_COUNT(__first, __last, __min);
3478 #ifndef _LIBCPP_NO_EXCEPTIONS
3479 if (__temp == __first)
3480 throw regex_error(regex_constants::error_badbrace);
3481 #endif // _LIBCPP_NO_EXCEPTIONS
3483 #ifndef _LIBCPP_NO_EXCEPTIONS
3484 if (__first == __last)
3485 throw regex_error(regex_constants::error_brace);
3486 #endif // _LIBCPP_NO_EXCEPTIONS
3487 if (*__first != ',')
3489 __temp = __parse_Back_close_brace(__first, __last);
3490 #ifndef _LIBCPP_NO_EXCEPTIONS
3491 if (__temp == __first)
3492 throw regex_error(regex_constants::error_brace);
3493 #endif // _LIBCPP_NO_EXCEPTIONS
3494 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
3500 ++__first; // consume ','
3502 __first = __parse_DUP_COUNT(__first, __last, __max);
3503 __temp = __parse_Back_close_brace(__first, __last);
3504 #ifndef _LIBCPP_NO_EXCEPTIONS
3505 if (__temp == __first)
3506 throw regex_error(regex_constants::error_brace);
3507 #endif // _LIBCPP_NO_EXCEPTIONS
3509 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3512 #ifndef _LIBCPP_NO_EXCEPTIONS
3514 throw regex_error(regex_constants::error_badbrace);
3515 #endif // _LIBCPP_NO_EXCEPTIONS
3516 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
3527 template <class _CharT, class _Traits>
3528 template <class _ForwardIterator>
3530 basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
3531 _ForwardIterator __last,
3532 __owns_one_state<_CharT>* __s,
3533 unsigned __mexp_begin,
3534 unsigned __mexp_end)
3536 if (__first != __last)
3538 unsigned __grammar = __flags_ & 0x1F0;
3543 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3546 __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3549 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3553 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3556 __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3559 __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3563 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3566 __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3569 __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
3574 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
3575 #ifndef _LIBCPP_NO_EXCEPTIONS
3576 if (__temp == __first)
3577 throw regex_error(regex_constants::error_badbrace);
3578 #endif // _LIBCPP_NO_EXCEPTIONS
3580 #ifndef _LIBCPP_NO_EXCEPTIONS
3581 if (__first == __last)
3582 throw regex_error(regex_constants::error_brace);
3583 #endif // _LIBCPP_NO_EXCEPTIONS
3588 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3591 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3594 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
3598 #ifndef _LIBCPP_NO_EXCEPTIONS
3599 if (__first == __last)
3600 throw regex_error(regex_constants::error_badbrace);
3601 #endif // _LIBCPP_NO_EXCEPTIONS
3602 if (*__first == '}')
3605 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3608 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3611 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3616 __temp = __parse_DUP_COUNT(__first, __last, __max);
3617 #ifndef _LIBCPP_NO_EXCEPTIONS
3618 if (__temp == __first)
3619 throw regex_error(regex_constants::error_brace);
3620 #endif // _LIBCPP_NO_EXCEPTIONS
3622 #ifndef _LIBCPP_NO_EXCEPTIONS
3623 if (__first == __last || *__first != '}')
3624 throw regex_error(regex_constants::error_brace);
3625 #endif // _LIBCPP_NO_EXCEPTIONS
3627 #ifndef _LIBCPP_NO_EXCEPTIONS
3629 throw regex_error(regex_constants::error_badbrace);
3630 #endif // _LIBCPP_NO_EXCEPTIONS
3631 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3634 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3637 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
3640 #ifndef _LIBCPP_NO_EXCEPTIONS
3642 throw regex_error(regex_constants::error_badbrace);
3643 #endif // _LIBCPP_NO_EXCEPTIONS
3652 template <class _CharT, class _Traits>
3653 template <class _ForwardIterator>
3655 basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
3656 _ForwardIterator __last)
3658 if (__first != __last && *__first == '[')
3661 #ifndef _LIBCPP_NO_EXCEPTIONS
3662 if (__first == __last)
3663 throw regex_error(regex_constants::error_brack);
3664 #endif // _LIBCPP_NO_EXCEPTIONS
3665 bool __negate = false;
3666 if (*__first == '^')
3671 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3672 // __ml owned by *this
3673 #ifndef _LIBCPP_NO_EXCEPTIONS
3674 if (__first == __last)
3675 throw regex_error(regex_constants::error_brack);
3676 #endif // _LIBCPP_NO_EXCEPTIONS
3677 if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']')
3679 __ml->__add_char(']');
3682 __first = __parse_follow_list(__first, __last, __ml);
3683 #ifndef _LIBCPP_NO_EXCEPTIONS
3684 if (__first == __last)
3685 throw regex_error(regex_constants::error_brack);
3686 #endif // _LIBCPP_NO_EXCEPTIONS
3687 if (*__first == '-')
3689 __ml->__add_char('-');
3692 #ifndef _LIBCPP_NO_EXCEPTIONS
3693 if (__first == __last || *__first != ']')
3694 throw regex_error(regex_constants::error_brack);
3695 #endif // _LIBCPP_NO_EXCEPTIONS
3701 template <class _CharT, class _Traits>
3702 template <class _ForwardIterator>
3704 basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
3705 _ForwardIterator __last,
3706 __bracket_expression<_CharT, _Traits>* __ml)
3708 if (__first != __last)
3712 _ForwardIterator __temp = __parse_expression_term(__first, __last,
3714 if (__temp == __first)
3722 template <class _CharT, class _Traits>
3723 template <class _ForwardIterator>
3725 basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
3726 _ForwardIterator __last,
3727 __bracket_expression<_CharT, _Traits>* __ml)
3729 if (__first != __last && *__first != ']')
3731 _ForwardIterator __temp = _VSTD::next(__first);
3732 basic_string<_CharT> __start_range;
3733 if (__temp != __last && *__first == '[')
3736 return __parse_equivalence_class(++__temp, __last, __ml);
3737 else if (*__temp == ':')
3738 return __parse_character_class(++__temp, __last, __ml);
3739 else if (*__temp == '.')
3740 __first = __parse_collating_symbol(++__temp, __last, __start_range);
3742 unsigned __grammar = __flags_ & 0x1F0;
3743 if (__start_range.empty())
3745 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3747 if (__grammar == ECMAScript)
3748 __first = __parse_class_escape(++__first, __last, __start_range, __ml);
3750 __first = __parse_awk_escape(++__first, __last, &__start_range);
3754 __start_range = *__first;
3758 if (__first != __last && *__first != ']')
3760 __temp = _VSTD::next(__first);
3761 if (__temp != __last && *__first == '-' && *__temp != ']')
3764 basic_string<_CharT> __end_range;
3767 if (__temp != __last && *__first == '[' && *__temp == '.')
3768 __first = __parse_collating_symbol(++__temp, __last, __end_range);
3771 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3773 if (__grammar == ECMAScript)
3774 __first = __parse_class_escape(++__first, __last,
3777 __first = __parse_awk_escape(++__first, __last,
3782 __end_range = *__first;
3786 __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range));
3788 else if (!__start_range.empty())
3790 if (__start_range.size() == 1)
3791 __ml->__add_char(__start_range[0]);
3793 __ml->__add_digraph(__start_range[0], __start_range[1]);
3796 else if (!__start_range.empty())
3798 if (__start_range.size() == 1)
3799 __ml->__add_char(__start_range[0]);
3801 __ml->__add_digraph(__start_range[0], __start_range[1]);
3807 template <class _CharT, class _Traits>
3808 template <class _ForwardIterator>
3810 basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
3811 _ForwardIterator __last,
3812 basic_string<_CharT>& __str,
3813 __bracket_expression<_CharT, _Traits>* __ml)
3815 #ifndef _LIBCPP_NO_EXCEPTIONS
3816 if (__first == __last)
3817 throw regex_error(regex_constants::error_escape);
3818 #endif // _LIBCPP_NO_EXCEPTIONS
3828 __ml->__add_class(ctype_base::digit);
3831 __ml->__add_neg_class(ctype_base::digit);
3834 __ml->__add_class(ctype_base::space);
3837 __ml->__add_neg_class(ctype_base::space);
3840 __ml->__add_class(ctype_base::alnum);
3841 __ml->__add_char('_');
3844 __ml->__add_neg_class(ctype_base::alnum);
3845 __ml->__add_neg_char('_');
3848 __first = __parse_character_escape(__first, __last, &__str);
3852 template <class _CharT, class _Traits>
3853 template <class _ForwardIterator>
3855 basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
3856 _ForwardIterator __last,
3857 basic_string<_CharT>* __str)
3859 #ifndef _LIBCPP_NO_EXCEPTIONS
3860 if (__first == __last)
3861 throw regex_error(regex_constants::error_escape);
3862 #endif // _LIBCPP_NO_EXCEPTIONS
3871 __push_char(*__first);
3877 __push_char(_CharT(7));
3883 __push_char(_CharT(8));
3887 *__str = _CharT(0xC);
3889 __push_char(_CharT(0xC));
3893 *__str = _CharT(0xA);
3895 __push_char(_CharT(0xA));
3899 *__str = _CharT(0xD);
3901 __push_char(_CharT(0xD));
3905 *__str = _CharT(0x9);
3907 __push_char(_CharT(0x9));
3911 *__str = _CharT(0xB);
3913 __push_char(_CharT(0xB));
3916 if ('0' <= *__first && *__first <= '7')
3918 unsigned __val = *__first - '0';
3919 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3921 __val = 8 * __val + *__first - '0';
3922 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3923 __val = 8 * __val + *__first++ - '0';
3926 *__str = _CharT(__val);
3928 __push_char(_CharT(__val));
3930 #ifndef _LIBCPP_NO_EXCEPTIONS
3932 throw regex_error(regex_constants::error_escape);
3933 #endif // _LIBCPP_NO_EXCEPTIONS
3937 template <class _CharT, class _Traits>
3938 template <class _ForwardIterator>
3940 basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
3941 _ForwardIterator __last,
3942 __bracket_expression<_CharT, _Traits>* __ml)
3945 // This means =] must exist
3946 value_type _Equal_close[2] = {'=', ']'};
3947 _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close,
3949 #ifndef _LIBCPP_NO_EXCEPTIONS
3950 if (__temp == __last)
3951 throw regex_error(regex_constants::error_brack);
3952 #endif // _LIBCPP_NO_EXCEPTIONS
3953 // [__first, __temp) contains all text in [= ... =]
3954 typedef typename _Traits::string_type string_type;
3955 string_type __collate_name =
3956 __traits_.lookup_collatename(__first, __temp);
3957 #ifndef _LIBCPP_NO_EXCEPTIONS
3958 if (__collate_name.empty())
3959 throw regex_error(regex_constants::error_collate);
3960 #endif // _LIBCPP_NO_EXCEPTIONS
3961 string_type __equiv_name =
3962 __traits_.transform_primary(__collate_name.begin(),
3963 __collate_name.end());
3964 if (!__equiv_name.empty())
3965 __ml->__add_equivalence(__equiv_name);
3968 switch (__collate_name.size())
3971 __ml->__add_char(__collate_name[0]);
3974 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
3976 #ifndef _LIBCPP_NO_EXCEPTIONS
3978 throw regex_error(regex_constants::error_collate);
3979 #endif // _LIBCPP_NO_EXCEPTIONS
3982 __first = _VSTD::next(__temp, 2);
3986 template <class _CharT, class _Traits>
3987 template <class _ForwardIterator>
3989 basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
3990 _ForwardIterator __last,
3991 __bracket_expression<_CharT, _Traits>* __ml)
3994 // This means :] must exist
3995 value_type _Colon_close[2] = {':', ']'};
3996 _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close,
3998 #ifndef _LIBCPP_NO_EXCEPTIONS
3999 if (__temp == __last)
4000 throw regex_error(regex_constants::error_brack);
4001 #endif // _LIBCPP_NO_EXCEPTIONS
4002 // [__first, __temp) contains all text in [: ... :]
4003 typedef typename _Traits::char_class_type char_class_type;
4004 char_class_type __class_type =
4005 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
4006 #ifndef _LIBCPP_NO_EXCEPTIONS
4007 if (__class_type == 0)
4008 throw regex_error(regex_constants::error_brack);
4009 #endif // _LIBCPP_NO_EXCEPTIONS
4010 __ml->__add_class(__class_type);
4011 __first = _VSTD::next(__temp, 2);
4015 template <class _CharT, class _Traits>
4016 template <class _ForwardIterator>
4018 basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
4019 _ForwardIterator __last,
4020 basic_string<_CharT>& __col_sym)
4023 // This means .] must exist
4024 value_type _Dot_close[2] = {'.', ']'};
4025 _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close,
4027 #ifndef _LIBCPP_NO_EXCEPTIONS
4028 if (__temp == __last)
4029 throw regex_error(regex_constants::error_brack);
4030 #endif // _LIBCPP_NO_EXCEPTIONS
4031 // [__first, __temp) contains all text in [. ... .]
4032 typedef typename _Traits::string_type string_type;
4033 __col_sym = __traits_.lookup_collatename(__first, __temp);
4034 switch (__col_sym.size())
4039 #ifndef _LIBCPP_NO_EXCEPTIONS
4041 throw regex_error(regex_constants::error_collate);
4042 #endif // _LIBCPP_NO_EXCEPTIONS
4044 __first = _VSTD::next(__temp, 2);
4048 template <class _CharT, class _Traits>
4049 template <class _ForwardIterator>
4051 basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
4052 _ForwardIterator __last,
4055 if (__first != __last && '0' <= *__first && *__first <= '9')
4057 __c = *__first - '0';
4058 for (++__first; __first != __last && '0' <= *__first && *__first <= '9';
4062 __c += *__first - '0';
4068 template <class _CharT, class _Traits>
4069 template <class _ForwardIterator>
4071 basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
4072 _ForwardIterator __last)
4074 __owns_one_state<_CharT>* __sa = __end_;
4075 _ForwardIterator __temp = __parse_alternative(__first, __last);
4076 if (__temp == __first)
4079 while (__first != __last && *__first == '|')
4081 __owns_one_state<_CharT>* __sb = __end_;
4082 __temp = __parse_alternative(++__first, __last);
4083 if (__temp == __first)
4085 __push_alternation(__sa, __sb);
4091 template <class _CharT, class _Traits>
4092 template <class _ForwardIterator>
4094 basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
4095 _ForwardIterator __last)
4099 _ForwardIterator __temp = __parse_term(__first, __last);
4100 if (__temp == __first)
4107 template <class _CharT, class _Traits>
4108 template <class _ForwardIterator>
4110 basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
4111 _ForwardIterator __last)
4113 _ForwardIterator __temp = __parse_assertion(__first, __last);
4114 if (__temp == __first)
4116 __owns_one_state<_CharT>* __e = __end_;
4117 unsigned __mexp_begin = __marked_count_;
4118 __temp = __parse_atom(__first, __last);
4119 if (__temp != __first)
4120 __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
4121 __mexp_begin+1, __marked_count_+1);
4128 template <class _CharT, class _Traits>
4129 template <class _ForwardIterator>
4131 basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
4132 _ForwardIterator __last)
4134 if (__first != __last)
4148 _ForwardIterator __temp = _VSTD::next(__first);
4149 if (__temp != __last)
4153 __push_word_boundary(false);
4156 else if (*__temp == 'B')
4158 __push_word_boundary(true);
4166 _ForwardIterator __temp = _VSTD::next(__first);
4167 if (__temp != __last && *__temp == '?')
4169 if (++__temp != __last)
4176 __exp.__flags_ = __flags_;
4177 __temp = __exp.__parse(++__temp, __last);
4178 unsigned __mexp = __exp.__marked_count_;
4179 __push_lookahead(_VSTD::move(__exp), false, __marked_count_);
4180 __marked_count_ += __mexp;
4181 #ifndef _LIBCPP_NO_EXCEPTIONS
4182 if (__temp == __last || *__temp != ')')
4183 throw regex_error(regex_constants::error_paren);
4184 #endif // _LIBCPP_NO_EXCEPTIONS
4191 __exp.__flags_ = __flags_;
4192 __temp = __exp.__parse(++__temp, __last);
4193 unsigned __mexp = __exp.__marked_count_;
4194 __push_lookahead(_VSTD::move(__exp), true, __marked_count_);
4195 __marked_count_ += __mexp;
4196 #ifndef _LIBCPP_NO_EXCEPTIONS
4197 if (__temp == __last || *__temp != ')')
4198 throw regex_error(regex_constants::error_paren);
4199 #endif // _LIBCPP_NO_EXCEPTIONS
4213 template <class _CharT, class _Traits>
4214 template <class _ForwardIterator>
4216 basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
4217 _ForwardIterator __last)
4219 if (__first != __last)
4224 __push_match_any_but_newline();
4228 __first = __parse_atom_escape(__first, __last);
4231 __first = __parse_bracket_expression(__first, __last);
4236 #ifndef _LIBCPP_NO_EXCEPTIONS
4237 if (__first == __last)
4238 throw regex_error(regex_constants::error_paren);
4239 #endif // _LIBCPP_NO_EXCEPTIONS
4240 _ForwardIterator __temp = _VSTD::next(__first);
4241 if (__temp != __last && *__first == '?' && *__temp == ':')
4244 __first = __parse_ecma_exp(++__temp, __last);
4245 #ifndef _LIBCPP_NO_EXCEPTIONS
4246 if (__first == __last || *__first != ')')
4247 throw regex_error(regex_constants::error_paren);
4248 #endif // _LIBCPP_NO_EXCEPTIONS
4254 __push_begin_marked_subexpression();
4255 unsigned __temp_count = __marked_count_;
4257 __first = __parse_ecma_exp(__first, __last);
4258 #ifndef _LIBCPP_NO_EXCEPTIONS
4259 if (__first == __last || *__first != ')')
4260 throw regex_error(regex_constants::error_paren);
4261 #endif // _LIBCPP_NO_EXCEPTIONS
4262 __push_end_marked_subexpression(__temp_count);
4269 __first = __parse_pattern_character(__first, __last);
4276 template <class _CharT, class _Traits>
4277 template <class _ForwardIterator>
4279 basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
4280 _ForwardIterator __last)
4282 if (__first != __last && *__first == '\\')
4284 _ForwardIterator __t1 = _VSTD::next(__first);
4285 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
4290 __t2 = __parse_character_class_escape(__t1, __last);
4295 __t2 = __parse_character_escape(__t1, __last);
4304 template <class _CharT, class _Traits>
4305 template <class _ForwardIterator>
4307 basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
4308 _ForwardIterator __last)
4310 if (__first != __last)
4312 if (*__first == '0')
4314 __push_char(_CharT());
4317 else if ('1' <= *__first && *__first <= '9')
4319 unsigned __v = *__first - '0';
4320 for (++__first; '0' <= *__first && *__first <= '9'; ++__first)
4321 __v = 10 * __v + *__first - '0';
4322 #ifndef _LIBCPP_NO_EXCEPTIONS
4323 if (__v > mark_count())
4324 throw regex_error(regex_constants::error_backref);
4325 #endif // _LIBCPP_NO_EXCEPTIONS
4326 __push_back_ref(__v);
4332 template <class _CharT, class _Traits>
4333 template <class _ForwardIterator>
4335 basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
4336 _ForwardIterator __last)
4338 if (__first != __last)
4340 __bracket_expression<_CharT, _Traits>* __ml;
4344 __ml = __start_matching_list(false);
4345 __ml->__add_class(ctype_base::digit);
4349 __ml = __start_matching_list(true);
4350 __ml->__add_class(ctype_base::digit);
4354 __ml = __start_matching_list(false);
4355 __ml->__add_class(ctype_base::space);
4359 __ml = __start_matching_list(true);
4360 __ml->__add_class(ctype_base::space);
4364 __ml = __start_matching_list(false);
4365 __ml->__add_class(ctype_base::alnum);
4366 __ml->__add_char('_');
4370 __ml = __start_matching_list(true);
4371 __ml->__add_class(ctype_base::alnum);
4372 __ml->__add_char('_');
4380 template <class _CharT, class _Traits>
4381 template <class _ForwardIterator>
4383 basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
4384 _ForwardIterator __last,
4385 basic_string<_CharT>* __str)
4387 if (__first != __last)
4389 _ForwardIterator __t;
4396 *__str = _CharT(0xC);
4398 __push_char(_CharT(0xC));
4403 *__str = _CharT(0xA);
4405 __push_char(_CharT(0xA));
4410 *__str = _CharT(0xD);
4412 __push_char(_CharT(0xD));
4417 *__str = _CharT(0x9);
4419 __push_char(_CharT(0x9));
4424 *__str = _CharT(0xB);
4426 __push_char(_CharT(0xB));
4430 if ((__t = _VSTD::next(__first)) != __last)
4432 if (('A' <= *__t && *__t <= 'Z') ||
4433 ('a' <= *__t && *__t <= 'z'))
4436 *__str = _CharT(*__t % 32);
4438 __push_char(_CharT(*__t % 32));
4441 #ifndef _LIBCPP_NO_EXCEPTIONS
4443 throw regex_error(regex_constants::error_escape);
4444 #endif // _LIBCPP_NO_EXCEPTIONS
4446 #ifndef _LIBCPP_NO_EXCEPTIONS
4448 throw regex_error(regex_constants::error_escape);
4449 #endif // _LIBCPP_NO_EXCEPTIONS
4453 #ifndef _LIBCPP_NO_EXCEPTIONS
4454 if (__first == __last)
4455 throw regex_error(regex_constants::error_escape);
4456 #endif // _LIBCPP_NO_EXCEPTIONS
4457 __hd = __traits_.value(*__first, 16);
4458 #ifndef _LIBCPP_NO_EXCEPTIONS
4460 throw regex_error(regex_constants::error_escape);
4461 #endif // _LIBCPP_NO_EXCEPTIONS
4462 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4464 #ifndef _LIBCPP_NO_EXCEPTIONS
4465 if (__first == __last)
4466 throw regex_error(regex_constants::error_escape);
4467 #endif // _LIBCPP_NO_EXCEPTIONS
4468 __hd = __traits_.value(*__first, 16);
4469 #ifndef _LIBCPP_NO_EXCEPTIONS
4471 throw regex_error(regex_constants::error_escape);
4472 #endif // _LIBCPP_NO_EXCEPTIONS
4473 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4477 #ifndef _LIBCPP_NO_EXCEPTIONS
4478 if (__first == __last)
4479 throw regex_error(regex_constants::error_escape);
4480 #endif // _LIBCPP_NO_EXCEPTIONS
4481 __hd = __traits_.value(*__first, 16);
4482 #ifndef _LIBCPP_NO_EXCEPTIONS
4484 throw regex_error(regex_constants::error_escape);
4485 #endif // _LIBCPP_NO_EXCEPTIONS
4486 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4488 #ifndef _LIBCPP_NO_EXCEPTIONS
4489 if (__first == __last)
4490 throw regex_error(regex_constants::error_escape);
4491 #endif // _LIBCPP_NO_EXCEPTIONS
4492 __hd = __traits_.value(*__first, 16);
4493 #ifndef _LIBCPP_NO_EXCEPTIONS
4495 throw regex_error(regex_constants::error_escape);
4496 #endif // _LIBCPP_NO_EXCEPTIONS
4497 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4499 *__str = _CharT(__sum);
4501 __push_char(_CharT(__sum));
4505 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
4510 __push_char(*__first);
4513 #ifndef _LIBCPP_NO_EXCEPTIONS
4515 throw regex_error(regex_constants::error_escape);
4516 #endif // _LIBCPP_NO_EXCEPTIONS
4523 template <class _CharT, class _Traits>
4524 template <class _ForwardIterator>
4526 basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
4527 _ForwardIterator __last)
4529 if (__first != __last)
4549 __push_char(*__first);
4557 template <class _CharT, class _Traits>
4558 template <class _ForwardIterator>
4560 basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
4561 _ForwardIterator __last)
4563 __owns_one_state<_CharT>* __sa = __end_;
4564 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4565 if (__t1 != __first)
4566 __parse_basic_reg_exp(__first, __t1);
4570 if (__first != __last)
4572 while (__first != __last)
4574 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4575 __owns_one_state<_CharT>* __sb = __end_;
4576 if (__t1 != __first)
4577 __parse_basic_reg_exp(__first, __t1);
4580 __push_alternation(__sa, __sb);
4582 if (__first != __last)
4588 template <class _CharT, class _Traits>
4589 template <class _ForwardIterator>
4591 basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
4592 _ForwardIterator __last)
4594 __owns_one_state<_CharT>* __sa = __end_;
4595 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4596 if (__t1 != __first)
4597 __parse_extended_reg_exp(__first, __t1);
4601 if (__first != __last)
4603 while (__first != __last)
4605 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4606 __owns_one_state<_CharT>* __sb = __end_;
4607 if (__t1 != __first)
4608 __parse_extended_reg_exp(__first, __t1);
4611 __push_alternation(__sa, __sb);
4613 if (__first != __last)
4619 template <class _CharT, class _Traits>
4621 basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
4622 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
4625 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4626 __end_->first() = nullptr;
4627 unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
4628 __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
4630 __s->first() = nullptr;
4632 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
4633 __end_ = __e2->second();
4634 __s->first() = __e2.release();
4638 template <class _CharT, class _Traits>
4640 basic_regex<_CharT, _Traits>::__push_char(value_type __c)
4642 if (flags() & icase)
4643 __end_->first() = new __match_char_icase<_CharT, _Traits>
4644 (__traits_, __c, __end_->first());
4645 else if (flags() & collate)
4646 __end_->first() = new __match_char_collate<_CharT, _Traits>
4647 (__traits_, __c, __end_->first());
4649 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
4650 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4653 template <class _CharT, class _Traits>
4655 basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
4657 if (!(__flags_ & nosubs))
4660 new __begin_marked_subexpression<_CharT>(++__marked_count_,
4662 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4666 template <class _CharT, class _Traits>
4668 basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
4670 if (!(__flags_ & nosubs))
4673 new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4674 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4678 template <class _CharT, class _Traits>
4680 basic_regex<_CharT, _Traits>::__push_l_anchor()
4682 __end_->first() = new __l_anchor<_CharT>(__end_->first());
4683 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4686 template <class _CharT, class _Traits>
4688 basic_regex<_CharT, _Traits>::__push_r_anchor()
4690 __end_->first() = new __r_anchor<_CharT>(__end_->first());
4691 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4694 template <class _CharT, class _Traits>
4696 basic_regex<_CharT, _Traits>::__push_match_any()
4698 __end_->first() = new __match_any<_CharT>(__end_->first());
4699 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4702 template <class _CharT, class _Traits>
4704 basic_regex<_CharT, _Traits>::__push_match_any_but_newline()
4706 __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
4707 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4710 template <class _CharT, class _Traits>
4712 basic_regex<_CharT, _Traits>::__push_empty()
4714 __end_->first() = new __empty_state<_CharT>(__end_->first());
4715 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4718 template <class _CharT, class _Traits>
4720 basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
4722 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
4724 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4727 template <class _CharT, class _Traits>
4729 basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
4731 if (flags() & icase)
4732 __end_->first() = new __back_ref_icase<_CharT, _Traits>
4733 (__traits_, __i, __end_->first());
4734 else if (flags() & collate)
4735 __end_->first() = new __back_ref_collate<_CharT, _Traits>
4736 (__traits_, __i, __end_->first());
4738 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
4739 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4742 template <class _CharT, class _Traits>
4744 basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
4745 __owns_one_state<_CharT>* __ea)
4747 __sa->first() = new __alternate<_CharT>(
4748 static_cast<__owns_one_state<_CharT>*>(__sa->first()),
4749 static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4750 __ea->first() = nullptr;
4751 __ea->first() = new __empty_state<_CharT>(__end_->first());
4752 __end_->first() = nullptr;
4753 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4754 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4757 template <class _CharT, class _Traits>
4758 __bracket_expression<_CharT, _Traits>*
4759 basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
4761 __bracket_expression<_CharT, _Traits>* __r =
4762 new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
4763 __negate, __flags_ & icase,
4764 __flags_ & collate);
4765 __end_->first() = __r;
4770 template <class _CharT, class _Traits>
4772 basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
4776 __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
4777 __end_->first(), __mexp);
4778 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4781 typedef basic_regex<char> regex;
4782 typedef basic_regex<wchar_t> wregex;
4786 template <class _BidirectionalIterator>
4787 class _LIBCPP_TYPE_VIS_ONLY sub_match
4788 : public pair<_BidirectionalIterator, _BidirectionalIterator>
4791 typedef _BidirectionalIterator iterator;
4792 typedef typename iterator_traits<iterator>::value_type value_type;
4793 typedef typename iterator_traits<iterator>::difference_type difference_type;
4794 typedef basic_string<value_type> string_type;
4798 _LIBCPP_INLINE_VISIBILITY
4799 _LIBCPP_CONSTEXPR sub_match() : matched() {}
4801 _LIBCPP_INLINE_VISIBILITY
4802 difference_type length() const
4803 {return matched ? _VSTD::distance(this->first, this->second) : 0;}
4804 _LIBCPP_INLINE_VISIBILITY
4805 string_type str() const
4806 {return matched ? string_type(this->first, this->second) : string_type();}
4807 _LIBCPP_INLINE_VISIBILITY
4808 operator string_type() const
4811 _LIBCPP_INLINE_VISIBILITY
4812 int compare(const sub_match& __s) const
4813 {return str().compare(__s.str());}
4814 _LIBCPP_INLINE_VISIBILITY
4815 int compare(const string_type& __s) const
4816 {return str().compare(__s);}
4817 _LIBCPP_INLINE_VISIBILITY
4818 int compare(const value_type* __s) const
4819 {return str().compare(__s);}
4822 typedef sub_match<const char*> csub_match;
4823 typedef sub_match<const wchar_t*> wcsub_match;
4824 typedef sub_match<string::const_iterator> ssub_match;
4825 typedef sub_match<wstring::const_iterator> wssub_match;
4827 template <class _BiIter>
4828 inline _LIBCPP_INLINE_VISIBILITY
4830 operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4832 return __x.compare(__y) == 0;
4835 template <class _BiIter>
4836 inline _LIBCPP_INLINE_VISIBILITY
4838 operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4840 return !(__x == __y);
4843 template <class _BiIter>
4844 inline _LIBCPP_INLINE_VISIBILITY
4846 operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4848 return __x.compare(__y) < 0;
4851 template <class _BiIter>
4852 inline _LIBCPP_INLINE_VISIBILITY
4854 operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4856 return !(__y < __x);
4859 template <class _BiIter>
4860 inline _LIBCPP_INLINE_VISIBILITY
4862 operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4864 return !(__x < __y);
4867 template <class _BiIter>
4868 inline _LIBCPP_INLINE_VISIBILITY
4870 operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4875 template <class _BiIter, class _ST, class _SA>
4876 inline _LIBCPP_INLINE_VISIBILITY
4878 operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4879 const sub_match<_BiIter>& __y)
4881 return __y.compare(__x.c_str()) == 0;
4884 template <class _BiIter, class _ST, class _SA>
4885 inline _LIBCPP_INLINE_VISIBILITY
4887 operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4888 const sub_match<_BiIter>& __y)
4890 return !(__x == __y);
4893 template <class _BiIter, class _ST, class _SA>
4894 inline _LIBCPP_INLINE_VISIBILITY
4896 operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4897 const sub_match<_BiIter>& __y)
4899 return __y.compare(__x.c_str()) > 0;
4902 template <class _BiIter, class _ST, class _SA>
4903 inline _LIBCPP_INLINE_VISIBILITY
4905 operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4906 const sub_match<_BiIter>& __y)
4911 template <class _BiIter, class _ST, class _SA>
4912 inline _LIBCPP_INLINE_VISIBILITY
4913 bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4914 const sub_match<_BiIter>& __y)
4916 return !(__x < __y);
4919 template <class _BiIter, class _ST, class _SA>
4920 inline _LIBCPP_INLINE_VISIBILITY
4922 operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4923 const sub_match<_BiIter>& __y)
4925 return !(__y < __x);
4928 template <class _BiIter, class _ST, class _SA>
4929 inline _LIBCPP_INLINE_VISIBILITY
4931 operator==(const sub_match<_BiIter>& __x,
4932 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4934 return __x.compare(__y.c_str()) == 0;
4937 template <class _BiIter, class _ST, class _SA>
4938 inline _LIBCPP_INLINE_VISIBILITY
4940 operator!=(const sub_match<_BiIter>& __x,
4941 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4943 return !(__x == __y);
4946 template <class _BiIter, class _ST, class _SA>
4947 inline _LIBCPP_INLINE_VISIBILITY
4949 operator<(const sub_match<_BiIter>& __x,
4950 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4952 return __x.compare(__y.c_str()) < 0;
4955 template <class _BiIter, class _ST, class _SA>
4956 inline _LIBCPP_INLINE_VISIBILITY
4957 bool operator>(const sub_match<_BiIter>& __x,
4958 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4963 template <class _BiIter, class _ST, class _SA>
4964 inline _LIBCPP_INLINE_VISIBILITY
4966 operator>=(const sub_match<_BiIter>& __x,
4967 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4969 return !(__x < __y);
4972 template <class _BiIter, class _ST, class _SA>
4973 inline _LIBCPP_INLINE_VISIBILITY
4975 operator<=(const sub_match<_BiIter>& __x,
4976 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4978 return !(__y < __x);
4981 template <class _BiIter>
4982 inline _LIBCPP_INLINE_VISIBILITY
4984 operator==(typename iterator_traits<_BiIter>::value_type const* __x,
4985 const sub_match<_BiIter>& __y)
4987 return __y.compare(__x) == 0;
4990 template <class _BiIter>
4991 inline _LIBCPP_INLINE_VISIBILITY
4993 operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
4994 const sub_match<_BiIter>& __y)
4996 return !(__x == __y);
4999 template <class _BiIter>
5000 inline _LIBCPP_INLINE_VISIBILITY
5002 operator<(typename iterator_traits<_BiIter>::value_type const* __x,
5003 const sub_match<_BiIter>& __y)
5005 return __y.compare(__x) > 0;
5008 template <class _BiIter>
5009 inline _LIBCPP_INLINE_VISIBILITY
5011 operator>(typename iterator_traits<_BiIter>::value_type const* __x,
5012 const sub_match<_BiIter>& __y)
5017 template <class _BiIter>
5018 inline _LIBCPP_INLINE_VISIBILITY
5020 operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
5021 const sub_match<_BiIter>& __y)
5023 return !(__x < __y);
5026 template <class _BiIter>
5027 inline _LIBCPP_INLINE_VISIBILITY
5029 operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
5030 const sub_match<_BiIter>& __y)
5032 return !(__y < __x);
5035 template <class _BiIter>
5036 inline _LIBCPP_INLINE_VISIBILITY
5038 operator==(const sub_match<_BiIter>& __x,
5039 typename iterator_traits<_BiIter>::value_type const* __y)
5041 return __x.compare(__y) == 0;
5044 template <class _BiIter>
5045 inline _LIBCPP_INLINE_VISIBILITY
5047 operator!=(const sub_match<_BiIter>& __x,
5048 typename iterator_traits<_BiIter>::value_type const* __y)
5050 return !(__x == __y);
5053 template <class _BiIter>
5054 inline _LIBCPP_INLINE_VISIBILITY
5056 operator<(const sub_match<_BiIter>& __x,
5057 typename iterator_traits<_BiIter>::value_type const* __y)
5059 return __x.compare(__y) < 0;
5062 template <class _BiIter>
5063 inline _LIBCPP_INLINE_VISIBILITY
5065 operator>(const sub_match<_BiIter>& __x,
5066 typename iterator_traits<_BiIter>::value_type const* __y)
5071 template <class _BiIter>
5072 inline _LIBCPP_INLINE_VISIBILITY
5074 operator>=(const sub_match<_BiIter>& __x,
5075 typename iterator_traits<_BiIter>::value_type const* __y)
5077 return !(__x < __y);
5080 template <class _BiIter>
5081 inline _LIBCPP_INLINE_VISIBILITY
5083 operator<=(const sub_match<_BiIter>& __x,
5084 typename iterator_traits<_BiIter>::value_type const* __y)
5086 return !(__y < __x);
5089 template <class _BiIter>
5090 inline _LIBCPP_INLINE_VISIBILITY
5092 operator==(typename iterator_traits<_BiIter>::value_type const& __x,
5093 const sub_match<_BiIter>& __y)
5095 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5096 return __y.compare(string_type(1, __x)) == 0;
5099 template <class _BiIter>
5100 inline _LIBCPP_INLINE_VISIBILITY
5102 operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
5103 const sub_match<_BiIter>& __y)
5105 return !(__x == __y);
5108 template <class _BiIter>
5109 inline _LIBCPP_INLINE_VISIBILITY
5111 operator<(typename iterator_traits<_BiIter>::value_type const& __x,
5112 const sub_match<_BiIter>& __y)
5114 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5115 return __y.compare(string_type(1, __x)) > 0;
5118 template <class _BiIter>
5119 inline _LIBCPP_INLINE_VISIBILITY
5121 operator>(typename iterator_traits<_BiIter>::value_type const& __x,
5122 const sub_match<_BiIter>& __y)
5127 template <class _BiIter>
5128 inline _LIBCPP_INLINE_VISIBILITY
5130 operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
5131 const sub_match<_BiIter>& __y)
5133 return !(__x < __y);
5136 template <class _BiIter>
5137 inline _LIBCPP_INLINE_VISIBILITY
5139 operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
5140 const sub_match<_BiIter>& __y)
5142 return !(__y < __x);
5145 template <class _BiIter>
5146 inline _LIBCPP_INLINE_VISIBILITY
5148 operator==(const sub_match<_BiIter>& __x,
5149 typename iterator_traits<_BiIter>::value_type const& __y)
5151 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5152 return __x.compare(string_type(1, __y)) == 0;
5155 template <class _BiIter>
5156 inline _LIBCPP_INLINE_VISIBILITY
5158 operator!=(const sub_match<_BiIter>& __x,
5159 typename iterator_traits<_BiIter>::value_type const& __y)
5161 return !(__x == __y);
5164 template <class _BiIter>
5165 inline _LIBCPP_INLINE_VISIBILITY
5167 operator<(const sub_match<_BiIter>& __x,
5168 typename iterator_traits<_BiIter>::value_type const& __y)
5170 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5171 return __x.compare(string_type(1, __y)) < 0;
5174 template <class _BiIter>
5175 inline _LIBCPP_INLINE_VISIBILITY
5177 operator>(const sub_match<_BiIter>& __x,
5178 typename iterator_traits<_BiIter>::value_type const& __y)
5183 template <class _BiIter>
5184 inline _LIBCPP_INLINE_VISIBILITY
5186 operator>=(const sub_match<_BiIter>& __x,
5187 typename iterator_traits<_BiIter>::value_type const& __y)
5189 return !(__x < __y);
5192 template <class _BiIter>
5193 inline _LIBCPP_INLINE_VISIBILITY
5195 operator<=(const sub_match<_BiIter>& __x,
5196 typename iterator_traits<_BiIter>::value_type const& __y)
5198 return !(__y < __x);
5201 template <class _CharT, class _ST, class _BiIter>
5202 inline _LIBCPP_INLINE_VISIBILITY
5203 basic_ostream<_CharT, _ST>&
5204 operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
5206 return __os << __m.str();
5209 template <class _BidirectionalIterator, class _Allocator>
5210 class _LIBCPP_TYPE_VIS_ONLY match_results
5213 typedef _Allocator allocator_type;
5214 typedef sub_match<_BidirectionalIterator> value_type;
5216 typedef vector<value_type, allocator_type> __container_type;
5218 __container_type __matches_;
5219 value_type __unmatched_;
5220 value_type __prefix_;
5221 value_type __suffix_;
5224 _BidirectionalIterator __position_start_;
5225 typedef const value_type& const_reference;
5226 typedef const_reference reference;
5227 typedef typename __container_type::const_iterator const_iterator;
5228 typedef const_iterator iterator;
5229 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
5230 typedef typename allocator_traits<allocator_type>::size_type size_type;
5231 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
5232 typedef basic_string<char_type> string_type;
5234 // construct/copy/destroy:
5235 explicit match_results(const allocator_type& __a = allocator_type());
5236 // match_results(const match_results&) = default;
5237 // match_results& operator=(const match_results&) = default;
5238 // match_results(match_results&& __m) = default;
5239 // match_results& operator=(match_results&& __m) = default;
5240 // ~match_results() = default;
5242 _LIBCPP_INLINE_VISIBILITY
5243 bool ready() const {return __ready_;}
5246 _LIBCPP_INLINE_VISIBILITY
5247 size_type size() const {return __matches_.size();}
5248 _LIBCPP_INLINE_VISIBILITY
5249 size_type max_size() const {return __matches_.max_size();}
5250 _LIBCPP_INLINE_VISIBILITY
5251 bool empty() const {return size() == 0;}
5254 _LIBCPP_INLINE_VISIBILITY
5255 difference_type length(size_type __sub = 0) const
5256 {return (*this)[__sub].length();}
5257 _LIBCPP_INLINE_VISIBILITY
5258 difference_type position(size_type __sub = 0) const
5259 {return _VSTD::distance(__position_start_, (*this)[__sub].first);}
5260 _LIBCPP_INLINE_VISIBILITY
5261 string_type str(size_type __sub = 0) const
5262 {return (*this)[__sub].str();}
5263 _LIBCPP_INLINE_VISIBILITY
5264 const_reference operator[](size_type __n) const
5265 {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
5267 _LIBCPP_INLINE_VISIBILITY
5268 const_reference prefix() const {return __prefix_;}
5269 _LIBCPP_INLINE_VISIBILITY
5270 const_reference suffix() const {return __suffix_;}
5272 _LIBCPP_INLINE_VISIBILITY
5273 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();}
5274 _LIBCPP_INLINE_VISIBILITY
5275 const_iterator end() const {return __matches_.end();}
5276 _LIBCPP_INLINE_VISIBILITY
5277 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();}
5278 _LIBCPP_INLINE_VISIBILITY
5279 const_iterator cend() const {return __matches_.end();}
5282 template <class _OutputIter>
5284 format(_OutputIter __out, const char_type* __fmt_first,
5285 const char_type* __fmt_last,
5286 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
5287 template <class _OutputIter, class _ST, class _SA>
5288 _LIBCPP_INLINE_VISIBILITY
5290 format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt,
5291 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5292 {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
5293 template <class _ST, class _SA>
5294 _LIBCPP_INLINE_VISIBILITY
5295 basic_string<char_type, _ST, _SA>
5296 format(const basic_string<char_type, _ST, _SA>& __fmt,
5297 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5299 basic_string<char_type, _ST, _SA> __r;
5300 format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
5304 _LIBCPP_INLINE_VISIBILITY
5306 format(const char_type* __fmt,
5307 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5310 format(back_inserter(__r), __fmt,
5311 __fmt + char_traits<char_type>::length(__fmt), __flags);
5316 _LIBCPP_INLINE_VISIBILITY
5317 allocator_type get_allocator() const {return __matches_.get_allocator();}
5320 void swap(match_results& __m);
5322 template <class _Bp, class _Ap>
5323 _LIBCPP_INLINE_VISIBILITY
5324 void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
5325 const match_results<_Bp, _Ap>& __m, bool __no_update_pos)
5327 _Bp __mf = __m.prefix().first;
5328 __matches_.resize(__m.size());
5329 for (size_type __i = 0; __i < __matches_.size(); ++__i)
5331 __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first));
5332 __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second));
5333 __matches_[__i].matched = __m[__i].matched;
5335 __unmatched_.first = __l;
5336 __unmatched_.second = __l;
5337 __unmatched_.matched = false;
5338 __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first));
5339 __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second));
5340 __prefix_.matched = __m.prefix().matched;
5341 __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first));
5342 __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second));
5343 __suffix_.matched = __m.suffix().matched;
5344 if (!__no_update_pos)
5345 __position_start_ = __prefix_.first;
5346 __ready_ = __m.ready();
5350 void __init(unsigned __s,
5351 _BidirectionalIterator __f, _BidirectionalIterator __l,
5352 bool __no_update_pos = false);
5354 template <class, class> friend class basic_regex;
5356 template <class _Bp, class _Ap, class _Cp, class _Tp>
5359 regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
5360 regex_constants::match_flag_type);
5362 template <class _Bp, class _Ap>
5365 operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
5367 template <class, class> friend class __lookahead;
5370 template <class _BidirectionalIterator, class _Allocator>
5371 match_results<_BidirectionalIterator, _Allocator>::match_results(
5372 const allocator_type& __a)
5377 __position_start_(),
5382 template <class _BidirectionalIterator, class _Allocator>
5384 match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
5385 _BidirectionalIterator __f, _BidirectionalIterator __l,
5386 bool __no_update_pos)
5388 __unmatched_.first = __l;
5389 __unmatched_.second = __l;
5390 __unmatched_.matched = false;
5391 __matches_.assign(__s, __unmatched_);
5392 __prefix_.first = __f;
5393 __prefix_.second = __f;
5394 __prefix_.matched = false;
5395 __suffix_ = __unmatched_;
5396 if (!__no_update_pos)
5397 __position_start_ = __prefix_.first;
5401 template <class _BidirectionalIterator, class _Allocator>
5402 template <class _OutputIter>
5404 match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
5405 const char_type* __fmt_first, const char_type* __fmt_last,
5406 regex_constants::match_flag_type __flags) const
5408 if (__flags & regex_constants::format_sed)
5410 for (; __fmt_first != __fmt_last; ++__fmt_first)
5412 if (*__fmt_first == '&')
5413 __out = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5415 else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
5418 if ('0' <= *__fmt_first && *__fmt_first <= '9')
5420 size_t __i = *__fmt_first - '0';
5421 __out = _VSTD::copy(__matches_[__i].first,
5422 __matches_[__i].second, __out);
5426 *__out = *__fmt_first;
5432 *__out = *__fmt_first;
5439 for (; __fmt_first != __fmt_last; ++__fmt_first)
5441 if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
5443 switch (__fmt_first[1])
5446 *__out = *++__fmt_first;
5451 __out = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5456 __out = _VSTD::copy(__prefix_.first, __prefix_.second, __out);
5460 __out = _VSTD::copy(__suffix_.first, __suffix_.second, __out);
5463 if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5466 size_t __i = *__fmt_first - '0';
5467 if (__fmt_first + 1 != __fmt_last &&
5468 '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5471 __i = 10 * __i + *__fmt_first - '0';
5473 __out = _VSTD::copy(__matches_[__i].first,
5474 __matches_[__i].second, __out);
5478 *__out = *__fmt_first;
5486 *__out = *__fmt_first;
5494 template <class _BidirectionalIterator, class _Allocator>
5496 match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
5499 swap(__matches_, __m.__matches_);
5500 swap(__unmatched_, __m.__unmatched_);
5501 swap(__prefix_, __m.__prefix_);
5502 swap(__suffix_, __m.__suffix_);
5503 swap(__position_start_, __m.__position_start_);
5504 swap(__ready_, __m.__ready_);
5507 typedef match_results<const char*> cmatch;
5508 typedef match_results<const wchar_t*> wcmatch;
5509 typedef match_results<string::const_iterator> smatch;
5510 typedef match_results<wstring::const_iterator> wsmatch;
5512 template <class _BidirectionalIterator, class _Allocator>
5514 operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
5515 const match_results<_BidirectionalIterator, _Allocator>& __y)
5517 if (__x.__ready_ != __y.__ready_)
5521 return __x.__matches_ == __y.__matches_ &&
5522 __x.__prefix_ == __y.__prefix_ &&
5523 __x.__suffix_ == __y.__suffix_;
5526 template <class _BidirectionalIterator, class _Allocator>
5527 inline _LIBCPP_INLINE_VISIBILITY
5529 operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
5530 const match_results<_BidirectionalIterator, _Allocator>& __y)
5532 return !(__x == __y);
5535 template <class _BidirectionalIterator, class _Allocator>
5536 inline _LIBCPP_INLINE_VISIBILITY
5538 swap(match_results<_BidirectionalIterator, _Allocator>& __x,
5539 match_results<_BidirectionalIterator, _Allocator>& __y)
5546 template <class _CharT, class _Traits>
5547 template <class _Allocator>
5549 basic_regex<_CharT, _Traits>::__match_at_start_ecma(
5550 const _CharT* __first, const _CharT* __last,
5551 match_results<const _CharT*, _Allocator>& __m,
5552 regex_constants::match_flag_type __flags, bool __at_first) const
5554 vector<__state> __states;
5555 __node* __st = __start_.get();
5558 __states.push_back(__state());
5559 __states.back().__do_ = 0;
5560 __states.back().__first_ = __first;
5561 __states.back().__current_ = __first;
5562 __states.back().__last_ = __last;
5563 __states.back().__sub_matches_.resize(mark_count());
5564 __states.back().__loop_data_.resize(__loop_count());
5565 __states.back().__node_ = __st;
5566 __states.back().__flags_ = __flags;
5567 __states.back().__at_first_ = __at_first;
5570 __state& __s = __states.back();
5572 __s.__node_->__exec(__s);
5575 case __state::__end_state:
5576 __m.__matches_[0].first = __first;
5577 __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
5578 __m.__matches_[0].matched = true;
5579 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
5580 __m.__matches_[__i+1] = __s.__sub_matches_[__i];
5582 case __state::__accept_and_consume:
5583 case __state::__repeat:
5584 case __state::__accept_but_not_consume:
5586 case __state::__split:
5588 __state __snext = __s;
5589 __s.__node_->__exec_split(true, __s);
5590 __snext.__node_->__exec_split(false, __snext);
5591 __states.push_back(_VSTD::move(__snext));
5594 case __state::__reject:
5595 __states.pop_back();
5598 #ifndef _LIBCPP_NO_EXCEPTIONS
5599 throw regex_error(regex_constants::__re_err_unknown);
5604 } while (!__states.empty());
5609 template <class _CharT, class _Traits>
5610 template <class _Allocator>
5612 basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
5613 const _CharT* __first, const _CharT* __last,
5614 match_results<const _CharT*, _Allocator>& __m,
5615 regex_constants::match_flag_type __flags, bool __at_first) const
5617 deque<__state> __states;
5618 ptrdiff_t __highest_j = 0;
5619 ptrdiff_t _Np = _VSTD::distance(__first, __last);
5620 __node* __st = __start_.get();
5623 __states.push_back(__state());
5624 __states.back().__do_ = 0;
5625 __states.back().__first_ = __first;
5626 __states.back().__current_ = __first;
5627 __states.back().__last_ = __last;
5628 __states.back().__loop_data_.resize(__loop_count());
5629 __states.back().__node_ = __st;
5630 __states.back().__flags_ = __flags;
5631 __states.back().__at_first_ = __at_first;
5632 bool __matched = false;
5635 __state& __s = __states.back();
5637 __s.__node_->__exec(__s);
5640 case __state::__end_state:
5641 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
5642 __highest_j = __s.__current_ - __s.__first_;
5644 if (__highest_j == _Np)
5647 __states.pop_back();
5649 case __state::__consume_input:
5651 case __state::__accept_and_consume:
5652 __states.push_front(_VSTD::move(__s));
5653 __states.pop_back();
5655 case __state::__repeat:
5656 case __state::__accept_but_not_consume:
5658 case __state::__split:
5660 __state __snext = __s;
5661 __s.__node_->__exec_split(true, __s);
5662 __snext.__node_->__exec_split(false, __snext);
5663 __states.push_back(_VSTD::move(__snext));
5666 case __state::__reject:
5667 __states.pop_back();
5670 #ifndef _LIBCPP_NO_EXCEPTIONS
5671 throw regex_error(regex_constants::__re_err_unknown);
5675 } while (!__states.empty());
5678 __m.__matches_[0].first = __first;
5679 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
5680 __m.__matches_[0].matched = true;
5687 template <class _CharT, class _Traits>
5688 template <class _Allocator>
5690 basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
5691 const _CharT* __first, const _CharT* __last,
5692 match_results<const _CharT*, _Allocator>& __m,
5693 regex_constants::match_flag_type __flags, bool __at_first) const
5695 vector<__state> __states;
5696 __state __best_state;
5698 ptrdiff_t __highest_j = 0;
5699 ptrdiff_t _Np = _VSTD::distance(__first, __last);
5700 __node* __st = __start_.get();
5703 __states.push_back(__state());
5704 __states.back().__do_ = 0;
5705 __states.back().__first_ = __first;
5706 __states.back().__current_ = __first;
5707 __states.back().__last_ = __last;
5708 __states.back().__sub_matches_.resize(mark_count());
5709 __states.back().__loop_data_.resize(__loop_count());
5710 __states.back().__node_ = __st;
5711 __states.back().__flags_ = __flags;
5712 __states.back().__at_first_ = __at_first;
5713 const _CharT* __current = __first;
5714 bool __matched = false;
5717 __state& __s = __states.back();
5719 __s.__node_->__exec(__s);
5722 case __state::__end_state:
5723 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
5725 __highest_j = __s.__current_ - __s.__first_;
5729 if (__highest_j == _Np)
5732 __states.pop_back();
5734 case __state::__accept_and_consume:
5735 __j += __s.__current_ - __current;
5736 __current = __s.__current_;
5738 case __state::__repeat:
5739 case __state::__accept_but_not_consume:
5741 case __state::__split:
5743 __state __snext = __s;
5744 __s.__node_->__exec_split(true, __s);
5745 __snext.__node_->__exec_split(false, __snext);
5746 __states.push_back(_VSTD::move(__snext));
5749 case __state::__reject:
5750 __states.pop_back();
5753 #ifndef _LIBCPP_NO_EXCEPTIONS
5754 throw regex_error(regex_constants::__re_err_unknown);
5758 } while (!__states.empty());
5761 __m.__matches_[0].first = __first;
5762 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
5763 __m.__matches_[0].matched = true;
5764 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
5765 __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
5772 template <class _CharT, class _Traits>
5773 template <class _Allocator>
5775 basic_regex<_CharT, _Traits>::__match_at_start(
5776 const _CharT* __first, const _CharT* __last,
5777 match_results<const _CharT*, _Allocator>& __m,
5778 regex_constants::match_flag_type __flags, bool __at_first) const
5780 if ((__flags_ & 0x1F0) == ECMAScript)
5781 return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
5782 if (mark_count() == 0)
5783 return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
5784 return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
5787 template <class _CharT, class _Traits>
5788 template <class _Allocator>
5790 basic_regex<_CharT, _Traits>::__search(
5791 const _CharT* __first, const _CharT* __last,
5792 match_results<const _CharT*, _Allocator>& __m,
5793 regex_constants::match_flag_type __flags) const
5795 __m.__init(1 + mark_count(), __first, __last,
5796 __flags & regex_constants::__no_update_pos);
5797 if (__match_at_start(__first, __last, __m, __flags,
5798 !(__flags & regex_constants::__no_update_pos)))
5800 __m.__prefix_.second = __m[0].first;
5801 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5802 __m.__suffix_.first = __m[0].second;
5803 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5806 if (__first != __last && !(__flags & regex_constants::match_continuous))
5808 __flags |= regex_constants::match_prev_avail;
5809 for (++__first; __first != __last; ++__first)
5811 __m.__matches_.assign(__m.size(), __m.__unmatched_);
5812 if (__match_at_start(__first, __last, __m, __flags, false))
5814 __m.__prefix_.second = __m[0].first;
5815 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5816 __m.__suffix_.first = __m[0].second;
5817 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5820 __m.__matches_.assign(__m.size(), __m.__unmatched_);
5823 __m.__matches_.clear();
5827 template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5828 inline _LIBCPP_INLINE_VISIBILITY
5830 regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5831 match_results<_BidirectionalIterator, _Allocator>& __m,
5832 const basic_regex<_CharT, _Traits>& __e,
5833 regex_constants::match_flag_type __flags = regex_constants::match_default)
5835 int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
5836 basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last);
5837 match_results<const _CharT*> __mc;
5838 bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
5839 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
5843 template <class _Iter, class _Allocator, class _CharT, class _Traits>
5844 inline _LIBCPP_INLINE_VISIBILITY
5846 regex_search(__wrap_iter<_Iter> __first,
5847 __wrap_iter<_Iter> __last,
5848 match_results<__wrap_iter<_Iter>, _Allocator>& __m,
5849 const basic_regex<_CharT, _Traits>& __e,
5850 regex_constants::match_flag_type __flags = regex_constants::match_default)
5852 match_results<const _CharT*> __mc;
5853 bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
5854 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
5858 template <class _Allocator, class _CharT, class _Traits>
5859 inline _LIBCPP_INLINE_VISIBILITY
5861 regex_search(const _CharT* __first, const _CharT* __last,
5862 match_results<const _CharT*, _Allocator>& __m,
5863 const basic_regex<_CharT, _Traits>& __e,
5864 regex_constants::match_flag_type __flags = regex_constants::match_default)
5866 return __e.__search(__first, __last, __m, __flags);
5869 template <class _BidirectionalIterator, class _CharT, class _Traits>
5870 inline _LIBCPP_INLINE_VISIBILITY
5872 regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5873 const basic_regex<_CharT, _Traits>& __e,
5874 regex_constants::match_flag_type __flags = regex_constants::match_default)
5876 basic_string<_CharT> __s(__first, __last);
5877 match_results<const _CharT*> __mc;
5878 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5881 template <class _CharT, class _Traits>
5882 inline _LIBCPP_INLINE_VISIBILITY
5884 regex_search(const _CharT* __first, const _CharT* __last,
5885 const basic_regex<_CharT, _Traits>& __e,
5886 regex_constants::match_flag_type __flags = regex_constants::match_default)
5888 match_results<const _CharT*> __mc;
5889 return __e.__search(__first, __last, __mc, __flags);
5892 template <class _CharT, class _Allocator, class _Traits>
5893 inline _LIBCPP_INLINE_VISIBILITY
5895 regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5896 const basic_regex<_CharT, _Traits>& __e,
5897 regex_constants::match_flag_type __flags = regex_constants::match_default)
5899 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
5902 template <class _CharT, class _Traits>
5903 inline _LIBCPP_INLINE_VISIBILITY
5905 regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5906 regex_constants::match_flag_type __flags = regex_constants::match_default)
5908 match_results<const _CharT*> __m;
5909 return _VSTD::regex_search(__str, __m, __e, __flags);
5912 template <class _ST, class _SA, class _CharT, class _Traits>
5913 inline _LIBCPP_INLINE_VISIBILITY
5915 regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5916 const basic_regex<_CharT, _Traits>& __e,
5917 regex_constants::match_flag_type __flags = regex_constants::match_default)
5919 match_results<const _CharT*> __mc;
5920 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5923 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5924 inline _LIBCPP_INLINE_VISIBILITY
5926 regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5927 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5928 const basic_regex<_CharT, _Traits>& __e,
5929 regex_constants::match_flag_type __flags = regex_constants::match_default)
5931 match_results<const _CharT*> __mc;
5932 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5933 __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
5939 template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5941 regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5942 match_results<_BidirectionalIterator, _Allocator>& __m,
5943 const basic_regex<_CharT, _Traits>& __e,
5944 regex_constants::match_flag_type __flags = regex_constants::match_default)
5946 bool __r = _VSTD::regex_search(__first, __last, __m, __e,
5947 __flags | regex_constants::match_continuous);
5950 __r = !__m.suffix().matched;
5952 __m.__matches_.clear();
5957 template <class _BidirectionalIterator, class _CharT, class _Traits>
5958 inline _LIBCPP_INLINE_VISIBILITY
5960 regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5961 const basic_regex<_CharT, _Traits>& __e,
5962 regex_constants::match_flag_type __flags = regex_constants::match_default)
5964 match_results<_BidirectionalIterator> __m;
5965 return _VSTD::regex_match(__first, __last, __m, __e, __flags);
5968 template <class _CharT, class _Allocator, class _Traits>
5969 inline _LIBCPP_INLINE_VISIBILITY
5971 regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5972 const basic_regex<_CharT, _Traits>& __e,
5973 regex_constants::match_flag_type __flags = regex_constants::match_default)
5975 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
5978 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5979 inline _LIBCPP_INLINE_VISIBILITY
5981 regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5982 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5983 const basic_regex<_CharT, _Traits>& __e,
5984 regex_constants::match_flag_type __flags = regex_constants::match_default)
5986 return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
5989 template <class _CharT, class _Traits>
5990 inline _LIBCPP_INLINE_VISIBILITY
5992 regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5993 regex_constants::match_flag_type __flags = regex_constants::match_default)
5995 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
5998 template <class _ST, class _SA, class _CharT, class _Traits>
5999 inline _LIBCPP_INLINE_VISIBILITY
6001 regex_match(const basic_string<_CharT, _ST, _SA>& __s,
6002 const basic_regex<_CharT, _Traits>& __e,
6003 regex_constants::match_flag_type __flags = regex_constants::match_default)
6005 return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags);
6010 template <class _BidirectionalIterator,
6011 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6012 class _Traits = regex_traits<_CharT> >
6013 class _LIBCPP_TYPE_VIS_ONLY regex_iterator
6016 typedef basic_regex<_CharT, _Traits> regex_type;
6017 typedef match_results<_BidirectionalIterator> value_type;
6018 typedef ptrdiff_t difference_type;
6019 typedef const value_type* pointer;
6020 typedef const value_type& reference;
6021 typedef forward_iterator_tag iterator_category;
6024 _BidirectionalIterator __begin_;
6025 _BidirectionalIterator __end_;
6026 const regex_type* __pregex_;
6027 regex_constants::match_flag_type __flags_;
6028 value_type __match_;
6032 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6033 const regex_type& __re,
6034 regex_constants::match_flag_type __m = regex_constants::match_default);
6036 bool operator==(const regex_iterator& __x) const;
6037 _LIBCPP_INLINE_VISIBILITY
6038 bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
6040 _LIBCPP_INLINE_VISIBILITY
6041 reference operator*() const {return __match_;}
6042 _LIBCPP_INLINE_VISIBILITY
6043 pointer operator->() const {return &__match_;}
6045 regex_iterator& operator++();
6046 _LIBCPP_INLINE_VISIBILITY
6047 regex_iterator operator++(int)
6049 regex_iterator __t(*this);
6055 template <class _BidirectionalIterator, class _CharT, class _Traits>
6056 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
6057 : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
6061 template <class _BidirectionalIterator, class _CharT, class _Traits>
6062 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6063 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6064 const regex_type& __re, regex_constants::match_flag_type __m)
6070 _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
6073 template <class _BidirectionalIterator, class _CharT, class _Traits>
6075 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6076 operator==(const regex_iterator& __x) const
6078 if (__match_.empty() && __x.__match_.empty())
6080 if (__match_.empty() || __x.__match_.empty())
6082 return __begin_ == __x.__begin_ &&
6083 __end_ == __x.__end_ &&
6084 __pregex_ == __x.__pregex_ &&
6085 __flags_ == __x.__flags_ &&
6086 __match_[0] == __x.__match_[0];
6089 template <class _BidirectionalIterator, class _CharT, class _Traits>
6090 regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
6091 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6093 __flags_ |= regex_constants::__no_update_pos;
6094 _BidirectionalIterator __start = __match_[0].second;
6095 if (__match_.empty())
6097 if (__start == __end_)
6099 __match_ = value_type();
6102 else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_,
6103 __flags_ | regex_constants::match_not_null |
6104 regex_constants::match_continuous))
6109 __flags_ |= regex_constants::match_prev_avail;
6110 if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
6111 __match_ = value_type();
6115 typedef regex_iterator<const char*> cregex_iterator;
6116 typedef regex_iterator<const wchar_t*> wcregex_iterator;
6117 typedef regex_iterator<string::const_iterator> sregex_iterator;
6118 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
6120 // regex_token_iterator
6122 template <class _BidirectionalIterator,
6123 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6124 class _Traits = regex_traits<_CharT> >
6125 class _LIBCPP_TYPE_VIS_ONLY regex_token_iterator
6128 typedef basic_regex<_CharT, _Traits> regex_type;
6129 typedef sub_match<_BidirectionalIterator> value_type;
6130 typedef ptrdiff_t difference_type;
6131 typedef const value_type* pointer;
6132 typedef const value_type& reference;
6133 typedef forward_iterator_tag iterator_category;
6136 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
6138 _Position __position_;
6139 const value_type* __result_;
6140 value_type __suffix_;
6142 vector<int> __subs_;
6145 regex_token_iterator();
6146 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6147 const regex_type& __re, int __submatch = 0,
6148 regex_constants::match_flag_type __m =
6149 regex_constants::match_default);
6150 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6151 const regex_type& __re, const vector<int>& __submatches,
6152 regex_constants::match_flag_type __m =
6153 regex_constants::match_default);
6154 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6155 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6156 const regex_type& __re,
6157 initializer_list<int> __submatches,
6158 regex_constants::match_flag_type __m =
6159 regex_constants::match_default);
6160 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6161 template <size_t _Np>
6162 regex_token_iterator(_BidirectionalIterator __a,
6163 _BidirectionalIterator __b,
6164 const regex_type& __re,
6165 const int (&__submatches)[_Np],
6166 regex_constants::match_flag_type __m =
6167 regex_constants::match_default);
6168 regex_token_iterator(const regex_token_iterator&);
6169 regex_token_iterator& operator=(const regex_token_iterator&);
6171 bool operator==(const regex_token_iterator& __x) const;
6172 _LIBCPP_INLINE_VISIBILITY
6173 bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
6175 _LIBCPP_INLINE_VISIBILITY
6176 const value_type& operator*() const {return *__result_;}
6177 _LIBCPP_INLINE_VISIBILITY
6178 const value_type* operator->() const {return __result_;}
6180 regex_token_iterator& operator++();
6181 _LIBCPP_INLINE_VISIBILITY
6182 regex_token_iterator operator++(int)
6184 regex_token_iterator __t(*this);
6190 void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
6193 template <class _BidirectionalIterator, class _CharT, class _Traits>
6194 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6195 regex_token_iterator()
6196 : __result_(nullptr),
6202 template <class _BidirectionalIterator, class _CharT, class _Traits>
6204 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6205 __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
6207 if (__position_ != _Position())
6209 if (__subs_[_N_] == -1)
6210 __result_ = &__position_->prefix();
6212 __result_ = &(*__position_)[__subs_[_N_]];
6214 else if (__subs_[_N_] == -1)
6216 __suffix_.matched = true;
6217 __suffix_.first = __a;
6218 __suffix_.second = __b;
6219 __result_ = &__suffix_;
6222 __result_ = nullptr;
6225 template <class _BidirectionalIterator, class _CharT, class _Traits>
6226 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6227 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6228 const regex_type& __re, int __submatch,
6229 regex_constants::match_flag_type __m)
6230 : __position_(__a, __b, __re, __m),
6232 __subs_(1, __submatch)
6237 template <class _BidirectionalIterator, class _CharT, class _Traits>
6238 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6239 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6240 const regex_type& __re, const vector<int>& __submatches,
6241 regex_constants::match_flag_type __m)
6242 : __position_(__a, __b, __re, __m),
6244 __subs_(__submatches)
6249 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6251 template <class _BidirectionalIterator, class _CharT, class _Traits>
6252 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6253 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6254 const regex_type& __re,
6255 initializer_list<int> __submatches,
6256 regex_constants::match_flag_type __m)
6257 : __position_(__a, __b, __re, __m),
6259 __subs_(__submatches)
6264 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6266 template <class _BidirectionalIterator, class _CharT, class _Traits>
6267 template <size_t _Np>
6268 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6269 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6270 const regex_type& __re,
6271 const int (&__submatches)[_Np],
6272 regex_constants::match_flag_type __m)
6273 : __position_(__a, __b, __re, __m),
6275 __subs_(__submatches, __submatches + _Np)
6280 template <class _BidirectionalIterator, class _CharT, class _Traits>
6281 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6282 regex_token_iterator(const regex_token_iterator& __x)
6283 : __position_(__x.__position_),
6284 __result_(__x.__result_),
6285 __suffix_(__x.__suffix_),
6287 __subs_(__x.__subs_)
6289 if (__x.__result_ == &__x.__suffix_)
6290 __result_ == &__suffix_;
6293 template <class _BidirectionalIterator, class _CharT, class _Traits>
6294 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6295 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6296 operator=(const regex_token_iterator& __x)
6300 __position_ = __x.__position_;
6301 if (__x.__result_ == &__x.__suffix_)
6302 __result_ == &__suffix_;
6304 __result_ = __x.__result_;
6305 __suffix_ = __x.__suffix_;
6307 __subs_ = __x.__subs_;
6312 template <class _BidirectionalIterator, class _CharT, class _Traits>
6314 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6315 operator==(const regex_token_iterator& __x) const
6317 if (__result_ == nullptr && __x.__result_ == nullptr)
6319 if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
6320 __suffix_ == __x.__suffix_)
6322 if (__result_ == nullptr || __x.__result_ == nullptr)
6324 if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
6326 return __position_ == __x.__position_ && _N_ == __x._N_ &&
6327 __subs_ == __x.__subs_;
6330 template <class _BidirectionalIterator, class _CharT, class _Traits>
6331 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6332 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6334 _Position __prev = __position_;
6335 if (__result_ == &__suffix_)
6336 __result_ = nullptr;
6337 else if (_N_ + 1 < __subs_.size())
6340 if (__subs_[_N_] == -1)
6341 __result_ = &__position_->prefix();
6343 __result_ = &(*__position_)[__subs_[_N_]];
6349 if (__position_ != _Position())
6351 if (__subs_[_N_] == -1)
6352 __result_ = &__position_->prefix();
6354 __result_ = &(*__position_)[__subs_[_N_]];
6358 if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
6359 && __prev->suffix().length() != 0)
6361 __suffix_.matched = true;
6362 __suffix_.first = __prev->suffix().first;
6363 __suffix_.second = __prev->suffix().second;
6364 __result_ = &__suffix_;
6367 __result_ = nullptr;
6373 typedef regex_token_iterator<const char*> cregex_token_iterator;
6374 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
6375 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
6376 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
6380 template <class _OutputIterator, class _BidirectionalIterator,
6381 class _Traits, class _CharT>
6383 regex_replace(_OutputIterator __out,
6384 _BidirectionalIterator __first, _BidirectionalIterator __last,
6385 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6386 regex_constants::match_flag_type __flags = regex_constants::match_default)
6388 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
6389 _Iter __i(__first, __last, __e, __flags);
6393 if (!(__flags & regex_constants::format_no_copy))
6394 __out = _VSTD::copy(__first, __last, __out);
6398 sub_match<_BidirectionalIterator> __lm;
6399 for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
6401 if (!(__flags & regex_constants::format_no_copy))
6402 __out = _VSTD::copy(__i->prefix().first, __i->prefix().second, __out);
6403 __out = __i->format(__out, __fmt, __fmt + __len, __flags);
6404 __lm = __i->suffix();
6405 if (__flags & regex_constants::format_first_only)
6408 if (!(__flags & regex_constants::format_no_copy))
6409 __out = _VSTD::copy(__lm.first, __lm.second, __out);
6414 template <class _OutputIterator, class _BidirectionalIterator,
6415 class _Traits, class _CharT, class _ST, class _SA>
6416 inline _LIBCPP_INLINE_VISIBILITY
6418 regex_replace(_OutputIterator __out,
6419 _BidirectionalIterator __first, _BidirectionalIterator __last,
6420 const basic_regex<_CharT, _Traits>& __e,
6421 const basic_string<_CharT, _ST, _SA>& __fmt,
6422 regex_constants::match_flag_type __flags = regex_constants::match_default)
6424 return _VSTD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
6427 template <class _Traits, class _CharT, class _ST, class _SA, class _FST,
6429 inline _LIBCPP_INLINE_VISIBILITY
6430 basic_string<_CharT, _ST, _SA>
6431 regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6432 const basic_regex<_CharT, _Traits>& __e,
6433 const basic_string<_CharT, _FST, _FSA>& __fmt,
6434 regex_constants::match_flag_type __flags = regex_constants::match_default)
6436 basic_string<_CharT, _ST, _SA> __r;
6437 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6438 __fmt.c_str(), __flags);
6442 template <class _Traits, class _CharT, class _ST, class _SA>
6443 inline _LIBCPP_INLINE_VISIBILITY
6444 basic_string<_CharT, _ST, _SA>
6445 regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6446 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6447 regex_constants::match_flag_type __flags = regex_constants::match_default)
6449 basic_string<_CharT, _ST, _SA> __r;
6450 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6455 template <class _Traits, class _CharT, class _ST, class _SA>
6456 inline _LIBCPP_INLINE_VISIBILITY
6457 basic_string<_CharT>
6458 regex_replace(const _CharT* __s,
6459 const basic_regex<_CharT, _Traits>& __e,
6460 const basic_string<_CharT, _ST, _SA>& __fmt,
6461 regex_constants::match_flag_type __flags = regex_constants::match_default)
6463 basic_string<_CharT> __r;
6464 _VSTD::regex_replace(back_inserter(__r), __s,
6465 __s + char_traits<_CharT>::length(__s), __e,
6466 __fmt.c_str(), __flags);
6470 template <class _Traits, class _CharT>
6471 inline _LIBCPP_INLINE_VISIBILITY
6472 basic_string<_CharT>
6473 regex_replace(const _CharT* __s,
6474 const basic_regex<_CharT, _Traits>& __e,
6475 const _CharT* __fmt,
6476 regex_constants::match_flag_type __flags = regex_constants::match_default)
6478 basic_string<_CharT> __r;
6479 _VSTD::regex_replace(back_inserter(__r), __s,
6480 __s + char_traits<_CharT>::length(__s), __e,
6485 _LIBCPP_END_NAMESPACE_STD
6487 #endif // _LIBCPP_REGEX