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 value_type& 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 ST, class SA, class Allocator, class charT, class traits>
551 regex_match(const basic_string<charT, ST, SA>&& s,
552 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
553 const basic_regex<charT, traits>& e,
554 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
556 template <class charT, class traits>
558 regex_match(const charT* str, const basic_regex<charT, traits>& e,
559 regex_constants::match_flag_type flags = regex_constants::match_default);
561 template <class ST, class SA, class charT, class traits>
563 regex_match(const basic_string<charT, ST, SA>& s,
564 const basic_regex<charT, traits>& e,
565 regex_constants::match_flag_type flags = regex_constants::match_default);
567 template <class BidirectionalIterator, class Allocator, class charT, class traits>
569 regex_search(BidirectionalIterator first, BidirectionalIterator last,
570 match_results<BidirectionalIterator, Allocator>& m,
571 const basic_regex<charT, traits>& e,
572 regex_constants::match_flag_type flags = regex_constants::match_default);
574 template <class BidirectionalIterator, class charT, class traits>
576 regex_search(BidirectionalIterator first, BidirectionalIterator last,
577 const basic_regex<charT, traits>& e,
578 regex_constants::match_flag_type flags = regex_constants::match_default);
580 template <class charT, class Allocator, class traits>
582 regex_search(const charT* str, match_results<const charT*, Allocator>& m,
583 const basic_regex<charT, traits>& e,
584 regex_constants::match_flag_type flags = regex_constants::match_default);
586 template <class charT, class traits>
588 regex_search(const charT* str, const basic_regex<charT, traits>& e,
589 regex_constants::match_flag_type flags = regex_constants::match_default);
591 template <class ST, class SA, class charT, class traits>
593 regex_search(const basic_string<charT, ST, SA>& s,
594 const basic_regex<charT, traits>& e,
595 regex_constants::match_flag_type flags = regex_constants::match_default);
597 template <class ST, class SA, class Allocator, class charT, class traits>
599 regex_search(const basic_string<charT, ST, SA>& s,
600 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
601 const basic_regex<charT, traits>& e,
602 regex_constants::match_flag_type flags = regex_constants::match_default);
604 template <class ST, class SA, class Allocator, class charT, class traits>
606 regex_search(const basic_string<charT, ST, SA>&& s,
607 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
608 const basic_regex<charT, traits>& e,
609 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
611 template <class OutputIterator, class BidirectionalIterator,
612 class traits, class charT, class ST, class SA>
614 regex_replace(OutputIterator out,
615 BidirectionalIterator first, BidirectionalIterator last,
616 const basic_regex<charT, traits>& e,
617 const basic_string<charT, ST, SA>& fmt,
618 regex_constants::match_flag_type flags = regex_constants::match_default);
620 template <class OutputIterator, class BidirectionalIterator,
621 class traits, class charT>
623 regex_replace(OutputIterator out,
624 BidirectionalIterator first, BidirectionalIterator last,
625 const basic_regex<charT, traits>& e, const charT* fmt,
626 regex_constants::match_flag_type flags = regex_constants::match_default);
628 template <class traits, class charT, class ST, class SA, class FST, class FSA>>
629 basic_string<charT, ST, SA>
630 regex_replace(const basic_string<charT, ST, SA>& s,
631 const basic_regex<charT, traits>& e,
632 const basic_string<charT, FST, FSA>& fmt,
633 regex_constants::match_flag_type flags = regex_constants::match_default);
635 template <class traits, class charT, class ST, class SA>
636 basic_string<charT, ST, SA>
637 regex_replace(const basic_string<charT, ST, SA>& s,
638 const basic_regex<charT, traits>& e, const charT* fmt,
639 regex_constants::match_flag_type flags = regex_constants::match_default);
641 template <class traits, class charT, class ST, class SA>
643 regex_replace(const charT* s,
644 const basic_regex<charT, traits>& e,
645 const basic_string<charT, ST, SA>& fmt,
646 regex_constants::match_flag_type flags = regex_constants::match_default);
648 template <class traits, class charT>
650 regex_replace(const charT* s,
651 const basic_regex<charT, traits>& e,
653 regex_constants::match_flag_type flags = regex_constants::match_default);
655 template <class BidirectionalIterator,
656 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
657 class traits = regex_traits<charT>>
661 typedef basic_regex<charT, traits> regex_type;
662 typedef match_results<BidirectionalIterator> value_type;
663 typedef ptrdiff_t difference_type;
664 typedef const value_type* pointer;
665 typedef const value_type& reference;
666 typedef forward_iterator_tag iterator_category;
669 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
670 const regex_type& re,
671 regex_constants::match_flag_type m = regex_constants::match_default);
672 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
673 const regex_type&& __re,
674 regex_constants::match_flag_type __m
675 = regex_constants::match_default) = delete; // C++14
676 regex_iterator(const regex_iterator&);
677 regex_iterator& operator=(const regex_iterator&);
679 bool operator==(const regex_iterator&) const;
680 bool operator!=(const regex_iterator&) const;
682 const value_type& operator*() const;
683 const value_type* operator->() const;
685 regex_iterator& operator++();
686 regex_iterator operator++(int);
689 typedef regex_iterator<const char*> cregex_iterator;
690 typedef regex_iterator<const wchar_t*> wcregex_iterator;
691 typedef regex_iterator<string::const_iterator> sregex_iterator;
692 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
694 template <class BidirectionalIterator,
695 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
696 class traits = regex_traits<charT>>
697 class regex_token_iterator
700 typedef basic_regex<charT, traits> regex_type;
701 typedef sub_match<BidirectionalIterator> value_type;
702 typedef ptrdiff_t difference_type;
703 typedef const value_type* pointer;
704 typedef const value_type& reference;
705 typedef forward_iterator_tag iterator_category;
707 regex_token_iterator();
708 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
709 const regex_type& re, int submatch = 0,
710 regex_constants::match_flag_type m = regex_constants::match_default);
711 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
712 const regex_type&& re, int submatch = 0,
713 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
714 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
715 const regex_type& re, const vector<int>& submatches,
716 regex_constants::match_flag_type m = regex_constants::match_default);
717 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
718 const regex_type&& re, const vector<int>& submatches,
719 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
720 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
721 const regex_type& re, initializer_list<int> submatches,
722 regex_constants::match_flag_type m = regex_constants::match_default);
723 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
724 const regex_type&& re, initializer_list<int> submatches,
725 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
727 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
728 const regex_type& re, const int (&submatches)[N],
729 regex_constants::match_flag_type m = regex_constants::match_default);
731 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
732 const regex_type& re, const int (&submatches)[N],
733 regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14;
734 regex_token_iterator(const regex_token_iterator&);
735 regex_token_iterator& operator=(const regex_token_iterator&);
737 bool operator==(const regex_token_iterator&) const;
738 bool operator!=(const regex_token_iterator&) const;
740 const value_type& operator*() const;
741 const value_type* operator->() const;
743 regex_token_iterator& operator++();
744 regex_token_iterator operator++(int);
747 typedef regex_token_iterator<const char*> cregex_token_iterator;
748 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
749 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
750 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
758 #include <initializer_list>
767 #include <__undef_min_max>
769 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
770 #pragma GCC system_header
773 _LIBCPP_BEGIN_NAMESPACE_STD
775 namespace regex_constants
778 // syntax_option_type
780 enum syntax_option_type
794 inline _LIBCPP_INLINE_VISIBILITY
797 operator~(syntax_option_type __x)
799 return syntax_option_type(~int(__x) & 0x1FF);
802 inline _LIBCPP_INLINE_VISIBILITY
805 operator&(syntax_option_type __x, syntax_option_type __y)
807 return syntax_option_type(int(__x) & int(__y));
810 inline _LIBCPP_INLINE_VISIBILITY
813 operator|(syntax_option_type __x, syntax_option_type __y)
815 return syntax_option_type(int(__x) | int(__y));
818 inline _LIBCPP_INLINE_VISIBILITY
821 operator^(syntax_option_type __x, syntax_option_type __y)
823 return syntax_option_type(int(__x) ^ int(__y));
826 inline _LIBCPP_INLINE_VISIBILITY
828 operator&=(syntax_option_type& __x, syntax_option_type __y)
834 inline _LIBCPP_INLINE_VISIBILITY
836 operator|=(syntax_option_type& __x, syntax_option_type __y)
842 inline _LIBCPP_INLINE_VISIBILITY
844 operator^=(syntax_option_type& __x, syntax_option_type __y)
855 match_not_bol = 1 << 0,
856 match_not_eol = 1 << 1,
857 match_not_bow = 1 << 2,
858 match_not_eow = 1 << 3,
860 match_not_null = 1 << 5,
861 match_continuous = 1 << 6,
862 match_prev_avail = 1 << 7,
865 format_no_copy = 1 << 9,
866 format_first_only = 1 << 10,
867 __no_update_pos = 1 << 11
870 inline _LIBCPP_INLINE_VISIBILITY
873 operator~(match_flag_type __x)
875 return match_flag_type(~int(__x) & 0x0FFF);
878 inline _LIBCPP_INLINE_VISIBILITY
881 operator&(match_flag_type __x, match_flag_type __y)
883 return match_flag_type(int(__x) & int(__y));
886 inline _LIBCPP_INLINE_VISIBILITY
889 operator|(match_flag_type __x, match_flag_type __y)
891 return match_flag_type(int(__x) | int(__y));
894 inline _LIBCPP_INLINE_VISIBILITY
897 operator^(match_flag_type __x, match_flag_type __y)
899 return match_flag_type(int(__x) ^ int(__y));
902 inline _LIBCPP_INLINE_VISIBILITY
904 operator&=(match_flag_type& __x, match_flag_type __y)
910 inline _LIBCPP_INLINE_VISIBILITY
912 operator|=(match_flag_type& __x, match_flag_type __y)
918 inline _LIBCPP_INLINE_VISIBILITY
920 operator^=(match_flag_type& __x, match_flag_type __y)
948 class _LIBCPP_EXCEPTION_ABI regex_error
949 : public runtime_error
951 regex_constants::error_type __code_;
953 explicit regex_error(regex_constants::error_type __ecode);
954 virtual ~regex_error() throw();
955 _LIBCPP_INLINE_VISIBILITY
956 regex_constants::error_type code() const {return __code_;}
959 template <regex_constants::error_type _Ev>
960 _LIBCPP_ALWAYS_INLINE
961 void __throw_regex_error()
963 #ifndef _LIBCPP_NO_EXCEPTIONS
964 throw regex_error(_Ev);
966 assert(!"regex_error");
970 template <class _CharT>
971 struct _LIBCPP_TYPE_VIS_ONLY regex_traits
974 typedef _CharT char_type;
975 typedef basic_string<char_type> string_type;
976 typedef locale locale_type;
977 typedef ctype_base::mask char_class_type;
979 #if defined(__mips__) && defined(__GLIBC__)
980 static const char_class_type __regex_word = static_cast<char_class_type>(_ISbit(15));
982 static const char_class_type __regex_word = 0x80;
987 const ctype<char_type>* __ct_;
988 const collate<char_type>* __col_;
993 _LIBCPP_INLINE_VISIBILITY
994 static size_t length(const char_type* __p)
995 {return char_traits<char_type>::length(__p);}
996 _LIBCPP_INLINE_VISIBILITY
997 char_type translate(char_type __c) const {return __c;}
998 char_type translate_nocase(char_type __c) const;
999 template <class _ForwardIterator>
1001 transform(_ForwardIterator __f, _ForwardIterator __l) const;
1002 template <class _ForwardIterator>
1003 _LIBCPP_INLINE_VISIBILITY
1005 transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
1006 {return __transform_primary(__f, __l, char_type());}
1007 template <class _ForwardIterator>
1008 _LIBCPP_INLINE_VISIBILITY
1010 lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
1011 {return __lookup_collatename(__f, __l, char_type());}
1012 template <class _ForwardIterator>
1013 _LIBCPP_INLINE_VISIBILITY
1015 lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1016 bool __icase = false) const
1017 {return __lookup_classname(__f, __l, __icase, char_type());}
1018 bool isctype(char_type __c, char_class_type __m) const;
1019 _LIBCPP_INLINE_VISIBILITY
1020 int value(char_type __ch, int __radix) const
1021 {return __regex_traits_value(__ch, __radix);}
1022 locale_type imbue(locale_type __l);
1023 _LIBCPP_INLINE_VISIBILITY
1024 locale_type getloc()const {return __loc_;}
1029 template <class _ForwardIterator>
1031 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
1032 template <class _ForwardIterator>
1034 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1036 template <class _ForwardIterator>
1038 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
1039 template <class _ForwardIterator>
1041 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1043 template <class _ForwardIterator>
1045 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1046 bool __icase, char) const;
1047 template <class _ForwardIterator>
1049 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1050 bool __icase, wchar_t) const;
1052 static int __regex_traits_value(unsigned char __ch, int __radix);
1053 _LIBCPP_INLINE_VISIBILITY
1054 int __regex_traits_value(char __ch, int __radix) const
1055 {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
1056 _LIBCPP_INLINE_VISIBILITY
1057 int __regex_traits_value(wchar_t __ch, int __radix) const;
1060 template <class _CharT>
1061 const typename regex_traits<_CharT>::char_class_type
1062 regex_traits<_CharT>::__regex_word;
1064 template <class _CharT>
1065 regex_traits<_CharT>::regex_traits()
1070 template <class _CharT>
1071 typename regex_traits<_CharT>::char_type
1072 regex_traits<_CharT>::translate_nocase(char_type __c) const
1074 return __ct_->tolower(__c);
1077 template <class _CharT>
1078 template <class _ForwardIterator>
1079 typename regex_traits<_CharT>::string_type
1080 regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
1082 string_type __s(__f, __l);
1083 return __col_->transform(__s.data(), __s.data() + __s.size());
1086 template <class _CharT>
1088 regex_traits<_CharT>::__init()
1090 __ct_ = &use_facet<ctype<char_type> >(__loc_);
1091 __col_ = &use_facet<collate<char_type> >(__loc_);
1094 template <class _CharT>
1095 typename regex_traits<_CharT>::locale_type
1096 regex_traits<_CharT>::imbue(locale_type __l)
1098 locale __r = __loc_;
1104 // transform_primary is very FreeBSD-specific
1106 template <class _CharT>
1107 template <class _ForwardIterator>
1108 typename regex_traits<_CharT>::string_type
1109 regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1110 _ForwardIterator __l, char) const
1112 const string_type __s(__f, __l);
1113 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1128 template <class _CharT>
1129 template <class _ForwardIterator>
1130 typename regex_traits<_CharT>::string_type
1131 regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1132 _ForwardIterator __l, wchar_t) const
1134 const string_type __s(__f, __l);
1135 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1150 // lookup_collatename is very FreeBSD-specific
1152 _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s);
1154 template <class _CharT>
1155 template <class _ForwardIterator>
1156 typename regex_traits<_CharT>::string_type
1157 regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1158 _ForwardIterator __l, char) const
1160 string_type __s(__f, __l);
1164 __r = __get_collation_name(__s.c_str());
1165 if (__r.empty() && __s.size() <= 2)
1167 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1168 if (__r.size() == 1 || __r.size() == 12)
1177 template <class _CharT>
1178 template <class _ForwardIterator>
1179 typename regex_traits<_CharT>::string_type
1180 regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1181 _ForwardIterator __l, wchar_t) const
1183 string_type __s(__f, __l);
1185 __n.reserve(__s.size());
1186 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1189 if (static_cast<unsigned>(*__i) >= 127)
1190 return string_type();
1191 __n.push_back(char(*__i));
1196 __n = __get_collation_name(__n.c_str());
1198 __r.assign(__n.begin(), __n.end());
1199 else if (__s.size() <= 2)
1201 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1202 if (__r.size() == 1 || __r.size() == 3)
1213 regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS
1214 __get_classname(const char* __s, bool __icase);
1216 template <class _CharT>
1217 template <class _ForwardIterator>
1218 typename regex_traits<_CharT>::char_class_type
1219 regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1220 _ForwardIterator __l,
1221 bool __icase, char) const
1223 string_type __s(__f, __l);
1224 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1225 return __get_classname(__s.c_str(), __icase);
1228 template <class _CharT>
1229 template <class _ForwardIterator>
1230 typename regex_traits<_CharT>::char_class_type
1231 regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1232 _ForwardIterator __l,
1233 bool __icase, wchar_t) const
1235 string_type __s(__f, __l);
1236 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1238 __n.reserve(__s.size());
1239 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1242 if (static_cast<unsigned>(*__i) >= 127)
1243 return char_class_type();
1244 __n.push_back(char(*__i));
1246 return __get_classname(__n.c_str(), __icase);
1249 template <class _CharT>
1251 regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
1253 if (__ct_->is(__m, __c))
1255 return (__c == '_' && (__m & __regex_word));
1258 template <class _CharT>
1260 regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
1262 if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
1266 if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
1270 __ch |= 0x20; // tolower
1271 if ('a' <= __ch && __ch <= 'f')
1272 return __ch - ('a' - 10);
1278 template <class _CharT>
1281 regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
1283 return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
1286 template <class _CharT> class __node;
1288 template <class _BidirectionalIterator> class _LIBCPP_TYPE_VIS_ONLY sub_match;
1290 template <class _BidirectionalIterator,
1291 class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1292 class _LIBCPP_TYPE_VIS_ONLY match_results;
1294 template <class _CharT>
1299 __end_state = -1000,
1300 __consume_input, // -999
1301 __begin_marked_expr, // -998
1302 __end_marked_expr, // -997
1303 __pop_state, // -996
1304 __accept_and_consume, // -995
1305 __accept_but_not_consume, // -994
1312 const _CharT* __first_;
1313 const _CharT* __current_;
1314 const _CharT* __last_;
1315 vector<sub_match<const _CharT*> > __sub_matches_;
1316 vector<pair<size_t, const _CharT*> > __loop_data_;
1317 const __node<_CharT>* __node_;
1318 regex_constants::match_flag_type __flags_;
1321 _LIBCPP_INLINE_VISIBILITY
1323 : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
1324 __node_(nullptr), __flags_() {}
1329 template <class _CharT>
1332 __node(const __node&);
1333 __node& operator=(const __node&);
1335 typedef _VSTD::__state<_CharT> __state;
1337 _LIBCPP_INLINE_VISIBILITY
1339 _LIBCPP_INLINE_VISIBILITY
1340 virtual ~__node() {}
1342 _LIBCPP_INLINE_VISIBILITY
1343 virtual void __exec(__state&) const {};
1344 _LIBCPP_INLINE_VISIBILITY
1345 virtual void __exec_split(bool, __state&) const {};
1350 template <class _CharT>
1352 : public __node<_CharT>
1355 typedef _VSTD::__state<_CharT> __state;
1357 _LIBCPP_INLINE_VISIBILITY
1360 virtual void __exec(__state&) const;
1363 template <class _CharT>
1365 __end_state<_CharT>::__exec(__state& __s) const
1367 __s.__do_ = __state::__end_state;
1372 template <class _CharT>
1373 class __has_one_state
1374 : public __node<_CharT>
1376 __node<_CharT>* __first_;
1379 _LIBCPP_INLINE_VISIBILITY
1380 explicit __has_one_state(__node<_CharT>* __s)
1383 _LIBCPP_INLINE_VISIBILITY
1384 __node<_CharT>* first() const {return __first_;}
1385 _LIBCPP_INLINE_VISIBILITY
1386 __node<_CharT>*& first() {return __first_;}
1391 template <class _CharT>
1392 class __owns_one_state
1393 : public __has_one_state<_CharT>
1395 typedef __has_one_state<_CharT> base;
1398 _LIBCPP_INLINE_VISIBILITY
1399 explicit __owns_one_state(__node<_CharT>* __s)
1402 virtual ~__owns_one_state();
1405 template <class _CharT>
1406 __owns_one_state<_CharT>::~__owns_one_state()
1408 delete this->first();
1413 template <class _CharT>
1415 : public __owns_one_state<_CharT>
1417 typedef __owns_one_state<_CharT> base;
1420 typedef _VSTD::__state<_CharT> __state;
1422 _LIBCPP_INLINE_VISIBILITY
1423 explicit __empty_state(__node<_CharT>* __s)
1426 virtual void __exec(__state&) const;
1429 template <class _CharT>
1431 __empty_state<_CharT>::__exec(__state& __s) const
1433 __s.__do_ = __state::__accept_but_not_consume;
1434 __s.__node_ = this->first();
1437 // __empty_non_own_state
1439 template <class _CharT>
1440 class __empty_non_own_state
1441 : public __has_one_state<_CharT>
1443 typedef __has_one_state<_CharT> base;
1446 typedef _VSTD::__state<_CharT> __state;
1448 _LIBCPP_INLINE_VISIBILITY
1449 explicit __empty_non_own_state(__node<_CharT>* __s)
1452 virtual void __exec(__state&) const;
1455 template <class _CharT>
1457 __empty_non_own_state<_CharT>::__exec(__state& __s) const
1459 __s.__do_ = __state::__accept_but_not_consume;
1460 __s.__node_ = this->first();
1463 // __repeat_one_loop
1465 template <class _CharT>
1466 class __repeat_one_loop
1467 : public __has_one_state<_CharT>
1469 typedef __has_one_state<_CharT> base;
1472 typedef _VSTD::__state<_CharT> __state;
1474 _LIBCPP_INLINE_VISIBILITY
1475 explicit __repeat_one_loop(__node<_CharT>* __s)
1478 virtual void __exec(__state&) const;
1481 template <class _CharT>
1483 __repeat_one_loop<_CharT>::__exec(__state& __s) const
1485 __s.__do_ = __state::__repeat;
1486 __s.__node_ = this->first();
1489 // __owns_two_states
1491 template <class _CharT>
1492 class __owns_two_states
1493 : public __owns_one_state<_CharT>
1495 typedef __owns_one_state<_CharT> base;
1500 _LIBCPP_INLINE_VISIBILITY
1501 explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
1502 : base(__s1), __second_(__s2) {}
1504 virtual ~__owns_two_states();
1506 _LIBCPP_INLINE_VISIBILITY
1507 base* second() const {return __second_;}
1508 _LIBCPP_INLINE_VISIBILITY
1509 base*& second() {return __second_;}
1512 template <class _CharT>
1513 __owns_two_states<_CharT>::~__owns_two_states()
1520 template <class _CharT>
1522 : public __owns_two_states<_CharT>
1524 typedef __owns_two_states<_CharT> base;
1528 unsigned __loop_id_;
1529 unsigned __mexp_begin_;
1530 unsigned __mexp_end_;
1534 typedef _VSTD::__state<_CharT> __state;
1536 _LIBCPP_INLINE_VISIBILITY
1537 explicit __loop(unsigned __loop_id,
1538 __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
1539 unsigned __mexp_begin, unsigned __mexp_end,
1540 bool __greedy = true,
1542 size_t __max = numeric_limits<size_t>::max())
1543 : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
1544 __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
1545 __greedy_(__greedy) {}
1547 virtual void __exec(__state& __s) const;
1548 virtual void __exec_split(bool __second, __state& __s) const;
1551 _LIBCPP_INLINE_VISIBILITY
1552 void __init_repeat(__state& __s) const
1554 __s.__loop_data_[__loop_id_].second = __s.__current_;
1555 for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
1557 __s.__sub_matches_[__i].first = __s.__last_;
1558 __s.__sub_matches_[__i].second = __s.__last_;
1559 __s.__sub_matches_[__i].matched = false;
1564 template <class _CharT>
1566 __loop<_CharT>::__exec(__state& __s) const
1568 if (__s.__do_ == __state::__repeat)
1570 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1571 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1572 if (__do_repeat && __do_alt &&
1573 __s.__loop_data_[__loop_id_].second == __s.__current_)
1574 __do_repeat = false;
1575 if (__do_repeat && __do_alt)
1576 __s.__do_ = __state::__split;
1577 else if (__do_repeat)
1579 __s.__do_ = __state::__accept_but_not_consume;
1580 __s.__node_ = this->first();
1585 __s.__do_ = __state::__accept_but_not_consume;
1586 __s.__node_ = this->second();
1591 __s.__loop_data_[__loop_id_].first = 0;
1592 bool __do_repeat = 0 < __max_;
1593 bool __do_alt = 0 >= __min_;
1594 if (__do_repeat && __do_alt)
1595 __s.__do_ = __state::__split;
1596 else if (__do_repeat)
1598 __s.__do_ = __state::__accept_but_not_consume;
1599 __s.__node_ = this->first();
1604 __s.__do_ = __state::__accept_but_not_consume;
1605 __s.__node_ = this->second();
1610 template <class _CharT>
1612 __loop<_CharT>::__exec_split(bool __second, __state& __s) const
1614 __s.__do_ = __state::__accept_but_not_consume;
1615 if (__greedy_ != __second)
1617 __s.__node_ = this->first();
1621 __s.__node_ = this->second();
1626 template <class _CharT>
1628 : public __owns_two_states<_CharT>
1630 typedef __owns_two_states<_CharT> base;
1633 typedef _VSTD::__state<_CharT> __state;
1635 _LIBCPP_INLINE_VISIBILITY
1636 explicit __alternate(__owns_one_state<_CharT>* __s1,
1637 __owns_one_state<_CharT>* __s2)
1638 : base(__s1, __s2) {}
1640 virtual void __exec(__state& __s) const;
1641 virtual void __exec_split(bool __second, __state& __s) const;
1644 template <class _CharT>
1646 __alternate<_CharT>::__exec(__state& __s) const
1648 __s.__do_ = __state::__split;
1651 template <class _CharT>
1653 __alternate<_CharT>::__exec_split(bool __second, __state& __s) const
1655 __s.__do_ = __state::__accept_but_not_consume;
1657 __s.__node_ = this->second();
1659 __s.__node_ = this->first();
1662 // __begin_marked_subexpression
1664 template <class _CharT>
1665 class __begin_marked_subexpression
1666 : public __owns_one_state<_CharT>
1668 typedef __owns_one_state<_CharT> base;
1672 typedef _VSTD::__state<_CharT> __state;
1674 _LIBCPP_INLINE_VISIBILITY
1675 explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1676 : base(__s), __mexp_(__mexp) {}
1678 virtual void __exec(__state&) const;
1681 template <class _CharT>
1683 __begin_marked_subexpression<_CharT>::__exec(__state& __s) const
1685 __s.__do_ = __state::__accept_but_not_consume;
1686 __s.__sub_matches_[__mexp_-1].first = __s.__current_;
1687 __s.__node_ = this->first();
1690 // __end_marked_subexpression
1692 template <class _CharT>
1693 class __end_marked_subexpression
1694 : public __owns_one_state<_CharT>
1696 typedef __owns_one_state<_CharT> base;
1700 typedef _VSTD::__state<_CharT> __state;
1702 _LIBCPP_INLINE_VISIBILITY
1703 explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1704 : base(__s), __mexp_(__mexp) {}
1706 virtual void __exec(__state&) const;
1709 template <class _CharT>
1711 __end_marked_subexpression<_CharT>::__exec(__state& __s) const
1713 __s.__do_ = __state::__accept_but_not_consume;
1714 __s.__sub_matches_[__mexp_-1].second = __s.__current_;
1715 __s.__sub_matches_[__mexp_-1].matched = true;
1716 __s.__node_ = this->first();
1721 template <class _CharT>
1723 : public __owns_one_state<_CharT>
1725 typedef __owns_one_state<_CharT> base;
1729 typedef _VSTD::__state<_CharT> __state;
1731 _LIBCPP_INLINE_VISIBILITY
1732 explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
1733 : base(__s), __mexp_(__mexp) {}
1735 virtual void __exec(__state&) const;
1738 template <class _CharT>
1740 __back_ref<_CharT>::__exec(__state& __s) const
1742 if (__mexp_ > __s.__sub_matches_.size())
1743 __throw_regex_error<regex_constants::error_backref>();
1744 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1747 ptrdiff_t __len = __sm.second - __sm.first;
1748 if (__s.__last_ - __s.__current_ >= __len &&
1749 _VSTD::equal(__sm.first, __sm.second, __s.__current_))
1751 __s.__do_ = __state::__accept_but_not_consume;
1752 __s.__current_ += __len;
1753 __s.__node_ = this->first();
1757 __s.__do_ = __state::__reject;
1758 __s.__node_ = nullptr;
1763 __s.__do_ = __state::__reject;
1764 __s.__node_ = nullptr;
1770 template <class _CharT, class _Traits>
1771 class __back_ref_icase
1772 : public __owns_one_state<_CharT>
1774 typedef __owns_one_state<_CharT> base;
1779 typedef _VSTD::__state<_CharT> __state;
1781 _LIBCPP_INLINE_VISIBILITY
1782 explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
1783 __node<_CharT>* __s)
1784 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1786 virtual void __exec(__state&) const;
1789 template <class _CharT, class _Traits>
1791 __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
1793 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1796 ptrdiff_t __len = __sm.second - __sm.first;
1797 if (__s.__last_ - __s.__current_ >= __len)
1799 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1801 if (__traits_.translate_nocase(__sm.first[__i]) !=
1802 __traits_.translate_nocase(__s.__current_[__i]))
1805 __s.__do_ = __state::__accept_but_not_consume;
1806 __s.__current_ += __len;
1807 __s.__node_ = this->first();
1811 __s.__do_ = __state::__reject;
1812 __s.__node_ = nullptr;
1818 __s.__do_ = __state::__reject;
1819 __s.__node_ = nullptr;
1823 // __back_ref_collate
1825 template <class _CharT, class _Traits>
1826 class __back_ref_collate
1827 : public __owns_one_state<_CharT>
1829 typedef __owns_one_state<_CharT> base;
1834 typedef _VSTD::__state<_CharT> __state;
1836 _LIBCPP_INLINE_VISIBILITY
1837 explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
1838 __node<_CharT>* __s)
1839 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1841 virtual void __exec(__state&) const;
1844 template <class _CharT, class _Traits>
1846 __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
1848 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1851 ptrdiff_t __len = __sm.second - __sm.first;
1852 if (__s.__last_ - __s.__current_ >= __len)
1854 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1856 if (__traits_.translate(__sm.first[__i]) !=
1857 __traits_.translate(__s.__current_[__i]))
1860 __s.__do_ = __state::__accept_but_not_consume;
1861 __s.__current_ += __len;
1862 __s.__node_ = this->first();
1866 __s.__do_ = __state::__reject;
1867 __s.__node_ = nullptr;
1873 __s.__do_ = __state::__reject;
1874 __s.__node_ = nullptr;
1880 template <class _CharT, class _Traits>
1881 class __word_boundary
1882 : public __owns_one_state<_CharT>
1884 typedef __owns_one_state<_CharT> base;
1889 typedef _VSTD::__state<_CharT> __state;
1891 _LIBCPP_INLINE_VISIBILITY
1892 explicit __word_boundary(const _Traits& __traits, bool __invert,
1893 __node<_CharT>* __s)
1894 : base(__s), __traits_(__traits), __invert_(__invert) {}
1896 virtual void __exec(__state&) const;
1899 template <class _CharT, class _Traits>
1901 __word_boundary<_CharT, _Traits>::__exec(__state& __s) const
1903 bool __is_word_b = false;
1904 if (__s.__first_ != __s.__last_)
1906 if (__s.__current_ == __s.__last_)
1908 if (!(__s.__flags_ & regex_constants::match_not_eow))
1910 _CharT __c = __s.__current_[-1];
1911 __is_word_b = __c == '_' ||
1912 __traits_.isctype(__c, ctype_base::alnum);
1915 else if (__s.__current_ == __s.__first_ &&
1916 !(__s.__flags_ & regex_constants::match_prev_avail))
1918 if (!(__s.__flags_ & regex_constants::match_not_bow))
1920 _CharT __c = *__s.__current_;
1921 __is_word_b = __c == '_' ||
1922 __traits_.isctype(__c, ctype_base::alnum);
1927 _CharT __c1 = __s.__current_[-1];
1928 _CharT __c2 = *__s.__current_;
1929 bool __is_c1_b = __c1 == '_' ||
1930 __traits_.isctype(__c1, ctype_base::alnum);
1931 bool __is_c2_b = __c2 == '_' ||
1932 __traits_.isctype(__c2, ctype_base::alnum);
1933 __is_word_b = __is_c1_b != __is_c2_b;
1936 if (__is_word_b != __invert_)
1938 __s.__do_ = __state::__accept_but_not_consume;
1939 __s.__node_ = this->first();
1943 __s.__do_ = __state::__reject;
1944 __s.__node_ = nullptr;
1950 template <class _CharT>
1952 : public __owns_one_state<_CharT>
1954 typedef __owns_one_state<_CharT> base;
1957 typedef _VSTD::__state<_CharT> __state;
1959 _LIBCPP_INLINE_VISIBILITY
1960 __l_anchor(__node<_CharT>* __s)
1963 virtual void __exec(__state&) const;
1966 template <class _CharT>
1968 __l_anchor<_CharT>::__exec(__state& __s) const
1970 if (__s.__at_first_ && __s.__current_ == __s.__first_ &&
1971 !(__s.__flags_ & regex_constants::match_not_bol))
1973 __s.__do_ = __state::__accept_but_not_consume;
1974 __s.__node_ = this->first();
1978 __s.__do_ = __state::__reject;
1979 __s.__node_ = nullptr;
1985 template <class _CharT>
1987 : public __owns_one_state<_CharT>
1989 typedef __owns_one_state<_CharT> base;
1992 typedef _VSTD::__state<_CharT> __state;
1994 _LIBCPP_INLINE_VISIBILITY
1995 __r_anchor(__node<_CharT>* __s)
1998 virtual void __exec(__state&) const;
2001 template <class _CharT>
2003 __r_anchor<_CharT>::__exec(__state& __s) const
2005 if (__s.__current_ == __s.__last_ &&
2006 !(__s.__flags_ & regex_constants::match_not_eol))
2008 __s.__do_ = __state::__accept_but_not_consume;
2009 __s.__node_ = this->first();
2013 __s.__do_ = __state::__reject;
2014 __s.__node_ = nullptr;
2020 template <class _CharT>
2022 : public __owns_one_state<_CharT>
2024 typedef __owns_one_state<_CharT> base;
2027 typedef _VSTD::__state<_CharT> __state;
2029 _LIBCPP_INLINE_VISIBILITY
2030 __match_any(__node<_CharT>* __s)
2033 virtual void __exec(__state&) const;
2036 template <class _CharT>
2038 __match_any<_CharT>::__exec(__state& __s) const
2040 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
2042 __s.__do_ = __state::__accept_and_consume;
2044 __s.__node_ = this->first();
2048 __s.__do_ = __state::__reject;
2049 __s.__node_ = nullptr;
2053 // __match_any_but_newline
2055 template <class _CharT>
2056 class __match_any_but_newline
2057 : public __owns_one_state<_CharT>
2059 typedef __owns_one_state<_CharT> base;
2062 typedef _VSTD::__state<_CharT> __state;
2064 _LIBCPP_INLINE_VISIBILITY
2065 __match_any_but_newline(__node<_CharT>* __s)
2068 virtual void __exec(__state&) const;
2071 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
2072 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
2076 template <class _CharT>
2078 : public __owns_one_state<_CharT>
2080 typedef __owns_one_state<_CharT> base;
2084 __match_char(const __match_char&);
2085 __match_char& operator=(const __match_char&);
2087 typedef _VSTD::__state<_CharT> __state;
2089 _LIBCPP_INLINE_VISIBILITY
2090 __match_char(_CharT __c, __node<_CharT>* __s)
2091 : base(__s), __c_(__c) {}
2093 virtual void __exec(__state&) const;
2096 template <class _CharT>
2098 __match_char<_CharT>::__exec(__state& __s) const
2100 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
2102 __s.__do_ = __state::__accept_and_consume;
2104 __s.__node_ = this->first();
2108 __s.__do_ = __state::__reject;
2109 __s.__node_ = nullptr;
2113 // __match_char_icase
2115 template <class _CharT, class _Traits>
2116 class __match_char_icase
2117 : public __owns_one_state<_CharT>
2119 typedef __owns_one_state<_CharT> base;
2124 __match_char_icase(const __match_char_icase&);
2125 __match_char_icase& operator=(const __match_char_icase&);
2127 typedef _VSTD::__state<_CharT> __state;
2129 _LIBCPP_INLINE_VISIBILITY
2130 __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2131 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
2133 virtual void __exec(__state&) const;
2136 template <class _CharT, class _Traits>
2138 __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
2140 if (__s.__current_ != __s.__last_ &&
2141 __traits_.translate_nocase(*__s.__current_) == __c_)
2143 __s.__do_ = __state::__accept_and_consume;
2145 __s.__node_ = this->first();
2149 __s.__do_ = __state::__reject;
2150 __s.__node_ = nullptr;
2154 // __match_char_collate
2156 template <class _CharT, class _Traits>
2157 class __match_char_collate
2158 : public __owns_one_state<_CharT>
2160 typedef __owns_one_state<_CharT> base;
2165 __match_char_collate(const __match_char_collate&);
2166 __match_char_collate& operator=(const __match_char_collate&);
2168 typedef _VSTD::__state<_CharT> __state;
2170 _LIBCPP_INLINE_VISIBILITY
2171 __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2172 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2174 virtual void __exec(__state&) const;
2177 template <class _CharT, class _Traits>
2179 __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
2181 if (__s.__current_ != __s.__last_ &&
2182 __traits_.translate(*__s.__current_) == __c_)
2184 __s.__do_ = __state::__accept_and_consume;
2186 __s.__node_ = this->first();
2190 __s.__do_ = __state::__reject;
2191 __s.__node_ = nullptr;
2195 // __bracket_expression
2197 template <class _CharT, class _Traits>
2198 class __bracket_expression
2199 : public __owns_one_state<_CharT>
2201 typedef __owns_one_state<_CharT> base;
2202 typedef typename _Traits::string_type string_type;
2205 vector<_CharT> __chars_;
2206 vector<_CharT> __neg_chars_;
2207 vector<pair<string_type, string_type> > __ranges_;
2208 vector<pair<_CharT, _CharT> > __digraphs_;
2209 vector<string_type> __equivalences_;
2210 typename regex_traits<_CharT>::char_class_type __mask_;
2211 typename regex_traits<_CharT>::char_class_type __neg_mask_;
2215 bool __might_have_digraph_;
2217 __bracket_expression(const __bracket_expression&);
2218 __bracket_expression& operator=(const __bracket_expression&);
2220 typedef _VSTD::__state<_CharT> __state;
2222 _LIBCPP_INLINE_VISIBILITY
2223 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
2224 bool __negate, bool __icase, bool __collate)
2225 : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
2226 __negate_(__negate), __icase_(__icase), __collate_(__collate),
2227 __might_have_digraph_(__traits_.getloc().name() != "C") {}
2229 virtual void __exec(__state&) const;
2231 _LIBCPP_INLINE_VISIBILITY
2232 bool __negated() const {return __negate_;}
2234 _LIBCPP_INLINE_VISIBILITY
2235 void __add_char(_CharT __c)
2238 __chars_.push_back(__traits_.translate_nocase(__c));
2239 else if (__collate_)
2240 __chars_.push_back(__traits_.translate(__c));
2242 __chars_.push_back(__c);
2244 _LIBCPP_INLINE_VISIBILITY
2245 void __add_neg_char(_CharT __c)
2248 __neg_chars_.push_back(__traits_.translate_nocase(__c));
2249 else if (__collate_)
2250 __neg_chars_.push_back(__traits_.translate(__c));
2252 __neg_chars_.push_back(__c);
2254 _LIBCPP_INLINE_VISIBILITY
2255 void __add_range(string_type __b, string_type __e)
2261 for (size_t __i = 0; __i < __b.size(); ++__i)
2262 __b[__i] = __traits_.translate_nocase(__b[__i]);
2263 for (size_t __i = 0; __i < __e.size(); ++__i)
2264 __e[__i] = __traits_.translate_nocase(__e[__i]);
2268 for (size_t __i = 0; __i < __b.size(); ++__i)
2269 __b[__i] = __traits_.translate(__b[__i]);
2270 for (size_t __i = 0; __i < __e.size(); ++__i)
2271 __e[__i] = __traits_.translate(__e[__i]);
2273 __ranges_.push_back(make_pair(
2274 __traits_.transform(__b.begin(), __b.end()),
2275 __traits_.transform(__e.begin(), __e.end())));
2279 if (__b.size() != 1 || __e.size() != 1)
2280 __throw_regex_error<regex_constants::error_collate>();
2283 __b[0] = __traits_.translate_nocase(__b[0]);
2284 __e[0] = __traits_.translate_nocase(__e[0]);
2286 __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e)));
2289 _LIBCPP_INLINE_VISIBILITY
2290 void __add_digraph(_CharT __c1, _CharT __c2)
2293 __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
2294 __traits_.translate_nocase(__c2)));
2295 else if (__collate_)
2296 __digraphs_.push_back(make_pair(__traits_.translate(__c1),
2297 __traits_.translate(__c2)));
2299 __digraphs_.push_back(make_pair(__c1, __c2));
2301 _LIBCPP_INLINE_VISIBILITY
2302 void __add_equivalence(const string_type& __s)
2303 {__equivalences_.push_back(__s);}
2304 _LIBCPP_INLINE_VISIBILITY
2305 void __add_class(typename regex_traits<_CharT>::char_class_type __mask)
2306 {__mask_ |= __mask;}
2307 _LIBCPP_INLINE_VISIBILITY
2308 void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask)
2309 {__neg_mask_ |= __mask;}
2312 template <class _CharT, class _Traits>
2314 __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
2316 bool __found = false;
2317 unsigned __consumed = 0;
2318 if (__s.__current_ != __s.__last_)
2321 if (__might_have_digraph_)
2323 const _CharT* __next = _VSTD::next(__s.__current_);
2324 if (__next != __s.__last_)
2326 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2329 __ch2.first = __traits_.translate_nocase(__ch2.first);
2330 __ch2.second = __traits_.translate_nocase(__ch2.second);
2332 else if (__collate_)
2334 __ch2.first = __traits_.translate(__ch2.first);
2335 __ch2.second = __traits_.translate(__ch2.second);
2337 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
2339 // __ch2 is a digraph in this locale
2341 for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
2343 if (__ch2 == __digraphs_[__i])
2349 if (__collate_ && !__ranges_.empty())
2351 string_type __s2 = __traits_.transform(&__ch2.first,
2353 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2355 if (__ranges_[__i].first <= __s2 &&
2356 __s2 <= __ranges_[__i].second)
2363 if (!__equivalences_.empty())
2365 string_type __s2 = __traits_.transform_primary(&__ch2.first,
2367 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2369 if (__s2 == __equivalences_[__i])
2376 if (__traits_.isctype(__ch2.first, __mask_) &&
2377 __traits_.isctype(__ch2.second, __mask_))
2382 if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
2383 !__traits_.isctype(__ch2.second, __neg_mask_))
2392 // test *__s.__current_ as not a digraph
2393 _CharT __ch = *__s.__current_;
2395 __ch = __traits_.translate_nocase(__ch);
2396 else if (__collate_)
2397 __ch = __traits_.translate(__ch);
2398 for (size_t __i = 0; __i < __chars_.size(); ++__i)
2400 if (__ch == __chars_[__i])
2406 if (!__neg_chars_.empty())
2408 for (size_t __i = 0; __i < __neg_chars_.size(); ++__i)
2410 if (__ch == __neg_chars_[__i])
2417 if (!__ranges_.empty())
2419 string_type __s2 = __collate_ ?
2420 __traits_.transform(&__ch, &__ch + 1) :
2421 string_type(1, __ch);
2422 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2424 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
2431 if (!__equivalences_.empty())
2433 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2434 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2436 if (__s2 == __equivalences_[__i])
2443 if (__traits_.isctype(__ch, __mask_))
2448 if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_))
2455 __found = __negate_; // force reject
2457 if (__found != __negate_)
2459 __s.__do_ = __state::__accept_and_consume;
2460 __s.__current_ += __consumed;
2461 __s.__node_ = this->first();
2465 __s.__do_ = __state::__reject;
2466 __s.__node_ = nullptr;
2470 template <class _CharT, class _Traits> class __lookahead;
2472 template <class _CharT, class _Traits = regex_traits<_CharT> >
2473 class _LIBCPP_TYPE_VIS_ONLY basic_regex
2477 typedef _CharT value_type;
2478 typedef regex_constants::syntax_option_type flag_type;
2479 typedef typename _Traits::locale_type locale_type;
2484 unsigned __marked_count_;
2485 unsigned __loop_count_;
2487 shared_ptr<__empty_state<_CharT> > __start_;
2488 __owns_one_state<_CharT>* __end_;
2490 typedef _VSTD::__state<_CharT> __state;
2491 typedef _VSTD::__node<_CharT> __node;
2495 static const regex_constants::syntax_option_type icase = regex_constants::icase;
2496 static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2497 static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
2498 static const regex_constants::syntax_option_type collate = regex_constants::collate;
2499 static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2500 static const regex_constants::syntax_option_type basic = regex_constants::basic;
2501 static const regex_constants::syntax_option_type extended = regex_constants::extended;
2502 static const regex_constants::syntax_option_type awk = regex_constants::awk;
2503 static const regex_constants::syntax_option_type grep = regex_constants::grep;
2504 static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
2506 // construct/copy/destroy:
2507 _LIBCPP_INLINE_VISIBILITY
2509 : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0),
2512 _LIBCPP_INLINE_VISIBILITY
2513 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2514 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2516 {__parse(__p, __p + __traits_.length(__p));}
2517 _LIBCPP_INLINE_VISIBILITY
2518 basic_regex(const value_type* __p, size_t __len, flag_type __f)
2519 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2521 {__parse(__p, __p + __len);}
2522 // basic_regex(const basic_regex&) = default;
2523 // basic_regex(basic_regex&&) = default;
2524 template <class _ST, class _SA>
2525 _LIBCPP_INLINE_VISIBILITY
2526 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2527 flag_type __f = regex_constants::ECMAScript)
2528 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2530 {__parse(__p.begin(), __p.end());}
2531 template <class _ForwardIterator>
2532 _LIBCPP_INLINE_VISIBILITY
2533 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
2534 flag_type __f = regex_constants::ECMAScript)
2535 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2537 {__parse(__first, __last);}
2538 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2539 _LIBCPP_INLINE_VISIBILITY
2540 basic_regex(initializer_list<value_type> __il,
2541 flag_type __f = regex_constants::ECMAScript)
2542 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2544 {__parse(__il.begin(), __il.end());}
2545 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2547 // ~basic_regex() = default;
2549 // basic_regex& operator=(const basic_regex&) = default;
2550 // basic_regex& operator=(basic_regex&&) = default;
2551 _LIBCPP_INLINE_VISIBILITY
2552 basic_regex& operator=(const value_type* __p)
2553 {return assign(__p);}
2554 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2555 _LIBCPP_INLINE_VISIBILITY
2556 basic_regex& operator=(initializer_list<value_type> __il)
2557 {return assign(__il);}
2558 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2559 template <class _ST, class _SA>
2560 _LIBCPP_INLINE_VISIBILITY
2561 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
2562 {return assign(__p);}
2565 _LIBCPP_INLINE_VISIBILITY
2566 basic_regex& assign(const basic_regex& __that)
2567 {return *this = __that;}
2568 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2569 _LIBCPP_INLINE_VISIBILITY
2570 basic_regex& assign(basic_regex&& __that) _NOEXCEPT
2571 {return *this = _VSTD::move(__that);}
2573 _LIBCPP_INLINE_VISIBILITY
2574 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2575 {return assign(__p, __p + __traits_.length(__p), __f);}
2576 _LIBCPP_INLINE_VISIBILITY
2577 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f)
2578 {return assign(__p, __p + __len, __f);}
2579 template <class _ST, class _SA>
2580 _LIBCPP_INLINE_VISIBILITY
2581 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
2582 flag_type __f = regex_constants::ECMAScript)
2583 {return assign(__s.begin(), __s.end(), __f);}
2585 template <class _InputIterator>
2586 _LIBCPP_INLINE_VISIBILITY
2589 __is_input_iterator <_InputIterator>::value &&
2590 !__is_forward_iterator<_InputIterator>::value,
2593 assign(_InputIterator __first, _InputIterator __last,
2594 flag_type __f = regex_constants::ECMAScript)
2596 basic_string<_CharT> __t(__first, __last);
2597 return assign(__t.begin(), __t.end(), __f);
2601 _LIBCPP_INLINE_VISIBILITY
2602 void __member_init(flag_type __f)
2605 __marked_count_ = 0;
2612 template <class _ForwardIterator>
2613 _LIBCPP_INLINE_VISIBILITY
2616 __is_forward_iterator<_ForwardIterator>::value,
2619 assign(_ForwardIterator __first, _ForwardIterator __last,
2620 flag_type __f = regex_constants::ECMAScript)
2622 return assign(basic_regex(__first, __last, __f));
2625 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2627 _LIBCPP_INLINE_VISIBILITY
2628 basic_regex& assign(initializer_list<value_type> __il,
2629 flag_type __f = regex_constants::ECMAScript)
2630 {return assign(__il.begin(), __il.end(), __f);}
2632 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2634 // const operations:
2635 _LIBCPP_INLINE_VISIBILITY
2636 unsigned mark_count() const {return __marked_count_;}
2637 _LIBCPP_INLINE_VISIBILITY
2638 flag_type flags() const {return __flags_;}
2641 _LIBCPP_INLINE_VISIBILITY
2642 locale_type imbue(locale_type __loc)
2644 __member_init(ECMAScript);
2646 return __traits_.imbue(__loc);
2648 _LIBCPP_INLINE_VISIBILITY
2649 locale_type getloc() const {return __traits_.getloc();}
2652 void swap(basic_regex& __r);
2655 _LIBCPP_INLINE_VISIBILITY
2656 unsigned __loop_count() const {return __loop_count_;}
2658 template <class _ForwardIterator>
2660 __parse(_ForwardIterator __first, _ForwardIterator __last);
2661 template <class _ForwardIterator>
2663 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2664 template <class _ForwardIterator>
2666 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2667 template <class _ForwardIterator>
2669 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2670 template <class _ForwardIterator>
2672 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2673 template <class _ForwardIterator>
2675 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2676 template <class _ForwardIterator>
2678 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2679 template <class _ForwardIterator>
2681 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2682 template <class _ForwardIterator>
2684 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2685 template <class _ForwardIterator>
2687 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2688 template <class _ForwardIterator>
2690 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2691 template <class _ForwardIterator>
2693 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2694 template <class _ForwardIterator>
2696 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2697 template <class _ForwardIterator>
2699 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2700 __owns_one_state<_CharT>* __s,
2701 unsigned __mexp_begin, unsigned __mexp_end);
2702 template <class _ForwardIterator>
2704 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2705 __owns_one_state<_CharT>* __s,
2706 unsigned __mexp_begin, unsigned __mexp_end);
2707 template <class _ForwardIterator>
2709 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2710 template <class _ForwardIterator>
2712 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
2713 __bracket_expression<_CharT, _Traits>* __ml);
2714 template <class _ForwardIterator>
2716 __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
2717 __bracket_expression<_CharT, _Traits>* __ml);
2718 template <class _ForwardIterator>
2720 __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
2721 __bracket_expression<_CharT, _Traits>* __ml);
2722 template <class _ForwardIterator>
2724 __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
2725 __bracket_expression<_CharT, _Traits>* __ml);
2726 template <class _ForwardIterator>
2728 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
2729 basic_string<_CharT>& __col_sym);
2730 template <class _ForwardIterator>
2732 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
2733 template <class _ForwardIterator>
2735 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2736 template <class _ForwardIterator>
2738 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2739 template <class _ForwardIterator>
2741 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2742 template <class _ForwardIterator>
2744 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2745 template <class _ForwardIterator>
2747 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2748 template <class _ForwardIterator>
2750 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2751 template <class _ForwardIterator>
2753 __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2754 template <class _ForwardIterator>
2756 __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2757 template <class _ForwardIterator>
2759 __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2760 template <class _ForwardIterator>
2762 __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2763 template <class _ForwardIterator>
2765 __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2766 template <class _ForwardIterator>
2768 __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2769 template <class _ForwardIterator>
2771 __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2772 template <class _ForwardIterator>
2774 __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2775 template <class _ForwardIterator>
2777 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
2778 basic_string<_CharT>* __str = nullptr);
2779 template <class _ForwardIterator>
2781 __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
2782 template <class _ForwardIterator>
2784 __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
2785 template <class _ForwardIterator>
2787 __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
2788 template <class _ForwardIterator>
2790 __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
2791 basic_string<_CharT>& __str,
2792 __bracket_expression<_CharT, _Traits>* __ml);
2793 template <class _ForwardIterator>
2795 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
2796 basic_string<_CharT>* __str = nullptr);
2798 _LIBCPP_INLINE_VISIBILITY
2799 void __push_l_anchor();
2800 void __push_r_anchor();
2801 void __push_match_any();
2802 void __push_match_any_but_newline();
2803 _LIBCPP_INLINE_VISIBILITY
2804 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2805 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2806 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2807 __mexp_begin, __mexp_end);}
2808 _LIBCPP_INLINE_VISIBILITY
2809 void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2810 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2811 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2812 __mexp_begin, __mexp_end, false);}
2813 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2814 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2815 bool __greedy = true);
2816 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
2817 void __push_char(value_type __c);
2818 void __push_back_ref(int __i);
2819 void __push_alternation(__owns_one_state<_CharT>* __sa,
2820 __owns_one_state<_CharT>* __sb);
2821 void __push_begin_marked_subexpression();
2822 void __push_end_marked_subexpression(unsigned);
2823 void __push_empty();
2824 void __push_word_boundary(bool);
2825 void __push_lookahead(const basic_regex&, bool, unsigned);
2827 template <class _Allocator>
2829 __search(const _CharT* __first, const _CharT* __last,
2830 match_results<const _CharT*, _Allocator>& __m,
2831 regex_constants::match_flag_type __flags) const;
2833 template <class _Allocator>
2835 __match_at_start(const _CharT* __first, const _CharT* __last,
2836 match_results<const _CharT*, _Allocator>& __m,
2837 regex_constants::match_flag_type __flags, bool) const;
2838 template <class _Allocator>
2840 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
2841 match_results<const _CharT*, _Allocator>& __m,
2842 regex_constants::match_flag_type __flags, bool) const;
2843 template <class _Allocator>
2845 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
2846 match_results<const _CharT*, _Allocator>& __m,
2847 regex_constants::match_flag_type __flags, bool) const;
2848 template <class _Allocator>
2850 __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
2851 match_results<const _CharT*, _Allocator>& __m,
2852 regex_constants::match_flag_type __flags, bool) const;
2854 template <class _Bp, class _Ap, class _Cp, class _Tp>
2857 regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
2858 regex_constants::match_flag_type);
2860 template <class _Ap, class _Cp, class _Tp>
2863 regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&,
2864 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
2866 template <class _Bp, class _Cp, class _Tp>
2869 regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&,
2870 regex_constants::match_flag_type);
2872 template <class _Cp, class _Tp>
2875 regex_search(const _Cp*, const _Cp*,
2876 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
2878 template <class _Cp, class _Ap, class _Tp>
2881 regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&,
2882 regex_constants::match_flag_type);
2884 template <class _ST, class _SA, class _Cp, class _Tp>
2887 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
2888 const basic_regex<_Cp, _Tp>& __e,
2889 regex_constants::match_flag_type __flags);
2891 template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
2894 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
2895 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
2896 const basic_regex<_Cp, _Tp>& __e,
2897 regex_constants::match_flag_type __flags);
2899 template <class _Iter, class _Ap, class _Cp, class _Tp>
2902 regex_search(__wrap_iter<_Iter> __first,
2903 __wrap_iter<_Iter> __last,
2904 match_results<__wrap_iter<_Iter>, _Ap>& __m,
2905 const basic_regex<_Cp, _Tp>& __e,
2906 regex_constants::match_flag_type __flags);
2908 template <class, class> friend class __lookahead;
2911 template <class _CharT, class _Traits>
2912 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
2913 template <class _CharT, class _Traits>
2914 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
2915 template <class _CharT, class _Traits>
2916 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
2917 template <class _CharT, class _Traits>
2918 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
2919 template <class _CharT, class _Traits>
2920 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
2921 template <class _CharT, class _Traits>
2922 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
2923 template <class _CharT, class _Traits>
2924 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
2925 template <class _CharT, class _Traits>
2926 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
2927 template <class _CharT, class _Traits>
2928 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
2929 template <class _CharT, class _Traits>
2930 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
2932 template <class _CharT, class _Traits>
2934 basic_regex<_CharT, _Traits>::swap(basic_regex& __r)
2937 swap(__traits_, __r.__traits_);
2938 swap(__flags_, __r.__flags_);
2939 swap(__marked_count_, __r.__marked_count_);
2940 swap(__loop_count_, __r.__loop_count_);
2941 swap(__open_count_, __r.__open_count_);
2942 swap(__start_, __r.__start_);
2943 swap(__end_, __r.__end_);
2946 template <class _CharT, class _Traits>
2947 inline _LIBCPP_INLINE_VISIBILITY
2949 swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
2951 return __x.swap(__y);
2956 template <class _CharT, class _Traits>
2958 : public __owns_one_state<_CharT>
2960 typedef __owns_one_state<_CharT> base;
2962 basic_regex<_CharT, _Traits> __exp_;
2966 __lookahead(const __lookahead&);
2967 __lookahead& operator=(const __lookahead&);
2969 typedef _VSTD::__state<_CharT> __state;
2971 _LIBCPP_INLINE_VISIBILITY
2972 __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
2973 : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
2975 virtual void __exec(__state&) const;
2978 template <class _CharT, class _Traits>
2980 __lookahead<_CharT, _Traits>::__exec(__state& __s) const
2982 match_results<const _CharT*> __m;
2983 __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
2984 bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_,
2986 __s.__flags_ | regex_constants::match_continuous,
2987 __s.__at_first_ && __s.__current_ == __s.__first_);
2988 if (__matched != __invert_)
2990 __s.__do_ = __state::__accept_but_not_consume;
2991 __s.__node_ = this->first();
2992 for (unsigned __i = 1; __i < __m.size(); ++__i) {
2993 __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
2998 __s.__do_ = __state::__reject;
2999 __s.__node_ = nullptr;
3003 template <class _CharT, class _Traits>
3004 template <class _ForwardIterator>
3006 basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
3007 _ForwardIterator __last)
3010 unique_ptr<__node> __h(new __end_state<_CharT>);
3011 __start_.reset(new __empty_state<_CharT>(__h.get()));
3013 __end_ = __start_.get();
3015 switch (__flags_ & 0x1F0)
3018 __first = __parse_ecma_exp(__first, __last);
3021 __first = __parse_basic_reg_exp(__first, __last);
3025 __first = __parse_extended_reg_exp(__first, __last);
3028 __first = __parse_grep(__first, __last);
3031 __first = __parse_egrep(__first, __last);
3034 __throw_regex_error<regex_constants::__re_err_grammar>();
3039 template <class _CharT, class _Traits>
3040 template <class _ForwardIterator>
3042 basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
3043 _ForwardIterator __last)
3045 if (__first != __last)
3047 if (*__first == '^')
3052 if (__first != __last)
3054 __first = __parse_RE_expression(__first, __last);
3055 if (__first != __last)
3057 _ForwardIterator __temp = _VSTD::next(__first);
3058 if (__temp == __last && *__first == '$')
3065 if (__first != __last)
3066 __throw_regex_error<regex_constants::__re_err_empty>();
3071 template <class _CharT, class _Traits>
3072 template <class _ForwardIterator>
3074 basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
3075 _ForwardIterator __last)
3077 __owns_one_state<_CharT>* __sa = __end_;
3078 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
3079 if (__temp == __first)
3080 __throw_regex_error<regex_constants::__re_err_empty>();
3082 while (__first != __last && *__first == '|')
3084 __owns_one_state<_CharT>* __sb = __end_;
3085 __temp = __parse_ERE_branch(++__first, __last);
3086 if (__temp == __first)
3087 __throw_regex_error<regex_constants::__re_err_empty>();
3088 __push_alternation(__sa, __sb);
3094 template <class _CharT, class _Traits>
3095 template <class _ForwardIterator>
3097 basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
3098 _ForwardIterator __last)
3100 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
3101 if (__temp == __first)
3102 __throw_regex_error<regex_constants::__re_err_empty>();
3106 __temp = __parse_ERE_expression(__first, __last);
3107 } while (__temp != __first);
3111 template <class _CharT, class _Traits>
3112 template <class _ForwardIterator>
3114 basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
3115 _ForwardIterator __last)
3117 __owns_one_state<_CharT>* __e = __end_;
3118 unsigned __mexp_begin = __marked_count_;
3119 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
3120 if (__temp == __first && __temp != __last)
3133 __push_begin_marked_subexpression();
3134 unsigned __temp_count = __marked_count_;
3136 __temp = __parse_extended_reg_exp(++__temp, __last);
3137 if (__temp == __last || *__temp != ')')
3138 __throw_regex_error<regex_constants::error_paren>();
3139 __push_end_marked_subexpression(__temp_count);
3145 if (__temp != __first)
3146 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
3152 template <class _CharT, class _Traits>
3153 template <class _ForwardIterator>
3155 basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
3156 _ForwardIterator __last)
3160 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
3161 if (__temp == __first)
3168 template <class _CharT, class _Traits>
3169 template <class _ForwardIterator>
3171 basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
3172 _ForwardIterator __last)
3174 if (__first != __last)
3176 __owns_one_state<_CharT>* __e = __end_;
3177 unsigned __mexp_begin = __marked_count_;
3178 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
3179 if (__temp != __first)
3180 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
3181 __mexp_begin+1, __marked_count_+1);
3186 template <class _CharT, class _Traits>
3187 template <class _ForwardIterator>
3189 basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
3190 _ForwardIterator __last)
3192 _ForwardIterator __temp = __first;
3193 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
3194 if (__temp == __first)
3196 __temp = __parse_Back_open_paren(__first, __last);
3197 if (__temp != __first)
3199 __push_begin_marked_subexpression();
3200 unsigned __temp_count = __marked_count_;
3201 __first = __parse_RE_expression(__temp, __last);
3202 __temp = __parse_Back_close_paren(__first, __last);
3203 if (__temp == __first)
3204 __throw_regex_error<regex_constants::error_paren>();
3205 __push_end_marked_subexpression(__temp_count);
3209 __first = __parse_BACKREF(__first, __last);
3214 template <class _CharT, class _Traits>
3215 template <class _ForwardIterator>
3217 basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
3218 _ForwardIterator __first,
3219 _ForwardIterator __last)
3221 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
3222 if (__temp == __first)
3224 __temp = __parse_QUOTED_CHAR(__first, __last);
3225 if (__temp == __first)
3227 if (__temp != __last && *__temp == '.')
3233 __temp = __parse_bracket_expression(__first, __last);
3240 template <class _CharT, class _Traits>
3241 template <class _ForwardIterator>
3243 basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
3244 _ForwardIterator __first,
3245 _ForwardIterator __last)
3247 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
3248 if (__temp == __first)
3250 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
3251 if (__temp == __first)
3253 if (__temp != __last && *__temp == '.')
3259 __temp = __parse_bracket_expression(__first, __last);
3266 template <class _CharT, class _Traits>
3267 template <class _ForwardIterator>
3269 basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_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_paren(_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_Back_open_brace(_ForwardIterator __first,
3306 _ForwardIterator __last)
3308 if (__first != __last)
3310 _ForwardIterator __temp = _VSTD::next(__first);
3311 if (__temp != __last)
3313 if (*__first == '\\' && *__temp == '{')
3320 template <class _CharT, class _Traits>
3321 template <class _ForwardIterator>
3323 basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
3324 _ForwardIterator __last)
3326 if (__first != __last)
3328 _ForwardIterator __temp = _VSTD::next(__first);
3329 if (__temp != __last)
3331 if (*__first == '\\' && *__temp == '}')
3338 template <class _CharT, class _Traits>
3339 template <class _ForwardIterator>
3341 basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
3342 _ForwardIterator __last)
3344 if (__first != __last)
3346 _ForwardIterator __temp = _VSTD::next(__first);
3347 if (__temp != __last)
3349 if (*__first == '\\')
3351 int __val = __traits_.value(*__temp, 10);
3352 if (__val >= 1 && __val <= 9)
3354 __push_back_ref(__val);
3363 template <class _CharT, class _Traits>
3364 template <class _ForwardIterator>
3366 basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
3367 _ForwardIterator __last)
3369 if (__first != __last)
3371 _ForwardIterator __temp = _VSTD::next(__first);
3372 if (__temp == __last && *__first == '$')
3374 // Not called inside a bracket
3375 if (*__first == '.' || *__first == '\\' || *__first == '[')
3377 __push_char(*__first);
3383 template <class _CharT, class _Traits>
3384 template <class _ForwardIterator>
3386 basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
3387 _ForwardIterator __last)
3389 if (__first != __last)
3406 if (__open_count_ == 0)
3408 __push_char(*__first);
3413 __push_char(*__first);
3421 template <class _CharT, class _Traits>
3422 template <class _ForwardIterator>
3424 basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
3425 _ForwardIterator __last)
3427 if (__first != __last)
3429 _ForwardIterator __temp = _VSTD::next(__first);
3430 if (__temp != __last)
3432 if (*__first == '\\')
3442 __push_char(*__temp);
3452 template <class _CharT, class _Traits>
3453 template <class _ForwardIterator>
3455 basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
3456 _ForwardIterator __last)
3458 if (__first != __last)
3460 _ForwardIterator __temp = _VSTD::next(__first);
3461 if (__temp != __last)
3463 if (*__first == '\\')
3480 __push_char(*__temp);
3484 if ((__flags_ & 0x1F0) == awk)
3485 __first = __parse_awk_escape(++__first, __last);
3494 template <class _CharT, class _Traits>
3495 template <class _ForwardIterator>
3497 basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
3498 _ForwardIterator __last,
3499 __owns_one_state<_CharT>* __s,
3500 unsigned __mexp_begin,
3501 unsigned __mexp_end)
3503 if (__first != __last)
3505 if (*__first == '*')
3507 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3512 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3513 if (__temp != __first)
3517 __temp = __parse_DUP_COUNT(__first, __last, __min);
3518 if (__temp == __first)
3519 __throw_regex_error<regex_constants::error_badbrace>();
3521 if (__first == __last)
3522 __throw_regex_error<regex_constants::error_brace>();
3523 if (*__first != ',')
3525 __temp = __parse_Back_close_brace(__first, __last);
3526 if (__temp == __first)
3527 __throw_regex_error<regex_constants::error_brace>();
3528 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
3534 ++__first; // consume ','
3536 __first = __parse_DUP_COUNT(__first, __last, __max);
3537 __temp = __parse_Back_close_brace(__first, __last);
3538 if (__temp == __first)
3539 __throw_regex_error<regex_constants::error_brace>();
3541 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3545 __throw_regex_error<regex_constants::error_badbrace>();
3546 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
3557 template <class _CharT, class _Traits>
3558 template <class _ForwardIterator>
3560 basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
3561 _ForwardIterator __last,
3562 __owns_one_state<_CharT>* __s,
3563 unsigned __mexp_begin,
3564 unsigned __mexp_end)
3566 if (__first != __last)
3568 unsigned __grammar = __flags_ & 0x1F0;
3573 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3576 __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3579 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3583 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3586 __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3589 __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3593 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3596 __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3599 __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
3604 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
3605 if (__temp == __first)
3606 __throw_regex_error<regex_constants::error_badbrace>();
3608 if (__first == __last)
3609 __throw_regex_error<regex_constants::error_brace>();
3614 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3617 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3620 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
3624 if (__first == __last)
3625 __throw_regex_error<regex_constants::error_badbrace>();
3626 if (*__first == '}')
3629 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3632 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3635 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3640 __temp = __parse_DUP_COUNT(__first, __last, __max);
3641 if (__temp == __first)
3642 __throw_regex_error<regex_constants::error_brace>();
3644 if (__first == __last || *__first != '}')
3645 __throw_regex_error<regex_constants::error_brace>();
3648 __throw_regex_error<regex_constants::error_badbrace>();
3649 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3652 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3655 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
3659 __throw_regex_error<regex_constants::error_badbrace>();
3668 template <class _CharT, class _Traits>
3669 template <class _ForwardIterator>
3671 basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
3672 _ForwardIterator __last)
3674 if (__first != __last && *__first == '[')
3677 if (__first == __last)
3678 __throw_regex_error<regex_constants::error_brack>();
3679 bool __negate = false;
3680 if (*__first == '^')
3685 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3686 // __ml owned by *this
3687 if (__first == __last)
3688 __throw_regex_error<regex_constants::error_brack>();
3689 if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']')
3691 __ml->__add_char(']');
3694 __first = __parse_follow_list(__first, __last, __ml);
3695 if (__first == __last)
3696 __throw_regex_error<regex_constants::error_brack>();
3697 if (*__first == '-')
3699 __ml->__add_char('-');
3702 if (__first == __last || *__first != ']')
3703 __throw_regex_error<regex_constants::error_brack>();
3709 template <class _CharT, class _Traits>
3710 template <class _ForwardIterator>
3712 basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
3713 _ForwardIterator __last,
3714 __bracket_expression<_CharT, _Traits>* __ml)
3716 if (__first != __last)
3720 _ForwardIterator __temp = __parse_expression_term(__first, __last,
3722 if (__temp == __first)
3730 template <class _CharT, class _Traits>
3731 template <class _ForwardIterator>
3733 basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
3734 _ForwardIterator __last,
3735 __bracket_expression<_CharT, _Traits>* __ml)
3737 if (__first != __last && *__first != ']')
3739 _ForwardIterator __temp = _VSTD::next(__first);
3740 basic_string<_CharT> __start_range;
3741 if (__temp != __last && *__first == '[')
3744 return __parse_equivalence_class(++__temp, __last, __ml);
3745 else if (*__temp == ':')
3746 return __parse_character_class(++__temp, __last, __ml);
3747 else if (*__temp == '.')
3748 __first = __parse_collating_symbol(++__temp, __last, __start_range);
3750 unsigned __grammar = __flags_ & 0x1F0;
3751 if (__start_range.empty())
3753 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3755 if (__grammar == ECMAScript)
3756 __first = __parse_class_escape(++__first, __last, __start_range, __ml);
3758 __first = __parse_awk_escape(++__first, __last, &__start_range);
3762 __start_range = *__first;
3766 if (__first != __last && *__first != ']')
3768 __temp = _VSTD::next(__first);
3769 if (__temp != __last && *__first == '-' && *__temp != ']')
3772 basic_string<_CharT> __end_range;
3775 if (__temp != __last && *__first == '[' && *__temp == '.')
3776 __first = __parse_collating_symbol(++__temp, __last, __end_range);
3779 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3781 if (__grammar == ECMAScript)
3782 __first = __parse_class_escape(++__first, __last,
3785 __first = __parse_awk_escape(++__first, __last,
3790 __end_range = *__first;
3794 __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range));
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]);
3804 else if (!__start_range.empty())
3806 if (__start_range.size() == 1)
3807 __ml->__add_char(__start_range[0]);
3809 __ml->__add_digraph(__start_range[0], __start_range[1]);
3815 template <class _CharT, class _Traits>
3816 template <class _ForwardIterator>
3818 basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
3819 _ForwardIterator __last,
3820 basic_string<_CharT>& __str,
3821 __bracket_expression<_CharT, _Traits>* __ml)
3823 if (__first == __last)
3824 __throw_regex_error<regex_constants::error_escape>();
3834 __ml->__add_class(ctype_base::digit);
3837 __ml->__add_neg_class(ctype_base::digit);
3840 __ml->__add_class(ctype_base::space);
3843 __ml->__add_neg_class(ctype_base::space);
3846 __ml->__add_class(ctype_base::alnum);
3847 __ml->__add_char('_');
3850 __ml->__add_neg_class(ctype_base::alnum);
3851 __ml->__add_neg_char('_');
3854 __first = __parse_character_escape(__first, __last, &__str);
3858 template <class _CharT, class _Traits>
3859 template <class _ForwardIterator>
3861 basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
3862 _ForwardIterator __last,
3863 basic_string<_CharT>* __str)
3865 if (__first == __last)
3866 __throw_regex_error<regex_constants::error_escape>();
3875 __push_char(*__first);
3881 __push_char(_CharT(7));
3887 __push_char(_CharT(8));
3891 *__str = _CharT(0xC);
3893 __push_char(_CharT(0xC));
3897 *__str = _CharT(0xA);
3899 __push_char(_CharT(0xA));
3903 *__str = _CharT(0xD);
3905 __push_char(_CharT(0xD));
3909 *__str = _CharT(0x9);
3911 __push_char(_CharT(0x9));
3915 *__str = _CharT(0xB);
3917 __push_char(_CharT(0xB));
3920 if ('0' <= *__first && *__first <= '7')
3922 unsigned __val = *__first - '0';
3923 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3925 __val = 8 * __val + *__first - '0';
3926 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3927 __val = 8 * __val + *__first++ - '0';
3930 *__str = _CharT(__val);
3932 __push_char(_CharT(__val));
3935 __throw_regex_error<regex_constants::error_escape>();
3939 template <class _CharT, class _Traits>
3940 template <class _ForwardIterator>
3942 basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
3943 _ForwardIterator __last,
3944 __bracket_expression<_CharT, _Traits>* __ml)
3947 // This means =] must exist
3948 value_type _Equal_close[2] = {'=', ']'};
3949 _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close,
3951 if (__temp == __last)
3952 __throw_regex_error<regex_constants::error_brack>();
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 if (__collate_name.empty())
3958 __throw_regex_error<regex_constants::error_collate>();
3959 string_type __equiv_name =
3960 __traits_.transform_primary(__collate_name.begin(),
3961 __collate_name.end());
3962 if (!__equiv_name.empty())
3963 __ml->__add_equivalence(__equiv_name);
3966 switch (__collate_name.size())
3969 __ml->__add_char(__collate_name[0]);
3972 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
3975 __throw_regex_error<regex_constants::error_collate>();
3978 __first = _VSTD::next(__temp, 2);
3982 template <class _CharT, class _Traits>
3983 template <class _ForwardIterator>
3985 basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
3986 _ForwardIterator __last,
3987 __bracket_expression<_CharT, _Traits>* __ml)
3990 // This means :] must exist
3991 value_type _Colon_close[2] = {':', ']'};
3992 _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close,
3994 if (__temp == __last)
3995 __throw_regex_error<regex_constants::error_brack>();
3996 // [__first, __temp) contains all text in [: ... :]
3997 typedef typename _Traits::char_class_type char_class_type;
3998 char_class_type __class_type =
3999 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
4000 if (__class_type == 0)
4001 __throw_regex_error<regex_constants::error_brack>();
4002 __ml->__add_class(__class_type);
4003 __first = _VSTD::next(__temp, 2);
4007 template <class _CharT, class _Traits>
4008 template <class _ForwardIterator>
4010 basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
4011 _ForwardIterator __last,
4012 basic_string<_CharT>& __col_sym)
4015 // This means .] must exist
4016 value_type _Dot_close[2] = {'.', ']'};
4017 _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close,
4019 if (__temp == __last)
4020 __throw_regex_error<regex_constants::error_brack>();
4021 // [__first, __temp) contains all text in [. ... .]
4022 __col_sym = __traits_.lookup_collatename(__first, __temp);
4023 switch (__col_sym.size())
4029 __throw_regex_error<regex_constants::error_collate>();
4031 __first = _VSTD::next(__temp, 2);
4035 template <class _CharT, class _Traits>
4036 template <class _ForwardIterator>
4038 basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
4039 _ForwardIterator __last,
4042 if (__first != __last )
4044 int __val = __traits_.value(*__first, 10);
4049 __first != __last && ( __val = __traits_.value(*__first, 10)) != -1;
4060 template <class _CharT, class _Traits>
4061 template <class _ForwardIterator>
4063 basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
4064 _ForwardIterator __last)
4066 __owns_one_state<_CharT>* __sa = __end_;
4067 _ForwardIterator __temp = __parse_alternative(__first, __last);
4068 if (__temp == __first)
4071 while (__first != __last && *__first == '|')
4073 __owns_one_state<_CharT>* __sb = __end_;
4074 __temp = __parse_alternative(++__first, __last);
4075 if (__temp == __first)
4077 __push_alternation(__sa, __sb);
4083 template <class _CharT, class _Traits>
4084 template <class _ForwardIterator>
4086 basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
4087 _ForwardIterator __last)
4091 _ForwardIterator __temp = __parse_term(__first, __last);
4092 if (__temp == __first)
4099 template <class _CharT, class _Traits>
4100 template <class _ForwardIterator>
4102 basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
4103 _ForwardIterator __last)
4105 _ForwardIterator __temp = __parse_assertion(__first, __last);
4106 if (__temp == __first)
4108 __owns_one_state<_CharT>* __e = __end_;
4109 unsigned __mexp_begin = __marked_count_;
4110 __temp = __parse_atom(__first, __last);
4111 if (__temp != __first)
4112 __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
4113 __mexp_begin+1, __marked_count_+1);
4120 template <class _CharT, class _Traits>
4121 template <class _ForwardIterator>
4123 basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
4124 _ForwardIterator __last)
4126 if (__first != __last)
4140 _ForwardIterator __temp = _VSTD::next(__first);
4141 if (__temp != __last)
4145 __push_word_boundary(false);
4148 else if (*__temp == 'B')
4150 __push_word_boundary(true);
4158 _ForwardIterator __temp = _VSTD::next(__first);
4159 if (__temp != __last && *__temp == '?')
4161 if (++__temp != __last)
4168 __exp.__flags_ = __flags_;
4169 __temp = __exp.__parse(++__temp, __last);
4170 unsigned __mexp = __exp.__marked_count_;
4171 __push_lookahead(_VSTD::move(__exp), false, __marked_count_);
4172 __marked_count_ += __mexp;
4173 if (__temp == __last || *__temp != ')')
4174 __throw_regex_error<regex_constants::error_paren>();
4181 __exp.__flags_ = __flags_;
4182 __temp = __exp.__parse(++__temp, __last);
4183 unsigned __mexp = __exp.__marked_count_;
4184 __push_lookahead(_VSTD::move(__exp), true, __marked_count_);
4185 __marked_count_ += __mexp;
4186 if (__temp == __last || *__temp != ')')
4187 __throw_regex_error<regex_constants::error_paren>();
4201 template <class _CharT, class _Traits>
4202 template <class _ForwardIterator>
4204 basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
4205 _ForwardIterator __last)
4207 if (__first != __last)
4212 __push_match_any_but_newline();
4216 __first = __parse_atom_escape(__first, __last);
4219 __first = __parse_bracket_expression(__first, __last);
4224 if (__first == __last)
4225 __throw_regex_error<regex_constants::error_paren>();
4226 _ForwardIterator __temp = _VSTD::next(__first);
4227 if (__temp != __last && *__first == '?' && *__temp == ':')
4230 __first = __parse_ecma_exp(++__temp, __last);
4231 if (__first == __last || *__first != ')')
4232 __throw_regex_error<regex_constants::error_paren>();
4238 __push_begin_marked_subexpression();
4239 unsigned __temp_count = __marked_count_;
4241 __first = __parse_ecma_exp(__first, __last);
4242 if (__first == __last || *__first != ')')
4243 __throw_regex_error<regex_constants::error_paren>();
4244 __push_end_marked_subexpression(__temp_count);
4254 __throw_regex_error<regex_constants::error_badrepeat>();
4257 __first = __parse_pattern_character(__first, __last);
4264 template <class _CharT, class _Traits>
4265 template <class _ForwardIterator>
4267 basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
4268 _ForwardIterator __last)
4270 if (__first != __last && *__first == '\\')
4272 _ForwardIterator __t1 = _VSTD::next(__first);
4274 __throw_regex_error<regex_constants::error_escape>();
4276 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
4281 __t2 = __parse_character_class_escape(__t1, __last);
4286 __t2 = __parse_character_escape(__t1, __last);
4295 template <class _CharT, class _Traits>
4296 template <class _ForwardIterator>
4298 basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
4299 _ForwardIterator __last)
4301 if (__first != __last)
4303 if (*__first == '0')
4305 __push_char(_CharT());
4308 else if ('1' <= *__first && *__first <= '9')
4310 unsigned __v = *__first - '0';
4311 for (++__first; '0' <= *__first && *__first <= '9'; ++__first)
4312 __v = 10 * __v + *__first - '0';
4313 if (__v > mark_count())
4314 __throw_regex_error<regex_constants::error_backref>();
4315 __push_back_ref(__v);
4321 template <class _CharT, class _Traits>
4322 template <class _ForwardIterator>
4324 basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
4325 _ForwardIterator __last)
4327 if (__first != __last)
4329 __bracket_expression<_CharT, _Traits>* __ml;
4333 __ml = __start_matching_list(false);
4334 __ml->__add_class(ctype_base::digit);
4338 __ml = __start_matching_list(true);
4339 __ml->__add_class(ctype_base::digit);
4343 __ml = __start_matching_list(false);
4344 __ml->__add_class(ctype_base::space);
4348 __ml = __start_matching_list(true);
4349 __ml->__add_class(ctype_base::space);
4353 __ml = __start_matching_list(false);
4354 __ml->__add_class(ctype_base::alnum);
4355 __ml->__add_char('_');
4359 __ml = __start_matching_list(true);
4360 __ml->__add_class(ctype_base::alnum);
4361 __ml->__add_char('_');
4369 template <class _CharT, class _Traits>
4370 template <class _ForwardIterator>
4372 basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
4373 _ForwardIterator __last,
4374 basic_string<_CharT>* __str)
4376 if (__first != __last)
4378 _ForwardIterator __t;
4385 *__str = _CharT(0xC);
4387 __push_char(_CharT(0xC));
4392 *__str = _CharT(0xA);
4394 __push_char(_CharT(0xA));
4399 *__str = _CharT(0xD);
4401 __push_char(_CharT(0xD));
4406 *__str = _CharT(0x9);
4408 __push_char(_CharT(0x9));
4413 *__str = _CharT(0xB);
4415 __push_char(_CharT(0xB));
4419 if ((__t = _VSTD::next(__first)) != __last)
4421 if (('A' <= *__t && *__t <= 'Z') ||
4422 ('a' <= *__t && *__t <= 'z'))
4425 *__str = _CharT(*__t % 32);
4427 __push_char(_CharT(*__t % 32));
4431 __throw_regex_error<regex_constants::error_escape>();
4434 __throw_regex_error<regex_constants::error_escape>();
4438 if (__first == __last)
4439 __throw_regex_error<regex_constants::error_escape>();
4440 __hd = __traits_.value(*__first, 16);
4442 __throw_regex_error<regex_constants::error_escape>();
4443 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4445 if (__first == __last)
4446 __throw_regex_error<regex_constants::error_escape>();
4447 __hd = __traits_.value(*__first, 16);
4449 __throw_regex_error<regex_constants::error_escape>();
4450 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4454 if (__first == __last)
4455 __throw_regex_error<regex_constants::error_escape>();
4456 __hd = __traits_.value(*__first, 16);
4458 __throw_regex_error<regex_constants::error_escape>();
4459 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4461 if (__first == __last)
4462 __throw_regex_error<regex_constants::error_escape>();
4463 __hd = __traits_.value(*__first, 16);
4465 __throw_regex_error<regex_constants::error_escape>();
4466 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4468 *__str = _CharT(__sum);
4470 __push_char(_CharT(__sum));
4477 __push_char(_CharT(0));
4481 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
4486 __push_char(*__first);
4490 __throw_regex_error<regex_constants::error_escape>();
4497 template <class _CharT, class _Traits>
4498 template <class _ForwardIterator>
4500 basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
4501 _ForwardIterator __last)
4503 if (__first != __last)
4523 __push_char(*__first);
4531 template <class _CharT, class _Traits>
4532 template <class _ForwardIterator>
4534 basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
4535 _ForwardIterator __last)
4537 __owns_one_state<_CharT>* __sa = __end_;
4538 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4539 if (__t1 != __first)
4540 __parse_basic_reg_exp(__first, __t1);
4544 if (__first != __last)
4546 while (__first != __last)
4548 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4549 __owns_one_state<_CharT>* __sb = __end_;
4550 if (__t1 != __first)
4551 __parse_basic_reg_exp(__first, __t1);
4554 __push_alternation(__sa, __sb);
4556 if (__first != __last)
4562 template <class _CharT, class _Traits>
4563 template <class _ForwardIterator>
4565 basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
4566 _ForwardIterator __last)
4568 __owns_one_state<_CharT>* __sa = __end_;
4569 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4570 if (__t1 != __first)
4571 __parse_extended_reg_exp(__first, __t1);
4575 if (__first != __last)
4577 while (__first != __last)
4579 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4580 __owns_one_state<_CharT>* __sb = __end_;
4581 if (__t1 != __first)
4582 __parse_extended_reg_exp(__first, __t1);
4585 __push_alternation(__sa, __sb);
4587 if (__first != __last)
4593 template <class _CharT, class _Traits>
4595 basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
4596 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
4599 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4600 __end_->first() = nullptr;
4601 unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
4602 __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
4604 __s->first() = nullptr;
4606 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
4607 __end_ = __e2->second();
4608 __s->first() = __e2.release();
4612 template <class _CharT, class _Traits>
4614 basic_regex<_CharT, _Traits>::__push_char(value_type __c)
4616 if (flags() & icase)
4617 __end_->first() = new __match_char_icase<_CharT, _Traits>
4618 (__traits_, __c, __end_->first());
4619 else if (flags() & collate)
4620 __end_->first() = new __match_char_collate<_CharT, _Traits>
4621 (__traits_, __c, __end_->first());
4623 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
4624 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4627 template <class _CharT, class _Traits>
4629 basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
4631 if (!(__flags_ & nosubs))
4634 new __begin_marked_subexpression<_CharT>(++__marked_count_,
4636 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4640 template <class _CharT, class _Traits>
4642 basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
4644 if (!(__flags_ & nosubs))
4647 new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4648 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4652 template <class _CharT, class _Traits>
4654 basic_regex<_CharT, _Traits>::__push_l_anchor()
4656 __end_->first() = new __l_anchor<_CharT>(__end_->first());
4657 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4660 template <class _CharT, class _Traits>
4662 basic_regex<_CharT, _Traits>::__push_r_anchor()
4664 __end_->first() = new __r_anchor<_CharT>(__end_->first());
4665 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4668 template <class _CharT, class _Traits>
4670 basic_regex<_CharT, _Traits>::__push_match_any()
4672 __end_->first() = new __match_any<_CharT>(__end_->first());
4673 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4676 template <class _CharT, class _Traits>
4678 basic_regex<_CharT, _Traits>::__push_match_any_but_newline()
4680 __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
4681 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4684 template <class _CharT, class _Traits>
4686 basic_regex<_CharT, _Traits>::__push_empty()
4688 __end_->first() = new __empty_state<_CharT>(__end_->first());
4689 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4692 template <class _CharT, class _Traits>
4694 basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
4696 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
4698 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4701 template <class _CharT, class _Traits>
4703 basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
4705 if (flags() & icase)
4706 __end_->first() = new __back_ref_icase<_CharT, _Traits>
4707 (__traits_, __i, __end_->first());
4708 else if (flags() & collate)
4709 __end_->first() = new __back_ref_collate<_CharT, _Traits>
4710 (__traits_, __i, __end_->first());
4712 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
4713 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4716 template <class _CharT, class _Traits>
4718 basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
4719 __owns_one_state<_CharT>* __ea)
4721 __sa->first() = new __alternate<_CharT>(
4722 static_cast<__owns_one_state<_CharT>*>(__sa->first()),
4723 static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4724 __ea->first() = nullptr;
4725 __ea->first() = new __empty_state<_CharT>(__end_->first());
4726 __end_->first() = nullptr;
4727 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4728 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4731 template <class _CharT, class _Traits>
4732 __bracket_expression<_CharT, _Traits>*
4733 basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
4735 __bracket_expression<_CharT, _Traits>* __r =
4736 new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
4737 __negate, __flags_ & icase,
4738 __flags_ & collate);
4739 __end_->first() = __r;
4744 template <class _CharT, class _Traits>
4746 basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
4750 __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
4751 __end_->first(), __mexp);
4752 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4755 typedef basic_regex<char> regex;
4756 typedef basic_regex<wchar_t> wregex;
4760 template <class _BidirectionalIterator>
4761 class _LIBCPP_TYPE_VIS_ONLY sub_match
4762 : public pair<_BidirectionalIterator, _BidirectionalIterator>
4765 typedef _BidirectionalIterator iterator;
4766 typedef typename iterator_traits<iterator>::value_type value_type;
4767 typedef typename iterator_traits<iterator>::difference_type difference_type;
4768 typedef basic_string<value_type> string_type;
4772 _LIBCPP_INLINE_VISIBILITY
4773 _LIBCPP_CONSTEXPR sub_match() : matched() {}
4775 _LIBCPP_INLINE_VISIBILITY
4776 difference_type length() const
4777 {return matched ? _VSTD::distance(this->first, this->second) : 0;}
4778 _LIBCPP_INLINE_VISIBILITY
4779 string_type str() const
4780 {return matched ? string_type(this->first, this->second) : string_type();}
4781 _LIBCPP_INLINE_VISIBILITY
4782 operator string_type() const
4785 _LIBCPP_INLINE_VISIBILITY
4786 int compare(const sub_match& __s) const
4787 {return str().compare(__s.str());}
4788 _LIBCPP_INLINE_VISIBILITY
4789 int compare(const string_type& __s) const
4790 {return str().compare(__s);}
4791 _LIBCPP_INLINE_VISIBILITY
4792 int compare(const value_type* __s) const
4793 {return str().compare(__s);}
4796 typedef sub_match<const char*> csub_match;
4797 typedef sub_match<const wchar_t*> wcsub_match;
4798 typedef sub_match<string::const_iterator> ssub_match;
4799 typedef sub_match<wstring::const_iterator> wssub_match;
4801 template <class _BiIter>
4802 inline _LIBCPP_INLINE_VISIBILITY
4804 operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4806 return __x.compare(__y) == 0;
4809 template <class _BiIter>
4810 inline _LIBCPP_INLINE_VISIBILITY
4812 operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4814 return !(__x == __y);
4817 template <class _BiIter>
4818 inline _LIBCPP_INLINE_VISIBILITY
4820 operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4822 return __x.compare(__y) < 0;
4825 template <class _BiIter>
4826 inline _LIBCPP_INLINE_VISIBILITY
4828 operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4830 return !(__y < __x);
4833 template <class _BiIter>
4834 inline _LIBCPP_INLINE_VISIBILITY
4836 operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4838 return !(__x < __y);
4841 template <class _BiIter>
4842 inline _LIBCPP_INLINE_VISIBILITY
4844 operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4849 template <class _BiIter, class _ST, class _SA>
4850 inline _LIBCPP_INLINE_VISIBILITY
4852 operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4853 const sub_match<_BiIter>& __y)
4855 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
4858 template <class _BiIter, class _ST, class _SA>
4859 inline _LIBCPP_INLINE_VISIBILITY
4861 operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4862 const sub_match<_BiIter>& __y)
4864 return !(__x == __y);
4867 template <class _BiIter, class _ST, class _SA>
4868 inline _LIBCPP_INLINE_VISIBILITY
4870 operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4871 const sub_match<_BiIter>& __y)
4873 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
4876 template <class _BiIter, class _ST, class _SA>
4877 inline _LIBCPP_INLINE_VISIBILITY
4879 operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4880 const sub_match<_BiIter>& __y)
4885 template <class _BiIter, class _ST, class _SA>
4886 inline _LIBCPP_INLINE_VISIBILITY
4887 bool 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 < __x);
4902 template <class _BiIter, class _ST, class _SA>
4903 inline _LIBCPP_INLINE_VISIBILITY
4905 operator==(const sub_match<_BiIter>& __x,
4906 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4908 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
4911 template <class _BiIter, class _ST, class _SA>
4912 inline _LIBCPP_INLINE_VISIBILITY
4914 operator!=(const sub_match<_BiIter>& __x,
4915 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4917 return !(__x == __y);
4920 template <class _BiIter, class _ST, class _SA>
4921 inline _LIBCPP_INLINE_VISIBILITY
4923 operator<(const sub_match<_BiIter>& __x,
4924 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4926 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
4929 template <class _BiIter, class _ST, class _SA>
4930 inline _LIBCPP_INLINE_VISIBILITY
4931 bool operator>(const sub_match<_BiIter>& __x,
4932 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
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 !(__y < __x);
4955 template <class _BiIter>
4956 inline _LIBCPP_INLINE_VISIBILITY
4958 operator==(typename iterator_traits<_BiIter>::value_type const* __x,
4959 const sub_match<_BiIter>& __y)
4961 return __y.compare(__x) == 0;
4964 template <class _BiIter>
4965 inline _LIBCPP_INLINE_VISIBILITY
4967 operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
4968 const sub_match<_BiIter>& __y)
4970 return !(__x == __y);
4973 template <class _BiIter>
4974 inline _LIBCPP_INLINE_VISIBILITY
4976 operator<(typename iterator_traits<_BiIter>::value_type const* __x,
4977 const sub_match<_BiIter>& __y)
4979 return __y.compare(__x) > 0;
4982 template <class _BiIter>
4983 inline _LIBCPP_INLINE_VISIBILITY
4985 operator>(typename iterator_traits<_BiIter>::value_type const* __x,
4986 const sub_match<_BiIter>& __y)
4991 template <class _BiIter>
4992 inline _LIBCPP_INLINE_VISIBILITY
4994 operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
4995 const sub_match<_BiIter>& __y)
4997 return !(__x < __y);
5000 template <class _BiIter>
5001 inline _LIBCPP_INLINE_VISIBILITY
5003 operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
5004 const sub_match<_BiIter>& __y)
5006 return !(__y < __x);
5009 template <class _BiIter>
5010 inline _LIBCPP_INLINE_VISIBILITY
5012 operator==(const sub_match<_BiIter>& __x,
5013 typename iterator_traits<_BiIter>::value_type const* __y)
5015 return __x.compare(__y) == 0;
5018 template <class _BiIter>
5019 inline _LIBCPP_INLINE_VISIBILITY
5021 operator!=(const sub_match<_BiIter>& __x,
5022 typename iterator_traits<_BiIter>::value_type const* __y)
5024 return !(__x == __y);
5027 template <class _BiIter>
5028 inline _LIBCPP_INLINE_VISIBILITY
5030 operator<(const sub_match<_BiIter>& __x,
5031 typename iterator_traits<_BiIter>::value_type const* __y)
5033 return __x.compare(__y) < 0;
5036 template <class _BiIter>
5037 inline _LIBCPP_INLINE_VISIBILITY
5039 operator>(const sub_match<_BiIter>& __x,
5040 typename iterator_traits<_BiIter>::value_type const* __y)
5045 template <class _BiIter>
5046 inline _LIBCPP_INLINE_VISIBILITY
5048 operator>=(const sub_match<_BiIter>& __x,
5049 typename iterator_traits<_BiIter>::value_type const* __y)
5051 return !(__x < __y);
5054 template <class _BiIter>
5055 inline _LIBCPP_INLINE_VISIBILITY
5057 operator<=(const sub_match<_BiIter>& __x,
5058 typename iterator_traits<_BiIter>::value_type const* __y)
5060 return !(__y < __x);
5063 template <class _BiIter>
5064 inline _LIBCPP_INLINE_VISIBILITY
5066 operator==(typename iterator_traits<_BiIter>::value_type const& __x,
5067 const sub_match<_BiIter>& __y)
5069 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5070 return __y.compare(string_type(1, __x)) == 0;
5073 template <class _BiIter>
5074 inline _LIBCPP_INLINE_VISIBILITY
5076 operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
5077 const sub_match<_BiIter>& __y)
5079 return !(__x == __y);
5082 template <class _BiIter>
5083 inline _LIBCPP_INLINE_VISIBILITY
5085 operator<(typename iterator_traits<_BiIter>::value_type const& __x,
5086 const sub_match<_BiIter>& __y)
5088 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5089 return __y.compare(string_type(1, __x)) > 0;
5092 template <class _BiIter>
5093 inline _LIBCPP_INLINE_VISIBILITY
5095 operator>(typename iterator_traits<_BiIter>::value_type const& __x,
5096 const sub_match<_BiIter>& __y)
5101 template <class _BiIter>
5102 inline _LIBCPP_INLINE_VISIBILITY
5104 operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
5105 const sub_match<_BiIter>& __y)
5107 return !(__x < __y);
5110 template <class _BiIter>
5111 inline _LIBCPP_INLINE_VISIBILITY
5113 operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
5114 const sub_match<_BiIter>& __y)
5116 return !(__y < __x);
5119 template <class _BiIter>
5120 inline _LIBCPP_INLINE_VISIBILITY
5122 operator==(const sub_match<_BiIter>& __x,
5123 typename iterator_traits<_BiIter>::value_type const& __y)
5125 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5126 return __x.compare(string_type(1, __y)) == 0;
5129 template <class _BiIter>
5130 inline _LIBCPP_INLINE_VISIBILITY
5132 operator!=(const sub_match<_BiIter>& __x,
5133 typename iterator_traits<_BiIter>::value_type const& __y)
5135 return !(__x == __y);
5138 template <class _BiIter>
5139 inline _LIBCPP_INLINE_VISIBILITY
5141 operator<(const sub_match<_BiIter>& __x,
5142 typename iterator_traits<_BiIter>::value_type const& __y)
5144 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5145 return __x.compare(string_type(1, __y)) < 0;
5148 template <class _BiIter>
5149 inline _LIBCPP_INLINE_VISIBILITY
5151 operator>(const sub_match<_BiIter>& __x,
5152 typename iterator_traits<_BiIter>::value_type const& __y)
5157 template <class _BiIter>
5158 inline _LIBCPP_INLINE_VISIBILITY
5160 operator>=(const sub_match<_BiIter>& __x,
5161 typename iterator_traits<_BiIter>::value_type const& __y)
5163 return !(__x < __y);
5166 template <class _BiIter>
5167 inline _LIBCPP_INLINE_VISIBILITY
5169 operator<=(const sub_match<_BiIter>& __x,
5170 typename iterator_traits<_BiIter>::value_type const& __y)
5172 return !(__y < __x);
5175 template <class _CharT, class _ST, class _BiIter>
5176 inline _LIBCPP_INLINE_VISIBILITY
5177 basic_ostream<_CharT, _ST>&
5178 operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
5180 return __os << __m.str();
5183 template <class _BidirectionalIterator, class _Allocator>
5184 class _LIBCPP_TYPE_VIS_ONLY match_results
5187 typedef _Allocator allocator_type;
5188 typedef sub_match<_BidirectionalIterator> value_type;
5190 typedef vector<value_type, allocator_type> __container_type;
5192 __container_type __matches_;
5193 value_type __unmatched_;
5194 value_type __prefix_;
5195 value_type __suffix_;
5198 _BidirectionalIterator __position_start_;
5199 typedef const value_type& const_reference;
5200 typedef value_type& reference;
5201 typedef typename __container_type::const_iterator const_iterator;
5202 typedef const_iterator iterator;
5203 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
5204 typedef typename allocator_traits<allocator_type>::size_type size_type;
5205 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
5206 typedef basic_string<char_type> string_type;
5208 // construct/copy/destroy:
5209 explicit match_results(const allocator_type& __a = allocator_type());
5210 // match_results(const match_results&) = default;
5211 // match_results& operator=(const match_results&) = default;
5212 // match_results(match_results&& __m) = default;
5213 // match_results& operator=(match_results&& __m) = default;
5214 // ~match_results() = default;
5216 _LIBCPP_INLINE_VISIBILITY
5217 bool ready() const {return __ready_;}
5220 _LIBCPP_INLINE_VISIBILITY
5221 size_type size() const {return __matches_.size();}
5222 _LIBCPP_INLINE_VISIBILITY
5223 size_type max_size() const {return __matches_.max_size();}
5224 _LIBCPP_INLINE_VISIBILITY
5225 bool empty() const {return size() == 0;}
5228 _LIBCPP_INLINE_VISIBILITY
5229 difference_type length(size_type __sub = 0) const
5230 {return (*this)[__sub].length();}
5231 _LIBCPP_INLINE_VISIBILITY
5232 difference_type position(size_type __sub = 0) const
5233 {return _VSTD::distance(__position_start_, (*this)[__sub].first);}
5234 _LIBCPP_INLINE_VISIBILITY
5235 string_type str(size_type __sub = 0) const
5236 {return (*this)[__sub].str();}
5237 _LIBCPP_INLINE_VISIBILITY
5238 const_reference operator[](size_type __n) const
5239 {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
5241 _LIBCPP_INLINE_VISIBILITY
5242 const_reference prefix() const {return __prefix_;}
5243 _LIBCPP_INLINE_VISIBILITY
5244 const_reference suffix() const {return __suffix_;}
5246 _LIBCPP_INLINE_VISIBILITY
5247 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();}
5248 _LIBCPP_INLINE_VISIBILITY
5249 const_iterator end() const {return __matches_.end();}
5250 _LIBCPP_INLINE_VISIBILITY
5251 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();}
5252 _LIBCPP_INLINE_VISIBILITY
5253 const_iterator cend() const {return __matches_.end();}
5256 template <class _OutputIter>
5258 format(_OutputIter __out, const char_type* __fmt_first,
5259 const char_type* __fmt_last,
5260 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
5261 template <class _OutputIter, class _ST, class _SA>
5262 _LIBCPP_INLINE_VISIBILITY
5264 format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt,
5265 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5266 {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
5267 template <class _ST, class _SA>
5268 _LIBCPP_INLINE_VISIBILITY
5269 basic_string<char_type, _ST, _SA>
5270 format(const basic_string<char_type, _ST, _SA>& __fmt,
5271 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5273 basic_string<char_type, _ST, _SA> __r;
5274 format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
5278 _LIBCPP_INLINE_VISIBILITY
5280 format(const char_type* __fmt,
5281 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5284 format(back_inserter(__r), __fmt,
5285 __fmt + char_traits<char_type>::length(__fmt), __flags);
5290 _LIBCPP_INLINE_VISIBILITY
5291 allocator_type get_allocator() const {return __matches_.get_allocator();}
5294 void swap(match_results& __m);
5296 template <class _Bp, class _Ap>
5297 _LIBCPP_INLINE_VISIBILITY
5298 void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
5299 const match_results<_Bp, _Ap>& __m, bool __no_update_pos)
5301 _Bp __mf = __m.prefix().first;
5302 __matches_.resize(__m.size());
5303 for (size_type __i = 0; __i < __matches_.size(); ++__i)
5305 __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first));
5306 __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second));
5307 __matches_[__i].matched = __m[__i].matched;
5309 __unmatched_.first = __l;
5310 __unmatched_.second = __l;
5311 __unmatched_.matched = false;
5312 __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first));
5313 __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second));
5314 __prefix_.matched = __m.prefix().matched;
5315 __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first));
5316 __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second));
5317 __suffix_.matched = __m.suffix().matched;
5318 if (!__no_update_pos)
5319 __position_start_ = __prefix_.first;
5320 __ready_ = __m.ready();
5324 void __init(unsigned __s,
5325 _BidirectionalIterator __f, _BidirectionalIterator __l,
5326 bool __no_update_pos = false);
5328 template <class, class> friend class basic_regex;
5330 template <class _Bp, class _Ap, class _Cp, class _Tp>
5333 regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
5334 regex_constants::match_flag_type);
5336 template <class _Bp, class _Ap>
5339 operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
5341 template <class, class> friend class __lookahead;
5344 template <class _BidirectionalIterator, class _Allocator>
5345 match_results<_BidirectionalIterator, _Allocator>::match_results(
5346 const allocator_type& __a)
5356 template <class _BidirectionalIterator, class _Allocator>
5358 match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
5359 _BidirectionalIterator __f, _BidirectionalIterator __l,
5360 bool __no_update_pos)
5362 __unmatched_.first = __l;
5363 __unmatched_.second = __l;
5364 __unmatched_.matched = false;
5365 __matches_.assign(__s, __unmatched_);
5366 __prefix_.first = __f;
5367 __prefix_.second = __f;
5368 __prefix_.matched = false;
5369 __suffix_ = __unmatched_;
5370 if (!__no_update_pos)
5371 __position_start_ = __prefix_.first;
5375 template <class _BidirectionalIterator, class _Allocator>
5376 template <class _OutputIter>
5378 match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
5379 const char_type* __fmt_first, const char_type* __fmt_last,
5380 regex_constants::match_flag_type __flags) const
5382 if (__flags & regex_constants::format_sed)
5384 for (; __fmt_first != __fmt_last; ++__fmt_first)
5386 if (*__fmt_first == '&')
5387 __out = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5389 else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
5392 if ('0' <= *__fmt_first && *__fmt_first <= '9')
5394 size_t __i = *__fmt_first - '0';
5395 __out = _VSTD::copy((*this)[__i].first,
5396 (*this)[__i].second, __out);
5400 *__out = *__fmt_first;
5406 *__out = *__fmt_first;
5413 for (; __fmt_first != __fmt_last; ++__fmt_first)
5415 if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
5417 switch (__fmt_first[1])
5420 *__out = *++__fmt_first;
5425 __out = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5430 __out = _VSTD::copy(__prefix_.first, __prefix_.second, __out);
5434 __out = _VSTD::copy(__suffix_.first, __suffix_.second, __out);
5437 if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5440 size_t __i = *__fmt_first - '0';
5441 if (__fmt_first + 1 != __fmt_last &&
5442 '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5445 __i = 10 * __i + *__fmt_first - '0';
5447 __out = _VSTD::copy((*this)[__i].first,
5448 (*this)[__i].second, __out);
5452 *__out = *__fmt_first;
5460 *__out = *__fmt_first;
5468 template <class _BidirectionalIterator, class _Allocator>
5470 match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
5473 swap(__matches_, __m.__matches_);
5474 swap(__unmatched_, __m.__unmatched_);
5475 swap(__prefix_, __m.__prefix_);
5476 swap(__suffix_, __m.__suffix_);
5477 swap(__position_start_, __m.__position_start_);
5478 swap(__ready_, __m.__ready_);
5481 typedef match_results<const char*> cmatch;
5482 typedef match_results<const wchar_t*> wcmatch;
5483 typedef match_results<string::const_iterator> smatch;
5484 typedef match_results<wstring::const_iterator> wsmatch;
5486 template <class _BidirectionalIterator, class _Allocator>
5488 operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
5489 const match_results<_BidirectionalIterator, _Allocator>& __y)
5491 if (__x.__ready_ != __y.__ready_)
5495 return __x.__matches_ == __y.__matches_ &&
5496 __x.__prefix_ == __y.__prefix_ &&
5497 __x.__suffix_ == __y.__suffix_;
5500 template <class _BidirectionalIterator, class _Allocator>
5501 inline _LIBCPP_INLINE_VISIBILITY
5503 operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
5504 const match_results<_BidirectionalIterator, _Allocator>& __y)
5506 return !(__x == __y);
5509 template <class _BidirectionalIterator, class _Allocator>
5510 inline _LIBCPP_INLINE_VISIBILITY
5512 swap(match_results<_BidirectionalIterator, _Allocator>& __x,
5513 match_results<_BidirectionalIterator, _Allocator>& __y)
5520 template <class _CharT, class _Traits>
5521 template <class _Allocator>
5523 basic_regex<_CharT, _Traits>::__match_at_start_ecma(
5524 const _CharT* __first, const _CharT* __last,
5525 match_results<const _CharT*, _Allocator>& __m,
5526 regex_constants::match_flag_type __flags, bool __at_first) const
5528 vector<__state> __states;
5529 __node* __st = __start_.get();
5532 sub_match<const _CharT*> __unmatched;
5533 __unmatched.first = __last;
5534 __unmatched.second = __last;
5535 __unmatched.matched = false;
5537 __states.push_back(__state());
5538 __states.back().__do_ = 0;
5539 __states.back().__first_ = __first;
5540 __states.back().__current_ = __first;
5541 __states.back().__last_ = __last;
5542 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
5543 __states.back().__loop_data_.resize(__loop_count());
5544 __states.back().__node_ = __st;
5545 __states.back().__flags_ = __flags;
5546 __states.back().__at_first_ = __at_first;
5549 __state& __s = __states.back();
5551 __s.__node_->__exec(__s);
5554 case __state::__end_state:
5555 __m.__matches_[0].first = __first;
5556 __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
5557 __m.__matches_[0].matched = true;
5558 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
5559 __m.__matches_[__i+1] = __s.__sub_matches_[__i];
5561 case __state::__accept_and_consume:
5562 case __state::__repeat:
5563 case __state::__accept_but_not_consume:
5565 case __state::__split:
5567 __state __snext = __s;
5568 __s.__node_->__exec_split(true, __s);
5569 __snext.__node_->__exec_split(false, __snext);
5570 __states.push_back(_VSTD::move(__snext));
5573 case __state::__reject:
5574 __states.pop_back();
5577 __throw_regex_error<regex_constants::__re_err_unknown>();
5581 } while (!__states.empty());
5586 template <class _CharT, class _Traits>
5587 template <class _Allocator>
5589 basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
5590 const _CharT* __first, const _CharT* __last,
5591 match_results<const _CharT*, _Allocator>& __m,
5592 regex_constants::match_flag_type __flags, bool __at_first) const
5594 deque<__state> __states;
5595 ptrdiff_t __highest_j = 0;
5596 ptrdiff_t _Np = _VSTD::distance(__first, __last);
5597 __node* __st = __start_.get();
5600 __states.push_back(__state());
5601 __states.back().__do_ = 0;
5602 __states.back().__first_ = __first;
5603 __states.back().__current_ = __first;
5604 __states.back().__last_ = __last;
5605 __states.back().__loop_data_.resize(__loop_count());
5606 __states.back().__node_ = __st;
5607 __states.back().__flags_ = __flags;
5608 __states.back().__at_first_ = __at_first;
5609 bool __matched = false;
5612 __state& __s = __states.back();
5614 __s.__node_->__exec(__s);
5617 case __state::__end_state:
5618 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
5619 __highest_j = __s.__current_ - __s.__first_;
5621 if (__highest_j == _Np)
5624 __states.pop_back();
5626 case __state::__consume_input:
5628 case __state::__accept_and_consume:
5629 __states.push_front(_VSTD::move(__s));
5630 __states.pop_back();
5632 case __state::__repeat:
5633 case __state::__accept_but_not_consume:
5635 case __state::__split:
5637 __state __snext = __s;
5638 __s.__node_->__exec_split(true, __s);
5639 __snext.__node_->__exec_split(false, __snext);
5640 __states.push_back(_VSTD::move(__snext));
5643 case __state::__reject:
5644 __states.pop_back();
5647 __throw_regex_error<regex_constants::__re_err_unknown>();
5650 } while (!__states.empty());
5653 __m.__matches_[0].first = __first;
5654 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
5655 __m.__matches_[0].matched = true;
5662 template <class _CharT, class _Traits>
5663 template <class _Allocator>
5665 basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
5666 const _CharT* __first, const _CharT* __last,
5667 match_results<const _CharT*, _Allocator>& __m,
5668 regex_constants::match_flag_type __flags, bool __at_first) const
5670 vector<__state> __states;
5671 __state __best_state;
5673 ptrdiff_t __highest_j = 0;
5674 ptrdiff_t _Np = _VSTD::distance(__first, __last);
5675 __node* __st = __start_.get();
5678 sub_match<const _CharT*> __unmatched;
5679 __unmatched.first = __last;
5680 __unmatched.second = __last;
5681 __unmatched.matched = false;
5683 __states.push_back(__state());
5684 __states.back().__do_ = 0;
5685 __states.back().__first_ = __first;
5686 __states.back().__current_ = __first;
5687 __states.back().__last_ = __last;
5688 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
5689 __states.back().__loop_data_.resize(__loop_count());
5690 __states.back().__node_ = __st;
5691 __states.back().__flags_ = __flags;
5692 __states.back().__at_first_ = __at_first;
5693 const _CharT* __current = __first;
5694 bool __matched = false;
5697 __state& __s = __states.back();
5699 __s.__node_->__exec(__s);
5702 case __state::__end_state:
5703 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
5705 __highest_j = __s.__current_ - __s.__first_;
5709 if (__highest_j == _Np)
5712 __states.pop_back();
5714 case __state::__accept_and_consume:
5715 __j += __s.__current_ - __current;
5716 __current = __s.__current_;
5718 case __state::__repeat:
5719 case __state::__accept_but_not_consume:
5721 case __state::__split:
5723 __state __snext = __s;
5724 __s.__node_->__exec_split(true, __s);
5725 __snext.__node_->__exec_split(false, __snext);
5726 __states.push_back(_VSTD::move(__snext));
5729 case __state::__reject:
5730 __states.pop_back();
5733 __throw_regex_error<regex_constants::__re_err_unknown>();
5736 } while (!__states.empty());
5739 __m.__matches_[0].first = __first;
5740 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
5741 __m.__matches_[0].matched = true;
5742 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
5743 __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
5750 template <class _CharT, class _Traits>
5751 template <class _Allocator>
5753 basic_regex<_CharT, _Traits>::__match_at_start(
5754 const _CharT* __first, const _CharT* __last,
5755 match_results<const _CharT*, _Allocator>& __m,
5756 regex_constants::match_flag_type __flags, bool __at_first) const
5758 if ((__flags_ & 0x1F0) == ECMAScript)
5759 return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
5760 if (mark_count() == 0)
5761 return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
5762 return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
5765 template <class _CharT, class _Traits>
5766 template <class _Allocator>
5768 basic_regex<_CharT, _Traits>::__search(
5769 const _CharT* __first, const _CharT* __last,
5770 match_results<const _CharT*, _Allocator>& __m,
5771 regex_constants::match_flag_type __flags) const
5773 __m.__init(1 + mark_count(), __first, __last,
5774 __flags & regex_constants::__no_update_pos);
5775 if (__match_at_start(__first, __last, __m, __flags,
5776 !(__flags & regex_constants::__no_update_pos)))
5778 __m.__prefix_.second = __m[0].first;
5779 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5780 __m.__suffix_.first = __m[0].second;
5781 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5784 if (__first != __last && !(__flags & regex_constants::match_continuous))
5786 __flags |= regex_constants::match_prev_avail;
5787 for (++__first; __first != __last; ++__first)
5789 __m.__matches_.assign(__m.size(), __m.__unmatched_);
5790 if (__match_at_start(__first, __last, __m, __flags, false))
5792 __m.__prefix_.second = __m[0].first;
5793 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5794 __m.__suffix_.first = __m[0].second;
5795 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5798 __m.__matches_.assign(__m.size(), __m.__unmatched_);
5801 __m.__matches_.clear();
5805 template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5806 inline _LIBCPP_INLINE_VISIBILITY
5808 regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5809 match_results<_BidirectionalIterator, _Allocator>& __m,
5810 const basic_regex<_CharT, _Traits>& __e,
5811 regex_constants::match_flag_type __flags = regex_constants::match_default)
5813 int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
5814 basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last);
5815 match_results<const _CharT*> __mc;
5816 bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
5817 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
5821 template <class _Iter, class _Allocator, class _CharT, class _Traits>
5822 inline _LIBCPP_INLINE_VISIBILITY
5824 regex_search(__wrap_iter<_Iter> __first,
5825 __wrap_iter<_Iter> __last,
5826 match_results<__wrap_iter<_Iter>, _Allocator>& __m,
5827 const basic_regex<_CharT, _Traits>& __e,
5828 regex_constants::match_flag_type __flags = regex_constants::match_default)
5830 match_results<const _CharT*> __mc;
5831 bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
5832 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
5836 template <class _Allocator, class _CharT, class _Traits>
5837 inline _LIBCPP_INLINE_VISIBILITY
5839 regex_search(const _CharT* __first, const _CharT* __last,
5840 match_results<const _CharT*, _Allocator>& __m,
5841 const basic_regex<_CharT, _Traits>& __e,
5842 regex_constants::match_flag_type __flags = regex_constants::match_default)
5844 return __e.__search(__first, __last, __m, __flags);
5847 template <class _BidirectionalIterator, class _CharT, class _Traits>
5848 inline _LIBCPP_INLINE_VISIBILITY
5850 regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5851 const basic_regex<_CharT, _Traits>& __e,
5852 regex_constants::match_flag_type __flags = regex_constants::match_default)
5854 basic_string<_CharT> __s(__first, __last);
5855 match_results<const _CharT*> __mc;
5856 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5859 template <class _CharT, class _Traits>
5860 inline _LIBCPP_INLINE_VISIBILITY
5862 regex_search(const _CharT* __first, const _CharT* __last,
5863 const basic_regex<_CharT, _Traits>& __e,
5864 regex_constants::match_flag_type __flags = regex_constants::match_default)
5866 match_results<const _CharT*> __mc;
5867 return __e.__search(__first, __last, __mc, __flags);
5870 template <class _CharT, class _Allocator, class _Traits>
5871 inline _LIBCPP_INLINE_VISIBILITY
5873 regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5874 const basic_regex<_CharT, _Traits>& __e,
5875 regex_constants::match_flag_type __flags = regex_constants::match_default)
5877 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
5880 template <class _CharT, class _Traits>
5881 inline _LIBCPP_INLINE_VISIBILITY
5883 regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5884 regex_constants::match_flag_type __flags = regex_constants::match_default)
5886 match_results<const _CharT*> __m;
5887 return _VSTD::regex_search(__str, __m, __e, __flags);
5890 template <class _ST, class _SA, class _CharT, class _Traits>
5891 inline _LIBCPP_INLINE_VISIBILITY
5893 regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5894 const basic_regex<_CharT, _Traits>& __e,
5895 regex_constants::match_flag_type __flags = regex_constants::match_default)
5897 match_results<const _CharT*> __mc;
5898 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5901 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5902 inline _LIBCPP_INLINE_VISIBILITY
5904 regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5905 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5906 const basic_regex<_CharT, _Traits>& __e,
5907 regex_constants::match_flag_type __flags = regex_constants::match_default)
5909 match_results<const _CharT*> __mc;
5910 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5911 __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
5915 #if _LIBCPP_STD_VER > 11
5916 template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
5918 regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
5919 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
5920 const basic_regex<_Cp, _Tp>& __e,
5921 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5926 template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5928 regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5929 match_results<_BidirectionalIterator, _Allocator>& __m,
5930 const basic_regex<_CharT, _Traits>& __e,
5931 regex_constants::match_flag_type __flags = regex_constants::match_default)
5933 bool __r = _VSTD::regex_search(__first, __last, __m, __e,
5934 __flags | regex_constants::match_continuous);
5937 __r = !__m.suffix().matched;
5939 __m.__matches_.clear();
5944 template <class _BidirectionalIterator, class _CharT, class _Traits>
5945 inline _LIBCPP_INLINE_VISIBILITY
5947 regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5948 const basic_regex<_CharT, _Traits>& __e,
5949 regex_constants::match_flag_type __flags = regex_constants::match_default)
5951 match_results<_BidirectionalIterator> __m;
5952 return _VSTD::regex_match(__first, __last, __m, __e, __flags);
5955 template <class _CharT, class _Allocator, class _Traits>
5956 inline _LIBCPP_INLINE_VISIBILITY
5958 regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5959 const basic_regex<_CharT, _Traits>& __e,
5960 regex_constants::match_flag_type __flags = regex_constants::match_default)
5962 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
5965 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5966 inline _LIBCPP_INLINE_VISIBILITY
5968 regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5969 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5970 const basic_regex<_CharT, _Traits>& __e,
5971 regex_constants::match_flag_type __flags = regex_constants::match_default)
5973 return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
5976 #if _LIBCPP_STD_VER > 11
5977 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5978 inline _LIBCPP_INLINE_VISIBILITY
5980 regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
5981 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5982 const basic_regex<_CharT, _Traits>& __e,
5983 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5986 template <class _CharT, class _Traits>
5987 inline _LIBCPP_INLINE_VISIBILITY
5989 regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5990 regex_constants::match_flag_type __flags = regex_constants::match_default)
5992 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
5995 template <class _ST, class _SA, class _CharT, class _Traits>
5996 inline _LIBCPP_INLINE_VISIBILITY
5998 regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5999 const basic_regex<_CharT, _Traits>& __e,
6000 regex_constants::match_flag_type __flags = regex_constants::match_default)
6002 return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags);
6007 template <class _BidirectionalIterator,
6008 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6009 class _Traits = regex_traits<_CharT> >
6010 class _LIBCPP_TYPE_VIS_ONLY regex_iterator
6013 typedef basic_regex<_CharT, _Traits> regex_type;
6014 typedef match_results<_BidirectionalIterator> value_type;
6015 typedef ptrdiff_t difference_type;
6016 typedef const value_type* pointer;
6017 typedef const value_type& reference;
6018 typedef forward_iterator_tag iterator_category;
6021 _BidirectionalIterator __begin_;
6022 _BidirectionalIterator __end_;
6023 const regex_type* __pregex_;
6024 regex_constants::match_flag_type __flags_;
6025 value_type __match_;
6029 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6030 const regex_type& __re,
6031 regex_constants::match_flag_type __m
6032 = regex_constants::match_default);
6033 #if _LIBCPP_STD_VER > 11
6034 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6035 const regex_type&& __re,
6036 regex_constants::match_flag_type __m
6037 = regex_constants::match_default) = delete;
6040 bool operator==(const regex_iterator& __x) const;
6041 _LIBCPP_INLINE_VISIBILITY
6042 bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
6044 _LIBCPP_INLINE_VISIBILITY
6045 reference operator*() const {return __match_;}
6046 _LIBCPP_INLINE_VISIBILITY
6047 pointer operator->() const {return &__match_;}
6049 regex_iterator& operator++();
6050 _LIBCPP_INLINE_VISIBILITY
6051 regex_iterator operator++(int)
6053 regex_iterator __t(*this);
6059 template <class _BidirectionalIterator, class _CharT, class _Traits>
6060 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
6061 : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
6065 template <class _BidirectionalIterator, class _CharT, class _Traits>
6066 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6067 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6068 const regex_type& __re, regex_constants::match_flag_type __m)
6074 _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
6077 template <class _BidirectionalIterator, class _CharT, class _Traits>
6079 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6080 operator==(const regex_iterator& __x) const
6082 if (__match_.empty() && __x.__match_.empty())
6084 if (__match_.empty() || __x.__match_.empty())
6086 return __begin_ == __x.__begin_ &&
6087 __end_ == __x.__end_ &&
6088 __pregex_ == __x.__pregex_ &&
6089 __flags_ == __x.__flags_ &&
6090 __match_[0] == __x.__match_[0];
6093 template <class _BidirectionalIterator, class _CharT, class _Traits>
6094 regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
6095 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6097 __flags_ |= regex_constants::__no_update_pos;
6098 _BidirectionalIterator __start = __match_[0].second;
6099 if (__match_.empty())
6101 if (__start == __end_)
6103 __match_ = value_type();
6106 else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_,
6107 __flags_ | regex_constants::match_not_null |
6108 regex_constants::match_continuous))
6113 __flags_ |= regex_constants::match_prev_avail;
6114 if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
6115 __match_ = value_type();
6119 typedef regex_iterator<const char*> cregex_iterator;
6120 typedef regex_iterator<const wchar_t*> wcregex_iterator;
6121 typedef regex_iterator<string::const_iterator> sregex_iterator;
6122 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
6124 // regex_token_iterator
6126 template <class _BidirectionalIterator,
6127 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6128 class _Traits = regex_traits<_CharT> >
6129 class _LIBCPP_TYPE_VIS_ONLY regex_token_iterator
6132 typedef basic_regex<_CharT, _Traits> regex_type;
6133 typedef sub_match<_BidirectionalIterator> value_type;
6134 typedef ptrdiff_t difference_type;
6135 typedef const value_type* pointer;
6136 typedef const value_type& reference;
6137 typedef forward_iterator_tag iterator_category;
6140 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
6142 _Position __position_;
6143 const value_type* __result_;
6144 value_type __suffix_;
6146 vector<int> __subs_;
6149 regex_token_iterator();
6150 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6151 const regex_type& __re, int __submatch = 0,
6152 regex_constants::match_flag_type __m =
6153 regex_constants::match_default);
6154 #if _LIBCPP_STD_VER > 11
6155 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6156 const regex_type&& __re, int __submatch = 0,
6157 regex_constants::match_flag_type __m =
6158 regex_constants::match_default) = delete;
6161 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6162 const regex_type& __re, const vector<int>& __submatches,
6163 regex_constants::match_flag_type __m =
6164 regex_constants::match_default);
6165 #if _LIBCPP_STD_VER > 11
6166 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6167 const regex_type&& __re, const vector<int>& __submatches,
6168 regex_constants::match_flag_type __m =
6169 regex_constants::match_default) = delete;
6172 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6173 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6174 const regex_type& __re,
6175 initializer_list<int> __submatches,
6176 regex_constants::match_flag_type __m =
6177 regex_constants::match_default);
6179 #if _LIBCPP_STD_VER > 11
6180 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6181 const regex_type&& __re,
6182 initializer_list<int> __submatches,
6183 regex_constants::match_flag_type __m =
6184 regex_constants::match_default) = delete;
6186 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6187 template <size_t _Np>
6188 regex_token_iterator(_BidirectionalIterator __a,
6189 _BidirectionalIterator __b,
6190 const regex_type& __re,
6191 const int (&__submatches)[_Np],
6192 regex_constants::match_flag_type __m =
6193 regex_constants::match_default);
6194 #if _LIBCPP_STD_VER > 11
6195 template <std::size_t _Np>
6196 regex_token_iterator(_BidirectionalIterator __a,
6197 _BidirectionalIterator __b,
6198 const regex_type&& __re,
6199 const int (&__submatches)[_Np],
6200 regex_constants::match_flag_type __m =
6201 regex_constants::match_default) = delete;
6204 regex_token_iterator(const regex_token_iterator&);
6205 regex_token_iterator& operator=(const regex_token_iterator&);
6207 bool operator==(const regex_token_iterator& __x) const;
6208 _LIBCPP_INLINE_VISIBILITY
6209 bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
6211 _LIBCPP_INLINE_VISIBILITY
6212 const value_type& operator*() const {return *__result_;}
6213 _LIBCPP_INLINE_VISIBILITY
6214 const value_type* operator->() const {return __result_;}
6216 regex_token_iterator& operator++();
6217 _LIBCPP_INLINE_VISIBILITY
6218 regex_token_iterator operator++(int)
6220 regex_token_iterator __t(*this);
6226 void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
6227 void __establish_result () {
6228 if (__subs_[_N_] == -1)
6229 __result_ = &__position_->prefix();
6231 __result_ = &(*__position_)[__subs_[_N_]];
6235 template <class _BidirectionalIterator, class _CharT, class _Traits>
6236 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6237 regex_token_iterator()
6238 : __result_(nullptr),
6244 template <class _BidirectionalIterator, class _CharT, class _Traits>
6246 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6247 __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
6249 if (__position_ != _Position())
6250 __establish_result ();
6251 else if (__subs_[_N_] == -1)
6253 __suffix_.matched = true;
6254 __suffix_.first = __a;
6255 __suffix_.second = __b;
6256 __result_ = &__suffix_;
6259 __result_ = nullptr;
6262 template <class _BidirectionalIterator, class _CharT, class _Traits>
6263 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6264 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6265 const regex_type& __re, int __submatch,
6266 regex_constants::match_flag_type __m)
6267 : __position_(__a, __b, __re, __m),
6269 __subs_(1, __submatch)
6274 template <class _BidirectionalIterator, class _CharT, class _Traits>
6275 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6276 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6277 const regex_type& __re, const vector<int>& __submatches,
6278 regex_constants::match_flag_type __m)
6279 : __position_(__a, __b, __re, __m),
6281 __subs_(__submatches)
6286 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6288 template <class _BidirectionalIterator, class _CharT, class _Traits>
6289 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6290 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6291 const regex_type& __re,
6292 initializer_list<int> __submatches,
6293 regex_constants::match_flag_type __m)
6294 : __position_(__a, __b, __re, __m),
6296 __subs_(__submatches)
6301 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6303 template <class _BidirectionalIterator, class _CharT, class _Traits>
6304 template <size_t _Np>
6305 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6306 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6307 const regex_type& __re,
6308 const int (&__submatches)[_Np],
6309 regex_constants::match_flag_type __m)
6310 : __position_(__a, __b, __re, __m),
6312 __subs_(__submatches, __submatches + _Np)
6317 template <class _BidirectionalIterator, class _CharT, class _Traits>
6318 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6319 regex_token_iterator(const regex_token_iterator& __x)
6320 : __position_(__x.__position_),
6321 __result_(__x.__result_),
6322 __suffix_(__x.__suffix_),
6324 __subs_(__x.__subs_)
6326 if (__x.__result_ == &__x.__suffix_)
6327 __result_ = &__suffix_;
6328 else if ( __result_ != nullptr )
6329 __establish_result ();
6332 template <class _BidirectionalIterator, class _CharT, class _Traits>
6333 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6334 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6335 operator=(const regex_token_iterator& __x)
6339 __position_ = __x.__position_;
6340 if (__x.__result_ == &__x.__suffix_)
6341 __result_ = &__suffix_;
6343 __result_ = __x.__result_;
6344 __suffix_ = __x.__suffix_;
6346 __subs_ = __x.__subs_;
6348 if ( __result_ != nullptr && __result_ != &__suffix_ )
6349 __establish_result();
6354 template <class _BidirectionalIterator, class _CharT, class _Traits>
6356 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6357 operator==(const regex_token_iterator& __x) const
6359 if (__result_ == nullptr && __x.__result_ == nullptr)
6361 if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
6362 __suffix_ == __x.__suffix_)
6364 if (__result_ == nullptr || __x.__result_ == nullptr)
6366 if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
6368 return __position_ == __x.__position_ && _N_ == __x._N_ &&
6369 __subs_ == __x.__subs_;
6372 template <class _BidirectionalIterator, class _CharT, class _Traits>
6373 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6374 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6376 _Position __prev = __position_;
6377 if (__result_ == &__suffix_)
6378 __result_ = nullptr;
6379 else if (_N_ + 1 < __subs_.size())
6382 __establish_result();
6388 if (__position_ != _Position())
6389 __establish_result();
6392 if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
6393 && __prev->suffix().length() != 0)
6395 __suffix_.matched = true;
6396 __suffix_.first = __prev->suffix().first;
6397 __suffix_.second = __prev->suffix().second;
6398 __result_ = &__suffix_;
6401 __result_ = nullptr;
6407 typedef regex_token_iterator<const char*> cregex_token_iterator;
6408 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
6409 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
6410 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
6414 template <class _OutputIterator, class _BidirectionalIterator,
6415 class _Traits, class _CharT>
6417 regex_replace(_OutputIterator __out,
6418 _BidirectionalIterator __first, _BidirectionalIterator __last,
6419 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6420 regex_constants::match_flag_type __flags = regex_constants::match_default)
6422 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
6423 _Iter __i(__first, __last, __e, __flags);
6427 if (!(__flags & regex_constants::format_no_copy))
6428 __out = _VSTD::copy(__first, __last, __out);
6432 sub_match<_BidirectionalIterator> __lm;
6433 for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
6435 if (!(__flags & regex_constants::format_no_copy))
6436 __out = _VSTD::copy(__i->prefix().first, __i->prefix().second, __out);
6437 __out = __i->format(__out, __fmt, __fmt + __len, __flags);
6438 __lm = __i->suffix();
6439 if (__flags & regex_constants::format_first_only)
6442 if (!(__flags & regex_constants::format_no_copy))
6443 __out = _VSTD::copy(__lm.first, __lm.second, __out);
6448 template <class _OutputIterator, class _BidirectionalIterator,
6449 class _Traits, class _CharT, class _ST, class _SA>
6450 inline _LIBCPP_INLINE_VISIBILITY
6452 regex_replace(_OutputIterator __out,
6453 _BidirectionalIterator __first, _BidirectionalIterator __last,
6454 const basic_regex<_CharT, _Traits>& __e,
6455 const basic_string<_CharT, _ST, _SA>& __fmt,
6456 regex_constants::match_flag_type __flags = regex_constants::match_default)
6458 return _VSTD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
6461 template <class _Traits, class _CharT, class _ST, class _SA, class _FST,
6463 inline _LIBCPP_INLINE_VISIBILITY
6464 basic_string<_CharT, _ST, _SA>
6465 regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6466 const basic_regex<_CharT, _Traits>& __e,
6467 const basic_string<_CharT, _FST, _FSA>& __fmt,
6468 regex_constants::match_flag_type __flags = regex_constants::match_default)
6470 basic_string<_CharT, _ST, _SA> __r;
6471 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6472 __fmt.c_str(), __flags);
6476 template <class _Traits, class _CharT, class _ST, class _SA>
6477 inline _LIBCPP_INLINE_VISIBILITY
6478 basic_string<_CharT, _ST, _SA>
6479 regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6480 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6481 regex_constants::match_flag_type __flags = regex_constants::match_default)
6483 basic_string<_CharT, _ST, _SA> __r;
6484 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6489 template <class _Traits, class _CharT, class _ST, class _SA>
6490 inline _LIBCPP_INLINE_VISIBILITY
6491 basic_string<_CharT>
6492 regex_replace(const _CharT* __s,
6493 const basic_regex<_CharT, _Traits>& __e,
6494 const basic_string<_CharT, _ST, _SA>& __fmt,
6495 regex_constants::match_flag_type __flags = regex_constants::match_default)
6497 basic_string<_CharT> __r;
6498 _VSTD::regex_replace(back_inserter(__r), __s,
6499 __s + char_traits<_CharT>::length(__s), __e,
6500 __fmt.c_str(), __flags);
6504 template <class _Traits, class _CharT>
6505 inline _LIBCPP_INLINE_VISIBILITY
6506 basic_string<_CharT>
6507 regex_replace(const _CharT* __s,
6508 const basic_regex<_CharT, _Traits>& __e,
6509 const _CharT* __fmt,
6510 regex_constants::match_flag_type __flags = regex_constants::match_default)
6512 basic_string<_CharT> __r;
6513 _VSTD::regex_replace(back_inserter(__r), __s,
6514 __s + char_traits<_CharT>::length(__s), __e,
6519 _LIBCPP_END_NAMESPACE_STD
6521 #endif // _LIBCPP_REGEX