2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
16 #include <initializer_list>
21 namespace regex_constants
24 enum syntax_option_type
28 optimize = unspecified,
29 collate = unspecified,
30 ECMAScript = unspecified,
32 extended = unspecified,
36 multiline = 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;
146 static constexpr regex_constants::syntax_option_type multiline = regex_constants::multiline;
148 // construct/copy/destroy:
150 explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
151 basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
152 basic_regex(const basic_regex&);
153 basic_regex(basic_regex&&) noexcept;
154 template <class ST, class SA>
155 explicit basic_regex(const basic_string<charT, ST, SA>& p,
156 flag_type f = regex_constants::ECMAScript);
157 template <class ForwardIterator>
158 basic_regex(ForwardIterator first, ForwardIterator last,
159 flag_type f = regex_constants::ECMAScript);
160 basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
164 basic_regex& operator=(const basic_regex&);
165 basic_regex& operator=(basic_regex&&) noexcept;
166 basic_regex& operator=(const charT* ptr);
167 basic_regex& operator=(initializer_list<charT> il);
168 template <class ST, class SA>
169 basic_regex& operator=(const basic_string<charT, ST, SA>& p);
172 basic_regex& assign(const basic_regex& that);
173 basic_regex& assign(basic_regex&& that) noexcept;
174 basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
175 basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
176 template <class string_traits, class A>
177 basic_regex& assign(const basic_string<charT, string_traits, A>& s,
178 flag_type f = regex_constants::ECMAScript);
179 template <class InputIterator>
180 basic_regex& assign(InputIterator first, InputIterator last,
181 flag_type f = regex_constants::ECMAScript);
182 basic_regex& assign(initializer_list<charT>, flag_type f = regex_constants::ECMAScript);
185 unsigned mark_count() const;
186 flag_type flags() const;
189 locale_type imbue(locale_type loc);
190 locale_type getloc() const;
193 void swap(basic_regex&);
196 template<class ForwardIterator>
197 basic_regex(ForwardIterator, ForwardIterator,
198 regex_constants::syntax_option_type = regex_constants::ECMAScript)
199 -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; // C++17
201 typedef basic_regex<char> regex;
202 typedef basic_regex<wchar_t> wregex;
204 template <class charT, class traits>
205 void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
207 template <class BidirectionalIterator>
209 : public pair<BidirectionalIterator, BidirectionalIterator>
212 typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
213 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
214 typedef BidirectionalIterator iterator;
215 typedef basic_string<value_type> string_type;
219 constexpr sub_match();
221 difference_type length() const;
222 operator string_type() const;
223 string_type str() const;
225 int compare(const sub_match& s) const;
226 int compare(const string_type& s) const;
227 int compare(const value_type* s) const;
230 typedef sub_match<const char*> csub_match;
231 typedef sub_match<const wchar_t*> wcsub_match;
232 typedef sub_match<string::const_iterator> ssub_match;
233 typedef sub_match<wstring::const_iterator> wssub_match;
235 template <class BiIter>
237 operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
239 template <class BiIter>
241 operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
243 template <class BiIter>
245 operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
247 template <class BiIter>
249 operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
251 template <class BiIter>
253 operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
255 template <class BiIter>
257 operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
259 template <class BiIter, class ST, class SA>
261 operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
262 const sub_match<BiIter>& rhs);
264 template <class BiIter, class ST, class SA>
266 operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
267 const sub_match<BiIter>& rhs);
269 template <class BiIter, class ST, class SA>
271 operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
272 const sub_match<BiIter>& rhs);
274 template <class BiIter, class ST, class SA>
276 operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
277 const sub_match<BiIter>& rhs);
279 template <class BiIter, class ST, class SA>
280 bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
281 const sub_match<BiIter>& rhs);
283 template <class BiIter, class ST, class SA>
285 operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
286 const sub_match<BiIter>& rhs);
288 template <class BiIter, class ST, class SA>
290 operator==(const sub_match<BiIter>& lhs,
291 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
293 template <class BiIter, class ST, class SA>
295 operator!=(const sub_match<BiIter>& lhs,
296 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
298 template <class BiIter, class ST, class SA>
300 operator<(const sub_match<BiIter>& lhs,
301 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
303 template <class BiIter, class ST, class SA>
304 bool operator>(const sub_match<BiIter>& lhs,
305 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
307 template <class BiIter, class ST, class SA>
309 operator>=(const sub_match<BiIter>& lhs,
310 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
312 template <class BiIter, class ST, class SA>
314 operator<=(const sub_match<BiIter>& lhs,
315 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
317 template <class BiIter>
319 operator==(typename iterator_traits<BiIter>::value_type const* lhs,
320 const sub_match<BiIter>& rhs);
322 template <class BiIter>
324 operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
325 const sub_match<BiIter>& rhs);
327 template <class BiIter>
329 operator<(typename iterator_traits<BiIter>::value_type const* lhs,
330 const sub_match<BiIter>& rhs);
332 template <class BiIter>
334 operator>(typename iterator_traits<BiIter>::value_type const* lhs,
335 const sub_match<BiIter>& rhs);
337 template <class BiIter>
339 operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
340 const sub_match<BiIter>& rhs);
342 template <class BiIter>
344 operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
345 const sub_match<BiIter>& rhs);
347 template <class BiIter>
349 operator==(const sub_match<BiIter>& lhs,
350 typename iterator_traits<BiIter>::value_type const* rhs);
352 template <class BiIter>
354 operator!=(const sub_match<BiIter>& lhs,
355 typename iterator_traits<BiIter>::value_type const* rhs);
357 template <class BiIter>
359 operator<(const sub_match<BiIter>& lhs,
360 typename iterator_traits<BiIter>::value_type const* rhs);
362 template <class BiIter>
364 operator>(const sub_match<BiIter>& lhs,
365 typename iterator_traits<BiIter>::value_type const* rhs);
367 template <class BiIter>
369 operator>=(const sub_match<BiIter>& lhs,
370 typename iterator_traits<BiIter>::value_type const* rhs);
372 template <class BiIter>
374 operator<=(const sub_match<BiIter>& lhs,
375 typename iterator_traits<BiIter>::value_type const* rhs);
377 template <class BiIter>
379 operator==(typename iterator_traits<BiIter>::value_type const& lhs,
380 const sub_match<BiIter>& rhs);
382 template <class BiIter>
384 operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
385 const sub_match<BiIter>& rhs);
387 template <class BiIter>
389 operator<(typename iterator_traits<BiIter>::value_type const& lhs,
390 const sub_match<BiIter>& rhs);
392 template <class BiIter>
394 operator>(typename iterator_traits<BiIter>::value_type const& lhs,
395 const sub_match<BiIter>& rhs);
397 template <class BiIter>
399 operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
400 const sub_match<BiIter>& rhs);
402 template <class BiIter>
404 operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
405 const sub_match<BiIter>& rhs);
407 template <class BiIter>
409 operator==(const sub_match<BiIter>& lhs,
410 typename iterator_traits<BiIter>::value_type const& rhs);
412 template <class BiIter>
414 operator!=(const sub_match<BiIter>& lhs,
415 typename iterator_traits<BiIter>::value_type const& rhs);
417 template <class BiIter>
419 operator<(const sub_match<BiIter>& lhs,
420 typename iterator_traits<BiIter>::value_type const& rhs);
422 template <class BiIter>
424 operator>(const sub_match<BiIter>& lhs,
425 typename iterator_traits<BiIter>::value_type const& rhs);
427 template <class BiIter>
429 operator>=(const sub_match<BiIter>& lhs,
430 typename iterator_traits<BiIter>::value_type const& rhs);
432 template <class BiIter>
434 operator<=(const sub_match<BiIter>& lhs,
435 typename iterator_traits<BiIter>::value_type const& rhs);
437 template <class charT, class ST, class BiIter>
438 basic_ostream<charT, ST>&
439 operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
441 template <class BidirectionalIterator,
442 class Allocator = allocator<sub_match<BidirectionalIterator>>>
446 typedef sub_match<BidirectionalIterator> value_type;
447 typedef const value_type& const_reference;
448 typedef value_type& reference;
449 typedef /implementation-defined/ const_iterator;
450 typedef const_iterator iterator;
451 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
452 typedef typename allocator_traits<Allocator>::size_type size_type;
453 typedef Allocator allocator_type;
454 typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
455 typedef basic_string<char_type> string_type;
457 // construct/copy/destroy:
458 explicit match_results(const Allocator& a = Allocator()); // before C++20
459 match_results() : match_results(Allocator()) {} // C++20
460 explicit match_results(const Allocator& a); // C++20
461 match_results(const match_results& m);
462 match_results(match_results&& m) noexcept;
463 match_results& operator=(const match_results& m);
464 match_results& operator=(match_results&& m);
470 size_type size() const;
471 size_type max_size() const;
475 difference_type length(size_type sub = 0) const;
476 difference_type position(size_type sub = 0) const;
477 string_type str(size_type sub = 0) const;
478 const_reference operator[](size_type n) const;
480 const_reference prefix() const;
481 const_reference suffix() const;
483 const_iterator begin() const;
484 const_iterator end() const;
485 const_iterator cbegin() const;
486 const_iterator cend() const;
489 template <class OutputIter>
491 format(OutputIter out, const char_type* fmt_first,
492 const char_type* fmt_last,
493 regex_constants::match_flag_type flags = regex_constants::format_default) const;
494 template <class OutputIter, class ST, class SA>
496 format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
497 regex_constants::match_flag_type flags = regex_constants::format_default) const;
498 template <class ST, class SA>
499 basic_string<char_type, ST, SA>
500 format(const basic_string<char_type, ST, SA>& fmt,
501 regex_constants::match_flag_type flags = regex_constants::format_default) const;
503 format(const char_type* fmt,
504 regex_constants::match_flag_type flags = regex_constants::format_default) const;
507 allocator_type get_allocator() const;
510 void swap(match_results& that);
513 typedef match_results<const char*> cmatch;
514 typedef match_results<const wchar_t*> wcmatch;
515 typedef match_results<string::const_iterator> smatch;
516 typedef match_results<wstring::const_iterator> wsmatch;
518 template <class BidirectionalIterator, class Allocator>
520 operator==(const match_results<BidirectionalIterator, Allocator>& m1,
521 const match_results<BidirectionalIterator, Allocator>& m2);
523 template <class BidirectionalIterator, class Allocator>
525 operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
526 const match_results<BidirectionalIterator, Allocator>& m2);
528 template <class BidirectionalIterator, class Allocator>
530 swap(match_results<BidirectionalIterator, Allocator>& m1,
531 match_results<BidirectionalIterator, Allocator>& m2);
533 template <class BidirectionalIterator, class Allocator, class charT, class traits>
535 regex_match(BidirectionalIterator first, BidirectionalIterator last,
536 match_results<BidirectionalIterator, Allocator>& m,
537 const basic_regex<charT, traits>& e,
538 regex_constants::match_flag_type flags = regex_constants::match_default);
540 template <class BidirectionalIterator, class charT, class traits>
542 regex_match(BidirectionalIterator first, BidirectionalIterator last,
543 const basic_regex<charT, traits>& e,
544 regex_constants::match_flag_type flags = regex_constants::match_default);
546 template <class charT, class Allocator, class traits>
548 regex_match(const charT* str, match_results<const charT*, Allocator>& m,
549 const basic_regex<charT, traits>& e,
550 regex_constants::match_flag_type flags = regex_constants::match_default);
552 template <class ST, class SA, class Allocator, class charT, class traits>
554 regex_match(const basic_string<charT, ST, SA>& s,
555 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
556 const basic_regex<charT, traits>& e,
557 regex_constants::match_flag_type flags = regex_constants::match_default);
559 template <class ST, class SA, class Allocator, class charT, class traits>
561 regex_match(const basic_string<charT, ST, SA>&& s,
562 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
563 const basic_regex<charT, traits>& e,
564 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
566 template <class charT, class traits>
568 regex_match(const charT* str, const basic_regex<charT, traits>& e,
569 regex_constants::match_flag_type flags = regex_constants::match_default);
571 template <class ST, class SA, class charT, class traits>
573 regex_match(const basic_string<charT, ST, SA>& s,
574 const basic_regex<charT, traits>& e,
575 regex_constants::match_flag_type flags = regex_constants::match_default);
577 template <class BidirectionalIterator, class Allocator, class charT, class traits>
579 regex_search(BidirectionalIterator first, BidirectionalIterator last,
580 match_results<BidirectionalIterator, Allocator>& m,
581 const basic_regex<charT, traits>& e,
582 regex_constants::match_flag_type flags = regex_constants::match_default);
584 template <class BidirectionalIterator, class charT, class traits>
586 regex_search(BidirectionalIterator first, BidirectionalIterator last,
587 const basic_regex<charT, traits>& e,
588 regex_constants::match_flag_type flags = regex_constants::match_default);
590 template <class charT, class Allocator, class traits>
592 regex_search(const charT* str, match_results<const charT*, Allocator>& m,
593 const basic_regex<charT, traits>& e,
594 regex_constants::match_flag_type flags = regex_constants::match_default);
596 template <class charT, class traits>
598 regex_search(const charT* str, const basic_regex<charT, traits>& e,
599 regex_constants::match_flag_type flags = regex_constants::match_default);
601 template <class ST, class SA, class charT, class traits>
603 regex_search(const basic_string<charT, ST, SA>& s,
604 const basic_regex<charT, traits>& e,
605 regex_constants::match_flag_type flags = regex_constants::match_default);
607 template <class ST, class SA, class Allocator, class charT, class traits>
609 regex_search(const basic_string<charT, ST, SA>& s,
610 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
611 const basic_regex<charT, traits>& e,
612 regex_constants::match_flag_type flags = regex_constants::match_default);
614 template <class ST, class SA, class Allocator, class charT, class traits>
616 regex_search(const basic_string<charT, ST, SA>&& s,
617 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
618 const basic_regex<charT, traits>& e,
619 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
621 template <class OutputIterator, class BidirectionalIterator,
622 class traits, class charT, class ST, class SA>
624 regex_replace(OutputIterator out,
625 BidirectionalIterator first, BidirectionalIterator last,
626 const basic_regex<charT, traits>& e,
627 const basic_string<charT, ST, SA>& fmt,
628 regex_constants::match_flag_type flags = regex_constants::match_default);
630 template <class OutputIterator, class BidirectionalIterator,
631 class traits, class charT>
633 regex_replace(OutputIterator out,
634 BidirectionalIterator first, BidirectionalIterator last,
635 const basic_regex<charT, traits>& e, const charT* fmt,
636 regex_constants::match_flag_type flags = regex_constants::match_default);
638 template <class traits, class charT, class ST, class SA, class FST, class FSA>
639 basic_string<charT, ST, SA>
640 regex_replace(const basic_string<charT, ST, SA>& s,
641 const basic_regex<charT, traits>& e,
642 const basic_string<charT, FST, FSA>& fmt,
643 regex_constants::match_flag_type flags = regex_constants::match_default);
645 template <class traits, class charT, class ST, class SA>
646 basic_string<charT, ST, SA>
647 regex_replace(const basic_string<charT, ST, SA>& s,
648 const basic_regex<charT, traits>& e, const charT* fmt,
649 regex_constants::match_flag_type flags = regex_constants::match_default);
651 template <class traits, class charT, class ST, class SA>
653 regex_replace(const charT* s,
654 const basic_regex<charT, traits>& e,
655 const basic_string<charT, ST, SA>& fmt,
656 regex_constants::match_flag_type flags = regex_constants::match_default);
658 template <class traits, class charT>
660 regex_replace(const charT* s,
661 const basic_regex<charT, traits>& e,
663 regex_constants::match_flag_type flags = regex_constants::match_default);
665 template <class BidirectionalIterator,
666 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
667 class traits = regex_traits<charT>>
671 typedef basic_regex<charT, traits> regex_type;
672 typedef match_results<BidirectionalIterator> value_type;
673 typedef ptrdiff_t difference_type;
674 typedef const value_type* pointer;
675 typedef const value_type& reference;
676 typedef forward_iterator_tag iterator_category;
679 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
680 const regex_type& re,
681 regex_constants::match_flag_type m = regex_constants::match_default);
682 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
683 const regex_type&& re,
684 regex_constants::match_flag_type m
685 = regex_constants::match_default) = delete; // C++14
686 regex_iterator(const regex_iterator&);
687 regex_iterator& operator=(const regex_iterator&);
689 bool operator==(const regex_iterator&) const;
690 bool operator!=(const regex_iterator&) const;
692 const value_type& operator*() const;
693 const value_type* operator->() const;
695 regex_iterator& operator++();
696 regex_iterator operator++(int);
699 typedef regex_iterator<const char*> cregex_iterator;
700 typedef regex_iterator<const wchar_t*> wcregex_iterator;
701 typedef regex_iterator<string::const_iterator> sregex_iterator;
702 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
704 template <class BidirectionalIterator,
705 class charT = typename iterator_traits<BidirectionalIterator>::value_type,
706 class traits = regex_traits<charT>>
707 class regex_token_iterator
710 typedef basic_regex<charT, traits> regex_type;
711 typedef sub_match<BidirectionalIterator> value_type;
712 typedef ptrdiff_t difference_type;
713 typedef const value_type* pointer;
714 typedef const value_type& reference;
715 typedef forward_iterator_tag iterator_category;
717 regex_token_iterator();
718 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
719 const regex_type& re, int submatch = 0,
720 regex_constants::match_flag_type m = regex_constants::match_default);
721 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
722 const regex_type&& re, int submatch = 0,
723 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
724 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
725 const regex_type& re, const vector<int>& submatches,
726 regex_constants::match_flag_type m = regex_constants::match_default);
727 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
728 const regex_type&& re, const vector<int>& submatches,
729 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
730 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
731 const regex_type& re, initializer_list<int> submatches,
732 regex_constants::match_flag_type m = regex_constants::match_default);
733 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
734 const regex_type&& re, initializer_list<int> submatches,
735 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
737 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
738 const regex_type& re, const int (&submatches)[N],
739 regex_constants::match_flag_type m = regex_constants::match_default);
741 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
742 const regex_type&& re, const int (&submatches)[N],
743 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
744 regex_token_iterator(const regex_token_iterator&);
745 regex_token_iterator& operator=(const regex_token_iterator&);
747 bool operator==(const regex_token_iterator&) const;
748 bool operator!=(const regex_token_iterator&) const;
750 const value_type& operator*() const;
751 const value_type* operator->() const;
753 regex_token_iterator& operator++();
754 regex_token_iterator operator++(int);
757 typedef regex_token_iterator<const char*> cregex_token_iterator;
758 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
759 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
760 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
767 #include <__iterator/wrap_iter.h>
771 #include <initializer_list>
780 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
781 #pragma GCC system_header
785 #include <__undef_macros>
788 #define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
790 _LIBCPP_BEGIN_NAMESPACE_STD
792 namespace regex_constants
795 // syntax_option_type
797 enum syntax_option_type
803 #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
813 // 1 << 9 may be used by ECMAScript
817 inline _LIBCPP_CONSTEXPR
818 syntax_option_type __get_grammar(syntax_option_type __g)
820 #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
821 return static_cast<syntax_option_type>(__g & 0x3F0);
823 return static_cast<syntax_option_type>(__g & 0x1F0);
827 inline _LIBCPP_INLINE_VISIBILITY
830 operator~(syntax_option_type __x)
832 return syntax_option_type(~int(__x) & 0x1FF);
835 inline _LIBCPP_INLINE_VISIBILITY
838 operator&(syntax_option_type __x, syntax_option_type __y)
840 return syntax_option_type(int(__x) & int(__y));
843 inline _LIBCPP_INLINE_VISIBILITY
846 operator|(syntax_option_type __x, syntax_option_type __y)
848 return syntax_option_type(int(__x) | int(__y));
851 inline _LIBCPP_INLINE_VISIBILITY
854 operator^(syntax_option_type __x, syntax_option_type __y)
856 return syntax_option_type(int(__x) ^ int(__y));
859 inline _LIBCPP_INLINE_VISIBILITY
861 operator&=(syntax_option_type& __x, syntax_option_type __y)
867 inline _LIBCPP_INLINE_VISIBILITY
869 operator|=(syntax_option_type& __x, syntax_option_type __y)
875 inline _LIBCPP_INLINE_VISIBILITY
877 operator^=(syntax_option_type& __x, syntax_option_type __y)
888 match_not_bol = 1 << 0,
889 match_not_eol = 1 << 1,
890 match_not_bow = 1 << 2,
891 match_not_eow = 1 << 3,
893 match_not_null = 1 << 5,
894 match_continuous = 1 << 6,
895 match_prev_avail = 1 << 7,
898 format_no_copy = 1 << 9,
899 format_first_only = 1 << 10,
900 __no_update_pos = 1 << 11,
901 __full_match = 1 << 12
904 inline _LIBCPP_INLINE_VISIBILITY
907 operator~(match_flag_type __x)
909 return match_flag_type(~int(__x) & 0x0FFF);
912 inline _LIBCPP_INLINE_VISIBILITY
915 operator&(match_flag_type __x, match_flag_type __y)
917 return match_flag_type(int(__x) & int(__y));
920 inline _LIBCPP_INLINE_VISIBILITY
923 operator|(match_flag_type __x, match_flag_type __y)
925 return match_flag_type(int(__x) | int(__y));
928 inline _LIBCPP_INLINE_VISIBILITY
931 operator^(match_flag_type __x, match_flag_type __y)
933 return match_flag_type(int(__x) ^ int(__y));
936 inline _LIBCPP_INLINE_VISIBILITY
938 operator&=(match_flag_type& __x, match_flag_type __y)
944 inline _LIBCPP_INLINE_VISIBILITY
946 operator|=(match_flag_type& __x, match_flag_type __y)
952 inline _LIBCPP_INLINE_VISIBILITY
954 operator^=(match_flag_type& __x, match_flag_type __y)
983 class _LIBCPP_EXCEPTION_ABI regex_error
984 : public runtime_error
986 regex_constants::error_type __code_;
988 explicit regex_error(regex_constants::error_type __ecode);
989 regex_error(const regex_error&) _NOEXCEPT = default;
990 virtual ~regex_error() _NOEXCEPT;
991 _LIBCPP_INLINE_VISIBILITY
992 regex_constants::error_type code() const {return __code_;}
995 template <regex_constants::error_type _Ev>
996 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
997 void __throw_regex_error()
999 #ifndef _LIBCPP_NO_EXCEPTIONS
1000 throw regex_error(_Ev);
1006 template <class _CharT>
1007 struct _LIBCPP_TEMPLATE_VIS regex_traits
1010 typedef _CharT char_type;
1011 typedef basic_string<char_type> string_type;
1012 typedef locale locale_type;
1014 // Originally bionic's ctype_base used its own ctype masks because the
1015 // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask
1016 // was only 8 bits wide and already saturated, so it used a wider type here
1017 // to make room for __regex_word (then a part of this class rather than
1018 // ctype_base). Bionic has since moved to the builtin ctype_base
1019 // implementation, but this was not updated to match. Since then Android has
1020 // needed to maintain a stable libc++ ABI, and this can't be changed without
1022 typedef uint16_t char_class_type;
1024 typedef ctype_base::mask char_class_type;
1027 static const char_class_type __regex_word = ctype_base::__regex_word;
1030 const ctype<char_type>* __ct_;
1031 const collate<char_type>* __col_;
1036 _LIBCPP_INLINE_VISIBILITY
1037 static size_t length(const char_type* __p)
1038 {return char_traits<char_type>::length(__p);}
1039 _LIBCPP_INLINE_VISIBILITY
1040 char_type translate(char_type __c) const {return __c;}
1041 char_type translate_nocase(char_type __c) const;
1042 template <class _ForwardIterator>
1044 transform(_ForwardIterator __f, _ForwardIterator __l) const;
1045 template <class _ForwardIterator>
1046 _LIBCPP_INLINE_VISIBILITY
1048 transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
1049 {return __transform_primary(__f, __l, char_type());}
1050 template <class _ForwardIterator>
1051 _LIBCPP_INLINE_VISIBILITY
1053 lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
1054 {return __lookup_collatename(__f, __l, char_type());}
1055 template <class _ForwardIterator>
1056 _LIBCPP_INLINE_VISIBILITY
1058 lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1059 bool __icase = false) const
1060 {return __lookup_classname(__f, __l, __icase, char_type());}
1061 bool isctype(char_type __c, char_class_type __m) const;
1062 _LIBCPP_INLINE_VISIBILITY
1063 int value(char_type __ch, int __radix) const
1064 {return __regex_traits_value(__ch, __radix);}
1065 locale_type imbue(locale_type __l);
1066 _LIBCPP_INLINE_VISIBILITY
1067 locale_type getloc()const {return __loc_;}
1072 template <class _ForwardIterator>
1074 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
1075 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1076 template <class _ForwardIterator>
1078 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1080 template <class _ForwardIterator>
1082 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
1083 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1084 template <class _ForwardIterator>
1086 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1088 template <class _ForwardIterator>
1090 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1091 bool __icase, char) const;
1092 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1093 template <class _ForwardIterator>
1095 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1096 bool __icase, wchar_t) const;
1099 static int __regex_traits_value(unsigned char __ch, int __radix);
1100 _LIBCPP_INLINE_VISIBILITY
1101 int __regex_traits_value(char __ch, int __radix) const
1102 {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
1103 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1104 _LIBCPP_INLINE_VISIBILITY
1105 int __regex_traits_value(wchar_t __ch, int __radix) const;
1109 template <class _CharT>
1110 const typename regex_traits<_CharT>::char_class_type
1111 regex_traits<_CharT>::__regex_word;
1113 template <class _CharT>
1114 regex_traits<_CharT>::regex_traits()
1119 template <class _CharT>
1120 typename regex_traits<_CharT>::char_type
1121 regex_traits<_CharT>::translate_nocase(char_type __c) const
1123 return __ct_->tolower(__c);
1126 template <class _CharT>
1127 template <class _ForwardIterator>
1128 typename regex_traits<_CharT>::string_type
1129 regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
1131 string_type __s(__f, __l);
1132 return __col_->transform(__s.data(), __s.data() + __s.size());
1135 template <class _CharT>
1137 regex_traits<_CharT>::__init()
1139 __ct_ = &use_facet<ctype<char_type> >(__loc_);
1140 __col_ = &use_facet<collate<char_type> >(__loc_);
1143 template <class _CharT>
1144 typename regex_traits<_CharT>::locale_type
1145 regex_traits<_CharT>::imbue(locale_type __l)
1147 locale __r = __loc_;
1153 // transform_primary is very FreeBSD-specific
1155 template <class _CharT>
1156 template <class _ForwardIterator>
1157 typename regex_traits<_CharT>::string_type
1158 regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1159 _ForwardIterator __l, char) const
1161 const string_type __s(__f, __l);
1162 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1177 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1178 template <class _CharT>
1179 template <class _ForwardIterator>
1180 typename regex_traits<_CharT>::string_type
1181 regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1182 _ForwardIterator __l, wchar_t) const
1184 const string_type __s(__f, __l);
1185 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1201 // lookup_collatename is very FreeBSD-specific
1203 _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s);
1205 template <class _CharT>
1206 template <class _ForwardIterator>
1207 typename regex_traits<_CharT>::string_type
1208 regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1209 _ForwardIterator __l, char) const
1211 string_type __s(__f, __l);
1215 __r = __get_collation_name(__s.c_str());
1216 if (__r.empty() && __s.size() <= 2)
1218 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1219 if (__r.size() == 1 || __r.size() == 12)
1228 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1229 template <class _CharT>
1230 template <class _ForwardIterator>
1231 typename regex_traits<_CharT>::string_type
1232 regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1233 _ForwardIterator __l, wchar_t) const
1235 string_type __s(__f, __l);
1237 __n.reserve(__s.size());
1238 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1241 if (static_cast<unsigned>(*__i) >= 127)
1242 return string_type();
1243 __n.push_back(char(*__i));
1248 __n = __get_collation_name(__n.c_str());
1250 __r.assign(__n.begin(), __n.end());
1251 else if (__s.size() <= 2)
1253 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1254 if (__r.size() == 1 || __r.size() == 3)
1262 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1266 regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS
1267 __get_classname(const char* __s, bool __icase);
1269 template <class _CharT>
1270 template <class _ForwardIterator>
1271 typename regex_traits<_CharT>::char_class_type
1272 regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1273 _ForwardIterator __l,
1274 bool __icase, char) const
1276 string_type __s(__f, __l);
1277 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1278 return __get_classname(__s.c_str(), __icase);
1281 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1282 template <class _CharT>
1283 template <class _ForwardIterator>
1284 typename regex_traits<_CharT>::char_class_type
1285 regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1286 _ForwardIterator __l,
1287 bool __icase, wchar_t) const
1289 string_type __s(__f, __l);
1290 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1292 __n.reserve(__s.size());
1293 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1296 if (static_cast<unsigned>(*__i) >= 127)
1297 return char_class_type();
1298 __n.push_back(char(*__i));
1300 return __get_classname(__n.c_str(), __icase);
1302 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1304 template <class _CharT>
1306 regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
1308 if (__ct_->is(__m, __c))
1310 return (__c == '_' && (__m & __regex_word));
1313 template <class _CharT>
1315 regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
1317 if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
1321 if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
1325 __ch |= 0x20; // tolower
1326 if ('a' <= __ch && __ch <= 'f')
1327 return __ch - ('a' - 10);
1333 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1334 template <class _CharT>
1337 regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
1339 return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
1343 template <class _CharT> class __node;
1345 template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match;
1347 template <class _BidirectionalIterator,
1348 class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1349 class _LIBCPP_TEMPLATE_VIS match_results;
1351 template <class _CharT>
1356 __end_state = -1000,
1357 __consume_input, // -999
1358 __begin_marked_expr, // -998
1359 __end_marked_expr, // -997
1360 __pop_state, // -996
1361 __accept_and_consume, // -995
1362 __accept_but_not_consume, // -994
1369 const _CharT* __first_;
1370 const _CharT* __current_;
1371 const _CharT* __last_;
1372 vector<sub_match<const _CharT*> > __sub_matches_;
1373 vector<pair<size_t, const _CharT*> > __loop_data_;
1374 const __node<_CharT>* __node_;
1375 regex_constants::match_flag_type __flags_;
1378 _LIBCPP_INLINE_VISIBILITY
1380 : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
1381 __node_(nullptr), __flags_() {}
1386 template <class _CharT>
1389 __node(const __node&);
1390 __node& operator=(const __node&);
1392 typedef _VSTD::__state<_CharT> __state;
1394 _LIBCPP_INLINE_VISIBILITY
1396 _LIBCPP_INLINE_VISIBILITY
1397 virtual ~__node() {}
1399 _LIBCPP_INLINE_VISIBILITY
1400 virtual void __exec(__state&) const {}
1401 _LIBCPP_INLINE_VISIBILITY
1402 virtual void __exec_split(bool, __state&) const {}
1407 template <class _CharT>
1409 : public __node<_CharT>
1412 typedef _VSTD::__state<_CharT> __state;
1414 _LIBCPP_INLINE_VISIBILITY
1417 virtual void __exec(__state&) const;
1420 template <class _CharT>
1422 __end_state<_CharT>::__exec(__state& __s) const
1424 __s.__do_ = __state::__end_state;
1429 template <class _CharT>
1430 class __has_one_state
1431 : public __node<_CharT>
1433 __node<_CharT>* __first_;
1436 _LIBCPP_INLINE_VISIBILITY
1437 explicit __has_one_state(__node<_CharT>* __s)
1440 _LIBCPP_INLINE_VISIBILITY
1441 __node<_CharT>* first() const {return __first_;}
1442 _LIBCPP_INLINE_VISIBILITY
1443 __node<_CharT>*& first() {return __first_;}
1448 template <class _CharT>
1449 class __owns_one_state
1450 : public __has_one_state<_CharT>
1452 typedef __has_one_state<_CharT> base;
1455 _LIBCPP_INLINE_VISIBILITY
1456 explicit __owns_one_state(__node<_CharT>* __s)
1459 virtual ~__owns_one_state();
1462 template <class _CharT>
1463 __owns_one_state<_CharT>::~__owns_one_state()
1465 delete this->first();
1470 template <class _CharT>
1472 : public __owns_one_state<_CharT>
1474 typedef __owns_one_state<_CharT> base;
1477 typedef _VSTD::__state<_CharT> __state;
1479 _LIBCPP_INLINE_VISIBILITY
1480 explicit __empty_state(__node<_CharT>* __s)
1483 virtual void __exec(__state&) const;
1486 template <class _CharT>
1488 __empty_state<_CharT>::__exec(__state& __s) const
1490 __s.__do_ = __state::__accept_but_not_consume;
1491 __s.__node_ = this->first();
1494 // __empty_non_own_state
1496 template <class _CharT>
1497 class __empty_non_own_state
1498 : public __has_one_state<_CharT>
1500 typedef __has_one_state<_CharT> base;
1503 typedef _VSTD::__state<_CharT> __state;
1505 _LIBCPP_INLINE_VISIBILITY
1506 explicit __empty_non_own_state(__node<_CharT>* __s)
1509 virtual void __exec(__state&) const;
1512 template <class _CharT>
1514 __empty_non_own_state<_CharT>::__exec(__state& __s) const
1516 __s.__do_ = __state::__accept_but_not_consume;
1517 __s.__node_ = this->first();
1520 // __repeat_one_loop
1522 template <class _CharT>
1523 class __repeat_one_loop
1524 : public __has_one_state<_CharT>
1526 typedef __has_one_state<_CharT> base;
1529 typedef _VSTD::__state<_CharT> __state;
1531 _LIBCPP_INLINE_VISIBILITY
1532 explicit __repeat_one_loop(__node<_CharT>* __s)
1535 virtual void __exec(__state&) const;
1538 template <class _CharT>
1540 __repeat_one_loop<_CharT>::__exec(__state& __s) const
1542 __s.__do_ = __state::__repeat;
1543 __s.__node_ = this->first();
1546 // __owns_two_states
1548 template <class _CharT>
1549 class __owns_two_states
1550 : public __owns_one_state<_CharT>
1552 typedef __owns_one_state<_CharT> base;
1557 _LIBCPP_INLINE_VISIBILITY
1558 explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
1559 : base(__s1), __second_(__s2) {}
1561 virtual ~__owns_two_states();
1563 _LIBCPP_INLINE_VISIBILITY
1564 base* second() const {return __second_;}
1565 _LIBCPP_INLINE_VISIBILITY
1566 base*& second() {return __second_;}
1569 template <class _CharT>
1570 __owns_two_states<_CharT>::~__owns_two_states()
1577 template <class _CharT>
1579 : public __owns_two_states<_CharT>
1581 typedef __owns_two_states<_CharT> base;
1585 unsigned __loop_id_;
1586 unsigned __mexp_begin_;
1587 unsigned __mexp_end_;
1591 typedef _VSTD::__state<_CharT> __state;
1593 _LIBCPP_INLINE_VISIBILITY
1594 explicit __loop(unsigned __loop_id,
1595 __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
1596 unsigned __mexp_begin, unsigned __mexp_end,
1597 bool __greedy = true,
1599 size_t __max = numeric_limits<size_t>::max())
1600 : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
1601 __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
1602 __greedy_(__greedy) {}
1604 virtual void __exec(__state& __s) const;
1605 virtual void __exec_split(bool __second, __state& __s) const;
1608 _LIBCPP_INLINE_VISIBILITY
1609 void __init_repeat(__state& __s) const
1611 __s.__loop_data_[__loop_id_].second = __s.__current_;
1612 for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
1614 __s.__sub_matches_[__i].first = __s.__last_;
1615 __s.__sub_matches_[__i].second = __s.__last_;
1616 __s.__sub_matches_[__i].matched = false;
1621 template <class _CharT>
1623 __loop<_CharT>::__exec(__state& __s) const
1625 if (__s.__do_ == __state::__repeat)
1627 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1628 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1629 if (__do_repeat && __do_alt &&
1630 __s.__loop_data_[__loop_id_].second == __s.__current_)
1631 __do_repeat = false;
1632 if (__do_repeat && __do_alt)
1633 __s.__do_ = __state::__split;
1634 else if (__do_repeat)
1636 __s.__do_ = __state::__accept_but_not_consume;
1637 __s.__node_ = this->first();
1642 __s.__do_ = __state::__accept_but_not_consume;
1643 __s.__node_ = this->second();
1648 __s.__loop_data_[__loop_id_].first = 0;
1649 bool __do_repeat = 0 < __max_;
1650 bool __do_alt = 0 >= __min_;
1651 if (__do_repeat && __do_alt)
1652 __s.__do_ = __state::__split;
1653 else if (__do_repeat)
1655 __s.__do_ = __state::__accept_but_not_consume;
1656 __s.__node_ = this->first();
1661 __s.__do_ = __state::__accept_but_not_consume;
1662 __s.__node_ = this->second();
1667 template <class _CharT>
1669 __loop<_CharT>::__exec_split(bool __second, __state& __s) const
1671 __s.__do_ = __state::__accept_but_not_consume;
1672 if (__greedy_ != __second)
1674 __s.__node_ = this->first();
1678 __s.__node_ = this->second();
1683 template <class _CharT>
1685 : public __owns_two_states<_CharT>
1687 typedef __owns_two_states<_CharT> base;
1690 typedef _VSTD::__state<_CharT> __state;
1692 _LIBCPP_INLINE_VISIBILITY
1693 explicit __alternate(__owns_one_state<_CharT>* __s1,
1694 __owns_one_state<_CharT>* __s2)
1695 : base(__s1, __s2) {}
1697 virtual void __exec(__state& __s) const;
1698 virtual void __exec_split(bool __second, __state& __s) const;
1701 template <class _CharT>
1703 __alternate<_CharT>::__exec(__state& __s) const
1705 __s.__do_ = __state::__split;
1708 template <class _CharT>
1710 __alternate<_CharT>::__exec_split(bool __second, __state& __s) const
1712 __s.__do_ = __state::__accept_but_not_consume;
1714 __s.__node_ = this->second();
1716 __s.__node_ = this->first();
1719 // __begin_marked_subexpression
1721 template <class _CharT>
1722 class __begin_marked_subexpression
1723 : public __owns_one_state<_CharT>
1725 typedef __owns_one_state<_CharT> base;
1729 typedef _VSTD::__state<_CharT> __state;
1731 _LIBCPP_INLINE_VISIBILITY
1732 explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1733 : base(__s), __mexp_(__mexp) {}
1735 virtual void __exec(__state&) const;
1738 template <class _CharT>
1740 __begin_marked_subexpression<_CharT>::__exec(__state& __s) const
1742 __s.__do_ = __state::__accept_but_not_consume;
1743 __s.__sub_matches_[__mexp_-1].first = __s.__current_;
1744 __s.__node_ = this->first();
1747 // __end_marked_subexpression
1749 template <class _CharT>
1750 class __end_marked_subexpression
1751 : public __owns_one_state<_CharT>
1753 typedef __owns_one_state<_CharT> base;
1757 typedef _VSTD::__state<_CharT> __state;
1759 _LIBCPP_INLINE_VISIBILITY
1760 explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1761 : base(__s), __mexp_(__mexp) {}
1763 virtual void __exec(__state&) const;
1766 template <class _CharT>
1768 __end_marked_subexpression<_CharT>::__exec(__state& __s) const
1770 __s.__do_ = __state::__accept_but_not_consume;
1771 __s.__sub_matches_[__mexp_-1].second = __s.__current_;
1772 __s.__sub_matches_[__mexp_-1].matched = true;
1773 __s.__node_ = this->first();
1778 template <class _CharT>
1780 : public __owns_one_state<_CharT>
1782 typedef __owns_one_state<_CharT> base;
1786 typedef _VSTD::__state<_CharT> __state;
1788 _LIBCPP_INLINE_VISIBILITY
1789 explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
1790 : base(__s), __mexp_(__mexp) {}
1792 virtual void __exec(__state&) const;
1795 template <class _CharT>
1797 __back_ref<_CharT>::__exec(__state& __s) const
1799 if (__mexp_ > __s.__sub_matches_.size())
1800 __throw_regex_error<regex_constants::error_backref>();
1801 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1804 ptrdiff_t __len = __sm.second - __sm.first;
1805 if (__s.__last_ - __s.__current_ >= __len &&
1806 _VSTD::equal(__sm.first, __sm.second, __s.__current_))
1808 __s.__do_ = __state::__accept_but_not_consume;
1809 __s.__current_ += __len;
1810 __s.__node_ = this->first();
1814 __s.__do_ = __state::__reject;
1815 __s.__node_ = nullptr;
1820 __s.__do_ = __state::__reject;
1821 __s.__node_ = nullptr;
1827 template <class _CharT, class _Traits>
1828 class __back_ref_icase
1829 : public __owns_one_state<_CharT>
1831 typedef __owns_one_state<_CharT> base;
1836 typedef _VSTD::__state<_CharT> __state;
1838 _LIBCPP_INLINE_VISIBILITY
1839 explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
1840 __node<_CharT>* __s)
1841 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1843 virtual void __exec(__state&) const;
1846 template <class _CharT, class _Traits>
1848 __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
1850 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1853 ptrdiff_t __len = __sm.second - __sm.first;
1854 if (__s.__last_ - __s.__current_ >= __len)
1856 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1858 if (__traits_.translate_nocase(__sm.first[__i]) !=
1859 __traits_.translate_nocase(__s.__current_[__i]))
1862 __s.__do_ = __state::__accept_but_not_consume;
1863 __s.__current_ += __len;
1864 __s.__node_ = this->first();
1868 __s.__do_ = __state::__reject;
1869 __s.__node_ = nullptr;
1875 __s.__do_ = __state::__reject;
1876 __s.__node_ = nullptr;
1880 // __back_ref_collate
1882 template <class _CharT, class _Traits>
1883 class __back_ref_collate
1884 : public __owns_one_state<_CharT>
1886 typedef __owns_one_state<_CharT> base;
1891 typedef _VSTD::__state<_CharT> __state;
1893 _LIBCPP_INLINE_VISIBILITY
1894 explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
1895 __node<_CharT>* __s)
1896 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1898 virtual void __exec(__state&) const;
1901 template <class _CharT, class _Traits>
1903 __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
1905 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1908 ptrdiff_t __len = __sm.second - __sm.first;
1909 if (__s.__last_ - __s.__current_ >= __len)
1911 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1913 if (__traits_.translate(__sm.first[__i]) !=
1914 __traits_.translate(__s.__current_[__i]))
1917 __s.__do_ = __state::__accept_but_not_consume;
1918 __s.__current_ += __len;
1919 __s.__node_ = this->first();
1923 __s.__do_ = __state::__reject;
1924 __s.__node_ = nullptr;
1930 __s.__do_ = __state::__reject;
1931 __s.__node_ = nullptr;
1937 template <class _CharT, class _Traits>
1938 class __word_boundary
1939 : public __owns_one_state<_CharT>
1941 typedef __owns_one_state<_CharT> base;
1946 typedef _VSTD::__state<_CharT> __state;
1948 _LIBCPP_INLINE_VISIBILITY
1949 explicit __word_boundary(const _Traits& __traits, bool __invert,
1950 __node<_CharT>* __s)
1951 : base(__s), __traits_(__traits), __invert_(__invert) {}
1953 virtual void __exec(__state&) const;
1956 template <class _CharT, class _Traits>
1958 __word_boundary<_CharT, _Traits>::__exec(__state& __s) const
1960 bool __is_word_b = false;
1961 if (__s.__first_ != __s.__last_)
1963 if (__s.__current_ == __s.__last_)
1965 if (!(__s.__flags_ & regex_constants::match_not_eow))
1967 _CharT __c = __s.__current_[-1];
1968 __is_word_b = __c == '_' ||
1969 __traits_.isctype(__c, ctype_base::alnum);
1972 else if (__s.__current_ == __s.__first_ &&
1973 !(__s.__flags_ & regex_constants::match_prev_avail))
1975 if (!(__s.__flags_ & regex_constants::match_not_bow))
1977 _CharT __c = *__s.__current_;
1978 __is_word_b = __c == '_' ||
1979 __traits_.isctype(__c, ctype_base::alnum);
1984 _CharT __c1 = __s.__current_[-1];
1985 _CharT __c2 = *__s.__current_;
1986 bool __is_c1_b = __c1 == '_' ||
1987 __traits_.isctype(__c1, ctype_base::alnum);
1988 bool __is_c2_b = __c2 == '_' ||
1989 __traits_.isctype(__c2, ctype_base::alnum);
1990 __is_word_b = __is_c1_b != __is_c2_b;
1993 if (__is_word_b != __invert_)
1995 __s.__do_ = __state::__accept_but_not_consume;
1996 __s.__node_ = this->first();
2000 __s.__do_ = __state::__reject;
2001 __s.__node_ = nullptr;
2007 template <class _CharT>
2008 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2009 bool __is_eol(_CharT c)
2011 return c == '\r' || c == '\n';
2014 template <class _CharT>
2015 class __l_anchor_multiline
2016 : public __owns_one_state<_CharT>
2018 typedef __owns_one_state<_CharT> base;
2023 typedef _VSTD::__state<_CharT> __state;
2025 _LIBCPP_INLINE_VISIBILITY
2026 __l_anchor_multiline(bool __multiline, __node<_CharT>* __s)
2027 : base(__s), __multiline_(__multiline) {}
2029 virtual void __exec(__state&) const;
2032 template <class _CharT>
2034 __l_anchor_multiline<_CharT>::__exec(__state& __s) const
2036 if (__s.__at_first_ && __s.__current_ == __s.__first_ &&
2037 !(__s.__flags_ & regex_constants::match_not_bol))
2039 __s.__do_ = __state::__accept_but_not_consume;
2040 __s.__node_ = this->first();
2042 else if (__multiline_ &&
2044 __is_eol(*_VSTD::prev(__s.__current_)))
2046 __s.__do_ = __state::__accept_but_not_consume;
2047 __s.__node_ = this->first();
2051 __s.__do_ = __state::__reject;
2052 __s.__node_ = nullptr;
2058 template <class _CharT>
2059 class __r_anchor_multiline
2060 : public __owns_one_state<_CharT>
2062 typedef __owns_one_state<_CharT> base;
2067 typedef _VSTD::__state<_CharT> __state;
2069 _LIBCPP_INLINE_VISIBILITY
2070 __r_anchor_multiline(bool __multiline, __node<_CharT>* __s)
2071 : base(__s), __multiline(__multiline) {}
2073 virtual void __exec(__state&) const;
2076 template <class _CharT>
2078 __r_anchor_multiline<_CharT>::__exec(__state& __s) const
2080 if (__s.__current_ == __s.__last_ &&
2081 !(__s.__flags_ & regex_constants::match_not_eol))
2083 __s.__do_ = __state::__accept_but_not_consume;
2084 __s.__node_ = this->first();
2086 else if (__multiline && __is_eol(*__s.__current_))
2088 __s.__do_ = __state::__accept_but_not_consume;
2089 __s.__node_ = this->first();
2093 __s.__do_ = __state::__reject;
2094 __s.__node_ = nullptr;
2100 template <class _CharT>
2102 : public __owns_one_state<_CharT>
2104 typedef __owns_one_state<_CharT> base;
2107 typedef _VSTD::__state<_CharT> __state;
2109 _LIBCPP_INLINE_VISIBILITY
2110 __match_any(__node<_CharT>* __s)
2113 virtual void __exec(__state&) const;
2116 template <class _CharT>
2118 __match_any<_CharT>::__exec(__state& __s) const
2120 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
2122 __s.__do_ = __state::__accept_and_consume;
2124 __s.__node_ = this->first();
2128 __s.__do_ = __state::__reject;
2129 __s.__node_ = nullptr;
2133 // __match_any_but_newline
2135 template <class _CharT>
2136 class __match_any_but_newline
2137 : public __owns_one_state<_CharT>
2139 typedef __owns_one_state<_CharT> base;
2142 typedef _VSTD::__state<_CharT> __state;
2144 _LIBCPP_INLINE_VISIBILITY
2145 __match_any_but_newline(__node<_CharT>* __s)
2148 virtual void __exec(__state&) const;
2151 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
2152 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2153 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
2158 template <class _CharT>
2160 : public __owns_one_state<_CharT>
2162 typedef __owns_one_state<_CharT> base;
2166 __match_char(const __match_char&);
2167 __match_char& operator=(const __match_char&);
2169 typedef _VSTD::__state<_CharT> __state;
2171 _LIBCPP_INLINE_VISIBILITY
2172 __match_char(_CharT __c, __node<_CharT>* __s)
2173 : base(__s), __c_(__c) {}
2175 virtual void __exec(__state&) const;
2178 template <class _CharT>
2180 __match_char<_CharT>::__exec(__state& __s) const
2182 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
2184 __s.__do_ = __state::__accept_and_consume;
2186 __s.__node_ = this->first();
2190 __s.__do_ = __state::__reject;
2191 __s.__node_ = nullptr;
2195 // __match_char_icase
2197 template <class _CharT, class _Traits>
2198 class __match_char_icase
2199 : public __owns_one_state<_CharT>
2201 typedef __owns_one_state<_CharT> base;
2206 __match_char_icase(const __match_char_icase&);
2207 __match_char_icase& operator=(const __match_char_icase&);
2209 typedef _VSTD::__state<_CharT> __state;
2211 _LIBCPP_INLINE_VISIBILITY
2212 __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2213 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
2215 virtual void __exec(__state&) const;
2218 template <class _CharT, class _Traits>
2220 __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
2222 if (__s.__current_ != __s.__last_ &&
2223 __traits_.translate_nocase(*__s.__current_) == __c_)
2225 __s.__do_ = __state::__accept_and_consume;
2227 __s.__node_ = this->first();
2231 __s.__do_ = __state::__reject;
2232 __s.__node_ = nullptr;
2236 // __match_char_collate
2238 template <class _CharT, class _Traits>
2239 class __match_char_collate
2240 : public __owns_one_state<_CharT>
2242 typedef __owns_one_state<_CharT> base;
2247 __match_char_collate(const __match_char_collate&);
2248 __match_char_collate& operator=(const __match_char_collate&);
2250 typedef _VSTD::__state<_CharT> __state;
2252 _LIBCPP_INLINE_VISIBILITY
2253 __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2254 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2256 virtual void __exec(__state&) const;
2259 template <class _CharT, class _Traits>
2261 __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
2263 if (__s.__current_ != __s.__last_ &&
2264 __traits_.translate(*__s.__current_) == __c_)
2266 __s.__do_ = __state::__accept_and_consume;
2268 __s.__node_ = this->first();
2272 __s.__do_ = __state::__reject;
2273 __s.__node_ = nullptr;
2277 // __bracket_expression
2279 template <class _CharT, class _Traits>
2280 class __bracket_expression
2281 : public __owns_one_state<_CharT>
2283 typedef __owns_one_state<_CharT> base;
2284 typedef typename _Traits::string_type string_type;
2287 vector<_CharT> __chars_;
2288 vector<_CharT> __neg_chars_;
2289 vector<pair<string_type, string_type> > __ranges_;
2290 vector<pair<_CharT, _CharT> > __digraphs_;
2291 vector<string_type> __equivalences_;
2292 typename regex_traits<_CharT>::char_class_type __mask_;
2293 typename regex_traits<_CharT>::char_class_type __neg_mask_;
2297 bool __might_have_digraph_;
2299 __bracket_expression(const __bracket_expression&);
2300 __bracket_expression& operator=(const __bracket_expression&);
2302 typedef _VSTD::__state<_CharT> __state;
2304 _LIBCPP_INLINE_VISIBILITY
2305 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
2306 bool __negate, bool __icase, bool __collate)
2307 : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
2308 __negate_(__negate), __icase_(__icase), __collate_(__collate),
2309 __might_have_digraph_(__traits_.getloc().name() != "C") {}
2311 virtual void __exec(__state&) const;
2313 _LIBCPP_INLINE_VISIBILITY
2314 bool __negated() const {return __negate_;}
2316 _LIBCPP_INLINE_VISIBILITY
2317 void __add_char(_CharT __c)
2320 __chars_.push_back(__traits_.translate_nocase(__c));
2321 else if (__collate_)
2322 __chars_.push_back(__traits_.translate(__c));
2324 __chars_.push_back(__c);
2326 _LIBCPP_INLINE_VISIBILITY
2327 void __add_neg_char(_CharT __c)
2330 __neg_chars_.push_back(__traits_.translate_nocase(__c));
2331 else if (__collate_)
2332 __neg_chars_.push_back(__traits_.translate(__c));
2334 __neg_chars_.push_back(__c);
2336 _LIBCPP_INLINE_VISIBILITY
2337 void __add_range(string_type __b, string_type __e)
2343 for (size_t __i = 0; __i < __b.size(); ++__i)
2344 __b[__i] = __traits_.translate_nocase(__b[__i]);
2345 for (size_t __i = 0; __i < __e.size(); ++__i)
2346 __e[__i] = __traits_.translate_nocase(__e[__i]);
2350 for (size_t __i = 0; __i < __b.size(); ++__i)
2351 __b[__i] = __traits_.translate(__b[__i]);
2352 for (size_t __i = 0; __i < __e.size(); ++__i)
2353 __e[__i] = __traits_.translate(__e[__i]);
2355 __ranges_.push_back(make_pair(
2356 __traits_.transform(__b.begin(), __b.end()),
2357 __traits_.transform(__e.begin(), __e.end())));
2361 if (__b.size() != 1 || __e.size() != 1)
2362 __throw_regex_error<regex_constants::error_range>();
2365 __b[0] = __traits_.translate_nocase(__b[0]);
2366 __e[0] = __traits_.translate_nocase(__e[0]);
2368 __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e)));
2371 _LIBCPP_INLINE_VISIBILITY
2372 void __add_digraph(_CharT __c1, _CharT __c2)
2375 __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
2376 __traits_.translate_nocase(__c2)));
2377 else if (__collate_)
2378 __digraphs_.push_back(make_pair(__traits_.translate(__c1),
2379 __traits_.translate(__c2)));
2381 __digraphs_.push_back(make_pair(__c1, __c2));
2383 _LIBCPP_INLINE_VISIBILITY
2384 void __add_equivalence(const string_type& __s)
2385 {__equivalences_.push_back(__s);}
2386 _LIBCPP_INLINE_VISIBILITY
2387 void __add_class(typename regex_traits<_CharT>::char_class_type __mask)
2388 {__mask_ |= __mask;}
2389 _LIBCPP_INLINE_VISIBILITY
2390 void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask)
2391 {__neg_mask_ |= __mask;}
2394 template <class _CharT, class _Traits>
2396 __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
2398 bool __found = false;
2399 unsigned __consumed = 0;
2400 if (__s.__current_ != __s.__last_)
2403 if (__might_have_digraph_)
2405 const _CharT* __next = _VSTD::next(__s.__current_);
2406 if (__next != __s.__last_)
2408 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2411 __ch2.first = __traits_.translate_nocase(__ch2.first);
2412 __ch2.second = __traits_.translate_nocase(__ch2.second);
2414 else if (__collate_)
2416 __ch2.first = __traits_.translate(__ch2.first);
2417 __ch2.second = __traits_.translate(__ch2.second);
2419 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
2421 // __ch2 is a digraph in this locale
2423 for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
2425 if (__ch2 == __digraphs_[__i])
2431 if (__collate_ && !__ranges_.empty())
2433 string_type __s2 = __traits_.transform(&__ch2.first,
2435 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2437 if (__ranges_[__i].first <= __s2 &&
2438 __s2 <= __ranges_[__i].second)
2445 if (!__equivalences_.empty())
2447 string_type __s2 = __traits_.transform_primary(&__ch2.first,
2449 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2451 if (__s2 == __equivalences_[__i])
2458 if (__traits_.isctype(__ch2.first, __mask_) &&
2459 __traits_.isctype(__ch2.second, __mask_))
2464 if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
2465 !__traits_.isctype(__ch2.second, __neg_mask_))
2474 // test *__s.__current_ as not a digraph
2475 _CharT __ch = *__s.__current_;
2477 __ch = __traits_.translate_nocase(__ch);
2478 else if (__collate_)
2479 __ch = __traits_.translate(__ch);
2480 for (size_t __i = 0; __i < __chars_.size(); ++__i)
2482 if (__ch == __chars_[__i])
2488 // When there's at least one of __neg_chars_ and __neg_mask_, the set
2489 // of "__found" chars is
2490 // union(complement(union(__neg_chars_, __neg_mask_)),
2493 // It doesn't make sense to check this when there are no __neg_chars_
2494 // and no __neg_mask_.
2495 if (!(__neg_mask_ == 0 && __neg_chars_.empty()))
2497 const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_);
2498 const bool __in_neg_chars =
2499 _VSTD::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) !=
2501 if (!(__in_neg_mask || __in_neg_chars))
2507 if (!__ranges_.empty())
2509 string_type __s2 = __collate_ ?
2510 __traits_.transform(&__ch, &__ch + 1) :
2511 string_type(1, __ch);
2512 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2514 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
2521 if (!__equivalences_.empty())
2523 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2524 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2526 if (__s2 == __equivalences_[__i])
2533 if (__traits_.isctype(__ch, __mask_))
2540 __found = __negate_; // force reject
2542 if (__found != __negate_)
2544 __s.__do_ = __state::__accept_and_consume;
2545 __s.__current_ += __consumed;
2546 __s.__node_ = this->first();
2550 __s.__do_ = __state::__reject;
2551 __s.__node_ = nullptr;
2555 template <class _CharT, class _Traits> class __lookahead;
2557 template <class _CharT, class _Traits = regex_traits<_CharT> >
2558 class _LIBCPP_TEMPLATE_VIS basic_regex;
2560 typedef basic_regex<char> regex;
2561 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2562 typedef basic_regex<wchar_t> wregex;
2565 template <class _CharT, class _Traits>
2567 _LIBCPP_TEMPLATE_VIS
2568 _LIBCPP_PREFERRED_NAME(regex)
2569 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex))
2574 typedef _CharT value_type;
2575 typedef _Traits traits_type;
2576 typedef typename _Traits::string_type string_type;
2577 typedef regex_constants::syntax_option_type flag_type;
2578 typedef typename _Traits::locale_type locale_type;
2583 unsigned __marked_count_;
2584 unsigned __loop_count_;
2586 shared_ptr<__empty_state<_CharT> > __start_;
2587 __owns_one_state<_CharT>* __end_;
2589 typedef _VSTD::__state<_CharT> __state;
2590 typedef _VSTD::__node<_CharT> __node;
2594 static const regex_constants::syntax_option_type icase = regex_constants::icase;
2595 static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2596 static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
2597 static const regex_constants::syntax_option_type collate = regex_constants::collate;
2598 static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2599 static const regex_constants::syntax_option_type basic = regex_constants::basic;
2600 static const regex_constants::syntax_option_type extended = regex_constants::extended;
2601 static const regex_constants::syntax_option_type awk = regex_constants::awk;
2602 static const regex_constants::syntax_option_type grep = regex_constants::grep;
2603 static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
2604 static const regex_constants::syntax_option_type multiline = regex_constants::multiline;
2606 // construct/copy/destroy:
2607 _LIBCPP_INLINE_VISIBILITY
2609 : __flags_(regex_constants::ECMAScript), __marked_count_(0), __loop_count_(0), __open_count_(0),
2612 _LIBCPP_INLINE_VISIBILITY
2613 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2614 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2617 __init(__p, __p + __traits_.length(__p));
2620 _LIBCPP_INLINE_VISIBILITY
2621 basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
2622 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2625 __init(__p, __p + __len);
2628 // basic_regex(const basic_regex&) = default;
2629 // basic_regex(basic_regex&&) = default;
2630 template <class _ST, class _SA>
2631 _LIBCPP_INLINE_VISIBILITY
2632 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2633 flag_type __f = regex_constants::ECMAScript)
2634 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2637 __init(__p.begin(), __p.end());
2640 template <class _ForwardIterator>
2641 _LIBCPP_INLINE_VISIBILITY
2642 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
2643 flag_type __f = regex_constants::ECMAScript)
2644 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2647 __init(__first, __last);
2649 #ifndef _LIBCPP_CXX03_LANG
2650 _LIBCPP_INLINE_VISIBILITY
2651 basic_regex(initializer_list<value_type> __il,
2652 flag_type __f = regex_constants::ECMAScript)
2653 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2656 __init(__il.begin(), __il.end());
2658 #endif // _LIBCPP_CXX03_LANG
2660 // ~basic_regex() = default;
2662 // basic_regex& operator=(const basic_regex&) = default;
2663 // basic_regex& operator=(basic_regex&&) = default;
2664 _LIBCPP_INLINE_VISIBILITY
2665 basic_regex& operator=(const value_type* __p)
2666 {return assign(__p);}
2667 #ifndef _LIBCPP_CXX03_LANG
2668 _LIBCPP_INLINE_VISIBILITY
2669 basic_regex& operator=(initializer_list<value_type> __il)
2670 {return assign(__il);}
2671 #endif // _LIBCPP_CXX03_LANG
2672 template <class _ST, class _SA>
2673 _LIBCPP_INLINE_VISIBILITY
2674 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
2675 {return assign(__p);}
2678 _LIBCPP_INLINE_VISIBILITY
2679 basic_regex& assign(const basic_regex& __that)
2680 {return *this = __that;}
2681 #ifndef _LIBCPP_CXX03_LANG
2682 _LIBCPP_INLINE_VISIBILITY
2683 basic_regex& assign(basic_regex&& __that) _NOEXCEPT
2684 {return *this = _VSTD::move(__that);}
2686 _LIBCPP_INLINE_VISIBILITY
2687 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2688 {return assign(__p, __p + __traits_.length(__p), __f);}
2689 _LIBCPP_INLINE_VISIBILITY
2690 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
2691 {return assign(__p, __p + __len, __f);}
2692 template <class _ST, class _SA>
2693 _LIBCPP_INLINE_VISIBILITY
2694 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
2695 flag_type __f = regex_constants::ECMAScript)
2696 {return assign(__s.begin(), __s.end(), __f);}
2698 template <class _InputIterator>
2699 _LIBCPP_INLINE_VISIBILITY
2702 __is_cpp17_input_iterator <_InputIterator>::value &&
2703 !__is_cpp17_forward_iterator<_InputIterator>::value,
2706 assign(_InputIterator __first, _InputIterator __last,
2707 flag_type __f = regex_constants::ECMAScript)
2709 basic_string<_CharT> __t(__first, __last);
2710 return assign(__t.begin(), __t.end(), __f);
2714 _LIBCPP_INLINE_VISIBILITY
2715 void __member_init(flag_type __f)
2718 __marked_count_ = 0;
2725 template <class _ForwardIterator>
2726 _LIBCPP_INLINE_VISIBILITY
2729 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2732 assign(_ForwardIterator __first, _ForwardIterator __last,
2733 flag_type __f = regex_constants::ECMAScript)
2735 return assign(basic_regex(__first, __last, __f));
2738 #ifndef _LIBCPP_CXX03_LANG
2740 _LIBCPP_INLINE_VISIBILITY
2741 basic_regex& assign(initializer_list<value_type> __il,
2742 flag_type __f = regex_constants::ECMAScript)
2743 {return assign(__il.begin(), __il.end(), __f);}
2745 #endif // _LIBCPP_CXX03_LANG
2747 // const operations:
2748 _LIBCPP_INLINE_VISIBILITY
2749 unsigned mark_count() const {return __marked_count_;}
2750 _LIBCPP_INLINE_VISIBILITY
2751 flag_type flags() const {return __flags_;}
2754 _LIBCPP_INLINE_VISIBILITY
2755 locale_type imbue(locale_type __loc)
2757 __member_init(ECMAScript);
2759 return __traits_.imbue(__loc);
2761 _LIBCPP_INLINE_VISIBILITY
2762 locale_type getloc() const {return __traits_.getloc();}
2765 void swap(basic_regex& __r);
2768 _LIBCPP_INLINE_VISIBILITY
2769 unsigned __loop_count() const {return __loop_count_;}
2771 _LIBCPP_INLINE_VISIBILITY
2772 bool __use_multiline() const
2774 return __get_grammar(__flags_) == ECMAScript && (__flags_ & multiline);
2777 template <class _ForwardIterator>
2779 __init(_ForwardIterator __first, _ForwardIterator __last);
2780 template <class _ForwardIterator>
2782 __parse(_ForwardIterator __first, _ForwardIterator __last);
2783 template <class _ForwardIterator>
2785 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2786 template <class _ForwardIterator>
2788 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2789 template <class _ForwardIterator>
2791 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2792 template <class _ForwardIterator>
2794 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2795 template <class _ForwardIterator>
2797 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2798 template <class _ForwardIterator>
2800 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2801 template <class _ForwardIterator>
2803 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2804 template <class _ForwardIterator>
2806 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2807 template <class _ForwardIterator>
2809 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2810 template <class _ForwardIterator>
2812 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2813 template <class _ForwardIterator>
2815 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2816 template <class _ForwardIterator>
2818 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2819 template <class _ForwardIterator>
2821 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2822 __owns_one_state<_CharT>* __s,
2823 unsigned __mexp_begin, unsigned __mexp_end);
2824 template <class _ForwardIterator>
2826 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2827 __owns_one_state<_CharT>* __s,
2828 unsigned __mexp_begin, unsigned __mexp_end);
2829 template <class _ForwardIterator>
2831 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2832 template <class _ForwardIterator>
2834 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
2835 __bracket_expression<_CharT, _Traits>* __ml);
2836 template <class _ForwardIterator>
2838 __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
2839 __bracket_expression<_CharT, _Traits>* __ml);
2840 template <class _ForwardIterator>
2842 __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
2843 __bracket_expression<_CharT, _Traits>* __ml);
2844 template <class _ForwardIterator>
2846 __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
2847 __bracket_expression<_CharT, _Traits>* __ml);
2848 template <class _ForwardIterator>
2850 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
2851 basic_string<_CharT>& __col_sym);
2852 template <class _ForwardIterator>
2854 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
2855 template <class _ForwardIterator>
2857 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2858 template <class _ForwardIterator>
2860 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2861 template <class _ForwardIterator>
2863 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2864 template <class _ForwardIterator>
2866 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2867 template <class _ForwardIterator>
2869 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2870 template <class _ForwardIterator>
2872 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2873 template <class _ForwardIterator>
2875 __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2876 template <class _ForwardIterator>
2878 __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2879 template <class _ForwardIterator>
2881 __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2882 template <class _ForwardIterator>
2884 __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2885 template <class _ForwardIterator>
2887 __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2888 template <class _ForwardIterator>
2890 __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2891 template <class _ForwardIterator>
2893 __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2894 template <class _ForwardIterator>
2896 __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2897 template <class _ForwardIterator>
2899 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
2900 basic_string<_CharT>* __str = nullptr);
2901 template <class _ForwardIterator>
2903 __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
2904 template <class _ForwardIterator>
2906 __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
2907 template <class _ForwardIterator>
2909 __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
2910 template <class _ForwardIterator>
2912 __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
2913 basic_string<_CharT>& __str,
2914 __bracket_expression<_CharT, _Traits>* __ml);
2915 template <class _ForwardIterator>
2917 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
2918 basic_string<_CharT>* __str = nullptr);
2920 bool __test_back_ref(_CharT c);
2922 _LIBCPP_INLINE_VISIBILITY
2923 void __push_l_anchor();
2924 void __push_r_anchor();
2925 void __push_match_any();
2926 void __push_match_any_but_newline();
2927 _LIBCPP_INLINE_VISIBILITY
2928 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2929 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2930 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2931 __mexp_begin, __mexp_end);}
2932 _LIBCPP_INLINE_VISIBILITY
2933 void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2934 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2935 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2936 __mexp_begin, __mexp_end, false);}
2937 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2938 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2939 bool __greedy = true);
2940 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
2941 void __push_char(value_type __c);
2942 void __push_back_ref(int __i);
2943 void __push_alternation(__owns_one_state<_CharT>* __sa,
2944 __owns_one_state<_CharT>* __sb);
2945 void __push_begin_marked_subexpression();
2946 void __push_end_marked_subexpression(unsigned);
2947 void __push_empty();
2948 void __push_word_boundary(bool);
2949 void __push_lookahead(const basic_regex&, bool, unsigned);
2951 template <class _Allocator>
2953 __search(const _CharT* __first, const _CharT* __last,
2954 match_results<const _CharT*, _Allocator>& __m,
2955 regex_constants::match_flag_type __flags) const;
2957 template <class _Allocator>
2959 __match_at_start(const _CharT* __first, const _CharT* __last,
2960 match_results<const _CharT*, _Allocator>& __m,
2961 regex_constants::match_flag_type __flags, bool) const;
2962 template <class _Allocator>
2964 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
2965 match_results<const _CharT*, _Allocator>& __m,
2966 regex_constants::match_flag_type __flags, bool) const;
2967 template <class _Allocator>
2969 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
2970 match_results<const _CharT*, _Allocator>& __m,
2971 regex_constants::match_flag_type __flags, bool) const;
2972 template <class _Allocator>
2974 __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
2975 match_results<const _CharT*, _Allocator>& __m,
2976 regex_constants::match_flag_type __flags, bool) const;
2978 template <class _Bp, class _Ap, class _Cp, class _Tp>
2981 regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
2982 regex_constants::match_flag_type);
2984 template <class _Ap, class _Cp, class _Tp>
2987 regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&,
2988 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
2990 template <class _Bp, class _Cp, class _Tp>
2993 regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&,
2994 regex_constants::match_flag_type);
2996 template <class _Cp, class _Tp>
2999 regex_search(const _Cp*, const _Cp*,
3000 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
3002 template <class _Cp, class _Ap, class _Tp>
3005 regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&,
3006 regex_constants::match_flag_type);
3008 template <class _ST, class _SA, class _Cp, class _Tp>
3011 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
3012 const basic_regex<_Cp, _Tp>& __e,
3013 regex_constants::match_flag_type __flags);
3015 template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
3018 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
3019 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
3020 const basic_regex<_Cp, _Tp>& __e,
3021 regex_constants::match_flag_type __flags);
3023 template <class _Iter, class _Ap, class _Cp, class _Tp>
3026 regex_search(__wrap_iter<_Iter> __first,
3027 __wrap_iter<_Iter> __last,
3028 match_results<__wrap_iter<_Iter>, _Ap>& __m,
3029 const basic_regex<_Cp, _Tp>& __e,
3030 regex_constants::match_flag_type __flags);
3032 template <class, class> friend class __lookahead;
3035 #if _LIBCPP_STD_VER >= 17
3036 template <class _ForwardIterator,
3037 class = typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value, nullptr_t>::type
3039 basic_regex(_ForwardIterator, _ForwardIterator,
3040 regex_constants::syntax_option_type = regex_constants::ECMAScript)
3041 -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
3044 template <class _CharT, class _Traits>
3045 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
3046 template <class _CharT, class _Traits>
3047 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
3048 template <class _CharT, class _Traits>
3049 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
3050 template <class _CharT, class _Traits>
3051 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
3052 template <class _CharT, class _Traits>
3053 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
3054 template <class _CharT, class _Traits>
3055 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
3056 template <class _CharT, class _Traits>
3057 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
3058 template <class _CharT, class _Traits>
3059 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
3060 template <class _CharT, class _Traits>
3061 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
3062 template <class _CharT, class _Traits>
3063 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
3065 template <class _CharT, class _Traits>
3067 basic_regex<_CharT, _Traits>::swap(basic_regex& __r)
3070 swap(__traits_, __r.__traits_);
3071 swap(__flags_, __r.__flags_);
3072 swap(__marked_count_, __r.__marked_count_);
3073 swap(__loop_count_, __r.__loop_count_);
3074 swap(__open_count_, __r.__open_count_);
3075 swap(__start_, __r.__start_);
3076 swap(__end_, __r.__end_);
3079 template <class _CharT, class _Traits>
3080 inline _LIBCPP_INLINE_VISIBILITY
3082 swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
3084 return __x.swap(__y);
3089 template <class _CharT, class _Traits>
3091 : public __owns_one_state<_CharT>
3093 typedef __owns_one_state<_CharT> base;
3095 basic_regex<_CharT, _Traits> __exp_;
3099 __lookahead(const __lookahead&);
3100 __lookahead& operator=(const __lookahead&);
3102 typedef _VSTD::__state<_CharT> __state;
3104 _LIBCPP_INLINE_VISIBILITY
3105 __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
3106 : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
3108 virtual void __exec(__state&) const;
3111 template <class _CharT, class _Traits>
3113 __lookahead<_CharT, _Traits>::__exec(__state& __s) const
3115 match_results<const _CharT*> __m;
3116 __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
3117 bool __matched = __exp_.__match_at_start_ecma(
3118 __s.__current_, __s.__last_,
3120 (__s.__flags_ | regex_constants::match_continuous) &
3121 ~regex_constants::__full_match,
3122 __s.__at_first_ && __s.__current_ == __s.__first_);
3123 if (__matched != __invert_)
3125 __s.__do_ = __state::__accept_but_not_consume;
3126 __s.__node_ = this->first();
3127 for (unsigned __i = 1; __i < __m.size(); ++__i) {
3128 __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
3133 __s.__do_ = __state::__reject;
3134 __s.__node_ = nullptr;
3138 template <class _CharT, class _Traits>
3139 template <class _ForwardIterator>
3141 basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last)
3143 if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript;
3144 _ForwardIterator __temp = __parse(__first, __last);
3145 if ( __temp != __last)
3146 __throw_regex_error<regex_constants::__re_err_parse>();
3149 template <class _CharT, class _Traits>
3150 template <class _ForwardIterator>
3152 basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
3153 _ForwardIterator __last)
3156 unique_ptr<__node> __h(new __end_state<_CharT>);
3157 __start_.reset(new __empty_state<_CharT>(__h.get()));
3159 __end_ = __start_.get();
3161 switch (__get_grammar(__flags_))
3164 __first = __parse_ecma_exp(__first, __last);
3167 __first = __parse_basic_reg_exp(__first, __last);
3171 __first = __parse_extended_reg_exp(__first, __last);
3174 __first = __parse_grep(__first, __last);
3177 __first = __parse_egrep(__first, __last);
3180 __throw_regex_error<regex_constants::__re_err_grammar>();
3185 template <class _CharT, class _Traits>
3186 template <class _ForwardIterator>
3188 basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
3189 _ForwardIterator __last)
3191 if (__first != __last)
3193 if (*__first == '^')
3198 if (__first != __last)
3200 __first = __parse_RE_expression(__first, __last);
3201 if (__first != __last)
3203 _ForwardIterator __temp = _VSTD::next(__first);
3204 if (__temp == __last && *__first == '$')
3211 if (__first != __last)
3212 __throw_regex_error<regex_constants::__re_err_empty>();
3217 template <class _CharT, class _Traits>
3218 template <class _ForwardIterator>
3220 basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
3221 _ForwardIterator __last)
3223 __owns_one_state<_CharT>* __sa = __end_;
3224 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
3225 if (__temp == __first)
3226 __throw_regex_error<regex_constants::__re_err_empty>();
3228 while (__first != __last && *__first == '|')
3230 __owns_one_state<_CharT>* __sb = __end_;
3231 __temp = __parse_ERE_branch(++__first, __last);
3232 if (__temp == __first)
3233 __throw_regex_error<regex_constants::__re_err_empty>();
3234 __push_alternation(__sa, __sb);
3240 template <class _CharT, class _Traits>
3241 template <class _ForwardIterator>
3243 basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
3244 _ForwardIterator __last)
3246 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
3247 if (__temp == __first)
3248 __throw_regex_error<regex_constants::__re_err_empty>();
3252 __temp = __parse_ERE_expression(__first, __last);
3253 } while (__temp != __first);
3257 template <class _CharT, class _Traits>
3258 template <class _ForwardIterator>
3260 basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
3261 _ForwardIterator __last)
3263 __owns_one_state<_CharT>* __e = __end_;
3264 unsigned __mexp_begin = __marked_count_;
3265 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
3266 if (__temp == __first && __temp != __last)
3279 __push_begin_marked_subexpression();
3280 unsigned __temp_count = __marked_count_;
3282 __temp = __parse_extended_reg_exp(++__temp, __last);
3283 if (__temp == __last || *__temp != ')')
3284 __throw_regex_error<regex_constants::error_paren>();
3285 __push_end_marked_subexpression(__temp_count);
3291 if (__temp != __first)
3292 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
3298 template <class _CharT, class _Traits>
3299 template <class _ForwardIterator>
3301 basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
3302 _ForwardIterator __last)
3306 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
3307 if (__temp == __first)
3314 template <class _CharT, class _Traits>
3315 template <class _ForwardIterator>
3317 basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
3318 _ForwardIterator __last)
3320 if (__first != __last)
3322 __owns_one_state<_CharT>* __e = __end_;
3323 unsigned __mexp_begin = __marked_count_;
3324 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
3325 if (__temp != __first)
3326 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
3327 __mexp_begin+1, __marked_count_+1);
3332 template <class _CharT, class _Traits>
3333 template <class _ForwardIterator>
3335 basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
3336 _ForwardIterator __last)
3338 _ForwardIterator __temp = __first;
3339 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
3340 if (__temp == __first)
3342 __temp = __parse_Back_open_paren(__first, __last);
3343 if (__temp != __first)
3345 __push_begin_marked_subexpression();
3346 unsigned __temp_count = __marked_count_;
3347 __first = __parse_RE_expression(__temp, __last);
3348 __temp = __parse_Back_close_paren(__first, __last);
3349 if (__temp == __first)
3350 __throw_regex_error<regex_constants::error_paren>();
3351 __push_end_marked_subexpression(__temp_count);
3355 __first = __parse_BACKREF(__first, __last);
3360 template <class _CharT, class _Traits>
3361 template <class _ForwardIterator>
3363 basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
3364 _ForwardIterator __first,
3365 _ForwardIterator __last)
3367 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
3368 if (__temp == __first)
3370 __temp = __parse_QUOTED_CHAR(__first, __last);
3371 if (__temp == __first)
3373 if (__temp != __last && *__temp == '.')
3379 __temp = __parse_bracket_expression(__first, __last);
3386 template <class _CharT, class _Traits>
3387 template <class _ForwardIterator>
3389 basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
3390 _ForwardIterator __first,
3391 _ForwardIterator __last)
3393 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
3394 if (__temp == __first)
3396 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
3397 if (__temp == __first)
3399 if (__temp != __last && *__temp == '.')
3405 __temp = __parse_bracket_expression(__first, __last);
3412 template <class _CharT, class _Traits>
3413 template <class _ForwardIterator>
3415 basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
3416 _ForwardIterator __last)
3418 if (__first != __last)
3420 _ForwardIterator __temp = _VSTD::next(__first);
3421 if (__temp != __last)
3423 if (*__first == '\\' && *__temp == '(')
3430 template <class _CharT, class _Traits>
3431 template <class _ForwardIterator>
3433 basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
3434 _ForwardIterator __last)
3436 if (__first != __last)
3438 _ForwardIterator __temp = _VSTD::next(__first);
3439 if (__temp != __last)
3441 if (*__first == '\\' && *__temp == ')')
3448 template <class _CharT, class _Traits>
3449 template <class _ForwardIterator>
3451 basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
3452 _ForwardIterator __last)
3454 if (__first != __last)
3456 _ForwardIterator __temp = _VSTD::next(__first);
3457 if (__temp != __last)
3459 if (*__first == '\\' && *__temp == '{')
3466 template <class _CharT, class _Traits>
3467 template <class _ForwardIterator>
3469 basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
3470 _ForwardIterator __last)
3472 if (__first != __last)
3474 _ForwardIterator __temp = _VSTD::next(__first);
3475 if (__temp != __last)
3477 if (*__first == '\\' && *__temp == '}')
3484 template <class _CharT, class _Traits>
3485 template <class _ForwardIterator>
3487 basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
3488 _ForwardIterator __last)
3490 if (__first != __last)
3492 _ForwardIterator __temp = _VSTD::next(__first);
3493 if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp))
3499 template <class _CharT, class _Traits>
3500 template <class _ForwardIterator>
3502 basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
3503 _ForwardIterator __last)
3505 if (__first != __last)
3507 _ForwardIterator __temp = _VSTD::next(__first);
3508 if (__temp == __last && *__first == '$')
3510 // Not called inside a bracket
3511 if (*__first == '.' || *__first == '\\' || *__first == '[')
3513 __push_char(*__first);
3519 template <class _CharT, class _Traits>
3520 template <class _ForwardIterator>
3522 basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
3523 _ForwardIterator __last)
3525 if (__first != __last)
3542 if (__open_count_ == 0)
3544 __push_char(*__first);
3549 __push_char(*__first);
3557 template <class _CharT, class _Traits>
3558 template <class _ForwardIterator>
3560 basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
3561 _ForwardIterator __last)
3563 if (__first != __last)
3565 _ForwardIterator __temp = _VSTD::next(__first);
3566 if (__temp != __last)
3568 if (*__first == '\\')
3578 __push_char(*__temp);
3588 template <class _CharT, class _Traits>
3589 template <class _ForwardIterator>
3591 basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
3592 _ForwardIterator __last)
3594 if (__first != __last)
3596 _ForwardIterator __temp = _VSTD::next(__first);
3597 if (__temp != __last)
3599 if (*__first == '\\')
3616 __push_char(*__temp);
3620 if (__get_grammar(__flags_) == awk)
3621 __first = __parse_awk_escape(++__first, __last);
3622 else if(__test_back_ref(*__temp))
3632 template <class _CharT, class _Traits>
3633 template <class _ForwardIterator>
3635 basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
3636 _ForwardIterator __last,
3637 __owns_one_state<_CharT>* __s,
3638 unsigned __mexp_begin,
3639 unsigned __mexp_end)
3641 if (__first != __last)
3643 if (*__first == '*')
3645 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3650 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3651 if (__temp != __first)
3655 __temp = __parse_DUP_COUNT(__first, __last, __min);
3656 if (__temp == __first)
3657 __throw_regex_error<regex_constants::error_badbrace>();
3659 if (__first == __last)
3660 __throw_regex_error<regex_constants::error_brace>();
3661 if (*__first != ',')
3663 __temp = __parse_Back_close_brace(__first, __last);
3664 if (__temp == __first)
3665 __throw_regex_error<regex_constants::error_brace>();
3666 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
3672 ++__first; // consume ','
3674 __first = __parse_DUP_COUNT(__first, __last, __max);
3675 __temp = __parse_Back_close_brace(__first, __last);
3676 if (__temp == __first)
3677 __throw_regex_error<regex_constants::error_brace>();
3679 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3683 __throw_regex_error<regex_constants::error_badbrace>();
3684 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
3695 template <class _CharT, class _Traits>
3696 template <class _ForwardIterator>
3698 basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
3699 _ForwardIterator __last,
3700 __owns_one_state<_CharT>* __s,
3701 unsigned __mexp_begin,
3702 unsigned __mexp_end)
3704 if (__first != __last)
3706 unsigned __grammar = __get_grammar(__flags_);
3711 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3714 __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3717 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3721 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3724 __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3727 __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3731 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3734 __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3737 __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
3742 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
3743 if (__temp == __first)
3744 __throw_regex_error<regex_constants::error_badbrace>();
3746 if (__first == __last)
3747 __throw_regex_error<regex_constants::error_brace>();
3752 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3755 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3758 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
3762 if (__first == __last)
3763 __throw_regex_error<regex_constants::error_badbrace>();
3764 if (*__first == '}')
3767 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3770 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3773 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3778 __temp = __parse_DUP_COUNT(__first, __last, __max);
3779 if (__temp == __first)
3780 __throw_regex_error<regex_constants::error_brace>();
3782 if (__first == __last || *__first != '}')
3783 __throw_regex_error<regex_constants::error_brace>();
3786 __throw_regex_error<regex_constants::error_badbrace>();
3787 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3790 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3793 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
3797 __throw_regex_error<regex_constants::error_badbrace>();
3806 template <class _CharT, class _Traits>
3807 template <class _ForwardIterator>
3809 basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
3810 _ForwardIterator __last)
3812 if (__first != __last && *__first == '[')
3815 if (__first == __last)
3816 __throw_regex_error<regex_constants::error_brack>();
3817 bool __negate = false;
3818 if (*__first == '^')
3823 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3824 // __ml owned by *this
3825 if (__first == __last)
3826 __throw_regex_error<regex_constants::error_brack>();
3827 if (__get_grammar(__flags_) != ECMAScript && *__first == ']')
3829 __ml->__add_char(']');
3832 __first = __parse_follow_list(__first, __last, __ml);
3833 if (__first == __last)
3834 __throw_regex_error<regex_constants::error_brack>();
3835 if (*__first == '-')
3837 __ml->__add_char('-');
3840 if (__first == __last || *__first != ']')
3841 __throw_regex_error<regex_constants::error_brack>();
3847 template <class _CharT, class _Traits>
3848 template <class _ForwardIterator>
3850 basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
3851 _ForwardIterator __last,
3852 __bracket_expression<_CharT, _Traits>* __ml)
3854 if (__first != __last)
3858 _ForwardIterator __temp = __parse_expression_term(__first, __last,
3860 if (__temp == __first)
3868 template <class _CharT, class _Traits>
3869 template <class _ForwardIterator>
3871 basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
3872 _ForwardIterator __last,
3873 __bracket_expression<_CharT, _Traits>* __ml)
3875 if (__first != __last && *__first != ']')
3877 _ForwardIterator __temp = _VSTD::next(__first);
3878 basic_string<_CharT> __start_range;
3879 if (__temp != __last && *__first == '[')
3882 return __parse_equivalence_class(++__temp, __last, __ml);
3883 else if (*__temp == ':')
3884 return __parse_character_class(++__temp, __last, __ml);
3885 else if (*__temp == '.')
3886 __first = __parse_collating_symbol(++__temp, __last, __start_range);
3888 unsigned __grammar = __get_grammar(__flags_);
3889 if (__start_range.empty())
3891 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3893 if (__grammar == ECMAScript)
3894 __first = __parse_class_escape(++__first, __last, __start_range, __ml);
3896 __first = __parse_awk_escape(++__first, __last, &__start_range);
3900 __start_range = *__first;
3904 if (__first != __last && *__first != ']')
3906 __temp = _VSTD::next(__first);
3907 if (__temp != __last && *__first == '-' && *__temp != ']')
3910 basic_string<_CharT> __end_range;
3913 if (__temp != __last && *__first == '[' && *__temp == '.')
3914 __first = __parse_collating_symbol(++__temp, __last, __end_range);
3917 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3919 if (__grammar == ECMAScript)
3920 __first = __parse_class_escape(++__first, __last,
3923 __first = __parse_awk_escape(++__first, __last,
3928 __end_range = *__first;
3932 __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range));
3934 else if (!__start_range.empty())
3936 if (__start_range.size() == 1)
3937 __ml->__add_char(__start_range[0]);
3939 __ml->__add_digraph(__start_range[0], __start_range[1]);
3942 else if (!__start_range.empty())
3944 if (__start_range.size() == 1)
3945 __ml->__add_char(__start_range[0]);
3947 __ml->__add_digraph(__start_range[0], __start_range[1]);
3953 template <class _CharT, class _Traits>
3954 template <class _ForwardIterator>
3956 basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
3957 _ForwardIterator __last,
3958 basic_string<_CharT>& __str,
3959 __bracket_expression<_CharT, _Traits>* __ml)
3961 if (__first == __last)
3962 __throw_regex_error<regex_constants::error_escape>();
3972 __ml->__add_class(ctype_base::digit);
3975 __ml->__add_neg_class(ctype_base::digit);
3978 __ml->__add_class(ctype_base::space);
3981 __ml->__add_neg_class(ctype_base::space);
3984 __ml->__add_class(ctype_base::alnum);
3985 __ml->__add_char('_');
3988 __ml->__add_neg_class(ctype_base::alnum);
3989 __ml->__add_neg_char('_');
3992 __first = __parse_character_escape(__first, __last, &__str);
3996 template <class _CharT, class _Traits>
3997 template <class _ForwardIterator>
3999 basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
4000 _ForwardIterator __last,
4001 basic_string<_CharT>* __str)
4003 if (__first == __last)
4004 __throw_regex_error<regex_constants::error_escape>();
4013 __push_char(*__first);
4019 __push_char(_CharT(7));
4025 __push_char(_CharT(8));
4029 *__str = _CharT(0xC);
4031 __push_char(_CharT(0xC));
4035 *__str = _CharT(0xA);
4037 __push_char(_CharT(0xA));
4041 *__str = _CharT(0xD);
4043 __push_char(_CharT(0xD));
4047 *__str = _CharT(0x9);
4049 __push_char(_CharT(0x9));
4053 *__str = _CharT(0xB);
4055 __push_char(_CharT(0xB));
4058 if ('0' <= *__first && *__first <= '7')
4060 unsigned __val = *__first - '0';
4061 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
4063 __val = 8 * __val + *__first - '0';
4064 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
4065 __val = 8 * __val + *__first++ - '0';
4068 *__str = _CharT(__val);
4070 __push_char(_CharT(__val));
4073 __throw_regex_error<regex_constants::error_escape>();
4077 template <class _CharT, class _Traits>
4078 template <class _ForwardIterator>
4080 basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
4081 _ForwardIterator __last,
4082 __bracket_expression<_CharT, _Traits>* __ml)
4085 // This means =] must exist
4086 value_type _Equal_close[2] = {'=', ']'};
4087 _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close,
4089 if (__temp == __last)
4090 __throw_regex_error<regex_constants::error_brack>();
4091 // [__first, __temp) contains all text in [= ... =]
4092 string_type __collate_name =
4093 __traits_.lookup_collatename(__first, __temp);
4094 if (__collate_name.empty())
4095 __throw_regex_error<regex_constants::error_collate>();
4096 string_type __equiv_name =
4097 __traits_.transform_primary(__collate_name.begin(),
4098 __collate_name.end());
4099 if (!__equiv_name.empty())
4100 __ml->__add_equivalence(__equiv_name);
4103 switch (__collate_name.size())
4106 __ml->__add_char(__collate_name[0]);
4109 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
4112 __throw_regex_error<regex_constants::error_collate>();
4115 __first = _VSTD::next(__temp, 2);
4119 template <class _CharT, class _Traits>
4120 template <class _ForwardIterator>
4122 basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
4123 _ForwardIterator __last,
4124 __bracket_expression<_CharT, _Traits>* __ml)
4127 // This means :] must exist
4128 value_type _Colon_close[2] = {':', ']'};
4129 _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close,
4131 if (__temp == __last)
4132 __throw_regex_error<regex_constants::error_brack>();
4133 // [__first, __temp) contains all text in [: ... :]
4134 typedef typename _Traits::char_class_type char_class_type;
4135 char_class_type __class_type =
4136 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
4137 if (__class_type == 0)
4138 __throw_regex_error<regex_constants::error_ctype>();
4139 __ml->__add_class(__class_type);
4140 __first = _VSTD::next(__temp, 2);
4144 template <class _CharT, class _Traits>
4145 template <class _ForwardIterator>
4147 basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
4148 _ForwardIterator __last,
4149 basic_string<_CharT>& __col_sym)
4152 // This means .] must exist
4153 value_type _Dot_close[2] = {'.', ']'};
4154 _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close,
4156 if (__temp == __last)
4157 __throw_regex_error<regex_constants::error_brack>();
4158 // [__first, __temp) contains all text in [. ... .]
4159 __col_sym = __traits_.lookup_collatename(__first, __temp);
4160 switch (__col_sym.size())
4166 __throw_regex_error<regex_constants::error_collate>();
4168 __first = _VSTD::next(__temp, 2);
4172 template <class _CharT, class _Traits>
4173 template <class _ForwardIterator>
4175 basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
4176 _ForwardIterator __last,
4179 if (__first != __last )
4181 int __val = __traits_.value(*__first, 10);
4186 __first != __last && ( __val = __traits_.value(*__first, 10)) != -1;
4189 if (__c >= numeric_limits<int>::max() / 10)
4190 __throw_regex_error<regex_constants::error_badbrace>();
4199 template <class _CharT, class _Traits>
4200 template <class _ForwardIterator>
4202 basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
4203 _ForwardIterator __last)
4205 __owns_one_state<_CharT>* __sa = __end_;
4206 _ForwardIterator __temp = __parse_alternative(__first, __last);
4207 if (__temp == __first)
4210 while (__first != __last && *__first == '|')
4212 __owns_one_state<_CharT>* __sb = __end_;
4213 __temp = __parse_alternative(++__first, __last);
4214 if (__temp == __first)
4216 __push_alternation(__sa, __sb);
4222 template <class _CharT, class _Traits>
4223 template <class _ForwardIterator>
4225 basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
4226 _ForwardIterator __last)
4230 _ForwardIterator __temp = __parse_term(__first, __last);
4231 if (__temp == __first)
4238 template <class _CharT, class _Traits>
4239 template <class _ForwardIterator>
4241 basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
4242 _ForwardIterator __last)
4244 _ForwardIterator __temp = __parse_assertion(__first, __last);
4245 if (__temp == __first)
4247 __owns_one_state<_CharT>* __e = __end_;
4248 unsigned __mexp_begin = __marked_count_;
4249 __temp = __parse_atom(__first, __last);
4250 if (__temp != __first)
4251 __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
4252 __mexp_begin+1, __marked_count_+1);
4259 template <class _CharT, class _Traits>
4260 template <class _ForwardIterator>
4262 basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
4263 _ForwardIterator __last)
4265 if (__first != __last)
4279 _ForwardIterator __temp = _VSTD::next(__first);
4280 if (__temp != __last)
4284 __push_word_boundary(false);
4287 else if (*__temp == 'B')
4289 __push_word_boundary(true);
4297 _ForwardIterator __temp = _VSTD::next(__first);
4298 if (__temp != __last && *__temp == '?')
4300 if (++__temp != __last)
4307 __exp.__flags_ = __flags_;
4308 __temp = __exp.__parse(++__temp, __last);
4309 unsigned __mexp = __exp.__marked_count_;
4310 __push_lookahead(_VSTD::move(__exp), false, __marked_count_);
4311 __marked_count_ += __mexp;
4312 if (__temp == __last || *__temp != ')')
4313 __throw_regex_error<regex_constants::error_paren>();
4320 __exp.__flags_ = __flags_;
4321 __temp = __exp.__parse(++__temp, __last);
4322 unsigned __mexp = __exp.__marked_count_;
4323 __push_lookahead(_VSTD::move(__exp), true, __marked_count_);
4324 __marked_count_ += __mexp;
4325 if (__temp == __last || *__temp != ')')
4326 __throw_regex_error<regex_constants::error_paren>();
4340 template <class _CharT, class _Traits>
4341 template <class _ForwardIterator>
4343 basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
4344 _ForwardIterator __last)
4346 if (__first != __last)
4351 __push_match_any_but_newline();
4355 __first = __parse_atom_escape(__first, __last);
4358 __first = __parse_bracket_expression(__first, __last);
4363 if (__first == __last)
4364 __throw_regex_error<regex_constants::error_paren>();
4365 _ForwardIterator __temp = _VSTD::next(__first);
4366 if (__temp != __last && *__first == '?' && *__temp == ':')
4369 __first = __parse_ecma_exp(++__temp, __last);
4370 if (__first == __last || *__first != ')')
4371 __throw_regex_error<regex_constants::error_paren>();
4377 __push_begin_marked_subexpression();
4378 unsigned __temp_count = __marked_count_;
4380 __first = __parse_ecma_exp(__first, __last);
4381 if (__first == __last || *__first != ')')
4382 __throw_regex_error<regex_constants::error_paren>();
4383 __push_end_marked_subexpression(__temp_count);
4393 __throw_regex_error<regex_constants::error_badrepeat>();
4396 __first = __parse_pattern_character(__first, __last);
4403 template <class _CharT, class _Traits>
4404 template <class _ForwardIterator>
4406 basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
4407 _ForwardIterator __last)
4409 if (__first != __last && *__first == '\\')
4411 _ForwardIterator __t1 = _VSTD::next(__first);
4413 __throw_regex_error<regex_constants::error_escape>();
4415 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
4420 __t2 = __parse_character_class_escape(__t1, __last);
4425 __t2 = __parse_character_escape(__t1, __last);
4434 template <class _CharT, class _Traits>
4435 template <class _ForwardIterator>
4437 basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
4438 _ForwardIterator __last)
4440 if (__first != __last)
4442 if (*__first == '0')
4444 __push_char(_CharT());
4447 else if ('1' <= *__first && *__first <= '9')
4449 unsigned __v = *__first - '0';
4451 __first != __last && '0' <= *__first && *__first <= '9'; ++__first)
4453 if (__v >= numeric_limits<unsigned>::max() / 10)
4454 __throw_regex_error<regex_constants::error_backref>();
4455 __v = 10 * __v + *__first - '0';
4457 if (__v == 0 || __v > mark_count())
4458 __throw_regex_error<regex_constants::error_backref>();
4459 __push_back_ref(__v);
4465 template <class _CharT, class _Traits>
4466 template <class _ForwardIterator>
4468 basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
4469 _ForwardIterator __last)
4471 if (__first != __last)
4473 __bracket_expression<_CharT, _Traits>* __ml;
4477 __ml = __start_matching_list(false);
4478 __ml->__add_class(ctype_base::digit);
4482 __ml = __start_matching_list(true);
4483 __ml->__add_class(ctype_base::digit);
4487 __ml = __start_matching_list(false);
4488 __ml->__add_class(ctype_base::space);
4492 __ml = __start_matching_list(true);
4493 __ml->__add_class(ctype_base::space);
4497 __ml = __start_matching_list(false);
4498 __ml->__add_class(ctype_base::alnum);
4499 __ml->__add_char('_');
4503 __ml = __start_matching_list(true);
4504 __ml->__add_class(ctype_base::alnum);
4505 __ml->__add_char('_');
4513 template <class _CharT, class _Traits>
4514 template <class _ForwardIterator>
4516 basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
4517 _ForwardIterator __last,
4518 basic_string<_CharT>* __str)
4520 if (__first != __last)
4522 _ForwardIterator __t;
4529 *__str = _CharT(0xC);
4531 __push_char(_CharT(0xC));
4536 *__str = _CharT(0xA);
4538 __push_char(_CharT(0xA));
4543 *__str = _CharT(0xD);
4545 __push_char(_CharT(0xD));
4550 *__str = _CharT(0x9);
4552 __push_char(_CharT(0x9));
4557 *__str = _CharT(0xB);
4559 __push_char(_CharT(0xB));
4563 if ((__t = _VSTD::next(__first)) != __last)
4565 if (('A' <= *__t && *__t <= 'Z') ||
4566 ('a' <= *__t && *__t <= 'z'))
4569 *__str = _CharT(*__t % 32);
4571 __push_char(_CharT(*__t % 32));
4575 __throw_regex_error<regex_constants::error_escape>();
4578 __throw_regex_error<regex_constants::error_escape>();
4582 if (__first == __last)
4583 __throw_regex_error<regex_constants::error_escape>();
4584 __hd = __traits_.value(*__first, 16);
4586 __throw_regex_error<regex_constants::error_escape>();
4587 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4589 if (__first == __last)
4590 __throw_regex_error<regex_constants::error_escape>();
4591 __hd = __traits_.value(*__first, 16);
4593 __throw_regex_error<regex_constants::error_escape>();
4594 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4598 if (__first == __last)
4599 __throw_regex_error<regex_constants::error_escape>();
4600 __hd = __traits_.value(*__first, 16);
4602 __throw_regex_error<regex_constants::error_escape>();
4603 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4605 if (__first == __last)
4606 __throw_regex_error<regex_constants::error_escape>();
4607 __hd = __traits_.value(*__first, 16);
4609 __throw_regex_error<regex_constants::error_escape>();
4610 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4612 *__str = _CharT(__sum);
4614 __push_char(_CharT(__sum));
4621 __push_char(_CharT(0));
4625 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
4630 __push_char(*__first);
4634 __throw_regex_error<regex_constants::error_escape>();
4641 template <class _CharT, class _Traits>
4642 template <class _ForwardIterator>
4644 basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
4645 _ForwardIterator __last)
4647 if (__first != __last)
4667 __push_char(*__first);
4675 template <class _CharT, class _Traits>
4676 template <class _ForwardIterator>
4678 basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
4679 _ForwardIterator __last)
4681 __owns_one_state<_CharT>* __sa = __end_;
4682 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4683 if (__t1 != __first)
4684 __parse_basic_reg_exp(__first, __t1);
4688 if (__first != __last)
4690 while (__first != __last)
4692 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4693 __owns_one_state<_CharT>* __sb = __end_;
4694 if (__t1 != __first)
4695 __parse_basic_reg_exp(__first, __t1);
4698 __push_alternation(__sa, __sb);
4700 if (__first != __last)
4706 template <class _CharT, class _Traits>
4707 template <class _ForwardIterator>
4709 basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
4710 _ForwardIterator __last)
4712 __owns_one_state<_CharT>* __sa = __end_;
4713 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4714 if (__t1 != __first)
4715 __parse_extended_reg_exp(__first, __t1);
4719 if (__first != __last)
4721 while (__first != __last)
4723 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4724 __owns_one_state<_CharT>* __sb = __end_;
4725 if (__t1 != __first)
4726 __parse_extended_reg_exp(__first, __t1);
4729 __push_alternation(__sa, __sb);
4731 if (__first != __last)
4737 template <class _CharT, class _Traits>
4739 basic_regex<_CharT, _Traits>::__test_back_ref(_CharT c)
4741 unsigned __val = __traits_.value(c, 10);
4742 if (__val >= 1 && __val <= 9)
4744 if (__val > mark_count())
4745 __throw_regex_error<regex_constants::error_backref>();
4746 __push_back_ref(__val);
4753 template <class _CharT, class _Traits>
4755 basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
4756 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
4759 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4760 __end_->first() = nullptr;
4761 unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
4762 __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
4764 __s->first() = nullptr;
4766 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
4767 __end_ = __e2->second();
4768 __s->first() = __e2.release();
4772 template <class _CharT, class _Traits>
4774 basic_regex<_CharT, _Traits>::__push_char(value_type __c)
4776 if (flags() & icase)
4777 __end_->first() = new __match_char_icase<_CharT, _Traits>
4778 (__traits_, __c, __end_->first());
4779 else if (flags() & collate)
4780 __end_->first() = new __match_char_collate<_CharT, _Traits>
4781 (__traits_, __c, __end_->first());
4783 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
4784 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4787 template <class _CharT, class _Traits>
4789 basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
4791 if (!(__flags_ & nosubs))
4794 new __begin_marked_subexpression<_CharT>(++__marked_count_,
4796 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4800 template <class _CharT, class _Traits>
4802 basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
4804 if (!(__flags_ & nosubs))
4807 new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4808 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4812 template <class _CharT, class _Traits>
4814 basic_regex<_CharT, _Traits>::__push_l_anchor()
4816 __end_->first() = new __l_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
4817 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4820 template <class _CharT, class _Traits>
4822 basic_regex<_CharT, _Traits>::__push_r_anchor()
4824 __end_->first() = new __r_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
4825 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4828 template <class _CharT, class _Traits>
4830 basic_regex<_CharT, _Traits>::__push_match_any()
4832 __end_->first() = new __match_any<_CharT>(__end_->first());
4833 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4836 template <class _CharT, class _Traits>
4838 basic_regex<_CharT, _Traits>::__push_match_any_but_newline()
4840 __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
4841 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4844 template <class _CharT, class _Traits>
4846 basic_regex<_CharT, _Traits>::__push_empty()
4848 __end_->first() = new __empty_state<_CharT>(__end_->first());
4849 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4852 template <class _CharT, class _Traits>
4854 basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
4856 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
4858 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4861 template <class _CharT, class _Traits>
4863 basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
4865 if (flags() & icase)
4866 __end_->first() = new __back_ref_icase<_CharT, _Traits>
4867 (__traits_, __i, __end_->first());
4868 else if (flags() & collate)
4869 __end_->first() = new __back_ref_collate<_CharT, _Traits>
4870 (__traits_, __i, __end_->first());
4872 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
4873 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4876 template <class _CharT, class _Traits>
4878 basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
4879 __owns_one_state<_CharT>* __ea)
4881 __sa->first() = new __alternate<_CharT>(
4882 static_cast<__owns_one_state<_CharT>*>(__sa->first()),
4883 static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4884 __ea->first() = nullptr;
4885 __ea->first() = new __empty_state<_CharT>(__end_->first());
4886 __end_->first() = nullptr;
4887 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4888 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4891 template <class _CharT, class _Traits>
4892 __bracket_expression<_CharT, _Traits>*
4893 basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
4895 __bracket_expression<_CharT, _Traits>* __r =
4896 new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
4897 __negate, __flags_ & icase,
4898 __flags_ & collate);
4899 __end_->first() = __r;
4904 template <class _CharT, class _Traits>
4906 basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
4910 __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
4911 __end_->first(), __mexp);
4912 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4917 typedef sub_match<const char*> csub_match;
4918 typedef sub_match<string::const_iterator> ssub_match;
4919 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4920 typedef sub_match<const wchar_t*> wcsub_match;
4921 typedef sub_match<wstring::const_iterator> wssub_match;
4924 template <class _BidirectionalIterator>
4926 _LIBCPP_TEMPLATE_VIS
4927 _LIBCPP_PREFERRED_NAME(csub_match)
4928 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match))
4929 _LIBCPP_PREFERRED_NAME(ssub_match)
4930 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match))
4932 : public pair<_BidirectionalIterator, _BidirectionalIterator>
4935 typedef _BidirectionalIterator iterator;
4936 typedef typename iterator_traits<iterator>::value_type value_type;
4937 typedef typename iterator_traits<iterator>::difference_type difference_type;
4938 typedef basic_string<value_type> string_type;
4942 _LIBCPP_INLINE_VISIBILITY
4943 _LIBCPP_CONSTEXPR sub_match() : matched() {}
4945 _LIBCPP_INLINE_VISIBILITY
4946 difference_type length() const
4947 {return matched ? _VSTD::distance(this->first, this->second) : 0;}
4948 _LIBCPP_INLINE_VISIBILITY
4949 string_type str() const
4950 {return matched ? string_type(this->first, this->second) : string_type();}
4951 _LIBCPP_INLINE_VISIBILITY
4952 operator string_type() const
4955 _LIBCPP_INLINE_VISIBILITY
4956 int compare(const sub_match& __s) const
4957 {return str().compare(__s.str());}
4958 _LIBCPP_INLINE_VISIBILITY
4959 int compare(const string_type& __s) const
4960 {return str().compare(__s);}
4961 _LIBCPP_INLINE_VISIBILITY
4962 int compare(const value_type* __s) const
4963 {return str().compare(__s);}
4966 template <class _BiIter>
4967 inline _LIBCPP_INLINE_VISIBILITY
4969 operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4971 return __x.compare(__y) == 0;
4974 template <class _BiIter>
4975 inline _LIBCPP_INLINE_VISIBILITY
4977 operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4979 return !(__x == __y);
4982 template <class _BiIter>
4983 inline _LIBCPP_INLINE_VISIBILITY
4985 operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4987 return __x.compare(__y) < 0;
4990 template <class _BiIter>
4991 inline _LIBCPP_INLINE_VISIBILITY
4993 operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4995 return !(__y < __x);
4998 template <class _BiIter>
4999 inline _LIBCPP_INLINE_VISIBILITY
5001 operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
5003 return !(__x < __y);
5006 template <class _BiIter>
5007 inline _LIBCPP_INLINE_VISIBILITY
5009 operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
5014 template <class _BiIter, class _ST, class _SA>
5015 inline _LIBCPP_INLINE_VISIBILITY
5017 operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5018 const sub_match<_BiIter>& __y)
5020 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
5023 template <class _BiIter, class _ST, class _SA>
5024 inline _LIBCPP_INLINE_VISIBILITY
5026 operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5027 const sub_match<_BiIter>& __y)
5029 return !(__x == __y);
5032 template <class _BiIter, class _ST, class _SA>
5033 inline _LIBCPP_INLINE_VISIBILITY
5035 operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5036 const sub_match<_BiIter>& __y)
5038 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
5041 template <class _BiIter, class _ST, class _SA>
5042 inline _LIBCPP_INLINE_VISIBILITY
5044 operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5045 const sub_match<_BiIter>& __y)
5050 template <class _BiIter, class _ST, class _SA>
5051 inline _LIBCPP_INLINE_VISIBILITY
5052 bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5053 const sub_match<_BiIter>& __y)
5055 return !(__x < __y);
5058 template <class _BiIter, class _ST, class _SA>
5059 inline _LIBCPP_INLINE_VISIBILITY
5061 operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5062 const sub_match<_BiIter>& __y)
5064 return !(__y < __x);
5067 template <class _BiIter, class _ST, class _SA>
5068 inline _LIBCPP_INLINE_VISIBILITY
5070 operator==(const sub_match<_BiIter>& __x,
5071 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5073 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
5076 template <class _BiIter, class _ST, class _SA>
5077 inline _LIBCPP_INLINE_VISIBILITY
5079 operator!=(const sub_match<_BiIter>& __x,
5080 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5082 return !(__x == __y);
5085 template <class _BiIter, class _ST, class _SA>
5086 inline _LIBCPP_INLINE_VISIBILITY
5088 operator<(const sub_match<_BiIter>& __x,
5089 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5091 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
5094 template <class _BiIter, class _ST, class _SA>
5095 inline _LIBCPP_INLINE_VISIBILITY
5096 bool operator>(const sub_match<_BiIter>& __x,
5097 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5102 template <class _BiIter, class _ST, class _SA>
5103 inline _LIBCPP_INLINE_VISIBILITY
5105 operator>=(const sub_match<_BiIter>& __x,
5106 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5108 return !(__x < __y);
5111 template <class _BiIter, class _ST, class _SA>
5112 inline _LIBCPP_INLINE_VISIBILITY
5114 operator<=(const sub_match<_BiIter>& __x,
5115 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5117 return !(__y < __x);
5120 template <class _BiIter>
5121 inline _LIBCPP_INLINE_VISIBILITY
5123 operator==(typename iterator_traits<_BiIter>::value_type const* __x,
5124 const sub_match<_BiIter>& __y)
5126 return __y.compare(__x) == 0;
5129 template <class _BiIter>
5130 inline _LIBCPP_INLINE_VISIBILITY
5132 operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
5133 const sub_match<_BiIter>& __y)
5135 return !(__x == __y);
5138 template <class _BiIter>
5139 inline _LIBCPP_INLINE_VISIBILITY
5141 operator<(typename iterator_traits<_BiIter>::value_type const* __x,
5142 const sub_match<_BiIter>& __y)
5144 return __y.compare(__x) > 0;
5147 template <class _BiIter>
5148 inline _LIBCPP_INLINE_VISIBILITY
5150 operator>(typename iterator_traits<_BiIter>::value_type const* __x,
5151 const sub_match<_BiIter>& __y)
5156 template <class _BiIter>
5157 inline _LIBCPP_INLINE_VISIBILITY
5159 operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
5160 const sub_match<_BiIter>& __y)
5162 return !(__x < __y);
5165 template <class _BiIter>
5166 inline _LIBCPP_INLINE_VISIBILITY
5168 operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
5169 const sub_match<_BiIter>& __y)
5171 return !(__y < __x);
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 __x.compare(__y) == 0;
5183 template <class _BiIter>
5184 inline _LIBCPP_INLINE_VISIBILITY
5186 operator!=(const sub_match<_BiIter>& __x,
5187 typename iterator_traits<_BiIter>::value_type const* __y)
5189 return !(__x == __y);
5192 template <class _BiIter>
5193 inline _LIBCPP_INLINE_VISIBILITY
5195 operator<(const sub_match<_BiIter>& __x,
5196 typename iterator_traits<_BiIter>::value_type const* __y)
5198 return __x.compare(__y) < 0;
5201 template <class _BiIter>
5202 inline _LIBCPP_INLINE_VISIBILITY
5204 operator>(const sub_match<_BiIter>& __x,
5205 typename iterator_traits<_BiIter>::value_type const* __y)
5210 template <class _BiIter>
5211 inline _LIBCPP_INLINE_VISIBILITY
5213 operator>=(const sub_match<_BiIter>& __x,
5214 typename iterator_traits<_BiIter>::value_type const* __y)
5216 return !(__x < __y);
5219 template <class _BiIter>
5220 inline _LIBCPP_INLINE_VISIBILITY
5222 operator<=(const sub_match<_BiIter>& __x,
5223 typename iterator_traits<_BiIter>::value_type const* __y)
5225 return !(__y < __x);
5228 template <class _BiIter>
5229 inline _LIBCPP_INLINE_VISIBILITY
5231 operator==(typename iterator_traits<_BiIter>::value_type const& __x,
5232 const sub_match<_BiIter>& __y)
5234 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5235 return __y.compare(string_type(1, __x)) == 0;
5238 template <class _BiIter>
5239 inline _LIBCPP_INLINE_VISIBILITY
5241 operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
5242 const sub_match<_BiIter>& __y)
5244 return !(__x == __y);
5247 template <class _BiIter>
5248 inline _LIBCPP_INLINE_VISIBILITY
5250 operator<(typename iterator_traits<_BiIter>::value_type const& __x,
5251 const sub_match<_BiIter>& __y)
5253 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5254 return __y.compare(string_type(1, __x)) > 0;
5257 template <class _BiIter>
5258 inline _LIBCPP_INLINE_VISIBILITY
5260 operator>(typename iterator_traits<_BiIter>::value_type const& __x,
5261 const sub_match<_BiIter>& __y)
5266 template <class _BiIter>
5267 inline _LIBCPP_INLINE_VISIBILITY
5269 operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
5270 const sub_match<_BiIter>& __y)
5272 return !(__x < __y);
5275 template <class _BiIter>
5276 inline _LIBCPP_INLINE_VISIBILITY
5278 operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
5279 const sub_match<_BiIter>& __y)
5281 return !(__y < __x);
5284 template <class _BiIter>
5285 inline _LIBCPP_INLINE_VISIBILITY
5287 operator==(const sub_match<_BiIter>& __x,
5288 typename iterator_traits<_BiIter>::value_type const& __y)
5290 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5291 return __x.compare(string_type(1, __y)) == 0;
5294 template <class _BiIter>
5295 inline _LIBCPP_INLINE_VISIBILITY
5297 operator!=(const sub_match<_BiIter>& __x,
5298 typename iterator_traits<_BiIter>::value_type const& __y)
5300 return !(__x == __y);
5303 template <class _BiIter>
5304 inline _LIBCPP_INLINE_VISIBILITY
5306 operator<(const sub_match<_BiIter>& __x,
5307 typename iterator_traits<_BiIter>::value_type const& __y)
5309 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5310 return __x.compare(string_type(1, __y)) < 0;
5313 template <class _BiIter>
5314 inline _LIBCPP_INLINE_VISIBILITY
5316 operator>(const sub_match<_BiIter>& __x,
5317 typename iterator_traits<_BiIter>::value_type const& __y)
5322 template <class _BiIter>
5323 inline _LIBCPP_INLINE_VISIBILITY
5325 operator>=(const sub_match<_BiIter>& __x,
5326 typename iterator_traits<_BiIter>::value_type const& __y)
5328 return !(__x < __y);
5331 template <class _BiIter>
5332 inline _LIBCPP_INLINE_VISIBILITY
5334 operator<=(const sub_match<_BiIter>& __x,
5335 typename iterator_traits<_BiIter>::value_type const& __y)
5337 return !(__y < __x);
5340 template <class _CharT, class _ST, class _BiIter>
5341 inline _LIBCPP_INLINE_VISIBILITY
5342 basic_ostream<_CharT, _ST>&
5343 operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
5345 return __os << __m.str();
5348 typedef match_results<const char*> cmatch;
5349 typedef match_results<string::const_iterator> smatch;
5350 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5351 typedef match_results<const wchar_t*> wcmatch;
5352 typedef match_results<wstring::const_iterator> wsmatch;
5355 template <class _BidirectionalIterator, class _Allocator>
5357 _LIBCPP_TEMPLATE_VIS
5358 _LIBCPP_PREFERRED_NAME(cmatch)
5359 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch))
5360 _LIBCPP_PREFERRED_NAME(smatch)
5361 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch))
5365 typedef _Allocator allocator_type;
5366 typedef sub_match<_BidirectionalIterator> value_type;
5368 typedef vector<value_type, allocator_type> __container_type;
5370 __container_type __matches_;
5371 value_type __unmatched_;
5372 value_type __prefix_;
5373 value_type __suffix_;
5376 _BidirectionalIterator __position_start_;
5377 typedef const value_type& const_reference;
5378 typedef value_type& reference;
5379 typedef typename __container_type::const_iterator const_iterator;
5380 typedef const_iterator iterator;
5381 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
5382 typedef typename allocator_traits<allocator_type>::size_type size_type;
5383 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
5384 typedef basic_string<char_type> string_type;
5386 // construct/copy/destroy:
5387 #ifndef _LIBCPP_CXX03_LANG
5388 match_results() : match_results(allocator_type()) {}
5389 explicit match_results(const allocator_type& __a);
5391 explicit match_results(const allocator_type& __a = allocator_type());
5394 // match_results(const match_results&) = default;
5395 // match_results& operator=(const match_results&) = default;
5396 // match_results(match_results&& __m) = default;
5397 // match_results& operator=(match_results&& __m) = default;
5398 // ~match_results() = default;
5400 _LIBCPP_INLINE_VISIBILITY
5401 bool ready() const {return __ready_;}
5404 _LIBCPP_INLINE_VISIBILITY
5405 size_type size() const _NOEXCEPT {return __matches_.size();}
5406 _LIBCPP_INLINE_VISIBILITY
5407 size_type max_size() const _NOEXCEPT {return __matches_.max_size();}
5408 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5409 bool empty() const _NOEXCEPT {return size() == 0;}
5412 _LIBCPP_INLINE_VISIBILITY
5413 difference_type length(size_type __sub = 0) const
5415 _LIBCPP_ASSERT(ready(), "match_results::length() called when not ready");
5416 return (*this)[__sub].length();
5418 _LIBCPP_INLINE_VISIBILITY
5419 difference_type position(size_type __sub = 0) const
5421 _LIBCPP_ASSERT(ready(), "match_results::position() called when not ready");
5422 return _VSTD::distance(__position_start_, (*this)[__sub].first);
5424 _LIBCPP_INLINE_VISIBILITY
5425 string_type str(size_type __sub = 0) const
5427 _LIBCPP_ASSERT(ready(), "match_results::str() called when not ready");
5428 return (*this)[__sub].str();
5430 _LIBCPP_INLINE_VISIBILITY
5431 const_reference operator[](size_type __n) const
5433 _LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready");
5434 return __n < __matches_.size() ? __matches_[__n] : __unmatched_;
5437 _LIBCPP_INLINE_VISIBILITY
5438 const_reference prefix() const
5440 _LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready");
5443 _LIBCPP_INLINE_VISIBILITY
5444 const_reference suffix() const
5446 _LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready");
5450 _LIBCPP_INLINE_VISIBILITY
5451 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();}
5452 _LIBCPP_INLINE_VISIBILITY
5453 const_iterator end() const {return __matches_.end();}
5454 _LIBCPP_INLINE_VISIBILITY
5455 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();}
5456 _LIBCPP_INLINE_VISIBILITY
5457 const_iterator cend() const {return __matches_.end();}
5460 template <class _OutputIter>
5462 format(_OutputIter __output_iter, const char_type* __fmt_first,
5463 const char_type* __fmt_last,
5464 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
5465 template <class _OutputIter, class _ST, class _SA>
5466 _LIBCPP_INLINE_VISIBILITY
5468 format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt,
5469 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5470 {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
5471 template <class _ST, class _SA>
5472 _LIBCPP_INLINE_VISIBILITY
5473 basic_string<char_type, _ST, _SA>
5474 format(const basic_string<char_type, _ST, _SA>& __fmt,
5475 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5477 basic_string<char_type, _ST, _SA> __r;
5478 format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
5482 _LIBCPP_INLINE_VISIBILITY
5484 format(const char_type* __fmt,
5485 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5488 format(back_inserter(__r), __fmt,
5489 __fmt + char_traits<char_type>::length(__fmt), __flags);
5494 _LIBCPP_INLINE_VISIBILITY
5495 allocator_type get_allocator() const {return __matches_.get_allocator();}
5498 void swap(match_results& __m);
5500 template <class _Bp, class _Ap>
5501 _LIBCPP_INLINE_VISIBILITY
5502 void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
5503 const match_results<_Bp, _Ap>& __m, bool __no_update_pos)
5505 _Bp __mf = __m.prefix().first;
5506 __matches_.resize(__m.size());
5507 for (size_type __i = 0; __i < __matches_.size(); ++__i)
5509 __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first));
5510 __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second));
5511 __matches_[__i].matched = __m[__i].matched;
5513 __unmatched_.first = __l;
5514 __unmatched_.second = __l;
5515 __unmatched_.matched = false;
5516 __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first));
5517 __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second));
5518 __prefix_.matched = __m.prefix().matched;
5519 __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first));
5520 __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second));
5521 __suffix_.matched = __m.suffix().matched;
5522 if (!__no_update_pos)
5523 __position_start_ = __prefix_.first;
5524 __ready_ = __m.ready();
5528 void __init(unsigned __s,
5529 _BidirectionalIterator __f, _BidirectionalIterator __l,
5530 bool __no_update_pos = false);
5532 template <class, class> friend class basic_regex;
5534 template <class _Bp, class _Ap, class _Cp, class _Tp>
5537 regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
5538 regex_constants::match_flag_type);
5540 template <class _Bp, class _Ap>
5543 operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
5545 template <class, class> friend class __lookahead;
5548 template <class _BidirectionalIterator, class _Allocator>
5549 match_results<_BidirectionalIterator, _Allocator>::match_results(
5550 const allocator_type& __a)
5560 template <class _BidirectionalIterator, class _Allocator>
5562 match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
5563 _BidirectionalIterator __f, _BidirectionalIterator __l,
5564 bool __no_update_pos)
5566 __unmatched_.first = __l;
5567 __unmatched_.second = __l;
5568 __unmatched_.matched = false;
5569 __matches_.assign(__s, __unmatched_);
5570 __prefix_.first = __f;
5571 __prefix_.second = __f;
5572 __prefix_.matched = false;
5573 __suffix_ = __unmatched_;
5574 if (!__no_update_pos)
5575 __position_start_ = __prefix_.first;
5579 template <class _BidirectionalIterator, class _Allocator>
5580 template <class _OutputIter>
5582 match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter,
5583 const char_type* __fmt_first, const char_type* __fmt_last,
5584 regex_constants::match_flag_type __flags) const
5586 _LIBCPP_ASSERT(ready(), "match_results::format() called when not ready");
5587 if (__flags & regex_constants::format_sed)
5589 for (; __fmt_first != __fmt_last; ++__fmt_first)
5591 if (*__fmt_first == '&')
5592 __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5594 else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
5597 if ('0' <= *__fmt_first && *__fmt_first <= '9')
5599 size_t __i = *__fmt_first - '0';
5600 __output_iter = _VSTD::copy((*this)[__i].first,
5601 (*this)[__i].second, __output_iter);
5605 *__output_iter = *__fmt_first;
5611 *__output_iter = *__fmt_first;
5618 for (; __fmt_first != __fmt_last; ++__fmt_first)
5620 if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
5622 switch (__fmt_first[1])
5625 *__output_iter = *++__fmt_first;
5630 __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5635 __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter);
5639 __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter);
5642 if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5645 size_t __idx = *__fmt_first - '0';
5646 if (__fmt_first + 1 != __fmt_last &&
5647 '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5650 if (__idx >= numeric_limits<size_t>::max() / 10)
5651 __throw_regex_error<regex_constants::error_escape>();
5652 __idx = 10 * __idx + *__fmt_first - '0';
5654 __output_iter = _VSTD::copy((*this)[__idx].first,
5655 (*this)[__idx].second, __output_iter);
5659 *__output_iter = *__fmt_first;
5667 *__output_iter = *__fmt_first;
5672 return __output_iter;
5675 template <class _BidirectionalIterator, class _Allocator>
5677 match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
5680 swap(__matches_, __m.__matches_);
5681 swap(__unmatched_, __m.__unmatched_);
5682 swap(__prefix_, __m.__prefix_);
5683 swap(__suffix_, __m.__suffix_);
5684 swap(__position_start_, __m.__position_start_);
5685 swap(__ready_, __m.__ready_);
5688 template <class _BidirectionalIterator, class _Allocator>
5690 operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
5691 const match_results<_BidirectionalIterator, _Allocator>& __y)
5693 if (__x.__ready_ != __y.__ready_)
5697 return __x.__matches_ == __y.__matches_ &&
5698 __x.__prefix_ == __y.__prefix_ &&
5699 __x.__suffix_ == __y.__suffix_;
5702 template <class _BidirectionalIterator, class _Allocator>
5703 inline _LIBCPP_INLINE_VISIBILITY
5705 operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
5706 const match_results<_BidirectionalIterator, _Allocator>& __y)
5708 return !(__x == __y);
5711 template <class _BidirectionalIterator, class _Allocator>
5712 inline _LIBCPP_INLINE_VISIBILITY
5714 swap(match_results<_BidirectionalIterator, _Allocator>& __x,
5715 match_results<_BidirectionalIterator, _Allocator>& __y)
5722 template <class _CharT, class _Traits>
5723 template <class _Allocator>
5725 basic_regex<_CharT, _Traits>::__match_at_start_ecma(
5726 const _CharT* __first, const _CharT* __last,
5727 match_results<const _CharT*, _Allocator>& __m,
5728 regex_constants::match_flag_type __flags, bool __at_first) const
5730 vector<__state> __states;
5731 __node* __st = __start_.get();
5734 sub_match<const _CharT*> __unmatched;
5735 __unmatched.first = __last;
5736 __unmatched.second = __last;
5737 __unmatched.matched = false;
5739 __states.push_back(__state());
5740 __states.back().__do_ = 0;
5741 __states.back().__first_ = __first;
5742 __states.back().__current_ = __first;
5743 __states.back().__last_ = __last;
5744 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
5745 __states.back().__loop_data_.resize(__loop_count());
5746 __states.back().__node_ = __st;
5747 __states.back().__flags_ = __flags;
5748 __states.back().__at_first_ = __at_first;
5750 int __length = __last - __first;
5754 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
5755 __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
5756 __throw_regex_error<regex_constants::error_complexity>();
5757 __state& __s = __states.back();
5759 __s.__node_->__exec(__s);
5762 case __state::__end_state:
5763 if ((__flags & regex_constants::match_not_null) &&
5764 __s.__current_ == __first)
5766 __states.pop_back();
5769 if ((__flags & regex_constants::__full_match) &&
5770 __s.__current_ != __last)
5772 __states.pop_back();
5775 __m.__matches_[0].first = __first;
5776 __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
5777 __m.__matches_[0].matched = true;
5778 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
5779 __m.__matches_[__i+1] = __s.__sub_matches_[__i];
5781 case __state::__accept_and_consume:
5782 case __state::__repeat:
5783 case __state::__accept_but_not_consume:
5785 case __state::__split:
5787 __state __snext = __s;
5788 __s.__node_->__exec_split(true, __s);
5789 __snext.__node_->__exec_split(false, __snext);
5790 __states.push_back(_VSTD::move(__snext));
5793 case __state::__reject:
5794 __states.pop_back();
5797 __throw_regex_error<regex_constants::__re_err_unknown>();
5801 } while (!__states.empty());
5806 template <class _CharT, class _Traits>
5807 template <class _Allocator>
5809 basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
5810 const _CharT* __first, const _CharT* __last,
5811 match_results<const _CharT*, _Allocator>& __m,
5812 regex_constants::match_flag_type __flags, bool __at_first) const
5814 deque<__state> __states;
5815 ptrdiff_t __highest_j = 0;
5816 ptrdiff_t _Np = _VSTD::distance(__first, __last);
5817 __node* __st = __start_.get();
5820 __states.push_back(__state());
5821 __states.back().__do_ = 0;
5822 __states.back().__first_ = __first;
5823 __states.back().__current_ = __first;
5824 __states.back().__last_ = __last;
5825 __states.back().__loop_data_.resize(__loop_count());
5826 __states.back().__node_ = __st;
5827 __states.back().__flags_ = __flags;
5828 __states.back().__at_first_ = __at_first;
5829 bool __matched = false;
5831 int __length = __last - __first;
5835 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
5836 __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
5837 __throw_regex_error<regex_constants::error_complexity>();
5838 __state& __s = __states.back();
5840 __s.__node_->__exec(__s);
5843 case __state::__end_state:
5844 if ((__flags & regex_constants::match_not_null) &&
5845 __s.__current_ == __first)
5847 __states.pop_back();
5850 if ((__flags & regex_constants::__full_match) &&
5851 __s.__current_ != __last)
5853 __states.pop_back();
5856 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
5857 __highest_j = __s.__current_ - __s.__first_;
5859 if (__highest_j == _Np)
5862 __states.pop_back();
5864 case __state::__consume_input:
5866 case __state::__accept_and_consume:
5867 __states.push_front(_VSTD::move(__s));
5868 __states.pop_back();
5870 case __state::__repeat:
5871 case __state::__accept_but_not_consume:
5873 case __state::__split:
5875 __state __snext = __s;
5876 __s.__node_->__exec_split(true, __s);
5877 __snext.__node_->__exec_split(false, __snext);
5878 __states.push_back(_VSTD::move(__snext));
5881 case __state::__reject:
5882 __states.pop_back();
5885 __throw_regex_error<regex_constants::__re_err_unknown>();
5888 } while (!__states.empty());
5891 __m.__matches_[0].first = __first;
5892 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
5893 __m.__matches_[0].matched = true;
5900 template <class _CharT, class _Traits>
5901 template <class _Allocator>
5903 basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
5904 const _CharT* __first, const _CharT* __last,
5905 match_results<const _CharT*, _Allocator>& __m,
5906 regex_constants::match_flag_type __flags, bool __at_first) const
5908 vector<__state> __states;
5909 __state __best_state;
5910 ptrdiff_t __highest_j = 0;
5911 ptrdiff_t _Np = _VSTD::distance(__first, __last);
5912 __node* __st = __start_.get();
5915 sub_match<const _CharT*> __unmatched;
5916 __unmatched.first = __last;
5917 __unmatched.second = __last;
5918 __unmatched.matched = false;
5920 __states.push_back(__state());
5921 __states.back().__do_ = 0;
5922 __states.back().__first_ = __first;
5923 __states.back().__current_ = __first;
5924 __states.back().__last_ = __last;
5925 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
5926 __states.back().__loop_data_.resize(__loop_count());
5927 __states.back().__node_ = __st;
5928 __states.back().__flags_ = __flags;
5929 __states.back().__at_first_ = __at_first;
5930 bool __matched = false;
5932 int __length = __last - __first;
5936 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
5937 __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
5938 __throw_regex_error<regex_constants::error_complexity>();
5939 __state& __s = __states.back();
5941 __s.__node_->__exec(__s);
5944 case __state::__end_state:
5945 if ((__flags & regex_constants::match_not_null) &&
5946 __s.__current_ == __first)
5948 __states.pop_back();
5951 if ((__flags & regex_constants::__full_match) &&
5952 __s.__current_ != __last)
5954 __states.pop_back();
5957 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
5959 __highest_j = __s.__current_ - __s.__first_;
5963 if (__highest_j == _Np)
5966 __states.pop_back();
5968 case __state::__accept_and_consume:
5969 case __state::__repeat:
5970 case __state::__accept_but_not_consume:
5972 case __state::__split:
5974 __state __snext = __s;
5975 __s.__node_->__exec_split(true, __s);
5976 __snext.__node_->__exec_split(false, __snext);
5977 __states.push_back(_VSTD::move(__snext));
5980 case __state::__reject:
5981 __states.pop_back();
5984 __throw_regex_error<regex_constants::__re_err_unknown>();
5987 } while (!__states.empty());
5990 __m.__matches_[0].first = __first;
5991 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
5992 __m.__matches_[0].matched = true;
5993 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
5994 __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
6001 template <class _CharT, class _Traits>
6002 template <class _Allocator>
6004 basic_regex<_CharT, _Traits>::__match_at_start(
6005 const _CharT* __first, const _CharT* __last,
6006 match_results<const _CharT*, _Allocator>& __m,
6007 regex_constants::match_flag_type __flags, bool __at_first) const
6009 if (__get_grammar(__flags_) == ECMAScript)
6010 return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
6011 if (mark_count() == 0)
6012 return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
6013 return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
6016 template <class _CharT, class _Traits>
6017 template <class _Allocator>
6019 basic_regex<_CharT, _Traits>::__search(
6020 const _CharT* __first, const _CharT* __last,
6021 match_results<const _CharT*, _Allocator>& __m,
6022 regex_constants::match_flag_type __flags) const
6024 if (__flags & regex_constants::match_prev_avail)
6025 __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow);
6027 __m.__init(1 + mark_count(), __first, __last,
6028 __flags & regex_constants::__no_update_pos);
6029 if (__match_at_start(__first, __last, __m, __flags,
6030 !(__flags & regex_constants::__no_update_pos)))
6032 __m.__prefix_.second = __m[0].first;
6033 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
6034 __m.__suffix_.first = __m[0].second;
6035 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
6038 if (__first != __last && !(__flags & regex_constants::match_continuous))
6040 __flags |= regex_constants::match_prev_avail;
6041 for (++__first; __first != __last; ++__first)
6043 __m.__matches_.assign(__m.size(), __m.__unmatched_);
6044 if (__match_at_start(__first, __last, __m, __flags, false))
6046 __m.__prefix_.second = __m[0].first;
6047 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
6048 __m.__suffix_.first = __m[0].second;
6049 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
6052 __m.__matches_.assign(__m.size(), __m.__unmatched_);
6055 __m.__matches_.clear();
6059 template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
6060 inline _LIBCPP_INLINE_VISIBILITY
6062 regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
6063 match_results<_BidirectionalIterator, _Allocator>& __m,
6064 const basic_regex<_CharT, _Traits>& __e,
6065 regex_constants::match_flag_type __flags = regex_constants::match_default)
6067 int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
6068 basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last);
6069 match_results<const _CharT*> __mc;
6070 bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
6071 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
6075 template <class _Iter, class _Allocator, class _CharT, class _Traits>
6076 inline _LIBCPP_INLINE_VISIBILITY
6078 regex_search(__wrap_iter<_Iter> __first,
6079 __wrap_iter<_Iter> __last,
6080 match_results<__wrap_iter<_Iter>, _Allocator>& __m,
6081 const basic_regex<_CharT, _Traits>& __e,
6082 regex_constants::match_flag_type __flags = regex_constants::match_default)
6084 match_results<const _CharT*> __mc;
6085 bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
6086 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
6090 template <class _Allocator, class _CharT, class _Traits>
6091 inline _LIBCPP_INLINE_VISIBILITY
6093 regex_search(const _CharT* __first, const _CharT* __last,
6094 match_results<const _CharT*, _Allocator>& __m,
6095 const basic_regex<_CharT, _Traits>& __e,
6096 regex_constants::match_flag_type __flags = regex_constants::match_default)
6098 return __e.__search(__first, __last, __m, __flags);
6101 template <class _BidirectionalIterator, class _CharT, class _Traits>
6102 inline _LIBCPP_INLINE_VISIBILITY
6104 regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
6105 const basic_regex<_CharT, _Traits>& __e,
6106 regex_constants::match_flag_type __flags = regex_constants::match_default)
6108 basic_string<_CharT> __s(__first, __last);
6109 match_results<const _CharT*> __mc;
6110 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
6113 template <class _CharT, class _Traits>
6114 inline _LIBCPP_INLINE_VISIBILITY
6116 regex_search(const _CharT* __first, const _CharT* __last,
6117 const basic_regex<_CharT, _Traits>& __e,
6118 regex_constants::match_flag_type __flags = regex_constants::match_default)
6120 match_results<const _CharT*> __mc;
6121 return __e.__search(__first, __last, __mc, __flags);
6124 template <class _CharT, class _Allocator, class _Traits>
6125 inline _LIBCPP_INLINE_VISIBILITY
6127 regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
6128 const basic_regex<_CharT, _Traits>& __e,
6129 regex_constants::match_flag_type __flags = regex_constants::match_default)
6131 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
6134 template <class _CharT, class _Traits>
6135 inline _LIBCPP_INLINE_VISIBILITY
6137 regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
6138 regex_constants::match_flag_type __flags = regex_constants::match_default)
6140 match_results<const _CharT*> __m;
6141 return _VSTD::regex_search(__str, __m, __e, __flags);
6144 template <class _ST, class _SA, class _CharT, class _Traits>
6145 inline _LIBCPP_INLINE_VISIBILITY
6147 regex_search(const basic_string<_CharT, _ST, _SA>& __s,
6148 const basic_regex<_CharT, _Traits>& __e,
6149 regex_constants::match_flag_type __flags = regex_constants::match_default)
6151 match_results<const _CharT*> __mc;
6152 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
6155 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
6156 inline _LIBCPP_INLINE_VISIBILITY
6158 regex_search(const basic_string<_CharT, _ST, _SA>& __s,
6159 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
6160 const basic_regex<_CharT, _Traits>& __e,
6161 regex_constants::match_flag_type __flags = regex_constants::match_default)
6163 match_results<const _CharT*> __mc;
6164 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
6165 __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
6169 #if _LIBCPP_STD_VER > 11
6170 template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
6172 regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
6173 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
6174 const basic_regex<_Cp, _Tp>& __e,
6175 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
6180 template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
6182 regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
6183 match_results<_BidirectionalIterator, _Allocator>& __m,
6184 const basic_regex<_CharT, _Traits>& __e,
6185 regex_constants::match_flag_type __flags = regex_constants::match_default)
6187 bool __r = _VSTD::regex_search(
6188 __first, __last, __m, __e,
6189 __flags | regex_constants::match_continuous |
6190 regex_constants::__full_match);
6193 __r = !__m.suffix().matched;
6195 __m.__matches_.clear();
6200 template <class _BidirectionalIterator, class _CharT, class _Traits>
6201 inline _LIBCPP_INLINE_VISIBILITY
6203 regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
6204 const basic_regex<_CharT, _Traits>& __e,
6205 regex_constants::match_flag_type __flags = regex_constants::match_default)
6207 match_results<_BidirectionalIterator> __m;
6208 return _VSTD::regex_match(__first, __last, __m, __e, __flags);
6211 template <class _CharT, class _Allocator, class _Traits>
6212 inline _LIBCPP_INLINE_VISIBILITY
6214 regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
6215 const basic_regex<_CharT, _Traits>& __e,
6216 regex_constants::match_flag_type __flags = regex_constants::match_default)
6218 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
6221 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
6222 inline _LIBCPP_INLINE_VISIBILITY
6224 regex_match(const basic_string<_CharT, _ST, _SA>& __s,
6225 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
6226 const basic_regex<_CharT, _Traits>& __e,
6227 regex_constants::match_flag_type __flags = regex_constants::match_default)
6229 return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
6232 #if _LIBCPP_STD_VER > 11
6233 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
6234 inline _LIBCPP_INLINE_VISIBILITY
6236 regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
6237 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
6238 const basic_regex<_CharT, _Traits>& __e,
6239 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
6242 template <class _CharT, class _Traits>
6243 inline _LIBCPP_INLINE_VISIBILITY
6245 regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
6246 regex_constants::match_flag_type __flags = regex_constants::match_default)
6248 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
6251 template <class _ST, class _SA, class _CharT, class _Traits>
6252 inline _LIBCPP_INLINE_VISIBILITY
6254 regex_match(const basic_string<_CharT, _ST, _SA>& __s,
6255 const basic_regex<_CharT, _Traits>& __e,
6256 regex_constants::match_flag_type __flags = regex_constants::match_default)
6258 return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags);
6263 template <class _BidirectionalIterator,
6264 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6265 class _Traits = regex_traits<_CharT> >
6266 class _LIBCPP_TEMPLATE_VIS regex_iterator;
6268 typedef regex_iterator<const char*> cregex_iterator;
6269 typedef regex_iterator<string::const_iterator> sregex_iterator;
6270 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
6271 typedef regex_iterator<const wchar_t*> wcregex_iterator;
6272 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
6275 template <class _BidirectionalIterator, class _CharT, class _Traits>
6277 _LIBCPP_TEMPLATE_VIS
6278 _LIBCPP_PREFERRED_NAME(cregex_iterator)
6279 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator))
6280 _LIBCPP_PREFERRED_NAME(sregex_iterator)
6281 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator))
6285 typedef basic_regex<_CharT, _Traits> regex_type;
6286 typedef match_results<_BidirectionalIterator> value_type;
6287 typedef ptrdiff_t difference_type;
6288 typedef const value_type* pointer;
6289 typedef const value_type& reference;
6290 typedef forward_iterator_tag iterator_category;
6293 _BidirectionalIterator __begin_;
6294 _BidirectionalIterator __end_;
6295 const regex_type* __pregex_;
6296 regex_constants::match_flag_type __flags_;
6297 value_type __match_;
6301 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6302 const regex_type& __re,
6303 regex_constants::match_flag_type __m
6304 = regex_constants::match_default);
6305 #if _LIBCPP_STD_VER > 11
6306 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6307 const regex_type&& __re,
6308 regex_constants::match_flag_type __m
6309 = regex_constants::match_default) = delete;
6312 bool operator==(const regex_iterator& __x) const;
6313 _LIBCPP_INLINE_VISIBILITY
6314 bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
6316 _LIBCPP_INLINE_VISIBILITY
6317 reference operator*() const {return __match_;}
6318 _LIBCPP_INLINE_VISIBILITY
6319 pointer operator->() const {return _VSTD::addressof(__match_);}
6321 regex_iterator& operator++();
6322 _LIBCPP_INLINE_VISIBILITY
6323 regex_iterator operator++(int)
6325 regex_iterator __t(*this);
6331 template <class _BidirectionalIterator, class _CharT, class _Traits>
6332 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
6333 : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
6337 template <class _BidirectionalIterator, class _CharT, class _Traits>
6338 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6339 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6340 const regex_type& __re, regex_constants::match_flag_type __m)
6343 __pregex_(_VSTD::addressof(__re)),
6346 _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
6349 template <class _BidirectionalIterator, class _CharT, class _Traits>
6351 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6352 operator==(const regex_iterator& __x) const
6354 if (__match_.empty() && __x.__match_.empty())
6356 if (__match_.empty() || __x.__match_.empty())
6358 return __begin_ == __x.__begin_ &&
6359 __end_ == __x.__end_ &&
6360 __pregex_ == __x.__pregex_ &&
6361 __flags_ == __x.__flags_ &&
6362 __match_[0] == __x.__match_[0];
6365 template <class _BidirectionalIterator, class _CharT, class _Traits>
6366 regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
6367 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6369 __flags_ |= regex_constants::__no_update_pos;
6370 _BidirectionalIterator __start = __match_[0].second;
6371 if (__match_[0].first == __match_[0].second)
6373 if (__start == __end_)
6375 __match_ = value_type();
6378 else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_,
6379 __flags_ | regex_constants::match_not_null |
6380 regex_constants::match_continuous))
6385 __flags_ |= regex_constants::match_prev_avail;
6386 if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
6387 __match_ = value_type();
6391 // regex_token_iterator
6393 template <class _BidirectionalIterator,
6394 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6395 class _Traits = regex_traits<_CharT> >
6396 class _LIBCPP_TEMPLATE_VIS regex_token_iterator;
6398 typedef regex_token_iterator<const char*> cregex_token_iterator;
6399 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
6400 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
6401 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
6402 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
6405 template <class _BidirectionalIterator, class _CharT, class _Traits>
6407 _LIBCPP_TEMPLATE_VIS
6408 _LIBCPP_PREFERRED_NAME(cregex_token_iterator)
6409 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator))
6410 _LIBCPP_PREFERRED_NAME(sregex_token_iterator)
6411 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator))
6412 regex_token_iterator
6415 typedef basic_regex<_CharT, _Traits> regex_type;
6416 typedef sub_match<_BidirectionalIterator> value_type;
6417 typedef ptrdiff_t difference_type;
6418 typedef const value_type* pointer;
6419 typedef const value_type& reference;
6420 typedef forward_iterator_tag iterator_category;
6423 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
6425 _Position __position_;
6426 const value_type* __result_;
6427 value_type __suffix_;
6429 vector<int> __subs_;
6432 regex_token_iterator();
6433 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6434 const regex_type& __re, int __submatch = 0,
6435 regex_constants::match_flag_type __m =
6436 regex_constants::match_default);
6437 #if _LIBCPP_STD_VER > 11
6438 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6439 const regex_type&& __re, int __submatch = 0,
6440 regex_constants::match_flag_type __m =
6441 regex_constants::match_default) = delete;
6444 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6445 const regex_type& __re, const vector<int>& __submatches,
6446 regex_constants::match_flag_type __m =
6447 regex_constants::match_default);
6448 #if _LIBCPP_STD_VER > 11
6449 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6450 const regex_type&& __re, const vector<int>& __submatches,
6451 regex_constants::match_flag_type __m =
6452 regex_constants::match_default) = delete;
6455 #ifndef _LIBCPP_CXX03_LANG
6456 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6457 const regex_type& __re,
6458 initializer_list<int> __submatches,
6459 regex_constants::match_flag_type __m =
6460 regex_constants::match_default);
6462 #if _LIBCPP_STD_VER > 11
6463 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6464 const regex_type&& __re,
6465 initializer_list<int> __submatches,
6466 regex_constants::match_flag_type __m =
6467 regex_constants::match_default) = delete;
6469 #endif // _LIBCPP_CXX03_LANG
6470 template <size_t _Np>
6471 regex_token_iterator(_BidirectionalIterator __a,
6472 _BidirectionalIterator __b,
6473 const regex_type& __re,
6474 const int (&__submatches)[_Np],
6475 regex_constants::match_flag_type __m =
6476 regex_constants::match_default);
6477 #if _LIBCPP_STD_VER > 11
6478 template <size_t _Np>
6479 regex_token_iterator(_BidirectionalIterator __a,
6480 _BidirectionalIterator __b,
6481 const regex_type&& __re,
6482 const int (&__submatches)[_Np],
6483 regex_constants::match_flag_type __m =
6484 regex_constants::match_default) = delete;
6487 regex_token_iterator(const regex_token_iterator&);
6488 regex_token_iterator& operator=(const regex_token_iterator&);
6490 bool operator==(const regex_token_iterator& __x) const;
6491 _LIBCPP_INLINE_VISIBILITY
6492 bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
6494 _LIBCPP_INLINE_VISIBILITY
6495 const value_type& operator*() const {return *__result_;}
6496 _LIBCPP_INLINE_VISIBILITY
6497 const value_type* operator->() const {return __result_;}
6499 regex_token_iterator& operator++();
6500 _LIBCPP_INLINE_VISIBILITY
6501 regex_token_iterator operator++(int)
6503 regex_token_iterator __t(*this);
6509 void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
6510 void __establish_result () {
6511 if (__subs_[__n_] == -1)
6512 __result_ = &__position_->prefix();
6514 __result_ = &(*__position_)[__subs_[__n_]];
6518 template <class _BidirectionalIterator, class _CharT, class _Traits>
6519 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6520 regex_token_iterator()
6521 : __result_(nullptr),
6527 template <class _BidirectionalIterator, class _CharT, class _Traits>
6529 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6530 __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
6532 if (__position_ != _Position())
6533 __establish_result ();
6534 else if (__subs_[__n_] == -1)
6536 __suffix_.matched = true;
6537 __suffix_.first = __a;
6538 __suffix_.second = __b;
6539 __result_ = &__suffix_;
6542 __result_ = nullptr;
6545 template <class _BidirectionalIterator, class _CharT, class _Traits>
6546 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6547 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6548 const regex_type& __re, int __submatch,
6549 regex_constants::match_flag_type __m)
6550 : __position_(__a, __b, __re, __m),
6552 __subs_(1, __submatch)
6557 template <class _BidirectionalIterator, class _CharT, class _Traits>
6558 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6559 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6560 const regex_type& __re, const vector<int>& __submatches,
6561 regex_constants::match_flag_type __m)
6562 : __position_(__a, __b, __re, __m),
6564 __subs_(__submatches)
6569 #ifndef _LIBCPP_CXX03_LANG
6571 template <class _BidirectionalIterator, class _CharT, class _Traits>
6572 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6573 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6574 const regex_type& __re,
6575 initializer_list<int> __submatches,
6576 regex_constants::match_flag_type __m)
6577 : __position_(__a, __b, __re, __m),
6579 __subs_(__submatches)
6584 #endif // _LIBCPP_CXX03_LANG
6586 template <class _BidirectionalIterator, class _CharT, class _Traits>
6587 template <size_t _Np>
6588 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6589 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6590 const regex_type& __re,
6591 const int (&__submatches)[_Np],
6592 regex_constants::match_flag_type __m)
6593 : __position_(__a, __b, __re, __m),
6595 __subs_(begin(__submatches), end(__submatches))
6600 template <class _BidirectionalIterator, class _CharT, class _Traits>
6601 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6602 regex_token_iterator(const regex_token_iterator& __x)
6603 : __position_(__x.__position_),
6604 __result_(__x.__result_),
6605 __suffix_(__x.__suffix_),
6607 __subs_(__x.__subs_)
6609 if (__x.__result_ == &__x.__suffix_)
6610 __result_ = &__suffix_;
6611 else if ( __result_ != nullptr )
6612 __establish_result ();
6615 template <class _BidirectionalIterator, class _CharT, class _Traits>
6616 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6617 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6618 operator=(const regex_token_iterator& __x)
6622 __position_ = __x.__position_;
6623 if (__x.__result_ == &__x.__suffix_)
6624 __result_ = &__suffix_;
6626 __result_ = __x.__result_;
6627 __suffix_ = __x.__suffix_;
6629 __subs_ = __x.__subs_;
6631 if ( __result_ != nullptr && __result_ != &__suffix_ )
6632 __establish_result();
6637 template <class _BidirectionalIterator, class _CharT, class _Traits>
6639 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6640 operator==(const regex_token_iterator& __x) const
6642 if (__result_ == nullptr && __x.__result_ == nullptr)
6644 if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
6645 __suffix_ == __x.__suffix_)
6647 if (__result_ == nullptr || __x.__result_ == nullptr)
6649 if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
6651 return __position_ == __x.__position_ && __n_ == __x.__n_ &&
6652 __subs_ == __x.__subs_;
6655 template <class _BidirectionalIterator, class _CharT, class _Traits>
6656 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6657 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6659 _Position __prev = __position_;
6660 if (__result_ == &__suffix_)
6661 __result_ = nullptr;
6662 else if (static_cast<size_t>(__n_ + 1) < __subs_.size())
6665 __establish_result();
6671 if (__position_ != _Position())
6672 __establish_result();
6675 if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
6676 && __prev->suffix().length() != 0)
6678 __suffix_.matched = true;
6679 __suffix_.first = __prev->suffix().first;
6680 __suffix_.second = __prev->suffix().second;
6681 __result_ = &__suffix_;
6684 __result_ = nullptr;
6692 template <class _OutputIterator, class _BidirectionalIterator,
6693 class _Traits, class _CharT>
6695 regex_replace(_OutputIterator __output_iter,
6696 _BidirectionalIterator __first, _BidirectionalIterator __last,
6697 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6698 regex_constants::match_flag_type __flags = regex_constants::match_default)
6700 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
6701 _Iter __i(__first, __last, __e, __flags);
6705 if (!(__flags & regex_constants::format_no_copy))
6706 __output_iter = _VSTD::copy(__first, __last, __output_iter);
6710 sub_match<_BidirectionalIterator> __lm;
6711 for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
6713 if (!(__flags & regex_constants::format_no_copy))
6714 __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter);
6715 __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags);
6716 __lm = __i->suffix();
6717 if (__flags & regex_constants::format_first_only)
6720 if (!(__flags & regex_constants::format_no_copy))
6721 __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter);
6723 return __output_iter;
6726 template <class _OutputIterator, class _BidirectionalIterator,
6727 class _Traits, class _CharT, class _ST, class _SA>
6728 inline _LIBCPP_INLINE_VISIBILITY
6730 regex_replace(_OutputIterator __output_iter,
6731 _BidirectionalIterator __first, _BidirectionalIterator __last,
6732 const basic_regex<_CharT, _Traits>& __e,
6733 const basic_string<_CharT, _ST, _SA>& __fmt,
6734 regex_constants::match_flag_type __flags = regex_constants::match_default)
6736 return _VSTD::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags);
6739 template <class _Traits, class _CharT, class _ST, class _SA, class _FST,
6741 inline _LIBCPP_INLINE_VISIBILITY
6742 basic_string<_CharT, _ST, _SA>
6743 regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6744 const basic_regex<_CharT, _Traits>& __e,
6745 const basic_string<_CharT, _FST, _FSA>& __fmt,
6746 regex_constants::match_flag_type __flags = regex_constants::match_default)
6748 basic_string<_CharT, _ST, _SA> __r;
6749 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6750 __fmt.c_str(), __flags);
6754 template <class _Traits, class _CharT, class _ST, class _SA>
6755 inline _LIBCPP_INLINE_VISIBILITY
6756 basic_string<_CharT, _ST, _SA>
6757 regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6758 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6759 regex_constants::match_flag_type __flags = regex_constants::match_default)
6761 basic_string<_CharT, _ST, _SA> __r;
6762 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6767 template <class _Traits, class _CharT, class _ST, class _SA>
6768 inline _LIBCPP_INLINE_VISIBILITY
6769 basic_string<_CharT>
6770 regex_replace(const _CharT* __s,
6771 const basic_regex<_CharT, _Traits>& __e,
6772 const basic_string<_CharT, _ST, _SA>& __fmt,
6773 regex_constants::match_flag_type __flags = regex_constants::match_default)
6775 basic_string<_CharT> __r;
6776 _VSTD::regex_replace(back_inserter(__r), __s,
6777 __s + char_traits<_CharT>::length(__s), __e,
6778 __fmt.c_str(), __flags);
6782 template <class _Traits, class _CharT>
6783 inline _LIBCPP_INLINE_VISIBILITY
6784 basic_string<_CharT>
6785 regex_replace(const _CharT* __s,
6786 const basic_regex<_CharT, _Traits>& __e,
6787 const _CharT* __fmt,
6788 regex_constants::match_flag_type __flags = regex_constants::match_default)
6790 basic_string<_CharT> __r;
6791 _VSTD::regex_replace(back_inserter(__r), __s,
6792 __s + char_traits<_CharT>::length(__s), __e,
6797 _LIBCPP_END_NAMESPACE_STD
6801 #endif // _LIBCPP_REGEX