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 traits traits_type;
131 typedef typename traits::string_type string_type;
132 typedef regex_constants::syntax_option_type flag_type;
133 typedef typename traits::locale_type locale_type;
136 static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
137 static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
138 static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
139 static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
140 static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
141 static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
142 static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
143 static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
144 static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
145 static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
147 // construct/copy/destroy:
149 explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
150 basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
151 basic_regex(const basic_regex&);
152 basic_regex(basic_regex&&) noexcept;
153 template <class ST, class SA>
154 explicit basic_regex(const basic_string<charT, ST, SA>& p,
155 flag_type f = regex_constants::ECMAScript);
156 template <class ForwardIterator>
157 basic_regex(ForwardIterator first, ForwardIterator last,
158 flag_type f = regex_constants::ECMAScript);
159 basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
163 basic_regex& operator=(const basic_regex&);
164 basic_regex& operator=(basic_regex&&) noexcept;
165 basic_regex& operator=(const charT* ptr);
166 basic_regex& operator=(initializer_list<charT> il);
167 template <class ST, class SA>
168 basic_regex& operator=(const basic_string<charT, ST, SA>& p);
171 basic_regex& assign(const basic_regex& that);
172 basic_regex& assign(basic_regex&& that) noexcept;
173 basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
174 basic_regex& assign(const charT* p, size_t len, flag_type f);
175 template <class string_traits, class A>
176 basic_regex& assign(const basic_string<charT, string_traits, A>& s,
177 flag_type f = regex_constants::ECMAScript);
178 template <class InputIterator>
179 basic_regex& assign(InputIterator first, InputIterator last,
180 flag_type f = regex_constants::ECMAScript);
181 basic_regex& assign(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
184 unsigned mark_count() const;
185 flag_type flags() const;
188 locale_type imbue(locale_type loc);
189 locale_type getloc() const;
192 void swap(basic_regex&);
195 typedef basic_regex<char> regex;
196 typedef basic_regex<wchar_t> wregex;
198 template <class charT, class traits>
199 void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
201 template <class BidirectionalIterator>
203 : public pair<BidirectionalIterator, BidirectionalIterator>
206 typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
207 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
208 typedef BidirectionalIterator iterator;
209 typedef basic_string<value_type> string_type;
213 constexpr sub_match();
215 difference_type length() const;
216 operator string_type() const;
217 string_type str() const;
219 int compare(const sub_match& s) const;
220 int compare(const string_type& s) const;
221 int compare(const value_type* s) const;
224 typedef sub_match<const char*> csub_match;
225 typedef sub_match<const wchar_t*> wcsub_match;
226 typedef sub_match<string::const_iterator> ssub_match;
227 typedef sub_match<wstring::const_iterator> wssub_match;
229 template <class BiIter>
231 operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
233 template <class BiIter>
235 operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
237 template <class BiIter>
239 operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
241 template <class BiIter>
243 operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
245 template <class BiIter>
247 operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
249 template <class BiIter>
251 operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
253 template <class BiIter, class ST, class SA>
255 operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
256 const sub_match<BiIter>& rhs);
258 template <class BiIter, class ST, class SA>
260 operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
261 const sub_match<BiIter>& rhs);
263 template <class BiIter, class ST, class SA>
265 operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
266 const sub_match<BiIter>& rhs);
268 template <class BiIter, class ST, class SA>
270 operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
271 const sub_match<BiIter>& rhs);
273 template <class BiIter, class ST, class SA>
274 bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
275 const sub_match<BiIter>& rhs);
277 template <class BiIter, class ST, class SA>
279 operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
280 const sub_match<BiIter>& rhs);
282 template <class BiIter, class ST, class SA>
284 operator==(const sub_match<BiIter>& lhs,
285 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
287 template <class BiIter, class ST, class SA>
289 operator!=(const sub_match<BiIter>& lhs,
290 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
292 template <class BiIter, class ST, class SA>
294 operator<(const sub_match<BiIter>& lhs,
295 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
297 template <class BiIter, class ST, class SA>
298 bool operator>(const sub_match<BiIter>& lhs,
299 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
301 template <class BiIter, class ST, class SA>
303 operator>=(const sub_match<BiIter>& lhs,
304 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
306 template <class BiIter, class ST, class SA>
308 operator<=(const sub_match<BiIter>& lhs,
309 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
311 template <class BiIter>
313 operator==(typename iterator_traits<BiIter>::value_type const* lhs,
314 const sub_match<BiIter>& rhs);
316 template <class BiIter>
318 operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
319 const sub_match<BiIter>& rhs);
321 template <class BiIter>
323 operator<(typename iterator_traits<BiIter>::value_type const* lhs,
324 const sub_match<BiIter>& rhs);
326 template <class BiIter>
328 operator>(typename iterator_traits<BiIter>::value_type const* lhs,
329 const sub_match<BiIter>& rhs);
331 template <class BiIter>
333 operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
334 const sub_match<BiIter>& rhs);
336 template <class BiIter>
338 operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
339 const sub_match<BiIter>& rhs);
341 template <class BiIter>
343 operator==(const sub_match<BiIter>& lhs,
344 typename iterator_traits<BiIter>::value_type const* rhs);
346 template <class BiIter>
348 operator!=(const sub_match<BiIter>& lhs,
349 typename iterator_traits<BiIter>::value_type const* rhs);
351 template <class BiIter>
353 operator<(const sub_match<BiIter>& lhs,
354 typename iterator_traits<BiIter>::value_type const* rhs);
356 template <class BiIter>
358 operator>(const sub_match<BiIter>& lhs,
359 typename iterator_traits<BiIter>::value_type const* rhs);
361 template <class BiIter>
363 operator>=(const sub_match<BiIter>& lhs,
364 typename iterator_traits<BiIter>::value_type const* rhs);
366 template <class BiIter>
368 operator<=(const sub_match<BiIter>& lhs,
369 typename iterator_traits<BiIter>::value_type const* rhs);
371 template <class BiIter>
373 operator==(typename iterator_traits<BiIter>::value_type const& lhs,
374 const sub_match<BiIter>& rhs);
376 template <class BiIter>
378 operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
379 const sub_match<BiIter>& rhs);
381 template <class BiIter>
383 operator<(typename iterator_traits<BiIter>::value_type const& lhs,
384 const sub_match<BiIter>& rhs);
386 template <class BiIter>
388 operator>(typename iterator_traits<BiIter>::value_type const& lhs,
389 const sub_match<BiIter>& rhs);
391 template <class BiIter>
393 operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
394 const sub_match<BiIter>& rhs);
396 template <class BiIter>
398 operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
399 const sub_match<BiIter>& rhs);
401 template <class BiIter>
403 operator==(const sub_match<BiIter>& lhs,
404 typename iterator_traits<BiIter>::value_type const& rhs);
406 template <class BiIter>
408 operator!=(const sub_match<BiIter>& lhs,
409 typename iterator_traits<BiIter>::value_type const& rhs);
411 template <class BiIter>
413 operator<(const sub_match<BiIter>& lhs,
414 typename iterator_traits<BiIter>::value_type const& rhs);
416 template <class BiIter>
418 operator>(const sub_match<BiIter>& lhs,
419 typename iterator_traits<BiIter>::value_type const& rhs);
421 template <class BiIter>
423 operator>=(const sub_match<BiIter>& lhs,
424 typename iterator_traits<BiIter>::value_type const& rhs);
426 template <class BiIter>
428 operator<=(const sub_match<BiIter>& lhs,
429 typename iterator_traits<BiIter>::value_type const& rhs);
431 template <class charT, class ST, class BiIter>
432 basic_ostream<charT, ST>&
433 operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
435 template <class BidirectionalIterator,
436 class Allocator = allocator<sub_match<BidirectionalIterator>>>
440 typedef sub_match<BidirectionalIterator> value_type;
441 typedef const value_type& const_reference;
442 typedef value_type& reference;
443 typedef /implementation-defined/ const_iterator;
444 typedef const_iterator iterator;
445 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
446 typedef typename allocator_traits<Allocator>::size_type size_type;
447 typedef Allocator allocator_type;
448 typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
449 typedef basic_string<char_type> string_type;
451 // construct/copy/destroy:
452 explicit match_results(const Allocator& a = Allocator());
453 match_results(const match_results& m);
454 match_results(match_results&& m) noexcept;
455 match_results& operator=(const match_results& m);
456 match_results& operator=(match_results&& m);
462 size_type size() const;
463 size_type max_size() const;
467 difference_type length(size_type sub = 0) const;
468 difference_type position(size_type sub = 0) const;
469 string_type str(size_type sub = 0) const;
470 const_reference operator[](size_type n) const;
472 const_reference prefix() const;
473 const_reference suffix() const;
475 const_iterator begin() const;
476 const_iterator end() const;
477 const_iterator cbegin() const;
478 const_iterator cend() const;
481 template <class OutputIter>
483 format(OutputIter out, const char_type* fmt_first,
484 const char_type* fmt_last,
485 regex_constants::match_flag_type flags = regex_constants::format_default) const;
486 template <class OutputIter, class ST, class SA>
488 format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
489 regex_constants::match_flag_type flags = regex_constants::format_default) const;
490 template <class ST, class SA>
491 basic_string<char_type, ST, SA>
492 format(const basic_string<char_type, ST, SA>& fmt,
493 regex_constants::match_flag_type flags = regex_constants::format_default) const;
495 format(const char_type* fmt,
496 regex_constants::match_flag_type flags = regex_constants::format_default) const;
499 allocator_type get_allocator() const;
502 void swap(match_results& that);
505 typedef match_results<const char*> cmatch;
506 typedef match_results<const wchar_t*> wcmatch;
507 typedef match_results<string::const_iterator> smatch;
508 typedef match_results<wstring::const_iterator> wsmatch;
510 template <class BidirectionalIterator, class Allocator>
512 operator==(const match_results<BidirectionalIterator, Allocator>& m1,
513 const match_results<BidirectionalIterator, Allocator>& m2);
515 template <class BidirectionalIterator, class Allocator>
517 operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
518 const match_results<BidirectionalIterator, Allocator>& m2);
520 template <class BidirectionalIterator, class Allocator>
522 swap(match_results<BidirectionalIterator, Allocator>& m1,
523 match_results<BidirectionalIterator, Allocator>& m2);
525 template <class BidirectionalIterator, class Allocator, class charT, class traits>
527 regex_match(BidirectionalIterator first, BidirectionalIterator last,
528 match_results<BidirectionalIterator, Allocator>& m,
529 const basic_regex<charT, traits>& e,
530 regex_constants::match_flag_type flags = regex_constants::match_default);
532 template <class BidirectionalIterator, class charT, class traits>
534 regex_match(BidirectionalIterator first, BidirectionalIterator last,
535 const basic_regex<charT, traits>& e,
536 regex_constants::match_flag_type flags = regex_constants::match_default);
538 template <class charT, class Allocator, class traits>
540 regex_match(const charT* str, match_results<const charT*, Allocator>& m,
541 const basic_regex<charT, traits>& e,
542 regex_constants::match_flag_type flags = regex_constants::match_default);
544 template <class ST, class SA, class Allocator, class charT, class traits>
546 regex_match(const basic_string<charT, ST, SA>& s,
547 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
548 const basic_regex<charT, traits>& e,
549 regex_constants::match_flag_type flags = regex_constants::match_default);
551 template <class ST, class SA, class Allocator, class charT, class traits>
553 regex_match(const basic_string<charT, ST, SA>&& s,
554 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
555 const basic_regex<charT, traits>& e,
556 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
558 template <class charT, class traits>
560 regex_match(const charT* str, const basic_regex<charT, traits>& e,
561 regex_constants::match_flag_type flags = regex_constants::match_default);
563 template <class ST, class SA, class charT, class traits>
565 regex_match(const basic_string<charT, ST, SA>& s,
566 const basic_regex<charT, traits>& e,
567 regex_constants::match_flag_type flags = regex_constants::match_default);
569 template <class BidirectionalIterator, class Allocator, class charT, class traits>
571 regex_search(BidirectionalIterator first, BidirectionalIterator last,
572 match_results<BidirectionalIterator, Allocator>& m,
573 const basic_regex<charT, traits>& e,
574 regex_constants::match_flag_type flags = regex_constants::match_default);
576 template <class BidirectionalIterator, class charT, class traits>
578 regex_search(BidirectionalIterator first, BidirectionalIterator last,
579 const basic_regex<charT, traits>& e,
580 regex_constants::match_flag_type flags = regex_constants::match_default);
582 template <class charT, class Allocator, class traits>
584 regex_search(const charT* str, match_results<const charT*, Allocator>& m,
585 const basic_regex<charT, traits>& e,
586 regex_constants::match_flag_type flags = regex_constants::match_default);
588 template <class charT, class traits>
590 regex_search(const charT* str, const basic_regex<charT, traits>& e,
591 regex_constants::match_flag_type flags = regex_constants::match_default);
593 template <class ST, class SA, class charT, class traits>
595 regex_search(const basic_string<charT, ST, SA>& s,
596 const basic_regex<charT, traits>& e,
597 regex_constants::match_flag_type flags = regex_constants::match_default);
599 template <class ST, class SA, class Allocator, class charT, class traits>
601 regex_search(const basic_string<charT, ST, SA>& s,
602 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
603 const basic_regex<charT, traits>& e,
604 regex_constants::match_flag_type flags = regex_constants::match_default);
606 template <class ST, class SA, class Allocator, class charT, class traits>
608 regex_search(const basic_string<charT, ST, SA>&& s,
609 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
610 const basic_regex<charT, traits>& e,
611 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
613 template <class OutputIterator, class BidirectionalIterator,
614 class traits, class charT, class ST, class SA>
616 regex_replace(OutputIterator out,
617 BidirectionalIterator first, BidirectionalIterator last,
618 const basic_regex<charT, traits>& e,
619 const basic_string<charT, ST, SA>& fmt,
620 regex_constants::match_flag_type flags = regex_constants::match_default);
622 template <class OutputIterator, class BidirectionalIterator,
623 class traits, class charT>
625 regex_replace(OutputIterator out,
626 BidirectionalIterator first, BidirectionalIterator last,
627 const basic_regex<charT, traits>& e, const charT* fmt,
628 regex_constants::match_flag_type flags = regex_constants::match_default);
630 template <class traits, class charT, class ST, class SA, class FST, class FSA>>
631 basic_string<charT, ST, SA>
632 regex_replace(const basic_string<charT, ST, SA>& s,
633 const basic_regex<charT, traits>& e,
634 const basic_string<charT, FST, FSA>& fmt,
635 regex_constants::match_flag_type flags = regex_constants::match_default);
637 template <class traits, class charT, class ST, class SA>
638 basic_string<charT, ST, SA>
639 regex_replace(const basic_string<charT, ST, SA>& s,
640 const basic_regex<charT, traits>& e, const charT* fmt,
641 regex_constants::match_flag_type flags = regex_constants::match_default);
643 template <class traits, class charT, class ST, class SA>
645 regex_replace(const charT* s,
646 const basic_regex<charT, traits>& e,
647 const basic_string<charT, ST, SA>& fmt,
648 regex_constants::match_flag_type flags = regex_constants::match_default);
650 template <class traits, class charT>
652 regex_replace(const charT* s,
653 const basic_regex<charT, traits>& e,
655 regex_constants::match_flag_type flags = regex_constants::match_default);
657 template <class BidirectionalIterator,
658 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
659 class traits = regex_traits<charT>>
663 typedef basic_regex<charT, traits> regex_type;
664 typedef match_results<BidirectionalIterator> value_type;
665 typedef ptrdiff_t difference_type;
666 typedef const value_type* pointer;
667 typedef const value_type& reference;
668 typedef forward_iterator_tag iterator_category;
671 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
672 const regex_type& re,
673 regex_constants::match_flag_type m = regex_constants::match_default);
674 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
675 const regex_type&& __re,
676 regex_constants::match_flag_type __m
677 = regex_constants::match_default) = delete; // C++14
678 regex_iterator(const regex_iterator&);
679 regex_iterator& operator=(const regex_iterator&);
681 bool operator==(const regex_iterator&) const;
682 bool operator!=(const regex_iterator&) const;
684 const value_type& operator*() const;
685 const value_type* operator->() const;
687 regex_iterator& operator++();
688 regex_iterator operator++(int);
691 typedef regex_iterator<const char*> cregex_iterator;
692 typedef regex_iterator<const wchar_t*> wcregex_iterator;
693 typedef regex_iterator<string::const_iterator> sregex_iterator;
694 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
696 template <class BidirectionalIterator,
697 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
698 class traits = regex_traits<charT>>
699 class regex_token_iterator
702 typedef basic_regex<charT, traits> regex_type;
703 typedef sub_match<BidirectionalIterator> value_type;
704 typedef ptrdiff_t difference_type;
705 typedef const value_type* pointer;
706 typedef const value_type& reference;
707 typedef forward_iterator_tag iterator_category;
709 regex_token_iterator();
710 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
711 const regex_type& re, int submatch = 0,
712 regex_constants::match_flag_type m = regex_constants::match_default);
713 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
714 const regex_type&& re, int submatch = 0,
715 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
716 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
717 const regex_type& re, const vector<int>& submatches,
718 regex_constants::match_flag_type m = regex_constants::match_default);
719 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
720 const regex_type&& re, const vector<int>& submatches,
721 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
722 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
723 const regex_type& re, initializer_list<int> submatches,
724 regex_constants::match_flag_type m = regex_constants::match_default);
725 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
726 const regex_type&& re, initializer_list<int> submatches,
727 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
729 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
730 const regex_type& re, const int (&submatches)[N],
731 regex_constants::match_flag_type m = regex_constants::match_default);
733 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
734 const regex_type& re, const int (&submatches)[N],
735 regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14;
736 regex_token_iterator(const regex_token_iterator&);
737 regex_token_iterator& operator=(const regex_token_iterator&);
739 bool operator==(const regex_token_iterator&) const;
740 bool operator!=(const regex_token_iterator&) const;
742 const value_type& operator*() const;
743 const value_type* operator->() const;
745 regex_token_iterator& operator++();
746 regex_token_iterator operator++(int);
749 typedef regex_token_iterator<const char*> cregex_token_iterator;
750 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
751 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
752 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
760 #include <initializer_list>
768 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
769 #pragma GCC system_header
773 #include <__undef_macros>
776 _LIBCPP_BEGIN_NAMESPACE_STD
778 namespace regex_constants
781 // syntax_option_type
783 enum syntax_option_type
797 inline _LIBCPP_INLINE_VISIBILITY
800 operator~(syntax_option_type __x)
802 return syntax_option_type(~int(__x) & 0x1FF);
805 inline _LIBCPP_INLINE_VISIBILITY
808 operator&(syntax_option_type __x, syntax_option_type __y)
810 return syntax_option_type(int(__x) & int(__y));
813 inline _LIBCPP_INLINE_VISIBILITY
816 operator|(syntax_option_type __x, syntax_option_type __y)
818 return syntax_option_type(int(__x) | int(__y));
821 inline _LIBCPP_INLINE_VISIBILITY
824 operator^(syntax_option_type __x, syntax_option_type __y)
826 return syntax_option_type(int(__x) ^ int(__y));
829 inline _LIBCPP_INLINE_VISIBILITY
831 operator&=(syntax_option_type& __x, syntax_option_type __y)
837 inline _LIBCPP_INLINE_VISIBILITY
839 operator|=(syntax_option_type& __x, syntax_option_type __y)
845 inline _LIBCPP_INLINE_VISIBILITY
847 operator^=(syntax_option_type& __x, syntax_option_type __y)
858 match_not_bol = 1 << 0,
859 match_not_eol = 1 << 1,
860 match_not_bow = 1 << 2,
861 match_not_eow = 1 << 3,
863 match_not_null = 1 << 5,
864 match_continuous = 1 << 6,
865 match_prev_avail = 1 << 7,
868 format_no_copy = 1 << 9,
869 format_first_only = 1 << 10,
870 __no_update_pos = 1 << 11,
871 __full_match = 1 << 12
874 inline _LIBCPP_INLINE_VISIBILITY
877 operator~(match_flag_type __x)
879 return match_flag_type(~int(__x) & 0x0FFF);
882 inline _LIBCPP_INLINE_VISIBILITY
885 operator&(match_flag_type __x, match_flag_type __y)
887 return match_flag_type(int(__x) & int(__y));
890 inline _LIBCPP_INLINE_VISIBILITY
893 operator|(match_flag_type __x, match_flag_type __y)
895 return match_flag_type(int(__x) | int(__y));
898 inline _LIBCPP_INLINE_VISIBILITY
901 operator^(match_flag_type __x, match_flag_type __y)
903 return match_flag_type(int(__x) ^ int(__y));
906 inline _LIBCPP_INLINE_VISIBILITY
908 operator&=(match_flag_type& __x, match_flag_type __y)
914 inline _LIBCPP_INLINE_VISIBILITY
916 operator|=(match_flag_type& __x, match_flag_type __y)
922 inline _LIBCPP_INLINE_VISIBILITY
924 operator^=(match_flag_type& __x, match_flag_type __y)
952 class _LIBCPP_EXCEPTION_ABI regex_error
953 : public runtime_error
955 regex_constants::error_type __code_;
957 explicit regex_error(regex_constants::error_type __ecode);
958 virtual ~regex_error() throw();
959 _LIBCPP_INLINE_VISIBILITY
960 regex_constants::error_type code() const {return __code_;}
963 template <regex_constants::error_type _Ev>
964 _LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
965 void __throw_regex_error()
967 #ifndef _LIBCPP_NO_EXCEPTIONS
968 throw regex_error(_Ev);
974 template <class _CharT>
975 struct _LIBCPP_TEMPLATE_VIS regex_traits
978 typedef _CharT char_type;
979 typedef basic_string<char_type> string_type;
980 typedef locale locale_type;
981 typedef ctype_base::mask char_class_type;
983 #if defined(__mips__) && defined(__GLIBC__)
984 static const char_class_type __regex_word = static_cast<char_class_type>(_ISbit(15));
986 static const char_class_type __regex_word = 0x80;
991 const ctype<char_type>* __ct_;
992 const collate<char_type>* __col_;
997 _LIBCPP_INLINE_VISIBILITY
998 static size_t length(const char_type* __p)
999 {return char_traits<char_type>::length(__p);}
1000 _LIBCPP_INLINE_VISIBILITY
1001 char_type translate(char_type __c) const {return __c;}
1002 char_type translate_nocase(char_type __c) const;
1003 template <class _ForwardIterator>
1005 transform(_ForwardIterator __f, _ForwardIterator __l) const;
1006 template <class _ForwardIterator>
1007 _LIBCPP_INLINE_VISIBILITY
1009 transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
1010 {return __transform_primary(__f, __l, char_type());}
1011 template <class _ForwardIterator>
1012 _LIBCPP_INLINE_VISIBILITY
1014 lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
1015 {return __lookup_collatename(__f, __l, char_type());}
1016 template <class _ForwardIterator>
1017 _LIBCPP_INLINE_VISIBILITY
1019 lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1020 bool __icase = false) const
1021 {return __lookup_classname(__f, __l, __icase, char_type());}
1022 bool isctype(char_type __c, char_class_type __m) const;
1023 _LIBCPP_INLINE_VISIBILITY
1024 int value(char_type __ch, int __radix) const
1025 {return __regex_traits_value(__ch, __radix);}
1026 locale_type imbue(locale_type __l);
1027 _LIBCPP_INLINE_VISIBILITY
1028 locale_type getloc()const {return __loc_;}
1033 template <class _ForwardIterator>
1035 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
1036 template <class _ForwardIterator>
1038 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1040 template <class _ForwardIterator>
1042 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
1043 template <class _ForwardIterator>
1045 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1047 template <class _ForwardIterator>
1049 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1050 bool __icase, char) const;
1051 template <class _ForwardIterator>
1053 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1054 bool __icase, wchar_t) const;
1056 static int __regex_traits_value(unsigned char __ch, int __radix);
1057 _LIBCPP_INLINE_VISIBILITY
1058 int __regex_traits_value(char __ch, int __radix) const
1059 {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
1060 _LIBCPP_INLINE_VISIBILITY
1061 int __regex_traits_value(wchar_t __ch, int __radix) const;
1064 template <class _CharT>
1065 const typename regex_traits<_CharT>::char_class_type
1066 regex_traits<_CharT>::__regex_word;
1068 template <class _CharT>
1069 regex_traits<_CharT>::regex_traits()
1074 template <class _CharT>
1075 typename regex_traits<_CharT>::char_type
1076 regex_traits<_CharT>::translate_nocase(char_type __c) const
1078 return __ct_->tolower(__c);
1081 template <class _CharT>
1082 template <class _ForwardIterator>
1083 typename regex_traits<_CharT>::string_type
1084 regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
1086 string_type __s(__f, __l);
1087 return __col_->transform(__s.data(), __s.data() + __s.size());
1090 template <class _CharT>
1092 regex_traits<_CharT>::__init()
1094 __ct_ = &use_facet<ctype<char_type> >(__loc_);
1095 __col_ = &use_facet<collate<char_type> >(__loc_);
1098 template <class _CharT>
1099 typename regex_traits<_CharT>::locale_type
1100 regex_traits<_CharT>::imbue(locale_type __l)
1102 locale __r = __loc_;
1108 // transform_primary is very FreeBSD-specific
1110 template <class _CharT>
1111 template <class _ForwardIterator>
1112 typename regex_traits<_CharT>::string_type
1113 regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1114 _ForwardIterator __l, char) const
1116 const string_type __s(__f, __l);
1117 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1132 template <class _CharT>
1133 template <class _ForwardIterator>
1134 typename regex_traits<_CharT>::string_type
1135 regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1136 _ForwardIterator __l, wchar_t) const
1138 const string_type __s(__f, __l);
1139 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1154 // lookup_collatename is very FreeBSD-specific
1156 _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s);
1158 template <class _CharT>
1159 template <class _ForwardIterator>
1160 typename regex_traits<_CharT>::string_type
1161 regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1162 _ForwardIterator __l, char) const
1164 string_type __s(__f, __l);
1168 __r = __get_collation_name(__s.c_str());
1169 if (__r.empty() && __s.size() <= 2)
1171 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1172 if (__r.size() == 1 || __r.size() == 12)
1181 template <class _CharT>
1182 template <class _ForwardIterator>
1183 typename regex_traits<_CharT>::string_type
1184 regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1185 _ForwardIterator __l, wchar_t) const
1187 string_type __s(__f, __l);
1189 __n.reserve(__s.size());
1190 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1193 if (static_cast<unsigned>(*__i) >= 127)
1194 return string_type();
1195 __n.push_back(char(*__i));
1200 __n = __get_collation_name(__n.c_str());
1202 __r.assign(__n.begin(), __n.end());
1203 else if (__s.size() <= 2)
1205 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1206 if (__r.size() == 1 || __r.size() == 3)
1217 regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS
1218 __get_classname(const char* __s, bool __icase);
1220 template <class _CharT>
1221 template <class _ForwardIterator>
1222 typename regex_traits<_CharT>::char_class_type
1223 regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1224 _ForwardIterator __l,
1225 bool __icase, char) const
1227 string_type __s(__f, __l);
1228 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1229 return __get_classname(__s.c_str(), __icase);
1232 template <class _CharT>
1233 template <class _ForwardIterator>
1234 typename regex_traits<_CharT>::char_class_type
1235 regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1236 _ForwardIterator __l,
1237 bool __icase, wchar_t) const
1239 string_type __s(__f, __l);
1240 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1242 __n.reserve(__s.size());
1243 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1246 if (static_cast<unsigned>(*__i) >= 127)
1247 return char_class_type();
1248 __n.push_back(char(*__i));
1250 return __get_classname(__n.c_str(), __icase);
1253 template <class _CharT>
1255 regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
1257 if (__ct_->is(__m, __c))
1259 return (__c == '_' && (__m & __regex_word));
1262 template <class _CharT>
1264 regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
1266 if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
1270 if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
1274 __ch |= 0x20; // tolower
1275 if ('a' <= __ch && __ch <= 'f')
1276 return __ch - ('a' - 10);
1282 template <class _CharT>
1285 regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
1287 return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
1290 template <class _CharT> class __node;
1292 template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match;
1294 template <class _BidirectionalIterator,
1295 class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1296 class _LIBCPP_TEMPLATE_VIS match_results;
1298 template <class _CharT>
1303 __end_state = -1000,
1304 __consume_input, // -999
1305 __begin_marked_expr, // -998
1306 __end_marked_expr, // -997
1307 __pop_state, // -996
1308 __accept_and_consume, // -995
1309 __accept_but_not_consume, // -994
1316 const _CharT* __first_;
1317 const _CharT* __current_;
1318 const _CharT* __last_;
1319 vector<sub_match<const _CharT*> > __sub_matches_;
1320 vector<pair<size_t, const _CharT*> > __loop_data_;
1321 const __node<_CharT>* __node_;
1322 regex_constants::match_flag_type __flags_;
1325 _LIBCPP_INLINE_VISIBILITY
1327 : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
1328 __node_(nullptr), __flags_() {}
1333 template <class _CharT>
1336 __node(const __node&);
1337 __node& operator=(const __node&);
1339 typedef _VSTD::__state<_CharT> __state;
1341 _LIBCPP_INLINE_VISIBILITY
1343 _LIBCPP_INLINE_VISIBILITY
1344 virtual ~__node() {}
1346 _LIBCPP_INLINE_VISIBILITY
1347 virtual void __exec(__state&) const {};
1348 _LIBCPP_INLINE_VISIBILITY
1349 virtual void __exec_split(bool, __state&) const {};
1354 template <class _CharT>
1356 : public __node<_CharT>
1359 typedef _VSTD::__state<_CharT> __state;
1361 _LIBCPP_INLINE_VISIBILITY
1364 virtual void __exec(__state&) const;
1367 template <class _CharT>
1369 __end_state<_CharT>::__exec(__state& __s) const
1371 __s.__do_ = __state::__end_state;
1376 template <class _CharT>
1377 class __has_one_state
1378 : public __node<_CharT>
1380 __node<_CharT>* __first_;
1383 _LIBCPP_INLINE_VISIBILITY
1384 explicit __has_one_state(__node<_CharT>* __s)
1387 _LIBCPP_INLINE_VISIBILITY
1388 __node<_CharT>* first() const {return __first_;}
1389 _LIBCPP_INLINE_VISIBILITY
1390 __node<_CharT>*& first() {return __first_;}
1395 template <class _CharT>
1396 class __owns_one_state
1397 : public __has_one_state<_CharT>
1399 typedef __has_one_state<_CharT> base;
1402 _LIBCPP_INLINE_VISIBILITY
1403 explicit __owns_one_state(__node<_CharT>* __s)
1406 virtual ~__owns_one_state();
1409 template <class _CharT>
1410 __owns_one_state<_CharT>::~__owns_one_state()
1412 delete this->first();
1417 template <class _CharT>
1419 : public __owns_one_state<_CharT>
1421 typedef __owns_one_state<_CharT> base;
1424 typedef _VSTD::__state<_CharT> __state;
1426 _LIBCPP_INLINE_VISIBILITY
1427 explicit __empty_state(__node<_CharT>* __s)
1430 virtual void __exec(__state&) const;
1433 template <class _CharT>
1435 __empty_state<_CharT>::__exec(__state& __s) const
1437 __s.__do_ = __state::__accept_but_not_consume;
1438 __s.__node_ = this->first();
1441 // __empty_non_own_state
1443 template <class _CharT>
1444 class __empty_non_own_state
1445 : public __has_one_state<_CharT>
1447 typedef __has_one_state<_CharT> base;
1450 typedef _VSTD::__state<_CharT> __state;
1452 _LIBCPP_INLINE_VISIBILITY
1453 explicit __empty_non_own_state(__node<_CharT>* __s)
1456 virtual void __exec(__state&) const;
1459 template <class _CharT>
1461 __empty_non_own_state<_CharT>::__exec(__state& __s) const
1463 __s.__do_ = __state::__accept_but_not_consume;
1464 __s.__node_ = this->first();
1467 // __repeat_one_loop
1469 template <class _CharT>
1470 class __repeat_one_loop
1471 : public __has_one_state<_CharT>
1473 typedef __has_one_state<_CharT> base;
1476 typedef _VSTD::__state<_CharT> __state;
1478 _LIBCPP_INLINE_VISIBILITY
1479 explicit __repeat_one_loop(__node<_CharT>* __s)
1482 virtual void __exec(__state&) const;
1485 template <class _CharT>
1487 __repeat_one_loop<_CharT>::__exec(__state& __s) const
1489 __s.__do_ = __state::__repeat;
1490 __s.__node_ = this->first();
1493 // __owns_two_states
1495 template <class _CharT>
1496 class __owns_two_states
1497 : public __owns_one_state<_CharT>
1499 typedef __owns_one_state<_CharT> base;
1504 _LIBCPP_INLINE_VISIBILITY
1505 explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
1506 : base(__s1), __second_(__s2) {}
1508 virtual ~__owns_two_states();
1510 _LIBCPP_INLINE_VISIBILITY
1511 base* second() const {return __second_;}
1512 _LIBCPP_INLINE_VISIBILITY
1513 base*& second() {return __second_;}
1516 template <class _CharT>
1517 __owns_two_states<_CharT>::~__owns_two_states()
1524 template <class _CharT>
1526 : public __owns_two_states<_CharT>
1528 typedef __owns_two_states<_CharT> base;
1532 unsigned __loop_id_;
1533 unsigned __mexp_begin_;
1534 unsigned __mexp_end_;
1538 typedef _VSTD::__state<_CharT> __state;
1540 _LIBCPP_INLINE_VISIBILITY
1541 explicit __loop(unsigned __loop_id,
1542 __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
1543 unsigned __mexp_begin, unsigned __mexp_end,
1544 bool __greedy = true,
1546 size_t __max = numeric_limits<size_t>::max())
1547 : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
1548 __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
1549 __greedy_(__greedy) {}
1551 virtual void __exec(__state& __s) const;
1552 virtual void __exec_split(bool __second, __state& __s) const;
1555 _LIBCPP_INLINE_VISIBILITY
1556 void __init_repeat(__state& __s) const
1558 __s.__loop_data_[__loop_id_].second = __s.__current_;
1559 for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
1561 __s.__sub_matches_[__i].first = __s.__last_;
1562 __s.__sub_matches_[__i].second = __s.__last_;
1563 __s.__sub_matches_[__i].matched = false;
1568 template <class _CharT>
1570 __loop<_CharT>::__exec(__state& __s) const
1572 if (__s.__do_ == __state::__repeat)
1574 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1575 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1576 if (__do_repeat && __do_alt &&
1577 __s.__loop_data_[__loop_id_].second == __s.__current_)
1578 __do_repeat = false;
1579 if (__do_repeat && __do_alt)
1580 __s.__do_ = __state::__split;
1581 else if (__do_repeat)
1583 __s.__do_ = __state::__accept_but_not_consume;
1584 __s.__node_ = this->first();
1589 __s.__do_ = __state::__accept_but_not_consume;
1590 __s.__node_ = this->second();
1595 __s.__loop_data_[__loop_id_].first = 0;
1596 bool __do_repeat = 0 < __max_;
1597 bool __do_alt = 0 >= __min_;
1598 if (__do_repeat && __do_alt)
1599 __s.__do_ = __state::__split;
1600 else if (__do_repeat)
1602 __s.__do_ = __state::__accept_but_not_consume;
1603 __s.__node_ = this->first();
1608 __s.__do_ = __state::__accept_but_not_consume;
1609 __s.__node_ = this->second();
1614 template <class _CharT>
1616 __loop<_CharT>::__exec_split(bool __second, __state& __s) const
1618 __s.__do_ = __state::__accept_but_not_consume;
1619 if (__greedy_ != __second)
1621 __s.__node_ = this->first();
1625 __s.__node_ = this->second();
1630 template <class _CharT>
1632 : public __owns_two_states<_CharT>
1634 typedef __owns_two_states<_CharT> base;
1637 typedef _VSTD::__state<_CharT> __state;
1639 _LIBCPP_INLINE_VISIBILITY
1640 explicit __alternate(__owns_one_state<_CharT>* __s1,
1641 __owns_one_state<_CharT>* __s2)
1642 : base(__s1, __s2) {}
1644 virtual void __exec(__state& __s) const;
1645 virtual void __exec_split(bool __second, __state& __s) const;
1648 template <class _CharT>
1650 __alternate<_CharT>::__exec(__state& __s) const
1652 __s.__do_ = __state::__split;
1655 template <class _CharT>
1657 __alternate<_CharT>::__exec_split(bool __second, __state& __s) const
1659 __s.__do_ = __state::__accept_but_not_consume;
1661 __s.__node_ = this->second();
1663 __s.__node_ = this->first();
1666 // __begin_marked_subexpression
1668 template <class _CharT>
1669 class __begin_marked_subexpression
1670 : public __owns_one_state<_CharT>
1672 typedef __owns_one_state<_CharT> base;
1676 typedef _VSTD::__state<_CharT> __state;
1678 _LIBCPP_INLINE_VISIBILITY
1679 explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1680 : base(__s), __mexp_(__mexp) {}
1682 virtual void __exec(__state&) const;
1685 template <class _CharT>
1687 __begin_marked_subexpression<_CharT>::__exec(__state& __s) const
1689 __s.__do_ = __state::__accept_but_not_consume;
1690 __s.__sub_matches_[__mexp_-1].first = __s.__current_;
1691 __s.__node_ = this->first();
1694 // __end_marked_subexpression
1696 template <class _CharT>
1697 class __end_marked_subexpression
1698 : public __owns_one_state<_CharT>
1700 typedef __owns_one_state<_CharT> base;
1704 typedef _VSTD::__state<_CharT> __state;
1706 _LIBCPP_INLINE_VISIBILITY
1707 explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1708 : base(__s), __mexp_(__mexp) {}
1710 virtual void __exec(__state&) const;
1713 template <class _CharT>
1715 __end_marked_subexpression<_CharT>::__exec(__state& __s) const
1717 __s.__do_ = __state::__accept_but_not_consume;
1718 __s.__sub_matches_[__mexp_-1].second = __s.__current_;
1719 __s.__sub_matches_[__mexp_-1].matched = true;
1720 __s.__node_ = this->first();
1725 template <class _CharT>
1727 : public __owns_one_state<_CharT>
1729 typedef __owns_one_state<_CharT> base;
1733 typedef _VSTD::__state<_CharT> __state;
1735 _LIBCPP_INLINE_VISIBILITY
1736 explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
1737 : base(__s), __mexp_(__mexp) {}
1739 virtual void __exec(__state&) const;
1742 template <class _CharT>
1744 __back_ref<_CharT>::__exec(__state& __s) const
1746 if (__mexp_ > __s.__sub_matches_.size())
1747 __throw_regex_error<regex_constants::error_backref>();
1748 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1751 ptrdiff_t __len = __sm.second - __sm.first;
1752 if (__s.__last_ - __s.__current_ >= __len &&
1753 _VSTD::equal(__sm.first, __sm.second, __s.__current_))
1755 __s.__do_ = __state::__accept_but_not_consume;
1756 __s.__current_ += __len;
1757 __s.__node_ = this->first();
1761 __s.__do_ = __state::__reject;
1762 __s.__node_ = nullptr;
1767 __s.__do_ = __state::__reject;
1768 __s.__node_ = nullptr;
1774 template <class _CharT, class _Traits>
1775 class __back_ref_icase
1776 : public __owns_one_state<_CharT>
1778 typedef __owns_one_state<_CharT> base;
1783 typedef _VSTD::__state<_CharT> __state;
1785 _LIBCPP_INLINE_VISIBILITY
1786 explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
1787 __node<_CharT>* __s)
1788 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1790 virtual void __exec(__state&) const;
1793 template <class _CharT, class _Traits>
1795 __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
1797 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1800 ptrdiff_t __len = __sm.second - __sm.first;
1801 if (__s.__last_ - __s.__current_ >= __len)
1803 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1805 if (__traits_.translate_nocase(__sm.first[__i]) !=
1806 __traits_.translate_nocase(__s.__current_[__i]))
1809 __s.__do_ = __state::__accept_but_not_consume;
1810 __s.__current_ += __len;
1811 __s.__node_ = this->first();
1815 __s.__do_ = __state::__reject;
1816 __s.__node_ = nullptr;
1822 __s.__do_ = __state::__reject;
1823 __s.__node_ = nullptr;
1827 // __back_ref_collate
1829 template <class _CharT, class _Traits>
1830 class __back_ref_collate
1831 : public __owns_one_state<_CharT>
1833 typedef __owns_one_state<_CharT> base;
1838 typedef _VSTD::__state<_CharT> __state;
1840 _LIBCPP_INLINE_VISIBILITY
1841 explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
1842 __node<_CharT>* __s)
1843 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1845 virtual void __exec(__state&) const;
1848 template <class _CharT, class _Traits>
1850 __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
1852 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1855 ptrdiff_t __len = __sm.second - __sm.first;
1856 if (__s.__last_ - __s.__current_ >= __len)
1858 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1860 if (__traits_.translate(__sm.first[__i]) !=
1861 __traits_.translate(__s.__current_[__i]))
1864 __s.__do_ = __state::__accept_but_not_consume;
1865 __s.__current_ += __len;
1866 __s.__node_ = this->first();
1870 __s.__do_ = __state::__reject;
1871 __s.__node_ = nullptr;
1877 __s.__do_ = __state::__reject;
1878 __s.__node_ = nullptr;
1884 template <class _CharT, class _Traits>
1885 class __word_boundary
1886 : public __owns_one_state<_CharT>
1888 typedef __owns_one_state<_CharT> base;
1893 typedef _VSTD::__state<_CharT> __state;
1895 _LIBCPP_INLINE_VISIBILITY
1896 explicit __word_boundary(const _Traits& __traits, bool __invert,
1897 __node<_CharT>* __s)
1898 : base(__s), __traits_(__traits), __invert_(__invert) {}
1900 virtual void __exec(__state&) const;
1903 template <class _CharT, class _Traits>
1905 __word_boundary<_CharT, _Traits>::__exec(__state& __s) const
1907 bool __is_word_b = false;
1908 if (__s.__first_ != __s.__last_)
1910 if (__s.__current_ == __s.__last_)
1912 if (!(__s.__flags_ & regex_constants::match_not_eow))
1914 _CharT __c = __s.__current_[-1];
1915 __is_word_b = __c == '_' ||
1916 __traits_.isctype(__c, ctype_base::alnum);
1919 else if (__s.__current_ == __s.__first_ &&
1920 !(__s.__flags_ & regex_constants::match_prev_avail))
1922 if (!(__s.__flags_ & regex_constants::match_not_bow))
1924 _CharT __c = *__s.__current_;
1925 __is_word_b = __c == '_' ||
1926 __traits_.isctype(__c, ctype_base::alnum);
1931 _CharT __c1 = __s.__current_[-1];
1932 _CharT __c2 = *__s.__current_;
1933 bool __is_c1_b = __c1 == '_' ||
1934 __traits_.isctype(__c1, ctype_base::alnum);
1935 bool __is_c2_b = __c2 == '_' ||
1936 __traits_.isctype(__c2, ctype_base::alnum);
1937 __is_word_b = __is_c1_b != __is_c2_b;
1940 if (__is_word_b != __invert_)
1942 __s.__do_ = __state::__accept_but_not_consume;
1943 __s.__node_ = this->first();
1947 __s.__do_ = __state::__reject;
1948 __s.__node_ = nullptr;
1954 template <class _CharT>
1956 : public __owns_one_state<_CharT>
1958 typedef __owns_one_state<_CharT> base;
1961 typedef _VSTD::__state<_CharT> __state;
1963 _LIBCPP_INLINE_VISIBILITY
1964 __l_anchor(__node<_CharT>* __s)
1967 virtual void __exec(__state&) const;
1970 template <class _CharT>
1972 __l_anchor<_CharT>::__exec(__state& __s) const
1974 if (__s.__at_first_ && __s.__current_ == __s.__first_ &&
1975 !(__s.__flags_ & regex_constants::match_not_bol))
1977 __s.__do_ = __state::__accept_but_not_consume;
1978 __s.__node_ = this->first();
1982 __s.__do_ = __state::__reject;
1983 __s.__node_ = nullptr;
1989 template <class _CharT>
1991 : public __owns_one_state<_CharT>
1993 typedef __owns_one_state<_CharT> base;
1996 typedef _VSTD::__state<_CharT> __state;
1998 _LIBCPP_INLINE_VISIBILITY
1999 __r_anchor(__node<_CharT>* __s)
2002 virtual void __exec(__state&) const;
2005 template <class _CharT>
2007 __r_anchor<_CharT>::__exec(__state& __s) const
2009 if (__s.__current_ == __s.__last_ &&
2010 !(__s.__flags_ & regex_constants::match_not_eol))
2012 __s.__do_ = __state::__accept_but_not_consume;
2013 __s.__node_ = this->first();
2017 __s.__do_ = __state::__reject;
2018 __s.__node_ = nullptr;
2024 template <class _CharT>
2026 : public __owns_one_state<_CharT>
2028 typedef __owns_one_state<_CharT> base;
2031 typedef _VSTD::__state<_CharT> __state;
2033 _LIBCPP_INLINE_VISIBILITY
2034 __match_any(__node<_CharT>* __s)
2037 virtual void __exec(__state&) const;
2040 template <class _CharT>
2042 __match_any<_CharT>::__exec(__state& __s) const
2044 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
2046 __s.__do_ = __state::__accept_and_consume;
2048 __s.__node_ = this->first();
2052 __s.__do_ = __state::__reject;
2053 __s.__node_ = nullptr;
2057 // __match_any_but_newline
2059 template <class _CharT>
2060 class __match_any_but_newline
2061 : public __owns_one_state<_CharT>
2063 typedef __owns_one_state<_CharT> base;
2066 typedef _VSTD::__state<_CharT> __state;
2068 _LIBCPP_INLINE_VISIBILITY
2069 __match_any_but_newline(__node<_CharT>* __s)
2072 virtual void __exec(__state&) const;
2075 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
2076 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
2080 template <class _CharT>
2082 : public __owns_one_state<_CharT>
2084 typedef __owns_one_state<_CharT> base;
2088 __match_char(const __match_char&);
2089 __match_char& operator=(const __match_char&);
2091 typedef _VSTD::__state<_CharT> __state;
2093 _LIBCPP_INLINE_VISIBILITY
2094 __match_char(_CharT __c, __node<_CharT>* __s)
2095 : base(__s), __c_(__c) {}
2097 virtual void __exec(__state&) const;
2100 template <class _CharT>
2102 __match_char<_CharT>::__exec(__state& __s) const
2104 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
2106 __s.__do_ = __state::__accept_and_consume;
2108 __s.__node_ = this->first();
2112 __s.__do_ = __state::__reject;
2113 __s.__node_ = nullptr;
2117 // __match_char_icase
2119 template <class _CharT, class _Traits>
2120 class __match_char_icase
2121 : public __owns_one_state<_CharT>
2123 typedef __owns_one_state<_CharT> base;
2128 __match_char_icase(const __match_char_icase&);
2129 __match_char_icase& operator=(const __match_char_icase&);
2131 typedef _VSTD::__state<_CharT> __state;
2133 _LIBCPP_INLINE_VISIBILITY
2134 __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2135 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
2137 virtual void __exec(__state&) const;
2140 template <class _CharT, class _Traits>
2142 __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
2144 if (__s.__current_ != __s.__last_ &&
2145 __traits_.translate_nocase(*__s.__current_) == __c_)
2147 __s.__do_ = __state::__accept_and_consume;
2149 __s.__node_ = this->first();
2153 __s.__do_ = __state::__reject;
2154 __s.__node_ = nullptr;
2158 // __match_char_collate
2160 template <class _CharT, class _Traits>
2161 class __match_char_collate
2162 : public __owns_one_state<_CharT>
2164 typedef __owns_one_state<_CharT> base;
2169 __match_char_collate(const __match_char_collate&);
2170 __match_char_collate& operator=(const __match_char_collate&);
2172 typedef _VSTD::__state<_CharT> __state;
2174 _LIBCPP_INLINE_VISIBILITY
2175 __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2176 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2178 virtual void __exec(__state&) const;
2181 template <class _CharT, class _Traits>
2183 __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
2185 if (__s.__current_ != __s.__last_ &&
2186 __traits_.translate(*__s.__current_) == __c_)
2188 __s.__do_ = __state::__accept_and_consume;
2190 __s.__node_ = this->first();
2194 __s.__do_ = __state::__reject;
2195 __s.__node_ = nullptr;
2199 // __bracket_expression
2201 template <class _CharT, class _Traits>
2202 class __bracket_expression
2203 : public __owns_one_state<_CharT>
2205 typedef __owns_one_state<_CharT> base;
2206 typedef typename _Traits::string_type string_type;
2209 vector<_CharT> __chars_;
2210 vector<_CharT> __neg_chars_;
2211 vector<pair<string_type, string_type> > __ranges_;
2212 vector<pair<_CharT, _CharT> > __digraphs_;
2213 vector<string_type> __equivalences_;
2214 typename regex_traits<_CharT>::char_class_type __mask_;
2215 typename regex_traits<_CharT>::char_class_type __neg_mask_;
2219 bool __might_have_digraph_;
2221 __bracket_expression(const __bracket_expression&);
2222 __bracket_expression& operator=(const __bracket_expression&);
2224 typedef _VSTD::__state<_CharT> __state;
2226 _LIBCPP_INLINE_VISIBILITY
2227 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
2228 bool __negate, bool __icase, bool __collate)
2229 : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
2230 __negate_(__negate), __icase_(__icase), __collate_(__collate),
2231 __might_have_digraph_(__traits_.getloc().name() != "C") {}
2233 virtual void __exec(__state&) const;
2235 _LIBCPP_INLINE_VISIBILITY
2236 bool __negated() const {return __negate_;}
2238 _LIBCPP_INLINE_VISIBILITY
2239 void __add_char(_CharT __c)
2242 __chars_.push_back(__traits_.translate_nocase(__c));
2243 else if (__collate_)
2244 __chars_.push_back(__traits_.translate(__c));
2246 __chars_.push_back(__c);
2248 _LIBCPP_INLINE_VISIBILITY
2249 void __add_neg_char(_CharT __c)
2252 __neg_chars_.push_back(__traits_.translate_nocase(__c));
2253 else if (__collate_)
2254 __neg_chars_.push_back(__traits_.translate(__c));
2256 __neg_chars_.push_back(__c);
2258 _LIBCPP_INLINE_VISIBILITY
2259 void __add_range(string_type __b, string_type __e)
2265 for (size_t __i = 0; __i < __b.size(); ++__i)
2266 __b[__i] = __traits_.translate_nocase(__b[__i]);
2267 for (size_t __i = 0; __i < __e.size(); ++__i)
2268 __e[__i] = __traits_.translate_nocase(__e[__i]);
2272 for (size_t __i = 0; __i < __b.size(); ++__i)
2273 __b[__i] = __traits_.translate(__b[__i]);
2274 for (size_t __i = 0; __i < __e.size(); ++__i)
2275 __e[__i] = __traits_.translate(__e[__i]);
2277 __ranges_.push_back(make_pair(
2278 __traits_.transform(__b.begin(), __b.end()),
2279 __traits_.transform(__e.begin(), __e.end())));
2283 if (__b.size() != 1 || __e.size() != 1)
2284 __throw_regex_error<regex_constants::error_collate>();
2287 __b[0] = __traits_.translate_nocase(__b[0]);
2288 __e[0] = __traits_.translate_nocase(__e[0]);
2290 __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e)));
2293 _LIBCPP_INLINE_VISIBILITY
2294 void __add_digraph(_CharT __c1, _CharT __c2)
2297 __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
2298 __traits_.translate_nocase(__c2)));
2299 else if (__collate_)
2300 __digraphs_.push_back(make_pair(__traits_.translate(__c1),
2301 __traits_.translate(__c2)));
2303 __digraphs_.push_back(make_pair(__c1, __c2));
2305 _LIBCPP_INLINE_VISIBILITY
2306 void __add_equivalence(const string_type& __s)
2307 {__equivalences_.push_back(__s);}
2308 _LIBCPP_INLINE_VISIBILITY
2309 void __add_class(typename regex_traits<_CharT>::char_class_type __mask)
2310 {__mask_ |= __mask;}
2311 _LIBCPP_INLINE_VISIBILITY
2312 void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask)
2313 {__neg_mask_ |= __mask;}
2316 template <class _CharT, class _Traits>
2318 __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
2320 bool __found = false;
2321 unsigned __consumed = 0;
2322 if (__s.__current_ != __s.__last_)
2325 if (__might_have_digraph_)
2327 const _CharT* __next = _VSTD::next(__s.__current_);
2328 if (__next != __s.__last_)
2330 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2333 __ch2.first = __traits_.translate_nocase(__ch2.first);
2334 __ch2.second = __traits_.translate_nocase(__ch2.second);
2336 else if (__collate_)
2338 __ch2.first = __traits_.translate(__ch2.first);
2339 __ch2.second = __traits_.translate(__ch2.second);
2341 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
2343 // __ch2 is a digraph in this locale
2345 for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
2347 if (__ch2 == __digraphs_[__i])
2353 if (__collate_ && !__ranges_.empty())
2355 string_type __s2 = __traits_.transform(&__ch2.first,
2357 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2359 if (__ranges_[__i].first <= __s2 &&
2360 __s2 <= __ranges_[__i].second)
2367 if (!__equivalences_.empty())
2369 string_type __s2 = __traits_.transform_primary(&__ch2.first,
2371 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2373 if (__s2 == __equivalences_[__i])
2380 if (__traits_.isctype(__ch2.first, __mask_) &&
2381 __traits_.isctype(__ch2.second, __mask_))
2386 if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
2387 !__traits_.isctype(__ch2.second, __neg_mask_))
2396 // test *__s.__current_ as not a digraph
2397 _CharT __ch = *__s.__current_;
2399 __ch = __traits_.translate_nocase(__ch);
2400 else if (__collate_)
2401 __ch = __traits_.translate(__ch);
2402 for (size_t __i = 0; __i < __chars_.size(); ++__i)
2404 if (__ch == __chars_[__i])
2410 if (!__neg_chars_.empty())
2412 for (size_t __i = 0; __i < __neg_chars_.size(); ++__i)
2414 if (__ch == __neg_chars_[__i])
2421 if (!__ranges_.empty())
2423 string_type __s2 = __collate_ ?
2424 __traits_.transform(&__ch, &__ch + 1) :
2425 string_type(1, __ch);
2426 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2428 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
2435 if (!__equivalences_.empty())
2437 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2438 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2440 if (__s2 == __equivalences_[__i])
2447 if (__traits_.isctype(__ch, __mask_))
2452 if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_))
2459 __found = __negate_; // force reject
2461 if (__found != __negate_)
2463 __s.__do_ = __state::__accept_and_consume;
2464 __s.__current_ += __consumed;
2465 __s.__node_ = this->first();
2469 __s.__do_ = __state::__reject;
2470 __s.__node_ = nullptr;
2474 template <class _CharT, class _Traits> class __lookahead;
2476 template <class _CharT, class _Traits = regex_traits<_CharT> >
2477 class _LIBCPP_TEMPLATE_VIS basic_regex
2481 typedef _CharT value_type;
2482 typedef _Traits traits_type;
2483 typedef typename _Traits::string_type string_type;
2484 typedef regex_constants::syntax_option_type flag_type;
2485 typedef typename _Traits::locale_type locale_type;
2490 unsigned __marked_count_;
2491 unsigned __loop_count_;
2493 shared_ptr<__empty_state<_CharT> > __start_;
2494 __owns_one_state<_CharT>* __end_;
2496 typedef _VSTD::__state<_CharT> __state;
2497 typedef _VSTD::__node<_CharT> __node;
2501 static const regex_constants::syntax_option_type icase = regex_constants::icase;
2502 static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2503 static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
2504 static const regex_constants::syntax_option_type collate = regex_constants::collate;
2505 static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2506 static const regex_constants::syntax_option_type basic = regex_constants::basic;
2507 static const regex_constants::syntax_option_type extended = regex_constants::extended;
2508 static const regex_constants::syntax_option_type awk = regex_constants::awk;
2509 static const regex_constants::syntax_option_type grep = regex_constants::grep;
2510 static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
2512 // construct/copy/destroy:
2513 _LIBCPP_INLINE_VISIBILITY
2515 : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0),
2518 _LIBCPP_INLINE_VISIBILITY
2519 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2520 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2522 {__parse(__p, __p + __traits_.length(__p));}
2523 _LIBCPP_INLINE_VISIBILITY
2524 basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
2525 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2527 {__parse(__p, __p + __len);}
2528 // basic_regex(const basic_regex&) = default;
2529 // basic_regex(basic_regex&&) = default;
2530 template <class _ST, class _SA>
2531 _LIBCPP_INLINE_VISIBILITY
2532 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2533 flag_type __f = regex_constants::ECMAScript)
2534 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2536 {__parse(__p.begin(), __p.end());}
2537 template <class _ForwardIterator>
2538 _LIBCPP_INLINE_VISIBILITY
2539 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
2540 flag_type __f = regex_constants::ECMAScript)
2541 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2543 {__parse(__first, __last);}
2544 #ifndef _LIBCPP_CXX03_LANG
2545 _LIBCPP_INLINE_VISIBILITY
2546 basic_regex(initializer_list<value_type> __il,
2547 flag_type __f = regex_constants::ECMAScript)
2548 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2550 {__parse(__il.begin(), __il.end());}
2551 #endif // _LIBCPP_CXX03_LANG
2553 // ~basic_regex() = default;
2555 // basic_regex& operator=(const basic_regex&) = default;
2556 // basic_regex& operator=(basic_regex&&) = default;
2557 _LIBCPP_INLINE_VISIBILITY
2558 basic_regex& operator=(const value_type* __p)
2559 {return assign(__p);}
2560 #ifndef _LIBCPP_CXX03_LANG
2561 _LIBCPP_INLINE_VISIBILITY
2562 basic_regex& operator=(initializer_list<value_type> __il)
2563 {return assign(__il);}
2564 #endif // _LIBCPP_CXX03_LANG
2565 template <class _ST, class _SA>
2566 _LIBCPP_INLINE_VISIBILITY
2567 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
2568 {return assign(__p);}
2571 _LIBCPP_INLINE_VISIBILITY
2572 basic_regex& assign(const basic_regex& __that)
2573 {return *this = __that;}
2574 #ifndef _LIBCPP_CXX03_LANG
2575 _LIBCPP_INLINE_VISIBILITY
2576 basic_regex& assign(basic_regex&& __that) _NOEXCEPT
2577 {return *this = _VSTD::move(__that);}
2579 _LIBCPP_INLINE_VISIBILITY
2580 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2581 {return assign(__p, __p + __traits_.length(__p), __f);}
2582 _LIBCPP_INLINE_VISIBILITY
2583 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f)
2584 {return assign(__p, __p + __len, __f);}
2585 template <class _ST, class _SA>
2586 _LIBCPP_INLINE_VISIBILITY
2587 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
2588 flag_type __f = regex_constants::ECMAScript)
2589 {return assign(__s.begin(), __s.end(), __f);}
2591 template <class _InputIterator>
2592 _LIBCPP_INLINE_VISIBILITY
2595 __is_input_iterator <_InputIterator>::value &&
2596 !__is_forward_iterator<_InputIterator>::value,
2599 assign(_InputIterator __first, _InputIterator __last,
2600 flag_type __f = regex_constants::ECMAScript)
2602 basic_string<_CharT> __t(__first, __last);
2603 return assign(__t.begin(), __t.end(), __f);
2607 _LIBCPP_INLINE_VISIBILITY
2608 void __member_init(flag_type __f)
2611 __marked_count_ = 0;
2618 template <class _ForwardIterator>
2619 _LIBCPP_INLINE_VISIBILITY
2622 __is_forward_iterator<_ForwardIterator>::value,
2625 assign(_ForwardIterator __first, _ForwardIterator __last,
2626 flag_type __f = regex_constants::ECMAScript)
2628 return assign(basic_regex(__first, __last, __f));
2631 #ifndef _LIBCPP_CXX03_LANG
2633 _LIBCPP_INLINE_VISIBILITY
2634 basic_regex& assign(initializer_list<value_type> __il,
2635 flag_type __f = regex_constants::ECMAScript)
2636 {return assign(__il.begin(), __il.end(), __f);}
2638 #endif // _LIBCPP_CXX03_LANG
2640 // const operations:
2641 _LIBCPP_INLINE_VISIBILITY
2642 unsigned mark_count() const {return __marked_count_;}
2643 _LIBCPP_INLINE_VISIBILITY
2644 flag_type flags() const {return __flags_;}
2647 _LIBCPP_INLINE_VISIBILITY
2648 locale_type imbue(locale_type __loc)
2650 __member_init(ECMAScript);
2652 return __traits_.imbue(__loc);
2654 _LIBCPP_INLINE_VISIBILITY
2655 locale_type getloc() const {return __traits_.getloc();}
2658 void swap(basic_regex& __r);
2661 _LIBCPP_INLINE_VISIBILITY
2662 unsigned __loop_count() const {return __loop_count_;}
2664 template <class _ForwardIterator>
2666 __parse(_ForwardIterator __first, _ForwardIterator __last);
2667 template <class _ForwardIterator>
2669 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2670 template <class _ForwardIterator>
2672 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2673 template <class _ForwardIterator>
2675 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2676 template <class _ForwardIterator>
2678 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2679 template <class _ForwardIterator>
2681 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2682 template <class _ForwardIterator>
2684 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2685 template <class _ForwardIterator>
2687 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2688 template <class _ForwardIterator>
2690 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2691 template <class _ForwardIterator>
2693 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2694 template <class _ForwardIterator>
2696 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2697 template <class _ForwardIterator>
2699 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2700 template <class _ForwardIterator>
2702 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2703 template <class _ForwardIterator>
2705 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2706 __owns_one_state<_CharT>* __s,
2707 unsigned __mexp_begin, unsigned __mexp_end);
2708 template <class _ForwardIterator>
2710 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2711 __owns_one_state<_CharT>* __s,
2712 unsigned __mexp_begin, unsigned __mexp_end);
2713 template <class _ForwardIterator>
2715 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2716 template <class _ForwardIterator>
2718 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
2719 __bracket_expression<_CharT, _Traits>* __ml);
2720 template <class _ForwardIterator>
2722 __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
2723 __bracket_expression<_CharT, _Traits>* __ml);
2724 template <class _ForwardIterator>
2726 __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
2727 __bracket_expression<_CharT, _Traits>* __ml);
2728 template <class _ForwardIterator>
2730 __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
2731 __bracket_expression<_CharT, _Traits>* __ml);
2732 template <class _ForwardIterator>
2734 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
2735 basic_string<_CharT>& __col_sym);
2736 template <class _ForwardIterator>
2738 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
2739 template <class _ForwardIterator>
2741 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2742 template <class _ForwardIterator>
2744 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2745 template <class _ForwardIterator>
2747 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2748 template <class _ForwardIterator>
2750 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2751 template <class _ForwardIterator>
2753 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2754 template <class _ForwardIterator>
2756 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2757 template <class _ForwardIterator>
2759 __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2760 template <class _ForwardIterator>
2762 __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2763 template <class _ForwardIterator>
2765 __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2766 template <class _ForwardIterator>
2768 __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2769 template <class _ForwardIterator>
2771 __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2772 template <class _ForwardIterator>
2774 __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2775 template <class _ForwardIterator>
2777 __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2778 template <class _ForwardIterator>
2780 __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2781 template <class _ForwardIterator>
2783 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
2784 basic_string<_CharT>* __str = nullptr);
2785 template <class _ForwardIterator>
2787 __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
2788 template <class _ForwardIterator>
2790 __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
2791 template <class _ForwardIterator>
2793 __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
2794 template <class _ForwardIterator>
2796 __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
2797 basic_string<_CharT>& __str,
2798 __bracket_expression<_CharT, _Traits>* __ml);
2799 template <class _ForwardIterator>
2801 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
2802 basic_string<_CharT>* __str = nullptr);
2804 _LIBCPP_INLINE_VISIBILITY
2805 void __push_l_anchor();
2806 void __push_r_anchor();
2807 void __push_match_any();
2808 void __push_match_any_but_newline();
2809 _LIBCPP_INLINE_VISIBILITY
2810 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2811 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2812 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2813 __mexp_begin, __mexp_end);}
2814 _LIBCPP_INLINE_VISIBILITY
2815 void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2816 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2817 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2818 __mexp_begin, __mexp_end, false);}
2819 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2820 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2821 bool __greedy = true);
2822 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
2823 void __push_char(value_type __c);
2824 void __push_back_ref(int __i);
2825 void __push_alternation(__owns_one_state<_CharT>* __sa,
2826 __owns_one_state<_CharT>* __sb);
2827 void __push_begin_marked_subexpression();
2828 void __push_end_marked_subexpression(unsigned);
2829 void __push_empty();
2830 void __push_word_boundary(bool);
2831 void __push_lookahead(const basic_regex&, bool, unsigned);
2833 template <class _Allocator>
2835 __search(const _CharT* __first, const _CharT* __last,
2836 match_results<const _CharT*, _Allocator>& __m,
2837 regex_constants::match_flag_type __flags) const;
2839 template <class _Allocator>
2841 __match_at_start(const _CharT* __first, const _CharT* __last,
2842 match_results<const _CharT*, _Allocator>& __m,
2843 regex_constants::match_flag_type __flags, bool) const;
2844 template <class _Allocator>
2846 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
2847 match_results<const _CharT*, _Allocator>& __m,
2848 regex_constants::match_flag_type __flags, bool) const;
2849 template <class _Allocator>
2851 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
2852 match_results<const _CharT*, _Allocator>& __m,
2853 regex_constants::match_flag_type __flags, bool) const;
2854 template <class _Allocator>
2856 __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
2857 match_results<const _CharT*, _Allocator>& __m,
2858 regex_constants::match_flag_type __flags, bool) const;
2860 template <class _Bp, class _Ap, class _Cp, class _Tp>
2863 regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
2864 regex_constants::match_flag_type);
2866 template <class _Ap, class _Cp, class _Tp>
2869 regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&,
2870 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
2872 template <class _Bp, class _Cp, class _Tp>
2875 regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&,
2876 regex_constants::match_flag_type);
2878 template <class _Cp, class _Tp>
2881 regex_search(const _Cp*, const _Cp*,
2882 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
2884 template <class _Cp, class _Ap, class _Tp>
2887 regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&,
2888 regex_constants::match_flag_type);
2890 template <class _ST, class _SA, class _Cp, class _Tp>
2893 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
2894 const basic_regex<_Cp, _Tp>& __e,
2895 regex_constants::match_flag_type __flags);
2897 template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
2900 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
2901 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
2902 const basic_regex<_Cp, _Tp>& __e,
2903 regex_constants::match_flag_type __flags);
2905 template <class _Iter, class _Ap, class _Cp, class _Tp>
2908 regex_search(__wrap_iter<_Iter> __first,
2909 __wrap_iter<_Iter> __last,
2910 match_results<__wrap_iter<_Iter>, _Ap>& __m,
2911 const basic_regex<_Cp, _Tp>& __e,
2912 regex_constants::match_flag_type __flags);
2914 template <class, class> friend class __lookahead;
2917 template <class _CharT, class _Traits>
2918 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
2919 template <class _CharT, class _Traits>
2920 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
2921 template <class _CharT, class _Traits>
2922 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
2923 template <class _CharT, class _Traits>
2924 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
2925 template <class _CharT, class _Traits>
2926 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
2927 template <class _CharT, class _Traits>
2928 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
2929 template <class _CharT, class _Traits>
2930 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
2931 template <class _CharT, class _Traits>
2932 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
2933 template <class _CharT, class _Traits>
2934 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
2935 template <class _CharT, class _Traits>
2936 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
2938 template <class _CharT, class _Traits>
2940 basic_regex<_CharT, _Traits>::swap(basic_regex& __r)
2943 swap(__traits_, __r.__traits_);
2944 swap(__flags_, __r.__flags_);
2945 swap(__marked_count_, __r.__marked_count_);
2946 swap(__loop_count_, __r.__loop_count_);
2947 swap(__open_count_, __r.__open_count_);
2948 swap(__start_, __r.__start_);
2949 swap(__end_, __r.__end_);
2952 template <class _CharT, class _Traits>
2953 inline _LIBCPP_INLINE_VISIBILITY
2955 swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
2957 return __x.swap(__y);
2962 template <class _CharT, class _Traits>
2964 : public __owns_one_state<_CharT>
2966 typedef __owns_one_state<_CharT> base;
2968 basic_regex<_CharT, _Traits> __exp_;
2972 __lookahead(const __lookahead&);
2973 __lookahead& operator=(const __lookahead&);
2975 typedef _VSTD::__state<_CharT> __state;
2977 _LIBCPP_INLINE_VISIBILITY
2978 __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
2979 : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
2981 virtual void __exec(__state&) const;
2984 template <class _CharT, class _Traits>
2986 __lookahead<_CharT, _Traits>::__exec(__state& __s) const
2988 match_results<const _CharT*> __m;
2989 __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
2990 bool __matched = __exp_.__match_at_start_ecma(
2991 __s.__current_, __s.__last_,
2993 (__s.__flags_ | regex_constants::match_continuous) &
2994 ~regex_constants::__full_match,
2995 __s.__at_first_ && __s.__current_ == __s.__first_);
2996 if (__matched != __invert_)
2998 __s.__do_ = __state::__accept_but_not_consume;
2999 __s.__node_ = this->first();
3000 for (unsigned __i = 1; __i < __m.size(); ++__i) {
3001 __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
3006 __s.__do_ = __state::__reject;
3007 __s.__node_ = nullptr;
3011 template <class _CharT, class _Traits>
3012 template <class _ForwardIterator>
3014 basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
3015 _ForwardIterator __last)
3018 unique_ptr<__node> __h(new __end_state<_CharT>);
3019 __start_.reset(new __empty_state<_CharT>(__h.get()));
3021 __end_ = __start_.get();
3023 switch (__flags_ & 0x1F0)
3026 __first = __parse_ecma_exp(__first, __last);
3029 __first = __parse_basic_reg_exp(__first, __last);
3033 __first = __parse_extended_reg_exp(__first, __last);
3036 __first = __parse_grep(__first, __last);
3039 __first = __parse_egrep(__first, __last);
3042 __throw_regex_error<regex_constants::__re_err_grammar>();
3047 template <class _CharT, class _Traits>
3048 template <class _ForwardIterator>
3050 basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
3051 _ForwardIterator __last)
3053 if (__first != __last)
3055 if (*__first == '^')
3060 if (__first != __last)
3062 __first = __parse_RE_expression(__first, __last);
3063 if (__first != __last)
3065 _ForwardIterator __temp = _VSTD::next(__first);
3066 if (__temp == __last && *__first == '$')
3073 if (__first != __last)
3074 __throw_regex_error<regex_constants::__re_err_empty>();
3079 template <class _CharT, class _Traits>
3080 template <class _ForwardIterator>
3082 basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
3083 _ForwardIterator __last)
3085 __owns_one_state<_CharT>* __sa = __end_;
3086 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
3087 if (__temp == __first)
3088 __throw_regex_error<regex_constants::__re_err_empty>();
3090 while (__first != __last && *__first == '|')
3092 __owns_one_state<_CharT>* __sb = __end_;
3093 __temp = __parse_ERE_branch(++__first, __last);
3094 if (__temp == __first)
3095 __throw_regex_error<regex_constants::__re_err_empty>();
3096 __push_alternation(__sa, __sb);
3102 template <class _CharT, class _Traits>
3103 template <class _ForwardIterator>
3105 basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
3106 _ForwardIterator __last)
3108 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
3109 if (__temp == __first)
3110 __throw_regex_error<regex_constants::__re_err_empty>();
3114 __temp = __parse_ERE_expression(__first, __last);
3115 } while (__temp != __first);
3119 template <class _CharT, class _Traits>
3120 template <class _ForwardIterator>
3122 basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
3123 _ForwardIterator __last)
3125 __owns_one_state<_CharT>* __e = __end_;
3126 unsigned __mexp_begin = __marked_count_;
3127 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
3128 if (__temp == __first && __temp != __last)
3141 __push_begin_marked_subexpression();
3142 unsigned __temp_count = __marked_count_;
3144 __temp = __parse_extended_reg_exp(++__temp, __last);
3145 if (__temp == __last || *__temp != ')')
3146 __throw_regex_error<regex_constants::error_paren>();
3147 __push_end_marked_subexpression(__temp_count);
3153 if (__temp != __first)
3154 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
3160 template <class _CharT, class _Traits>
3161 template <class _ForwardIterator>
3163 basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
3164 _ForwardIterator __last)
3168 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
3169 if (__temp == __first)
3176 template <class _CharT, class _Traits>
3177 template <class _ForwardIterator>
3179 basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
3180 _ForwardIterator __last)
3182 if (__first != __last)
3184 __owns_one_state<_CharT>* __e = __end_;
3185 unsigned __mexp_begin = __marked_count_;
3186 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
3187 if (__temp != __first)
3188 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
3189 __mexp_begin+1, __marked_count_+1);
3194 template <class _CharT, class _Traits>
3195 template <class _ForwardIterator>
3197 basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
3198 _ForwardIterator __last)
3200 _ForwardIterator __temp = __first;
3201 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
3202 if (__temp == __first)
3204 __temp = __parse_Back_open_paren(__first, __last);
3205 if (__temp != __first)
3207 __push_begin_marked_subexpression();
3208 unsigned __temp_count = __marked_count_;
3209 __first = __parse_RE_expression(__temp, __last);
3210 __temp = __parse_Back_close_paren(__first, __last);
3211 if (__temp == __first)
3212 __throw_regex_error<regex_constants::error_paren>();
3213 __push_end_marked_subexpression(__temp_count);
3217 __first = __parse_BACKREF(__first, __last);
3222 template <class _CharT, class _Traits>
3223 template <class _ForwardIterator>
3225 basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
3226 _ForwardIterator __first,
3227 _ForwardIterator __last)
3229 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
3230 if (__temp == __first)
3232 __temp = __parse_QUOTED_CHAR(__first, __last);
3233 if (__temp == __first)
3235 if (__temp != __last && *__temp == '.')
3241 __temp = __parse_bracket_expression(__first, __last);
3248 template <class _CharT, class _Traits>
3249 template <class _ForwardIterator>
3251 basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
3252 _ForwardIterator __first,
3253 _ForwardIterator __last)
3255 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
3256 if (__temp == __first)
3258 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
3259 if (__temp == __first)
3261 if (__temp != __last && *__temp == '.')
3267 __temp = __parse_bracket_expression(__first, __last);
3274 template <class _CharT, class _Traits>
3275 template <class _ForwardIterator>
3277 basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
3278 _ForwardIterator __last)
3280 if (__first != __last)
3282 _ForwardIterator __temp = _VSTD::next(__first);
3283 if (__temp != __last)
3285 if (*__first == '\\' && *__temp == '(')
3292 template <class _CharT, class _Traits>
3293 template <class _ForwardIterator>
3295 basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
3296 _ForwardIterator __last)
3298 if (__first != __last)
3300 _ForwardIterator __temp = _VSTD::next(__first);
3301 if (__temp != __last)
3303 if (*__first == '\\' && *__temp == ')')
3310 template <class _CharT, class _Traits>
3311 template <class _ForwardIterator>
3313 basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
3314 _ForwardIterator __last)
3316 if (__first != __last)
3318 _ForwardIterator __temp = _VSTD::next(__first);
3319 if (__temp != __last)
3321 if (*__first == '\\' && *__temp == '{')
3328 template <class _CharT, class _Traits>
3329 template <class _ForwardIterator>
3331 basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
3332 _ForwardIterator __last)
3334 if (__first != __last)
3336 _ForwardIterator __temp = _VSTD::next(__first);
3337 if (__temp != __last)
3339 if (*__first == '\\' && *__temp == '}')
3346 template <class _CharT, class _Traits>
3347 template <class _ForwardIterator>
3349 basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
3350 _ForwardIterator __last)
3352 if (__first != __last)
3354 _ForwardIterator __temp = _VSTD::next(__first);
3355 if (__temp != __last)
3357 if (*__first == '\\')
3359 int __val = __traits_.value(*__temp, 10);
3360 if (__val >= 1 && __val <= 9)
3362 __push_back_ref(__val);
3371 template <class _CharT, class _Traits>
3372 template <class _ForwardIterator>
3374 basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
3375 _ForwardIterator __last)
3377 if (__first != __last)
3379 _ForwardIterator __temp = _VSTD::next(__first);
3380 if (__temp == __last && *__first == '$')
3382 // Not called inside a bracket
3383 if (*__first == '.' || *__first == '\\' || *__first == '[')
3385 __push_char(*__first);
3391 template <class _CharT, class _Traits>
3392 template <class _ForwardIterator>
3394 basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
3395 _ForwardIterator __last)
3397 if (__first != __last)
3414 if (__open_count_ == 0)
3416 __push_char(*__first);
3421 __push_char(*__first);
3429 template <class _CharT, class _Traits>
3430 template <class _ForwardIterator>
3432 basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
3433 _ForwardIterator __last)
3435 if (__first != __last)
3437 _ForwardIterator __temp = _VSTD::next(__first);
3438 if (__temp != __last)
3440 if (*__first == '\\')
3450 __push_char(*__temp);
3460 template <class _CharT, class _Traits>
3461 template <class _ForwardIterator>
3463 basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
3464 _ForwardIterator __last)
3466 if (__first != __last)
3468 _ForwardIterator __temp = _VSTD::next(__first);
3469 if (__temp != __last)
3471 if (*__first == '\\')
3488 __push_char(*__temp);
3492 if ((__flags_ & 0x1F0) == awk)
3493 __first = __parse_awk_escape(++__first, __last);
3502 template <class _CharT, class _Traits>
3503 template <class _ForwardIterator>
3505 basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
3506 _ForwardIterator __last,
3507 __owns_one_state<_CharT>* __s,
3508 unsigned __mexp_begin,
3509 unsigned __mexp_end)
3511 if (__first != __last)
3513 if (*__first == '*')
3515 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3520 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3521 if (__temp != __first)
3525 __temp = __parse_DUP_COUNT(__first, __last, __min);
3526 if (__temp == __first)
3527 __throw_regex_error<regex_constants::error_badbrace>();
3529 if (__first == __last)
3530 __throw_regex_error<regex_constants::error_brace>();
3531 if (*__first != ',')
3533 __temp = __parse_Back_close_brace(__first, __last);
3534 if (__temp == __first)
3535 __throw_regex_error<regex_constants::error_brace>();
3536 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
3542 ++__first; // consume ','
3544 __first = __parse_DUP_COUNT(__first, __last, __max);
3545 __temp = __parse_Back_close_brace(__first, __last);
3546 if (__temp == __first)
3547 __throw_regex_error<regex_constants::error_brace>();
3549 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3553 __throw_regex_error<regex_constants::error_badbrace>();
3554 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
3565 template <class _CharT, class _Traits>
3566 template <class _ForwardIterator>
3568 basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
3569 _ForwardIterator __last,
3570 __owns_one_state<_CharT>* __s,
3571 unsigned __mexp_begin,
3572 unsigned __mexp_end)
3574 if (__first != __last)
3576 unsigned __grammar = __flags_ & 0x1F0;
3581 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3584 __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3587 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3591 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3594 __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3597 __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3601 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3604 __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3607 __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
3612 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
3613 if (__temp == __first)
3614 __throw_regex_error<regex_constants::error_badbrace>();
3616 if (__first == __last)
3617 __throw_regex_error<regex_constants::error_brace>();
3622 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3625 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3628 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
3632 if (__first == __last)
3633 __throw_regex_error<regex_constants::error_badbrace>();
3634 if (*__first == '}')
3637 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3640 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3643 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3648 __temp = __parse_DUP_COUNT(__first, __last, __max);
3649 if (__temp == __first)
3650 __throw_regex_error<regex_constants::error_brace>();
3652 if (__first == __last || *__first != '}')
3653 __throw_regex_error<regex_constants::error_brace>();
3656 __throw_regex_error<regex_constants::error_badbrace>();
3657 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3660 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3663 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
3667 __throw_regex_error<regex_constants::error_badbrace>();
3676 template <class _CharT, class _Traits>
3677 template <class _ForwardIterator>
3679 basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
3680 _ForwardIterator __last)
3682 if (__first != __last && *__first == '[')
3685 if (__first == __last)
3686 __throw_regex_error<regex_constants::error_brack>();
3687 bool __negate = false;
3688 if (*__first == '^')
3693 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3694 // __ml owned by *this
3695 if (__first == __last)
3696 __throw_regex_error<regex_constants::error_brack>();
3697 if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']')
3699 __ml->__add_char(']');
3702 __first = __parse_follow_list(__first, __last, __ml);
3703 if (__first == __last)
3704 __throw_regex_error<regex_constants::error_brack>();
3705 if (*__first == '-')
3707 __ml->__add_char('-');
3710 if (__first == __last || *__first != ']')
3711 __throw_regex_error<regex_constants::error_brack>();
3717 template <class _CharT, class _Traits>
3718 template <class _ForwardIterator>
3720 basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
3721 _ForwardIterator __last,
3722 __bracket_expression<_CharT, _Traits>* __ml)
3724 if (__first != __last)
3728 _ForwardIterator __temp = __parse_expression_term(__first, __last,
3730 if (__temp == __first)
3738 template <class _CharT, class _Traits>
3739 template <class _ForwardIterator>
3741 basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
3742 _ForwardIterator __last,
3743 __bracket_expression<_CharT, _Traits>* __ml)
3745 if (__first != __last && *__first != ']')
3747 _ForwardIterator __temp = _VSTD::next(__first);
3748 basic_string<_CharT> __start_range;
3749 if (__temp != __last && *__first == '[')
3752 return __parse_equivalence_class(++__temp, __last, __ml);
3753 else if (*__temp == ':')
3754 return __parse_character_class(++__temp, __last, __ml);
3755 else if (*__temp == '.')
3756 __first = __parse_collating_symbol(++__temp, __last, __start_range);
3758 unsigned __grammar = __flags_ & 0x1F0;
3759 if (__start_range.empty())
3761 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3763 if (__grammar == ECMAScript)
3764 __first = __parse_class_escape(++__first, __last, __start_range, __ml);
3766 __first = __parse_awk_escape(++__first, __last, &__start_range);
3770 __start_range = *__first;
3774 if (__first != __last && *__first != ']')
3776 __temp = _VSTD::next(__first);
3777 if (__temp != __last && *__first == '-' && *__temp != ']')
3780 basic_string<_CharT> __end_range;
3783 if (__temp != __last && *__first == '[' && *__temp == '.')
3784 __first = __parse_collating_symbol(++__temp, __last, __end_range);
3787 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3789 if (__grammar == ECMAScript)
3790 __first = __parse_class_escape(++__first, __last,
3793 __first = __parse_awk_escape(++__first, __last,
3798 __end_range = *__first;
3802 __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range));
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]);
3812 else if (!__start_range.empty())
3814 if (__start_range.size() == 1)
3815 __ml->__add_char(__start_range[0]);
3817 __ml->__add_digraph(__start_range[0], __start_range[1]);
3823 template <class _CharT, class _Traits>
3824 template <class _ForwardIterator>
3826 basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
3827 _ForwardIterator __last,
3828 basic_string<_CharT>& __str,
3829 __bracket_expression<_CharT, _Traits>* __ml)
3831 if (__first == __last)
3832 __throw_regex_error<regex_constants::error_escape>();
3842 __ml->__add_class(ctype_base::digit);
3845 __ml->__add_neg_class(ctype_base::digit);
3848 __ml->__add_class(ctype_base::space);
3851 __ml->__add_neg_class(ctype_base::space);
3854 __ml->__add_class(ctype_base::alnum);
3855 __ml->__add_char('_');
3858 __ml->__add_neg_class(ctype_base::alnum);
3859 __ml->__add_neg_char('_');
3862 __first = __parse_character_escape(__first, __last, &__str);
3866 template <class _CharT, class _Traits>
3867 template <class _ForwardIterator>
3869 basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
3870 _ForwardIterator __last,
3871 basic_string<_CharT>* __str)
3873 if (__first == __last)
3874 __throw_regex_error<regex_constants::error_escape>();
3883 __push_char(*__first);
3889 __push_char(_CharT(7));
3895 __push_char(_CharT(8));
3899 *__str = _CharT(0xC);
3901 __push_char(_CharT(0xC));
3905 *__str = _CharT(0xA);
3907 __push_char(_CharT(0xA));
3911 *__str = _CharT(0xD);
3913 __push_char(_CharT(0xD));
3917 *__str = _CharT(0x9);
3919 __push_char(_CharT(0x9));
3923 *__str = _CharT(0xB);
3925 __push_char(_CharT(0xB));
3928 if ('0' <= *__first && *__first <= '7')
3930 unsigned __val = *__first - '0';
3931 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3933 __val = 8 * __val + *__first - '0';
3934 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3935 __val = 8 * __val + *__first++ - '0';
3938 *__str = _CharT(__val);
3940 __push_char(_CharT(__val));
3943 __throw_regex_error<regex_constants::error_escape>();
3947 template <class _CharT, class _Traits>
3948 template <class _ForwardIterator>
3950 basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
3951 _ForwardIterator __last,
3952 __bracket_expression<_CharT, _Traits>* __ml)
3955 // This means =] must exist
3956 value_type _Equal_close[2] = {'=', ']'};
3957 _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close,
3959 if (__temp == __last)
3960 __throw_regex_error<regex_constants::error_brack>();
3961 // [__first, __temp) contains all text in [= ... =]
3962 string_type __collate_name =
3963 __traits_.lookup_collatename(__first, __temp);
3964 if (__collate_name.empty())
3965 __throw_regex_error<regex_constants::error_collate>();
3966 string_type __equiv_name =
3967 __traits_.transform_primary(__collate_name.begin(),
3968 __collate_name.end());
3969 if (!__equiv_name.empty())
3970 __ml->__add_equivalence(__equiv_name);
3973 switch (__collate_name.size())
3976 __ml->__add_char(__collate_name[0]);
3979 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
3982 __throw_regex_error<regex_constants::error_collate>();
3985 __first = _VSTD::next(__temp, 2);
3989 template <class _CharT, class _Traits>
3990 template <class _ForwardIterator>
3992 basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
3993 _ForwardIterator __last,
3994 __bracket_expression<_CharT, _Traits>* __ml)
3997 // This means :] must exist
3998 value_type _Colon_close[2] = {':', ']'};
3999 _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close,
4001 if (__temp == __last)
4002 __throw_regex_error<regex_constants::error_brack>();
4003 // [__first, __temp) contains all text in [: ... :]
4004 typedef typename _Traits::char_class_type char_class_type;
4005 char_class_type __class_type =
4006 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
4007 if (__class_type == 0)
4008 __throw_regex_error<regex_constants::error_brack>();
4009 __ml->__add_class(__class_type);
4010 __first = _VSTD::next(__temp, 2);
4014 template <class _CharT, class _Traits>
4015 template <class _ForwardIterator>
4017 basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
4018 _ForwardIterator __last,
4019 basic_string<_CharT>& __col_sym)
4022 // This means .] must exist
4023 value_type _Dot_close[2] = {'.', ']'};
4024 _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close,
4026 if (__temp == __last)
4027 __throw_regex_error<regex_constants::error_brack>();
4028 // [__first, __temp) contains all text in [. ... .]
4029 __col_sym = __traits_.lookup_collatename(__first, __temp);
4030 switch (__col_sym.size())
4036 __throw_regex_error<regex_constants::error_collate>();
4038 __first = _VSTD::next(__temp, 2);
4042 template <class _CharT, class _Traits>
4043 template <class _ForwardIterator>
4045 basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
4046 _ForwardIterator __last,
4049 if (__first != __last )
4051 int __val = __traits_.value(*__first, 10);
4056 __first != __last && ( __val = __traits_.value(*__first, 10)) != -1;
4067 template <class _CharT, class _Traits>
4068 template <class _ForwardIterator>
4070 basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
4071 _ForwardIterator __last)
4073 __owns_one_state<_CharT>* __sa = __end_;
4074 _ForwardIterator __temp = __parse_alternative(__first, __last);
4075 if (__temp == __first)
4078 while (__first != __last && *__first == '|')
4080 __owns_one_state<_CharT>* __sb = __end_;
4081 __temp = __parse_alternative(++__first, __last);
4082 if (__temp == __first)
4084 __push_alternation(__sa, __sb);
4090 template <class _CharT, class _Traits>
4091 template <class _ForwardIterator>
4093 basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
4094 _ForwardIterator __last)
4098 _ForwardIterator __temp = __parse_term(__first, __last);
4099 if (__temp == __first)
4106 template <class _CharT, class _Traits>
4107 template <class _ForwardIterator>
4109 basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
4110 _ForwardIterator __last)
4112 _ForwardIterator __temp = __parse_assertion(__first, __last);
4113 if (__temp == __first)
4115 __owns_one_state<_CharT>* __e = __end_;
4116 unsigned __mexp_begin = __marked_count_;
4117 __temp = __parse_atom(__first, __last);
4118 if (__temp != __first)
4119 __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
4120 __mexp_begin+1, __marked_count_+1);
4127 template <class _CharT, class _Traits>
4128 template <class _ForwardIterator>
4130 basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
4131 _ForwardIterator __last)
4133 if (__first != __last)
4147 _ForwardIterator __temp = _VSTD::next(__first);
4148 if (__temp != __last)
4152 __push_word_boundary(false);
4155 else if (*__temp == 'B')
4157 __push_word_boundary(true);
4165 _ForwardIterator __temp = _VSTD::next(__first);
4166 if (__temp != __last && *__temp == '?')
4168 if (++__temp != __last)
4175 __exp.__flags_ = __flags_;
4176 __temp = __exp.__parse(++__temp, __last);
4177 unsigned __mexp = __exp.__marked_count_;
4178 __push_lookahead(_VSTD::move(__exp), false, __marked_count_);
4179 __marked_count_ += __mexp;
4180 if (__temp == __last || *__temp != ')')
4181 __throw_regex_error<regex_constants::error_paren>();
4188 __exp.__flags_ = __flags_;
4189 __temp = __exp.__parse(++__temp, __last);
4190 unsigned __mexp = __exp.__marked_count_;
4191 __push_lookahead(_VSTD::move(__exp), true, __marked_count_);
4192 __marked_count_ += __mexp;
4193 if (__temp == __last || *__temp != ')')
4194 __throw_regex_error<regex_constants::error_paren>();
4208 template <class _CharT, class _Traits>
4209 template <class _ForwardIterator>
4211 basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
4212 _ForwardIterator __last)
4214 if (__first != __last)
4219 __push_match_any_but_newline();
4223 __first = __parse_atom_escape(__first, __last);
4226 __first = __parse_bracket_expression(__first, __last);
4231 if (__first == __last)
4232 __throw_regex_error<regex_constants::error_paren>();
4233 _ForwardIterator __temp = _VSTD::next(__first);
4234 if (__temp != __last && *__first == '?' && *__temp == ':')
4237 __first = __parse_ecma_exp(++__temp, __last);
4238 if (__first == __last || *__first != ')')
4239 __throw_regex_error<regex_constants::error_paren>();
4245 __push_begin_marked_subexpression();
4246 unsigned __temp_count = __marked_count_;
4248 __first = __parse_ecma_exp(__first, __last);
4249 if (__first == __last || *__first != ')')
4250 __throw_regex_error<regex_constants::error_paren>();
4251 __push_end_marked_subexpression(__temp_count);
4261 __throw_regex_error<regex_constants::error_badrepeat>();
4264 __first = __parse_pattern_character(__first, __last);
4271 template <class _CharT, class _Traits>
4272 template <class _ForwardIterator>
4274 basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
4275 _ForwardIterator __last)
4277 if (__first != __last && *__first == '\\')
4279 _ForwardIterator __t1 = _VSTD::next(__first);
4281 __throw_regex_error<regex_constants::error_escape>();
4283 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
4288 __t2 = __parse_character_class_escape(__t1, __last);
4293 __t2 = __parse_character_escape(__t1, __last);
4302 template <class _CharT, class _Traits>
4303 template <class _ForwardIterator>
4305 basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
4306 _ForwardIterator __last)
4308 if (__first != __last)
4310 if (*__first == '0')
4312 __push_char(_CharT());
4315 else if ('1' <= *__first && *__first <= '9')
4317 unsigned __v = *__first - '0';
4319 __first != __last && '0' <= *__first && *__first <= '9'; ++__first)
4320 __v = 10 * __v + *__first - '0';
4321 if (__v > mark_count())
4322 __throw_regex_error<regex_constants::error_backref>();
4323 __push_back_ref(__v);
4329 template <class _CharT, class _Traits>
4330 template <class _ForwardIterator>
4332 basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
4333 _ForwardIterator __last)
4335 if (__first != __last)
4337 __bracket_expression<_CharT, _Traits>* __ml;
4341 __ml = __start_matching_list(false);
4342 __ml->__add_class(ctype_base::digit);
4346 __ml = __start_matching_list(true);
4347 __ml->__add_class(ctype_base::digit);
4351 __ml = __start_matching_list(false);
4352 __ml->__add_class(ctype_base::space);
4356 __ml = __start_matching_list(true);
4357 __ml->__add_class(ctype_base::space);
4361 __ml = __start_matching_list(false);
4362 __ml->__add_class(ctype_base::alnum);
4363 __ml->__add_char('_');
4367 __ml = __start_matching_list(true);
4368 __ml->__add_class(ctype_base::alnum);
4369 __ml->__add_char('_');
4377 template <class _CharT, class _Traits>
4378 template <class _ForwardIterator>
4380 basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
4381 _ForwardIterator __last,
4382 basic_string<_CharT>* __str)
4384 if (__first != __last)
4386 _ForwardIterator __t;
4393 *__str = _CharT(0xC);
4395 __push_char(_CharT(0xC));
4400 *__str = _CharT(0xA);
4402 __push_char(_CharT(0xA));
4407 *__str = _CharT(0xD);
4409 __push_char(_CharT(0xD));
4414 *__str = _CharT(0x9);
4416 __push_char(_CharT(0x9));
4421 *__str = _CharT(0xB);
4423 __push_char(_CharT(0xB));
4427 if ((__t = _VSTD::next(__first)) != __last)
4429 if (('A' <= *__t && *__t <= 'Z') ||
4430 ('a' <= *__t && *__t <= 'z'))
4433 *__str = _CharT(*__t % 32);
4435 __push_char(_CharT(*__t % 32));
4439 __throw_regex_error<regex_constants::error_escape>();
4442 __throw_regex_error<regex_constants::error_escape>();
4446 if (__first == __last)
4447 __throw_regex_error<regex_constants::error_escape>();
4448 __hd = __traits_.value(*__first, 16);
4450 __throw_regex_error<regex_constants::error_escape>();
4451 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4453 if (__first == __last)
4454 __throw_regex_error<regex_constants::error_escape>();
4455 __hd = __traits_.value(*__first, 16);
4457 __throw_regex_error<regex_constants::error_escape>();
4458 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4462 if (__first == __last)
4463 __throw_regex_error<regex_constants::error_escape>();
4464 __hd = __traits_.value(*__first, 16);
4466 __throw_regex_error<regex_constants::error_escape>();
4467 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4469 if (__first == __last)
4470 __throw_regex_error<regex_constants::error_escape>();
4471 __hd = __traits_.value(*__first, 16);
4473 __throw_regex_error<regex_constants::error_escape>();
4474 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4476 *__str = _CharT(__sum);
4478 __push_char(_CharT(__sum));
4485 __push_char(_CharT(0));
4489 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
4494 __push_char(*__first);
4498 __throw_regex_error<regex_constants::error_escape>();
4505 template <class _CharT, class _Traits>
4506 template <class _ForwardIterator>
4508 basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
4509 _ForwardIterator __last)
4511 if (__first != __last)
4531 __push_char(*__first);
4539 template <class _CharT, class _Traits>
4540 template <class _ForwardIterator>
4542 basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
4543 _ForwardIterator __last)
4545 __owns_one_state<_CharT>* __sa = __end_;
4546 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4547 if (__t1 != __first)
4548 __parse_basic_reg_exp(__first, __t1);
4552 if (__first != __last)
4554 while (__first != __last)
4556 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4557 __owns_one_state<_CharT>* __sb = __end_;
4558 if (__t1 != __first)
4559 __parse_basic_reg_exp(__first, __t1);
4562 __push_alternation(__sa, __sb);
4564 if (__first != __last)
4570 template <class _CharT, class _Traits>
4571 template <class _ForwardIterator>
4573 basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
4574 _ForwardIterator __last)
4576 __owns_one_state<_CharT>* __sa = __end_;
4577 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4578 if (__t1 != __first)
4579 __parse_extended_reg_exp(__first, __t1);
4583 if (__first != __last)
4585 while (__first != __last)
4587 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4588 __owns_one_state<_CharT>* __sb = __end_;
4589 if (__t1 != __first)
4590 __parse_extended_reg_exp(__first, __t1);
4593 __push_alternation(__sa, __sb);
4595 if (__first != __last)
4601 template <class _CharT, class _Traits>
4603 basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
4604 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
4607 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4608 __end_->first() = nullptr;
4609 unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
4610 __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
4612 __s->first() = nullptr;
4614 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
4615 __end_ = __e2->second();
4616 __s->first() = __e2.release();
4620 template <class _CharT, class _Traits>
4622 basic_regex<_CharT, _Traits>::__push_char(value_type __c)
4624 if (flags() & icase)
4625 __end_->first() = new __match_char_icase<_CharT, _Traits>
4626 (__traits_, __c, __end_->first());
4627 else if (flags() & collate)
4628 __end_->first() = new __match_char_collate<_CharT, _Traits>
4629 (__traits_, __c, __end_->first());
4631 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
4632 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4635 template <class _CharT, class _Traits>
4637 basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
4639 if (!(__flags_ & nosubs))
4642 new __begin_marked_subexpression<_CharT>(++__marked_count_,
4644 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4648 template <class _CharT, class _Traits>
4650 basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
4652 if (!(__flags_ & nosubs))
4655 new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4656 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4660 template <class _CharT, class _Traits>
4662 basic_regex<_CharT, _Traits>::__push_l_anchor()
4664 __end_->first() = new __l_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_r_anchor()
4672 __end_->first() = new __r_anchor<_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()
4680 __end_->first() = new __match_any<_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_match_any_but_newline()
4688 __end_->first() = new __match_any_but_newline<_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_empty()
4696 __end_->first() = new __empty_state<_CharT>(__end_->first());
4697 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4700 template <class _CharT, class _Traits>
4702 basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
4704 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
4706 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4709 template <class _CharT, class _Traits>
4711 basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
4713 if (flags() & icase)
4714 __end_->first() = new __back_ref_icase<_CharT, _Traits>
4715 (__traits_, __i, __end_->first());
4716 else if (flags() & collate)
4717 __end_->first() = new __back_ref_collate<_CharT, _Traits>
4718 (__traits_, __i, __end_->first());
4720 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
4721 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4724 template <class _CharT, class _Traits>
4726 basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
4727 __owns_one_state<_CharT>* __ea)
4729 __sa->first() = new __alternate<_CharT>(
4730 static_cast<__owns_one_state<_CharT>*>(__sa->first()),
4731 static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4732 __ea->first() = nullptr;
4733 __ea->first() = new __empty_state<_CharT>(__end_->first());
4734 __end_->first() = nullptr;
4735 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4736 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4739 template <class _CharT, class _Traits>
4740 __bracket_expression<_CharT, _Traits>*
4741 basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
4743 __bracket_expression<_CharT, _Traits>* __r =
4744 new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
4745 __negate, __flags_ & icase,
4746 __flags_ & collate);
4747 __end_->first() = __r;
4752 template <class _CharT, class _Traits>
4754 basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
4758 __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
4759 __end_->first(), __mexp);
4760 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4763 typedef basic_regex<char> regex;
4764 typedef basic_regex<wchar_t> wregex;
4768 template <class _BidirectionalIterator>
4769 class _LIBCPP_TEMPLATE_VIS sub_match
4770 : public pair<_BidirectionalIterator, _BidirectionalIterator>
4773 typedef _BidirectionalIterator iterator;
4774 typedef typename iterator_traits<iterator>::value_type value_type;
4775 typedef typename iterator_traits<iterator>::difference_type difference_type;
4776 typedef basic_string<value_type> string_type;
4780 _LIBCPP_INLINE_VISIBILITY
4781 _LIBCPP_CONSTEXPR sub_match() : matched() {}
4783 _LIBCPP_INLINE_VISIBILITY
4784 difference_type length() const
4785 {return matched ? _VSTD::distance(this->first, this->second) : 0;}
4786 _LIBCPP_INLINE_VISIBILITY
4787 string_type str() const
4788 {return matched ? string_type(this->first, this->second) : string_type();}
4789 _LIBCPP_INLINE_VISIBILITY
4790 operator string_type() const
4793 _LIBCPP_INLINE_VISIBILITY
4794 int compare(const sub_match& __s) const
4795 {return str().compare(__s.str());}
4796 _LIBCPP_INLINE_VISIBILITY
4797 int compare(const string_type& __s) const
4798 {return str().compare(__s);}
4799 _LIBCPP_INLINE_VISIBILITY
4800 int compare(const value_type* __s) const
4801 {return str().compare(__s);}
4804 typedef sub_match<const char*> csub_match;
4805 typedef sub_match<const wchar_t*> wcsub_match;
4806 typedef sub_match<string::const_iterator> ssub_match;
4807 typedef sub_match<wstring::const_iterator> wssub_match;
4809 template <class _BiIter>
4810 inline _LIBCPP_INLINE_VISIBILITY
4812 operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4814 return __x.compare(__y) == 0;
4817 template <class _BiIter>
4818 inline _LIBCPP_INLINE_VISIBILITY
4820 operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4822 return !(__x == __y);
4825 template <class _BiIter>
4826 inline _LIBCPP_INLINE_VISIBILITY
4828 operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4830 return __x.compare(__y) < 0;
4833 template <class _BiIter>
4834 inline _LIBCPP_INLINE_VISIBILITY
4836 operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4838 return !(__y < __x);
4841 template <class _BiIter>
4842 inline _LIBCPP_INLINE_VISIBILITY
4844 operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4846 return !(__x < __y);
4849 template <class _BiIter>
4850 inline _LIBCPP_INLINE_VISIBILITY
4852 operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4857 template <class _BiIter, class _ST, class _SA>
4858 inline _LIBCPP_INLINE_VISIBILITY
4860 operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4861 const sub_match<_BiIter>& __y)
4863 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
4866 template <class _BiIter, class _ST, class _SA>
4867 inline _LIBCPP_INLINE_VISIBILITY
4869 operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4870 const sub_match<_BiIter>& __y)
4872 return !(__x == __y);
4875 template <class _BiIter, class _ST, class _SA>
4876 inline _LIBCPP_INLINE_VISIBILITY
4878 operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4879 const sub_match<_BiIter>& __y)
4881 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
4884 template <class _BiIter, class _ST, class _SA>
4885 inline _LIBCPP_INLINE_VISIBILITY
4887 operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4888 const sub_match<_BiIter>& __y)
4893 template <class _BiIter, class _ST, class _SA>
4894 inline _LIBCPP_INLINE_VISIBILITY
4895 bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4896 const sub_match<_BiIter>& __y)
4898 return !(__x < __y);
4901 template <class _BiIter, class _ST, class _SA>
4902 inline _LIBCPP_INLINE_VISIBILITY
4904 operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4905 const sub_match<_BiIter>& __y)
4907 return !(__y < __x);
4910 template <class _BiIter, class _ST, class _SA>
4911 inline _LIBCPP_INLINE_VISIBILITY
4913 operator==(const sub_match<_BiIter>& __x,
4914 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4916 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
4919 template <class _BiIter, class _ST, class _SA>
4920 inline _LIBCPP_INLINE_VISIBILITY
4922 operator!=(const sub_match<_BiIter>& __x,
4923 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4925 return !(__x == __y);
4928 template <class _BiIter, class _ST, class _SA>
4929 inline _LIBCPP_INLINE_VISIBILITY
4931 operator<(const sub_match<_BiIter>& __x,
4932 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4934 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
4937 template <class _BiIter, class _ST, class _SA>
4938 inline _LIBCPP_INLINE_VISIBILITY
4939 bool operator>(const sub_match<_BiIter>& __x,
4940 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4945 template <class _BiIter, class _ST, class _SA>
4946 inline _LIBCPP_INLINE_VISIBILITY
4948 operator>=(const sub_match<_BiIter>& __x,
4949 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4951 return !(__x < __y);
4954 template <class _BiIter, class _ST, class _SA>
4955 inline _LIBCPP_INLINE_VISIBILITY
4957 operator<=(const sub_match<_BiIter>& __x,
4958 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4960 return !(__y < __x);
4963 template <class _BiIter>
4964 inline _LIBCPP_INLINE_VISIBILITY
4966 operator==(typename iterator_traits<_BiIter>::value_type const* __x,
4967 const sub_match<_BiIter>& __y)
4969 return __y.compare(__x) == 0;
4972 template <class _BiIter>
4973 inline _LIBCPP_INLINE_VISIBILITY
4975 operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
4976 const sub_match<_BiIter>& __y)
4978 return !(__x == __y);
4981 template <class _BiIter>
4982 inline _LIBCPP_INLINE_VISIBILITY
4984 operator<(typename iterator_traits<_BiIter>::value_type const* __x,
4985 const sub_match<_BiIter>& __y)
4987 return __y.compare(__x) > 0;
4990 template <class _BiIter>
4991 inline _LIBCPP_INLINE_VISIBILITY
4993 operator>(typename iterator_traits<_BiIter>::value_type const* __x,
4994 const sub_match<_BiIter>& __y)
4999 template <class _BiIter>
5000 inline _LIBCPP_INLINE_VISIBILITY
5002 operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
5003 const sub_match<_BiIter>& __y)
5005 return !(__x < __y);
5008 template <class _BiIter>
5009 inline _LIBCPP_INLINE_VISIBILITY
5011 operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
5012 const sub_match<_BiIter>& __y)
5014 return !(__y < __x);
5017 template <class _BiIter>
5018 inline _LIBCPP_INLINE_VISIBILITY
5020 operator==(const sub_match<_BiIter>& __x,
5021 typename iterator_traits<_BiIter>::value_type const* __y)
5023 return __x.compare(__y) == 0;
5026 template <class _BiIter>
5027 inline _LIBCPP_INLINE_VISIBILITY
5029 operator!=(const sub_match<_BiIter>& __x,
5030 typename iterator_traits<_BiIter>::value_type const* __y)
5032 return !(__x == __y);
5035 template <class _BiIter>
5036 inline _LIBCPP_INLINE_VISIBILITY
5038 operator<(const sub_match<_BiIter>& __x,
5039 typename iterator_traits<_BiIter>::value_type const* __y)
5041 return __x.compare(__y) < 0;
5044 template <class _BiIter>
5045 inline _LIBCPP_INLINE_VISIBILITY
5047 operator>(const sub_match<_BiIter>& __x,
5048 typename iterator_traits<_BiIter>::value_type const* __y)
5053 template <class _BiIter>
5054 inline _LIBCPP_INLINE_VISIBILITY
5056 operator>=(const sub_match<_BiIter>& __x,
5057 typename iterator_traits<_BiIter>::value_type const* __y)
5059 return !(__x < __y);
5062 template <class _BiIter>
5063 inline _LIBCPP_INLINE_VISIBILITY
5065 operator<=(const sub_match<_BiIter>& __x,
5066 typename iterator_traits<_BiIter>::value_type const* __y)
5068 return !(__y < __x);
5071 template <class _BiIter>
5072 inline _LIBCPP_INLINE_VISIBILITY
5074 operator==(typename iterator_traits<_BiIter>::value_type const& __x,
5075 const sub_match<_BiIter>& __y)
5077 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5078 return __y.compare(string_type(1, __x)) == 0;
5081 template <class _BiIter>
5082 inline _LIBCPP_INLINE_VISIBILITY
5084 operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
5085 const sub_match<_BiIter>& __y)
5087 return !(__x == __y);
5090 template <class _BiIter>
5091 inline _LIBCPP_INLINE_VISIBILITY
5093 operator<(typename iterator_traits<_BiIter>::value_type const& __x,
5094 const sub_match<_BiIter>& __y)
5096 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5097 return __y.compare(string_type(1, __x)) > 0;
5100 template <class _BiIter>
5101 inline _LIBCPP_INLINE_VISIBILITY
5103 operator>(typename iterator_traits<_BiIter>::value_type const& __x,
5104 const sub_match<_BiIter>& __y)
5109 template <class _BiIter>
5110 inline _LIBCPP_INLINE_VISIBILITY
5112 operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
5113 const sub_match<_BiIter>& __y)
5115 return !(__x < __y);
5118 template <class _BiIter>
5119 inline _LIBCPP_INLINE_VISIBILITY
5121 operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
5122 const sub_match<_BiIter>& __y)
5124 return !(__y < __x);
5127 template <class _BiIter>
5128 inline _LIBCPP_INLINE_VISIBILITY
5130 operator==(const sub_match<_BiIter>& __x,
5131 typename iterator_traits<_BiIter>::value_type const& __y)
5133 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5134 return __x.compare(string_type(1, __y)) == 0;
5137 template <class _BiIter>
5138 inline _LIBCPP_INLINE_VISIBILITY
5140 operator!=(const sub_match<_BiIter>& __x,
5141 typename iterator_traits<_BiIter>::value_type const& __y)
5143 return !(__x == __y);
5146 template <class _BiIter>
5147 inline _LIBCPP_INLINE_VISIBILITY
5149 operator<(const sub_match<_BiIter>& __x,
5150 typename iterator_traits<_BiIter>::value_type const& __y)
5152 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5153 return __x.compare(string_type(1, __y)) < 0;
5156 template <class _BiIter>
5157 inline _LIBCPP_INLINE_VISIBILITY
5159 operator>(const sub_match<_BiIter>& __x,
5160 typename iterator_traits<_BiIter>::value_type const& __y)
5165 template <class _BiIter>
5166 inline _LIBCPP_INLINE_VISIBILITY
5168 operator>=(const sub_match<_BiIter>& __x,
5169 typename iterator_traits<_BiIter>::value_type const& __y)
5171 return !(__x < __y);
5174 template <class _BiIter>
5175 inline _LIBCPP_INLINE_VISIBILITY
5177 operator<=(const sub_match<_BiIter>& __x,
5178 typename iterator_traits<_BiIter>::value_type const& __y)
5180 return !(__y < __x);
5183 template <class _CharT, class _ST, class _BiIter>
5184 inline _LIBCPP_INLINE_VISIBILITY
5185 basic_ostream<_CharT, _ST>&
5186 operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
5188 return __os << __m.str();
5191 template <class _BidirectionalIterator, class _Allocator>
5192 class _LIBCPP_TEMPLATE_VIS match_results
5195 typedef _Allocator allocator_type;
5196 typedef sub_match<_BidirectionalIterator> value_type;
5198 typedef vector<value_type, allocator_type> __container_type;
5200 __container_type __matches_;
5201 value_type __unmatched_;
5202 value_type __prefix_;
5203 value_type __suffix_;
5206 _BidirectionalIterator __position_start_;
5207 typedef const value_type& const_reference;
5208 typedef value_type& reference;
5209 typedef typename __container_type::const_iterator const_iterator;
5210 typedef const_iterator iterator;
5211 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
5212 typedef typename allocator_traits<allocator_type>::size_type size_type;
5213 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
5214 typedef basic_string<char_type> string_type;
5216 // construct/copy/destroy:
5217 explicit match_results(const allocator_type& __a = allocator_type());
5218 // match_results(const match_results&) = default;
5219 // match_results& operator=(const match_results&) = default;
5220 // match_results(match_results&& __m) = default;
5221 // match_results& operator=(match_results&& __m) = default;
5222 // ~match_results() = default;
5224 _LIBCPP_INLINE_VISIBILITY
5225 bool ready() const {return __ready_;}
5228 _LIBCPP_INLINE_VISIBILITY
5229 size_type size() const {return __matches_.size();}
5230 _LIBCPP_INLINE_VISIBILITY
5231 size_type max_size() const {return __matches_.max_size();}
5232 _LIBCPP_INLINE_VISIBILITY
5233 bool empty() const {return size() == 0;}
5236 _LIBCPP_INLINE_VISIBILITY
5237 difference_type length(size_type __sub = 0) const
5238 {return (*this)[__sub].length();}
5239 _LIBCPP_INLINE_VISIBILITY
5240 difference_type position(size_type __sub = 0) const
5241 {return _VSTD::distance(__position_start_, (*this)[__sub].first);}
5242 _LIBCPP_INLINE_VISIBILITY
5243 string_type str(size_type __sub = 0) const
5244 {return (*this)[__sub].str();}
5245 _LIBCPP_INLINE_VISIBILITY
5246 const_reference operator[](size_type __n) const
5247 {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
5249 _LIBCPP_INLINE_VISIBILITY
5250 const_reference prefix() const {return __prefix_;}
5251 _LIBCPP_INLINE_VISIBILITY
5252 const_reference suffix() const {return __suffix_;}
5254 _LIBCPP_INLINE_VISIBILITY
5255 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();}
5256 _LIBCPP_INLINE_VISIBILITY
5257 const_iterator end() const {return __matches_.end();}
5258 _LIBCPP_INLINE_VISIBILITY
5259 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();}
5260 _LIBCPP_INLINE_VISIBILITY
5261 const_iterator cend() const {return __matches_.end();}
5264 template <class _OutputIter>
5266 format(_OutputIter __output, const char_type* __fmt_first,
5267 const char_type* __fmt_last,
5268 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
5269 template <class _OutputIter, class _ST, class _SA>
5270 _LIBCPP_INLINE_VISIBILITY
5272 format(_OutputIter __output, const basic_string<char_type, _ST, _SA>& __fmt,
5273 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5274 {return format(__output, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
5275 template <class _ST, class _SA>
5276 _LIBCPP_INLINE_VISIBILITY
5277 basic_string<char_type, _ST, _SA>
5278 format(const basic_string<char_type, _ST, _SA>& __fmt,
5279 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5281 basic_string<char_type, _ST, _SA> __r;
5282 format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
5286 _LIBCPP_INLINE_VISIBILITY
5288 format(const char_type* __fmt,
5289 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5292 format(back_inserter(__r), __fmt,
5293 __fmt + char_traits<char_type>::length(__fmt), __flags);
5298 _LIBCPP_INLINE_VISIBILITY
5299 allocator_type get_allocator() const {return __matches_.get_allocator();}
5302 void swap(match_results& __m);
5304 template <class _Bp, class _Ap>
5305 _LIBCPP_INLINE_VISIBILITY
5306 void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
5307 const match_results<_Bp, _Ap>& __m, bool __no_update_pos)
5309 _Bp __mf = __m.prefix().first;
5310 __matches_.resize(__m.size());
5311 for (size_type __i = 0; __i < __matches_.size(); ++__i)
5313 __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first));
5314 __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second));
5315 __matches_[__i].matched = __m[__i].matched;
5317 __unmatched_.first = __l;
5318 __unmatched_.second = __l;
5319 __unmatched_.matched = false;
5320 __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first));
5321 __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second));
5322 __prefix_.matched = __m.prefix().matched;
5323 __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first));
5324 __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second));
5325 __suffix_.matched = __m.suffix().matched;
5326 if (!__no_update_pos)
5327 __position_start_ = __prefix_.first;
5328 __ready_ = __m.ready();
5332 void __init(unsigned __s,
5333 _BidirectionalIterator __f, _BidirectionalIterator __l,
5334 bool __no_update_pos = false);
5336 template <class, class> friend class basic_regex;
5338 template <class _Bp, class _Ap, class _Cp, class _Tp>
5341 regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
5342 regex_constants::match_flag_type);
5344 template <class _Bp, class _Ap>
5347 operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
5349 template <class, class> friend class __lookahead;
5352 template <class _BidirectionalIterator, class _Allocator>
5353 match_results<_BidirectionalIterator, _Allocator>::match_results(
5354 const allocator_type& __a)
5364 template <class _BidirectionalIterator, class _Allocator>
5366 match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
5367 _BidirectionalIterator __f, _BidirectionalIterator __l,
5368 bool __no_update_pos)
5370 __unmatched_.first = __l;
5371 __unmatched_.second = __l;
5372 __unmatched_.matched = false;
5373 __matches_.assign(__s, __unmatched_);
5374 __prefix_.first = __f;
5375 __prefix_.second = __f;
5376 __prefix_.matched = false;
5377 __suffix_ = __unmatched_;
5378 if (!__no_update_pos)
5379 __position_start_ = __prefix_.first;
5383 template <class _BidirectionalIterator, class _Allocator>
5384 template <class _OutputIter>
5386 match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output,
5387 const char_type* __fmt_first, const char_type* __fmt_last,
5388 regex_constants::match_flag_type __flags) const
5390 if (__flags & regex_constants::format_sed)
5392 for (; __fmt_first != __fmt_last; ++__fmt_first)
5394 if (*__fmt_first == '&')
5395 __output = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5397 else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
5400 if ('0' <= *__fmt_first && *__fmt_first <= '9')
5402 size_t __i = *__fmt_first - '0';
5403 __output = _VSTD::copy((*this)[__i].first,
5404 (*this)[__i].second, __output);
5408 *__output = *__fmt_first;
5414 *__output = *__fmt_first;
5421 for (; __fmt_first != __fmt_last; ++__fmt_first)
5423 if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
5425 switch (__fmt_first[1])
5428 *__output = *++__fmt_first;
5433 __output = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5438 __output = _VSTD::copy(__prefix_.first, __prefix_.second, __output);
5442 __output = _VSTD::copy(__suffix_.first, __suffix_.second, __output);
5445 if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5448 size_t __i = *__fmt_first - '0';
5449 if (__fmt_first + 1 != __fmt_last &&
5450 '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5453 __i = 10 * __i + *__fmt_first - '0';
5455 __output = _VSTD::copy((*this)[__i].first,
5456 (*this)[__i].second, __output);
5460 *__output = *__fmt_first;
5468 *__output = *__fmt_first;
5476 template <class _BidirectionalIterator, class _Allocator>
5478 match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
5481 swap(__matches_, __m.__matches_);
5482 swap(__unmatched_, __m.__unmatched_);
5483 swap(__prefix_, __m.__prefix_);
5484 swap(__suffix_, __m.__suffix_);
5485 swap(__position_start_, __m.__position_start_);
5486 swap(__ready_, __m.__ready_);
5489 typedef match_results<const char*> cmatch;
5490 typedef match_results<const wchar_t*> wcmatch;
5491 typedef match_results<string::const_iterator> smatch;
5492 typedef match_results<wstring::const_iterator> wsmatch;
5494 template <class _BidirectionalIterator, class _Allocator>
5496 operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
5497 const match_results<_BidirectionalIterator, _Allocator>& __y)
5499 if (__x.__ready_ != __y.__ready_)
5503 return __x.__matches_ == __y.__matches_ &&
5504 __x.__prefix_ == __y.__prefix_ &&
5505 __x.__suffix_ == __y.__suffix_;
5508 template <class _BidirectionalIterator, class _Allocator>
5509 inline _LIBCPP_INLINE_VISIBILITY
5511 operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
5512 const match_results<_BidirectionalIterator, _Allocator>& __y)
5514 return !(__x == __y);
5517 template <class _BidirectionalIterator, class _Allocator>
5518 inline _LIBCPP_INLINE_VISIBILITY
5520 swap(match_results<_BidirectionalIterator, _Allocator>& __x,
5521 match_results<_BidirectionalIterator, _Allocator>& __y)
5528 template <class _CharT, class _Traits>
5529 template <class _Allocator>
5531 basic_regex<_CharT, _Traits>::__match_at_start_ecma(
5532 const _CharT* __first, const _CharT* __last,
5533 match_results<const _CharT*, _Allocator>& __m,
5534 regex_constants::match_flag_type __flags, bool __at_first) const
5536 vector<__state> __states;
5537 __node* __st = __start_.get();
5540 sub_match<const _CharT*> __unmatched;
5541 __unmatched.first = __last;
5542 __unmatched.second = __last;
5543 __unmatched.matched = false;
5545 __states.push_back(__state());
5546 __states.back().__do_ = 0;
5547 __states.back().__first_ = __first;
5548 __states.back().__current_ = __first;
5549 __states.back().__last_ = __last;
5550 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
5551 __states.back().__loop_data_.resize(__loop_count());
5552 __states.back().__node_ = __st;
5553 __states.back().__flags_ = __flags;
5554 __states.back().__at_first_ = __at_first;
5557 __state& __s = __states.back();
5559 __s.__node_->__exec(__s);
5562 case __state::__end_state:
5563 if ((__flags & regex_constants::match_not_null) &&
5564 __s.__current_ == __first)
5566 __states.pop_back();
5569 if ((__flags & regex_constants::__full_match) &&
5570 __s.__current_ != __last)
5572 __states.pop_back();
5575 __m.__matches_[0].first = __first;
5576 __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
5577 __m.__matches_[0].matched = true;
5578 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
5579 __m.__matches_[__i+1] = __s.__sub_matches_[__i];
5581 case __state::__accept_and_consume:
5582 case __state::__repeat:
5583 case __state::__accept_but_not_consume:
5585 case __state::__split:
5587 __state __snext = __s;
5588 __s.__node_->__exec_split(true, __s);
5589 __snext.__node_->__exec_split(false, __snext);
5590 __states.push_back(_VSTD::move(__snext));
5593 case __state::__reject:
5594 __states.pop_back();
5597 __throw_regex_error<regex_constants::__re_err_unknown>();
5601 } while (!__states.empty());
5606 template <class _CharT, class _Traits>
5607 template <class _Allocator>
5609 basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
5610 const _CharT* __first, const _CharT* __last,
5611 match_results<const _CharT*, _Allocator>& __m,
5612 regex_constants::match_flag_type __flags, bool __at_first) const
5614 deque<__state> __states;
5615 ptrdiff_t __highest_j = 0;
5616 ptrdiff_t _Np = _VSTD::distance(__first, __last);
5617 __node* __st = __start_.get();
5620 __states.push_back(__state());
5621 __states.back().__do_ = 0;
5622 __states.back().__first_ = __first;
5623 __states.back().__current_ = __first;
5624 __states.back().__last_ = __last;
5625 __states.back().__loop_data_.resize(__loop_count());
5626 __states.back().__node_ = __st;
5627 __states.back().__flags_ = __flags;
5628 __states.back().__at_first_ = __at_first;
5629 bool __matched = false;
5632 __state& __s = __states.back();
5634 __s.__node_->__exec(__s);
5637 case __state::__end_state:
5638 if ((__flags & regex_constants::match_not_null) &&
5639 __s.__current_ == __first)
5641 __states.pop_back();
5644 if ((__flags & regex_constants::__full_match) &&
5645 __s.__current_ != __last)
5647 __states.pop_back();
5650 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
5651 __highest_j = __s.__current_ - __s.__first_;
5653 if (__highest_j == _Np)
5656 __states.pop_back();
5658 case __state::__consume_input:
5660 case __state::__accept_and_consume:
5661 __states.push_front(_VSTD::move(__s));
5662 __states.pop_back();
5664 case __state::__repeat:
5665 case __state::__accept_but_not_consume:
5667 case __state::__split:
5669 __state __snext = __s;
5670 __s.__node_->__exec_split(true, __s);
5671 __snext.__node_->__exec_split(false, __snext);
5672 __states.push_back(_VSTD::move(__snext));
5675 case __state::__reject:
5676 __states.pop_back();
5679 __throw_regex_error<regex_constants::__re_err_unknown>();
5682 } while (!__states.empty());
5685 __m.__matches_[0].first = __first;
5686 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
5687 __m.__matches_[0].matched = true;
5694 template <class _CharT, class _Traits>
5695 template <class _Allocator>
5697 basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
5698 const _CharT* __first, const _CharT* __last,
5699 match_results<const _CharT*, _Allocator>& __m,
5700 regex_constants::match_flag_type __flags, bool __at_first) const
5702 vector<__state> __states;
5703 __state __best_state;
5705 ptrdiff_t __highest_j = 0;
5706 ptrdiff_t _Np = _VSTD::distance(__first, __last);
5707 __node* __st = __start_.get();
5710 sub_match<const _CharT*> __unmatched;
5711 __unmatched.first = __last;
5712 __unmatched.second = __last;
5713 __unmatched.matched = false;
5715 __states.push_back(__state());
5716 __states.back().__do_ = 0;
5717 __states.back().__first_ = __first;
5718 __states.back().__current_ = __first;
5719 __states.back().__last_ = __last;
5720 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
5721 __states.back().__loop_data_.resize(__loop_count());
5722 __states.back().__node_ = __st;
5723 __states.back().__flags_ = __flags;
5724 __states.back().__at_first_ = __at_first;
5725 const _CharT* __current = __first;
5726 bool __matched = false;
5729 __state& __s = __states.back();
5731 __s.__node_->__exec(__s);
5734 case __state::__end_state:
5735 if ((__flags & regex_constants::match_not_null) &&
5736 __s.__current_ == __first)
5738 __states.pop_back();
5741 if ((__flags & regex_constants::__full_match) &&
5742 __s.__current_ != __last)
5744 __states.pop_back();
5747 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
5749 __highest_j = __s.__current_ - __s.__first_;
5753 if (__highest_j == _Np)
5756 __states.pop_back();
5758 case __state::__accept_and_consume:
5759 __j += __s.__current_ - __current;
5760 __current = __s.__current_;
5762 case __state::__repeat:
5763 case __state::__accept_but_not_consume:
5765 case __state::__split:
5767 __state __snext = __s;
5768 __s.__node_->__exec_split(true, __s);
5769 __snext.__node_->__exec_split(false, __snext);
5770 __states.push_back(_VSTD::move(__snext));
5773 case __state::__reject:
5774 __states.pop_back();
5777 __throw_regex_error<regex_constants::__re_err_unknown>();
5780 } while (!__states.empty());
5783 __m.__matches_[0].first = __first;
5784 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
5785 __m.__matches_[0].matched = true;
5786 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
5787 __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
5794 template <class _CharT, class _Traits>
5795 template <class _Allocator>
5797 basic_regex<_CharT, _Traits>::__match_at_start(
5798 const _CharT* __first, const _CharT* __last,
5799 match_results<const _CharT*, _Allocator>& __m,
5800 regex_constants::match_flag_type __flags, bool __at_first) const
5802 if ((__flags_ & 0x1F0) == ECMAScript)
5803 return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
5804 if (mark_count() == 0)
5805 return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
5806 return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
5809 template <class _CharT, class _Traits>
5810 template <class _Allocator>
5812 basic_regex<_CharT, _Traits>::__search(
5813 const _CharT* __first, const _CharT* __last,
5814 match_results<const _CharT*, _Allocator>& __m,
5815 regex_constants::match_flag_type __flags) const
5817 __m.__init(1 + mark_count(), __first, __last,
5818 __flags & regex_constants::__no_update_pos);
5819 if (__match_at_start(__first, __last, __m, __flags,
5820 !(__flags & regex_constants::__no_update_pos)))
5822 __m.__prefix_.second = __m[0].first;
5823 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5824 __m.__suffix_.first = __m[0].second;
5825 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5828 if (__first != __last && !(__flags & regex_constants::match_continuous))
5830 __flags |= regex_constants::match_prev_avail;
5831 for (++__first; __first != __last; ++__first)
5833 __m.__matches_.assign(__m.size(), __m.__unmatched_);
5834 if (__match_at_start(__first, __last, __m, __flags, false))
5836 __m.__prefix_.second = __m[0].first;
5837 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5838 __m.__suffix_.first = __m[0].second;
5839 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5842 __m.__matches_.assign(__m.size(), __m.__unmatched_);
5845 __m.__matches_.clear();
5849 template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5850 inline _LIBCPP_INLINE_VISIBILITY
5852 regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5853 match_results<_BidirectionalIterator, _Allocator>& __m,
5854 const basic_regex<_CharT, _Traits>& __e,
5855 regex_constants::match_flag_type __flags = regex_constants::match_default)
5857 int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
5858 basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last);
5859 match_results<const _CharT*> __mc;
5860 bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
5861 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
5865 template <class _Iter, class _Allocator, class _CharT, class _Traits>
5866 inline _LIBCPP_INLINE_VISIBILITY
5868 regex_search(__wrap_iter<_Iter> __first,
5869 __wrap_iter<_Iter> __last,
5870 match_results<__wrap_iter<_Iter>, _Allocator>& __m,
5871 const basic_regex<_CharT, _Traits>& __e,
5872 regex_constants::match_flag_type __flags = regex_constants::match_default)
5874 match_results<const _CharT*> __mc;
5875 bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
5876 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
5880 template <class _Allocator, class _CharT, class _Traits>
5881 inline _LIBCPP_INLINE_VISIBILITY
5883 regex_search(const _CharT* __first, const _CharT* __last,
5884 match_results<const _CharT*, _Allocator>& __m,
5885 const basic_regex<_CharT, _Traits>& __e,
5886 regex_constants::match_flag_type __flags = regex_constants::match_default)
5888 return __e.__search(__first, __last, __m, __flags);
5891 template <class _BidirectionalIterator, class _CharT, class _Traits>
5892 inline _LIBCPP_INLINE_VISIBILITY
5894 regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5895 const basic_regex<_CharT, _Traits>& __e,
5896 regex_constants::match_flag_type __flags = regex_constants::match_default)
5898 basic_string<_CharT> __s(__first, __last);
5899 match_results<const _CharT*> __mc;
5900 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5903 template <class _CharT, class _Traits>
5904 inline _LIBCPP_INLINE_VISIBILITY
5906 regex_search(const _CharT* __first, const _CharT* __last,
5907 const basic_regex<_CharT, _Traits>& __e,
5908 regex_constants::match_flag_type __flags = regex_constants::match_default)
5910 match_results<const _CharT*> __mc;
5911 return __e.__search(__first, __last, __mc, __flags);
5914 template <class _CharT, class _Allocator, class _Traits>
5915 inline _LIBCPP_INLINE_VISIBILITY
5917 regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5918 const basic_regex<_CharT, _Traits>& __e,
5919 regex_constants::match_flag_type __flags = regex_constants::match_default)
5921 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
5924 template <class _CharT, class _Traits>
5925 inline _LIBCPP_INLINE_VISIBILITY
5927 regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5928 regex_constants::match_flag_type __flags = regex_constants::match_default)
5930 match_results<const _CharT*> __m;
5931 return _VSTD::regex_search(__str, __m, __e, __flags);
5934 template <class _ST, class _SA, class _CharT, class _Traits>
5935 inline _LIBCPP_INLINE_VISIBILITY
5937 regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5938 const basic_regex<_CharT, _Traits>& __e,
5939 regex_constants::match_flag_type __flags = regex_constants::match_default)
5941 match_results<const _CharT*> __mc;
5942 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5945 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5946 inline _LIBCPP_INLINE_VISIBILITY
5948 regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5949 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5950 const basic_regex<_CharT, _Traits>& __e,
5951 regex_constants::match_flag_type __flags = regex_constants::match_default)
5953 match_results<const _CharT*> __mc;
5954 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5955 __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
5959 #if _LIBCPP_STD_VER > 11
5960 template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
5962 regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
5963 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
5964 const basic_regex<_Cp, _Tp>& __e,
5965 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5970 template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5972 regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5973 match_results<_BidirectionalIterator, _Allocator>& __m,
5974 const basic_regex<_CharT, _Traits>& __e,
5975 regex_constants::match_flag_type __flags = regex_constants::match_default)
5977 bool __r = _VSTD::regex_search(
5978 __first, __last, __m, __e,
5979 __flags | regex_constants::match_continuous |
5980 regex_constants::__full_match);
5983 __r = !__m.suffix().matched;
5985 __m.__matches_.clear();
5990 template <class _BidirectionalIterator, class _CharT, class _Traits>
5991 inline _LIBCPP_INLINE_VISIBILITY
5993 regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5994 const basic_regex<_CharT, _Traits>& __e,
5995 regex_constants::match_flag_type __flags = regex_constants::match_default)
5997 match_results<_BidirectionalIterator> __m;
5998 return _VSTD::regex_match(__first, __last, __m, __e, __flags);
6001 template <class _CharT, class _Allocator, class _Traits>
6002 inline _LIBCPP_INLINE_VISIBILITY
6004 regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
6005 const basic_regex<_CharT, _Traits>& __e,
6006 regex_constants::match_flag_type __flags = regex_constants::match_default)
6008 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
6011 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
6012 inline _LIBCPP_INLINE_VISIBILITY
6014 regex_match(const basic_string<_CharT, _ST, _SA>& __s,
6015 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
6016 const basic_regex<_CharT, _Traits>& __e,
6017 regex_constants::match_flag_type __flags = regex_constants::match_default)
6019 return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
6022 #if _LIBCPP_STD_VER > 11
6023 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
6024 inline _LIBCPP_INLINE_VISIBILITY
6026 regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
6027 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
6028 const basic_regex<_CharT, _Traits>& __e,
6029 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
6032 template <class _CharT, class _Traits>
6033 inline _LIBCPP_INLINE_VISIBILITY
6035 regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
6036 regex_constants::match_flag_type __flags = regex_constants::match_default)
6038 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
6041 template <class _ST, class _SA, class _CharT, class _Traits>
6042 inline _LIBCPP_INLINE_VISIBILITY
6044 regex_match(const basic_string<_CharT, _ST, _SA>& __s,
6045 const basic_regex<_CharT, _Traits>& __e,
6046 regex_constants::match_flag_type __flags = regex_constants::match_default)
6048 return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags);
6053 template <class _BidirectionalIterator,
6054 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6055 class _Traits = regex_traits<_CharT> >
6056 class _LIBCPP_TEMPLATE_VIS regex_iterator
6059 typedef basic_regex<_CharT, _Traits> regex_type;
6060 typedef match_results<_BidirectionalIterator> value_type;
6061 typedef ptrdiff_t difference_type;
6062 typedef const value_type* pointer;
6063 typedef const value_type& reference;
6064 typedef forward_iterator_tag iterator_category;
6067 _BidirectionalIterator __begin_;
6068 _BidirectionalIterator __end_;
6069 const regex_type* __pregex_;
6070 regex_constants::match_flag_type __flags_;
6071 value_type __match_;
6075 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6076 const regex_type& __re,
6077 regex_constants::match_flag_type __m
6078 = regex_constants::match_default);
6079 #if _LIBCPP_STD_VER > 11
6080 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6081 const regex_type&& __re,
6082 regex_constants::match_flag_type __m
6083 = regex_constants::match_default) = delete;
6086 bool operator==(const regex_iterator& __x) const;
6087 _LIBCPP_INLINE_VISIBILITY
6088 bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
6090 _LIBCPP_INLINE_VISIBILITY
6091 reference operator*() const {return __match_;}
6092 _LIBCPP_INLINE_VISIBILITY
6093 pointer operator->() const {return &__match_;}
6095 regex_iterator& operator++();
6096 _LIBCPP_INLINE_VISIBILITY
6097 regex_iterator operator++(int)
6099 regex_iterator __t(*this);
6105 template <class _BidirectionalIterator, class _CharT, class _Traits>
6106 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
6107 : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
6111 template <class _BidirectionalIterator, class _CharT, class _Traits>
6112 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6113 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6114 const regex_type& __re, regex_constants::match_flag_type __m)
6120 _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
6123 template <class _BidirectionalIterator, class _CharT, class _Traits>
6125 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6126 operator==(const regex_iterator& __x) const
6128 if (__match_.empty() && __x.__match_.empty())
6130 if (__match_.empty() || __x.__match_.empty())
6132 return __begin_ == __x.__begin_ &&
6133 __end_ == __x.__end_ &&
6134 __pregex_ == __x.__pregex_ &&
6135 __flags_ == __x.__flags_ &&
6136 __match_[0] == __x.__match_[0];
6139 template <class _BidirectionalIterator, class _CharT, class _Traits>
6140 regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
6141 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6143 __flags_ |= regex_constants::__no_update_pos;
6144 _BidirectionalIterator __start = __match_[0].second;
6145 if (__match_[0].first == __match_[0].second)
6147 if (__start == __end_)
6149 __match_ = value_type();
6152 else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_,
6153 __flags_ | regex_constants::match_not_null |
6154 regex_constants::match_continuous))
6159 __flags_ |= regex_constants::match_prev_avail;
6160 if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
6161 __match_ = value_type();
6165 typedef regex_iterator<const char*> cregex_iterator;
6166 typedef regex_iterator<const wchar_t*> wcregex_iterator;
6167 typedef regex_iterator<string::const_iterator> sregex_iterator;
6168 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
6170 // regex_token_iterator
6172 template <class _BidirectionalIterator,
6173 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6174 class _Traits = regex_traits<_CharT> >
6175 class _LIBCPP_TEMPLATE_VIS regex_token_iterator
6178 typedef basic_regex<_CharT, _Traits> regex_type;
6179 typedef sub_match<_BidirectionalIterator> value_type;
6180 typedef ptrdiff_t difference_type;
6181 typedef const value_type* pointer;
6182 typedef const value_type& reference;
6183 typedef forward_iterator_tag iterator_category;
6186 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
6188 _Position __position_;
6189 const value_type* __result_;
6190 value_type __suffix_;
6192 vector<int> __subs_;
6195 regex_token_iterator();
6196 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6197 const regex_type& __re, int __submatch = 0,
6198 regex_constants::match_flag_type __m =
6199 regex_constants::match_default);
6200 #if _LIBCPP_STD_VER > 11
6201 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6202 const regex_type&& __re, int __submatch = 0,
6203 regex_constants::match_flag_type __m =
6204 regex_constants::match_default) = delete;
6207 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6208 const regex_type& __re, const vector<int>& __submatches,
6209 regex_constants::match_flag_type __m =
6210 regex_constants::match_default);
6211 #if _LIBCPP_STD_VER > 11
6212 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6213 const regex_type&& __re, const vector<int>& __submatches,
6214 regex_constants::match_flag_type __m =
6215 regex_constants::match_default) = delete;
6218 #ifndef _LIBCPP_CXX03_LANG
6219 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6220 const regex_type& __re,
6221 initializer_list<int> __submatches,
6222 regex_constants::match_flag_type __m =
6223 regex_constants::match_default);
6225 #if _LIBCPP_STD_VER > 11
6226 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6227 const regex_type&& __re,
6228 initializer_list<int> __submatches,
6229 regex_constants::match_flag_type __m =
6230 regex_constants::match_default) = delete;
6232 #endif // _LIBCPP_CXX03_LANG
6233 template <size_t _Np>
6234 regex_token_iterator(_BidirectionalIterator __a,
6235 _BidirectionalIterator __b,
6236 const regex_type& __re,
6237 const int (&__submatches)[_Np],
6238 regex_constants::match_flag_type __m =
6239 regex_constants::match_default);
6240 #if _LIBCPP_STD_VER > 11
6241 template <std::size_t _Np>
6242 regex_token_iterator(_BidirectionalIterator __a,
6243 _BidirectionalIterator __b,
6244 const regex_type&& __re,
6245 const int (&__submatches)[_Np],
6246 regex_constants::match_flag_type __m =
6247 regex_constants::match_default) = delete;
6250 regex_token_iterator(const regex_token_iterator&);
6251 regex_token_iterator& operator=(const regex_token_iterator&);
6253 bool operator==(const regex_token_iterator& __x) const;
6254 _LIBCPP_INLINE_VISIBILITY
6255 bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
6257 _LIBCPP_INLINE_VISIBILITY
6258 const value_type& operator*() const {return *__result_;}
6259 _LIBCPP_INLINE_VISIBILITY
6260 const value_type* operator->() const {return __result_;}
6262 regex_token_iterator& operator++();
6263 _LIBCPP_INLINE_VISIBILITY
6264 regex_token_iterator operator++(int)
6266 regex_token_iterator __t(*this);
6272 void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
6273 void __establish_result () {
6274 if (__subs_[__n_] == -1)
6275 __result_ = &__position_->prefix();
6277 __result_ = &(*__position_)[__subs_[__n_]];
6281 template <class _BidirectionalIterator, class _CharT, class _Traits>
6282 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6283 regex_token_iterator()
6284 : __result_(nullptr),
6290 template <class _BidirectionalIterator, class _CharT, class _Traits>
6292 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6293 __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
6295 if (__position_ != _Position())
6296 __establish_result ();
6297 else if (__subs_[__n_] == -1)
6299 __suffix_.matched = true;
6300 __suffix_.first = __a;
6301 __suffix_.second = __b;
6302 __result_ = &__suffix_;
6305 __result_ = nullptr;
6308 template <class _BidirectionalIterator, class _CharT, class _Traits>
6309 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6310 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6311 const regex_type& __re, int __submatch,
6312 regex_constants::match_flag_type __m)
6313 : __position_(__a, __b, __re, __m),
6315 __subs_(1, __submatch)
6320 template <class _BidirectionalIterator, class _CharT, class _Traits>
6321 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6322 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6323 const regex_type& __re, const vector<int>& __submatches,
6324 regex_constants::match_flag_type __m)
6325 : __position_(__a, __b, __re, __m),
6327 __subs_(__submatches)
6332 #ifndef _LIBCPP_CXX03_LANG
6334 template <class _BidirectionalIterator, class _CharT, class _Traits>
6335 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6336 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6337 const regex_type& __re,
6338 initializer_list<int> __submatches,
6339 regex_constants::match_flag_type __m)
6340 : __position_(__a, __b, __re, __m),
6342 __subs_(__submatches)
6347 #endif // _LIBCPP_CXX03_LANG
6349 template <class _BidirectionalIterator, class _CharT, class _Traits>
6350 template <size_t _Np>
6351 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6352 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6353 const regex_type& __re,
6354 const int (&__submatches)[_Np],
6355 regex_constants::match_flag_type __m)
6356 : __position_(__a, __b, __re, __m),
6358 __subs_(__submatches, __submatches + _Np)
6363 template <class _BidirectionalIterator, class _CharT, class _Traits>
6364 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6365 regex_token_iterator(const regex_token_iterator& __x)
6366 : __position_(__x.__position_),
6367 __result_(__x.__result_),
6368 __suffix_(__x.__suffix_),
6370 __subs_(__x.__subs_)
6372 if (__x.__result_ == &__x.__suffix_)
6373 __result_ = &__suffix_;
6374 else if ( __result_ != nullptr )
6375 __establish_result ();
6378 template <class _BidirectionalIterator, class _CharT, class _Traits>
6379 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6380 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6381 operator=(const regex_token_iterator& __x)
6385 __position_ = __x.__position_;
6386 if (__x.__result_ == &__x.__suffix_)
6387 __result_ = &__suffix_;
6389 __result_ = __x.__result_;
6390 __suffix_ = __x.__suffix_;
6392 __subs_ = __x.__subs_;
6394 if ( __result_ != nullptr && __result_ != &__suffix_ )
6395 __establish_result();
6400 template <class _BidirectionalIterator, class _CharT, class _Traits>
6402 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6403 operator==(const regex_token_iterator& __x) const
6405 if (__result_ == nullptr && __x.__result_ == nullptr)
6407 if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
6408 __suffix_ == __x.__suffix_)
6410 if (__result_ == nullptr || __x.__result_ == nullptr)
6412 if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
6414 return __position_ == __x.__position_ && __n_ == __x.__n_ &&
6415 __subs_ == __x.__subs_;
6418 template <class _BidirectionalIterator, class _CharT, class _Traits>
6419 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6420 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6422 _Position __prev = __position_;
6423 if (__result_ == &__suffix_)
6424 __result_ = nullptr;
6425 else if (static_cast<size_t>(__n_ + 1) < __subs_.size())
6428 __establish_result();
6434 if (__position_ != _Position())
6435 __establish_result();
6438 if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
6439 && __prev->suffix().length() != 0)
6441 __suffix_.matched = true;
6442 __suffix_.first = __prev->suffix().first;
6443 __suffix_.second = __prev->suffix().second;
6444 __result_ = &__suffix_;
6447 __result_ = nullptr;
6453 typedef regex_token_iterator<const char*> cregex_token_iterator;
6454 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
6455 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
6456 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
6460 template <class _OutputIterator, class _BidirectionalIterator,
6461 class _Traits, class _CharT>
6463 regex_replace(_OutputIterator __output,
6464 _BidirectionalIterator __first, _BidirectionalIterator __last,
6465 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6466 regex_constants::match_flag_type __flags = regex_constants::match_default)
6468 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
6469 _Iter __i(__first, __last, __e, __flags);
6473 if (!(__flags & regex_constants::format_no_copy))
6474 __output = _VSTD::copy(__first, __last, __output);
6478 sub_match<_BidirectionalIterator> __lm;
6479 for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
6481 if (!(__flags & regex_constants::format_no_copy))
6482 __output = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output);
6483 __output = __i->format(__output, __fmt, __fmt + __len, __flags);
6484 __lm = __i->suffix();
6485 if (__flags & regex_constants::format_first_only)
6488 if (!(__flags & regex_constants::format_no_copy))
6489 __output = _VSTD::copy(__lm.first, __lm.second, __output);
6494 template <class _OutputIterator, class _BidirectionalIterator,
6495 class _Traits, class _CharT, class _ST, class _SA>
6496 inline _LIBCPP_INLINE_VISIBILITY
6498 regex_replace(_OutputIterator __output,
6499 _BidirectionalIterator __first, _BidirectionalIterator __last,
6500 const basic_regex<_CharT, _Traits>& __e,
6501 const basic_string<_CharT, _ST, _SA>& __fmt,
6502 regex_constants::match_flag_type __flags = regex_constants::match_default)
6504 return _VSTD::regex_replace(__output, __first, __last, __e, __fmt.c_str(), __flags);
6507 template <class _Traits, class _CharT, class _ST, class _SA, class _FST,
6509 inline _LIBCPP_INLINE_VISIBILITY
6510 basic_string<_CharT, _ST, _SA>
6511 regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6512 const basic_regex<_CharT, _Traits>& __e,
6513 const basic_string<_CharT, _FST, _FSA>& __fmt,
6514 regex_constants::match_flag_type __flags = regex_constants::match_default)
6516 basic_string<_CharT, _ST, _SA> __r;
6517 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6518 __fmt.c_str(), __flags);
6522 template <class _Traits, class _CharT, class _ST, class _SA>
6523 inline _LIBCPP_INLINE_VISIBILITY
6524 basic_string<_CharT, _ST, _SA>
6525 regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6526 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6527 regex_constants::match_flag_type __flags = regex_constants::match_default)
6529 basic_string<_CharT, _ST, _SA> __r;
6530 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6535 template <class _Traits, class _CharT, class _ST, class _SA>
6536 inline _LIBCPP_INLINE_VISIBILITY
6537 basic_string<_CharT>
6538 regex_replace(const _CharT* __s,
6539 const basic_regex<_CharT, _Traits>& __e,
6540 const basic_string<_CharT, _ST, _SA>& __fmt,
6541 regex_constants::match_flag_type __flags = regex_constants::match_default)
6543 basic_string<_CharT> __r;
6544 _VSTD::regex_replace(back_inserter(__r), __s,
6545 __s + char_traits<_CharT>::length(__s), __e,
6546 __fmt.c_str(), __flags);
6550 template <class _Traits, class _CharT>
6551 inline _LIBCPP_INLINE_VISIBILITY
6552 basic_string<_CharT>
6553 regex_replace(const _CharT* __s,
6554 const basic_regex<_CharT, _Traits>& __e,
6555 const _CharT* __fmt,
6556 regex_constants::match_flag_type __flags = regex_constants::match_default)
6558 basic_string<_CharT> __r;
6559 _VSTD::regex_replace(back_inserter(__r), __s,
6560 __s + char_traits<_CharT>::length(__s), __e,
6565 _LIBCPP_END_NAMESPACE_STD
6569 #endif // _LIBCPP_REGEX