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;
765 #include <__algorithm/find.h>
766 #include <__algorithm/search.h>
767 #include <__assert> // all public C++ headers provide the assertion handler
769 #include <__iterator/back_insert_iterator.h>
770 #include <__iterator/wrap_iter.h>
772 #include <__utility/move.h>
773 #include <__utility/swap.h>
781 // standard-mandated includes
784 #include <__iterator/access.h>
785 #include <__iterator/data.h>
786 #include <__iterator/empty.h>
787 #include <__iterator/reverse_access.h>
788 #include <__iterator/size.h>
792 #include <initializer_list>
794 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
795 # pragma GCC system_header
799 #include <__undef_macros>
802 #define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
804 _LIBCPP_BEGIN_NAMESPACE_STD
806 namespace regex_constants
809 // syntax_option_type
811 enum syntax_option_type
817 #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
827 // 1 << 9 may be used by ECMAScript
831 inline _LIBCPP_CONSTEXPR
832 syntax_option_type __get_grammar(syntax_option_type __g)
834 #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
835 return static_cast<syntax_option_type>(__g & 0x3F0);
837 return static_cast<syntax_option_type>(__g & 0x1F0);
841 inline _LIBCPP_INLINE_VISIBILITY
844 operator~(syntax_option_type __x)
846 return syntax_option_type(~int(__x) & 0x1FF);
849 inline _LIBCPP_INLINE_VISIBILITY
852 operator&(syntax_option_type __x, syntax_option_type __y)
854 return syntax_option_type(int(__x) & int(__y));
857 inline _LIBCPP_INLINE_VISIBILITY
860 operator|(syntax_option_type __x, syntax_option_type __y)
862 return syntax_option_type(int(__x) | int(__y));
865 inline _LIBCPP_INLINE_VISIBILITY
868 operator^(syntax_option_type __x, syntax_option_type __y)
870 return syntax_option_type(int(__x) ^ int(__y));
873 inline _LIBCPP_INLINE_VISIBILITY
875 operator&=(syntax_option_type& __x, syntax_option_type __y)
881 inline _LIBCPP_INLINE_VISIBILITY
883 operator|=(syntax_option_type& __x, syntax_option_type __y)
889 inline _LIBCPP_INLINE_VISIBILITY
891 operator^=(syntax_option_type& __x, syntax_option_type __y)
902 match_not_bol = 1 << 0,
903 match_not_eol = 1 << 1,
904 match_not_bow = 1 << 2,
905 match_not_eow = 1 << 3,
907 match_not_null = 1 << 5,
908 match_continuous = 1 << 6,
909 match_prev_avail = 1 << 7,
912 format_no_copy = 1 << 9,
913 format_first_only = 1 << 10,
914 __no_update_pos = 1 << 11,
915 __full_match = 1 << 12
918 inline _LIBCPP_INLINE_VISIBILITY
921 operator~(match_flag_type __x)
923 return match_flag_type(~int(__x) & 0x0FFF);
926 inline _LIBCPP_INLINE_VISIBILITY
929 operator&(match_flag_type __x, match_flag_type __y)
931 return match_flag_type(int(__x) & int(__y));
934 inline _LIBCPP_INLINE_VISIBILITY
937 operator|(match_flag_type __x, match_flag_type __y)
939 return match_flag_type(int(__x) | int(__y));
942 inline _LIBCPP_INLINE_VISIBILITY
945 operator^(match_flag_type __x, match_flag_type __y)
947 return match_flag_type(int(__x) ^ int(__y));
950 inline _LIBCPP_INLINE_VISIBILITY
952 operator&=(match_flag_type& __x, match_flag_type __y)
958 inline _LIBCPP_INLINE_VISIBILITY
960 operator|=(match_flag_type& __x, match_flag_type __y)
966 inline _LIBCPP_INLINE_VISIBILITY
968 operator^=(match_flag_type& __x, match_flag_type __y)
995 } // namespace regex_constants
997 class _LIBCPP_EXCEPTION_ABI regex_error
998 : public runtime_error
1000 regex_constants::error_type __code_;
1002 explicit regex_error(regex_constants::error_type __ecode);
1003 regex_error(const regex_error&) _NOEXCEPT = default;
1004 virtual ~regex_error() _NOEXCEPT;
1005 _LIBCPP_INLINE_VISIBILITY
1006 regex_constants::error_type code() const {return __code_;}
1009 template <regex_constants::error_type _Ev>
1010 _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
1011 void __throw_regex_error()
1013 #ifndef _LIBCPP_NO_EXCEPTIONS
1014 throw regex_error(_Ev);
1020 template <class _CharT>
1021 struct _LIBCPP_TEMPLATE_VIS regex_traits
1024 typedef _CharT char_type;
1025 typedef basic_string<char_type> string_type;
1026 typedef locale locale_type;
1028 // Originally bionic's ctype_base used its own ctype masks because the
1029 // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask
1030 // was only 8 bits wide and already saturated, so it used a wider type here
1031 // to make room for __regex_word (then a part of this class rather than
1032 // ctype_base). Bionic has since moved to the builtin ctype_base
1033 // implementation, but this was not updated to match. Since then Android has
1034 // needed to maintain a stable libc++ ABI, and this can't be changed without
1036 typedef uint16_t char_class_type;
1038 typedef ctype_base::mask char_class_type;
1041 static const char_class_type __regex_word = ctype_base::__regex_word;
1044 const ctype<char_type>* __ct_;
1045 const collate<char_type>* __col_;
1050 _LIBCPP_INLINE_VISIBILITY
1051 static size_t length(const char_type* __p)
1052 {return char_traits<char_type>::length(__p);}
1053 _LIBCPP_INLINE_VISIBILITY
1054 char_type translate(char_type __c) const {return __c;}
1055 char_type translate_nocase(char_type __c) const;
1056 template <class _ForwardIterator>
1058 transform(_ForwardIterator __f, _ForwardIterator __l) const;
1059 template <class _ForwardIterator>
1060 _LIBCPP_INLINE_VISIBILITY
1062 transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
1063 {return __transform_primary(__f, __l, char_type());}
1064 template <class _ForwardIterator>
1065 _LIBCPP_INLINE_VISIBILITY
1067 lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
1068 {return __lookup_collatename(__f, __l, char_type());}
1069 template <class _ForwardIterator>
1070 _LIBCPP_INLINE_VISIBILITY
1072 lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1073 bool __icase = false) const
1074 {return __lookup_classname(__f, __l, __icase, char_type());}
1075 bool isctype(char_type __c, char_class_type __m) const;
1076 _LIBCPP_INLINE_VISIBILITY
1077 int value(char_type __ch, int __radix) const
1078 {return __regex_traits_value(__ch, __radix);}
1079 locale_type imbue(locale_type __l);
1080 _LIBCPP_INLINE_VISIBILITY
1081 locale_type getloc()const {return __loc_;}
1086 template <class _ForwardIterator>
1088 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
1089 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1090 template <class _ForwardIterator>
1092 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1094 template <class _ForwardIterator>
1096 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
1097 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1098 template <class _ForwardIterator>
1100 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1102 template <class _ForwardIterator>
1104 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1105 bool __icase, char) const;
1106 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1107 template <class _ForwardIterator>
1109 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1110 bool __icase, wchar_t) const;
1113 static int __regex_traits_value(unsigned char __ch, int __radix);
1114 _LIBCPP_INLINE_VISIBILITY
1115 int __regex_traits_value(char __ch, int __radix) const
1116 {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
1117 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1118 _LIBCPP_INLINE_VISIBILITY
1119 int __regex_traits_value(wchar_t __ch, int __radix) const;
1123 template <class _CharT>
1124 const typename regex_traits<_CharT>::char_class_type
1125 regex_traits<_CharT>::__regex_word;
1127 template <class _CharT>
1128 regex_traits<_CharT>::regex_traits()
1133 template <class _CharT>
1134 typename regex_traits<_CharT>::char_type
1135 regex_traits<_CharT>::translate_nocase(char_type __c) const
1137 return __ct_->tolower(__c);
1140 template <class _CharT>
1141 template <class _ForwardIterator>
1142 typename regex_traits<_CharT>::string_type
1143 regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
1145 string_type __s(__f, __l);
1146 return __col_->transform(__s.data(), __s.data() + __s.size());
1149 template <class _CharT>
1151 regex_traits<_CharT>::__init()
1153 __ct_ = &use_facet<ctype<char_type> >(__loc_);
1154 __col_ = &use_facet<collate<char_type> >(__loc_);
1157 template <class _CharT>
1158 typename regex_traits<_CharT>::locale_type
1159 regex_traits<_CharT>::imbue(locale_type __l)
1161 locale __r = __loc_;
1167 // transform_primary is very FreeBSD-specific
1169 template <class _CharT>
1170 template <class _ForwardIterator>
1171 typename regex_traits<_CharT>::string_type
1172 regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1173 _ForwardIterator __l, char) const
1175 const string_type __s(__f, __l);
1176 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1191 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1192 template <class _CharT>
1193 template <class _ForwardIterator>
1194 typename regex_traits<_CharT>::string_type
1195 regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1196 _ForwardIterator __l, wchar_t) const
1198 const string_type __s(__f, __l);
1199 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1215 // lookup_collatename is very FreeBSD-specific
1217 _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s);
1219 template <class _CharT>
1220 template <class _ForwardIterator>
1221 typename regex_traits<_CharT>::string_type
1222 regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1223 _ForwardIterator __l, char) const
1225 string_type __s(__f, __l);
1229 __r = __get_collation_name(__s.c_str());
1230 if (__r.empty() && __s.size() <= 2)
1232 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1233 if (__r.size() == 1 || __r.size() == 12)
1242 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1243 template <class _CharT>
1244 template <class _ForwardIterator>
1245 typename regex_traits<_CharT>::string_type
1246 regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1247 _ForwardIterator __l, wchar_t) const
1249 string_type __s(__f, __l);
1251 __n.reserve(__s.size());
1252 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1255 if (static_cast<unsigned>(*__i) >= 127)
1256 return string_type();
1257 __n.push_back(char(*__i));
1262 __n = __get_collation_name(__n.c_str());
1264 __r.assign(__n.begin(), __n.end());
1265 else if (__s.size() <= 2)
1267 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1268 if (__r.size() == 1 || __r.size() == 3)
1276 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1280 regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS
1281 __get_classname(const char* __s, bool __icase);
1283 template <class _CharT>
1284 template <class _ForwardIterator>
1285 typename regex_traits<_CharT>::char_class_type
1286 regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1287 _ForwardIterator __l,
1288 bool __icase, char) const
1290 string_type __s(__f, __l);
1291 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1292 return __get_classname(__s.c_str(), __icase);
1295 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1296 template <class _CharT>
1297 template <class _ForwardIterator>
1298 typename regex_traits<_CharT>::char_class_type
1299 regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1300 _ForwardIterator __l,
1301 bool __icase, wchar_t) const
1303 string_type __s(__f, __l);
1304 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1306 __n.reserve(__s.size());
1307 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1310 if (static_cast<unsigned>(*__i) >= 127)
1311 return char_class_type();
1312 __n.push_back(char(*__i));
1314 return __get_classname(__n.c_str(), __icase);
1316 #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
1318 template <class _CharT>
1320 regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
1322 if (__ct_->is(__m, __c))
1324 return (__c == '_' && (__m & __regex_word));
1327 inline _LIBCPP_INLINE_VISIBILITY
1328 bool __is_07(unsigned char c)
1330 return (c & 0xF8u) ==
1331 #if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1338 inline _LIBCPP_INLINE_VISIBILITY
1339 bool __is_89(unsigned char c)
1341 return (c & 0xFEu) ==
1342 #if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1349 inline _LIBCPP_INLINE_VISIBILITY
1350 unsigned char __to_lower(unsigned char c)
1352 #if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1359 template <class _CharT>
1361 regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
1363 if (__is_07(__ch)) // '0' <= __ch && __ch <= '7'
1367 if (__is_89(__ch)) // '8' <= __ch && __ch <= '9'
1371 __ch = __to_lower(__ch); // tolower
1372 if ('a' <= __ch && __ch <= 'f')
1373 return __ch - ('a' - 10);
1379 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1380 template <class _CharT>
1383 regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
1385 return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
1389 template <class _CharT> class __node;
1391 template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match;
1393 template <class _BidirectionalIterator,
1394 class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1395 class _LIBCPP_TEMPLATE_VIS match_results;
1397 template <class _CharT>
1402 __end_state = -1000,
1403 __consume_input, // -999
1404 __begin_marked_expr, // -998
1405 __end_marked_expr, // -997
1406 __pop_state, // -996
1407 __accept_and_consume, // -995
1408 __accept_but_not_consume, // -994
1415 const _CharT* __first_;
1416 const _CharT* __current_;
1417 const _CharT* __last_;
1418 vector<sub_match<const _CharT*> > __sub_matches_;
1419 vector<pair<size_t, const _CharT*> > __loop_data_;
1420 const __node<_CharT>* __node_;
1421 regex_constants::match_flag_type __flags_;
1424 _LIBCPP_INLINE_VISIBILITY
1426 : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
1427 __node_(nullptr), __flags_() {}
1432 template <class _CharT>
1435 __node(const __node&);
1436 __node& operator=(const __node&);
1438 typedef _VSTD::__state<_CharT> __state;
1440 _LIBCPP_INLINE_VISIBILITY
1442 _LIBCPP_INLINE_VISIBILITY
1443 virtual ~__node() {}
1445 _LIBCPP_INLINE_VISIBILITY
1446 virtual void __exec(__state&) const {}
1447 _LIBCPP_INLINE_VISIBILITY
1448 virtual void __exec_split(bool, __state&) const {}
1453 template <class _CharT>
1455 : public __node<_CharT>
1458 typedef _VSTD::__state<_CharT> __state;
1460 _LIBCPP_INLINE_VISIBILITY
1463 virtual void __exec(__state&) const;
1466 template <class _CharT>
1468 __end_state<_CharT>::__exec(__state& __s) const
1470 __s.__do_ = __state::__end_state;
1475 template <class _CharT>
1476 class __has_one_state
1477 : public __node<_CharT>
1479 __node<_CharT>* __first_;
1482 _LIBCPP_INLINE_VISIBILITY
1483 explicit __has_one_state(__node<_CharT>* __s)
1486 _LIBCPP_INLINE_VISIBILITY
1487 __node<_CharT>* first() const {return __first_;}
1488 _LIBCPP_INLINE_VISIBILITY
1489 __node<_CharT>*& first() {return __first_;}
1494 template <class _CharT>
1495 class __owns_one_state
1496 : public __has_one_state<_CharT>
1498 typedef __has_one_state<_CharT> base;
1501 _LIBCPP_INLINE_VISIBILITY
1502 explicit __owns_one_state(__node<_CharT>* __s)
1505 virtual ~__owns_one_state();
1508 template <class _CharT>
1509 __owns_one_state<_CharT>::~__owns_one_state()
1511 delete this->first();
1516 template <class _CharT>
1518 : public __owns_one_state<_CharT>
1520 typedef __owns_one_state<_CharT> base;
1523 typedef _VSTD::__state<_CharT> __state;
1525 _LIBCPP_INLINE_VISIBILITY
1526 explicit __empty_state(__node<_CharT>* __s)
1529 virtual void __exec(__state&) const;
1532 template <class _CharT>
1534 __empty_state<_CharT>::__exec(__state& __s) const
1536 __s.__do_ = __state::__accept_but_not_consume;
1537 __s.__node_ = this->first();
1540 // __empty_non_own_state
1542 template <class _CharT>
1543 class __empty_non_own_state
1544 : public __has_one_state<_CharT>
1546 typedef __has_one_state<_CharT> base;
1549 typedef _VSTD::__state<_CharT> __state;
1551 _LIBCPP_INLINE_VISIBILITY
1552 explicit __empty_non_own_state(__node<_CharT>* __s)
1555 virtual void __exec(__state&) const;
1558 template <class _CharT>
1560 __empty_non_own_state<_CharT>::__exec(__state& __s) const
1562 __s.__do_ = __state::__accept_but_not_consume;
1563 __s.__node_ = this->first();
1566 // __repeat_one_loop
1568 template <class _CharT>
1569 class __repeat_one_loop
1570 : public __has_one_state<_CharT>
1572 typedef __has_one_state<_CharT> base;
1575 typedef _VSTD::__state<_CharT> __state;
1577 _LIBCPP_INLINE_VISIBILITY
1578 explicit __repeat_one_loop(__node<_CharT>* __s)
1581 virtual void __exec(__state&) const;
1584 template <class _CharT>
1586 __repeat_one_loop<_CharT>::__exec(__state& __s) const
1588 __s.__do_ = __state::__repeat;
1589 __s.__node_ = this->first();
1592 // __owns_two_states
1594 template <class _CharT>
1595 class __owns_two_states
1596 : public __owns_one_state<_CharT>
1598 typedef __owns_one_state<_CharT> base;
1603 _LIBCPP_INLINE_VISIBILITY
1604 explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
1605 : base(__s1), __second_(__s2) {}
1607 virtual ~__owns_two_states();
1609 _LIBCPP_INLINE_VISIBILITY
1610 base* second() const {return __second_;}
1611 _LIBCPP_INLINE_VISIBILITY
1612 base*& second() {return __second_;}
1615 template <class _CharT>
1616 __owns_two_states<_CharT>::~__owns_two_states()
1623 template <class _CharT>
1625 : public __owns_two_states<_CharT>
1627 typedef __owns_two_states<_CharT> base;
1631 unsigned __loop_id_;
1632 unsigned __mexp_begin_;
1633 unsigned __mexp_end_;
1637 typedef _VSTD::__state<_CharT> __state;
1639 _LIBCPP_INLINE_VISIBILITY
1640 explicit __loop(unsigned __loop_id,
1641 __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
1642 unsigned __mexp_begin, unsigned __mexp_end,
1643 bool __greedy = true,
1645 size_t __max = numeric_limits<size_t>::max())
1646 : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
1647 __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
1648 __greedy_(__greedy) {}
1650 virtual void __exec(__state& __s) const;
1651 virtual void __exec_split(bool __second, __state& __s) const;
1654 _LIBCPP_INLINE_VISIBILITY
1655 void __init_repeat(__state& __s) const
1657 __s.__loop_data_[__loop_id_].second = __s.__current_;
1658 for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
1660 __s.__sub_matches_[__i].first = __s.__last_;
1661 __s.__sub_matches_[__i].second = __s.__last_;
1662 __s.__sub_matches_[__i].matched = false;
1667 template <class _CharT>
1669 __loop<_CharT>::__exec(__state& __s) const
1671 if (__s.__do_ == __state::__repeat)
1673 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1674 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1675 if (__do_repeat && __do_alt &&
1676 __s.__loop_data_[__loop_id_].second == __s.__current_)
1677 __do_repeat = false;
1678 if (__do_repeat && __do_alt)
1679 __s.__do_ = __state::__split;
1680 else if (__do_repeat)
1682 __s.__do_ = __state::__accept_but_not_consume;
1683 __s.__node_ = this->first();
1688 __s.__do_ = __state::__accept_but_not_consume;
1689 __s.__node_ = this->second();
1694 __s.__loop_data_[__loop_id_].first = 0;
1695 bool __do_repeat = 0 < __max_;
1696 bool __do_alt = 0 >= __min_;
1697 if (__do_repeat && __do_alt)
1698 __s.__do_ = __state::__split;
1699 else if (__do_repeat)
1701 __s.__do_ = __state::__accept_but_not_consume;
1702 __s.__node_ = this->first();
1707 __s.__do_ = __state::__accept_but_not_consume;
1708 __s.__node_ = this->second();
1713 template <class _CharT>
1715 __loop<_CharT>::__exec_split(bool __second, __state& __s) const
1717 __s.__do_ = __state::__accept_but_not_consume;
1718 if (__greedy_ != __second)
1720 __s.__node_ = this->first();
1724 __s.__node_ = this->second();
1729 template <class _CharT>
1731 : public __owns_two_states<_CharT>
1733 typedef __owns_two_states<_CharT> base;
1736 typedef _VSTD::__state<_CharT> __state;
1738 _LIBCPP_INLINE_VISIBILITY
1739 explicit __alternate(__owns_one_state<_CharT>* __s1,
1740 __owns_one_state<_CharT>* __s2)
1741 : base(__s1, __s2) {}
1743 virtual void __exec(__state& __s) const;
1744 virtual void __exec_split(bool __second, __state& __s) const;
1747 template <class _CharT>
1749 __alternate<_CharT>::__exec(__state& __s) const
1751 __s.__do_ = __state::__split;
1754 template <class _CharT>
1756 __alternate<_CharT>::__exec_split(bool __second, __state& __s) const
1758 __s.__do_ = __state::__accept_but_not_consume;
1760 __s.__node_ = this->second();
1762 __s.__node_ = this->first();
1765 // __begin_marked_subexpression
1767 template <class _CharT>
1768 class __begin_marked_subexpression
1769 : public __owns_one_state<_CharT>
1771 typedef __owns_one_state<_CharT> base;
1775 typedef _VSTD::__state<_CharT> __state;
1777 _LIBCPP_INLINE_VISIBILITY
1778 explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1779 : base(__s), __mexp_(__mexp) {}
1781 virtual void __exec(__state&) const;
1784 template <class _CharT>
1786 __begin_marked_subexpression<_CharT>::__exec(__state& __s) const
1788 __s.__do_ = __state::__accept_but_not_consume;
1789 __s.__sub_matches_[__mexp_-1].first = __s.__current_;
1790 __s.__node_ = this->first();
1793 // __end_marked_subexpression
1795 template <class _CharT>
1796 class __end_marked_subexpression
1797 : public __owns_one_state<_CharT>
1799 typedef __owns_one_state<_CharT> base;
1803 typedef _VSTD::__state<_CharT> __state;
1805 _LIBCPP_INLINE_VISIBILITY
1806 explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1807 : base(__s), __mexp_(__mexp) {}
1809 virtual void __exec(__state&) const;
1812 template <class _CharT>
1814 __end_marked_subexpression<_CharT>::__exec(__state& __s) const
1816 __s.__do_ = __state::__accept_but_not_consume;
1817 __s.__sub_matches_[__mexp_-1].second = __s.__current_;
1818 __s.__sub_matches_[__mexp_-1].matched = true;
1819 __s.__node_ = this->first();
1824 template <class _CharT>
1826 : public __owns_one_state<_CharT>
1828 typedef __owns_one_state<_CharT> base;
1832 typedef _VSTD::__state<_CharT> __state;
1834 _LIBCPP_INLINE_VISIBILITY
1835 explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
1836 : base(__s), __mexp_(__mexp) {}
1838 virtual void __exec(__state&) const;
1841 template <class _CharT>
1843 __back_ref<_CharT>::__exec(__state& __s) const
1845 if (__mexp_ > __s.__sub_matches_.size())
1846 __throw_regex_error<regex_constants::error_backref>();
1847 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1850 ptrdiff_t __len = __sm.second - __sm.first;
1851 if (__s.__last_ - __s.__current_ >= __len &&
1852 _VSTD::equal(__sm.first, __sm.second, __s.__current_))
1854 __s.__do_ = __state::__accept_but_not_consume;
1855 __s.__current_ += __len;
1856 __s.__node_ = this->first();
1860 __s.__do_ = __state::__reject;
1861 __s.__node_ = nullptr;
1866 __s.__do_ = __state::__reject;
1867 __s.__node_ = nullptr;
1873 template <class _CharT, class _Traits>
1874 class __back_ref_icase
1875 : public __owns_one_state<_CharT>
1877 typedef __owns_one_state<_CharT> base;
1882 typedef _VSTD::__state<_CharT> __state;
1884 _LIBCPP_INLINE_VISIBILITY
1885 explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
1886 __node<_CharT>* __s)
1887 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1889 virtual void __exec(__state&) const;
1892 template <class _CharT, class _Traits>
1894 __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
1896 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1899 ptrdiff_t __len = __sm.second - __sm.first;
1900 if (__s.__last_ - __s.__current_ >= __len)
1902 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1904 if (__traits_.translate_nocase(__sm.first[__i]) !=
1905 __traits_.translate_nocase(__s.__current_[__i]))
1908 __s.__do_ = __state::__accept_but_not_consume;
1909 __s.__current_ += __len;
1910 __s.__node_ = this->first();
1914 __s.__do_ = __state::__reject;
1915 __s.__node_ = nullptr;
1921 __s.__do_ = __state::__reject;
1922 __s.__node_ = nullptr;
1926 // __back_ref_collate
1928 template <class _CharT, class _Traits>
1929 class __back_ref_collate
1930 : public __owns_one_state<_CharT>
1932 typedef __owns_one_state<_CharT> base;
1937 typedef _VSTD::__state<_CharT> __state;
1939 _LIBCPP_INLINE_VISIBILITY
1940 explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
1941 __node<_CharT>* __s)
1942 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1944 virtual void __exec(__state&) const;
1947 template <class _CharT, class _Traits>
1949 __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
1951 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1954 ptrdiff_t __len = __sm.second - __sm.first;
1955 if (__s.__last_ - __s.__current_ >= __len)
1957 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1959 if (__traits_.translate(__sm.first[__i]) !=
1960 __traits_.translate(__s.__current_[__i]))
1963 __s.__do_ = __state::__accept_but_not_consume;
1964 __s.__current_ += __len;
1965 __s.__node_ = this->first();
1969 __s.__do_ = __state::__reject;
1970 __s.__node_ = nullptr;
1976 __s.__do_ = __state::__reject;
1977 __s.__node_ = nullptr;
1983 template <class _CharT, class _Traits>
1984 class __word_boundary
1985 : public __owns_one_state<_CharT>
1987 typedef __owns_one_state<_CharT> base;
1992 typedef _VSTD::__state<_CharT> __state;
1994 _LIBCPP_INLINE_VISIBILITY
1995 explicit __word_boundary(const _Traits& __traits, bool __invert,
1996 __node<_CharT>* __s)
1997 : base(__s), __traits_(__traits), __invert_(__invert) {}
1999 virtual void __exec(__state&) const;
2002 template <class _CharT, class _Traits>
2004 __word_boundary<_CharT, _Traits>::__exec(__state& __s) const
2006 bool __is_word_b = false;
2007 if (__s.__first_ != __s.__last_)
2009 if (__s.__current_ == __s.__last_)
2011 if (!(__s.__flags_ & regex_constants::match_not_eow))
2013 _CharT __c = __s.__current_[-1];
2014 __is_word_b = __c == '_' ||
2015 __traits_.isctype(__c, ctype_base::alnum);
2018 else if (__s.__current_ == __s.__first_ &&
2019 !(__s.__flags_ & regex_constants::match_prev_avail))
2021 if (!(__s.__flags_ & regex_constants::match_not_bow))
2023 _CharT __c = *__s.__current_;
2024 __is_word_b = __c == '_' ||
2025 __traits_.isctype(__c, ctype_base::alnum);
2030 _CharT __c1 = __s.__current_[-1];
2031 _CharT __c2 = *__s.__current_;
2032 bool __is_c1_b = __c1 == '_' ||
2033 __traits_.isctype(__c1, ctype_base::alnum);
2034 bool __is_c2_b = __c2 == '_' ||
2035 __traits_.isctype(__c2, ctype_base::alnum);
2036 __is_word_b = __is_c1_b != __is_c2_b;
2039 if (__is_word_b != __invert_)
2041 __s.__do_ = __state::__accept_but_not_consume;
2042 __s.__node_ = this->first();
2046 __s.__do_ = __state::__reject;
2047 __s.__node_ = nullptr;
2053 template <class _CharT>
2054 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
2055 bool __is_eol(_CharT c)
2057 return c == '\r' || c == '\n';
2060 template <class _CharT>
2061 class __l_anchor_multiline
2062 : public __owns_one_state<_CharT>
2064 typedef __owns_one_state<_CharT> base;
2069 typedef _VSTD::__state<_CharT> __state;
2071 _LIBCPP_INLINE_VISIBILITY
2072 __l_anchor_multiline(bool __multiline, __node<_CharT>* __s)
2073 : base(__s), __multiline_(__multiline) {}
2075 virtual void __exec(__state&) const;
2078 template <class _CharT>
2080 __l_anchor_multiline<_CharT>::__exec(__state& __s) const
2082 if (__s.__at_first_ && __s.__current_ == __s.__first_ &&
2083 !(__s.__flags_ & regex_constants::match_not_bol))
2085 __s.__do_ = __state::__accept_but_not_consume;
2086 __s.__node_ = this->first();
2088 else if (__multiline_ &&
2090 __is_eol(*_VSTD::prev(__s.__current_)))
2092 __s.__do_ = __state::__accept_but_not_consume;
2093 __s.__node_ = this->first();
2097 __s.__do_ = __state::__reject;
2098 __s.__node_ = nullptr;
2104 template <class _CharT>
2105 class __r_anchor_multiline
2106 : public __owns_one_state<_CharT>
2108 typedef __owns_one_state<_CharT> base;
2113 typedef _VSTD::__state<_CharT> __state;
2115 _LIBCPP_INLINE_VISIBILITY
2116 __r_anchor_multiline(bool __multiline, __node<_CharT>* __s)
2117 : base(__s), __multiline_(__multiline) {}
2119 virtual void __exec(__state&) const;
2122 template <class _CharT>
2124 __r_anchor_multiline<_CharT>::__exec(__state& __s) const
2126 if (__s.__current_ == __s.__last_ &&
2127 !(__s.__flags_ & regex_constants::match_not_eol))
2129 __s.__do_ = __state::__accept_but_not_consume;
2130 __s.__node_ = this->first();
2132 else if (__multiline_ && __is_eol(*__s.__current_))
2134 __s.__do_ = __state::__accept_but_not_consume;
2135 __s.__node_ = this->first();
2139 __s.__do_ = __state::__reject;
2140 __s.__node_ = nullptr;
2146 template <class _CharT>
2148 : public __owns_one_state<_CharT>
2150 typedef __owns_one_state<_CharT> base;
2153 typedef _VSTD::__state<_CharT> __state;
2155 _LIBCPP_INLINE_VISIBILITY
2156 __match_any(__node<_CharT>* __s)
2159 virtual void __exec(__state&) const;
2162 template <class _CharT>
2164 __match_any<_CharT>::__exec(__state& __s) const
2166 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
2168 __s.__do_ = __state::__accept_and_consume;
2170 __s.__node_ = this->first();
2174 __s.__do_ = __state::__reject;
2175 __s.__node_ = nullptr;
2179 // __match_any_but_newline
2181 template <class _CharT>
2182 class __match_any_but_newline
2183 : public __owns_one_state<_CharT>
2185 typedef __owns_one_state<_CharT> base;
2188 typedef _VSTD::__state<_CharT> __state;
2190 _LIBCPP_INLINE_VISIBILITY
2191 __match_any_but_newline(__node<_CharT>* __s)
2194 virtual void __exec(__state&) const;
2197 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
2198 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2199 template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
2204 template <class _CharT>
2206 : public __owns_one_state<_CharT>
2208 typedef __owns_one_state<_CharT> base;
2212 __match_char(const __match_char&);
2213 __match_char& operator=(const __match_char&);
2215 typedef _VSTD::__state<_CharT> __state;
2217 _LIBCPP_INLINE_VISIBILITY
2218 __match_char(_CharT __c, __node<_CharT>* __s)
2219 : base(__s), __c_(__c) {}
2221 virtual void __exec(__state&) const;
2224 template <class _CharT>
2226 __match_char<_CharT>::__exec(__state& __s) const
2228 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
2230 __s.__do_ = __state::__accept_and_consume;
2232 __s.__node_ = this->first();
2236 __s.__do_ = __state::__reject;
2237 __s.__node_ = nullptr;
2241 // __match_char_icase
2243 template <class _CharT, class _Traits>
2244 class __match_char_icase
2245 : public __owns_one_state<_CharT>
2247 typedef __owns_one_state<_CharT> base;
2252 __match_char_icase(const __match_char_icase&);
2253 __match_char_icase& operator=(const __match_char_icase&);
2255 typedef _VSTD::__state<_CharT> __state;
2257 _LIBCPP_INLINE_VISIBILITY
2258 __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2259 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
2261 virtual void __exec(__state&) const;
2264 template <class _CharT, class _Traits>
2266 __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
2268 if (__s.__current_ != __s.__last_ &&
2269 __traits_.translate_nocase(*__s.__current_) == __c_)
2271 __s.__do_ = __state::__accept_and_consume;
2273 __s.__node_ = this->first();
2277 __s.__do_ = __state::__reject;
2278 __s.__node_ = nullptr;
2282 // __match_char_collate
2284 template <class _CharT, class _Traits>
2285 class __match_char_collate
2286 : public __owns_one_state<_CharT>
2288 typedef __owns_one_state<_CharT> base;
2293 __match_char_collate(const __match_char_collate&);
2294 __match_char_collate& operator=(const __match_char_collate&);
2296 typedef _VSTD::__state<_CharT> __state;
2298 _LIBCPP_INLINE_VISIBILITY
2299 __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2300 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2302 virtual void __exec(__state&) const;
2305 template <class _CharT, class _Traits>
2307 __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
2309 if (__s.__current_ != __s.__last_ &&
2310 __traits_.translate(*__s.__current_) == __c_)
2312 __s.__do_ = __state::__accept_and_consume;
2314 __s.__node_ = this->first();
2318 __s.__do_ = __state::__reject;
2319 __s.__node_ = nullptr;
2323 // __bracket_expression
2325 template <class _CharT, class _Traits>
2326 class __bracket_expression
2327 : public __owns_one_state<_CharT>
2329 typedef __owns_one_state<_CharT> base;
2330 typedef typename _Traits::string_type string_type;
2333 vector<_CharT> __chars_;
2334 vector<_CharT> __neg_chars_;
2335 vector<pair<string_type, string_type> > __ranges_;
2336 vector<pair<_CharT, _CharT> > __digraphs_;
2337 vector<string_type> __equivalences_;
2338 typename regex_traits<_CharT>::char_class_type __mask_;
2339 typename regex_traits<_CharT>::char_class_type __neg_mask_;
2343 bool __might_have_digraph_;
2345 __bracket_expression(const __bracket_expression&);
2346 __bracket_expression& operator=(const __bracket_expression&);
2348 typedef _VSTD::__state<_CharT> __state;
2350 _LIBCPP_INLINE_VISIBILITY
2351 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
2352 bool __negate, bool __icase, bool __collate)
2353 : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
2354 __negate_(__negate), __icase_(__icase), __collate_(__collate),
2355 __might_have_digraph_(__traits_.getloc().name() != "C") {}
2357 virtual void __exec(__state&) const;
2359 _LIBCPP_INLINE_VISIBILITY
2360 bool __negated() const {return __negate_;}
2362 _LIBCPP_INLINE_VISIBILITY
2363 void __add_char(_CharT __c)
2366 __chars_.push_back(__traits_.translate_nocase(__c));
2367 else if (__collate_)
2368 __chars_.push_back(__traits_.translate(__c));
2370 __chars_.push_back(__c);
2372 _LIBCPP_INLINE_VISIBILITY
2373 void __add_neg_char(_CharT __c)
2376 __neg_chars_.push_back(__traits_.translate_nocase(__c));
2377 else if (__collate_)
2378 __neg_chars_.push_back(__traits_.translate(__c));
2380 __neg_chars_.push_back(__c);
2382 _LIBCPP_INLINE_VISIBILITY
2383 void __add_range(string_type __b, string_type __e)
2389 for (size_t __i = 0; __i < __b.size(); ++__i)
2390 __b[__i] = __traits_.translate_nocase(__b[__i]);
2391 for (size_t __i = 0; __i < __e.size(); ++__i)
2392 __e[__i] = __traits_.translate_nocase(__e[__i]);
2396 for (size_t __i = 0; __i < __b.size(); ++__i)
2397 __b[__i] = __traits_.translate(__b[__i]);
2398 for (size_t __i = 0; __i < __e.size(); ++__i)
2399 __e[__i] = __traits_.translate(__e[__i]);
2401 __ranges_.push_back(make_pair(
2402 __traits_.transform(__b.begin(), __b.end()),
2403 __traits_.transform(__e.begin(), __e.end())));
2407 if (__b.size() != 1 || __e.size() != 1)
2408 __throw_regex_error<regex_constants::error_range>();
2411 __b[0] = __traits_.translate_nocase(__b[0]);
2412 __e[0] = __traits_.translate_nocase(__e[0]);
2414 __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e)));
2417 _LIBCPP_INLINE_VISIBILITY
2418 void __add_digraph(_CharT __c1, _CharT __c2)
2421 __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
2422 __traits_.translate_nocase(__c2)));
2423 else if (__collate_)
2424 __digraphs_.push_back(make_pair(__traits_.translate(__c1),
2425 __traits_.translate(__c2)));
2427 __digraphs_.push_back(make_pair(__c1, __c2));
2429 _LIBCPP_INLINE_VISIBILITY
2430 void __add_equivalence(const string_type& __s)
2431 {__equivalences_.push_back(__s);}
2432 _LIBCPP_INLINE_VISIBILITY
2433 void __add_class(typename regex_traits<_CharT>::char_class_type __mask)
2434 {__mask_ |= __mask;}
2435 _LIBCPP_INLINE_VISIBILITY
2436 void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask)
2437 {__neg_mask_ |= __mask;}
2440 template <class _CharT, class _Traits>
2442 __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
2444 bool __found = false;
2445 unsigned __consumed = 0;
2446 if (__s.__current_ != __s.__last_)
2449 if (__might_have_digraph_)
2451 const _CharT* __next = _VSTD::next(__s.__current_);
2452 if (__next != __s.__last_)
2454 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2457 __ch2.first = __traits_.translate_nocase(__ch2.first);
2458 __ch2.second = __traits_.translate_nocase(__ch2.second);
2460 else if (__collate_)
2462 __ch2.first = __traits_.translate(__ch2.first);
2463 __ch2.second = __traits_.translate(__ch2.second);
2465 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
2467 // __ch2 is a digraph in this locale
2469 for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
2471 if (__ch2 == __digraphs_[__i])
2477 if (__collate_ && !__ranges_.empty())
2479 string_type __s2 = __traits_.transform(&__ch2.first,
2481 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2483 if (__ranges_[__i].first <= __s2 &&
2484 __s2 <= __ranges_[__i].second)
2491 if (!__equivalences_.empty())
2493 string_type __s2 = __traits_.transform_primary(&__ch2.first,
2495 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2497 if (__s2 == __equivalences_[__i])
2504 if (__traits_.isctype(__ch2.first, __mask_) &&
2505 __traits_.isctype(__ch2.second, __mask_))
2510 if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
2511 !__traits_.isctype(__ch2.second, __neg_mask_))
2520 // test *__s.__current_ as not a digraph
2521 _CharT __ch = *__s.__current_;
2523 __ch = __traits_.translate_nocase(__ch);
2524 else if (__collate_)
2525 __ch = __traits_.translate(__ch);
2526 for (size_t __i = 0; __i < __chars_.size(); ++__i)
2528 if (__ch == __chars_[__i])
2534 // When there's at least one of __neg_chars_ and __neg_mask_, the set
2535 // of "__found" chars is
2536 // union(complement(union(__neg_chars_, __neg_mask_)),
2539 // It doesn't make sense to check this when there are no __neg_chars_
2540 // and no __neg_mask_.
2541 if (!(__neg_mask_ == 0 && __neg_chars_.empty()))
2543 const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_);
2544 const bool __in_neg_chars =
2545 _VSTD::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) !=
2547 if (!(__in_neg_mask || __in_neg_chars))
2553 if (!__ranges_.empty())
2555 string_type __s2 = __collate_ ?
2556 __traits_.transform(&__ch, &__ch + 1) :
2557 string_type(1, __ch);
2558 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2560 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
2567 if (!__equivalences_.empty())
2569 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2570 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2572 if (__s2 == __equivalences_[__i])
2579 if (__traits_.isctype(__ch, __mask_))
2586 __found = __negate_; // force reject
2588 if (__found != __negate_)
2590 __s.__do_ = __state::__accept_and_consume;
2591 __s.__current_ += __consumed;
2592 __s.__node_ = this->first();
2596 __s.__do_ = __state::__reject;
2597 __s.__node_ = nullptr;
2601 template <class _CharT, class _Traits> class __lookahead;
2603 template <class _CharT, class _Traits = regex_traits<_CharT> >
2604 class _LIBCPP_TEMPLATE_VIS basic_regex;
2606 typedef basic_regex<char> regex;
2607 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2608 typedef basic_regex<wchar_t> wregex;
2611 template <class _CharT, class _Traits>
2613 _LIBCPP_TEMPLATE_VIS
2614 _LIBCPP_PREFERRED_NAME(regex)
2615 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex))
2620 typedef _CharT value_type;
2621 typedef _Traits traits_type;
2622 typedef typename _Traits::string_type string_type;
2623 typedef regex_constants::syntax_option_type flag_type;
2624 typedef typename _Traits::locale_type locale_type;
2629 unsigned __marked_count_;
2630 unsigned __loop_count_;
2632 shared_ptr<__empty_state<_CharT> > __start_;
2633 __owns_one_state<_CharT>* __end_;
2635 typedef _VSTD::__state<_CharT> __state;
2636 typedef _VSTD::__node<_CharT> __node;
2640 static const regex_constants::syntax_option_type icase = regex_constants::icase;
2641 static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2642 static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
2643 static const regex_constants::syntax_option_type collate = regex_constants::collate;
2644 static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2645 static const regex_constants::syntax_option_type basic = regex_constants::basic;
2646 static const regex_constants::syntax_option_type extended = regex_constants::extended;
2647 static const regex_constants::syntax_option_type awk = regex_constants::awk;
2648 static const regex_constants::syntax_option_type grep = regex_constants::grep;
2649 static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
2650 static const regex_constants::syntax_option_type multiline = regex_constants::multiline;
2652 // construct/copy/destroy:
2653 _LIBCPP_INLINE_VISIBILITY
2655 : __flags_(regex_constants::ECMAScript), __marked_count_(0), __loop_count_(0), __open_count_(0),
2658 _LIBCPP_INLINE_VISIBILITY
2659 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2660 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2663 __init(__p, __p + __traits_.length(__p));
2666 _LIBCPP_INLINE_VISIBILITY
2667 basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
2668 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2671 __init(__p, __p + __len);
2674 // basic_regex(const basic_regex&) = default;
2675 // basic_regex(basic_regex&&) = default;
2676 template <class _ST, class _SA>
2677 _LIBCPP_INLINE_VISIBILITY
2678 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2679 flag_type __f = regex_constants::ECMAScript)
2680 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2683 __init(__p.begin(), __p.end());
2686 template <class _ForwardIterator>
2687 _LIBCPP_INLINE_VISIBILITY
2688 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
2689 flag_type __f = regex_constants::ECMAScript)
2690 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2693 __init(__first, __last);
2695 #ifndef _LIBCPP_CXX03_LANG
2696 _LIBCPP_INLINE_VISIBILITY
2697 basic_regex(initializer_list<value_type> __il,
2698 flag_type __f = regex_constants::ECMAScript)
2699 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
2702 __init(__il.begin(), __il.end());
2704 #endif // _LIBCPP_CXX03_LANG
2706 // ~basic_regex() = default;
2708 // basic_regex& operator=(const basic_regex&) = default;
2709 // basic_regex& operator=(basic_regex&&) = default;
2710 _LIBCPP_INLINE_VISIBILITY
2711 basic_regex& operator=(const value_type* __p)
2712 {return assign(__p);}
2713 #ifndef _LIBCPP_CXX03_LANG
2714 _LIBCPP_INLINE_VISIBILITY
2715 basic_regex& operator=(initializer_list<value_type> __il)
2716 {return assign(__il);}
2717 #endif // _LIBCPP_CXX03_LANG
2718 template <class _ST, class _SA>
2719 _LIBCPP_INLINE_VISIBILITY
2720 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
2721 {return assign(__p);}
2724 _LIBCPP_INLINE_VISIBILITY
2725 basic_regex& assign(const basic_regex& __that)
2726 {return *this = __that;}
2727 #ifndef _LIBCPP_CXX03_LANG
2728 _LIBCPP_INLINE_VISIBILITY
2729 basic_regex& assign(basic_regex&& __that) _NOEXCEPT
2730 {return *this = _VSTD::move(__that);}
2732 _LIBCPP_INLINE_VISIBILITY
2733 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2734 {return assign(__p, __p + __traits_.length(__p), __f);}
2735 _LIBCPP_INLINE_VISIBILITY
2736 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
2737 {return assign(__p, __p + __len, __f);}
2738 template <class _ST, class _SA>
2739 _LIBCPP_INLINE_VISIBILITY
2740 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
2741 flag_type __f = regex_constants::ECMAScript)
2742 {return assign(__s.begin(), __s.end(), __f);}
2744 template <class _InputIterator>
2745 _LIBCPP_INLINE_VISIBILITY
2748 __is_cpp17_input_iterator <_InputIterator>::value &&
2749 !__is_cpp17_forward_iterator<_InputIterator>::value,
2752 assign(_InputIterator __first, _InputIterator __last,
2753 flag_type __f = regex_constants::ECMAScript)
2755 basic_string<_CharT> __t(__first, __last);
2756 return assign(__t.begin(), __t.end(), __f);
2760 _LIBCPP_INLINE_VISIBILITY
2761 void __member_init(flag_type __f)
2764 __marked_count_ = 0;
2771 template <class _ForwardIterator>
2772 _LIBCPP_INLINE_VISIBILITY
2775 __is_cpp17_forward_iterator<_ForwardIterator>::value,
2778 assign(_ForwardIterator __first, _ForwardIterator __last,
2779 flag_type __f = regex_constants::ECMAScript)
2781 return assign(basic_regex(__first, __last, __f));
2784 #ifndef _LIBCPP_CXX03_LANG
2786 _LIBCPP_INLINE_VISIBILITY
2787 basic_regex& assign(initializer_list<value_type> __il,
2788 flag_type __f = regex_constants::ECMAScript)
2789 {return assign(__il.begin(), __il.end(), __f);}
2791 #endif // _LIBCPP_CXX03_LANG
2793 // const operations:
2794 _LIBCPP_INLINE_VISIBILITY
2795 unsigned mark_count() const {return __marked_count_;}
2796 _LIBCPP_INLINE_VISIBILITY
2797 flag_type flags() const {return __flags_;}
2800 _LIBCPP_INLINE_VISIBILITY
2801 locale_type imbue(locale_type __loc)
2803 __member_init(ECMAScript);
2805 return __traits_.imbue(__loc);
2807 _LIBCPP_INLINE_VISIBILITY
2808 locale_type getloc() const {return __traits_.getloc();}
2811 void swap(basic_regex& __r);
2814 _LIBCPP_INLINE_VISIBILITY
2815 unsigned __loop_count() const {return __loop_count_;}
2817 _LIBCPP_INLINE_VISIBILITY
2818 bool __use_multiline() const
2820 return __get_grammar(__flags_) == ECMAScript && (__flags_ & multiline);
2823 template <class _ForwardIterator>
2825 __init(_ForwardIterator __first, _ForwardIterator __last);
2826 template <class _ForwardIterator>
2828 __parse(_ForwardIterator __first, _ForwardIterator __last);
2829 template <class _ForwardIterator>
2831 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2832 template <class _ForwardIterator>
2834 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2835 template <class _ForwardIterator>
2837 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2838 template <class _ForwardIterator>
2840 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2841 template <class _ForwardIterator>
2843 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2844 template <class _ForwardIterator>
2846 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2847 template <class _ForwardIterator>
2849 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2850 template <class _ForwardIterator>
2852 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2853 template <class _ForwardIterator>
2855 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2856 template <class _ForwardIterator>
2858 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2859 template <class _ForwardIterator>
2861 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2862 template <class _ForwardIterator>
2864 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2865 template <class _ForwardIterator>
2867 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2868 __owns_one_state<_CharT>* __s,
2869 unsigned __mexp_begin, unsigned __mexp_end);
2870 template <class _ForwardIterator>
2872 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2873 __owns_one_state<_CharT>* __s,
2874 unsigned __mexp_begin, unsigned __mexp_end);
2875 template <class _ForwardIterator>
2877 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2878 template <class _ForwardIterator>
2880 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
2881 __bracket_expression<_CharT, _Traits>* __ml);
2882 template <class _ForwardIterator>
2884 __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
2885 __bracket_expression<_CharT, _Traits>* __ml);
2886 template <class _ForwardIterator>
2888 __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
2889 __bracket_expression<_CharT, _Traits>* __ml);
2890 template <class _ForwardIterator>
2892 __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
2893 __bracket_expression<_CharT, _Traits>* __ml);
2894 template <class _ForwardIterator>
2896 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
2897 basic_string<_CharT>& __col_sym);
2898 template <class _ForwardIterator>
2900 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
2901 template <class _ForwardIterator>
2903 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2904 template <class _ForwardIterator>
2906 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2907 template <class _ForwardIterator>
2909 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2910 template <class _ForwardIterator>
2912 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2913 template <class _ForwardIterator>
2915 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2916 template <class _ForwardIterator>
2918 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2919 template <class _ForwardIterator>
2921 __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2922 template <class _ForwardIterator>
2924 __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2925 template <class _ForwardIterator>
2927 __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2928 template <class _ForwardIterator>
2930 __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2931 template <class _ForwardIterator>
2933 __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2934 template <class _ForwardIterator>
2936 __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2937 template <class _ForwardIterator>
2939 __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2940 template <class _ForwardIterator>
2942 __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2943 template <class _ForwardIterator>
2945 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
2946 basic_string<_CharT>* __str = nullptr);
2947 template <class _ForwardIterator>
2949 __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
2950 template <class _ForwardIterator>
2952 __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
2953 template <class _ForwardIterator>
2955 __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
2956 template <class _ForwardIterator>
2958 __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
2959 basic_string<_CharT>& __str,
2960 __bracket_expression<_CharT, _Traits>* __ml);
2961 template <class _ForwardIterator>
2963 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
2964 basic_string<_CharT>* __str = nullptr);
2966 bool __test_back_ref(_CharT c);
2968 _LIBCPP_INLINE_VISIBILITY
2969 void __push_l_anchor();
2970 void __push_r_anchor();
2971 void __push_match_any();
2972 void __push_match_any_but_newline();
2973 _LIBCPP_INLINE_VISIBILITY
2974 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2975 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2976 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2977 __mexp_begin, __mexp_end);}
2978 _LIBCPP_INLINE_VISIBILITY
2979 void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2980 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2981 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2982 __mexp_begin, __mexp_end, false);}
2983 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2984 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2985 bool __greedy = true);
2986 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
2987 void __push_char(value_type __c);
2988 void __push_back_ref(int __i);
2989 void __push_alternation(__owns_one_state<_CharT>* __sa,
2990 __owns_one_state<_CharT>* __sb);
2991 void __push_begin_marked_subexpression();
2992 void __push_end_marked_subexpression(unsigned);
2993 void __push_empty();
2994 void __push_word_boundary(bool);
2995 void __push_lookahead(const basic_regex&, bool, unsigned);
2997 template <class _Allocator>
2999 __search(const _CharT* __first, const _CharT* __last,
3000 match_results<const _CharT*, _Allocator>& __m,
3001 regex_constants::match_flag_type __flags) const;
3003 template <class _Allocator>
3005 __match_at_start(const _CharT* __first, const _CharT* __last,
3006 match_results<const _CharT*, _Allocator>& __m,
3007 regex_constants::match_flag_type __flags, bool) const;
3008 template <class _Allocator>
3010 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
3011 match_results<const _CharT*, _Allocator>& __m,
3012 regex_constants::match_flag_type __flags, bool) const;
3013 template <class _Allocator>
3015 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
3016 match_results<const _CharT*, _Allocator>& __m,
3017 regex_constants::match_flag_type __flags, bool) const;
3018 template <class _Allocator>
3020 __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
3021 match_results<const _CharT*, _Allocator>& __m,
3022 regex_constants::match_flag_type __flags, bool) const;
3024 template <class _Bp, class _Ap, class _Cp, class _Tp>
3027 regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
3028 regex_constants::match_flag_type);
3030 template <class _Ap, class _Cp, class _Tp>
3033 regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&,
3034 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
3036 template <class _Bp, class _Cp, class _Tp>
3039 regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&,
3040 regex_constants::match_flag_type);
3042 template <class _Cp, class _Tp>
3045 regex_search(const _Cp*, const _Cp*,
3046 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
3048 template <class _Cp, class _Ap, class _Tp>
3051 regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&,
3052 regex_constants::match_flag_type);
3054 template <class _ST, class _SA, class _Cp, class _Tp>
3057 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
3058 const basic_regex<_Cp, _Tp>& __e,
3059 regex_constants::match_flag_type __flags);
3061 template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
3064 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
3065 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
3066 const basic_regex<_Cp, _Tp>& __e,
3067 regex_constants::match_flag_type __flags);
3069 template <class _Iter, class _Ap, class _Cp, class _Tp>
3072 regex_search(__wrap_iter<_Iter> __first,
3073 __wrap_iter<_Iter> __last,
3074 match_results<__wrap_iter<_Iter>, _Ap>& __m,
3075 const basic_regex<_Cp, _Tp>& __e,
3076 regex_constants::match_flag_type __flags);
3078 template <class, class> friend class __lookahead;
3081 #if _LIBCPP_STD_VER >= 17
3082 template <class _ForwardIterator,
3083 class = typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value, nullptr_t>::type
3085 basic_regex(_ForwardIterator, _ForwardIterator,
3086 regex_constants::syntax_option_type = regex_constants::ECMAScript)
3087 -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
3090 template <class _CharT, class _Traits>
3091 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
3092 template <class _CharT, class _Traits>
3093 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
3094 template <class _CharT, class _Traits>
3095 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
3096 template <class _CharT, class _Traits>
3097 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
3098 template <class _CharT, class _Traits>
3099 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
3100 template <class _CharT, class _Traits>
3101 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
3102 template <class _CharT, class _Traits>
3103 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
3104 template <class _CharT, class _Traits>
3105 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
3106 template <class _CharT, class _Traits>
3107 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
3108 template <class _CharT, class _Traits>
3109 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
3111 template <class _CharT, class _Traits>
3113 basic_regex<_CharT, _Traits>::swap(basic_regex& __r)
3116 swap(__traits_, __r.__traits_);
3117 swap(__flags_, __r.__flags_);
3118 swap(__marked_count_, __r.__marked_count_);
3119 swap(__loop_count_, __r.__loop_count_);
3120 swap(__open_count_, __r.__open_count_);
3121 swap(__start_, __r.__start_);
3122 swap(__end_, __r.__end_);
3125 template <class _CharT, class _Traits>
3126 inline _LIBCPP_INLINE_VISIBILITY
3128 swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
3130 return __x.swap(__y);
3135 template <class _CharT, class _Traits>
3137 : public __owns_one_state<_CharT>
3139 typedef __owns_one_state<_CharT> base;
3141 basic_regex<_CharT, _Traits> __exp_;
3145 __lookahead(const __lookahead&);
3146 __lookahead& operator=(const __lookahead&);
3148 typedef _VSTD::__state<_CharT> __state;
3150 _LIBCPP_INLINE_VISIBILITY
3151 __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
3152 : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
3154 virtual void __exec(__state&) const;
3157 template <class _CharT, class _Traits>
3159 __lookahead<_CharT, _Traits>::__exec(__state& __s) const
3161 match_results<const _CharT*> __m;
3162 __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
3163 bool __matched = __exp_.__match_at_start_ecma(
3164 __s.__current_, __s.__last_,
3166 (__s.__flags_ | regex_constants::match_continuous) &
3167 ~regex_constants::__full_match,
3168 __s.__at_first_ && __s.__current_ == __s.__first_);
3169 if (__matched != __invert_)
3171 __s.__do_ = __state::__accept_but_not_consume;
3172 __s.__node_ = this->first();
3173 for (unsigned __i = 1; __i < __m.size(); ++__i) {
3174 __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
3179 __s.__do_ = __state::__reject;
3180 __s.__node_ = nullptr;
3184 template <class _CharT, class _Traits>
3185 template <class _ForwardIterator>
3187 basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last)
3189 if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript;
3190 _ForwardIterator __temp = __parse(__first, __last);
3191 if ( __temp != __last)
3192 __throw_regex_error<regex_constants::__re_err_parse>();
3195 template <class _CharT, class _Traits>
3196 template <class _ForwardIterator>
3198 basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
3199 _ForwardIterator __last)
3202 unique_ptr<__node> __h(new __end_state<_CharT>);
3203 __start_.reset(new __empty_state<_CharT>(__h.get()));
3205 __end_ = __start_.get();
3207 switch (__get_grammar(__flags_))
3210 __first = __parse_ecma_exp(__first, __last);
3213 __first = __parse_basic_reg_exp(__first, __last);
3217 __first = __parse_extended_reg_exp(__first, __last);
3220 __first = __parse_grep(__first, __last);
3223 __first = __parse_egrep(__first, __last);
3226 __throw_regex_error<regex_constants::__re_err_grammar>();
3231 template <class _CharT, class _Traits>
3232 template <class _ForwardIterator>
3234 basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
3235 _ForwardIterator __last)
3237 if (__first != __last)
3239 if (*__first == '^')
3244 if (__first != __last)
3246 __first = __parse_RE_expression(__first, __last);
3247 if (__first != __last)
3249 _ForwardIterator __temp = _VSTD::next(__first);
3250 if (__temp == __last && *__first == '$')
3257 if (__first != __last)
3258 __throw_regex_error<regex_constants::__re_err_empty>();
3263 template <class _CharT, class _Traits>
3264 template <class _ForwardIterator>
3266 basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
3267 _ForwardIterator __last)
3269 __owns_one_state<_CharT>* __sa = __end_;
3270 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
3271 if (__temp == __first)
3272 __throw_regex_error<regex_constants::__re_err_empty>();
3274 while (__first != __last && *__first == '|')
3276 __owns_one_state<_CharT>* __sb = __end_;
3277 __temp = __parse_ERE_branch(++__first, __last);
3278 if (__temp == __first)
3279 __throw_regex_error<regex_constants::__re_err_empty>();
3280 __push_alternation(__sa, __sb);
3286 template <class _CharT, class _Traits>
3287 template <class _ForwardIterator>
3289 basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
3290 _ForwardIterator __last)
3292 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
3293 if (__temp == __first)
3294 __throw_regex_error<regex_constants::__re_err_empty>();
3298 __temp = __parse_ERE_expression(__first, __last);
3299 } while (__temp != __first);
3303 template <class _CharT, class _Traits>
3304 template <class _ForwardIterator>
3306 basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
3307 _ForwardIterator __last)
3309 __owns_one_state<_CharT>* __e = __end_;
3310 unsigned __mexp_begin = __marked_count_;
3311 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
3312 if (__temp == __first && __temp != __last)
3325 __push_begin_marked_subexpression();
3326 unsigned __temp_count = __marked_count_;
3328 __temp = __parse_extended_reg_exp(++__temp, __last);
3329 if (__temp == __last || *__temp != ')')
3330 __throw_regex_error<regex_constants::error_paren>();
3331 __push_end_marked_subexpression(__temp_count);
3337 if (__temp != __first)
3338 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
3344 template <class _CharT, class _Traits>
3345 template <class _ForwardIterator>
3347 basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
3348 _ForwardIterator __last)
3352 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
3353 if (__temp == __first)
3360 template <class _CharT, class _Traits>
3361 template <class _ForwardIterator>
3363 basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
3364 _ForwardIterator __last)
3366 if (__first != __last)
3368 __owns_one_state<_CharT>* __e = __end_;
3369 unsigned __mexp_begin = __marked_count_;
3370 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
3371 if (__temp != __first)
3372 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
3373 __mexp_begin+1, __marked_count_+1);
3378 template <class _CharT, class _Traits>
3379 template <class _ForwardIterator>
3381 basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
3382 _ForwardIterator __last)
3384 _ForwardIterator __temp = __first;
3385 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
3386 if (__temp == __first)
3388 __temp = __parse_Back_open_paren(__first, __last);
3389 if (__temp != __first)
3391 __push_begin_marked_subexpression();
3392 unsigned __temp_count = __marked_count_;
3393 __first = __parse_RE_expression(__temp, __last);
3394 __temp = __parse_Back_close_paren(__first, __last);
3395 if (__temp == __first)
3396 __throw_regex_error<regex_constants::error_paren>();
3397 __push_end_marked_subexpression(__temp_count);
3401 __first = __parse_BACKREF(__first, __last);
3406 template <class _CharT, class _Traits>
3407 template <class _ForwardIterator>
3409 basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
3410 _ForwardIterator __first,
3411 _ForwardIterator __last)
3413 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
3414 if (__temp == __first)
3416 __temp = __parse_QUOTED_CHAR(__first, __last);
3417 if (__temp == __first)
3419 if (__temp != __last && *__temp == '.')
3425 __temp = __parse_bracket_expression(__first, __last);
3432 template <class _CharT, class _Traits>
3433 template <class _ForwardIterator>
3435 basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
3436 _ForwardIterator __first,
3437 _ForwardIterator __last)
3439 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
3440 if (__temp == __first)
3442 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
3443 if (__temp == __first)
3445 if (__temp != __last && *__temp == '.')
3451 __temp = __parse_bracket_expression(__first, __last);
3458 template <class _CharT, class _Traits>
3459 template <class _ForwardIterator>
3461 basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
3462 _ForwardIterator __last)
3464 if (__first != __last)
3466 _ForwardIterator __temp = _VSTD::next(__first);
3467 if (__temp != __last)
3469 if (*__first == '\\' && *__temp == '(')
3476 template <class _CharT, class _Traits>
3477 template <class _ForwardIterator>
3479 basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
3480 _ForwardIterator __last)
3482 if (__first != __last)
3484 _ForwardIterator __temp = _VSTD::next(__first);
3485 if (__temp != __last)
3487 if (*__first == '\\' && *__temp == ')')
3494 template <class _CharT, class _Traits>
3495 template <class _ForwardIterator>
3497 basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
3498 _ForwardIterator __last)
3500 if (__first != __last)
3502 _ForwardIterator __temp = _VSTD::next(__first);
3503 if (__temp != __last)
3505 if (*__first == '\\' && *__temp == '{')
3512 template <class _CharT, class _Traits>
3513 template <class _ForwardIterator>
3515 basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
3516 _ForwardIterator __last)
3518 if (__first != __last)
3520 _ForwardIterator __temp = _VSTD::next(__first);
3521 if (__temp != __last)
3523 if (*__first == '\\' && *__temp == '}')
3530 template <class _CharT, class _Traits>
3531 template <class _ForwardIterator>
3533 basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
3534 _ForwardIterator __last)
3536 if (__first != __last)
3538 _ForwardIterator __temp = _VSTD::next(__first);
3539 if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp))
3545 template <class _CharT, class _Traits>
3546 template <class _ForwardIterator>
3548 basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
3549 _ForwardIterator __last)
3551 if (__first != __last)
3553 _ForwardIterator __temp = _VSTD::next(__first);
3554 if (__temp == __last && *__first == '$')
3556 // Not called inside a bracket
3557 if (*__first == '.' || *__first == '\\' || *__first == '[')
3559 __push_char(*__first);
3565 template <class _CharT, class _Traits>
3566 template <class _ForwardIterator>
3568 basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
3569 _ForwardIterator __last)
3571 if (__first != __last)
3588 if (__open_count_ == 0)
3590 __push_char(*__first);
3595 __push_char(*__first);
3603 template <class _CharT, class _Traits>
3604 template <class _ForwardIterator>
3606 basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
3607 _ForwardIterator __last)
3609 if (__first != __last)
3611 _ForwardIterator __temp = _VSTD::next(__first);
3612 if (__temp != __last)
3614 if (*__first == '\\')
3624 __push_char(*__temp);
3634 template <class _CharT, class _Traits>
3635 template <class _ForwardIterator>
3637 basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
3638 _ForwardIterator __last)
3640 if (__first != __last)
3642 _ForwardIterator __temp = _VSTD::next(__first);
3643 if (__temp != __last)
3645 if (*__first == '\\')
3662 __push_char(*__temp);
3666 if (__get_grammar(__flags_) == awk)
3667 __first = __parse_awk_escape(++__first, __last);
3668 else if(__test_back_ref(*__temp))
3678 template <class _CharT, class _Traits>
3679 template <class _ForwardIterator>
3681 basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
3682 _ForwardIterator __last,
3683 __owns_one_state<_CharT>* __s,
3684 unsigned __mexp_begin,
3685 unsigned __mexp_end)
3687 if (__first != __last)
3689 if (*__first == '*')
3691 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3696 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3697 if (__temp != __first)
3701 __temp = __parse_DUP_COUNT(__first, __last, __min);
3702 if (__temp == __first)
3703 __throw_regex_error<regex_constants::error_badbrace>();
3705 if (__first == __last)
3706 __throw_regex_error<regex_constants::error_brace>();
3707 if (*__first != ',')
3709 __temp = __parse_Back_close_brace(__first, __last);
3710 if (__temp == __first)
3711 __throw_regex_error<regex_constants::error_brace>();
3712 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
3718 ++__first; // consume ','
3720 __first = __parse_DUP_COUNT(__first, __last, __max);
3721 __temp = __parse_Back_close_brace(__first, __last);
3722 if (__temp == __first)
3723 __throw_regex_error<regex_constants::error_brace>();
3725 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3729 __throw_regex_error<regex_constants::error_badbrace>();
3730 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
3741 template <class _CharT, class _Traits>
3742 template <class _ForwardIterator>
3744 basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
3745 _ForwardIterator __last,
3746 __owns_one_state<_CharT>* __s,
3747 unsigned __mexp_begin,
3748 unsigned __mexp_end)
3750 if (__first != __last)
3752 unsigned __grammar = __get_grammar(__flags_);
3757 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3760 __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3763 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3767 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3770 __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3773 __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3777 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3780 __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3783 __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
3788 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
3789 if (__temp == __first)
3790 __throw_regex_error<regex_constants::error_badbrace>();
3792 if (__first == __last)
3793 __throw_regex_error<regex_constants::error_brace>();
3798 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3801 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3804 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
3808 if (__first == __last)
3809 __throw_regex_error<regex_constants::error_badbrace>();
3810 if (*__first == '}')
3813 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3816 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3819 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3824 __temp = __parse_DUP_COUNT(__first, __last, __max);
3825 if (__temp == __first)
3826 __throw_regex_error<regex_constants::error_brace>();
3828 if (__first == __last || *__first != '}')
3829 __throw_regex_error<regex_constants::error_brace>();
3832 __throw_regex_error<regex_constants::error_badbrace>();
3833 if (__grammar == ECMAScript && __first != __last && *__first == '?')
3836 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3839 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
3843 __throw_regex_error<regex_constants::error_badbrace>();
3852 template <class _CharT, class _Traits>
3853 template <class _ForwardIterator>
3855 basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
3856 _ForwardIterator __last)
3858 if (__first != __last && *__first == '[')
3861 if (__first == __last)
3862 __throw_regex_error<regex_constants::error_brack>();
3863 bool __negate = false;
3864 if (*__first == '^')
3869 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3870 // __ml owned by *this
3871 if (__first == __last)
3872 __throw_regex_error<regex_constants::error_brack>();
3873 if (__get_grammar(__flags_) != ECMAScript && *__first == ']')
3875 __ml->__add_char(']');
3878 __first = __parse_follow_list(__first, __last, __ml);
3879 if (__first == __last)
3880 __throw_regex_error<regex_constants::error_brack>();
3881 if (*__first == '-')
3883 __ml->__add_char('-');
3886 if (__first == __last || *__first != ']')
3887 __throw_regex_error<regex_constants::error_brack>();
3893 template <class _CharT, class _Traits>
3894 template <class _ForwardIterator>
3896 basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
3897 _ForwardIterator __last,
3898 __bracket_expression<_CharT, _Traits>* __ml)
3900 if (__first != __last)
3904 _ForwardIterator __temp = __parse_expression_term(__first, __last,
3906 if (__temp == __first)
3914 template <class _CharT, class _Traits>
3915 template <class _ForwardIterator>
3917 basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
3918 _ForwardIterator __last,
3919 __bracket_expression<_CharT, _Traits>* __ml)
3921 if (__first != __last && *__first != ']')
3923 _ForwardIterator __temp = _VSTD::next(__first);
3924 basic_string<_CharT> __start_range;
3925 if (__temp != __last && *__first == '[')
3928 return __parse_equivalence_class(++__temp, __last, __ml);
3929 else if (*__temp == ':')
3930 return __parse_character_class(++__temp, __last, __ml);
3931 else if (*__temp == '.')
3932 __first = __parse_collating_symbol(++__temp, __last, __start_range);
3934 unsigned __grammar = __get_grammar(__flags_);
3935 if (__start_range.empty())
3937 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3939 if (__grammar == ECMAScript)
3940 __first = __parse_class_escape(++__first, __last, __start_range, __ml);
3942 __first = __parse_awk_escape(++__first, __last, &__start_range);
3946 __start_range = *__first;
3950 if (__first != __last && *__first != ']')
3952 __temp = _VSTD::next(__first);
3953 if (__temp != __last && *__first == '-' && *__temp != ']')
3956 basic_string<_CharT> __end_range;
3959 if (__temp != __last && *__first == '[' && *__temp == '.')
3960 __first = __parse_collating_symbol(++__temp, __last, __end_range);
3963 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3965 if (__grammar == ECMAScript)
3966 __first = __parse_class_escape(++__first, __last,
3969 __first = __parse_awk_escape(++__first, __last,
3974 __end_range = *__first;
3978 __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range));
3980 else if (!__start_range.empty())
3982 if (__start_range.size() == 1)
3983 __ml->__add_char(__start_range[0]);
3985 __ml->__add_digraph(__start_range[0], __start_range[1]);
3988 else if (!__start_range.empty())
3990 if (__start_range.size() == 1)
3991 __ml->__add_char(__start_range[0]);
3993 __ml->__add_digraph(__start_range[0], __start_range[1]);
3999 template <class _CharT, class _Traits>
4000 template <class _ForwardIterator>
4002 basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
4003 _ForwardIterator __last,
4004 basic_string<_CharT>& __str,
4005 __bracket_expression<_CharT, _Traits>* __ml)
4007 if (__first == __last)
4008 __throw_regex_error<regex_constants::error_escape>();
4018 __ml->__add_class(ctype_base::digit);
4021 __ml->__add_neg_class(ctype_base::digit);
4024 __ml->__add_class(ctype_base::space);
4027 __ml->__add_neg_class(ctype_base::space);
4030 __ml->__add_class(ctype_base::alnum);
4031 __ml->__add_char('_');
4034 __ml->__add_neg_class(ctype_base::alnum);
4035 __ml->__add_neg_char('_');
4038 __first = __parse_character_escape(__first, __last, &__str);
4042 template <class _CharT, class _Traits>
4043 template <class _ForwardIterator>
4045 basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
4046 _ForwardIterator __last,
4047 basic_string<_CharT>* __str)
4049 if (__first == __last)
4050 __throw_regex_error<regex_constants::error_escape>();
4059 __push_char(*__first);
4065 __push_char(_CharT(7));
4071 __push_char(_CharT(8));
4075 *__str = _CharT(0xC);
4077 __push_char(_CharT(0xC));
4081 *__str = _CharT(0xA);
4083 __push_char(_CharT(0xA));
4087 *__str = _CharT(0xD);
4089 __push_char(_CharT(0xD));
4093 *__str = _CharT(0x9);
4095 __push_char(_CharT(0x9));
4099 *__str = _CharT(0xB);
4101 __push_char(_CharT(0xB));
4104 if ('0' <= *__first && *__first <= '7')
4106 unsigned __val = *__first - '0';
4107 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
4109 __val = 8 * __val + *__first - '0';
4110 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
4111 __val = 8 * __val + *__first++ - '0';
4114 *__str = _CharT(__val);
4116 __push_char(_CharT(__val));
4119 __throw_regex_error<regex_constants::error_escape>();
4123 template <class _CharT, class _Traits>
4124 template <class _ForwardIterator>
4126 basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
4127 _ForwardIterator __last,
4128 __bracket_expression<_CharT, _Traits>* __ml)
4131 // This means =] must exist
4132 value_type _Equal_close[2] = {'=', ']'};
4133 _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close,
4135 if (__temp == __last)
4136 __throw_regex_error<regex_constants::error_brack>();
4137 // [__first, __temp) contains all text in [= ... =]
4138 string_type __collate_name =
4139 __traits_.lookup_collatename(__first, __temp);
4140 if (__collate_name.empty())
4141 __throw_regex_error<regex_constants::error_collate>();
4142 string_type __equiv_name =
4143 __traits_.transform_primary(__collate_name.begin(),
4144 __collate_name.end());
4145 if (!__equiv_name.empty())
4146 __ml->__add_equivalence(__equiv_name);
4149 switch (__collate_name.size())
4152 __ml->__add_char(__collate_name[0]);
4155 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
4158 __throw_regex_error<regex_constants::error_collate>();
4161 __first = _VSTD::next(__temp, 2);
4165 template <class _CharT, class _Traits>
4166 template <class _ForwardIterator>
4168 basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
4169 _ForwardIterator __last,
4170 __bracket_expression<_CharT, _Traits>* __ml)
4173 // This means :] must exist
4174 value_type _Colon_close[2] = {':', ']'};
4175 _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close,
4177 if (__temp == __last)
4178 __throw_regex_error<regex_constants::error_brack>();
4179 // [__first, __temp) contains all text in [: ... :]
4180 typedef typename _Traits::char_class_type char_class_type;
4181 char_class_type __class_type =
4182 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
4183 if (__class_type == 0)
4184 __throw_regex_error<regex_constants::error_ctype>();
4185 __ml->__add_class(__class_type);
4186 __first = _VSTD::next(__temp, 2);
4190 template <class _CharT, class _Traits>
4191 template <class _ForwardIterator>
4193 basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
4194 _ForwardIterator __last,
4195 basic_string<_CharT>& __col_sym)
4198 // This means .] must exist
4199 value_type _Dot_close[2] = {'.', ']'};
4200 _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close,
4202 if (__temp == __last)
4203 __throw_regex_error<regex_constants::error_brack>();
4204 // [__first, __temp) contains all text in [. ... .]
4205 __col_sym = __traits_.lookup_collatename(__first, __temp);
4206 switch (__col_sym.size())
4212 __throw_regex_error<regex_constants::error_collate>();
4214 __first = _VSTD::next(__temp, 2);
4218 template <class _CharT, class _Traits>
4219 template <class _ForwardIterator>
4221 basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
4222 _ForwardIterator __last,
4225 if (__first != __last )
4227 int __val = __traits_.value(*__first, 10);
4232 __first != __last && ( __val = __traits_.value(*__first, 10)) != -1;
4235 if (__c >= numeric_limits<int>::max() / 10)
4236 __throw_regex_error<regex_constants::error_badbrace>();
4245 template <class _CharT, class _Traits>
4246 template <class _ForwardIterator>
4248 basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
4249 _ForwardIterator __last)
4251 __owns_one_state<_CharT>* __sa = __end_;
4252 _ForwardIterator __temp = __parse_alternative(__first, __last);
4253 if (__temp == __first)
4256 while (__first != __last && *__first == '|')
4258 __owns_one_state<_CharT>* __sb = __end_;
4259 __temp = __parse_alternative(++__first, __last);
4260 if (__temp == __first)
4262 __push_alternation(__sa, __sb);
4268 template <class _CharT, class _Traits>
4269 template <class _ForwardIterator>
4271 basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
4272 _ForwardIterator __last)
4276 _ForwardIterator __temp = __parse_term(__first, __last);
4277 if (__temp == __first)
4284 template <class _CharT, class _Traits>
4285 template <class _ForwardIterator>
4287 basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
4288 _ForwardIterator __last)
4290 _ForwardIterator __temp = __parse_assertion(__first, __last);
4291 if (__temp == __first)
4293 __owns_one_state<_CharT>* __e = __end_;
4294 unsigned __mexp_begin = __marked_count_;
4295 __temp = __parse_atom(__first, __last);
4296 if (__temp != __first)
4297 __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
4298 __mexp_begin+1, __marked_count_+1);
4305 template <class _CharT, class _Traits>
4306 template <class _ForwardIterator>
4308 basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
4309 _ForwardIterator __last)
4311 if (__first != __last)
4325 _ForwardIterator __temp = _VSTD::next(__first);
4326 if (__temp != __last)
4330 __push_word_boundary(false);
4333 else if (*__temp == 'B')
4335 __push_word_boundary(true);
4343 _ForwardIterator __temp = _VSTD::next(__first);
4344 if (__temp != __last && *__temp == '?')
4346 if (++__temp != __last)
4353 __exp.__flags_ = __flags_;
4354 __temp = __exp.__parse(++__temp, __last);
4355 unsigned __mexp = __exp.__marked_count_;
4356 __push_lookahead(_VSTD::move(__exp), false, __marked_count_);
4357 __marked_count_ += __mexp;
4358 if (__temp == __last || *__temp != ')')
4359 __throw_regex_error<regex_constants::error_paren>();
4366 __exp.__flags_ = __flags_;
4367 __temp = __exp.__parse(++__temp, __last);
4368 unsigned __mexp = __exp.__marked_count_;
4369 __push_lookahead(_VSTD::move(__exp), true, __marked_count_);
4370 __marked_count_ += __mexp;
4371 if (__temp == __last || *__temp != ')')
4372 __throw_regex_error<regex_constants::error_paren>();
4386 template <class _CharT, class _Traits>
4387 template <class _ForwardIterator>
4389 basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
4390 _ForwardIterator __last)
4392 if (__first != __last)
4397 __push_match_any_but_newline();
4401 __first = __parse_atom_escape(__first, __last);
4404 __first = __parse_bracket_expression(__first, __last);
4409 if (__first == __last)
4410 __throw_regex_error<regex_constants::error_paren>();
4411 _ForwardIterator __temp = _VSTD::next(__first);
4412 if (__temp != __last && *__first == '?' && *__temp == ':')
4415 __first = __parse_ecma_exp(++__temp, __last);
4416 if (__first == __last || *__first != ')')
4417 __throw_regex_error<regex_constants::error_paren>();
4423 __push_begin_marked_subexpression();
4424 unsigned __temp_count = __marked_count_;
4426 __first = __parse_ecma_exp(__first, __last);
4427 if (__first == __last || *__first != ')')
4428 __throw_regex_error<regex_constants::error_paren>();
4429 __push_end_marked_subexpression(__temp_count);
4439 __throw_regex_error<regex_constants::error_badrepeat>();
4442 __first = __parse_pattern_character(__first, __last);
4449 template <class _CharT, class _Traits>
4450 template <class _ForwardIterator>
4452 basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
4453 _ForwardIterator __last)
4455 if (__first != __last && *__first == '\\')
4457 _ForwardIterator __t1 = _VSTD::next(__first);
4459 __throw_regex_error<regex_constants::error_escape>();
4461 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
4466 __t2 = __parse_character_class_escape(__t1, __last);
4471 __t2 = __parse_character_escape(__t1, __last);
4480 template <class _CharT, class _Traits>
4481 template <class _ForwardIterator>
4483 basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
4484 _ForwardIterator __last)
4486 if (__first != __last)
4488 if (*__first == '0')
4490 __push_char(_CharT());
4493 else if ('1' <= *__first && *__first <= '9')
4495 unsigned __v = *__first - '0';
4497 __first != __last && '0' <= *__first && *__first <= '9'; ++__first)
4499 if (__v >= numeric_limits<unsigned>::max() / 10)
4500 __throw_regex_error<regex_constants::error_backref>();
4501 __v = 10 * __v + *__first - '0';
4503 if (__v == 0 || __v > mark_count())
4504 __throw_regex_error<regex_constants::error_backref>();
4505 __push_back_ref(__v);
4511 template <class _CharT, class _Traits>
4512 template <class _ForwardIterator>
4514 basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
4515 _ForwardIterator __last)
4517 if (__first != __last)
4519 __bracket_expression<_CharT, _Traits>* __ml;
4523 __ml = __start_matching_list(false);
4524 __ml->__add_class(ctype_base::digit);
4528 __ml = __start_matching_list(true);
4529 __ml->__add_class(ctype_base::digit);
4533 __ml = __start_matching_list(false);
4534 __ml->__add_class(ctype_base::space);
4538 __ml = __start_matching_list(true);
4539 __ml->__add_class(ctype_base::space);
4543 __ml = __start_matching_list(false);
4544 __ml->__add_class(ctype_base::alnum);
4545 __ml->__add_char('_');
4549 __ml = __start_matching_list(true);
4550 __ml->__add_class(ctype_base::alnum);
4551 __ml->__add_char('_');
4559 template <class _CharT, class _Traits>
4560 template <class _ForwardIterator>
4562 basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
4563 _ForwardIterator __last,
4564 basic_string<_CharT>* __str)
4566 if (__first != __last)
4568 _ForwardIterator __t;
4575 *__str = _CharT(0xC);
4577 __push_char(_CharT(0xC));
4582 *__str = _CharT(0xA);
4584 __push_char(_CharT(0xA));
4589 *__str = _CharT(0xD);
4591 __push_char(_CharT(0xD));
4596 *__str = _CharT(0x9);
4598 __push_char(_CharT(0x9));
4603 *__str = _CharT(0xB);
4605 __push_char(_CharT(0xB));
4609 if ((__t = _VSTD::next(__first)) != __last)
4611 if (('A' <= *__t && *__t <= 'Z') ||
4612 ('a' <= *__t && *__t <= 'z'))
4615 *__str = _CharT(*__t % 32);
4617 __push_char(_CharT(*__t % 32));
4621 __throw_regex_error<regex_constants::error_escape>();
4624 __throw_regex_error<regex_constants::error_escape>();
4628 if (__first == __last)
4629 __throw_regex_error<regex_constants::error_escape>();
4630 __hd = __traits_.value(*__first, 16);
4632 __throw_regex_error<regex_constants::error_escape>();
4633 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4635 if (__first == __last)
4636 __throw_regex_error<regex_constants::error_escape>();
4637 __hd = __traits_.value(*__first, 16);
4639 __throw_regex_error<regex_constants::error_escape>();
4640 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4644 if (__first == __last)
4645 __throw_regex_error<regex_constants::error_escape>();
4646 __hd = __traits_.value(*__first, 16);
4648 __throw_regex_error<regex_constants::error_escape>();
4649 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4651 if (__first == __last)
4652 __throw_regex_error<regex_constants::error_escape>();
4653 __hd = __traits_.value(*__first, 16);
4655 __throw_regex_error<regex_constants::error_escape>();
4656 __sum = 16 * __sum + static_cast<unsigned>(__hd);
4658 *__str = _CharT(__sum);
4660 __push_char(_CharT(__sum));
4667 __push_char(_CharT(0));
4671 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
4676 __push_char(*__first);
4680 __throw_regex_error<regex_constants::error_escape>();
4687 template <class _CharT, class _Traits>
4688 template <class _ForwardIterator>
4690 basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
4691 _ForwardIterator __last)
4693 if (__first != __last)
4713 __push_char(*__first);
4721 template <class _CharT, class _Traits>
4722 template <class _ForwardIterator>
4724 basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
4725 _ForwardIterator __last)
4727 __owns_one_state<_CharT>* __sa = __end_;
4728 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4729 if (__t1 != __first)
4730 __parse_basic_reg_exp(__first, __t1);
4734 if (__first != __last)
4736 while (__first != __last)
4738 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4739 __owns_one_state<_CharT>* __sb = __end_;
4740 if (__t1 != __first)
4741 __parse_basic_reg_exp(__first, __t1);
4744 __push_alternation(__sa, __sb);
4746 if (__first != __last)
4752 template <class _CharT, class _Traits>
4753 template <class _ForwardIterator>
4755 basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
4756 _ForwardIterator __last)
4758 __owns_one_state<_CharT>* __sa = __end_;
4759 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4760 if (__t1 != __first)
4761 __parse_extended_reg_exp(__first, __t1);
4765 if (__first != __last)
4767 while (__first != __last)
4769 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
4770 __owns_one_state<_CharT>* __sb = __end_;
4771 if (__t1 != __first)
4772 __parse_extended_reg_exp(__first, __t1);
4775 __push_alternation(__sa, __sb);
4777 if (__first != __last)
4783 template <class _CharT, class _Traits>
4785 basic_regex<_CharT, _Traits>::__test_back_ref(_CharT c)
4787 unsigned __val = __traits_.value(c, 10);
4788 if (__val >= 1 && __val <= 9)
4790 if (__val > mark_count())
4791 __throw_regex_error<regex_constants::error_backref>();
4792 __push_back_ref(__val);
4799 template <class _CharT, class _Traits>
4801 basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
4802 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
4805 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4806 __end_->first() = nullptr;
4807 unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
4808 __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
4810 __s->first() = nullptr;
4812 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
4813 __end_ = __e2->second();
4814 __s->first() = __e2.release();
4818 template <class _CharT, class _Traits>
4820 basic_regex<_CharT, _Traits>::__push_char(value_type __c)
4822 if (flags() & icase)
4823 __end_->first() = new __match_char_icase<_CharT, _Traits>
4824 (__traits_, __c, __end_->first());
4825 else if (flags() & collate)
4826 __end_->first() = new __match_char_collate<_CharT, _Traits>
4827 (__traits_, __c, __end_->first());
4829 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
4830 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4833 template <class _CharT, class _Traits>
4835 basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
4837 if (!(__flags_ & nosubs))
4840 new __begin_marked_subexpression<_CharT>(++__marked_count_,
4842 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4846 template <class _CharT, class _Traits>
4848 basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
4850 if (!(__flags_ & nosubs))
4853 new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4854 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4858 template <class _CharT, class _Traits>
4860 basic_regex<_CharT, _Traits>::__push_l_anchor()
4862 __end_->first() = new __l_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
4863 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4866 template <class _CharT, class _Traits>
4868 basic_regex<_CharT, _Traits>::__push_r_anchor()
4870 __end_->first() = new __r_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
4871 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4874 template <class _CharT, class _Traits>
4876 basic_regex<_CharT, _Traits>::__push_match_any()
4878 __end_->first() = new __match_any<_CharT>(__end_->first());
4879 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4882 template <class _CharT, class _Traits>
4884 basic_regex<_CharT, _Traits>::__push_match_any_but_newline()
4886 __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
4887 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4890 template <class _CharT, class _Traits>
4892 basic_regex<_CharT, _Traits>::__push_empty()
4894 __end_->first() = new __empty_state<_CharT>(__end_->first());
4895 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4898 template <class _CharT, class _Traits>
4900 basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
4902 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
4904 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4907 template <class _CharT, class _Traits>
4909 basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
4911 if (flags() & icase)
4912 __end_->first() = new __back_ref_icase<_CharT, _Traits>
4913 (__traits_, __i, __end_->first());
4914 else if (flags() & collate)
4915 __end_->first() = new __back_ref_collate<_CharT, _Traits>
4916 (__traits_, __i, __end_->first());
4918 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
4919 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4922 template <class _CharT, class _Traits>
4924 basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
4925 __owns_one_state<_CharT>* __ea)
4927 __sa->first() = new __alternate<_CharT>(
4928 static_cast<__owns_one_state<_CharT>*>(__sa->first()),
4929 static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4930 __ea->first() = nullptr;
4931 __ea->first() = new __empty_state<_CharT>(__end_->first());
4932 __end_->first() = nullptr;
4933 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4934 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4937 template <class _CharT, class _Traits>
4938 __bracket_expression<_CharT, _Traits>*
4939 basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
4941 __bracket_expression<_CharT, _Traits>* __r =
4942 new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
4943 __negate, __flags_ & icase,
4944 __flags_ & collate);
4945 __end_->first() = __r;
4950 template <class _CharT, class _Traits>
4952 basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
4956 __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
4957 __end_->first(), __mexp);
4958 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4963 typedef sub_match<const char*> csub_match;
4964 typedef sub_match<string::const_iterator> ssub_match;
4965 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4966 typedef sub_match<const wchar_t*> wcsub_match;
4967 typedef sub_match<wstring::const_iterator> wssub_match;
4970 template <class _BidirectionalIterator>
4972 _LIBCPP_TEMPLATE_VIS
4973 _LIBCPP_PREFERRED_NAME(csub_match)
4974 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match))
4975 _LIBCPP_PREFERRED_NAME(ssub_match)
4976 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match))
4978 : public pair<_BidirectionalIterator, _BidirectionalIterator>
4981 typedef _BidirectionalIterator iterator;
4982 typedef typename iterator_traits<iterator>::value_type value_type;
4983 typedef typename iterator_traits<iterator>::difference_type difference_type;
4984 typedef basic_string<value_type> string_type;
4988 _LIBCPP_INLINE_VISIBILITY
4989 _LIBCPP_CONSTEXPR sub_match() : matched() {}
4991 _LIBCPP_INLINE_VISIBILITY
4992 difference_type length() const
4993 {return matched ? _VSTD::distance(this->first, this->second) : 0;}
4994 _LIBCPP_INLINE_VISIBILITY
4995 string_type str() const
4996 {return matched ? string_type(this->first, this->second) : string_type();}
4997 _LIBCPP_INLINE_VISIBILITY
4998 operator string_type() const
5001 _LIBCPP_INLINE_VISIBILITY
5002 int compare(const sub_match& __s) const
5003 {return str().compare(__s.str());}
5004 _LIBCPP_INLINE_VISIBILITY
5005 int compare(const string_type& __s) const
5006 {return str().compare(__s);}
5007 _LIBCPP_INLINE_VISIBILITY
5008 int compare(const value_type* __s) const
5009 {return str().compare(__s);}
5012 template <class _BiIter>
5013 inline _LIBCPP_INLINE_VISIBILITY
5015 operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
5017 return __x.compare(__y) == 0;
5020 template <class _BiIter>
5021 inline _LIBCPP_INLINE_VISIBILITY
5023 operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
5025 return !(__x == __y);
5028 template <class _BiIter>
5029 inline _LIBCPP_INLINE_VISIBILITY
5031 operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
5033 return __x.compare(__y) < 0;
5036 template <class _BiIter>
5037 inline _LIBCPP_INLINE_VISIBILITY
5039 operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
5041 return !(__y < __x);
5044 template <class _BiIter>
5045 inline _LIBCPP_INLINE_VISIBILITY
5047 operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
5049 return !(__x < __y);
5052 template <class _BiIter>
5053 inline _LIBCPP_INLINE_VISIBILITY
5055 operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
5060 template <class _BiIter, class _ST, class _SA>
5061 inline _LIBCPP_INLINE_VISIBILITY
5063 operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5064 const sub_match<_BiIter>& __y)
5066 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
5069 template <class _BiIter, class _ST, class _SA>
5070 inline _LIBCPP_INLINE_VISIBILITY
5072 operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5073 const sub_match<_BiIter>& __y)
5075 return !(__x == __y);
5078 template <class _BiIter, class _ST, class _SA>
5079 inline _LIBCPP_INLINE_VISIBILITY
5081 operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5082 const sub_match<_BiIter>& __y)
5084 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
5087 template <class _BiIter, class _ST, class _SA>
5088 inline _LIBCPP_INLINE_VISIBILITY
5090 operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5091 const sub_match<_BiIter>& __y)
5096 template <class _BiIter, class _ST, class _SA>
5097 inline _LIBCPP_INLINE_VISIBILITY
5098 bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5099 const sub_match<_BiIter>& __y)
5101 return !(__x < __y);
5104 template <class _BiIter, class _ST, class _SA>
5105 inline _LIBCPP_INLINE_VISIBILITY
5107 operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
5108 const sub_match<_BiIter>& __y)
5110 return !(__y < __x);
5113 template <class _BiIter, class _ST, class _SA>
5114 inline _LIBCPP_INLINE_VISIBILITY
5116 operator==(const sub_match<_BiIter>& __x,
5117 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5119 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
5122 template <class _BiIter, class _ST, class _SA>
5123 inline _LIBCPP_INLINE_VISIBILITY
5125 operator!=(const sub_match<_BiIter>& __x,
5126 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5128 return !(__x == __y);
5131 template <class _BiIter, class _ST, class _SA>
5132 inline _LIBCPP_INLINE_VISIBILITY
5134 operator<(const sub_match<_BiIter>& __x,
5135 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5137 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
5140 template <class _BiIter, class _ST, class _SA>
5141 inline _LIBCPP_INLINE_VISIBILITY
5142 bool operator>(const sub_match<_BiIter>& __x,
5143 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5148 template <class _BiIter, class _ST, class _SA>
5149 inline _LIBCPP_INLINE_VISIBILITY
5151 operator>=(const sub_match<_BiIter>& __x,
5152 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5154 return !(__x < __y);
5157 template <class _BiIter, class _ST, class _SA>
5158 inline _LIBCPP_INLINE_VISIBILITY
5160 operator<=(const sub_match<_BiIter>& __x,
5161 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
5163 return !(__y < __x);
5166 template <class _BiIter>
5167 inline _LIBCPP_INLINE_VISIBILITY
5169 operator==(typename iterator_traits<_BiIter>::value_type const* __x,
5170 const sub_match<_BiIter>& __y)
5172 return __y.compare(__x) == 0;
5175 template <class _BiIter>
5176 inline _LIBCPP_INLINE_VISIBILITY
5178 operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
5179 const sub_match<_BiIter>& __y)
5181 return !(__x == __y);
5184 template <class _BiIter>
5185 inline _LIBCPP_INLINE_VISIBILITY
5187 operator<(typename iterator_traits<_BiIter>::value_type const* __x,
5188 const sub_match<_BiIter>& __y)
5190 return __y.compare(__x) > 0;
5193 template <class _BiIter>
5194 inline _LIBCPP_INLINE_VISIBILITY
5196 operator>(typename iterator_traits<_BiIter>::value_type const* __x,
5197 const sub_match<_BiIter>& __y)
5202 template <class _BiIter>
5203 inline _LIBCPP_INLINE_VISIBILITY
5205 operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
5206 const sub_match<_BiIter>& __y)
5208 return !(__x < __y);
5211 template <class _BiIter>
5212 inline _LIBCPP_INLINE_VISIBILITY
5214 operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
5215 const sub_match<_BiIter>& __y)
5217 return !(__y < __x);
5220 template <class _BiIter>
5221 inline _LIBCPP_INLINE_VISIBILITY
5223 operator==(const sub_match<_BiIter>& __x,
5224 typename iterator_traits<_BiIter>::value_type const* __y)
5226 return __x.compare(__y) == 0;
5229 template <class _BiIter>
5230 inline _LIBCPP_INLINE_VISIBILITY
5232 operator!=(const sub_match<_BiIter>& __x,
5233 typename iterator_traits<_BiIter>::value_type const* __y)
5235 return !(__x == __y);
5238 template <class _BiIter>
5239 inline _LIBCPP_INLINE_VISIBILITY
5241 operator<(const sub_match<_BiIter>& __x,
5242 typename iterator_traits<_BiIter>::value_type const* __y)
5244 return __x.compare(__y) < 0;
5247 template <class _BiIter>
5248 inline _LIBCPP_INLINE_VISIBILITY
5250 operator>(const sub_match<_BiIter>& __x,
5251 typename iterator_traits<_BiIter>::value_type const* __y)
5256 template <class _BiIter>
5257 inline _LIBCPP_INLINE_VISIBILITY
5259 operator>=(const sub_match<_BiIter>& __x,
5260 typename iterator_traits<_BiIter>::value_type const* __y)
5262 return !(__x < __y);
5265 template <class _BiIter>
5266 inline _LIBCPP_INLINE_VISIBILITY
5268 operator<=(const sub_match<_BiIter>& __x,
5269 typename iterator_traits<_BiIter>::value_type const* __y)
5271 return !(__y < __x);
5274 template <class _BiIter>
5275 inline _LIBCPP_INLINE_VISIBILITY
5277 operator==(typename iterator_traits<_BiIter>::value_type const& __x,
5278 const sub_match<_BiIter>& __y)
5280 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5281 return __y.compare(string_type(1, __x)) == 0;
5284 template <class _BiIter>
5285 inline _LIBCPP_INLINE_VISIBILITY
5287 operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
5288 const sub_match<_BiIter>& __y)
5290 return !(__x == __y);
5293 template <class _BiIter>
5294 inline _LIBCPP_INLINE_VISIBILITY
5296 operator<(typename iterator_traits<_BiIter>::value_type const& __x,
5297 const sub_match<_BiIter>& __y)
5299 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5300 return __y.compare(string_type(1, __x)) > 0;
5303 template <class _BiIter>
5304 inline _LIBCPP_INLINE_VISIBILITY
5306 operator>(typename iterator_traits<_BiIter>::value_type const& __x,
5307 const sub_match<_BiIter>& __y)
5312 template <class _BiIter>
5313 inline _LIBCPP_INLINE_VISIBILITY
5315 operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
5316 const sub_match<_BiIter>& __y)
5318 return !(__x < __y);
5321 template <class _BiIter>
5322 inline _LIBCPP_INLINE_VISIBILITY
5324 operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
5325 const sub_match<_BiIter>& __y)
5327 return !(__y < __x);
5330 template <class _BiIter>
5331 inline _LIBCPP_INLINE_VISIBILITY
5333 operator==(const sub_match<_BiIter>& __x,
5334 typename iterator_traits<_BiIter>::value_type const& __y)
5336 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5337 return __x.compare(string_type(1, __y)) == 0;
5340 template <class _BiIter>
5341 inline _LIBCPP_INLINE_VISIBILITY
5343 operator!=(const sub_match<_BiIter>& __x,
5344 typename iterator_traits<_BiIter>::value_type const& __y)
5346 return !(__x == __y);
5349 template <class _BiIter>
5350 inline _LIBCPP_INLINE_VISIBILITY
5352 operator<(const sub_match<_BiIter>& __x,
5353 typename iterator_traits<_BiIter>::value_type const& __y)
5355 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5356 return __x.compare(string_type(1, __y)) < 0;
5359 template <class _BiIter>
5360 inline _LIBCPP_INLINE_VISIBILITY
5362 operator>(const sub_match<_BiIter>& __x,
5363 typename iterator_traits<_BiIter>::value_type const& __y)
5368 template <class _BiIter>
5369 inline _LIBCPP_INLINE_VISIBILITY
5371 operator>=(const sub_match<_BiIter>& __x,
5372 typename iterator_traits<_BiIter>::value_type const& __y)
5374 return !(__x < __y);
5377 template <class _BiIter>
5378 inline _LIBCPP_INLINE_VISIBILITY
5380 operator<=(const sub_match<_BiIter>& __x,
5381 typename iterator_traits<_BiIter>::value_type const& __y)
5383 return !(__y < __x);
5386 template <class _CharT, class _ST, class _BiIter>
5387 inline _LIBCPP_INLINE_VISIBILITY
5388 basic_ostream<_CharT, _ST>&
5389 operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
5391 return __os << __m.str();
5394 typedef match_results<const char*> cmatch;
5395 typedef match_results<string::const_iterator> smatch;
5396 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5397 typedef match_results<const wchar_t*> wcmatch;
5398 typedef match_results<wstring::const_iterator> wsmatch;
5401 template <class _BidirectionalIterator, class _Allocator>
5403 _LIBCPP_TEMPLATE_VIS
5404 _LIBCPP_PREFERRED_NAME(cmatch)
5405 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch))
5406 _LIBCPP_PREFERRED_NAME(smatch)
5407 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch))
5411 typedef _Allocator allocator_type;
5412 typedef sub_match<_BidirectionalIterator> value_type;
5414 typedef vector<value_type, allocator_type> __container_type;
5416 __container_type __matches_;
5417 value_type __unmatched_;
5418 value_type __prefix_;
5419 value_type __suffix_;
5422 _BidirectionalIterator __position_start_;
5423 typedef const value_type& const_reference;
5424 typedef value_type& reference;
5425 typedef typename __container_type::const_iterator const_iterator;
5426 typedef const_iterator iterator;
5427 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
5428 typedef typename allocator_traits<allocator_type>::size_type size_type;
5429 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
5430 typedef basic_string<char_type> string_type;
5432 // construct/copy/destroy:
5433 #ifndef _LIBCPP_CXX03_LANG
5434 match_results() : match_results(allocator_type()) {}
5435 explicit match_results(const allocator_type& __a);
5437 explicit match_results(const allocator_type& __a = allocator_type());
5440 // match_results(const match_results&) = default;
5441 // match_results& operator=(const match_results&) = default;
5442 // match_results(match_results&& __m) = default;
5443 // match_results& operator=(match_results&& __m) = default;
5444 // ~match_results() = default;
5446 _LIBCPP_INLINE_VISIBILITY
5447 bool ready() const {return __ready_;}
5450 _LIBCPP_INLINE_VISIBILITY
5451 size_type size() const _NOEXCEPT {return __matches_.size();}
5452 _LIBCPP_INLINE_VISIBILITY
5453 size_type max_size() const _NOEXCEPT {return __matches_.max_size();}
5454 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
5455 bool empty() const _NOEXCEPT {return size() == 0;}
5458 _LIBCPP_INLINE_VISIBILITY
5459 difference_type length(size_type __sub = 0) const
5461 _LIBCPP_ASSERT(ready(), "match_results::length() called when not ready");
5462 return (*this)[__sub].length();
5464 _LIBCPP_INLINE_VISIBILITY
5465 difference_type position(size_type __sub = 0) const
5467 _LIBCPP_ASSERT(ready(), "match_results::position() called when not ready");
5468 return _VSTD::distance(__position_start_, (*this)[__sub].first);
5470 _LIBCPP_INLINE_VISIBILITY
5471 string_type str(size_type __sub = 0) const
5473 _LIBCPP_ASSERT(ready(), "match_results::str() called when not ready");
5474 return (*this)[__sub].str();
5476 _LIBCPP_INLINE_VISIBILITY
5477 const_reference operator[](size_type __n) const
5479 _LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready");
5480 return __n < __matches_.size() ? __matches_[__n] : __unmatched_;
5483 _LIBCPP_INLINE_VISIBILITY
5484 const_reference prefix() const
5486 _LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready");
5489 _LIBCPP_INLINE_VISIBILITY
5490 const_reference suffix() const
5492 _LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready");
5496 _LIBCPP_INLINE_VISIBILITY
5497 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();}
5498 _LIBCPP_INLINE_VISIBILITY
5499 const_iterator end() const {return __matches_.end();}
5500 _LIBCPP_INLINE_VISIBILITY
5501 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();}
5502 _LIBCPP_INLINE_VISIBILITY
5503 const_iterator cend() const {return __matches_.end();}
5506 template <class _OutputIter>
5508 format(_OutputIter __output_iter, const char_type* __fmt_first,
5509 const char_type* __fmt_last,
5510 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
5511 template <class _OutputIter, class _ST, class _SA>
5512 _LIBCPP_INLINE_VISIBILITY
5514 format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt,
5515 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5516 {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
5517 template <class _ST, class _SA>
5518 _LIBCPP_INLINE_VISIBILITY
5519 basic_string<char_type, _ST, _SA>
5520 format(const basic_string<char_type, _ST, _SA>& __fmt,
5521 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5523 basic_string<char_type, _ST, _SA> __r;
5524 format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
5528 _LIBCPP_INLINE_VISIBILITY
5530 format(const char_type* __fmt,
5531 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5534 format(back_inserter(__r), __fmt,
5535 __fmt + char_traits<char_type>::length(__fmt), __flags);
5540 _LIBCPP_INLINE_VISIBILITY
5541 allocator_type get_allocator() const {return __matches_.get_allocator();}
5544 void swap(match_results& __m);
5546 template <class _Bp, class _Ap>
5547 _LIBCPP_INLINE_VISIBILITY
5548 void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
5549 const match_results<_Bp, _Ap>& __m, bool __no_update_pos)
5551 _Bp __mf = __m.prefix().first;
5552 __matches_.resize(__m.size());
5553 for (size_type __i = 0; __i < __matches_.size(); ++__i)
5555 __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first));
5556 __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second));
5557 __matches_[__i].matched = __m[__i].matched;
5559 __unmatched_.first = __l;
5560 __unmatched_.second = __l;
5561 __unmatched_.matched = false;
5562 __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first));
5563 __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second));
5564 __prefix_.matched = __m.prefix().matched;
5565 __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first));
5566 __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second));
5567 __suffix_.matched = __m.suffix().matched;
5568 if (!__no_update_pos)
5569 __position_start_ = __prefix_.first;
5570 __ready_ = __m.ready();
5574 void __init(unsigned __s,
5575 _BidirectionalIterator __f, _BidirectionalIterator __l,
5576 bool __no_update_pos = false);
5578 template <class, class> friend class basic_regex;
5580 template <class _Bp, class _Ap, class _Cp, class _Tp>
5583 regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
5584 regex_constants::match_flag_type);
5586 template <class _Bp, class _Ap>
5589 operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
5591 template <class, class> friend class __lookahead;
5594 template <class _BidirectionalIterator, class _Allocator>
5595 match_results<_BidirectionalIterator, _Allocator>::match_results(
5596 const allocator_type& __a)
5606 template <class _BidirectionalIterator, class _Allocator>
5608 match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
5609 _BidirectionalIterator __f, _BidirectionalIterator __l,
5610 bool __no_update_pos)
5612 __unmatched_.first = __l;
5613 __unmatched_.second = __l;
5614 __unmatched_.matched = false;
5615 __matches_.assign(__s, __unmatched_);
5616 __prefix_.first = __f;
5617 __prefix_.second = __f;
5618 __prefix_.matched = false;
5619 __suffix_ = __unmatched_;
5620 if (!__no_update_pos)
5621 __position_start_ = __prefix_.first;
5625 template <class _BidirectionalIterator, class _Allocator>
5626 template <class _OutputIter>
5628 match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter,
5629 const char_type* __fmt_first, const char_type* __fmt_last,
5630 regex_constants::match_flag_type __flags) const
5632 _LIBCPP_ASSERT(ready(), "match_results::format() called when not ready");
5633 if (__flags & regex_constants::format_sed)
5635 for (; __fmt_first != __fmt_last; ++__fmt_first)
5637 if (*__fmt_first == '&')
5638 __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5640 else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
5643 if ('0' <= *__fmt_first && *__fmt_first <= '9')
5645 size_t __i = *__fmt_first - '0';
5646 __output_iter = _VSTD::copy((*this)[__i].first,
5647 (*this)[__i].second, __output_iter);
5651 *__output_iter = *__fmt_first;
5657 *__output_iter = *__fmt_first;
5664 for (; __fmt_first != __fmt_last; ++__fmt_first)
5666 if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
5668 switch (__fmt_first[1])
5671 *__output_iter = *++__fmt_first;
5676 __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second,
5681 __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter);
5685 __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter);
5688 if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5691 size_t __idx = *__fmt_first - '0';
5692 if (__fmt_first + 1 != __fmt_last &&
5693 '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5696 if (__idx >= numeric_limits<size_t>::max() / 10)
5697 __throw_regex_error<regex_constants::error_escape>();
5698 __idx = 10 * __idx + *__fmt_first - '0';
5700 __output_iter = _VSTD::copy((*this)[__idx].first,
5701 (*this)[__idx].second, __output_iter);
5705 *__output_iter = *__fmt_first;
5713 *__output_iter = *__fmt_first;
5718 return __output_iter;
5721 template <class _BidirectionalIterator, class _Allocator>
5723 match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
5726 swap(__matches_, __m.__matches_);
5727 swap(__unmatched_, __m.__unmatched_);
5728 swap(__prefix_, __m.__prefix_);
5729 swap(__suffix_, __m.__suffix_);
5730 swap(__position_start_, __m.__position_start_);
5731 swap(__ready_, __m.__ready_);
5734 template <class _BidirectionalIterator, class _Allocator>
5736 operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
5737 const match_results<_BidirectionalIterator, _Allocator>& __y)
5739 if (__x.__ready_ != __y.__ready_)
5743 return __x.__matches_ == __y.__matches_ &&
5744 __x.__prefix_ == __y.__prefix_ &&
5745 __x.__suffix_ == __y.__suffix_;
5748 template <class _BidirectionalIterator, class _Allocator>
5749 inline _LIBCPP_INLINE_VISIBILITY
5751 operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
5752 const match_results<_BidirectionalIterator, _Allocator>& __y)
5754 return !(__x == __y);
5757 template <class _BidirectionalIterator, class _Allocator>
5758 inline _LIBCPP_INLINE_VISIBILITY
5760 swap(match_results<_BidirectionalIterator, _Allocator>& __x,
5761 match_results<_BidirectionalIterator, _Allocator>& __y)
5768 template <class _CharT, class _Traits>
5769 template <class _Allocator>
5771 basic_regex<_CharT, _Traits>::__match_at_start_ecma(
5772 const _CharT* __first, const _CharT* __last,
5773 match_results<const _CharT*, _Allocator>& __m,
5774 regex_constants::match_flag_type __flags, bool __at_first) const
5776 vector<__state> __states;
5777 __node* __st = __start_.get();
5780 sub_match<const _CharT*> __unmatched;
5781 __unmatched.first = __last;
5782 __unmatched.second = __last;
5783 __unmatched.matched = false;
5785 __states.push_back(__state());
5786 __states.back().__do_ = 0;
5787 __states.back().__first_ = __first;
5788 __states.back().__current_ = __first;
5789 __states.back().__last_ = __last;
5790 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
5791 __states.back().__loop_data_.resize(__loop_count());
5792 __states.back().__node_ = __st;
5793 __states.back().__flags_ = __flags;
5794 __states.back().__at_first_ = __at_first;
5796 int __length = __last - __first;
5800 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
5801 __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
5802 __throw_regex_error<regex_constants::error_complexity>();
5803 __state& __s = __states.back();
5805 __s.__node_->__exec(__s);
5808 case __state::__end_state:
5809 if ((__flags & regex_constants::match_not_null) &&
5810 __s.__current_ == __first)
5812 __states.pop_back();
5815 if ((__flags & regex_constants::__full_match) &&
5816 __s.__current_ != __last)
5818 __states.pop_back();
5821 __m.__matches_[0].first = __first;
5822 __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
5823 __m.__matches_[0].matched = true;
5824 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
5825 __m.__matches_[__i+1] = __s.__sub_matches_[__i];
5827 case __state::__accept_and_consume:
5828 case __state::__repeat:
5829 case __state::__accept_but_not_consume:
5831 case __state::__split:
5833 __state __snext = __s;
5834 __s.__node_->__exec_split(true, __s);
5835 __snext.__node_->__exec_split(false, __snext);
5836 __states.push_back(_VSTD::move(__snext));
5839 case __state::__reject:
5840 __states.pop_back();
5843 __throw_regex_error<regex_constants::__re_err_unknown>();
5847 } while (!__states.empty());
5852 template <class _CharT, class _Traits>
5853 template <class _Allocator>
5855 basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
5856 const _CharT* __first, const _CharT* __last,
5857 match_results<const _CharT*, _Allocator>& __m,
5858 regex_constants::match_flag_type __flags, bool __at_first) const
5860 deque<__state> __states;
5861 ptrdiff_t __highest_j = 0;
5862 ptrdiff_t _Np = _VSTD::distance(__first, __last);
5863 __node* __st = __start_.get();
5866 __states.push_back(__state());
5867 __states.back().__do_ = 0;
5868 __states.back().__first_ = __first;
5869 __states.back().__current_ = __first;
5870 __states.back().__last_ = __last;
5871 __states.back().__loop_data_.resize(__loop_count());
5872 __states.back().__node_ = __st;
5873 __states.back().__flags_ = __flags;
5874 __states.back().__at_first_ = __at_first;
5875 bool __matched = false;
5877 int __length = __last - __first;
5881 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
5882 __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
5883 __throw_regex_error<regex_constants::error_complexity>();
5884 __state& __s = __states.back();
5886 __s.__node_->__exec(__s);
5889 case __state::__end_state:
5890 if ((__flags & regex_constants::match_not_null) &&
5891 __s.__current_ == __first)
5893 __states.pop_back();
5896 if ((__flags & regex_constants::__full_match) &&
5897 __s.__current_ != __last)
5899 __states.pop_back();
5902 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
5903 __highest_j = __s.__current_ - __s.__first_;
5905 if (__highest_j == _Np)
5908 __states.pop_back();
5910 case __state::__consume_input:
5912 case __state::__accept_and_consume:
5913 __states.push_front(_VSTD::move(__s));
5914 __states.pop_back();
5916 case __state::__repeat:
5917 case __state::__accept_but_not_consume:
5919 case __state::__split:
5921 __state __snext = __s;
5922 __s.__node_->__exec_split(true, __s);
5923 __snext.__node_->__exec_split(false, __snext);
5924 __states.push_back(_VSTD::move(__snext));
5927 case __state::__reject:
5928 __states.pop_back();
5931 __throw_regex_error<regex_constants::__re_err_unknown>();
5934 } while (!__states.empty());
5937 __m.__matches_[0].first = __first;
5938 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
5939 __m.__matches_[0].matched = true;
5946 template <class _CharT, class _Traits>
5947 template <class _Allocator>
5949 basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
5950 const _CharT* __first, const _CharT* __last,
5951 match_results<const _CharT*, _Allocator>& __m,
5952 regex_constants::match_flag_type __flags, bool __at_first) const
5954 vector<__state> __states;
5955 __state __best_state;
5956 ptrdiff_t __highest_j = 0;
5957 ptrdiff_t _Np = _VSTD::distance(__first, __last);
5958 __node* __st = __start_.get();
5961 sub_match<const _CharT*> __unmatched;
5962 __unmatched.first = __last;
5963 __unmatched.second = __last;
5964 __unmatched.matched = false;
5966 __states.push_back(__state());
5967 __states.back().__do_ = 0;
5968 __states.back().__first_ = __first;
5969 __states.back().__current_ = __first;
5970 __states.back().__last_ = __last;
5971 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
5972 __states.back().__loop_data_.resize(__loop_count());
5973 __states.back().__node_ = __st;
5974 __states.back().__flags_ = __flags;
5975 __states.back().__at_first_ = __at_first;
5976 bool __matched = false;
5978 int __length = __last - __first;
5982 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
5983 __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
5984 __throw_regex_error<regex_constants::error_complexity>();
5985 __state& __s = __states.back();
5987 __s.__node_->__exec(__s);
5990 case __state::__end_state:
5991 if ((__flags & regex_constants::match_not_null) &&
5992 __s.__current_ == __first)
5994 __states.pop_back();
5997 if ((__flags & regex_constants::__full_match) &&
5998 __s.__current_ != __last)
6000 __states.pop_back();
6003 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
6005 __highest_j = __s.__current_ - __s.__first_;
6009 if (__highest_j == _Np)
6012 __states.pop_back();
6014 case __state::__accept_and_consume:
6015 case __state::__repeat:
6016 case __state::__accept_but_not_consume:
6018 case __state::__split:
6020 __state __snext = __s;
6021 __s.__node_->__exec_split(true, __s);
6022 __snext.__node_->__exec_split(false, __snext);
6023 __states.push_back(_VSTD::move(__snext));
6026 case __state::__reject:
6027 __states.pop_back();
6030 __throw_regex_error<regex_constants::__re_err_unknown>();
6033 } while (!__states.empty());
6036 __m.__matches_[0].first = __first;
6037 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
6038 __m.__matches_[0].matched = true;
6039 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
6040 __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
6047 template <class _CharT, class _Traits>
6048 template <class _Allocator>
6050 basic_regex<_CharT, _Traits>::__match_at_start(
6051 const _CharT* __first, const _CharT* __last,
6052 match_results<const _CharT*, _Allocator>& __m,
6053 regex_constants::match_flag_type __flags, bool __at_first) const
6055 if (__get_grammar(__flags_) == ECMAScript)
6056 return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
6057 if (mark_count() == 0)
6058 return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
6059 return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
6062 template <class _CharT, class _Traits>
6063 template <class _Allocator>
6065 basic_regex<_CharT, _Traits>::__search(
6066 const _CharT* __first, const _CharT* __last,
6067 match_results<const _CharT*, _Allocator>& __m,
6068 regex_constants::match_flag_type __flags) const
6070 if (__flags & regex_constants::match_prev_avail)
6071 __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow);
6073 __m.__init(1 + mark_count(), __first, __last,
6074 __flags & regex_constants::__no_update_pos);
6075 if (__match_at_start(__first, __last, __m, __flags,
6076 !(__flags & regex_constants::__no_update_pos)))
6078 __m.__prefix_.second = __m[0].first;
6079 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
6080 __m.__suffix_.first = __m[0].second;
6081 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
6084 if (__first != __last && !(__flags & regex_constants::match_continuous))
6086 __flags |= regex_constants::match_prev_avail;
6087 for (++__first; __first != __last; ++__first)
6089 __m.__matches_.assign(__m.size(), __m.__unmatched_);
6090 if (__match_at_start(__first, __last, __m, __flags, false))
6092 __m.__prefix_.second = __m[0].first;
6093 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
6094 __m.__suffix_.first = __m[0].second;
6095 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
6098 __m.__matches_.assign(__m.size(), __m.__unmatched_);
6101 __m.__matches_.clear();
6105 template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
6106 inline _LIBCPP_INLINE_VISIBILITY
6108 regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
6109 match_results<_BidirectionalIterator, _Allocator>& __m,
6110 const basic_regex<_CharT, _Traits>& __e,
6111 regex_constants::match_flag_type __flags = regex_constants::match_default)
6113 int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
6114 basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last);
6115 match_results<const _CharT*> __mc;
6116 bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
6117 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
6121 template <class _Iter, class _Allocator, class _CharT, class _Traits>
6122 inline _LIBCPP_INLINE_VISIBILITY
6124 regex_search(__wrap_iter<_Iter> __first,
6125 __wrap_iter<_Iter> __last,
6126 match_results<__wrap_iter<_Iter>, _Allocator>& __m,
6127 const basic_regex<_CharT, _Traits>& __e,
6128 regex_constants::match_flag_type __flags = regex_constants::match_default)
6130 match_results<const _CharT*> __mc;
6131 bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
6132 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
6136 template <class _Allocator, class _CharT, class _Traits>
6137 inline _LIBCPP_INLINE_VISIBILITY
6139 regex_search(const _CharT* __first, const _CharT* __last,
6140 match_results<const _CharT*, _Allocator>& __m,
6141 const basic_regex<_CharT, _Traits>& __e,
6142 regex_constants::match_flag_type __flags = regex_constants::match_default)
6144 return __e.__search(__first, __last, __m, __flags);
6147 template <class _BidirectionalIterator, class _CharT, class _Traits>
6148 inline _LIBCPP_INLINE_VISIBILITY
6150 regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
6151 const basic_regex<_CharT, _Traits>& __e,
6152 regex_constants::match_flag_type __flags = regex_constants::match_default)
6154 basic_string<_CharT> __s(__first, __last);
6155 match_results<const _CharT*> __mc;
6156 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
6159 template <class _CharT, class _Traits>
6160 inline _LIBCPP_INLINE_VISIBILITY
6162 regex_search(const _CharT* __first, const _CharT* __last,
6163 const basic_regex<_CharT, _Traits>& __e,
6164 regex_constants::match_flag_type __flags = regex_constants::match_default)
6166 match_results<const _CharT*> __mc;
6167 return __e.__search(__first, __last, __mc, __flags);
6170 template <class _CharT, class _Allocator, class _Traits>
6171 inline _LIBCPP_INLINE_VISIBILITY
6173 regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
6174 const basic_regex<_CharT, _Traits>& __e,
6175 regex_constants::match_flag_type __flags = regex_constants::match_default)
6177 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
6180 template <class _CharT, class _Traits>
6181 inline _LIBCPP_INLINE_VISIBILITY
6183 regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
6184 regex_constants::match_flag_type __flags = regex_constants::match_default)
6186 match_results<const _CharT*> __m;
6187 return _VSTD::regex_search(__str, __m, __e, __flags);
6190 template <class _ST, class _SA, class _CharT, class _Traits>
6191 inline _LIBCPP_INLINE_VISIBILITY
6193 regex_search(const basic_string<_CharT, _ST, _SA>& __s,
6194 const basic_regex<_CharT, _Traits>& __e,
6195 regex_constants::match_flag_type __flags = regex_constants::match_default)
6197 match_results<const _CharT*> __mc;
6198 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
6201 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
6202 inline _LIBCPP_INLINE_VISIBILITY
6204 regex_search(const basic_string<_CharT, _ST, _SA>& __s,
6205 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
6206 const basic_regex<_CharT, _Traits>& __e,
6207 regex_constants::match_flag_type __flags = regex_constants::match_default)
6209 match_results<const _CharT*> __mc;
6210 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
6211 __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
6215 #if _LIBCPP_STD_VER > 11
6216 template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
6218 regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
6219 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
6220 const basic_regex<_Cp, _Tp>& __e,
6221 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
6226 template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
6228 regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
6229 match_results<_BidirectionalIterator, _Allocator>& __m,
6230 const basic_regex<_CharT, _Traits>& __e,
6231 regex_constants::match_flag_type __flags = regex_constants::match_default)
6233 bool __r = _VSTD::regex_search(
6234 __first, __last, __m, __e,
6235 __flags | regex_constants::match_continuous |
6236 regex_constants::__full_match);
6239 __r = !__m.suffix().matched;
6241 __m.__matches_.clear();
6246 template <class _BidirectionalIterator, class _CharT, class _Traits>
6247 inline _LIBCPP_INLINE_VISIBILITY
6249 regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
6250 const basic_regex<_CharT, _Traits>& __e,
6251 regex_constants::match_flag_type __flags = regex_constants::match_default)
6253 match_results<_BidirectionalIterator> __m;
6254 return _VSTD::regex_match(__first, __last, __m, __e, __flags);
6257 template <class _CharT, class _Allocator, class _Traits>
6258 inline _LIBCPP_INLINE_VISIBILITY
6260 regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
6261 const basic_regex<_CharT, _Traits>& __e,
6262 regex_constants::match_flag_type __flags = regex_constants::match_default)
6264 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
6267 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
6268 inline _LIBCPP_INLINE_VISIBILITY
6270 regex_match(const basic_string<_CharT, _ST, _SA>& __s,
6271 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
6272 const basic_regex<_CharT, _Traits>& __e,
6273 regex_constants::match_flag_type __flags = regex_constants::match_default)
6275 return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
6278 #if _LIBCPP_STD_VER > 11
6279 template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
6280 inline _LIBCPP_INLINE_VISIBILITY
6282 regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
6283 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
6284 const basic_regex<_CharT, _Traits>& __e,
6285 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
6288 template <class _CharT, class _Traits>
6289 inline _LIBCPP_INLINE_VISIBILITY
6291 regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
6292 regex_constants::match_flag_type __flags = regex_constants::match_default)
6294 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
6297 template <class _ST, class _SA, class _CharT, class _Traits>
6298 inline _LIBCPP_INLINE_VISIBILITY
6300 regex_match(const basic_string<_CharT, _ST, _SA>& __s,
6301 const basic_regex<_CharT, _Traits>& __e,
6302 regex_constants::match_flag_type __flags = regex_constants::match_default)
6304 return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags);
6309 template <class _BidirectionalIterator,
6310 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6311 class _Traits = regex_traits<_CharT> >
6312 class _LIBCPP_TEMPLATE_VIS regex_iterator;
6314 typedef regex_iterator<const char*> cregex_iterator;
6315 typedef regex_iterator<string::const_iterator> sregex_iterator;
6316 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
6317 typedef regex_iterator<const wchar_t*> wcregex_iterator;
6318 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
6321 template <class _BidirectionalIterator, class _CharT, class _Traits>
6323 _LIBCPP_TEMPLATE_VIS
6324 _LIBCPP_PREFERRED_NAME(cregex_iterator)
6325 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator))
6326 _LIBCPP_PREFERRED_NAME(sregex_iterator)
6327 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator))
6331 typedef basic_regex<_CharT, _Traits> regex_type;
6332 typedef match_results<_BidirectionalIterator> value_type;
6333 typedef ptrdiff_t difference_type;
6334 typedef const value_type* pointer;
6335 typedef const value_type& reference;
6336 typedef forward_iterator_tag iterator_category;
6339 _BidirectionalIterator __begin_;
6340 _BidirectionalIterator __end_;
6341 const regex_type* __pregex_;
6342 regex_constants::match_flag_type __flags_;
6343 value_type __match_;
6347 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6348 const regex_type& __re,
6349 regex_constants::match_flag_type __m
6350 = regex_constants::match_default);
6351 #if _LIBCPP_STD_VER > 11
6352 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6353 const regex_type&& __re,
6354 regex_constants::match_flag_type __m
6355 = regex_constants::match_default) = delete;
6358 bool operator==(const regex_iterator& __x) const;
6359 _LIBCPP_INLINE_VISIBILITY
6360 bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
6362 _LIBCPP_INLINE_VISIBILITY
6363 reference operator*() const {return __match_;}
6364 _LIBCPP_INLINE_VISIBILITY
6365 pointer operator->() const {return _VSTD::addressof(__match_);}
6367 regex_iterator& operator++();
6368 _LIBCPP_INLINE_VISIBILITY
6369 regex_iterator operator++(int)
6371 regex_iterator __t(*this);
6377 template <class _BidirectionalIterator, class _CharT, class _Traits>
6378 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
6379 : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
6383 template <class _BidirectionalIterator, class _CharT, class _Traits>
6384 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6385 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6386 const regex_type& __re, regex_constants::match_flag_type __m)
6389 __pregex_(_VSTD::addressof(__re)),
6392 _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
6395 template <class _BidirectionalIterator, class _CharT, class _Traits>
6397 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6398 operator==(const regex_iterator& __x) const
6400 if (__match_.empty() && __x.__match_.empty())
6402 if (__match_.empty() || __x.__match_.empty())
6404 return __begin_ == __x.__begin_ &&
6405 __end_ == __x.__end_ &&
6406 __pregex_ == __x.__pregex_ &&
6407 __flags_ == __x.__flags_ &&
6408 __match_[0] == __x.__match_[0];
6411 template <class _BidirectionalIterator, class _CharT, class _Traits>
6412 regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
6413 regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6415 __flags_ |= regex_constants::__no_update_pos;
6416 _BidirectionalIterator __start = __match_[0].second;
6417 if (__match_[0].first == __match_[0].second)
6419 if (__start == __end_)
6421 __match_ = value_type();
6424 else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_,
6425 __flags_ | regex_constants::match_not_null |
6426 regex_constants::match_continuous))
6431 __flags_ |= regex_constants::match_prev_avail;
6432 if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
6433 __match_ = value_type();
6437 // regex_token_iterator
6439 template <class _BidirectionalIterator,
6440 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6441 class _Traits = regex_traits<_CharT> >
6442 class _LIBCPP_TEMPLATE_VIS regex_token_iterator;
6444 typedef regex_token_iterator<const char*> cregex_token_iterator;
6445 typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
6446 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
6447 typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
6448 typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
6451 template <class _BidirectionalIterator, class _CharT, class _Traits>
6453 _LIBCPP_TEMPLATE_VIS
6454 _LIBCPP_PREFERRED_NAME(cregex_token_iterator)
6455 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator))
6456 _LIBCPP_PREFERRED_NAME(sregex_token_iterator)
6457 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator))
6458 regex_token_iterator
6461 typedef basic_regex<_CharT, _Traits> regex_type;
6462 typedef sub_match<_BidirectionalIterator> value_type;
6463 typedef ptrdiff_t difference_type;
6464 typedef const value_type* pointer;
6465 typedef const value_type& reference;
6466 typedef forward_iterator_tag iterator_category;
6469 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
6471 _Position __position_;
6472 const value_type* __result_;
6473 value_type __suffix_;
6475 vector<int> __subs_;
6478 regex_token_iterator();
6479 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6480 const regex_type& __re, int __submatch = 0,
6481 regex_constants::match_flag_type __m =
6482 regex_constants::match_default);
6483 #if _LIBCPP_STD_VER > 11
6484 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6485 const regex_type&& __re, int __submatch = 0,
6486 regex_constants::match_flag_type __m =
6487 regex_constants::match_default) = delete;
6490 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6491 const regex_type& __re, const vector<int>& __submatches,
6492 regex_constants::match_flag_type __m =
6493 regex_constants::match_default);
6494 #if _LIBCPP_STD_VER > 11
6495 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6496 const regex_type&& __re, const vector<int>& __submatches,
6497 regex_constants::match_flag_type __m =
6498 regex_constants::match_default) = delete;
6501 #ifndef _LIBCPP_CXX03_LANG
6502 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6503 const regex_type& __re,
6504 initializer_list<int> __submatches,
6505 regex_constants::match_flag_type __m =
6506 regex_constants::match_default);
6508 #if _LIBCPP_STD_VER > 11
6509 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6510 const regex_type&& __re,
6511 initializer_list<int> __submatches,
6512 regex_constants::match_flag_type __m =
6513 regex_constants::match_default) = delete;
6515 #endif // _LIBCPP_CXX03_LANG
6516 template <size_t _Np>
6517 regex_token_iterator(_BidirectionalIterator __a,
6518 _BidirectionalIterator __b,
6519 const regex_type& __re,
6520 const int (&__submatches)[_Np],
6521 regex_constants::match_flag_type __m =
6522 regex_constants::match_default);
6523 #if _LIBCPP_STD_VER > 11
6524 template <size_t _Np>
6525 regex_token_iterator(_BidirectionalIterator __a,
6526 _BidirectionalIterator __b,
6527 const regex_type&& __re,
6528 const int (&__submatches)[_Np],
6529 regex_constants::match_flag_type __m =
6530 regex_constants::match_default) = delete;
6533 regex_token_iterator(const regex_token_iterator&);
6534 regex_token_iterator& operator=(const regex_token_iterator&);
6536 bool operator==(const regex_token_iterator& __x) const;
6537 _LIBCPP_INLINE_VISIBILITY
6538 bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
6540 _LIBCPP_INLINE_VISIBILITY
6541 const value_type& operator*() const {return *__result_;}
6542 _LIBCPP_INLINE_VISIBILITY
6543 const value_type* operator->() const {return __result_;}
6545 regex_token_iterator& operator++();
6546 _LIBCPP_INLINE_VISIBILITY
6547 regex_token_iterator operator++(int)
6549 regex_token_iterator __t(*this);
6555 void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
6556 void __establish_result () {
6557 if (__subs_[__n_] == -1)
6558 __result_ = &__position_->prefix();
6560 __result_ = &(*__position_)[__subs_[__n_]];
6564 template <class _BidirectionalIterator, class _CharT, class _Traits>
6565 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6566 regex_token_iterator()
6567 : __result_(nullptr),
6573 template <class _BidirectionalIterator, class _CharT, class _Traits>
6575 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6576 __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
6578 if (__position_ != _Position())
6579 __establish_result ();
6580 else if (__subs_[__n_] == -1)
6582 __suffix_.matched = true;
6583 __suffix_.first = __a;
6584 __suffix_.second = __b;
6585 __result_ = &__suffix_;
6588 __result_ = nullptr;
6591 template <class _BidirectionalIterator, class _CharT, class _Traits>
6592 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6593 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6594 const regex_type& __re, int __submatch,
6595 regex_constants::match_flag_type __m)
6596 : __position_(__a, __b, __re, __m),
6598 __subs_(1, __submatch)
6603 template <class _BidirectionalIterator, class _CharT, class _Traits>
6604 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6605 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6606 const regex_type& __re, const vector<int>& __submatches,
6607 regex_constants::match_flag_type __m)
6608 : __position_(__a, __b, __re, __m),
6610 __subs_(__submatches)
6615 #ifndef _LIBCPP_CXX03_LANG
6617 template <class _BidirectionalIterator, class _CharT, class _Traits>
6618 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6619 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6620 const regex_type& __re,
6621 initializer_list<int> __submatches,
6622 regex_constants::match_flag_type __m)
6623 : __position_(__a, __b, __re, __m),
6625 __subs_(__submatches)
6630 #endif // _LIBCPP_CXX03_LANG
6632 template <class _BidirectionalIterator, class _CharT, class _Traits>
6633 template <size_t _Np>
6634 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6635 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6636 const regex_type& __re,
6637 const int (&__submatches)[_Np],
6638 regex_constants::match_flag_type __m)
6639 : __position_(__a, __b, __re, __m),
6641 __subs_(begin(__submatches), end(__submatches))
6646 template <class _BidirectionalIterator, class _CharT, class _Traits>
6647 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6648 regex_token_iterator(const regex_token_iterator& __x)
6649 : __position_(__x.__position_),
6650 __result_(__x.__result_),
6651 __suffix_(__x.__suffix_),
6653 __subs_(__x.__subs_)
6655 if (__x.__result_ == &__x.__suffix_)
6656 __result_ = &__suffix_;
6657 else if ( __result_ != nullptr )
6658 __establish_result ();
6661 template <class _BidirectionalIterator, class _CharT, class _Traits>
6662 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6663 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6664 operator=(const regex_token_iterator& __x)
6668 __position_ = __x.__position_;
6669 if (__x.__result_ == &__x.__suffix_)
6670 __result_ = &__suffix_;
6672 __result_ = __x.__result_;
6673 __suffix_ = __x.__suffix_;
6675 __subs_ = __x.__subs_;
6677 if ( __result_ != nullptr && __result_ != &__suffix_ )
6678 __establish_result();
6683 template <class _BidirectionalIterator, class _CharT, class _Traits>
6685 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6686 operator==(const regex_token_iterator& __x) const
6688 if (__result_ == nullptr && __x.__result_ == nullptr)
6690 if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
6691 __suffix_ == __x.__suffix_)
6693 if (__result_ == nullptr || __x.__result_ == nullptr)
6695 if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
6697 return __position_ == __x.__position_ && __n_ == __x.__n_ &&
6698 __subs_ == __x.__subs_;
6701 template <class _BidirectionalIterator, class _CharT, class _Traits>
6702 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6703 regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6705 _Position __prev = __position_;
6706 if (__result_ == &__suffix_)
6707 __result_ = nullptr;
6708 else if (static_cast<size_t>(__n_ + 1) < __subs_.size())
6711 __establish_result();
6717 if (__position_ != _Position())
6718 __establish_result();
6721 if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
6722 && __prev->suffix().length() != 0)
6724 __suffix_.matched = true;
6725 __suffix_.first = __prev->suffix().first;
6726 __suffix_.second = __prev->suffix().second;
6727 __result_ = &__suffix_;
6730 __result_ = nullptr;
6738 template <class _OutputIterator, class _BidirectionalIterator,
6739 class _Traits, class _CharT>
6741 regex_replace(_OutputIterator __output_iter,
6742 _BidirectionalIterator __first, _BidirectionalIterator __last,
6743 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6744 regex_constants::match_flag_type __flags = regex_constants::match_default)
6746 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
6747 _Iter __i(__first, __last, __e, __flags);
6751 if (!(__flags & regex_constants::format_no_copy))
6752 __output_iter = _VSTD::copy(__first, __last, __output_iter);
6756 sub_match<_BidirectionalIterator> __lm;
6757 for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
6759 if (!(__flags & regex_constants::format_no_copy))
6760 __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter);
6761 __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags);
6762 __lm = __i->suffix();
6763 if (__flags & regex_constants::format_first_only)
6766 if (!(__flags & regex_constants::format_no_copy))
6767 __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter);
6769 return __output_iter;
6772 template <class _OutputIterator, class _BidirectionalIterator,
6773 class _Traits, class _CharT, class _ST, class _SA>
6774 inline _LIBCPP_INLINE_VISIBILITY
6776 regex_replace(_OutputIterator __output_iter,
6777 _BidirectionalIterator __first, _BidirectionalIterator __last,
6778 const basic_regex<_CharT, _Traits>& __e,
6779 const basic_string<_CharT, _ST, _SA>& __fmt,
6780 regex_constants::match_flag_type __flags = regex_constants::match_default)
6782 return _VSTD::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags);
6785 template <class _Traits, class _CharT, class _ST, class _SA, class _FST,
6787 inline _LIBCPP_INLINE_VISIBILITY
6788 basic_string<_CharT, _ST, _SA>
6789 regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6790 const basic_regex<_CharT, _Traits>& __e,
6791 const basic_string<_CharT, _FST, _FSA>& __fmt,
6792 regex_constants::match_flag_type __flags = regex_constants::match_default)
6794 basic_string<_CharT, _ST, _SA> __r;
6795 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6796 __fmt.c_str(), __flags);
6800 template <class _Traits, class _CharT, class _ST, class _SA>
6801 inline _LIBCPP_INLINE_VISIBILITY
6802 basic_string<_CharT, _ST, _SA>
6803 regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6804 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6805 regex_constants::match_flag_type __flags = regex_constants::match_default)
6807 basic_string<_CharT, _ST, _SA> __r;
6808 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
6813 template <class _Traits, class _CharT, class _ST, class _SA>
6814 inline _LIBCPP_INLINE_VISIBILITY
6815 basic_string<_CharT>
6816 regex_replace(const _CharT* __s,
6817 const basic_regex<_CharT, _Traits>& __e,
6818 const basic_string<_CharT, _ST, _SA>& __fmt,
6819 regex_constants::match_flag_type __flags = regex_constants::match_default)
6821 basic_string<_CharT> __r;
6822 _VSTD::regex_replace(back_inserter(__r), __s,
6823 __s + char_traits<_CharT>::length(__s), __e,
6824 __fmt.c_str(), __flags);
6828 template <class _Traits, class _CharT>
6829 inline _LIBCPP_INLINE_VISIBILITY
6830 basic_string<_CharT>
6831 regex_replace(const _CharT* __s,
6832 const basic_regex<_CharT, _Traits>& __e,
6833 const _CharT* __fmt,
6834 regex_constants::match_flag_type __flags = regex_constants::match_default)
6836 basic_string<_CharT> __r;
6837 _VSTD::regex_replace(back_inserter(__r), __s,
6838 __s + char_traits<_CharT>::length(__s), __e,
6843 _LIBCPP_END_NAMESPACE_STD
6847 #endif // _LIBCPP_REGEX