1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
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
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_REGEX
11#define _LIBCPP_REGEX
12
13/*
14 regex synopsis
15
16#include <compare>
17#include <initializer_list>
18
19namespace std
20{
21
22namespace regex_constants
23{
24
25enum syntax_option_type
26{
27 icase = unspecified,
28 nosubs = unspecified,
29 optimize = unspecified,
30 collate = unspecified,
31 ECMAScript = unspecified,
32 basic = unspecified,
33 extended = unspecified,
34 awk = unspecified,
35 grep = unspecified,
36 egrep = unspecified,
37 multiline = unspecified
38};
39
40constexpr syntax_option_type operator~(syntax_option_type f);
41constexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs);
42constexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs);
43
44enum match_flag_type
45{
46 match_default = 0,
47 match_not_bol = unspecified,
48 match_not_eol = unspecified,
49 match_not_bow = unspecified,
50 match_not_eow = unspecified,
51 match_any = unspecified,
52 match_not_null = unspecified,
53 match_continuous = unspecified,
54 match_prev_avail = unspecified,
55 format_default = 0,
56 format_sed = unspecified,
57 format_no_copy = unspecified,
58 format_first_only = unspecified
59};
60
61constexpr match_flag_type operator~(match_flag_type f);
62constexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs);
63constexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs);
64
65enum error_type
66{
67 error_collate = unspecified,
68 error_ctype = unspecified,
69 error_escape = unspecified,
70 error_backref = unspecified,
71 error_brack = unspecified,
72 error_paren = unspecified,
73 error_brace = unspecified,
74 error_badbrace = unspecified,
75 error_range = unspecified,
76 error_space = unspecified,
77 error_badrepeat = unspecified,
78 error_complexity = unspecified,
79 error_stack = unspecified
80};
81
82} // regex_constants
83
84class regex_error
85 : public runtime_error
86{
87public:
88 explicit regex_error(regex_constants::error_type ecode);
89 regex_constants::error_type code() const;
90};
91
92template <class charT>
93struct regex_traits
94{
95public:
96 typedef charT char_type;
97 typedef basic_string<char_type> string_type;
98 typedef locale locale_type;
99 typedef /bitmask_type/ char_class_type;
100
101 regex_traits();
102
103 static size_t length(const char_type* p);
104 charT translate(charT c) const;
105 charT translate_nocase(charT c) const;
106 template <class ForwardIterator>
107 string_type
108 transform(ForwardIterator first, ForwardIterator last) const;
109 template <class ForwardIterator>
110 string_type
111 transform_primary( ForwardIterator first, ForwardIterator last) const;
112 template <class ForwardIterator>
113 string_type
114 lookup_collatename(ForwardIterator first, ForwardIterator last) const;
115 template <class ForwardIterator>
116 char_class_type
117 lookup_classname(ForwardIterator first, ForwardIterator last,
118 bool icase = false) const;
119 bool isctype(charT c, char_class_type f) const;
120 int value(charT ch, int radix) const;
121 locale_type imbue(locale_type l);
122 locale_type getloc()const;
123};
124
125template <class charT, class traits = regex_traits<charT>>
126class basic_regex
127{
128public:
129 // types:
130 typedef charT value_type;
131 typedef traits traits_type;
132 typedef typename traits::string_type string_type;
133 typedef regex_constants::syntax_option_type flag_type;
134 typedef typename traits::locale_type locale_type;
135
136 // constants:
137 static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
138 static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
139 static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
140 static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
141 static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
142 static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
143 static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
144 static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
145 static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
146 static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
147 static constexpr regex_constants::syntax_option_type multiline = regex_constants::multiline;
148
149 // construct/copy/destroy:
150 basic_regex();
151 explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
152 basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
153 basic_regex(const basic_regex&);
154 basic_regex(basic_regex&&) noexcept;
155 template <class ST, class SA>
156 explicit basic_regex(const basic_string<charT, ST, SA>& p,
157 flag_type f = regex_constants::ECMAScript);
158 template <class ForwardIterator>
159 basic_regex(ForwardIterator first, ForwardIterator last,
160 flag_type f = regex_constants::ECMAScript);
161 basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
162
163 ~basic_regex();
164
165 basic_regex& operator=(const basic_regex&);
166 basic_regex& operator=(basic_regex&&) noexcept;
167 basic_regex& operator=(const charT* ptr);
168 basic_regex& operator=(initializer_list<charT> il);
169 template <class ST, class SA>
170 basic_regex& operator=(const basic_string<charT, ST, SA>& p);
171
172 // assign:
173 basic_regex& assign(const basic_regex& that);
174 basic_regex& assign(basic_regex&& that) noexcept;
175 basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
176 basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
177 template <class string_traits, class A>
178 basic_regex& assign(const basic_string<charT, string_traits, A>& s,
179 flag_type f = regex_constants::ECMAScript);
180 template <class InputIterator>
181 basic_regex& assign(InputIterator first, InputIterator last,
182 flag_type f = regex_constants::ECMAScript);
183 basic_regex& assign(initializer_list<charT>, flag_type f = regex_constants::ECMAScript);
184
185 // const operations:
186 unsigned mark_count() const;
187 flag_type flags() const;
188
189 // locale:
190 locale_type imbue(locale_type loc);
191 locale_type getloc() const;
192
193 // swap:
194 void swap(basic_regex&);
195};
196
197template<class ForwardIterator>
198basic_regex(ForwardIterator, ForwardIterator,
199 regex_constants::syntax_option_type = regex_constants::ECMAScript)
200 -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; // C++17
201
202typedef basic_regex<char> regex;
203typedef basic_regex<wchar_t> wregex;
204
205template <class charT, class traits>
206 void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
207
208template <class BidirectionalIterator>
209class sub_match
210 : public pair<BidirectionalIterator, BidirectionalIterator>
211{
212public:
213 typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
214 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
215 typedef BidirectionalIterator iterator;
216 typedef basic_string<value_type> string_type;
217
218 bool matched;
219
220 constexpr sub_match();
221
222 difference_type length() const;
223 operator string_type() const;
224 string_type str() const;
225
226 int compare(const sub_match& s) const;
227 int compare(const string_type& s) const;
228 int compare(const value_type* s) const;
229
230 void swap(sub_match& s) noexcept(see below);
231};
232
233typedef sub_match<const char*> csub_match;
234typedef sub_match<const wchar_t*> wcsub_match;
235typedef sub_match<string::const_iterator> ssub_match;
236typedef sub_match<wstring::const_iterator> wssub_match;
237
238template <class BiIter>
239 bool
240 operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
241
242template <class BiIter>
243 auto
244 operator<=>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); // Since C++20
245
246 template <class BiIter> // Removed in C++20
247 bool
248 operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
249
250template <class BiIter> // Removed in C++20
251 bool
252 operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
253
254template <class BiIter> // Removed in C++20
255 bool
256 operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
257
258template <class BiIter> // Removed in C++20
259 bool
260 operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
261
262template <class BiIter> // Removed in C++20
263 bool
264 operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
265
266template <class BiIter, class ST, class SA> // Removed in C++20
267 bool
268 operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
269 const sub_match<BiIter>& rhs);
270
271template <class BiIter, class ST, class SA> // Removed in C++20
272 bool
273 operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
274 const sub_match<BiIter>& rhs);
275
276template <class BiIter, class ST, class SA> // Removed in C++20
277 bool
278 operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
279 const sub_match<BiIter>& rhs);
280
281template <class BiIter, class ST, class SA> // Removed in C++20
282 bool
283 operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
284 const sub_match<BiIter>& rhs);
285
286template <class BiIter, class ST, class SA> // Removed in C++20
287 bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
288 const sub_match<BiIter>& rhs);
289
290template <class BiIter, class ST, class SA> // Removed in C++20
291 bool
292 operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
293 const sub_match<BiIter>& rhs);
294
295template <class BiIter, class ST, class SA>
296 bool
297 operator==(const sub_match<BiIter>& lhs,
298 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
299
300template <class BiIter, class ST, class SA> // Since C++20
301 auto
302 operator<=>(const sub_match<BiIter>& lhs,
303 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
304
305template <class BiIter, class ST, class SA> // Removed in C++20
306 bool
307 operator!=(const sub_match<BiIter>& lhs,
308 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
309
310template <class BiIter, class ST, class SA> // Removed in C++20
311 bool
312 operator<(const sub_match<BiIter>& lhs,
313 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
314
315template <class BiIter, class ST, class SA> // Removed in C++20
316 bool
317 operator>(const sub_match<BiIter>& lhs,
318 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
319
320template <class BiIter, class ST, class SA> // Removed in C++20
321 bool
322 operator>=(const sub_match<BiIter>& lhs,
323 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
324
325template <class BiIter, class ST, class SA> // Removed in C++20
326 bool
327 operator<=(const sub_match<BiIter>& lhs,
328 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
329
330template <class BiIter> // Removed in C++20
331 bool
332 operator==(typename iterator_traits<BiIter>::value_type const* lhs,
333 const sub_match<BiIter>& rhs);
334
335template <class BiIter> // Removed in C++20
336 bool
337 operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
338 const sub_match<BiIter>& rhs);
339
340template <class BiIter> // Removed in C++20
341 bool
342 operator<(typename iterator_traits<BiIter>::value_type const* lhs,
343 const sub_match<BiIter>& rhs);
344
345template <class BiIter> // Removed in C++20
346 bool
347 operator>(typename iterator_traits<BiIter>::value_type const* lhs,
348 const sub_match<BiIter>& rhs);
349
350template <class BiIter> // Removed in C++20
351 bool
352 operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
353 const sub_match<BiIter>& rhs);
354
355template <class BiIter> // Removed in C++20
356 bool
357 operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
358 const sub_match<BiIter>& rhs);
359
360template <class BiIter>
361 bool
362 operator==(const sub_match<BiIter>& lhs,
363 typename iterator_traits<BiIter>::value_type const* rhs);
364
365template <class BiIter> // Since C++20
366 auto
367 operator<=>(const sub_match<BiIter>& lhs,
368 typename iterator_traits<BiIter>::value_type const* rhs);
369
370template <class BiIter, class ST, class SA> // Removed in C++20
371 bool
372 operator!=(const sub_match<BiIter>& lhs,
373 typename iterator_traits<BiIter>::value_type const* rhs);
374
375template <class BiIter> // Removed in C++20
376 bool
377 operator<(const sub_match<BiIter>& lhs,
378 typename iterator_traits<BiIter>::value_type const* rhs);
379
380template <class BiIter> // Removed in C++20
381 bool
382 operator>(const sub_match<BiIter>& lhs,
383 typename iterator_traits<BiIter>::value_type const* rhs);
384
385template <class BiIter> // Removed in C++20
386 bool
387 operator>=(const sub_match<BiIter>& lhs,
388 typename iterator_traits<BiIter>::value_type const* rhs);
389
390template <class BiIter> // Removed in C++20
391 bool
392 operator<=(const sub_match<BiIter>& lhs,
393 typename iterator_traits<BiIter>::value_type const* rhs);
394
395template <class BiIter> // Removed in C++20
396 bool
397 operator==(typename iterator_traits<BiIter>::value_type const& lhs,
398 const sub_match<BiIter>& rhs);
399
400template <class BiIter> // Removed in C++20
401 bool
402 operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
403 const sub_match<BiIter>& rhs);
404
405template <class BiIter> // Removed in C++20
406 bool
407 operator<(typename iterator_traits<BiIter>::value_type const& lhs,
408 const sub_match<BiIter>& rhs);
409
410template <class BiIter> // Removed in C++20
411 bool
412 operator>(typename iterator_traits<BiIter>::value_type const& lhs,
413 const sub_match<BiIter>& rhs);
414
415template <class BiIter> // Removed in C++20
416 bool
417 operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
418 const sub_match<BiIter>& rhs);
419
420template <class BiIter> // Removed in C++20
421 bool
422 operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
423 const sub_match<BiIter>& rhs);
424
425template <class BiIter>
426 bool
427 operator==(const sub_match<BiIter>& lhs,
428 typename iterator_traits<BiIter>::value_type const& rhs);
429
430template <class BiIter> // Since C++20
431 auto
432 operator<=>(const sub_match<BiIter>& lhs,
433 typename iterator_traits<BiIter>::value_type const& rhs);
434
435template <class BiIter> // Removed in C++20
436 bool
437 operator!=(const sub_match<BiIter>& lhs,
438 typename iterator_traits<BiIter>::value_type const& rhs);
439
440template <class BiIter> // Removed in C++20
441 bool
442 operator<(const sub_match<BiIter>& lhs,
443 typename iterator_traits<BiIter>::value_type const& rhs);
444
445template <class BiIter> // Removed in C++20
446 bool
447 operator>(const sub_match<BiIter>& lhs,
448 typename iterator_traits<BiIter>::value_type const& rhs);
449
450template <class BiIter> // Removed in C++20
451 bool
452 operator>=(const sub_match<BiIter>& lhs,
453 typename iterator_traits<BiIter>::value_type const& rhs);
454
455template <class BiIter> // Removed in C++20
456 bool
457 operator<=(const sub_match<BiIter>& lhs,
458 typename iterator_traits<BiIter>::value_type const& rhs);
459
460template <class charT, class ST, class BiIter>
461 basic_ostream<charT, ST>&
462 operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
463
464template <class BidirectionalIterator,
465 class Allocator = allocator<sub_match<BidirectionalIterator>>>
466class match_results
467{
468public:
469 typedef sub_match<BidirectionalIterator> value_type;
470 typedef const value_type& const_reference;
471 typedef value_type& reference;
472 typedef /implementation-defined/ const_iterator;
473 typedef const_iterator iterator;
474 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
475 typedef typename allocator_traits<Allocator>::size_type size_type;
476 typedef Allocator allocator_type;
477 typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
478 typedef basic_string<char_type> string_type;
479
480 // construct/copy/destroy:
481 explicit match_results(const Allocator& a = Allocator()); // before C++20
482 match_results() : match_results(Allocator()) {} // C++20
483 explicit match_results(const Allocator& a); // C++20
484 match_results(const match_results& m);
485 match_results(match_results&& m) noexcept;
486 match_results& operator=(const match_results& m);
487 match_results& operator=(match_results&& m);
488 ~match_results();
489
490 bool ready() const;
491
492 // size:
493 size_type size() const;
494 size_type max_size() const;
495 bool empty() const;
496
497 // element access:
498 difference_type length(size_type sub = 0) const;
499 difference_type position(size_type sub = 0) const;
500 string_type str(size_type sub = 0) const;
501 const_reference operator[](size_type n) const;
502
503 const_reference prefix() const;
504 const_reference suffix() const;
505
506 const_iterator begin() const;
507 const_iterator end() const;
508 const_iterator cbegin() const;
509 const_iterator cend() const;
510
511 // format:
512 template <class OutputIter>
513 OutputIter
514 format(OutputIter out, const char_type* fmt_first,
515 const char_type* fmt_last,
516 regex_constants::match_flag_type flags = regex_constants::format_default) const;
517 template <class OutputIter, class ST, class SA>
518 OutputIter
519 format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
520 regex_constants::match_flag_type flags = regex_constants::format_default) const;
521 template <class ST, class SA>
522 basic_string<char_type, ST, SA>
523 format(const basic_string<char_type, ST, SA>& fmt,
524 regex_constants::match_flag_type flags = regex_constants::format_default) const;
525 string_type
526 format(const char_type* fmt,
527 regex_constants::match_flag_type flags = regex_constants::format_default) const;
528
529 // allocator:
530 allocator_type get_allocator() const;
531
532 // swap:
533 void swap(match_results& that);
534};
535
536typedef match_results<const char*> cmatch;
537typedef match_results<const wchar_t*> wcmatch;
538typedef match_results<string::const_iterator> smatch;
539typedef match_results<wstring::const_iterator> wsmatch;
540
541template <class BidirectionalIterator, class Allocator>
542 bool
543 operator==(const match_results<BidirectionalIterator, Allocator>& m1,
544 const match_results<BidirectionalIterator, Allocator>& m2);
545
546template <class BidirectionalIterator, class Allocator> // Removed in C++20
547 bool
548 operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
549 const match_results<BidirectionalIterator, Allocator>& m2);
550
551template <class BidirectionalIterator, class Allocator>
552 void
553 swap(match_results<BidirectionalIterator, Allocator>& m1,
554 match_results<BidirectionalIterator, Allocator>& m2);
555
556template <class BidirectionalIterator, class Allocator, class charT, class traits>
557 bool
558 regex_match(BidirectionalIterator first, BidirectionalIterator last,
559 match_results<BidirectionalIterator, Allocator>& m,
560 const basic_regex<charT, traits>& e,
561 regex_constants::match_flag_type flags = regex_constants::match_default);
562
563template <class BidirectionalIterator, class charT, class traits>
564 bool
565 regex_match(BidirectionalIterator first, BidirectionalIterator last,
566 const basic_regex<charT, traits>& e,
567 regex_constants::match_flag_type flags = regex_constants::match_default);
568
569template <class charT, class Allocator, class traits>
570 bool
571 regex_match(const charT* str, match_results<const charT*, Allocator>& m,
572 const basic_regex<charT, traits>& e,
573 regex_constants::match_flag_type flags = regex_constants::match_default);
574
575template <class ST, class SA, class Allocator, class charT, class traits>
576 bool
577 regex_match(const basic_string<charT, ST, SA>& s,
578 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
579 const basic_regex<charT, traits>& e,
580 regex_constants::match_flag_type flags = regex_constants::match_default);
581
582template <class ST, class SA, class Allocator, class charT, class traits>
583 bool
584 regex_match(const basic_string<charT, ST, SA>&& s,
585 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
586 const basic_regex<charT, traits>& e,
587 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
588
589template <class charT, class traits>
590 bool
591 regex_match(const charT* str, const basic_regex<charT, traits>& e,
592 regex_constants::match_flag_type flags = regex_constants::match_default);
593
594template <class ST, class SA, class charT, class traits>
595 bool
596 regex_match(const basic_string<charT, ST, SA>& s,
597 const basic_regex<charT, traits>& e,
598 regex_constants::match_flag_type flags = regex_constants::match_default);
599
600template <class BidirectionalIterator, class Allocator, class charT, class traits>
601 bool
602 regex_search(BidirectionalIterator first, BidirectionalIterator last,
603 match_results<BidirectionalIterator, Allocator>& m,
604 const basic_regex<charT, traits>& e,
605 regex_constants::match_flag_type flags = regex_constants::match_default);
606
607template <class BidirectionalIterator, class charT, class traits>
608 bool
609 regex_search(BidirectionalIterator first, BidirectionalIterator last,
610 const basic_regex<charT, traits>& e,
611 regex_constants::match_flag_type flags = regex_constants::match_default);
612
613template <class charT, class Allocator, class traits>
614 bool
615 regex_search(const charT* str, match_results<const charT*, Allocator>& m,
616 const basic_regex<charT, traits>& e,
617 regex_constants::match_flag_type flags = regex_constants::match_default);
618
619template <class charT, class traits>
620 bool
621 regex_search(const charT* str, const basic_regex<charT, traits>& e,
622 regex_constants::match_flag_type flags = regex_constants::match_default);
623
624template <class ST, class SA, class charT, class traits>
625 bool
626 regex_search(const basic_string<charT, ST, SA>& s,
627 const basic_regex<charT, traits>& e,
628 regex_constants::match_flag_type flags = regex_constants::match_default);
629
630template <class ST, class SA, class Allocator, class charT, class traits>
631 bool
632 regex_search(const basic_string<charT, ST, SA>& s,
633 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
634 const basic_regex<charT, traits>& e,
635 regex_constants::match_flag_type flags = regex_constants::match_default);
636
637template <class ST, class SA, class Allocator, class charT, class traits>
638 bool
639 regex_search(const basic_string<charT, ST, SA>&& s,
640 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
641 const basic_regex<charT, traits>& e,
642 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
643
644template <class OutputIterator, class BidirectionalIterator,
645 class traits, class charT, class ST, class SA>
646 OutputIterator
647 regex_replace(OutputIterator out,
648 BidirectionalIterator first, BidirectionalIterator last,
649 const basic_regex<charT, traits>& e,
650 const basic_string<charT, ST, SA>& fmt,
651 regex_constants::match_flag_type flags = regex_constants::match_default);
652
653template <class OutputIterator, class BidirectionalIterator,
654 class traits, class charT>
655 OutputIterator
656 regex_replace(OutputIterator out,
657 BidirectionalIterator first, BidirectionalIterator last,
658 const basic_regex<charT, traits>& e, const charT* fmt,
659 regex_constants::match_flag_type flags = regex_constants::match_default);
660
661template <class traits, class charT, class ST, class SA, class FST, class FSA>
662 basic_string<charT, ST, SA>
663 regex_replace(const basic_string<charT, ST, SA>& s,
664 const basic_regex<charT, traits>& e,
665 const basic_string<charT, FST, FSA>& fmt,
666 regex_constants::match_flag_type flags = regex_constants::match_default);
667
668template <class traits, class charT, class ST, class SA>
669 basic_string<charT, ST, SA>
670 regex_replace(const basic_string<charT, ST, SA>& s,
671 const basic_regex<charT, traits>& e, const charT* fmt,
672 regex_constants::match_flag_type flags = regex_constants::match_default);
673
674template <class traits, class charT, class ST, class SA>
675 basic_string<charT>
676 regex_replace(const charT* s,
677 const basic_regex<charT, traits>& e,
678 const basic_string<charT, ST, SA>& fmt,
679 regex_constants::match_flag_type flags = regex_constants::match_default);
680
681template <class traits, class charT>
682 basic_string<charT>
683 regex_replace(const charT* s,
684 const basic_regex<charT, traits>& e,
685 const charT* fmt,
686 regex_constants::match_flag_type flags = regex_constants::match_default);
687
688template <class BidirectionalIterator,
689 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
690 class traits = regex_traits<charT>>
691class regex_iterator
692{
693public:
694 typedef basic_regex<charT, traits> regex_type;
695 typedef match_results<BidirectionalIterator> value_type;
696 typedef ptrdiff_t difference_type;
697 typedef const value_type* pointer;
698 typedef const value_type& reference;
699 typedef forward_iterator_tag iterator_category;
700 typedef input_iterator_tag iterator_concept; // since C++20
701
702 regex_iterator();
703 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
704 const regex_type& re,
705 regex_constants::match_flag_type m = regex_constants::match_default);
706 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
707 const regex_type&& re,
708 regex_constants::match_flag_type m
709 = regex_constants::match_default) = delete; // C++14
710 regex_iterator(const regex_iterator&);
711 regex_iterator& operator=(const regex_iterator&);
712
713 bool operator==(const regex_iterator&) const;
714 bool operator==(default_sentinel_t) const { return *this == regex_iterator(); } // since C++20
715 bool operator!=(const regex_iterator&) const; // Removed in C++20
716
717 const value_type& operator*() const;
718 const value_type* operator->() const;
719
720 regex_iterator& operator++();
721 regex_iterator operator++(int);
722};
723
724typedef regex_iterator<const char*> cregex_iterator;
725typedef regex_iterator<const wchar_t*> wcregex_iterator;
726typedef regex_iterator<string::const_iterator> sregex_iterator;
727typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
728
729template <class BidirectionalIterator,
730 class charT = typename iterator_traits<BidirectionalIterator>::value_type,
731 class traits = regex_traits<charT>>
732class regex_token_iterator
733{
734public:
735 typedef basic_regex<charT, traits> regex_type;
736 typedef sub_match<BidirectionalIterator> value_type;
737 typedef ptrdiff_t difference_type;
738 typedef const value_type* pointer;
739 typedef const value_type& reference;
740 typedef forward_iterator_tag iterator_category;
741 typedef input_iterator_tag iterator_concept; // since C++20
742
743 regex_token_iterator();
744 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
745 const regex_type& re, int submatch = 0,
746 regex_constants::match_flag_type m = regex_constants::match_default);
747 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
748 const regex_type&& re, int submatch = 0,
749 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
750 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
751 const regex_type& re, const vector<int>& submatches,
752 regex_constants::match_flag_type m = regex_constants::match_default);
753 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
754 const regex_type&& re, const vector<int>& submatches,
755 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
756 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
757 const regex_type& re, initializer_list<int> submatches,
758 regex_constants::match_flag_type m = regex_constants::match_default);
759 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
760 const regex_type&& re, initializer_list<int> submatches,
761 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
762 template <size_t N>
763 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
764 const regex_type& re, const int (&submatches)[N],
765 regex_constants::match_flag_type m = regex_constants::match_default);
766 template <size_t N>
767 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
768 const regex_type&& re, const int (&submatches)[N],
769 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
770 regex_token_iterator(const regex_token_iterator&);
771 regex_token_iterator& operator=(const regex_token_iterator&);
772
773 bool operator==(const regex_token_iterator&) const;
774 bool operator==(default_sentinel_t) const { return *this == regex_token_iterator(); } // since C++20
775 bool operator!=(const regex_token_iterator&) const; // Removed in C++20
776
777 const value_type& operator*() const;
778 const value_type* operator->() const;
779
780 regex_token_iterator& operator++();
781 regex_token_iterator operator++(int);
782};
783
784typedef regex_token_iterator<const char*> cregex_token_iterator;
785typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
786typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
787typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
788
789} // std
790*/
791
792#if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
793# include <__cxx03/regex>
794#else
795# include <__config>
796
797// standard-mandated includes
798
799// [iterator.range]
800# include <__iterator/access.h>
801# include <__iterator/data.h>
802# include <__iterator/empty.h>
803# include <__iterator/reverse_access.h>
804# include <__iterator/size.h>
805
806// [re.syn]
807# include <compare>
808# include <initializer_list>
809
810# if _LIBCPP_HAS_LOCALIZATION
811
812# include <__algorithm/find.h>
813# include <__algorithm/search.h>
814# include <__assert>
815# include <__iterator/back_insert_iterator.h>
816# include <__iterator/default_sentinel.h>
817# include <__iterator/wrap_iter.h>
818# include <__locale>
819# include <__memory/addressof.h>
820# include <__memory/pointer_traits.h>
821# include <__memory/shared_ptr.h>
822# include <__memory_resource/polymorphic_allocator.h>
823# include <__type_traits/is_swappable.h>
824# include <__utility/move.h>
825# include <__utility/pair.h>
826# include <__utility/swap.h>
827# include <__verbose_abort>
828# include <deque>
829# include <stdexcept>
830# include <string>
831# include <vector>
832# include <version>
833
834# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
835# pragma GCC system_header
836# endif
837
838_LIBCPP_PUSH_MACROS
839# include <__undef_macros>
840
841# define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
842
843_LIBCPP_BEGIN_NAMESPACE_STD
844
845namespace regex_constants {
846
847// syntax_option_type
848
849enum syntax_option_type {
850 icase = 1 << 0,
851 nosubs = 1 << 1,
852 optimize = 1 << 2,
853 collate = 1 << 3,
854# ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
855 ECMAScript = 1 << 9,
856# else
857 ECMAScript = 0,
858# endif
859 basic = 1 << 4,
860 extended = 1 << 5,
861 awk = 1 << 6,
862 grep = 1 << 7,
863 egrep = 1 << 8,
864 // 1 << 9 may be used by ECMAScript
865 multiline = 1 << 10
866};
867
868_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR syntax_option_type __get_grammar(syntax_option_type __g) {
869# ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
870 return static_cast<syntax_option_type>(__g & 0x3F0);
871# else
872 return static_cast<syntax_option_type>(__g & 0x1F0);
873# endif
874}
875
876inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type operator~(syntax_option_type __x) {
877 return syntax_option_type(~int(__x) & 0x1FF);
878}
879
880inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type
881operator&(syntax_option_type __x, syntax_option_type __y) {
882 return syntax_option_type(int(__x) & int(__y));
883}
884
885inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type
886operator|(syntax_option_type __x, syntax_option_type __y) {
887 return syntax_option_type(int(__x) | int(__y));
888}
889
890inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type
891operator^(syntax_option_type __x, syntax_option_type __y) {
892 return syntax_option_type(int(__x) ^ int(__y));
893}
894
895inline _LIBCPP_HIDE_FROM_ABI syntax_option_type& operator&=(syntax_option_type& __x, syntax_option_type __y) {
896 __x = __x & __y;
897 return __x;
898}
899
900inline _LIBCPP_HIDE_FROM_ABI syntax_option_type& operator|=(syntax_option_type& __x, syntax_option_type __y) {
901 __x = __x | __y;
902 return __x;
903}
904
905inline _LIBCPP_HIDE_FROM_ABI syntax_option_type& operator^=(syntax_option_type& __x, syntax_option_type __y) {
906 __x = __x ^ __y;
907 return __x;
908}
909
910// match_flag_type
911
912enum match_flag_type {
913 match_default = 0,
914 match_not_bol = 1 << 0,
915 match_not_eol = 1 << 1,
916 match_not_bow = 1 << 2,
917 match_not_eow = 1 << 3,
918 match_any = 1 << 4,
919 match_not_null = 1 << 5,
920 match_continuous = 1 << 6,
921 match_prev_avail = 1 << 7,
922 format_default = 0,
923 format_sed = 1 << 8,
924 format_no_copy = 1 << 9,
925 format_first_only = 1 << 10,
926 __no_update_pos = 1 << 11,
927 __full_match = 1 << 12
928};
929
930inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator~(match_flag_type __x) {
931 return match_flag_type(~int(__x) & 0x0FFF);
932}
933
934inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator&(match_flag_type __x, match_flag_type __y) {
935 return match_flag_type(int(__x) & int(__y));
936}
937
938inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator|(match_flag_type __x, match_flag_type __y) {
939 return match_flag_type(int(__x) | int(__y));
940}
941
942inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator^(match_flag_type __x, match_flag_type __y) {
943 return match_flag_type(int(__x) ^ int(__y));
944}
945
946inline _LIBCPP_HIDE_FROM_ABI match_flag_type& operator&=(match_flag_type& __x, match_flag_type __y) {
947 __x = __x & __y;
948 return __x;
949}
950
951inline _LIBCPP_HIDE_FROM_ABI match_flag_type& operator|=(match_flag_type& __x, match_flag_type __y) {
952 __x = __x | __y;
953 return __x;
954}
955
956inline _LIBCPP_HIDE_FROM_ABI match_flag_type& operator^=(match_flag_type& __x, match_flag_type __y) {
957 __x = __x ^ __y;
958 return __x;
959}
960
961enum error_type {
962 error_collate = 1,
963 error_ctype,
964 error_escape,
965 error_backref,
966 error_brack,
967 error_paren,
968 error_brace,
969 error_badbrace,
970 error_range,
971 error_space,
972 error_badrepeat,
973 error_complexity,
974 error_stack,
975 __re_err_grammar,
976 __re_err_empty,
977 __re_err_unknown,
978 __re_err_parse
979};
980
981} // namespace regex_constants
982
983class _LIBCPP_EXPORTED_FROM_ABI regex_error : public runtime_error {
984 regex_constants::error_type __code_;
985
986public:
987 explicit regex_error(regex_constants::error_type __ecode);
988 _LIBCPP_HIDE_FROM_ABI regex_error(const regex_error&) _NOEXCEPT = default;
989 ~regex_error() _NOEXCEPT override;
990 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI regex_constants::error_type code() const { return __code_; }
991};
992
993template <regex_constants::error_type _Ev>
994[[__noreturn__]] inline _LIBCPP_HIDE_FROM_ABI void __throw_regex_error() {
995# if _LIBCPP_HAS_EXCEPTIONS
996 throw regex_error(_Ev);
997# else
998 _LIBCPP_VERBOSE_ABORT("regex_error was thrown in -fno-exceptions mode");
999# endif
1000}
1001
1002template <class _CharT>
1003struct regex_traits {
1004public:
1005 typedef _CharT char_type;
1006 typedef basic_string<char_type> string_type;
1007 typedef locale locale_type;
1008# if defined(__BIONIC__) || _LIBCPP_LIBC_NEWLIB
1009 // Originally bionic's ctype_base used its own ctype masks because the
1010 // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask
1011 // was only 8 bits wide and already saturated, so it used a wider type here
1012 // to make room for __regex_word (then a part of this class rather than
1013 // ctype_base). Bionic has since moved to the builtin ctype_base
1014 // implementation, but this was not updated to match. Since then Android has
1015 // needed to maintain a stable libc++ ABI, and this can't be changed without
1016 // an ABI break.
1017 // We also need this workaround for newlib since newlib is
1018 // often used for space constrained environments, so it makes sense not to
1019 // duplicate the ctype table.
1020 typedef uint16_t char_class_type;
1021# else
1022 typedef ctype_base::mask char_class_type;
1023# endif
1024
1025 static const char_class_type __regex_word = ctype_base::__regex_word;
1026
1027private:
1028 locale __loc_;
1029 const ctype<char_type>* __ct_;
1030 const collate<char_type>* __col_;
1031
1032public:
1033 regex_traits();
1034
1035 _LIBCPP_HIDE_FROM_ABI static size_t length(const char_type* __p) { return char_traits<char_type>::length(__p); }
1036 _LIBCPP_HIDE_FROM_ABI char_type translate(char_type __c) const { return __c; }
1037 char_type translate_nocase(char_type __c) const;
1038 template <class _ForwardIterator>
1039 string_type transform(_ForwardIterator __f, _ForwardIterator __l) const;
1040 template <class _ForwardIterator>
1041 _LIBCPP_HIDE_FROM_ABI string_type transform_primary(_ForwardIterator __f, _ForwardIterator __l) const {
1042 return __transform_primary(__f, __l, char_type());
1043 }
1044 template <class _ForwardIterator>
1045 _LIBCPP_HIDE_FROM_ABI string_type lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const {
1046 return __lookup_collatename(__f, __l, char_type());
1047 }
1048 template <class _ForwardIterator>
1049 _LIBCPP_HIDE_FROM_ABI char_class_type
1050 lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase = false) const {
1051 return __lookup_classname(__f, __l, __icase, char_type());
1052 }
1053 bool isctype(char_type __c, char_class_type __m) const;
1054 _LIBCPP_HIDE_FROM_ABI int value(char_type __ch, int __radix) const { return __regex_traits_value(__ch, __radix); }
1055 locale_type imbue(locale_type __l);
1056 _LIBCPP_HIDE_FROM_ABI locale_type getloc() const { return __loc_; }
1057
1058private:
1059 void __init();
1060
1061 template <class _ForwardIterator>
1062 string_type __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
1063# if _LIBCPP_HAS_WIDE_CHARACTERS
1064 template <class _ForwardIterator>
1065 string_type __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1066# endif
1067 template <class _ForwardIterator>
1068 string_type __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
1069# if _LIBCPP_HAS_WIDE_CHARACTERS
1070 template <class _ForwardIterator>
1071 string_type __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1072# endif
1073 template <class _ForwardIterator>
1074 char_class_type __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, char) const;
1075# if _LIBCPP_HAS_WIDE_CHARACTERS
1076 template <class _ForwardIterator>
1077 char_class_type __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, wchar_t) const;
1078# endif
1079
1080 static int __regex_traits_value(unsigned char __ch, int __radix);
1081 _LIBCPP_HIDE_FROM_ABI int __regex_traits_value(char __ch, int __radix) const {
1082 return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);
1083 }
1084# if _LIBCPP_HAS_WIDE_CHARACTERS
1085 _LIBCPP_HIDE_FROM_ABI int __regex_traits_value(wchar_t __ch, int __radix) const;
1086# endif
1087};
1088
1089template <class _CharT>
1090const typename regex_traits<_CharT>::char_class_type regex_traits<_CharT>::__regex_word;
1091
1092template <class _CharT>
1093regex_traits<_CharT>::regex_traits() {
1094 __init();
1095}
1096
1097template <class _CharT>
1098typename regex_traits<_CharT>::char_type regex_traits<_CharT>::translate_nocase(char_type __c) const {
1099 return __ct_->tolower(__c);
1100}
1101
1102template <class _CharT>
1103template <class _ForwardIterator>
1104typename regex_traits<_CharT>::string_type
1105regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const {
1106 string_type __s(__f, __l);
1107 return __col_->transform(__s.data(), __s.data() + __s.size());
1108}
1109
1110template <class _CharT>
1111void regex_traits<_CharT>::__init() {
1112 __ct_ = std::addressof(std::use_facet<ctype<char_type> >(__loc_));
1113 __col_ = std::addressof(std::use_facet<collate<char_type> >(__loc_));
1114}
1115
1116template <class _CharT>
1117typename regex_traits<_CharT>::locale_type regex_traits<_CharT>::imbue(locale_type __l) {
1118 locale __r = __loc_;
1119 __loc_ = __l;
1120 __init();
1121 return __r;
1122}
1123
1124// transform_primary is very FreeBSD-specific
1125
1126template <class _CharT>
1127template <class _ForwardIterator>
1128typename regex_traits<_CharT>::string_type
1129regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const {
1130 const string_type __s(__f, __l);
1131 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1132 switch (__d.size()) {
1133 case 1:
1134 break;
1135 case 12:
1136 __d[11] = __d[3];
1137 break;
1138 default:
1139 __d.clear();
1140 break;
1141 }
1142 return __d;
1143}
1144
1145# if _LIBCPP_HAS_WIDE_CHARACTERS
1146template <class _CharT>
1147template <class _ForwardIterator>
1148typename regex_traits<_CharT>::string_type
1149regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const {
1150 const string_type __s(__f, __l);
1151 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1152 switch (__d.size()) {
1153 case 1:
1154 break;
1155 case 3:
1156 __d[2] = __d[0];
1157 break;
1158 default:
1159 __d.clear();
1160 break;
1161 }
1162 return __d;
1163}
1164# endif
1165
1166// lookup_collatename is very FreeBSD-specific
1167
1168_LIBCPP_EXPORTED_FROM_ABI string __get_collation_name(const char* __s);
1169
1170template <class _CharT>
1171template <class _ForwardIterator>
1172typename regex_traits<_CharT>::string_type
1173regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const {
1174 string_type __s(__f, __l);
1175 string_type __r;
1176 if (!__s.empty()) {
1177 __r = std::__get_collation_name(s: __s.c_str());
1178 if (__r.empty() && __s.size() <= 2) {
1179 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1180 if (__r.size() == 1 || __r.size() == 12)
1181 __r = __s;
1182 else
1183 __r.clear();
1184 }
1185 }
1186 return __r;
1187}
1188
1189# if _LIBCPP_HAS_WIDE_CHARACTERS
1190template <class _CharT>
1191template <class _ForwardIterator>
1192typename regex_traits<_CharT>::string_type
1193regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const {
1194 string_type __s(__f, __l);
1195 string __n;
1196 __n.reserve(requested_capacity: __s.size());
1197 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); __i != __e; ++__i) {
1198 if (static_cast<unsigned>(*__i) >= 127)
1199 return string_type();
1200 __n.push_back(c: char(*__i));
1201 }
1202 string_type __r;
1203 if (!__s.empty()) {
1204 __n = __get_collation_name(s: __n.c_str());
1205 if (!__n.empty())
1206 __r.assign(__n.begin(), __n.end());
1207 else if (__s.size() <= 2) {
1208 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1209 if (__r.size() == 1 || __r.size() == 3)
1210 __r = __s;
1211 else
1212 __r.clear();
1213 }
1214 }
1215 return __r;
1216}
1217# endif // _LIBCPP_HAS_WIDE_CHARACTERS
1218
1219// lookup_classname
1220
1221regex_traits<char>::char_class_type _LIBCPP_EXPORTED_FROM_ABI __get_classname(const char* __s, bool __icase);
1222
1223template <class _CharT>
1224template <class _ForwardIterator>
1225typename regex_traits<_CharT>::char_class_type
1226regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, char) const {
1227 string_type __s(__f, __l);
1228 __ct_->tolower(std::addressof(__s[0]), std::addressof(__s[0]) + __s.size());
1229 return std::__get_classname(s: __s.c_str(), __icase);
1230}
1231
1232# if _LIBCPP_HAS_WIDE_CHARACTERS
1233template <class _CharT>
1234template <class _ForwardIterator>
1235typename regex_traits<_CharT>::char_class_type
1236regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, wchar_t) const {
1237 string_type __s(__f, __l);
1238 __ct_->tolower(std::addressof(__s[0]), std::addressof(__s[0]) + __s.size());
1239 string __n;
1240 __n.reserve(requested_capacity: __s.size());
1241 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); __i != __e; ++__i) {
1242 if (static_cast<unsigned>(*__i) >= 127)
1243 return char_class_type();
1244 __n.push_back(c: char(*__i));
1245 }
1246 return __get_classname(s: __n.c_str(), __icase);
1247}
1248# endif // _LIBCPP_HAS_WIDE_CHARACTERS
1249
1250template <class _CharT>
1251bool regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const {
1252 if (__ct_->is(__m, __c))
1253 return true;
1254 return (__c == '_' && (__m & __regex_word));
1255}
1256
1257inline _LIBCPP_HIDE_FROM_ABI bool __is_07(unsigned char __c) {
1258 return (__c & 0xF8u) ==
1259# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1260 0xF0;
1261# else
1262 0x30;
1263# endif
1264}
1265
1266inline _LIBCPP_HIDE_FROM_ABI bool __is_89(unsigned char __c) {
1267 return (__c & 0xFEu) ==
1268# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1269 0xF8;
1270# else
1271 0x38;
1272# endif
1273}
1274
1275inline _LIBCPP_HIDE_FROM_ABI unsigned char __to_lower(unsigned char __c) {
1276# if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1277 return __c & 0xBF;
1278# else
1279 return __c | 0x20;
1280# endif
1281}
1282
1283template <class _CharT>
1284int regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) {
1285 if (__is_07(c: __ch)) // '0' <= __ch && __ch <= '7'
1286 return __ch - '0';
1287 if (__radix != 8) {
1288 if (__is_89(c: __ch)) // '8' <= __ch && __ch <= '9'
1289 return __ch - '0';
1290 if (__radix == 16) {
1291 __ch = __to_lower(c: __ch); // tolower
1292 if ('a' <= __ch && __ch <= 'f')
1293 return __ch - ('a' - 10);
1294 }
1295 }
1296 return -1;
1297}
1298
1299# if _LIBCPP_HAS_WIDE_CHARACTERS
1300template <class _CharT>
1301inline int regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const {
1302 return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
1303}
1304# endif
1305
1306template <class _CharT>
1307class __node;
1308
1309template <class _BidirectionalIterator>
1310class sub_match;
1311
1312template <class _BidirectionalIterator, class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
1313class match_results;
1314
1315template <class _CharT>
1316struct __state {
1317 enum {
1318 __end_state = -1000,
1319 __consume_input, // -999
1320 __begin_marked_expr, // -998
1321 __end_marked_expr, // -997
1322 __pop_state, // -996
1323 __accept_and_consume, // -995
1324 __accept_but_not_consume, // -994
1325 __reject, // -993
1326 __split,
1327 __repeat
1328 };
1329
1330 int __do_;
1331 const _CharT* __first_;
1332 const _CharT* __current_;
1333 const _CharT* __last_;
1334 vector<sub_match<const _CharT*> > __sub_matches_;
1335 vector<pair<size_t, const _CharT*> > __loop_data_;
1336 const __node<_CharT>* __node_;
1337 regex_constants::match_flag_type __flags_;
1338 bool __at_first_;
1339
1340 _LIBCPP_HIDE_FROM_ABI __state()
1341 : __do_(0),
1342 __first_(nullptr),
1343 __current_(nullptr),
1344 __last_(nullptr),
1345 __node_(nullptr),
1346 __flags_(),
1347 __at_first_(false) {}
1348};
1349
1350// __node
1351
1352template <class _CharT>
1353class __node {
1354public:
1355 typedef std::__state<_CharT> __state;
1356
1357 _LIBCPP_HIDE_FROM_ABI __node() {}
1358 __node(const __node&) = delete;
1359 __node& operator=(const __node&) = delete;
1360 _LIBCPP_HIDE_FROM_ABI_VIRTUAL
1361 virtual ~__node() {}
1362
1363 _LIBCPP_HIDE_FROM_ABI_VIRTUAL
1364 virtual void __exec(__state&) const {}
1365 _LIBCPP_HIDE_FROM_ABI_VIRTUAL
1366 virtual void __exec_split(bool, __state&) const {}
1367};
1368
1369// __end_state
1370
1371template <class _CharT>
1372class __end_state : public __node<_CharT> {
1373public:
1374 typedef std::__state<_CharT> __state;
1375
1376 _LIBCPP_HIDE_FROM_ABI __end_state() {}
1377
1378 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1379};
1380
1381template <class _CharT>
1382void __end_state<_CharT>::__exec(__state& __s) const {
1383 __s.__do_ = __state::__end_state;
1384}
1385
1386// __has_one_state
1387
1388template <class _CharT>
1389class __has_one_state : public __node<_CharT> {
1390 __node<_CharT>* __first_;
1391
1392public:
1393 _LIBCPP_HIDE_FROM_ABI explicit __has_one_state(__node<_CharT>* __s) : __first_(__s) {}
1394
1395 _LIBCPP_HIDE_FROM_ABI __node<_CharT>* first() const { return __first_; }
1396 _LIBCPP_HIDE_FROM_ABI __node<_CharT>*& first() { return __first_; }
1397};
1398
1399// __owns_one_state
1400
1401template <class _CharT>
1402class __owns_one_state : public __has_one_state<_CharT> {
1403 typedef __has_one_state<_CharT> base;
1404
1405public:
1406 _LIBCPP_HIDE_FROM_ABI explicit __owns_one_state(__node<_CharT>* __s) : base(__s) {}
1407
1408 ~__owns_one_state() override;
1409};
1410
1411template <class _CharT>
1412__owns_one_state<_CharT>::~__owns_one_state() {
1413 delete this->first();
1414}
1415
1416// __empty_state
1417
1418template <class _CharT>
1419class __empty_state : public __owns_one_state<_CharT> {
1420 typedef __owns_one_state<_CharT> base;
1421
1422public:
1423 typedef std::__state<_CharT> __state;
1424
1425 _LIBCPP_HIDE_FROM_ABI explicit __empty_state(__node<_CharT>* __s) : base(__s) {}
1426
1427 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1428};
1429
1430template <class _CharT>
1431void __empty_state<_CharT>::__exec(__state& __s) const {
1432 __s.__do_ = __state::__accept_but_not_consume;
1433 __s.__node_ = this->first();
1434}
1435
1436// __empty_non_own_state
1437
1438template <class _CharT>
1439class __empty_non_own_state : public __has_one_state<_CharT> {
1440 typedef __has_one_state<_CharT> base;
1441
1442public:
1443 typedef std::__state<_CharT> __state;
1444
1445 _LIBCPP_HIDE_FROM_ABI explicit __empty_non_own_state(__node<_CharT>* __s) : base(__s) {}
1446
1447 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1448};
1449
1450template <class _CharT>
1451void __empty_non_own_state<_CharT>::__exec(__state& __s) const {
1452 __s.__do_ = __state::__accept_but_not_consume;
1453 __s.__node_ = this->first();
1454}
1455
1456// __repeat_one_loop
1457
1458template <class _CharT>
1459class __repeat_one_loop : public __has_one_state<_CharT> {
1460 typedef __has_one_state<_CharT> base;
1461
1462public:
1463 typedef std::__state<_CharT> __state;
1464
1465 _LIBCPP_HIDE_FROM_ABI explicit __repeat_one_loop(__node<_CharT>* __s) : base(__s) {}
1466
1467 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1468};
1469
1470template <class _CharT>
1471void __repeat_one_loop<_CharT>::__exec(__state& __s) const {
1472 __s.__do_ = __state::__repeat;
1473 __s.__node_ = this->first();
1474}
1475
1476// __owns_two_states
1477
1478template <class _CharT>
1479class __owns_two_states : public __owns_one_state<_CharT> {
1480 typedef __owns_one_state<_CharT> base;
1481
1482 base* __second_;
1483
1484public:
1485 _LIBCPP_HIDE_FROM_ABI explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) : base(__s1), __second_(__s2) {}
1486
1487 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual ~__owns_two_states();
1488
1489 _LIBCPP_HIDE_FROM_ABI base* second() const { return __second_; }
1490 _LIBCPP_HIDE_FROM_ABI base*& second() { return __second_; }
1491};
1492
1493template <class _CharT>
1494__owns_two_states<_CharT>::~__owns_two_states() {
1495 delete __second_;
1496}
1497
1498// __loop
1499
1500template <class _CharT>
1501class __loop : public __owns_two_states<_CharT> {
1502 typedef __owns_two_states<_CharT> base;
1503
1504 size_t __min_;
1505 size_t __max_;
1506 unsigned __loop_id_;
1507 unsigned __mexp_begin_;
1508 unsigned __mexp_end_;
1509 bool __greedy_;
1510
1511public:
1512 typedef std::__state<_CharT> __state;
1513
1514 _LIBCPP_HIDE_FROM_ABI explicit __loop(
1515 unsigned __loop_id,
1516 __node<_CharT>* __s1,
1517 __owns_one_state<_CharT>* __s2,
1518 unsigned __mexp_begin,
1519 unsigned __mexp_end,
1520 bool __greedy = true,
1521 size_t __min = 0,
1522 size_t __max = numeric_limits<size_t>::max())
1523 : base(__s1, __s2),
1524 __min_(__min),
1525 __max_(__max),
1526 __loop_id_(__loop_id),
1527 __mexp_begin_(__mexp_begin),
1528 __mexp_end_(__mexp_end),
1529 __greedy_(__greedy) {}
1530
1531 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state& __s) const;
1532 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec_split(bool __second, __state& __s) const;
1533
1534private:
1535 _LIBCPP_HIDE_FROM_ABI void __init_repeat(__state& __s) const {
1536 __s.__loop_data_[__loop_id_].second = __s.__current_;
1537 for (size_t __i = __mexp_begin_ - 1; __i != __mexp_end_ - 1; ++__i) {
1538 __s.__sub_matches_[__i].first = __s.__last_;
1539 __s.__sub_matches_[__i].second = __s.__last_;
1540 __s.__sub_matches_[__i].matched = false;
1541 }
1542 }
1543};
1544
1545template <class _CharT>
1546void __loop<_CharT>::__exec(__state& __s) const {
1547 if (__s.__do_ == __state::__repeat) {
1548 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1549 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1550 if (__do_repeat && __do_alt && __s.__loop_data_[__loop_id_].second == __s.__current_)
1551 __do_repeat = false;
1552 if (__do_repeat && __do_alt)
1553 __s.__do_ = __state::__split;
1554 else if (__do_repeat) {
1555 __s.__do_ = __state::__accept_but_not_consume;
1556 __s.__node_ = this->first();
1557 __init_repeat(__s);
1558 } else {
1559 __s.__do_ = __state::__accept_but_not_consume;
1560 __s.__node_ = this->second();
1561 }
1562 } else {
1563 __s.__loop_data_[__loop_id_].first = 0;
1564 bool __do_repeat = 0 < __max_;
1565 bool __do_alt = 0 >= __min_;
1566 if (__do_repeat && __do_alt)
1567 __s.__do_ = __state::__split;
1568 else if (__do_repeat) {
1569 __s.__do_ = __state::__accept_but_not_consume;
1570 __s.__node_ = this->first();
1571 __init_repeat(__s);
1572 } else {
1573 __s.__do_ = __state::__accept_but_not_consume;
1574 __s.__node_ = this->second();
1575 }
1576 }
1577}
1578
1579template <class _CharT>
1580void __loop<_CharT>::__exec_split(bool __second, __state& __s) const {
1581 __s.__do_ = __state::__accept_but_not_consume;
1582 if (__greedy_ != __second) {
1583 __s.__node_ = this->first();
1584 __init_repeat(__s);
1585 } else
1586 __s.__node_ = this->second();
1587}
1588
1589// __alternate
1590
1591template <class _CharT>
1592class __alternate : public __owns_two_states<_CharT> {
1593 typedef __owns_two_states<_CharT> base;
1594
1595public:
1596 typedef std::__state<_CharT> __state;
1597
1598 _LIBCPP_HIDE_FROM_ABI explicit __alternate(__owns_one_state<_CharT>* __s1, __owns_one_state<_CharT>* __s2)
1599 : base(__s1, __s2) {}
1600
1601 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state& __s) const;
1602 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec_split(bool __second, __state& __s) const;
1603};
1604
1605template <class _CharT>
1606void __alternate<_CharT>::__exec(__state& __s) const {
1607 __s.__do_ = __state::__split;
1608}
1609
1610template <class _CharT>
1611void __alternate<_CharT>::__exec_split(bool __second, __state& __s) const {
1612 __s.__do_ = __state::__accept_but_not_consume;
1613 if (__second)
1614 __s.__node_ = this->second();
1615 else
1616 __s.__node_ = this->first();
1617}
1618
1619// __begin_marked_subexpression
1620
1621template <class _CharT>
1622class __begin_marked_subexpression : public __owns_one_state<_CharT> {
1623 typedef __owns_one_state<_CharT> base;
1624
1625 unsigned __mexp_;
1626
1627public:
1628 typedef std::__state<_CharT> __state;
1629
1630 _LIBCPP_HIDE_FROM_ABI explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1631 : base(__s), __mexp_(__mexp) {}
1632
1633 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1634};
1635
1636template <class _CharT>
1637void __begin_marked_subexpression<_CharT>::__exec(__state& __s) const {
1638 __s.__do_ = __state::__accept_but_not_consume;
1639 __s.__sub_matches_[__mexp_ - 1].first = __s.__current_;
1640 __s.__node_ = this->first();
1641}
1642
1643// __end_marked_subexpression
1644
1645template <class _CharT>
1646class __end_marked_subexpression : public __owns_one_state<_CharT> {
1647 typedef __owns_one_state<_CharT> base;
1648
1649 unsigned __mexp_;
1650
1651public:
1652 typedef std::__state<_CharT> __state;
1653
1654 _LIBCPP_HIDE_FROM_ABI explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
1655 : base(__s), __mexp_(__mexp) {}
1656
1657 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1658};
1659
1660template <class _CharT>
1661void __end_marked_subexpression<_CharT>::__exec(__state& __s) const {
1662 __s.__do_ = __state::__accept_but_not_consume;
1663 __s.__sub_matches_[__mexp_ - 1].second = __s.__current_;
1664 __s.__sub_matches_[__mexp_ - 1].matched = true;
1665 __s.__node_ = this->first();
1666}
1667
1668// __back_ref
1669
1670template <class _CharT>
1671class __back_ref : public __owns_one_state<_CharT> {
1672 typedef __owns_one_state<_CharT> base;
1673
1674 unsigned __mexp_;
1675
1676public:
1677 typedef std::__state<_CharT> __state;
1678
1679 _LIBCPP_HIDE_FROM_ABI explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) : base(__s), __mexp_(__mexp) {}
1680
1681 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1682};
1683
1684template <class _CharT>
1685void __back_ref<_CharT>::__exec(__state& __s) const {
1686 if (__mexp_ > __s.__sub_matches_.size())
1687 std::__throw_regex_error<regex_constants::error_backref>();
1688 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_ - 1];
1689 if (__sm.matched) {
1690 ptrdiff_t __len = __sm.second - __sm.first;
1691 if (__s.__last_ - __s.__current_ >= __len && std::equal(__sm.first, __sm.second, __s.__current_)) {
1692 __s.__do_ = __state::__accept_but_not_consume;
1693 __s.__current_ += __len;
1694 __s.__node_ = this->first();
1695 } else {
1696 __s.__do_ = __state::__reject;
1697 __s.__node_ = nullptr;
1698 }
1699 } else {
1700 __s.__do_ = __state::__reject;
1701 __s.__node_ = nullptr;
1702 }
1703}
1704
1705// __back_ref_icase
1706
1707template <class _CharT, class _Traits>
1708class __back_ref_icase : public __owns_one_state<_CharT> {
1709 typedef __owns_one_state<_CharT> base;
1710
1711 _Traits __traits_;
1712 unsigned __mexp_;
1713
1714public:
1715 typedef std::__state<_CharT> __state;
1716
1717 _LIBCPP_HIDE_FROM_ABI explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, __node<_CharT>* __s)
1718 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1719
1720 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1721};
1722
1723template <class _CharT, class _Traits>
1724void __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const {
1725 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_ - 1];
1726 if (__sm.matched) {
1727 ptrdiff_t __len = __sm.second - __sm.first;
1728 if (__s.__last_ - __s.__current_ >= __len) {
1729 for (ptrdiff_t __i = 0; __i < __len; ++__i) {
1730 if (__traits_.translate_nocase(__sm.first[__i]) != __traits_.translate_nocase(__s.__current_[__i]))
1731 goto __not_equal;
1732 }
1733 __s.__do_ = __state::__accept_but_not_consume;
1734 __s.__current_ += __len;
1735 __s.__node_ = this->first();
1736 } else {
1737 __s.__do_ = __state::__reject;
1738 __s.__node_ = nullptr;
1739 }
1740 } else {
1741 __not_equal:
1742 __s.__do_ = __state::__reject;
1743 __s.__node_ = nullptr;
1744 }
1745}
1746
1747// __back_ref_collate
1748
1749template <class _CharT, class _Traits>
1750class __back_ref_collate : public __owns_one_state<_CharT> {
1751 typedef __owns_one_state<_CharT> base;
1752
1753 _Traits __traits_;
1754 unsigned __mexp_;
1755
1756public:
1757 typedef std::__state<_CharT> __state;
1758
1759 _LIBCPP_HIDE_FROM_ABI explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, __node<_CharT>* __s)
1760 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1761
1762 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1763};
1764
1765template <class _CharT, class _Traits>
1766void __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const {
1767 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_ - 1];
1768 if (__sm.matched) {
1769 ptrdiff_t __len = __sm.second - __sm.first;
1770 if (__s.__last_ - __s.__current_ >= __len) {
1771 for (ptrdiff_t __i = 0; __i < __len; ++__i) {
1772 if (__traits_.translate(__sm.first[__i]) != __traits_.translate(__s.__current_[__i]))
1773 goto __not_equal;
1774 }
1775 __s.__do_ = __state::__accept_but_not_consume;
1776 __s.__current_ += __len;
1777 __s.__node_ = this->first();
1778 } else {
1779 __s.__do_ = __state::__reject;
1780 __s.__node_ = nullptr;
1781 }
1782 } else {
1783 __not_equal:
1784 __s.__do_ = __state::__reject;
1785 __s.__node_ = nullptr;
1786 }
1787}
1788
1789// __word_boundary
1790
1791template <class _CharT, class _Traits>
1792class __word_boundary : public __owns_one_state<_CharT> {
1793 typedef __owns_one_state<_CharT> base;
1794
1795 _Traits __traits_;
1796 bool __invert_;
1797
1798public:
1799 typedef std::__state<_CharT> __state;
1800
1801 _LIBCPP_HIDE_FROM_ABI explicit __word_boundary(const _Traits& __traits, bool __invert, __node<_CharT>* __s)
1802 : base(__s), __traits_(__traits), __invert_(__invert) {}
1803
1804 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1805};
1806
1807template <class _CharT, class _Traits>
1808void __word_boundary<_CharT, _Traits>::__exec(__state& __s) const {
1809 bool __is_word_b = false;
1810 if (__s.__first_ != __s.__last_) {
1811 if (__s.__current_ == __s.__last_) {
1812 if (!(__s.__flags_ & regex_constants::match_not_eow)) {
1813 _CharT __c = __s.__current_[-1];
1814 __is_word_b = __c == '_' || __traits_.isctype(__c, ctype_base::alnum);
1815 }
1816 } else if (__s.__current_ == __s.__first_ && !(__s.__flags_ & regex_constants::match_prev_avail)) {
1817 if (!(__s.__flags_ & regex_constants::match_not_bow)) {
1818 _CharT __c = *__s.__current_;
1819 __is_word_b = __c == '_' || __traits_.isctype(__c, ctype_base::alnum);
1820 }
1821 } else {
1822 _CharT __c1 = __s.__current_[-1];
1823 _CharT __c2 = *__s.__current_;
1824 bool __is_c1_b = __c1 == '_' || __traits_.isctype(__c1, ctype_base::alnum);
1825 bool __is_c2_b = __c2 == '_' || __traits_.isctype(__c2, ctype_base::alnum);
1826 __is_word_b = __is_c1_b != __is_c2_b;
1827 }
1828 }
1829 if (__is_word_b != __invert_) {
1830 __s.__do_ = __state::__accept_but_not_consume;
1831 __s.__node_ = this->first();
1832 } else {
1833 __s.__do_ = __state::__reject;
1834 __s.__node_ = nullptr;
1835 }
1836}
1837
1838// __l_anchor
1839
1840template <class _CharT>
1841_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __is_eol(_CharT __c) {
1842 return __c == '\r' || __c == '\n';
1843}
1844
1845template <class _CharT>
1846class __l_anchor_multiline : public __owns_one_state<_CharT> {
1847 typedef __owns_one_state<_CharT> base;
1848
1849 bool __multiline_;
1850
1851public:
1852 typedef std::__state<_CharT> __state;
1853
1854 _LIBCPP_HIDE_FROM_ABI __l_anchor_multiline(bool __multiline, __node<_CharT>* __s)
1855 : base(__s), __multiline_(__multiline) {}
1856
1857 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1858};
1859
1860template <class _CharT>
1861void __l_anchor_multiline<_CharT>::__exec(__state& __s) const {
1862 if (__s.__at_first_ && __s.__current_ == __s.__first_ && !(__s.__flags_ & regex_constants::match_not_bol)) {
1863 __s.__do_ = __state::__accept_but_not_consume;
1864 __s.__node_ = this->first();
1865 } else if (__multiline_ && !__s.__at_first_ && std::__is_eol(*std::prev(__s.__current_))) {
1866 __s.__do_ = __state::__accept_but_not_consume;
1867 __s.__node_ = this->first();
1868 } else {
1869 __s.__do_ = __state::__reject;
1870 __s.__node_ = nullptr;
1871 }
1872}
1873
1874// __r_anchor
1875
1876template <class _CharT>
1877class __r_anchor_multiline : public __owns_one_state<_CharT> {
1878 typedef __owns_one_state<_CharT> base;
1879
1880 bool __multiline_;
1881
1882public:
1883 typedef std::__state<_CharT> __state;
1884
1885 _LIBCPP_HIDE_FROM_ABI __r_anchor_multiline(bool __multiline, __node<_CharT>* __s)
1886 : base(__s), __multiline_(__multiline) {}
1887
1888 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1889};
1890
1891template <class _CharT>
1892void __r_anchor_multiline<_CharT>::__exec(__state& __s) const {
1893 if (__s.__current_ == __s.__last_ && !(__s.__flags_ & regex_constants::match_not_eol)) {
1894 __s.__do_ = __state::__accept_but_not_consume;
1895 __s.__node_ = this->first();
1896 } else if (__multiline_ && std::__is_eol(*__s.__current_)) {
1897 __s.__do_ = __state::__accept_but_not_consume;
1898 __s.__node_ = this->first();
1899 } else {
1900 __s.__do_ = __state::__reject;
1901 __s.__node_ = nullptr;
1902 }
1903}
1904
1905// __match_any
1906
1907template <class _CharT>
1908class __match_any : public __owns_one_state<_CharT> {
1909 typedef __owns_one_state<_CharT> base;
1910
1911public:
1912 typedef std::__state<_CharT> __state;
1913
1914 _LIBCPP_HIDE_FROM_ABI __match_any(__node<_CharT>* __s) : base(__s) {}
1915
1916 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1917};
1918
1919template <class _CharT>
1920void __match_any<_CharT>::__exec(__state& __s) const {
1921 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) {
1922 __s.__do_ = __state::__accept_and_consume;
1923 ++__s.__current_;
1924 __s.__node_ = this->first();
1925 } else {
1926 __s.__do_ = __state::__reject;
1927 __s.__node_ = nullptr;
1928 }
1929}
1930
1931// __match_any_but_newline
1932
1933template <class _CharT>
1934class __match_any_but_newline : public __owns_one_state<_CharT> {
1935 typedef __owns_one_state<_CharT> base;
1936
1937public:
1938 typedef std::__state<_CharT> __state;
1939
1940 _LIBCPP_HIDE_FROM_ABI __match_any_but_newline(__node<_CharT>* __s) : base(__s) {}
1941
1942 void __exec(__state&) const override;
1943};
1944
1945template <>
1946_LIBCPP_EXPORTED_FROM_ABI void __match_any_but_newline<char>::__exec(__state&) const;
1947# if _LIBCPP_HAS_WIDE_CHARACTERS
1948template <>
1949_LIBCPP_EXPORTED_FROM_ABI void __match_any_but_newline<wchar_t>::__exec(__state&) const;
1950# endif
1951
1952// __match_char
1953
1954template <class _CharT>
1955class __match_char : public __owns_one_state<_CharT> {
1956 typedef __owns_one_state<_CharT> base;
1957
1958 _CharT __c_;
1959
1960public:
1961 typedef std::__state<_CharT> __state;
1962
1963 _LIBCPP_HIDE_FROM_ABI __match_char(_CharT __c, __node<_CharT>* __s) : base(__s), __c_(__c) {}
1964
1965 __match_char(const __match_char&) = delete;
1966 __match_char& operator=(const __match_char&) = delete;
1967
1968 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
1969};
1970
1971template <class _CharT>
1972void __match_char<_CharT>::__exec(__state& __s) const {
1973 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) {
1974 __s.__do_ = __state::__accept_and_consume;
1975 ++__s.__current_;
1976 __s.__node_ = this->first();
1977 } else {
1978 __s.__do_ = __state::__reject;
1979 __s.__node_ = nullptr;
1980 }
1981}
1982
1983// __match_char_icase
1984
1985template <class _CharT, class _Traits>
1986class __match_char_icase : public __owns_one_state<_CharT> {
1987 typedef __owns_one_state<_CharT> base;
1988
1989 _Traits __traits_;
1990 _CharT __c_;
1991
1992public:
1993 typedef std::__state<_CharT> __state;
1994
1995 _LIBCPP_HIDE_FROM_ABI __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
1996 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
1997
1998 __match_char_icase(const __match_char_icase&) = delete;
1999 __match_char_icase& operator=(const __match_char_icase&) = delete;
2000
2001 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
2002};
2003
2004template <class _CharT, class _Traits>
2005void __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const {
2006 if (__s.__current_ != __s.__last_ && __traits_.translate_nocase(*__s.__current_) == __c_) {
2007 __s.__do_ = __state::__accept_and_consume;
2008 ++__s.__current_;
2009 __s.__node_ = this->first();
2010 } else {
2011 __s.__do_ = __state::__reject;
2012 __s.__node_ = nullptr;
2013 }
2014}
2015
2016// __match_char_collate
2017
2018template <class _CharT, class _Traits>
2019class __match_char_collate : public __owns_one_state<_CharT> {
2020 typedef __owns_one_state<_CharT> base;
2021
2022 _Traits __traits_;
2023 _CharT __c_;
2024
2025public:
2026 typedef std::__state<_CharT> __state;
2027
2028 _LIBCPP_HIDE_FROM_ABI __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2029 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2030
2031 __match_char_collate(const __match_char_collate&) = delete;
2032 __match_char_collate& operator=(const __match_char_collate&) = delete;
2033
2034 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
2035};
2036
2037template <class _CharT, class _Traits>
2038void __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const {
2039 if (__s.__current_ != __s.__last_ && __traits_.translate(*__s.__current_) == __c_) {
2040 __s.__do_ = __state::__accept_and_consume;
2041 ++__s.__current_;
2042 __s.__node_ = this->first();
2043 } else {
2044 __s.__do_ = __state::__reject;
2045 __s.__node_ = nullptr;
2046 }
2047}
2048
2049// __bracket_expression
2050
2051template <class _CharT, class _Traits>
2052class __bracket_expression : public __owns_one_state<_CharT> {
2053 typedef __owns_one_state<_CharT> base;
2054 typedef typename _Traits::string_type string_type;
2055
2056 _Traits __traits_;
2057 vector<_CharT> __chars_;
2058 vector<_CharT> __neg_chars_;
2059 vector<pair<string_type, string_type> > __ranges_;
2060 vector<pair<_CharT, _CharT> > __digraphs_;
2061 vector<string_type> __equivalences_;
2062 typename regex_traits<_CharT>::char_class_type __mask_;
2063 typename regex_traits<_CharT>::char_class_type __neg_mask_;
2064 bool __negate_;
2065 bool __icase_;
2066 bool __collate_;
2067 bool __might_have_digraph_;
2068
2069public:
2070 typedef std::__state<_CharT> __state;
2071
2072 _LIBCPP_HIDE_FROM_ABI
2073 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, bool __negate, bool __icase, bool __collate)
2074 : base(__s),
2075 __traits_(__traits),
2076 __mask_(),
2077 __neg_mask_(),
2078 __negate_(__negate),
2079 __icase_(__icase),
2080 __collate_(__collate),
2081 __might_have_digraph_(__traits_.getloc().name() != "C") {}
2082
2083 __bracket_expression(const __bracket_expression&) = delete;
2084 __bracket_expression& operator=(const __bracket_expression&) = delete;
2085
2086 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
2087
2088 _LIBCPP_HIDE_FROM_ABI bool __negated() const { return __negate_; }
2089
2090 _LIBCPP_HIDE_FROM_ABI void __add_char(_CharT __c) {
2091 if (__icase_)
2092 __chars_.push_back(__traits_.translate_nocase(__c));
2093 else if (__collate_)
2094 __chars_.push_back(__traits_.translate(__c));
2095 else
2096 __chars_.push_back(__c);
2097 }
2098 _LIBCPP_HIDE_FROM_ABI void __add_neg_char(_CharT __c) {
2099 if (__icase_)
2100 __neg_chars_.push_back(__traits_.translate_nocase(__c));
2101 else if (__collate_)
2102 __neg_chars_.push_back(__traits_.translate(__c));
2103 else
2104 __neg_chars_.push_back(__c);
2105 }
2106 _LIBCPP_HIDE_FROM_ABI void __add_range(string_type __b, string_type __e) {
2107 if (__collate_) {
2108 if (__icase_) {
2109 for (size_t __i = 0; __i < __b.size(); ++__i)
2110 __b[__i] = __traits_.translate_nocase(__b[__i]);
2111 for (size_t __i = 0; __i < __e.size(); ++__i)
2112 __e[__i] = __traits_.translate_nocase(__e[__i]);
2113 } else {
2114 for (size_t __i = 0; __i < __b.size(); ++__i)
2115 __b[__i] = __traits_.translate(__b[__i]);
2116 for (size_t __i = 0; __i < __e.size(); ++__i)
2117 __e[__i] = __traits_.translate(__e[__i]);
2118 }
2119 __ranges_.push_back(
2120 std::make_pair(__traits_.transform(__b.begin(), __b.end()), __traits_.transform(__e.begin(), __e.end())));
2121 } else {
2122 if (__b.size() != 1 || __e.size() != 1 || char_traits<typename string_type::value_type>::lt(__e[0], __b[0]))
2123 std::__throw_regex_error<regex_constants::error_range>();
2124 if (__icase_) {
2125 __b[0] = __traits_.translate_nocase(__b[0]);
2126 __e[0] = __traits_.translate_nocase(__e[0]);
2127 }
2128 __ranges_.push_back(std::make_pair(std::move(__b), std::move(__e)));
2129 }
2130 }
2131 _LIBCPP_HIDE_FROM_ABI void __add_digraph(_CharT __c1, _CharT __c2) {
2132 if (__icase_)
2133 __digraphs_.push_back(std::make_pair(__traits_.translate_nocase(__c1), __traits_.translate_nocase(__c2)));
2134 else if (__collate_)
2135 __digraphs_.push_back(std::make_pair(__traits_.translate(__c1), __traits_.translate(__c2)));
2136 else
2137 __digraphs_.push_back(std::make_pair(__c1, __c2));
2138 }
2139 _LIBCPP_HIDE_FROM_ABI void __add_equivalence(const string_type& __s) { __equivalences_.push_back(__s); }
2140 _LIBCPP_HIDE_FROM_ABI void __add_class(typename regex_traits<_CharT>::char_class_type __mask) { __mask_ |= __mask; }
2141 _LIBCPP_HIDE_FROM_ABI void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask) {
2142 __neg_mask_ |= __mask;
2143 }
2144};
2145
2146template <class _CharT, class _Traits>
2147void __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const {
2148 bool __found = false;
2149 unsigned __consumed = 0;
2150 if (__s.__current_ != __s.__last_) {
2151 ++__consumed;
2152 if (__might_have_digraph_) {
2153 const _CharT* __next = std::next(__s.__current_);
2154 if (__next != __s.__last_) {
2155 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2156 if (__icase_) {
2157 __ch2.first = __traits_.translate_nocase(__ch2.first);
2158 __ch2.second = __traits_.translate_nocase(__ch2.second);
2159 } else if (__collate_) {
2160 __ch2.first = __traits_.translate(__ch2.first);
2161 __ch2.second = __traits_.translate(__ch2.second);
2162 }
2163 if (!__traits_.lookup_collatename(std::addressof(__ch2.first), std::addressof(__ch2.first) + 2).empty()) {
2164 // __ch2 is a digraph in this locale
2165 ++__consumed;
2166 for (size_t __i = 0; __i < __digraphs_.size(); ++__i) {
2167 if (__ch2 == __digraphs_[__i]) {
2168 __found = true;
2169 goto __exit;
2170 }
2171 }
2172 if (__collate_ && !__ranges_.empty()) {
2173 string_type __s2 = __traits_.transform(std::addressof(__ch2.first), std::addressof(__ch2.first) + 2);
2174 for (size_t __i = 0; __i < __ranges_.size(); ++__i) {
2175 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) {
2176 __found = true;
2177 goto __exit;
2178 }
2179 }
2180 }
2181 if (!__equivalences_.empty()) {
2182 string_type __s2 =
2183 __traits_.transform_primary(std::addressof(__ch2.first), std::addressof(__ch2.first) + 2);
2184 for (size_t __i = 0; __i < __equivalences_.size(); ++__i) {
2185 if (__s2 == __equivalences_[__i]) {
2186 __found = true;
2187 goto __exit;
2188 }
2189 }
2190 }
2191 if (__traits_.isctype(__ch2.first, __mask_) && __traits_.isctype(__ch2.second, __mask_)) {
2192 __found = true;
2193 goto __exit;
2194 }
2195 if (!__traits_.isctype(__ch2.first, __neg_mask_) && !__traits_.isctype(__ch2.second, __neg_mask_)) {
2196 __found = true;
2197 goto __exit;
2198 }
2199 goto __exit;
2200 }
2201 }
2202 }
2203 // test *__s.__current_ as not a digraph
2204 _CharT __ch = *__s.__current_;
2205 if (__icase_)
2206 __ch = __traits_.translate_nocase(__ch);
2207 else if (__collate_)
2208 __ch = __traits_.translate(__ch);
2209 for (size_t __i = 0; __i < __chars_.size(); ++__i) {
2210 if (__ch == __chars_[__i]) {
2211 __found = true;
2212 goto __exit;
2213 }
2214 }
2215 // When there's at least one of __neg_chars_ and __neg_mask_, the set
2216 // of "__found" chars is
2217 // union(complement(union(__neg_chars_, __neg_mask_)),
2218 // other cases...)
2219 //
2220 // It doesn't make sense to check this when there are no __neg_chars_
2221 // and no __neg_mask_.
2222 if (!(__neg_mask_ == 0 && __neg_chars_.empty())) {
2223 const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_);
2224 const bool __in_neg_chars = std::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != __neg_chars_.end();
2225 if (!(__in_neg_mask || __in_neg_chars)) {
2226 __found = true;
2227 goto __exit;
2228 }
2229 }
2230 if (!__ranges_.empty()) {
2231 string_type __s2 =
2232 __collate_ ? __traits_.transform(std::addressof(__ch), std::addressof(__ch) + 1) : string_type(1, __ch);
2233 for (size_t __i = 0; __i < __ranges_.size(); ++__i) {
2234 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) {
2235 __found = true;
2236 goto __exit;
2237 }
2238 }
2239 }
2240 if (!__equivalences_.empty()) {
2241 string_type __s2 = __traits_.transform_primary(std::addressof(__ch), std::addressof(__ch) + 1);
2242 for (size_t __i = 0; __i < __equivalences_.size(); ++__i) {
2243 if (__s2 == __equivalences_[__i]) {
2244 __found = true;
2245 goto __exit;
2246 }
2247 }
2248 }
2249 if (__traits_.isctype(__ch, __mask_)) {
2250 __found = true;
2251 goto __exit;
2252 }
2253 } else
2254 __found = __negate_; // force reject
2255__exit:
2256 if (__found != __negate_) {
2257 __s.__do_ = __state::__accept_and_consume;
2258 __s.__current_ += __consumed;
2259 __s.__node_ = this->first();
2260 } else {
2261 __s.__do_ = __state::__reject;
2262 __s.__node_ = nullptr;
2263 }
2264}
2265
2266template <class _CharT, class _Traits>
2267class __lookahead;
2268
2269template <class _CharT, class _Traits = regex_traits<_CharT> >
2270class basic_regex;
2271
2272typedef basic_regex<char> regex;
2273# if _LIBCPP_HAS_WIDE_CHARACTERS
2274typedef basic_regex<wchar_t> wregex;
2275# endif
2276
2277template <class _CharT, class _Traits>
2278class _LIBCPP_PREFERRED_NAME(regex) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex)) basic_regex {
2279public:
2280 // types:
2281 typedef _CharT value_type;
2282 typedef _Traits traits_type;
2283 typedef typename _Traits::string_type string_type;
2284 typedef regex_constants::syntax_option_type flag_type;
2285 typedef typename _Traits::locale_type locale_type;
2286
2287private:
2288 _Traits __traits_;
2289 flag_type __flags_;
2290 unsigned __marked_count_;
2291 unsigned __loop_count_;
2292 int __open_count_;
2293 shared_ptr<__empty_state<_CharT> > __start_;
2294 __owns_one_state<_CharT>* __end_;
2295
2296 typedef std::__state<_CharT> __state;
2297 typedef std::__node<_CharT> __node;
2298
2299public:
2300 // constants:
2301 static const regex_constants::syntax_option_type icase = regex_constants::icase;
2302 static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2303 static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
2304 static const regex_constants::syntax_option_type collate = regex_constants::collate;
2305 static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2306 static const regex_constants::syntax_option_type basic = regex_constants::basic;
2307 static const regex_constants::syntax_option_type extended = regex_constants::extended;
2308 static const regex_constants::syntax_option_type awk = regex_constants::awk;
2309 static const regex_constants::syntax_option_type grep = regex_constants::grep;
2310 static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
2311 static const regex_constants::syntax_option_type multiline = regex_constants::multiline;
2312
2313 // construct/copy/destroy:
2314 _LIBCPP_HIDE_FROM_ABI basic_regex()
2315 : __flags_(regex_constants::ECMAScript),
2316 __marked_count_(0),
2317 __loop_count_(0),
2318 __open_count_(0),
2319 __end_(nullptr) {}
2320 _LIBCPP_HIDE_FROM_ABI explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2321 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
2322 __init(__p, __p + __traits_.length(__p));
2323 }
2324
2325 _LIBCPP_HIDE_FROM_ABI basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
2326 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
2327 __init(__p, __p + __len);
2328 }
2329
2330 // basic_regex(const basic_regex&) = default;
2331 // basic_regex(basic_regex&&) = default;
2332 template <class _ST, class _SA>
2333 _LIBCPP_HIDE_FROM_ABI explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2334 flag_type __f = regex_constants::ECMAScript)
2335 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
2336 __init(__p.begin(), __p.end());
2337 }
2338
2339 template <class _ForwardIterator>
2340 _LIBCPP_HIDE_FROM_ABI
2341 basic_regex(_ForwardIterator __first, _ForwardIterator __last, flag_type __f = regex_constants::ECMAScript)
2342 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
2343 __init(__first, __last);
2344 }
2345# ifndef _LIBCPP_CXX03_LANG
2346 _LIBCPP_HIDE_FROM_ABI basic_regex(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript)
2347 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
2348 __init(__il.begin(), __il.end());
2349 }
2350# endif // _LIBCPP_CXX03_LANG
2351
2352 // ~basic_regex() = default;
2353
2354 // basic_regex& operator=(const basic_regex&) = default;
2355 // basic_regex& operator=(basic_regex&&) = default;
2356 _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(const value_type* __p) { return assign(__p); }
2357# ifndef _LIBCPP_CXX03_LANG
2358 _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(initializer_list<value_type> __il) { return assign(__il); }
2359# endif // _LIBCPP_CXX03_LANG
2360 template <class _ST, class _SA>
2361 _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) {
2362 return assign(__p);
2363 }
2364
2365 // assign:
2366 _LIBCPP_HIDE_FROM_ABI basic_regex& assign(const basic_regex& __that) { return *this = __that; }
2367# ifndef _LIBCPP_CXX03_LANG
2368 _LIBCPP_HIDE_FROM_ABI basic_regex& assign(basic_regex&& __that) _NOEXCEPT { return *this = std::move(__that); }
2369# endif
2370 _LIBCPP_HIDE_FROM_ABI basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) {
2371 return assign(__p, __p + __traits_.length(__p), __f);
2372 }
2373 _LIBCPP_HIDE_FROM_ABI basic_regex&
2374 assign(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript) {
2375 return assign(__p, __p + __len, __f);
2376 }
2377 template <class _ST, class _SA>
2378 _LIBCPP_HIDE_FROM_ABI basic_regex&
2379 assign(const basic_string<value_type, _ST, _SA>& __s, flag_type __f = regex_constants::ECMAScript) {
2380 return assign(__s.begin(), __s.end(), __f);
2381 }
2382
2383 template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
2384 _LIBCPP_HIDE_FROM_ABI basic_regex&
2385 assign(_InputIterator __first, _InputIterator __last, flag_type __f = regex_constants::ECMAScript) {
2386 basic_string<_CharT> __t(__first, __last);
2387 return assign(__t.begin(), __t.end(), __f);
2388 }
2389
2390private:
2391 _LIBCPP_HIDE_FROM_ABI void __member_init(flag_type __f) {
2392 __flags_ = __f;
2393 __marked_count_ = 0;
2394 __loop_count_ = 0;
2395 __open_count_ = 0;
2396 __end_ = nullptr;
2397 }
2398
2399public:
2400 template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
2401 _LIBCPP_HIDE_FROM_ABI basic_regex&
2402 assign(_ForwardIterator __first, _ForwardIterator __last, flag_type __f = regex_constants::ECMAScript) {
2403 return assign(basic_regex(__first, __last, __f));
2404 }
2405
2406# ifndef _LIBCPP_CXX03_LANG
2407
2408 _LIBCPP_HIDE_FROM_ABI basic_regex&
2409 assign(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript) {
2410 return assign(__il.begin(), __il.end(), __f);
2411 }
2412
2413# endif // _LIBCPP_CXX03_LANG
2414
2415 // const operations:
2416 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI unsigned mark_count() const { return __marked_count_; }
2417 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI flag_type flags() const { return __flags_; }
2418
2419 // locale:
2420 _LIBCPP_HIDE_FROM_ABI locale_type imbue(locale_type __loc) {
2421 __member_init(f: ECMAScript);
2422 __start_.reset();
2423 return __traits_.imbue(__loc);
2424 }
2425 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI locale_type getloc() const { return __traits_.getloc(); }
2426
2427 // swap:
2428 void swap(basic_regex& __r);
2429
2430private:
2431 _LIBCPP_HIDE_FROM_ABI unsigned __loop_count() const { return __loop_count_; }
2432
2433 _LIBCPP_HIDE_FROM_ABI bool __use_multiline() const {
2434 return __get_grammar(g: __flags_) == ECMAScript && (__flags_ & multiline);
2435 }
2436
2437 template <class _ForwardIterator>
2438 void __init(_ForwardIterator __first, _ForwardIterator __last);
2439 template <class _ForwardIterator>
2440 _ForwardIterator __parse(_ForwardIterator __first, _ForwardIterator __last);
2441 template <class _ForwardIterator>
2442 _ForwardIterator __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2443 template <class _ForwardIterator>
2444 _ForwardIterator __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2445 template <class _ForwardIterator>
2446 _ForwardIterator __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2447 template <class _ForwardIterator>
2448 _ForwardIterator __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2449 template <class _ForwardIterator>
2450 _ForwardIterator __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2451 template <class _ForwardIterator>
2452 _ForwardIterator __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2453 template <class _ForwardIterator>
2454 _ForwardIterator __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2455 template <class _ForwardIterator>
2456 _ForwardIterator __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2457 template <class _ForwardIterator>
2458 _ForwardIterator __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2459 template <class _ForwardIterator>
2460 _ForwardIterator __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2461 template <class _ForwardIterator>
2462 _ForwardIterator __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2463 template <class _ForwardIterator>
2464 _ForwardIterator __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2465 template <class _ForwardIterator>
2466 _ForwardIterator __parse_RE_dupl_symbol(
2467 _ForwardIterator __first,
2468 _ForwardIterator __last,
2469 __owns_one_state<_CharT>* __s,
2470 unsigned __mexp_begin,
2471 unsigned __mexp_end);
2472 template <class _ForwardIterator>
2473 _ForwardIterator __parse_ERE_dupl_symbol(
2474 _ForwardIterator __first,
2475 _ForwardIterator __last,
2476 __owns_one_state<_CharT>* __s,
2477 unsigned __mexp_begin,
2478 unsigned __mexp_end);
2479 template <class _ForwardIterator>
2480 _ForwardIterator __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2481 template <class _ForwardIterator>
2482 _ForwardIterator
2483 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
2484 template <class _ForwardIterator>
2485 _ForwardIterator __parse_expression_term(
2486 _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
2487 template <class _ForwardIterator>
2488 _ForwardIterator __parse_equivalence_class(
2489 _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
2490 template <class _ForwardIterator>
2491 _ForwardIterator __parse_character_class(
2492 _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
2493 template <class _ForwardIterator>
2494 _ForwardIterator
2495 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>& __col_sym);
2496 template <class _ForwardIterator>
2497 _ForwardIterator __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
2498 template <class _ForwardIterator>
2499 _ForwardIterator __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2500 template <class _ForwardIterator>
2501 _ForwardIterator __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2502 template <class _ForwardIterator>
2503 _ForwardIterator __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2504 template <class _ForwardIterator>
2505 _ForwardIterator __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2506 template <class _ForwardIterator>
2507 _ForwardIterator __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2508 template <class _ForwardIterator>
2509 _ForwardIterator __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2510 template <class _ForwardIterator>
2511 _ForwardIterator __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2512 template <class _ForwardIterator>
2513 _ForwardIterator __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2514 template <class _ForwardIterator>
2515 _ForwardIterator __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2516 template <class _ForwardIterator>
2517 _ForwardIterator __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2518 template <class _ForwardIterator>
2519 _ForwardIterator __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2520 template <class _ForwardIterator>
2521 _ForwardIterator __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2522 template <class _ForwardIterator>
2523 _ForwardIterator __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2524 template <class _ForwardIterator>
2525 _ForwardIterator __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2526 template <class _ForwardIterator>
2527 _ForwardIterator
2528 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str = nullptr);
2529 template <class _ForwardIterator>
2530 _ForwardIterator __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
2531 template <class _ForwardIterator>
2532 _ForwardIterator __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
2533 template <class _ForwardIterator>
2534 _ForwardIterator __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
2535 template <class _ForwardIterator>
2536 _ForwardIterator __parse_class_escape(
2537 _ForwardIterator __first,
2538 _ForwardIterator __last,
2539 basic_string<_CharT>& __str,
2540 __bracket_expression<_CharT, _Traits>* __ml);
2541 template <class _ForwardIterator>
2542 _ForwardIterator
2543 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str = nullptr);
2544
2545 bool __test_back_ref(_CharT);
2546
2547 _LIBCPP_HIDE_FROM_ABI void __push_l_anchor();
2548 void __push_r_anchor();
2549 void __push_match_any();
2550 void __push_match_any_but_newline();
2551 _LIBCPP_HIDE_FROM_ABI void __push_greedy_inf_repeat(
2552 size_t __min, __owns_one_state<_CharT>* __s, unsigned __mexp_begin = 0, unsigned __mexp_end = 0) {
2553 __push_loop(__min, max: numeric_limits<size_t>::max(), __s, __mexp_begin, __mexp_end);
2554 }
2555 _LIBCPP_HIDE_FROM_ABI void __push_nongreedy_inf_repeat(
2556 size_t __min, __owns_one_state<_CharT>* __s, unsigned __mexp_begin = 0, unsigned __mexp_end = 0) {
2557 __push_loop(__min, max: numeric_limits<size_t>::max(), __s, __mexp_begin, __mexp_end, greedy: false);
2558 }
2559 void __push_loop(size_t __min,
2560 size_t __max,
2561 __owns_one_state<_CharT>* __s,
2562 size_t __mexp_begin = 0,
2563 size_t __mexp_end = 0,
2564 bool __greedy = true);
2565 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
2566 void __push_char(value_type __c);
2567 void __push_back_ref(int __i);
2568 void __push_alternation(__owns_one_state<_CharT>* __sa, __owns_one_state<_CharT>* __sb);
2569 void __push_begin_marked_subexpression();
2570 void __push_end_marked_subexpression(unsigned);
2571 void __push_empty();
2572 void __push_word_boundary(bool);
2573 void __push_lookahead(const basic_regex&, bool, unsigned);
2574
2575 template <class _Allocator>
2576 bool __search(const _CharT* __first,
2577 const _CharT* __last,
2578 match_results<const _CharT*, _Allocator>& __m,
2579 regex_constants::match_flag_type __flags) const;
2580
2581 template <class _Allocator>
2582 bool __match_at_start(const _CharT* __first,
2583 const _CharT* __last,
2584 match_results<const _CharT*, _Allocator>& __m,
2585 regex_constants::match_flag_type __flags,
2586 bool) const;
2587 template <class _Allocator>
2588 bool __match_at_start_ecma(
2589 const _CharT* __first,
2590 const _CharT* __last,
2591 match_results<const _CharT*, _Allocator>& __m,
2592 regex_constants::match_flag_type __flags,
2593 bool) const;
2594 template <class _Allocator>
2595 bool __match_at_start_posix_nosubs(
2596 const _CharT* __first,
2597 const _CharT* __last,
2598 match_results<const _CharT*, _Allocator>& __m,
2599 regex_constants::match_flag_type __flags,
2600 bool) const;
2601 template <class _Allocator>
2602 bool __match_at_start_posix_subs(
2603 const _CharT* __first,
2604 const _CharT* __last,
2605 match_results<const _CharT*, _Allocator>& __m,
2606 regex_constants::match_flag_type __flags,
2607 bool) const;
2608
2609 template <class _Bp, class _Ap, class _Cp, class _Tp>
2610 friend bool
2611 regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
2612
2613 template <class _Ap, class _Cp, class _Tp>
2614 friend bool
2615 regex_search(const _Cp*,
2616 const _Cp*,
2617 match_results<const _Cp*, _Ap>&,
2618 const basic_regex<_Cp, _Tp>&,
2619 regex_constants::match_flag_type);
2620
2621 template <class _Bp, class _Cp, class _Tp>
2622 friend bool regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
2623
2624 template <class _Cp, class _Tp>
2625 friend bool regex_search(const _Cp*, const _Cp*, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
2626
2627 template <class _Cp, class _Ap, class _Tp>
2628 friend bool regex_search(
2629 const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
2630
2631 template <class _ST, class _SA, class _Cp, class _Tp>
2632 friend bool regex_search(const basic_string<_Cp, _ST, _SA>& __s,
2633 const basic_regex<_Cp, _Tp>& __e,
2634 regex_constants::match_flag_type __flags);
2635
2636 template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
2637 friend bool regex_search(const basic_string<_Cp, _ST, _SA>& __s,
2638 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
2639 const basic_regex<_Cp, _Tp>& __e,
2640 regex_constants::match_flag_type __flags);
2641
2642 template <class _Iter, class _Ap, class _Cp, class _Tp>
2643 friend bool
2644 regex_search(__wrap_iter<_Iter> __first,
2645 __wrap_iter<_Iter> __last,
2646 match_results<__wrap_iter<_Iter>, _Ap>& __m,
2647 const basic_regex<_Cp, _Tp>& __e,
2648 regex_constants::match_flag_type __flags);
2649
2650 template <class, class>
2651 friend class __lookahead;
2652};
2653
2654# if _LIBCPP_STD_VER >= 17
2655template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
2656basic_regex(_ForwardIterator, _ForwardIterator, regex_constants::syntax_option_type = regex_constants::ECMAScript)
2657 -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
2658# endif
2659
2660template <class _CharT, class _Traits>
2661const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
2662template <class _CharT, class _Traits>
2663const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
2664template <class _CharT, class _Traits>
2665const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
2666template <class _CharT, class _Traits>
2667const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
2668template <class _CharT, class _Traits>
2669const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
2670template <class _CharT, class _Traits>
2671const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
2672template <class _CharT, class _Traits>
2673const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
2674template <class _CharT, class _Traits>
2675const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
2676template <class _CharT, class _Traits>
2677const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
2678template <class _CharT, class _Traits>
2679const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
2680
2681template <class _CharT, class _Traits>
2682void basic_regex<_CharT, _Traits>::swap(basic_regex& __r) {
2683 using std::swap;
2684 swap(__traits_, __r.__traits_);
2685 swap(__flags_, __r.__flags_);
2686 swap(__marked_count_, __r.__marked_count_);
2687 swap(__loop_count_, __r.__loop_count_);
2688 swap(__open_count_, __r.__open_count_);
2689 swap(__start_, __r.__start_);
2690 swap(__end_, __r.__end_);
2691}
2692
2693template <class _CharT, class _Traits>
2694inline _LIBCPP_HIDE_FROM_ABI void swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) {
2695 return __x.swap(__y);
2696}
2697
2698// __lookahead
2699
2700template <class _CharT, class _Traits>
2701class __lookahead : public __owns_one_state<_CharT> {
2702 typedef __owns_one_state<_CharT> base;
2703
2704 basic_regex<_CharT, _Traits> __exp_;
2705 unsigned __mexp_;
2706 bool __invert_;
2707
2708public:
2709 typedef std::__state<_CharT> __state;
2710
2711 _LIBCPP_HIDE_FROM_ABI
2712 __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
2713 : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
2714
2715 __lookahead(const __lookahead&) = delete;
2716 __lookahead& operator=(const __lookahead&) = delete;
2717
2718 _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
2719};
2720
2721template <class _CharT, class _Traits>
2722void __lookahead<_CharT, _Traits>::__exec(__state& __s) const {
2723 match_results<const _CharT*> __m;
2724 __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
2725 bool __matched = __exp_.__match_at_start_ecma(
2726 __s.__current_,
2727 __s.__last_,
2728 __m,
2729 (__s.__flags_ | regex_constants::match_continuous) & ~regex_constants::__full_match,
2730 __s.__at_first_ && __s.__current_ == __s.__first_);
2731 if (__matched != __invert_) {
2732 __s.__do_ = __state::__accept_but_not_consume;
2733 __s.__node_ = this->first();
2734 for (unsigned __i = 1; __i < __m.size(); ++__i) {
2735 __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
2736 }
2737 } else {
2738 __s.__do_ = __state::__reject;
2739 __s.__node_ = nullptr;
2740 }
2741}
2742
2743template <class _CharT, class _Traits>
2744template <class _ForwardIterator>
2745void basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last) {
2746 if (__get_grammar(g: __flags_) == 0)
2747 __flags_ |= regex_constants::ECMAScript;
2748 _ForwardIterator __temp = __parse(__first, __last);
2749 if (__temp != __last)
2750 std::__throw_regex_error<regex_constants::__re_err_parse>();
2751}
2752
2753template <class _CharT, class _Traits>
2754template <class _ForwardIterator>
2755_ForwardIterator basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, _ForwardIterator __last) {
2756 {
2757 unique_ptr<__node> __h(new __end_state<_CharT>);
2758 __start_.reset(new __empty_state<_CharT>(__h.get()));
2759 __h.release();
2760 __end_ = __start_.get();
2761 }
2762 switch (__get_grammar(g: __flags_)) {
2763 case ECMAScript:
2764 __first = __parse_ecma_exp(__first, __last);
2765 break;
2766 case basic:
2767 __first = __parse_basic_reg_exp(__first, __last);
2768 break;
2769 case extended:
2770 case awk:
2771 __first = __parse_extended_reg_exp(__first, __last);
2772 break;
2773 case grep:
2774 __first = __parse_grep(__first, __last);
2775 break;
2776 case egrep:
2777 __first = __parse_egrep(__first, __last);
2778 break;
2779 default:
2780 std::__throw_regex_error<regex_constants::__re_err_grammar>();
2781 }
2782 return __first;
2783}
2784
2785template <class _CharT, class _Traits>
2786template <class _ForwardIterator>
2787_ForwardIterator
2788basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last) {
2789 if (__first != __last) {
2790 if (*__first == '^') {
2791 __push_l_anchor();
2792 ++__first;
2793 }
2794 if (__first != __last) {
2795 __first = __parse_RE_expression(__first, __last);
2796 if (__first != __last) {
2797 _ForwardIterator __temp = std::next(__first);
2798 if (__temp == __last && *__first == '$') {
2799 __push_r_anchor();
2800 ++__first;
2801 }
2802 }
2803 }
2804 if (__first != __last)
2805 std::__throw_regex_error<regex_constants::__re_err_empty>();
2806 }
2807 return __first;
2808}
2809
2810template <class _CharT, class _Traits>
2811template <class _ForwardIterator>
2812_ForwardIterator
2813basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last) {
2814 __owns_one_state<_CharT>* __sa = __end_;
2815 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
2816 if (__temp == __first)
2817 std::__throw_regex_error<regex_constants::__re_err_empty>();
2818 __first = __temp;
2819 while (__first != __last && *__first == '|') {
2820 __owns_one_state<_CharT>* __sb = __end_;
2821 __temp = __parse_ERE_branch(++__first, __last);
2822 if (__temp == __first)
2823 std::__throw_regex_error<regex_constants::__re_err_empty>();
2824 __push_alternation(__sa, __sb);
2825 __first = __temp;
2826 }
2827 return __first;
2828}
2829
2830template <class _CharT, class _Traits>
2831template <class _ForwardIterator>
2832_ForwardIterator basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last) {
2833 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
2834 if (__temp == __first)
2835 std::__throw_regex_error<regex_constants::__re_err_empty>();
2836 do {
2837 __first = __temp;
2838 __temp = __parse_ERE_expression(__first, __last);
2839 } while (__temp != __first);
2840 return __first;
2841}
2842
2843template <class _CharT, class _Traits>
2844template <class _ForwardIterator>
2845_ForwardIterator
2846basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last) {
2847 __owns_one_state<_CharT>* __e = __end_;
2848 unsigned __mexp_begin = __marked_count_;
2849 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
2850 if (__temp == __first && __temp != __last) {
2851 switch (*__temp) {
2852 case '^':
2853 __push_l_anchor();
2854 ++__temp;
2855 break;
2856 case '$':
2857 __push_r_anchor();
2858 ++__temp;
2859 break;
2860 case '(':
2861 __push_begin_marked_subexpression();
2862 unsigned __temp_count = __marked_count_;
2863 ++__open_count_;
2864 __temp = __parse_extended_reg_exp(++__temp, __last);
2865 if (__temp == __last || *__temp != ')')
2866 std::__throw_regex_error<regex_constants::error_paren>();
2867 __push_end_marked_subexpression(__temp_count);
2868 --__open_count_;
2869 ++__temp;
2870 break;
2871 }
2872 }
2873 if (__temp != __first)
2874 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin + 1, __marked_count_ + 1);
2875 __first = __temp;
2876 return __first;
2877}
2878
2879template <class _CharT, class _Traits>
2880template <class _ForwardIterator>
2881_ForwardIterator
2882basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last) {
2883 while (true) {
2884 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
2885 if (__temp == __first)
2886 break;
2887 __first = __temp;
2888 }
2889 return __first;
2890}
2891
2892template <class _CharT, class _Traits>
2893template <class _ForwardIterator>
2894_ForwardIterator basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last) {
2895 if (__first != __last) {
2896 __owns_one_state<_CharT>* __e = __end_;
2897 unsigned __mexp_begin = __marked_count_;
2898 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
2899 if (__temp != __first)
2900 __first = __parse_RE_dupl_symbol(__temp, __last, __e, __mexp_begin + 1, __marked_count_ + 1);
2901 }
2902 return __first;
2903}
2904
2905template <class _CharT, class _Traits>
2906template <class _ForwardIterator>
2907_ForwardIterator basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last) {
2908 _ForwardIterator __temp = __first;
2909 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
2910 if (__temp == __first) {
2911 __temp = __parse_Back_open_paren(__first, __last);
2912 if (__temp != __first) {
2913 __push_begin_marked_subexpression();
2914 unsigned __temp_count = __marked_count_;
2915 __first = __parse_RE_expression(__temp, __last);
2916 __temp = __parse_Back_close_paren(__first, __last);
2917 if (__temp == __first)
2918 std::__throw_regex_error<regex_constants::error_paren>();
2919 __push_end_marked_subexpression(__temp_count);
2920 __first = __temp;
2921 } else
2922 __first = __parse_BACKREF(__first, __last);
2923 }
2924 return __first;
2925}
2926
2927template <class _CharT, class _Traits>
2928template <class _ForwardIterator>
2929_ForwardIterator
2930basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last) {
2931 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
2932 if (__temp == __first) {
2933 __temp = __parse_QUOTED_CHAR(__first, __last);
2934 if (__temp == __first) {
2935 if (__temp != __last && *__temp == '.') {
2936 __push_match_any();
2937 ++__temp;
2938 } else
2939 __temp = __parse_bracket_expression(__first, __last);
2940 }
2941 }
2942 __first = __temp;
2943 return __first;
2944}
2945
2946template <class _CharT, class _Traits>
2947template <class _ForwardIterator>
2948_ForwardIterator
2949basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last) {
2950 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
2951 if (__temp == __first) {
2952 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
2953 if (__temp == __first) {
2954 if (__temp != __last && *__temp == '.') {
2955 __push_match_any();
2956 ++__temp;
2957 } else
2958 __temp = __parse_bracket_expression(__first, __last);
2959 }
2960 }
2961 __first = __temp;
2962 return __first;
2963}
2964
2965template <class _CharT, class _Traits>
2966template <class _ForwardIterator>
2967_ForwardIterator
2968basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last) {
2969 if (__first != __last) {
2970 _ForwardIterator __temp = std::next(__first);
2971 if (__temp != __last) {
2972 if (*__first == '\\' && *__temp == '(')
2973 __first = ++__temp;
2974 }
2975 }
2976 return __first;
2977}
2978
2979template <class _CharT, class _Traits>
2980template <class _ForwardIterator>
2981_ForwardIterator
2982basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last) {
2983 if (__first != __last) {
2984 _ForwardIterator __temp = std::next(__first);
2985 if (__temp != __last) {
2986 if (*__first == '\\' && *__temp == ')')
2987 __first = ++__temp;
2988 }
2989 }
2990 return __first;
2991}
2992
2993template <class _CharT, class _Traits>
2994template <class _ForwardIterator>
2995_ForwardIterator
2996basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last) {
2997 if (__first != __last) {
2998 _ForwardIterator __temp = std::next(__first);
2999 if (__temp != __last) {
3000 if (*__first == '\\' && *__temp == '{')
3001 __first = ++__temp;
3002 }
3003 }
3004 return __first;
3005}
3006
3007template <class _CharT, class _Traits>
3008template <class _ForwardIterator>
3009_ForwardIterator
3010basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last) {
3011 if (__first != __last) {
3012 _ForwardIterator __temp = std::next(__first);
3013 if (__temp != __last) {
3014 if (*__first == '\\' && *__temp == '}')
3015 __first = ++__temp;
3016 }
3017 }
3018 return __first;
3019}
3020
3021template <class _CharT, class _Traits>
3022template <class _ForwardIterator>
3023_ForwardIterator basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last) {
3024 if (__first != __last) {
3025 _ForwardIterator __temp = std::next(__first);
3026 if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp))
3027 __first = ++__temp;
3028 }
3029 return __first;
3030}
3031
3032template <class _CharT, class _Traits>
3033template <class _ForwardIterator>
3034_ForwardIterator basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last) {
3035 if (__first != __last) {
3036 _ForwardIterator __temp = std::next(__first);
3037 if (__temp == __last && *__first == '$')
3038 return __first;
3039 // Not called inside a bracket
3040 if (*__first == '.' || *__first == '\\' || *__first == '[')
3041 return __first;
3042 __push_char(c: *__first);
3043 ++__first;
3044 }
3045 return __first;
3046}
3047
3048template <class _CharT, class _Traits>
3049template <class _ForwardIterator>
3050_ForwardIterator basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last) {
3051 if (__first != __last) {
3052 switch (*__first) {
3053 case '^':
3054 case '.':
3055 case '[':
3056 case '$':
3057 case '(':
3058 case '|':
3059 case '*':
3060 case '+':
3061 case '?':
3062 case '{':
3063 case '\\':
3064 break;
3065 case ')':
3066 if (__open_count_ == 0) {
3067 __push_char(c: *__first);
3068 ++__first;
3069 }
3070 break;
3071 default:
3072 __push_char(c: *__first);
3073 ++__first;
3074 break;
3075 }
3076 }
3077 return __first;
3078}
3079
3080template <class _CharT, class _Traits>
3081template <class _ForwardIterator>
3082_ForwardIterator basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last) {
3083 if (__first != __last) {
3084 _ForwardIterator __temp = std::next(__first);
3085 if (__temp != __last) {
3086 if (*__first == '\\') {
3087 switch (*__temp) {
3088 case '^':
3089 case '.':
3090 case '*':
3091 case '[':
3092 case '$':
3093 case '\\':
3094 __push_char(c: *__temp);
3095 __first = ++__temp;
3096 break;
3097 }
3098 }
3099 }
3100 }
3101 return __first;
3102}
3103
3104template <class _CharT, class _Traits>
3105template <class _ForwardIterator>
3106_ForwardIterator
3107basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last) {
3108 if (__first != __last) {
3109 _ForwardIterator __temp = std::next(__first);
3110 if (__temp != __last) {
3111 if (*__first == '\\') {
3112 switch (*__temp) {
3113 case '^':
3114 case '.':
3115 case '*':
3116 case '[':
3117 case '$':
3118 case '\\':
3119 case '(':
3120 case ')':
3121 case '|':
3122 case '+':
3123 case '?':
3124 case '{':
3125 case '}':
3126 __push_char(c: *__temp);
3127 __first = ++__temp;
3128 break;
3129 default:
3130 if (__get_grammar(g: __flags_) == awk)
3131 __first = __parse_awk_escape(++__first, __last);
3132 else if (__test_back_ref(*__temp))
3133 __first = ++__temp;
3134 break;
3135 }
3136 }
3137 }
3138 }
3139 return __first;
3140}
3141
3142template <class _CharT, class _Traits>
3143template <class _ForwardIterator>
3144_ForwardIterator basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(
3145 _ForwardIterator __first,
3146 _ForwardIterator __last,
3147 __owns_one_state<_CharT>* __s,
3148 unsigned __mexp_begin,
3149 unsigned __mexp_end) {
3150 if (__first != __last) {
3151 if (*__first == '*') {
3152 __push_greedy_inf_repeat(min: 0, __s, __mexp_begin, __mexp_end);
3153 ++__first;
3154 } else {
3155 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3156 if (__temp != __first) {
3157 int __min = 0;
3158 __first = __temp;
3159 __temp = __parse_DUP_COUNT(__first, __last, __min);
3160 if (__temp == __first)
3161 std::__throw_regex_error<regex_constants::error_badbrace>();
3162 __first = __temp;
3163 if (__first == __last)
3164 std::__throw_regex_error<regex_constants::error_brace>();
3165 if (*__first != ',') {
3166 __temp = __parse_Back_close_brace(__first, __last);
3167 if (__temp == __first)
3168 std::__throw_regex_error<regex_constants::error_brace>();
3169 __push_loop(__min, max: __min, __s, __mexp_begin, __mexp_end, greedy: true);
3170 __first = __temp;
3171 } else {
3172 ++__first; // consume ','
3173 int __max = -1;
3174 __first = __parse_DUP_COUNT(__first, __last, __max);
3175 __temp = __parse_Back_close_brace(__first, __last);
3176 if (__temp == __first)
3177 std::__throw_regex_error<regex_constants::error_brace>();
3178 if (__max == -1)
3179 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3180 else {
3181 if (__max < __min)
3182 std::__throw_regex_error<regex_constants::error_badbrace>();
3183 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, greedy: true);
3184 }
3185 __first = __temp;
3186 }
3187 }
3188 }
3189 }
3190 return __first;
3191}
3192
3193template <class _CharT, class _Traits>
3194template <class _ForwardIterator>
3195_ForwardIterator basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(
3196 _ForwardIterator __first,
3197 _ForwardIterator __last,
3198 __owns_one_state<_CharT>* __s,
3199 unsigned __mexp_begin,
3200 unsigned __mexp_end) {
3201 if (__first != __last) {
3202 unsigned __grammar = __get_grammar(g: __flags_);
3203 switch (*__first) {
3204 case '*':
3205 ++__first;
3206 if (__grammar == ECMAScript && __first != __last && *__first == '?') {
3207 ++__first;
3208 __push_nongreedy_inf_repeat(min: 0, __s, __mexp_begin, __mexp_end);
3209 } else
3210 __push_greedy_inf_repeat(min: 0, __s, __mexp_begin, __mexp_end);
3211 break;
3212 case '+':
3213 ++__first;
3214 if (__grammar == ECMAScript && __first != __last && *__first == '?') {
3215 ++__first;
3216 __push_nongreedy_inf_repeat(min: 1, __s, __mexp_begin, __mexp_end);
3217 } else
3218 __push_greedy_inf_repeat(min: 1, __s, __mexp_begin, __mexp_end);
3219 break;
3220 case '?':
3221 ++__first;
3222 if (__grammar == ECMAScript && __first != __last && *__first == '?') {
3223 ++__first;
3224 __push_loop(min: 0, max: 1, __s, __mexp_begin, __mexp_end, greedy: false);
3225 } else
3226 __push_loop(min: 0, max: 1, __s, __mexp_begin, __mexp_end);
3227 break;
3228 case '{': {
3229 int __min;
3230 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
3231 if (__temp == __first)
3232 std::__throw_regex_error<regex_constants::error_badbrace>();
3233 __first = __temp;
3234 if (__first == __last)
3235 std::__throw_regex_error<regex_constants::error_brace>();
3236 switch (*__first) {
3237 case '}':
3238 ++__first;
3239 if (__grammar == ECMAScript && __first != __last && *__first == '?') {
3240 ++__first;
3241 __push_loop(__min, max: __min, __s, __mexp_begin, __mexp_end, greedy: false);
3242 } else
3243 __push_loop(__min, max: __min, __s, __mexp_begin, __mexp_end);
3244 break;
3245 case ',':
3246 ++__first;
3247 if (__first == __last)
3248 std::__throw_regex_error<regex_constants::error_badbrace>();
3249 if (*__first == '}') {
3250 ++__first;
3251 if (__grammar == ECMAScript && __first != __last && *__first == '?') {
3252 ++__first;
3253 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3254 } else
3255 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3256 } else {
3257 int __max = -1;
3258 __temp = __parse_DUP_COUNT(__first, __last, __max);
3259 if (__temp == __first)
3260 std::__throw_regex_error<regex_constants::error_brace>();
3261 __first = __temp;
3262 if (__first == __last || *__first != '}')
3263 std::__throw_regex_error<regex_constants::error_brace>();
3264 ++__first;
3265 if (__max < __min)
3266 std::__throw_regex_error<regex_constants::error_badbrace>();
3267 if (__grammar == ECMAScript && __first != __last && *__first == '?') {
3268 ++__first;
3269 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, greedy: false);
3270 } else
3271 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
3272 }
3273 break;
3274 default:
3275 std::__throw_regex_error<regex_constants::error_badbrace>();
3276 }
3277 } break;
3278 }
3279 }
3280 return __first;
3281}
3282
3283template <class _CharT, class _Traits>
3284template <class _ForwardIterator>
3285_ForwardIterator
3286basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last) {
3287 if (__first != __last && *__first == '[') {
3288 ++__first;
3289 if (__first == __last)
3290 std::__throw_regex_error<regex_constants::error_brack>();
3291 bool __negate = false;
3292 if (*__first == '^') {
3293 ++__first;
3294 __negate = true;
3295 }
3296 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3297 // __ml owned by *this
3298 if (__first == __last)
3299 std::__throw_regex_error<regex_constants::error_brack>();
3300 if (__get_grammar(g: __flags_) != ECMAScript && *__first == ']') {
3301 __ml->__add_char(']');
3302 ++__first;
3303 }
3304 __first = __parse_follow_list(__first, __last, __ml);
3305 if (__first == __last)
3306 std::__throw_regex_error<regex_constants::error_brack>();
3307 if (*__first == '-') {
3308 __ml->__add_char('-');
3309 ++__first;
3310 }
3311 if (__first == __last || *__first != ']')
3312 std::__throw_regex_error<regex_constants::error_brack>();
3313 ++__first;
3314 }
3315 return __first;
3316}
3317
3318template <class _CharT, class _Traits>
3319template <class _ForwardIterator>
3320_ForwardIterator basic_regex<_CharT, _Traits>::__parse_follow_list(
3321 _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
3322 if (__first != __last) {
3323 while (true) {
3324 _ForwardIterator __temp = __parse_expression_term(__first, __last, __ml);
3325 if (__temp == __first)
3326 break;
3327 __first = __temp;
3328 }
3329 }
3330 return __first;
3331}
3332
3333template <class _CharT, class _Traits>
3334template <class _ForwardIterator>
3335_ForwardIterator basic_regex<_CharT, _Traits>::__parse_expression_term(
3336 _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
3337 if (__first != __last && *__first != ']') {
3338 _ForwardIterator __temp = std::next(__first);
3339 basic_string<_CharT> __start_range;
3340 if (__temp != __last && *__first == '[') {
3341 if (*__temp == '=')
3342 return __parse_equivalence_class(++__temp, __last, __ml);
3343 else if (*__temp == ':')
3344 return __parse_character_class(++__temp, __last, __ml);
3345 else if (*__temp == '.')
3346 __first = __parse_collating_symbol(++__temp, __last, __start_range);
3347 }
3348 unsigned __grammar = __get_grammar(g: __flags_);
3349 if (__start_range.empty()) {
3350 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') {
3351 if (__grammar == ECMAScript)
3352 __first = __parse_class_escape(++__first, __last, __start_range, __ml);
3353 else
3354 __first = __parse_awk_escape(++__first, __last, std::addressof(__start_range));
3355 } else {
3356 __start_range = *__first;
3357 ++__first;
3358 }
3359 }
3360 if (__first != __last && *__first != ']') {
3361 __temp = std::next(__first);
3362 if (__temp != __last && *__first == '-' && *__temp != ']') {
3363 // parse a range
3364 basic_string<_CharT> __end_range;
3365 __first = __temp;
3366 ++__temp;
3367 if (__temp != __last && *__first == '[' && *__temp == '.')
3368 __first = __parse_collating_symbol(++__temp, __last, __end_range);
3369 else {
3370 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') {
3371 if (__grammar == ECMAScript)
3372 __first = __parse_class_escape(++__first, __last, __end_range, __ml);
3373 else
3374 __first = __parse_awk_escape(++__first, __last, std::addressof(__end_range));
3375 } else {
3376 __end_range = *__first;
3377 ++__first;
3378 }
3379 }
3380 __ml->__add_range(std::move(__start_range), std::move(__end_range));
3381 } else if (!__start_range.empty()) {
3382 if (__start_range.size() == 1)
3383 __ml->__add_char(__start_range[0]);
3384 else
3385 __ml->__add_digraph(__start_range[0], __start_range[1]);
3386 }
3387 } else if (!__start_range.empty()) {
3388 if (__start_range.size() == 1)
3389 __ml->__add_char(__start_range[0]);
3390 else
3391 __ml->__add_digraph(__start_range[0], __start_range[1]);
3392 }
3393 }
3394 return __first;
3395}
3396
3397template <class _CharT, class _Traits>
3398template <class _ForwardIterator>
3399_ForwardIterator basic_regex<_CharT, _Traits>::__parse_class_escape(
3400 _ForwardIterator __first,
3401 _ForwardIterator __last,
3402 basic_string<_CharT>& __str,
3403 __bracket_expression<_CharT, _Traits>* __ml) {
3404 if (__first == __last)
3405 std::__throw_regex_error<regex_constants::error_escape>();
3406 switch (*__first) {
3407 case 0:
3408 __str = *__first;
3409 return ++__first;
3410 case 'b':
3411 __str = _CharT(8);
3412 return ++__first;
3413 case 'd':
3414 __ml->__add_class(ctype_base::digit);
3415 return ++__first;
3416 case 'D':
3417 __ml->__add_neg_class(ctype_base::digit);
3418 return ++__first;
3419 case 's':
3420 __ml->__add_class(ctype_base::space);
3421 return ++__first;
3422 case 'S':
3423 __ml->__add_neg_class(ctype_base::space);
3424 return ++__first;
3425 case 'w':
3426 __ml->__add_class(ctype_base::alnum);
3427 __ml->__add_char('_');
3428 return ++__first;
3429 case 'W':
3430 __ml->__add_neg_class(ctype_base::alnum);
3431 __ml->__add_neg_char('_');
3432 return ++__first;
3433 }
3434 __first = __parse_character_escape(__first, __last, std::addressof(__str));
3435 return __first;
3436}
3437
3438template <class _CharT, class _Traits>
3439template <class _ForwardIterator>
3440_ForwardIterator basic_regex<_CharT, _Traits>::__parse_awk_escape(
3441 _ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str) {
3442 if (__first == __last)
3443 std::__throw_regex_error<regex_constants::error_escape>();
3444 switch (*__first) {
3445 case '\\':
3446 case '"':
3447 case '/':
3448 if (__str)
3449 *__str = *__first;
3450 else
3451 __push_char(c: *__first);
3452 return ++__first;
3453 case 'a':
3454 if (__str)
3455 *__str = _CharT(7);
3456 else
3457 __push_char(c: _CharT(7));
3458 return ++__first;
3459 case 'b':
3460 if (__str)
3461 *__str = _CharT(8);
3462 else
3463 __push_char(c: _CharT(8));
3464 return ++__first;
3465 case 'f':
3466 if (__str)
3467 *__str = _CharT(0xC);
3468 else
3469 __push_char(c: _CharT(0xC));
3470 return ++__first;
3471 case 'n':
3472 if (__str)
3473 *__str = _CharT(0xA);
3474 else
3475 __push_char(c: _CharT(0xA));
3476 return ++__first;
3477 case 'r':
3478 if (__str)
3479 *__str = _CharT(0xD);
3480 else
3481 __push_char(c: _CharT(0xD));
3482 return ++__first;
3483 case 't':
3484 if (__str)
3485 *__str = _CharT(0x9);
3486 else
3487 __push_char(c: _CharT(0x9));
3488 return ++__first;
3489 case 'v':
3490 if (__str)
3491 *__str = _CharT(0xB);
3492 else
3493 __push_char(c: _CharT(0xB));
3494 return ++__first;
3495 }
3496 if ('0' <= *__first && *__first <= '7') {
3497 unsigned __val = *__first - '0';
3498 if (++__first != __last && ('0' <= *__first && *__first <= '7')) {
3499 __val = 8 * __val + *__first - '0';
3500 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3501 __val = 8 * __val + *__first++ - '0';
3502 }
3503 if (__str)
3504 *__str = _CharT(__val);
3505 else
3506 __push_char(c: _CharT(__val));
3507 } else
3508 std::__throw_regex_error<regex_constants::error_escape>();
3509 return __first;
3510}
3511
3512template <class _CharT, class _Traits>
3513template <class _ForwardIterator>
3514_ForwardIterator basic_regex<_CharT, _Traits>::__parse_equivalence_class(
3515 _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
3516 // Found [=
3517 // This means =] must exist
3518 value_type __equal_close[2] = {'=', ']'};
3519 _ForwardIterator __temp = std::search(__first, __last, __equal_close, __equal_close + 2);
3520 if (__temp == __last)
3521 std::__throw_regex_error<regex_constants::error_brack>();
3522 // [__first, __temp) contains all text in [= ... =]
3523 string_type __collate_name = __traits_.lookup_collatename(__first, __temp);
3524 if (__collate_name.empty())
3525 std::__throw_regex_error<regex_constants::error_collate>();
3526 string_type __equiv_name = __traits_.transform_primary(__collate_name.begin(), __collate_name.end());
3527 if (!__equiv_name.empty())
3528 __ml->__add_equivalence(__equiv_name);
3529 else {
3530 switch (__collate_name.size()) {
3531 case 1:
3532 __ml->__add_char(__collate_name[0]);
3533 break;
3534 case 2:
3535 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
3536 break;
3537 default:
3538 std::__throw_regex_error<regex_constants::error_collate>();
3539 }
3540 }
3541 __first = std::next(__temp, 2);
3542 return __first;
3543}
3544
3545template <class _CharT, class _Traits>
3546template <class _ForwardIterator>
3547_ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_class(
3548 _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
3549 // Found [:
3550 // This means :] must exist
3551 value_type __colon_close[2] = {':', ']'};
3552 _ForwardIterator __temp = std::search(__first, __last, __colon_close, __colon_close + 2);
3553 if (__temp == __last)
3554 std::__throw_regex_error<regex_constants::error_brack>();
3555 // [__first, __temp) contains all text in [: ... :]
3556 typedef typename _Traits::char_class_type char_class_type;
3557 char_class_type __class_type = __traits_.lookup_classname(__first, __temp, __flags_ & icase);
3558 if (__class_type == 0)
3559 std::__throw_regex_error<regex_constants::error_ctype>();
3560 __ml->__add_class(__class_type);
3561 __first = std::next(__temp, 2);
3562 return __first;
3563}
3564
3565template <class _CharT, class _Traits>
3566template <class _ForwardIterator>
3567_ForwardIterator basic_regex<_CharT, _Traits>::__parse_collating_symbol(
3568 _ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>& __col_sym) {
3569 // Found [.
3570 // This means .] must exist
3571 value_type __dot_close[2] = {'.', ']'};
3572 _ForwardIterator __temp = std::search(__first, __last, __dot_close, __dot_close + 2);
3573 if (__temp == __last)
3574 std::__throw_regex_error<regex_constants::error_brack>();
3575 // [__first, __temp) contains all text in [. ... .]
3576 __col_sym = __traits_.lookup_collatename(__first, __temp);
3577 switch (__col_sym.size()) {
3578 case 1:
3579 case 2:
3580 break;
3581 default:
3582 std::__throw_regex_error<regex_constants::error_collate>();
3583 }
3584 __first = std::next(__temp, 2);
3585 return __first;
3586}
3587
3588template <class _CharT, class _Traits>
3589template <class _ForwardIterator>
3590_ForwardIterator
3591basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c) {
3592 if (__first != __last) {
3593 int __val = __traits_.value(*__first, 10);
3594 if (__val != -1) {
3595 __c = __val;
3596 for (++__first; __first != __last && (__val = __traits_.value(*__first, 10)) != -1; ++__first) {
3597 if (__c >= numeric_limits<int>::max() / 10)
3598 std::__throw_regex_error<regex_constants::error_badbrace>();
3599 __c *= 10;
3600 __c += __val;
3601 }
3602 }
3603 }
3604 return __first;
3605}
3606
3607template <class _CharT, class _Traits>
3608template <class _ForwardIterator>
3609_ForwardIterator basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last) {
3610 __owns_one_state<_CharT>* __sa = __end_;
3611 _ForwardIterator __temp = __parse_alternative(__first, __last);
3612 if (__temp == __first)
3613 __push_empty();
3614 __first = __temp;
3615 while (__first != __last && *__first == '|') {
3616 __owns_one_state<_CharT>* __sb = __end_;
3617 __temp = __parse_alternative(++__first, __last);
3618 if (__temp == __first)
3619 __push_empty();
3620 __push_alternation(__sa, __sb);
3621 __first = __temp;
3622 }
3623 return __first;
3624}
3625
3626template <class _CharT, class _Traits>
3627template <class _ForwardIterator>
3628_ForwardIterator basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, _ForwardIterator __last) {
3629 while (true) {
3630 _ForwardIterator __temp = __parse_term(__first, __last);
3631 if (__temp == __first)
3632 break;
3633 __first = __temp;
3634 }
3635 return __first;
3636}
3637
3638template <class _CharT, class _Traits>
3639template <class _ForwardIterator>
3640_ForwardIterator basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, _ForwardIterator __last) {
3641 _ForwardIterator __temp = __parse_assertion(__first, __last);
3642 if (__temp == __first) {
3643 __owns_one_state<_CharT>* __e = __end_;
3644 unsigned __mexp_begin = __marked_count_;
3645 __temp = __parse_atom(__first, __last);
3646 if (__temp != __first)
3647 __first = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin + 1, __marked_count_ + 1);
3648 } else
3649 __first = __temp;
3650 return __first;
3651}
3652
3653template <class _CharT, class _Traits>
3654template <class _ForwardIterator>
3655_ForwardIterator basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, _ForwardIterator __last) {
3656 if (__first != __last) {
3657 switch (*__first) {
3658 case '^':
3659 __push_l_anchor();
3660 ++__first;
3661 break;
3662 case '$':
3663 __push_r_anchor();
3664 ++__first;
3665 break;
3666 case '\\': {
3667 _ForwardIterator __temp = std::next(__first);
3668 if (__temp != __last) {
3669 if (*__temp == 'b') {
3670 __push_word_boundary(false);
3671 __first = ++__temp;
3672 } else if (*__temp == 'B') {
3673 __push_word_boundary(true);
3674 __first = ++__temp;
3675 }
3676 }
3677 } break;
3678 case '(': {
3679 _ForwardIterator __temp = std::next(__first);
3680 if (__temp != __last && *__temp == '?') {
3681 if (++__temp != __last) {
3682 switch (*__temp) {
3683 case '=': {
3684 basic_regex __exp;
3685 __exp.__flags_ = __flags_;
3686 __temp = __exp.__parse(++__temp, __last);
3687 unsigned __mexp = __exp.__marked_count_;
3688 __push_lookahead(std::move(__exp), false, __marked_count_);
3689 __marked_count_ += __mexp;
3690 if (__temp == __last || *__temp != ')')
3691 std::__throw_regex_error<regex_constants::error_paren>();
3692 __first = ++__temp;
3693 } break;
3694 case '!': {
3695 basic_regex __exp;
3696 __exp.__flags_ = __flags_;
3697 __temp = __exp.__parse(++__temp, __last);
3698 unsigned __mexp = __exp.__marked_count_;
3699 __push_lookahead(std::move(__exp), true, __marked_count_);
3700 __marked_count_ += __mexp;
3701 if (__temp == __last || *__temp != ')')
3702 std::__throw_regex_error<regex_constants::error_paren>();
3703 __first = ++__temp;
3704 } break;
3705 }
3706 }
3707 }
3708 } break;
3709 }
3710 }
3711 return __first;
3712}
3713
3714template <class _CharT, class _Traits>
3715template <class _ForwardIterator>
3716_ForwardIterator basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, _ForwardIterator __last) {
3717 if (__first != __last) {
3718 switch (*__first) {
3719 case '.':
3720 __push_match_any_but_newline();
3721 ++__first;
3722 break;
3723 case '\\':
3724 __first = __parse_atom_escape(__first, __last);
3725 break;
3726 case '[':
3727 __first = __parse_bracket_expression(__first, __last);
3728 break;
3729 case '(': {
3730 ++__first;
3731 if (__first == __last)
3732 std::__throw_regex_error<regex_constants::error_paren>();
3733 _ForwardIterator __temp = std::next(__first);
3734 if (__temp != __last && *__first == '?' && *__temp == ':') {
3735 ++__open_count_;
3736 __first = __parse_ecma_exp(++__temp, __last);
3737 if (__first == __last || *__first != ')')
3738 std::__throw_regex_error<regex_constants::error_paren>();
3739 --__open_count_;
3740 ++__first;
3741 } else {
3742 __push_begin_marked_subexpression();
3743 unsigned __temp_count = __marked_count_;
3744 ++__open_count_;
3745 __first = __parse_ecma_exp(__first, __last);
3746 if (__first == __last || *__first != ')')
3747 std::__throw_regex_error<regex_constants::error_paren>();
3748 __push_end_marked_subexpression(__temp_count);
3749 --__open_count_;
3750 ++__first;
3751 }
3752 } break;
3753 case '*':
3754 case '+':
3755 case '?':
3756 case '{':
3757 std::__throw_regex_error<regex_constants::error_badrepeat>();
3758 break;
3759 default:
3760 __first = __parse_pattern_character(__first, __last);
3761 break;
3762 }
3763 }
3764 return __first;
3765}
3766
3767template <class _CharT, class _Traits>
3768template <class _ForwardIterator>
3769_ForwardIterator basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last) {
3770 if (__first != __last && *__first == '\\') {
3771 _ForwardIterator __t1 = std::next(__first);
3772 if (__t1 == __last)
3773 std::__throw_regex_error<regex_constants::error_escape>();
3774
3775 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
3776 if (__t2 != __t1)
3777 __first = __t2;
3778 else {
3779 __t2 = __parse_character_class_escape(__t1, __last);
3780 if (__t2 != __t1)
3781 __first = __t2;
3782 else {
3783 __t2 = __parse_character_escape(__t1, __last);
3784 if (__t2 != __t1)
3785 __first = __t2;
3786 }
3787 }
3788 }
3789 return __first;
3790}
3791
3792template <class _CharT, class _Traits>
3793template <class _ForwardIterator>
3794_ForwardIterator
3795basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last) {
3796 if (__first != __last) {
3797 if (*__first == '0') {
3798 __push_char(c: _CharT());
3799 ++__first;
3800 } else if ('1' <= *__first && *__first <= '9') {
3801 unsigned __v = *__first - '0';
3802 for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; ++__first) {
3803 if (__v >= numeric_limits<unsigned>::max() / 10)
3804 std::__throw_regex_error<regex_constants::error_backref>();
3805 __v = 10 * __v + *__first - '0';
3806 }
3807 if (__v == 0 || __v > mark_count())
3808 std::__throw_regex_error<regex_constants::error_backref>();
3809 __push_back_ref(i: __v);
3810 }
3811 }
3812 return __first;
3813}
3814
3815template <class _CharT, class _Traits>
3816template <class _ForwardIterator>
3817_ForwardIterator
3818basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last) {
3819 if (__first != __last) {
3820 __bracket_expression<_CharT, _Traits>* __ml;
3821 switch (*__first) {
3822 case 'd':
3823 __ml = __start_matching_list(negate: false);
3824 __ml->__add_class(ctype_base::digit);
3825 ++__first;
3826 break;
3827 case 'D':
3828 __ml = __start_matching_list(negate: true);
3829 __ml->__add_class(ctype_base::digit);
3830 ++__first;
3831 break;
3832 case 's':
3833 __ml = __start_matching_list(negate: false);
3834 __ml->__add_class(ctype_base::space);
3835 ++__first;
3836 break;
3837 case 'S':
3838 __ml = __start_matching_list(negate: true);
3839 __ml->__add_class(ctype_base::space);
3840 ++__first;
3841 break;
3842 case 'w':
3843 __ml = __start_matching_list(negate: false);
3844 __ml->__add_class(ctype_base::alnum);
3845 __ml->__add_char('_');
3846 ++__first;
3847 break;
3848 case 'W':
3849 __ml = __start_matching_list(negate: true);
3850 __ml->__add_class(ctype_base::alnum);
3851 __ml->__add_char('_');
3852 ++__first;
3853 break;
3854 }
3855 }
3856 return __first;
3857}
3858
3859template <class _CharT, class _Traits>
3860template <class _ForwardIterator>
3861_ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
3862 _ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str) {
3863 if (__first != __last) {
3864 _ForwardIterator __t;
3865 unsigned __sum = 0;
3866 int __hd;
3867 switch (*__first) {
3868 case 'f':
3869 if (__str)
3870 *__str = _CharT(0xC);
3871 else
3872 __push_char(c: _CharT(0xC));
3873 ++__first;
3874 break;
3875 case 'n':
3876 if (__str)
3877 *__str = _CharT(0xA);
3878 else
3879 __push_char(c: _CharT(0xA));
3880 ++__first;
3881 break;
3882 case 'r':
3883 if (__str)
3884 *__str = _CharT(0xD);
3885 else
3886 __push_char(c: _CharT(0xD));
3887 ++__first;
3888 break;
3889 case 't':
3890 if (__str)
3891 *__str = _CharT(0x9);
3892 else
3893 __push_char(c: _CharT(0x9));
3894 ++__first;
3895 break;
3896 case 'v':
3897 if (__str)
3898 *__str = _CharT(0xB);
3899 else
3900 __push_char(c: _CharT(0xB));
3901 ++__first;
3902 break;
3903 case 'c':
3904 if ((__t = std::next(__first)) != __last) {
3905 if (('A' <= *__t && *__t <= 'Z') || ('a' <= *__t && *__t <= 'z')) {
3906 if (__str)
3907 *__str = _CharT(*__t % 32);
3908 else
3909 __push_char(c: _CharT(*__t % 32));
3910 __first = ++__t;
3911 } else
3912 std::__throw_regex_error<regex_constants::error_escape>();
3913 } else
3914 std::__throw_regex_error<regex_constants::error_escape>();
3915 break;
3916 case 'u':
3917 ++__first;
3918 if (__first == __last)
3919 std::__throw_regex_error<regex_constants::error_escape>();
3920 __hd = __traits_.value(*__first, 16);
3921 if (__hd == -1)
3922 std::__throw_regex_error<regex_constants::error_escape>();
3923 __sum = 16 * __sum + static_cast<unsigned>(__hd);
3924 ++__first;
3925 if (__first == __last)
3926 std::__throw_regex_error<regex_constants::error_escape>();
3927 __hd = __traits_.value(*__first, 16);
3928 if (__hd == -1)
3929 std::__throw_regex_error<regex_constants::error_escape>();
3930 __sum = 16 * __sum + static_cast<unsigned>(__hd);
3931 [[__fallthrough__]];
3932 case 'x':
3933 ++__first;
3934 if (__first == __last)
3935 std::__throw_regex_error<regex_constants::error_escape>();
3936 __hd = __traits_.value(*__first, 16);
3937 if (__hd == -1)
3938 std::__throw_regex_error<regex_constants::error_escape>();
3939 __sum = 16 * __sum + static_cast<unsigned>(__hd);
3940 ++__first;
3941 if (__first == __last)
3942 std::__throw_regex_error<regex_constants::error_escape>();
3943 __hd = __traits_.value(*__first, 16);
3944 if (__hd == -1)
3945 std::__throw_regex_error<regex_constants::error_escape>();
3946 __sum = 16 * __sum + static_cast<unsigned>(__hd);
3947 if (__str)
3948 *__str = _CharT(__sum);
3949 else
3950 __push_char(c: _CharT(__sum));
3951 ++__first;
3952 break;
3953 case '0':
3954 if (__str)
3955 *__str = _CharT(0);
3956 else
3957 __push_char(c: _CharT(0));
3958 ++__first;
3959 break;
3960 default:
3961 if (!__traits_.isctype(*__first, ctype_base::alnum)) {
3962 if (__str)
3963 *__str = *__first;
3964 else
3965 __push_char(c: *__first);
3966 ++__first;
3967 } else
3968 std::__throw_regex_error<regex_constants::error_escape>();
3969 break;
3970 }
3971 }
3972 return __first;
3973}
3974
3975template <class _CharT, class _Traits>
3976template <class _ForwardIterator>
3977_ForwardIterator
3978basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last) {
3979 if (__first != __last) {
3980 switch (*__first) {
3981 case '^':
3982 case '$':
3983 case '\\':
3984 case '.':
3985 case '*':
3986 case '+':
3987 case '?':
3988 case '(':
3989 case ')':
3990 case '[':
3991 case ']':
3992 case '{':
3993 case '}':
3994 case '|':
3995 break;
3996 default:
3997 __push_char(c: *__first);
3998 ++__first;
3999 break;
4000 }
4001 }
4002 return __first;
4003}
4004
4005template <class _CharT, class _Traits>
4006template <class _ForwardIterator>
4007_ForwardIterator basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, _ForwardIterator __last) {
4008 __owns_one_state<_CharT>* __sa = __end_;
4009 _ForwardIterator __t1 = std::find(__first, __last, _CharT('\n'));
4010 if (__t1 != __first)
4011 __parse_basic_reg_exp(__first, __t1);
4012 else
4013 __push_empty();
4014 __first = __t1;
4015 if (__first != __last)
4016 ++__first;
4017 while (__first != __last) {
4018 __t1 = std::find(__first, __last, _CharT('\n'));
4019 __owns_one_state<_CharT>* __sb = __end_;
4020 if (__t1 != __first)
4021 __parse_basic_reg_exp(__first, __t1);
4022 else
4023 __push_empty();
4024 __push_alternation(__sa, __sb);
4025 __first = __t1;
4026 if (__first != __last)
4027 ++__first;
4028 }
4029 return __first;
4030}
4031
4032template <class _CharT, class _Traits>
4033template <class _ForwardIterator>
4034_ForwardIterator basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, _ForwardIterator __last) {
4035 __owns_one_state<_CharT>* __sa = __end_;
4036 _ForwardIterator __t1 = std::find(__first, __last, _CharT('\n'));
4037 if (__t1 != __first)
4038 __parse_extended_reg_exp(__first, __t1);
4039 else
4040 __push_empty();
4041 __first = __t1;
4042 if (__first != __last)
4043 ++__first;
4044 while (__first != __last) {
4045 __t1 = std::find(__first, __last, _CharT('\n'));
4046 __owns_one_state<_CharT>* __sb = __end_;
4047 if (__t1 != __first)
4048 __parse_extended_reg_exp(__first, __t1);
4049 else
4050 __push_empty();
4051 __push_alternation(__sa, __sb);
4052 __first = __t1;
4053 if (__first != __last)
4054 ++__first;
4055 }
4056 return __first;
4057}
4058
4059template <class _CharT, class _Traits>
4060bool basic_regex<_CharT, _Traits>::__test_back_ref(_CharT __c) {
4061 unsigned __val = __traits_.value(__c, 10);
4062 if (__val >= 1 && __val <= 9) {
4063 if (__val > mark_count())
4064 std::__throw_regex_error<regex_constants::error_backref>();
4065 __push_back_ref(i: __val);
4066 return true;
4067 }
4068
4069 return false;
4070}
4071
4072template <class _CharT, class _Traits>
4073void basic_regex<_CharT, _Traits>::__push_loop(
4074 size_t __min, size_t __max, __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, bool __greedy) {
4075 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4076 __end_->first() = nullptr;
4077 unique_ptr<__loop<_CharT> > __e2(
4078 new __loop<_CharT>(__loop_count_, __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, __min, __max));
4079 __s->first() = nullptr;
4080 __e1.release();
4081 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
4082 __end_ = __e2->second();
4083 __s->first() = __e2.release();
4084 ++__loop_count_;
4085}
4086
4087template <class _CharT, class _Traits>
4088void basic_regex<_CharT, _Traits>::__push_char(value_type __c) {
4089 if (flags() & icase)
4090 __end_->first() = new __match_char_icase<_CharT, _Traits>(__traits_, __c, __end_->first());
4091 else if (flags() & collate)
4092 __end_->first() = new __match_char_collate<_CharT, _Traits>(__traits_, __c, __end_->first());
4093 else
4094 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
4095 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4096}
4097
4098template <class _CharT, class _Traits>
4099void basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() {
4100 if (!(__flags_ & nosubs)) {
4101 __end_->first() = new __begin_marked_subexpression<_CharT>(++__marked_count_, __end_->first());
4102 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4103 }
4104}
4105
4106template <class _CharT, class _Traits>
4107void basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) {
4108 if (!(__flags_ & nosubs)) {
4109 __end_->first() = new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4110 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4111 }
4112}
4113
4114template <class _CharT, class _Traits>
4115void basic_regex<_CharT, _Traits>::__push_l_anchor() {
4116 __end_->first() = new __l_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
4117 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4118}
4119
4120template <class _CharT, class _Traits>
4121void basic_regex<_CharT, _Traits>::__push_r_anchor() {
4122 __end_->first() = new __r_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
4123 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4124}
4125
4126template <class _CharT, class _Traits>
4127void basic_regex<_CharT, _Traits>::__push_match_any() {
4128 __end_->first() = new __match_any<_CharT>(__end_->first());
4129 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4130}
4131
4132template <class _CharT, class _Traits>
4133void basic_regex<_CharT, _Traits>::__push_match_any_but_newline() {
4134 __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
4135 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4136}
4137
4138template <class _CharT, class _Traits>
4139void basic_regex<_CharT, _Traits>::__push_empty() {
4140 __end_->first() = new __empty_state<_CharT>(__end_->first());
4141 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4142}
4143
4144template <class _CharT, class _Traits>
4145void basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) {
4146 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, __end_->first());
4147 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4148}
4149
4150template <class _CharT, class _Traits>
4151void basic_regex<_CharT, _Traits>::__push_back_ref(int __i) {
4152 if (flags() & icase)
4153 __end_->first() = new __back_ref_icase<_CharT, _Traits>(__traits_, __i, __end_->first());
4154 else if (flags() & collate)
4155 __end_->first() = new __back_ref_collate<_CharT, _Traits>(__traits_, __i, __end_->first());
4156 else
4157 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
4158 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4159}
4160
4161template <class _CharT, class _Traits>
4162void basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, __owns_one_state<_CharT>* __ea) {
4163 __sa->first() = new __alternate<_CharT>(
4164 static_cast<__owns_one_state<_CharT>*>(__sa->first()), static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4165 __ea->first() = nullptr;
4166 __ea->first() = new __empty_state<_CharT>(__end_->first());
4167 __end_->first() = nullptr;
4168 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4169 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4170}
4171
4172template <class _CharT, class _Traits>
4173__bracket_expression<_CharT, _Traits>* basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) {
4174 __bracket_expression<_CharT, _Traits>* __r = new __bracket_expression<_CharT, _Traits>(
4175 __traits_, __end_->first(), __negate, __flags_ & icase, __flags_ & collate);
4176 __end_->first() = __r;
4177 __end_ = __r;
4178 return __r;
4179}
4180
4181template <class _CharT, class _Traits>
4182void basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, bool __invert, unsigned __mexp) {
4183 __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, __end_->first(), __mexp);
4184 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4185}
4186
4187// sub_match
4188
4189typedef sub_match<const char*> csub_match;
4190typedef sub_match<string::const_iterator> ssub_match;
4191# if _LIBCPP_HAS_WIDE_CHARACTERS
4192typedef sub_match<const wchar_t*> wcsub_match;
4193typedef sub_match<wstring::const_iterator> wssub_match;
4194# endif
4195
4196template <class _BidirectionalIterator>
4197class _LIBCPP_PREFERRED_NAME(csub_match) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match))
4198 _LIBCPP_PREFERRED_NAME(ssub_match) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match)) sub_match
4199 : public pair<_BidirectionalIterator, _BidirectionalIterator> {
4200public:
4201 typedef _BidirectionalIterator iterator;
4202 typedef typename iterator_traits<iterator>::value_type value_type;
4203 typedef typename iterator_traits<iterator>::difference_type difference_type;
4204 typedef basic_string<value_type> string_type;
4205
4206 bool matched;
4207
4208 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR sub_match() : matched() {}
4209
4210 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI difference_type length() const {
4211 return matched ? std::distance(this->first, this->second) : 0;
4212 }
4213 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type str() const {
4214 return matched ? string_type(this->first, this->second) : string_type();
4215 }
4216 _LIBCPP_HIDE_FROM_ABI operator string_type() const { return str(); }
4217
4218 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int compare(const sub_match& __s) const { return str().compare(__s.str()); }
4219 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int compare(const string_type& __s) const { return str().compare(__s); }
4220 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI int compare(const value_type* __s) const { return str().compare(__s); }
4221
4222 _LIBCPP_HIDE_FROM_ABI void swap(sub_match& __s) _NOEXCEPT_(__is_nothrow_swappable_v<_BidirectionalIterator>) {
4223 this->pair<_BidirectionalIterator, _BidirectionalIterator>::swap(__s);
4224 std::swap(matched, __s.matched);
4225 }
4226};
4227
4228template <class _BiIter>
4229inline _LIBCPP_HIDE_FROM_ABI bool operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
4230 return __x.compare(__y) == 0;
4231}
4232
4233# if _LIBCPP_STD_VER >= 20
4234template <class _BiIter>
4235using __sub_match_cat _LIBCPP_NODEBUG =
4236 compare_three_way_result_t<basic_string<typename iterator_traits<_BiIter>::value_type>>;
4237
4238template <class _BiIter>
4239_LIBCPP_HIDE_FROM_ABI auto operator<=>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
4240 return static_cast<__sub_match_cat<_BiIter>>(__x.compare(__y) <=> 0);
4241}
4242# else // _LIBCPP_STD_VER >= 20
4243template <class _BiIter>
4244inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
4245 return !(__x == __y);
4246}
4247
4248template <class _BiIter>
4249inline _LIBCPP_HIDE_FROM_ABI bool operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
4250 return __x.compare(__y) < 0;
4251}
4252
4253template <class _BiIter>
4254inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
4255 return !(__y < __x);
4256}
4257
4258template <class _BiIter>
4259inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
4260 return !(__x < __y);
4261}
4262
4263template <class _BiIter>
4264inline _LIBCPP_HIDE_FROM_ABI bool operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
4265 return __y < __x;
4266}
4267
4268template <class _BiIter, class _ST, class _SA>
4269inline _LIBCPP_HIDE_FROM_ABI bool
4270operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4271 const sub_match<_BiIter>& __y) {
4272 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
4273}
4274
4275template <class _BiIter, class _ST, class _SA>
4276inline _LIBCPP_HIDE_FROM_ABI bool
4277operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4278 const sub_match<_BiIter>& __y) {
4279 return !(__x == __y);
4280}
4281
4282template <class _BiIter, class _ST, class _SA>
4283inline _LIBCPP_HIDE_FROM_ABI bool
4284operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4285 const sub_match<_BiIter>& __y) {
4286 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
4287}
4288
4289template <class _BiIter, class _ST, class _SA>
4290inline _LIBCPP_HIDE_FROM_ABI bool
4291operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4292 const sub_match<_BiIter>& __y) {
4293 return __y < __x;
4294}
4295
4296template <class _BiIter, class _ST, class _SA>
4297inline _LIBCPP_HIDE_FROM_ABI bool
4298operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4299 const sub_match<_BiIter>& __y) {
4300 return !(__x < __y);
4301}
4302
4303template <class _BiIter, class _ST, class _SA>
4304inline _LIBCPP_HIDE_FROM_ABI bool
4305operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4306 const sub_match<_BiIter>& __y) {
4307 return !(__y < __x);
4308}
4309# endif // _LIBCPP_STD_VER >= 20
4310
4311template <class _BiIter, class _ST, class _SA>
4312inline _LIBCPP_HIDE_FROM_ABI bool
4313operator==(const sub_match<_BiIter>& __x,
4314 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
4315 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
4316}
4317
4318# if _LIBCPP_STD_VER >= 20
4319template <class _BiIter, class _ST, class _SA>
4320_LIBCPP_HIDE_FROM_ABI auto
4321operator<=>(const sub_match<_BiIter>& __x,
4322 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
4323 return static_cast<__sub_match_cat<_BiIter>>(
4324 __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) <=> 0);
4325}
4326# else // _LIBCPP_STD_VER >= 20
4327template <class _BiIter, class _ST, class _SA>
4328inline _LIBCPP_HIDE_FROM_ABI bool
4329operator!=(const sub_match<_BiIter>& __x,
4330 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
4331 return !(__x == __y);
4332}
4333
4334template <class _BiIter, class _ST, class _SA>
4335inline _LIBCPP_HIDE_FROM_ABI bool
4336operator<(const sub_match<_BiIter>& __x,
4337 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
4338 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
4339}
4340
4341template <class _BiIter, class _ST, class _SA>
4342inline _LIBCPP_HIDE_FROM_ABI bool
4343operator>(const sub_match<_BiIter>& __x,
4344 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
4345 return __y < __x;
4346}
4347
4348template <class _BiIter, class _ST, class _SA>
4349inline _LIBCPP_HIDE_FROM_ABI bool
4350operator>=(const sub_match<_BiIter>& __x,
4351 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
4352 return !(__x < __y);
4353}
4354
4355template <class _BiIter, class _ST, class _SA>
4356inline _LIBCPP_HIDE_FROM_ABI bool
4357operator<=(const sub_match<_BiIter>& __x,
4358 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
4359 return !(__y < __x);
4360}
4361
4362template <class _BiIter>
4363inline _LIBCPP_HIDE_FROM_ABI bool
4364operator==(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
4365 return __y.compare(__x) == 0;
4366}
4367
4368template <class _BiIter>
4369inline _LIBCPP_HIDE_FROM_ABI bool
4370operator!=(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
4371 return !(__x == __y);
4372}
4373
4374template <class _BiIter>
4375inline _LIBCPP_HIDE_FROM_ABI bool
4376operator<(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
4377 return __y.compare(__x) > 0;
4378}
4379
4380template <class _BiIter>
4381inline _LIBCPP_HIDE_FROM_ABI bool
4382operator>(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
4383 return __y < __x;
4384}
4385
4386template <class _BiIter>
4387inline _LIBCPP_HIDE_FROM_ABI bool
4388operator>=(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
4389 return !(__x < __y);
4390}
4391
4392template <class _BiIter>
4393inline _LIBCPP_HIDE_FROM_ABI bool
4394operator<=(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
4395 return !(__y < __x);
4396}
4397# endif // _LIBCPP_STD_VER >= 20
4398
4399template <class _BiIter>
4400inline _LIBCPP_HIDE_FROM_ABI bool
4401operator==(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
4402 return __x.compare(__y) == 0;
4403}
4404
4405# if _LIBCPP_STD_VER >= 20
4406template <class _BiIter>
4407_LIBCPP_HIDE_FROM_ABI auto
4408operator<=>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
4409 return static_cast<__sub_match_cat<_BiIter>>(__x.compare(__y) <=> 0);
4410}
4411# else // _LIBCPP_STD_VER >= 20
4412template <class _BiIter>
4413inline _LIBCPP_HIDE_FROM_ABI bool
4414operator!=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
4415 return !(__x == __y);
4416}
4417
4418template <class _BiIter>
4419inline _LIBCPP_HIDE_FROM_ABI bool
4420operator<(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
4421 return __x.compare(__y) < 0;
4422}
4423
4424template <class _BiIter>
4425inline _LIBCPP_HIDE_FROM_ABI bool
4426operator>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
4427 return __y < __x;
4428}
4429
4430template <class _BiIter>
4431inline _LIBCPP_HIDE_FROM_ABI bool
4432operator>=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
4433 return !(__x < __y);
4434}
4435
4436template <class _BiIter>
4437inline _LIBCPP_HIDE_FROM_ABI bool
4438operator<=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
4439 return !(__y < __x);
4440}
4441
4442template <class _BiIter>
4443inline _LIBCPP_HIDE_FROM_ABI bool
4444operator==(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
4445 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4446 return __y.compare(string_type(1, __x)) == 0;
4447}
4448
4449template <class _BiIter>
4450inline _LIBCPP_HIDE_FROM_ABI bool
4451operator!=(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
4452 return !(__x == __y);
4453}
4454
4455template <class _BiIter>
4456inline _LIBCPP_HIDE_FROM_ABI bool
4457operator<(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
4458 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4459 return __y.compare(string_type(1, __x)) > 0;
4460}
4461
4462template <class _BiIter>
4463inline _LIBCPP_HIDE_FROM_ABI bool
4464operator>(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
4465 return __y < __x;
4466}
4467
4468template <class _BiIter>
4469inline _LIBCPP_HIDE_FROM_ABI bool
4470operator>=(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
4471 return !(__x < __y);
4472}
4473
4474template <class _BiIter>
4475inline _LIBCPP_HIDE_FROM_ABI bool
4476operator<=(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
4477 return !(__y < __x);
4478}
4479# endif // _LIBCPP_STD_VER >= 20
4480
4481template <class _BiIter>
4482inline _LIBCPP_HIDE_FROM_ABI bool
4483operator==(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
4484 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4485 return __x.compare(string_type(1, __y)) == 0;
4486}
4487
4488# if _LIBCPP_STD_VER >= 20
4489template <class _BiIter>
4490_LIBCPP_HIDE_FROM_ABI auto
4491operator<=>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
4492 using string_type = basic_string<typename iterator_traits<_BiIter>::value_type>;
4493 return static_cast<__sub_match_cat<_BiIter>>(__x.compare(string_type(1, __y)) <=> 0);
4494}
4495# else // _LIBCPP_STD_VER >= 20
4496template <class _BiIter>
4497inline _LIBCPP_HIDE_FROM_ABI bool
4498operator!=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
4499 return !(__x == __y);
4500}
4501
4502template <class _BiIter>
4503inline _LIBCPP_HIDE_FROM_ABI bool
4504operator<(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
4505 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
4506 return __x.compare(string_type(1, __y)) < 0;
4507}
4508
4509template <class _BiIter>
4510inline _LIBCPP_HIDE_FROM_ABI bool
4511operator>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
4512 return __y < __x;
4513}
4514
4515template <class _BiIter>
4516inline _LIBCPP_HIDE_FROM_ABI bool
4517operator>=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
4518 return !(__x < __y);
4519}
4520
4521template <class _BiIter>
4522inline _LIBCPP_HIDE_FROM_ABI bool
4523operator<=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
4524 return !(__y < __x);
4525}
4526# endif // _LIBCPP_STD_VER >= 20
4527
4528template <class _CharT, class _ST, class _BiIter>
4529inline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _ST>&
4530operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) {
4531 return __os << __m.str();
4532}
4533
4534typedef match_results<const char*> cmatch;
4535typedef match_results<string::const_iterator> smatch;
4536# if _LIBCPP_HAS_WIDE_CHARACTERS
4537typedef match_results<const wchar_t*> wcmatch;
4538typedef match_results<wstring::const_iterator> wsmatch;
4539# endif
4540
4541template <class _BidirectionalIterator, class _Allocator>
4542class _LIBCPP_PREFERRED_NAME(cmatch) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch))
4543 _LIBCPP_PREFERRED_NAME(smatch) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch)) match_results {
4544public:
4545 typedef _Allocator allocator_type;
4546 typedef sub_match<_BidirectionalIterator> value_type;
4547
4548private:
4549 typedef vector<value_type, allocator_type> __container_type;
4550
4551 __container_type __matches_;
4552 value_type __unmatched_;
4553 value_type __prefix_;
4554 value_type __suffix_;
4555 bool __ready_;
4556
4557public:
4558 _BidirectionalIterator __position_start_;
4559 typedef const value_type& const_reference;
4560 typedef value_type& reference;
4561 typedef typename __container_type::const_iterator const_iterator;
4562 typedef const_iterator iterator;
4563 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
4564 typedef typename allocator_traits<allocator_type>::size_type size_type;
4565 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
4566 typedef basic_string<char_type> string_type;
4567
4568 // construct/copy/destroy:
4569# ifndef _LIBCPP_CXX03_LANG
4570 match_results() : match_results(allocator_type()) {}
4571 explicit match_results(const allocator_type& __a);
4572# else
4573 explicit match_results(const allocator_type& __a = allocator_type());
4574# endif
4575
4576 // match_results(const match_results&) = default;
4577 // match_results& operator=(const match_results&) = default;
4578 // match_results(match_results&& __m) = default;
4579 // match_results& operator=(match_results&& __m) = default;
4580 // ~match_results() = default;
4581
4582 _LIBCPP_HIDE_FROM_ABI bool ready() const { return __ready_; }
4583
4584 // size:
4585 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __matches_.size(); }
4586 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __matches_.max_size(); }
4587 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return size() == 0; }
4588
4589 // element access:
4590 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI difference_type length(size_type __sub = 0) const {
4591 // If the match results are not ready, this will return `0`.
4592 _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::length() called when not ready");
4593 return (*this)[__sub].length();
4594 }
4595 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI difference_type position(size_type __sub = 0) const {
4596 // If the match results are not ready, this will return the result of subtracting two default-constructed iterators
4597 // (which is typically a well-defined operation).
4598 _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::position() called when not ready");
4599 return std::distance(__position_start_, (*this)[__sub].first);
4600 }
4601 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type str(size_type __sub = 0) const {
4602 // If the match results are not ready, this will return an empty string.
4603 _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::str() called when not ready");
4604 return (*this)[__sub].str();
4605 }
4606 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const {
4607 // If the match results are not ready, this call will be equivalent to calling this function with `__n >= size()`,
4608 // returning an empty subrange.
4609 _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::operator[]() called when not ready");
4610 return __n < __matches_.size() ? __matches_[__n] : __unmatched_;
4611 }
4612
4613 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reference prefix() const {
4614 // If the match results are not ready, this will return a default-constructed empty `__suffix_`.
4615 _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::prefix() called when not ready");
4616 return __prefix_;
4617 }
4618 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_reference suffix() const {
4619 // If the match results are not ready, this will return a default-constructed empty `__suffix_`.
4620 _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::suffix() called when not ready");
4621 return __suffix_;
4622 }
4623
4624 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_iterator begin() const {
4625 return empty() ? __matches_.end() : __matches_.begin();
4626 }
4627 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __matches_.end(); }
4628 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const {
4629 return empty() ? __matches_.end() : __matches_.begin();
4630 }
4631 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const_iterator cend() const { return __matches_.end(); }
4632
4633 // format:
4634 template <class _OutputIter>
4635 _OutputIter format(_OutputIter __output_iter,
4636 const char_type* __fmt_first,
4637 const char_type* __fmt_last,
4638 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
4639 template <class _OutputIter, class _ST, class _SA>
4640 _LIBCPP_HIDE_FROM_ABI _OutputIter
4641 format(_OutputIter __output_iter,
4642 const basic_string<char_type, _ST, _SA>& __fmt,
4643 regex_constants::match_flag_type __flags = regex_constants::format_default) const {
4644 return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);
4645 }
4646 template <class _ST, class _SA>
4647 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI basic_string<char_type, _ST, _SA>
4648 format(const basic_string<char_type, _ST, _SA>& __fmt,
4649 regex_constants::match_flag_type __flags = regex_constants::format_default) const {
4650 basic_string<char_type, _ST, _SA> __r;
4651 format(std::back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), __flags);
4652 return __r;
4653 }
4654 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI string_type
4655 format(const char_type* __fmt, regex_constants::match_flag_type __flags = regex_constants::format_default) const {
4656 string_type __r;
4657 format(std::back_inserter(__r), __fmt, __fmt + char_traits<char_type>::length(__fmt), __flags);
4658 return __r;
4659 }
4660
4661 // allocator:
4662 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const { return __matches_.get_allocator(); }
4663
4664 // swap:
4665 void swap(match_results& __m);
4666
4667 template <class _Bp, class _Ap>
4668 _LIBCPP_HIDE_FROM_ABI void
4669 __assign(_BidirectionalIterator __f,
4670 _BidirectionalIterator __l,
4671 const match_results<_Bp, _Ap>& __m,
4672 bool __no_update_pos) {
4673 _Bp __mf = __m.prefix().first;
4674 __matches_.resize(__m.size());
4675 for (size_type __i = 0; __i < __matches_.size(); ++__i) {
4676 __matches_[__i].first = std::next(__f, std::distance(__mf, __m[__i].first));
4677 __matches_[__i].second = std::next(__f, std::distance(__mf, __m[__i].second));
4678 __matches_[__i].matched = __m[__i].matched;
4679 }
4680 __unmatched_.first = __l;
4681 __unmatched_.second = __l;
4682 __unmatched_.matched = false;
4683 __prefix_.first = std::next(__f, std::distance(__mf, __m.prefix().first));
4684 __prefix_.second = std::next(__f, std::distance(__mf, __m.prefix().second));
4685 __prefix_.matched = __m.prefix().matched;
4686 __suffix_.first = std::next(__f, std::distance(__mf, __m.suffix().first));
4687 __suffix_.second = std::next(__f, std::distance(__mf, __m.suffix().second));
4688 __suffix_.matched = __m.suffix().matched;
4689 if (!__no_update_pos)
4690 __position_start_ = __prefix_.first;
4691 __ready_ = __m.ready();
4692 }
4693
4694private:
4695 void __init(unsigned __s, _BidirectionalIterator __f, _BidirectionalIterator __l, bool __no_update_pos = false);
4696
4697 template <class, class>
4698 friend class basic_regex;
4699
4700 template <class _Bp, class _Ap, class _Cp, class _Tp>
4701 friend bool
4702 regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
4703
4704 template <class _Bp, class _Ap>
4705 friend bool operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
4706
4707 template <class, class>
4708 friend class __lookahead;
4709
4710 template <class, class, class>
4711 friend class regex_iterator;
4712};
4713
4714template <class _BidirectionalIterator, class _Allocator>
4715match_results<_BidirectionalIterator, _Allocator>::match_results(const allocator_type& __a)
4716 : __matches_(__a), __unmatched_(), __prefix_(), __suffix_(), __ready_(false), __position_start_() {}
4717
4718template <class _BidirectionalIterator, class _Allocator>
4719void match_results<_BidirectionalIterator, _Allocator>::__init(
4720 unsigned __s, _BidirectionalIterator __f, _BidirectionalIterator __l, bool __no_update_pos) {
4721 __unmatched_.first = __l;
4722 __unmatched_.second = __l;
4723 __unmatched_.matched = false;
4724 __matches_.assign(__s, __unmatched_);
4725 __prefix_.first = __f;
4726 __prefix_.second = __f;
4727 __prefix_.matched = false;
4728 __suffix_ = __unmatched_;
4729 if (!__no_update_pos)
4730 __position_start_ = __prefix_.first;
4731 __ready_ = true;
4732}
4733
4734template <class _BidirectionalIterator, class _Allocator>
4735template <class _OutputIter>
4736_OutputIter match_results<_BidirectionalIterator, _Allocator>::format(
4737 _OutputIter __output_iter,
4738 const char_type* __fmt_first,
4739 const char_type* __fmt_last,
4740 regex_constants::match_flag_type __flags) const {
4741 // Note: this duplicates a check in `vector::operator[]` but provides a better error message.
4742 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(ready(), "match_results::format() called when not ready");
4743 if (__flags & regex_constants::format_sed) {
4744 for (; __fmt_first != __fmt_last; ++__fmt_first) {
4745 if (*__fmt_first == '&')
4746 __output_iter = std::copy(__matches_[0].first, __matches_[0].second, __output_iter);
4747 else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) {
4748 ++__fmt_first;
4749 if ('0' <= *__fmt_first && *__fmt_first <= '9') {
4750 size_t __i = *__fmt_first - '0';
4751 __output_iter = std::copy((*this)[__i].first, (*this)[__i].second, __output_iter);
4752 } else {
4753 *__output_iter = *__fmt_first;
4754 ++__output_iter;
4755 }
4756 } else {
4757 *__output_iter = *__fmt_first;
4758 ++__output_iter;
4759 }
4760 }
4761 } else {
4762 for (; __fmt_first != __fmt_last; ++__fmt_first) {
4763 if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) {
4764 switch (__fmt_first[1]) {
4765 case '$':
4766 *__output_iter = *++__fmt_first;
4767 ++__output_iter;
4768 break;
4769 case '&':
4770 ++__fmt_first;
4771 __output_iter = std::copy(__matches_[0].first, __matches_[0].second, __output_iter);
4772 break;
4773 case '`':
4774 ++__fmt_first;
4775 __output_iter = std::copy(__prefix_.first, __prefix_.second, __output_iter);
4776 break;
4777 case '\'':
4778 ++__fmt_first;
4779 __output_iter = std::copy(__suffix_.first, __suffix_.second, __output_iter);
4780 break;
4781 default:
4782 if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') {
4783 ++__fmt_first;
4784 size_t __idx = *__fmt_first - '0';
4785 if (__fmt_first + 1 != __fmt_last && '0' <= __fmt_first[1] && __fmt_first[1] <= '9') {
4786 ++__fmt_first;
4787 if (__idx >= numeric_limits<size_t>::max() / 10)
4788 std::__throw_regex_error<regex_constants::error_escape>();
4789 __idx = 10 * __idx + *__fmt_first - '0';
4790 }
4791 __output_iter = std::copy((*this)[__idx].first, (*this)[__idx].second, __output_iter);
4792 } else {
4793 *__output_iter = *__fmt_first;
4794 ++__output_iter;
4795 }
4796 break;
4797 }
4798 } else {
4799 *__output_iter = *__fmt_first;
4800 ++__output_iter;
4801 }
4802 }
4803 }
4804 return __output_iter;
4805}
4806
4807template <class _BidirectionalIterator, class _Allocator>
4808void match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) {
4809 using std::swap;
4810 swap(__matches_, __m.__matches_);
4811 swap(__unmatched_, __m.__unmatched_);
4812 swap(__prefix_, __m.__prefix_);
4813 swap(__suffix_, __m.__suffix_);
4814 swap(__position_start_, __m.__position_start_);
4815 swap(__ready_, __m.__ready_);
4816}
4817
4818template <class _BidirectionalIterator, class _Allocator>
4819_LIBCPP_HIDE_FROM_ABI bool operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
4820 const match_results<_BidirectionalIterator, _Allocator>& __y) {
4821 if (__x.__ready_ != __y.__ready_)
4822 return false;
4823 if (!__x.__ready_)
4824 return true;
4825 return __x.__matches_ == __y.__matches_ && __x.__prefix_ == __y.__prefix_ && __x.__suffix_ == __y.__suffix_;
4826}
4827
4828# if _LIBCPP_STD_VER < 20
4829template <class _BidirectionalIterator, class _Allocator>
4830inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
4831 const match_results<_BidirectionalIterator, _Allocator>& __y) {
4832 return !(__x == __y);
4833}
4834# endif
4835
4836template <class _BidirectionalIterator, class _Allocator>
4837inline _LIBCPP_HIDE_FROM_ABI void
4838swap(match_results<_BidirectionalIterator, _Allocator>& __x, match_results<_BidirectionalIterator, _Allocator>& __y) {
4839 __x.swap(__y);
4840}
4841
4842// regex_search
4843
4844template <class _CharT, class _Traits>
4845template <class _Allocator>
4846bool basic_regex<_CharT, _Traits>::__match_at_start_ecma(
4847 const _CharT* __first,
4848 const _CharT* __last,
4849 match_results<const _CharT*, _Allocator>& __m,
4850 regex_constants::match_flag_type __flags,
4851 bool __at_first) const {
4852 vector<__state> __states;
4853 __node* __st = __start_.get();
4854 if (__st) {
4855 sub_match<const _CharT*> __unmatched;
4856 __unmatched.first = __last;
4857 __unmatched.second = __last;
4858 __unmatched.matched = false;
4859
4860 __states.push_back(__state());
4861 __states.back().__do_ = 0;
4862 __states.back().__first_ = __first;
4863 __states.back().__current_ = __first;
4864 __states.back().__last_ = __last;
4865 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
4866 __states.back().__loop_data_.resize(__loop_count());
4867 __states.back().__node_ = __st;
4868 __states.back().__flags_ = __flags;
4869 __states.back().__at_first_ = __at_first;
4870 int __counter = 0;
4871 int __length = __last - __first;
4872 do {
4873 ++__counter;
4874 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
4875 std::__throw_regex_error<regex_constants::error_complexity>();
4876 __state& __s = __states.back();
4877 if (__s.__node_)
4878 __s.__node_->__exec(__s);
4879 switch (__s.__do_) {
4880 case __state::__end_state:
4881 if ((__flags & regex_constants::match_not_null) && __s.__current_ == __first) {
4882 __states.pop_back();
4883 break;
4884 }
4885 if ((__flags & regex_constants::__full_match) && __s.__current_ != __last) {
4886 __states.pop_back();
4887 break;
4888 }
4889 __m.__matches_[0].first = __first;
4890 __m.__matches_[0].second = std::next(__first, __s.__current_ - __first);
4891 __m.__matches_[0].matched = true;
4892 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
4893 __m.__matches_[__i + 1] = __s.__sub_matches_[__i];
4894 return true;
4895 case __state::__accept_and_consume:
4896 case __state::__repeat:
4897 case __state::__accept_but_not_consume:
4898 break;
4899 case __state::__split: {
4900 __state __snext = __s;
4901 __s.__node_->__exec_split(true, __s);
4902 __snext.__node_->__exec_split(false, __snext);
4903 __states.push_back(std::move(__snext));
4904 } break;
4905 case __state::__reject:
4906 __states.pop_back();
4907 break;
4908 default:
4909 std::__throw_regex_error<regex_constants::__re_err_unknown>();
4910 break;
4911 }
4912 } while (!__states.empty());
4913 }
4914 return false;
4915}
4916
4917template <class _CharT, class _Traits>
4918template <class _Allocator>
4919bool basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
4920 const _CharT* __first,
4921 const _CharT* __last,
4922 match_results<const _CharT*, _Allocator>& __m,
4923 regex_constants::match_flag_type __flags,
4924 bool __at_first) const {
4925 deque<__state> __states;
4926 ptrdiff_t __highest_j = 0;
4927 ptrdiff_t __np = std::distance(__first, __last);
4928 __node* __st = __start_.get();
4929 if (__st) {
4930 __states.push_back(__state());
4931 __states.back().__do_ = 0;
4932 __states.back().__first_ = __first;
4933 __states.back().__current_ = __first;
4934 __states.back().__last_ = __last;
4935 __states.back().__loop_data_.resize(__loop_count());
4936 __states.back().__node_ = __st;
4937 __states.back().__flags_ = __flags;
4938 __states.back().__at_first_ = __at_first;
4939 bool __matched = false;
4940 int __counter = 0;
4941 int __length = __last - __first;
4942 do {
4943 ++__counter;
4944 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
4945 std::__throw_regex_error<regex_constants::error_complexity>();
4946 __state& __s = __states.back();
4947 if (__s.__node_)
4948 __s.__node_->__exec(__s);
4949 switch (__s.__do_) {
4950 case __state::__end_state:
4951 if ((__flags & regex_constants::match_not_null) && __s.__current_ == __first) {
4952 __states.pop_back();
4953 break;
4954 }
4955 if ((__flags & regex_constants::__full_match) && __s.__current_ != __last) {
4956 __states.pop_back();
4957 break;
4958 }
4959 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
4960 __highest_j = __s.__current_ - __s.__first_;
4961 __matched = true;
4962 if (__highest_j == __np)
4963 __states.clear();
4964 else
4965 __states.pop_back();
4966 break;
4967 case __state::__consume_input:
4968 break;
4969 case __state::__accept_and_consume:
4970 __states.push_front(std::move(__s));
4971 __states.pop_back();
4972 break;
4973 case __state::__repeat:
4974 case __state::__accept_but_not_consume:
4975 break;
4976 case __state::__split: {
4977 __state __snext = __s;
4978 __s.__node_->__exec_split(true, __s);
4979 __snext.__node_->__exec_split(false, __snext);
4980 __states.push_back(std::move(__snext));
4981 } break;
4982 case __state::__reject:
4983 __states.pop_back();
4984 break;
4985 default:
4986 std::__throw_regex_error<regex_constants::__re_err_unknown>();
4987 break;
4988 }
4989 } while (!__states.empty());
4990 if (__matched) {
4991 __m.__matches_[0].first = __first;
4992 __m.__matches_[0].second = std::next(__first, __highest_j);
4993 __m.__matches_[0].matched = true;
4994 return true;
4995 }
4996 }
4997 return false;
4998}
4999
5000template <class _CharT, class _Traits>
5001template <class _Allocator>
5002bool basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
5003 const _CharT* __first,
5004 const _CharT* __last,
5005 match_results<const _CharT*, _Allocator>& __m,
5006 regex_constants::match_flag_type __flags,
5007 bool __at_first) const {
5008 vector<__state> __states;
5009 __state __best_state;
5010 ptrdiff_t __highest_j = 0;
5011 ptrdiff_t __np = std::distance(__first, __last);
5012 __node* __st = __start_.get();
5013 if (__st) {
5014 sub_match<const _CharT*> __unmatched;
5015 __unmatched.first = __last;
5016 __unmatched.second = __last;
5017 __unmatched.matched = false;
5018
5019 __states.push_back(__state());
5020 __states.back().__do_ = 0;
5021 __states.back().__first_ = __first;
5022 __states.back().__current_ = __first;
5023 __states.back().__last_ = __last;
5024 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
5025 __states.back().__loop_data_.resize(__loop_count());
5026 __states.back().__node_ = __st;
5027 __states.back().__flags_ = __flags;
5028 __states.back().__at_first_ = __at_first;
5029 bool __matched = false;
5030 int __counter = 0;
5031 int __length = __last - __first;
5032 do {
5033 ++__counter;
5034 if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
5035 std::__throw_regex_error<regex_constants::error_complexity>();
5036 __state& __s = __states.back();
5037 if (__s.__node_)
5038 __s.__node_->__exec(__s);
5039 switch (__s.__do_) {
5040 case __state::__end_state:
5041 if ((__flags & regex_constants::match_not_null) && __s.__current_ == __first) {
5042 __states.pop_back();
5043 break;
5044 }
5045 if ((__flags & regex_constants::__full_match) && __s.__current_ != __last) {
5046 __states.pop_back();
5047 break;
5048 }
5049 if (!__matched || __highest_j < __s.__current_ - __s.__first_) {
5050 __highest_j = __s.__current_ - __s.__first_;
5051 __best_state = __s;
5052 }
5053 __matched = true;
5054 if (__highest_j == __np)
5055 __states.clear();
5056 else
5057 __states.pop_back();
5058 break;
5059 case __state::__accept_and_consume:
5060 case __state::__repeat:
5061 case __state::__accept_but_not_consume:
5062 break;
5063 case __state::__split: {
5064 __state __snext = __s;
5065 __s.__node_->__exec_split(true, __s);
5066 __snext.__node_->__exec_split(false, __snext);
5067 __states.push_back(std::move(__snext));
5068 } break;
5069 case __state::__reject:
5070 __states.pop_back();
5071 break;
5072 default:
5073 std::__throw_regex_error<regex_constants::__re_err_unknown>();
5074 break;
5075 }
5076 } while (!__states.empty());
5077 if (__matched) {
5078 __m.__matches_[0].first = __first;
5079 __m.__matches_[0].second = std::next(__first, __highest_j);
5080 __m.__matches_[0].matched = true;
5081 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
5082 __m.__matches_[__i + 1] = __best_state.__sub_matches_[__i];
5083 return true;
5084 }
5085 }
5086 return false;
5087}
5088
5089template <class _CharT, class _Traits>
5090template <class _Allocator>
5091bool basic_regex<_CharT, _Traits>::__match_at_start(
5092 const _CharT* __first,
5093 const _CharT* __last,
5094 match_results<const _CharT*, _Allocator>& __m,
5095 regex_constants::match_flag_type __flags,
5096 bool __at_first) const {
5097 if (__get_grammar(g: __flags_) == ECMAScript)
5098 return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
5099 if (mark_count() == 0)
5100 return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
5101 return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
5102}
5103
5104template <class _CharT, class _Traits>
5105template <class _Allocator>
5106bool basic_regex<_CharT, _Traits>::__search(
5107 const _CharT* __first,
5108 const _CharT* __last,
5109 match_results<const _CharT*, _Allocator>& __m,
5110 regex_constants::match_flag_type __flags) const {
5111 if (__flags & regex_constants::match_prev_avail)
5112 __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow);
5113
5114 __m.__init(1 + mark_count(), __first, __last, __flags & regex_constants::__no_update_pos);
5115 if (__match_at_start(__first, __last, __m, __flags, !(__flags & regex_constants::__no_update_pos))) {
5116 __m.__prefix_.second = __m[0].first;
5117 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5118 __m.__suffix_.first = __m[0].second;
5119 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5120 return true;
5121 }
5122 if (__first != __last && !(__flags & regex_constants::match_continuous)) {
5123 __flags |= regex_constants::match_prev_avail;
5124 for (++__first; __first != __last; ++__first) {
5125 __m.__matches_.assign(__m.size(), __m.__unmatched_);
5126 if (__match_at_start(__first, __last, __m, __flags, false)) {
5127 __m.__prefix_.second = __m[0].first;
5128 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5129 __m.__suffix_.first = __m[0].second;
5130 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5131 return true;
5132 }
5133 __m.__matches_.assign(__m.size(), __m.__unmatched_);
5134 }
5135 __m.__matches_.assign(__m.size(), __m.__unmatched_);
5136 if (__match_at_start(__first, __last, __m, __flags, false)) {
5137 __m.__prefix_.second = __m[0].first;
5138 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5139 __m.__suffix_.first = __m[0].second;
5140 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5141 return true;
5142 }
5143 }
5144 __m.__matches_.clear();
5145 return false;
5146}
5147
5148template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5149inline _LIBCPP_HIDE_FROM_ABI bool
5150regex_search(_BidirectionalIterator __first,
5151 _BidirectionalIterator __last,
5152 match_results<_BidirectionalIterator, _Allocator>& __m,
5153 const basic_regex<_CharT, _Traits>& __e,
5154 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5155 int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
5156 basic_string<_CharT> __s(std::prev(__first, __offset), __last);
5157 match_results<const _CharT*> __mc;
5158 bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
5159 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
5160 return __r;
5161}
5162
5163template <class _Iter, class _Allocator, class _CharT, class _Traits>
5164inline _LIBCPP_HIDE_FROM_ABI bool
5165regex_search(__wrap_iter<_Iter> __first,
5166 __wrap_iter<_Iter> __last,
5167 match_results<__wrap_iter<_Iter>, _Allocator>& __m,
5168 const basic_regex<_CharT, _Traits>& __e,
5169 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5170 match_results<const _CharT*> __mc;
5171 bool __r = __e.__search(std::__to_address(__first), std::__to_address(__last), __mc, __flags);
5172 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
5173 return __r;
5174}
5175
5176template <class _Allocator, class _CharT, class _Traits>
5177inline _LIBCPP_HIDE_FROM_ABI bool
5178regex_search(const _CharT* __first,
5179 const _CharT* __last,
5180 match_results<const _CharT*, _Allocator>& __m,
5181 const basic_regex<_CharT, _Traits>& __e,
5182 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5183 return __e.__search(__first, __last, __m, __flags);
5184}
5185
5186template <class _BidirectionalIterator, class _CharT, class _Traits>
5187inline _LIBCPP_HIDE_FROM_ABI bool
5188regex_search(_BidirectionalIterator __first,
5189 _BidirectionalIterator __last,
5190 const basic_regex<_CharT, _Traits>& __e,
5191 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5192 basic_string<_CharT> __s(__first, __last);
5193 match_results<const _CharT*> __mc;
5194 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5195}
5196
5197template <class _CharT, class _Traits>
5198inline _LIBCPP_HIDE_FROM_ABI bool
5199regex_search(const _CharT* __first,
5200 const _CharT* __last,
5201 const basic_regex<_CharT, _Traits>& __e,
5202 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5203 match_results<const _CharT*> __mc;
5204 return __e.__search(__first, __last, __mc, __flags);
5205}
5206
5207template <class _CharT, class _Allocator, class _Traits>
5208inline _LIBCPP_HIDE_FROM_ABI bool
5209regex_search(const _CharT* __str,
5210 match_results<const _CharT*, _Allocator>& __m,
5211 const basic_regex<_CharT, _Traits>& __e,
5212 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5213 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
5214}
5215
5216template <class _CharT, class _Traits>
5217inline _LIBCPP_HIDE_FROM_ABI bool
5218regex_search(const _CharT* __str,
5219 const basic_regex<_CharT, _Traits>& __e,
5220 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5221 match_results<const _CharT*> __m;
5222 return std::regex_search(__str, __m, __e, __flags);
5223}
5224
5225template <class _ST, class _SA, class _CharT, class _Traits>
5226inline _LIBCPP_HIDE_FROM_ABI bool
5227regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5228 const basic_regex<_CharT, _Traits>& __e,
5229 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5230 match_results<const _CharT*> __mc;
5231 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5232}
5233
5234template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5235inline _LIBCPP_HIDE_FROM_ABI bool
5236regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5237 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5238 const basic_regex<_CharT, _Traits>& __e,
5239 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5240 match_results<const _CharT*> __mc;
5241 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5242 __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
5243 return __r;
5244}
5245
5246# if _LIBCPP_STD_VER >= 14
5247template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
5248bool regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
5249 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
5250 const basic_regex<_Cp, _Tp>& __e,
5251 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5252# endif
5253
5254// regex_match
5255
5256template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5257_LIBCPP_HIDE_FROM_ABI bool
5258regex_match(_BidirectionalIterator __first,
5259 _BidirectionalIterator __last,
5260 match_results<_BidirectionalIterator, _Allocator>& __m,
5261 const basic_regex<_CharT, _Traits>& __e,
5262 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5263 bool __r = std::regex_search(
5264 __first, __last, __m, __e, __flags | regex_constants::match_continuous | regex_constants::__full_match);
5265 if (__r) {
5266 __r = !__m.suffix().matched;
5267 if (!__r)
5268 __m.__matches_.clear();
5269 }
5270 return __r;
5271}
5272
5273template <class _BidirectionalIterator, class _CharT, class _Traits>
5274inline _LIBCPP_HIDE_FROM_ABI bool
5275regex_match(_BidirectionalIterator __first,
5276 _BidirectionalIterator __last,
5277 const basic_regex<_CharT, _Traits>& __e,
5278 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5279 match_results<_BidirectionalIterator> __m;
5280 return std::regex_match(__first, __last, __m, __e, __flags);
5281}
5282
5283template <class _CharT, class _Allocator, class _Traits>
5284inline _LIBCPP_HIDE_FROM_ABI bool
5285regex_match(const _CharT* __str,
5286 match_results<const _CharT*, _Allocator>& __m,
5287 const basic_regex<_CharT, _Traits>& __e,
5288 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5289 return std::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
5290}
5291
5292template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5293inline _LIBCPP_HIDE_FROM_ABI bool
5294regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5295 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5296 const basic_regex<_CharT, _Traits>& __e,
5297 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5298 return std::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
5299}
5300
5301# if _LIBCPP_STD_VER >= 14
5302template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5303inline _LIBCPP_HIDE_FROM_ABI bool
5304regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
5305 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5306 const basic_regex<_CharT, _Traits>& __e,
5307 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5308# endif
5309
5310template <class _CharT, class _Traits>
5311inline _LIBCPP_HIDE_FROM_ABI bool
5312regex_match(const _CharT* __str,
5313 const basic_regex<_CharT, _Traits>& __e,
5314 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5315 return std::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
5316}
5317
5318template <class _ST, class _SA, class _CharT, class _Traits>
5319inline _LIBCPP_HIDE_FROM_ABI bool
5320regex_match(const basic_string<_CharT, _ST, _SA>& __s,
5321 const basic_regex<_CharT, _Traits>& __e,
5322 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5323 return std::regex_match(__s.begin(), __s.end(), __e, __flags);
5324}
5325
5326// regex_iterator
5327
5328template <class _BidirectionalIterator,
5329 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
5330 class _Traits = regex_traits<_CharT> >
5331class regex_iterator;
5332
5333typedef regex_iterator<const char*> cregex_iterator;
5334typedef regex_iterator<string::const_iterator> sregex_iterator;
5335# if _LIBCPP_HAS_WIDE_CHARACTERS
5336typedef regex_iterator<const wchar_t*> wcregex_iterator;
5337typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
5338# endif
5339
5340template <class _BidirectionalIterator, class _CharT, class _Traits>
5341class _LIBCPP_PREFERRED_NAME(cregex_iterator) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator))
5342 _LIBCPP_PREFERRED_NAME(sregex_iterator)
5343 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator)) regex_iterator {
5344public:
5345 typedef basic_regex<_CharT, _Traits> regex_type;
5346 typedef match_results<_BidirectionalIterator> value_type;
5347 typedef ptrdiff_t difference_type;
5348 typedef const value_type* pointer;
5349 typedef const value_type& reference;
5350 typedef forward_iterator_tag iterator_category;
5351# if _LIBCPP_STD_VER >= 20
5352 typedef input_iterator_tag iterator_concept;
5353# endif
5354
5355private:
5356 _BidirectionalIterator __begin_;
5357 _BidirectionalIterator __end_;
5358 const regex_type* __pregex_;
5359 regex_constants::match_flag_type __flags_;
5360 value_type __match_;
5361
5362public:
5363 regex_iterator();
5364 regex_iterator(_BidirectionalIterator __a,
5365 _BidirectionalIterator __b,
5366 const regex_type& __re,
5367 regex_constants::match_flag_type __m = regex_constants::match_default);
5368# if _LIBCPP_STD_VER >= 14
5369 regex_iterator(_BidirectionalIterator __a,
5370 _BidirectionalIterator __b,
5371 const regex_type&& __re,
5372 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5373# endif
5374
5375 _LIBCPP_HIDE_FROM_ABI bool operator==(const regex_iterator& __x) const;
5376# if _LIBCPP_STD_VER >= 20
5377 _LIBCPP_HIDE_FROM_ABI bool operator==(default_sentinel_t) const { return *this == regex_iterator(); }
5378# endif
5379# if _LIBCPP_STD_VER < 20
5380 _LIBCPP_HIDE_FROM_ABI bool operator!=(const regex_iterator& __x) const { return !(*this == __x); }
5381# endif
5382
5383 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __match_; }
5384 _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return std::addressof(__match_); }
5385
5386 regex_iterator& operator++();
5387 _LIBCPP_HIDE_FROM_ABI regex_iterator operator++(int) {
5388 regex_iterator __t(*this);
5389 ++(*this);
5390 return __t;
5391 }
5392};
5393
5394template <class _BidirectionalIterator, class _CharT, class _Traits>
5395regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
5396 : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() {}
5397
5398template <class _BidirectionalIterator, class _CharT, class _Traits>
5399regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator(
5400 _BidirectionalIterator __a,
5401 _BidirectionalIterator __b,
5402 const regex_type& __re,
5403 regex_constants::match_flag_type __m)
5404 : __begin_(__a), __end_(__b), __pregex_(std::addressof(__re)), __flags_(__m) {
5405 std::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
5406}
5407
5408template <class _BidirectionalIterator, class _CharT, class _Traits>
5409bool regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator==(const regex_iterator& __x) const {
5410 if (__match_.empty() && __x.__match_.empty())
5411 return true;
5412 if (__match_.empty() || __x.__match_.empty())
5413 return false;
5414 return __begin_ == __x.__begin_ && __end_ == __x.__end_ && __pregex_ == __x.__pregex_ && __flags_ == __x.__flags_ &&
5415 __match_[0] == __x.__match_[0];
5416}
5417
5418template <class _BidirectionalIterator, class _CharT, class _Traits>
5419regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
5420regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() {
5421 __flags_ |= regex_constants::__no_update_pos;
5422 _BidirectionalIterator __start = __match_[0].second;
5423 _BidirectionalIterator __prefix_start = __start;
5424
5425 if (__match_[0].first == __match_[0].second) {
5426 if (__start == __end_) {
5427 __match_ = value_type();
5428 return *this;
5429 } else if (std::regex_search(__start,
5430 __end_,
5431 __match_,
5432 *__pregex_,
5433 __flags_ | regex_constants::match_not_null | regex_constants::match_continuous))
5434 return *this;
5435 else
5436 ++__start;
5437 }
5438
5439 __flags_ |= regex_constants::match_prev_avail;
5440 if (!std::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) {
5441 __match_ = value_type();
5442
5443 } else {
5444 // The Standard mandates that if `regex_search` returns true ([re.regiter.incr]), "`match.prefix().first` shall be
5445 // equal to the previous value of `match[0].second`... It is unspecified how the implementation makes these
5446 // adjustments." The adjustment is necessary if we incremented `__start` above (the branch that deals with
5447 // zero-length matches).
5448 auto& __prefix = __match_.__prefix_;
5449 __prefix.first = __prefix_start;
5450 __prefix.matched = __prefix.first != __prefix.second;
5451 }
5452
5453 return *this;
5454}
5455
5456// regex_token_iterator
5457
5458template <class _BidirectionalIterator,
5459 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
5460 class _Traits = regex_traits<_CharT> >
5461class regex_token_iterator;
5462
5463typedef regex_token_iterator<const char*> cregex_token_iterator;
5464typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
5465# if _LIBCPP_HAS_WIDE_CHARACTERS
5466typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
5467typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
5468# endif
5469
5470template <class _BidirectionalIterator, class _CharT, class _Traits>
5471class _LIBCPP_PREFERRED_NAME(cregex_token_iterator)
5472 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator))
5473 _LIBCPP_PREFERRED_NAME(sregex_token_iterator)
5474 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator)) regex_token_iterator {
5475public:
5476 typedef basic_regex<_CharT, _Traits> regex_type;
5477 typedef sub_match<_BidirectionalIterator> value_type;
5478 typedef ptrdiff_t difference_type;
5479 typedef const value_type* pointer;
5480 typedef const value_type& reference;
5481 typedef forward_iterator_tag iterator_category;
5482# if _LIBCPP_STD_VER >= 20
5483 typedef input_iterator_tag iterator_concept;
5484# endif
5485
5486private:
5487 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
5488
5489 _Position __position_;
5490 const value_type* __result_;
5491 value_type __suffix_;
5492 ptrdiff_t __n_;
5493 vector<int> __subs_;
5494
5495public:
5496 regex_token_iterator();
5497 regex_token_iterator(_BidirectionalIterator __a,
5498 _BidirectionalIterator __b,
5499 const regex_type& __re,
5500 int __submatch = 0,
5501 regex_constants::match_flag_type __m = regex_constants::match_default);
5502# if _LIBCPP_STD_VER >= 14
5503 regex_token_iterator(_BidirectionalIterator __a,
5504 _BidirectionalIterator __b,
5505 const regex_type&& __re,
5506 int __submatch = 0,
5507 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5508# endif
5509
5510 regex_token_iterator(_BidirectionalIterator __a,
5511 _BidirectionalIterator __b,
5512 const regex_type& __re,
5513 const vector<int>& __submatches,
5514 regex_constants::match_flag_type __m = regex_constants::match_default);
5515# if _LIBCPP_STD_VER >= 14
5516 regex_token_iterator(_BidirectionalIterator __a,
5517 _BidirectionalIterator __b,
5518 const regex_type&& __re,
5519 const vector<int>& __submatches,
5520 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5521# endif
5522
5523# ifndef _LIBCPP_CXX03_LANG
5524 regex_token_iterator(_BidirectionalIterator __a,
5525 _BidirectionalIterator __b,
5526 const regex_type& __re,
5527 initializer_list<int> __submatches,
5528 regex_constants::match_flag_type __m = regex_constants::match_default);
5529
5530# if _LIBCPP_STD_VER >= 14
5531 regex_token_iterator(_BidirectionalIterator __a,
5532 _BidirectionalIterator __b,
5533 const regex_type&& __re,
5534 initializer_list<int> __submatches,
5535 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5536# endif
5537# endif // _LIBCPP_CXX03_LANG
5538 template <size_t _Np>
5539 regex_token_iterator(_BidirectionalIterator __a,
5540 _BidirectionalIterator __b,
5541 const regex_type& __re,
5542 const int (&__submatches)[_Np],
5543 regex_constants::match_flag_type __m = regex_constants::match_default);
5544# if _LIBCPP_STD_VER >= 14
5545 template <size_t _Np>
5546 regex_token_iterator(_BidirectionalIterator __a,
5547 _BidirectionalIterator __b,
5548 const regex_type&& __re,
5549 const int (&__submatches)[_Np],
5550 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
5551# endif
5552
5553 regex_token_iterator(const regex_token_iterator&);
5554 regex_token_iterator& operator=(const regex_token_iterator&);
5555
5556 _LIBCPP_HIDE_FROM_ABI bool operator==(const regex_token_iterator& __x) const;
5557# if _LIBCPP_STD_VER >= 20
5558 _LIBCPP_HIDE_FROM_ABI bool operator==(default_sentinel_t) const { return *this == regex_token_iterator(); }
5559# endif
5560# if _LIBCPP_STD_VER < 20
5561 _LIBCPP_HIDE_FROM_ABI bool operator!=(const regex_token_iterator& __x) const { return !(*this == __x); }
5562# endif
5563
5564 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI const value_type& operator*() const { return *__result_; }
5565 _LIBCPP_HIDE_FROM_ABI const value_type* operator->() const { return __result_; }
5566
5567 regex_token_iterator& operator++();
5568 _LIBCPP_HIDE_FROM_ABI regex_token_iterator operator++(int) {
5569 regex_token_iterator __t(*this);
5570 ++(*this);
5571 return __t;
5572 }
5573
5574private:
5575 void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
5576 void __establish_result() {
5577 if (__subs_[__n_] == -1)
5578 __result_ = std::addressof(__position_->prefix());
5579 else
5580 __result_ = std::addressof((*__position_)[__subs_[__n_]]);
5581 }
5582};
5583
5584template <class _BidirectionalIterator, class _CharT, class _Traits>
5585regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator()
5586 : __result_(nullptr), __suffix_(), __n_(0) {}
5587
5588template <class _BidirectionalIterator, class _CharT, class _Traits>
5589void regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::__init(
5590 _BidirectionalIterator __a, _BidirectionalIterator __b) {
5591 if (__position_ != _Position())
5592 __establish_result();
5593 else if (__subs_[__n_] == -1) {
5594 __suffix_.matched = true;
5595 __suffix_.first = __a;
5596 __suffix_.second = __b;
5597 __result_ = std::addressof(__suffix_);
5598 } else
5599 __result_ = nullptr;
5600}
5601
5602template <class _BidirectionalIterator, class _CharT, class _Traits>
5603regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
5604 _BidirectionalIterator __a,
5605 _BidirectionalIterator __b,
5606 const regex_type& __re,
5607 int __submatch,
5608 regex_constants::match_flag_type __m)
5609 : __position_(__a, __b, __re, __m), __n_(0), __subs_(1, __submatch) {
5610 __init(__a, __b);
5611}
5612
5613template <class _BidirectionalIterator, class _CharT, class _Traits>
5614regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
5615 _BidirectionalIterator __a,
5616 _BidirectionalIterator __b,
5617 const regex_type& __re,
5618 const vector<int>& __submatches,
5619 regex_constants::match_flag_type __m)
5620 : __position_(__a, __b, __re, __m), __n_(0), __subs_(__submatches) {
5621 __init(__a, __b);
5622}
5623
5624# ifndef _LIBCPP_CXX03_LANG
5625
5626template <class _BidirectionalIterator, class _CharT, class _Traits>
5627regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
5628 _BidirectionalIterator __a,
5629 _BidirectionalIterator __b,
5630 const regex_type& __re,
5631 initializer_list<int> __submatches,
5632 regex_constants::match_flag_type __m)
5633 : __position_(__a, __b, __re, __m), __n_(0), __subs_(__submatches) {
5634 __init(__a, __b);
5635}
5636
5637# endif // _LIBCPP_CXX03_LANG
5638
5639template <class _BidirectionalIterator, class _CharT, class _Traits>
5640template <size_t _Np>
5641regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
5642 _BidirectionalIterator __a,
5643 _BidirectionalIterator __b,
5644 const regex_type& __re,
5645 const int (&__submatches)[_Np],
5646 regex_constants::match_flag_type __m)
5647 : __position_(__a, __b, __re, __m), __n_(0), __subs_(begin(__submatches), end(__submatches)) {
5648 __init(__a, __b);
5649}
5650
5651template <class _BidirectionalIterator, class _CharT, class _Traits>
5652regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(const regex_token_iterator& __x)
5653 : __position_(__x.__position_),
5654 __result_(__x.__result_),
5655 __suffix_(__x.__suffix_),
5656 __n_(__x.__n_),
5657 __subs_(__x.__subs_) {
5658 if (__x.__result_ == std::addressof(__x.__suffix_))
5659 __result_ = std::addressof(__suffix_);
5660 else if (__result_ != nullptr)
5661 __establish_result();
5662}
5663
5664template <class _BidirectionalIterator, class _CharT, class _Traits>
5665regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
5666regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator=(const regex_token_iterator& __x) {
5667 if (this != std::addressof(__x)) {
5668 __position_ = __x.__position_;
5669 if (__x.__result_ == std::addressof(__x.__suffix_))
5670 __result_ = std::addressof(__suffix_);
5671 else
5672 __result_ = __x.__result_;
5673 __suffix_ = __x.__suffix_;
5674 __n_ = __x.__n_;
5675 __subs_ = __x.__subs_;
5676
5677 if (__result_ != nullptr && __result_ != std::addressof(__suffix_))
5678 __establish_result();
5679 }
5680 return *this;
5681}
5682
5683template <class _BidirectionalIterator, class _CharT, class _Traits>
5684bool regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator==(const regex_token_iterator& __x) const {
5685 if (__result_ == nullptr && __x.__result_ == nullptr)
5686 return true;
5687 if (__result_ == std::addressof(__suffix_) && __x.__result_ == std::addressof(__x.__suffix_) &&
5688 __suffix_ == __x.__suffix_)
5689 return true;
5690 if (__result_ == nullptr || __x.__result_ == nullptr)
5691 return false;
5692 if (__result_ == std::addressof(__suffix_) || __x.__result_ == std::addressof(__x.__suffix_))
5693 return false;
5694 return __position_ == __x.__position_ && __n_ == __x.__n_ && __subs_ == __x.__subs_;
5695}
5696
5697template <class _BidirectionalIterator, class _CharT, class _Traits>
5698regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
5699regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() {
5700 _Position __prev = __position_;
5701 if (__result_ == std::addressof(__suffix_))
5702 __result_ = nullptr;
5703 else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) {
5704 ++__n_;
5705 __establish_result();
5706 } else {
5707 __n_ = 0;
5708 ++__position_;
5709 if (__position_ != _Position())
5710 __establish_result();
5711 else {
5712 if (std::find(first: __subs_.begin(), last: __subs_.end(), value: -1) != __subs_.end() && __prev->suffix().length() != 0) {
5713 __suffix_.matched = true;
5714 __suffix_.first = __prev->suffix().first;
5715 __suffix_.second = __prev->suffix().second;
5716 __result_ = std::addressof(__suffix_);
5717 } else
5718 __result_ = nullptr;
5719 }
5720 }
5721 return *this;
5722}
5723
5724// regex_replace
5725
5726template <class _OutputIterator, class _BidirectionalIterator, class _Traits, class _CharT>
5727_LIBCPP_HIDE_FROM_ABI _OutputIterator regex_replace(
5728 _OutputIterator __output_iter,
5729 _BidirectionalIterator __first,
5730 _BidirectionalIterator __last,
5731 const basic_regex<_CharT, _Traits>& __e,
5732 const _CharT* __fmt,
5733 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5734 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
5735 _Iter __i(__first, __last, __e, __flags);
5736 _Iter __eof;
5737 if (__i == __eof) {
5738 if (!(__flags & regex_constants::format_no_copy))
5739 __output_iter = std::copy(__first, __last, __output_iter);
5740 } else {
5741 sub_match<_BidirectionalIterator> __lm;
5742 for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) {
5743 if (!(__flags & regex_constants::format_no_copy))
5744 __output_iter = std::copy(__i->prefix().first, __i->prefix().second, __output_iter);
5745 __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags);
5746 __lm = __i->suffix();
5747 if (__flags & regex_constants::format_first_only)
5748 break;
5749 }
5750 if (!(__flags & regex_constants::format_no_copy))
5751 __output_iter = std::copy(__lm.first, __lm.second, __output_iter);
5752 }
5753 return __output_iter;
5754}
5755
5756template <class _OutputIterator, class _BidirectionalIterator, class _Traits, class _CharT, class _ST, class _SA>
5757inline _LIBCPP_HIDE_FROM_ABI _OutputIterator regex_replace(
5758 _OutputIterator __output_iter,
5759 _BidirectionalIterator __first,
5760 _BidirectionalIterator __last,
5761 const basic_regex<_CharT, _Traits>& __e,
5762 const basic_string<_CharT, _ST, _SA>& __fmt,
5763 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5764 return std::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags);
5765}
5766
5767template <class _Traits, class _CharT, class _ST, class _SA, class _FST, class _FSA>
5768inline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT, _ST, _SA>
5769regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
5770 const basic_regex<_CharT, _Traits>& __e,
5771 const basic_string<_CharT, _FST, _FSA>& __fmt,
5772 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5773 basic_string<_CharT, _ST, _SA> __r;
5774 std::regex_replace(std::back_inserter(__r), __s.begin(), __s.end(), __e, __fmt.c_str(), __flags);
5775 return __r;
5776}
5777
5778template <class _Traits, class _CharT, class _ST, class _SA>
5779inline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT, _ST, _SA>
5780regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
5781 const basic_regex<_CharT, _Traits>& __e,
5782 const _CharT* __fmt,
5783 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5784 basic_string<_CharT, _ST, _SA> __r;
5785 std::regex_replace(std::back_inserter(__r), __s.begin(), __s.end(), __e, __fmt, __flags);
5786 return __r;
5787}
5788
5789template <class _Traits, class _CharT, class _ST, class _SA>
5790inline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT>
5791regex_replace(const _CharT* __s,
5792 const basic_regex<_CharT, _Traits>& __e,
5793 const basic_string<_CharT, _ST, _SA>& __fmt,
5794 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5795 basic_string<_CharT> __r;
5796 std::regex_replace(std::back_inserter(__r), __s, __s + char_traits<_CharT>::length(__s), __e, __fmt.c_str(), __flags);
5797 return __r;
5798}
5799
5800template <class _Traits, class _CharT>
5801inline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT>
5802regex_replace(const _CharT* __s,
5803 const basic_regex<_CharT, _Traits>& __e,
5804 const _CharT* __fmt,
5805 regex_constants::match_flag_type __flags = regex_constants::match_default) {
5806 basic_string<_CharT> __r;
5807 std::regex_replace(std::back_inserter(__r), __s, __s + char_traits<_CharT>::length(__s), __e, __fmt, __flags);
5808 return __r;
5809}
5810
5811_LIBCPP_END_NAMESPACE_STD
5812
5813# if _LIBCPP_STD_VER >= 17
5814_LIBCPP_BEGIN_NAMESPACE_STD
5815namespace pmr {
5816template <class _BidirT>
5817using match_results _LIBCPP_AVAILABILITY_PMR =
5818 std::match_results<_BidirT, polymorphic_allocator<std::sub_match<_BidirT>>>;
5819
5820using cmatch _LIBCPP_AVAILABILITY_PMR = match_results<const char*>;
5821using smatch _LIBCPP_AVAILABILITY_PMR = match_results<std::pmr::string::const_iterator>;
5822
5823# if _LIBCPP_HAS_WIDE_CHARACTERS
5824using wcmatch _LIBCPP_AVAILABILITY_PMR = match_results<const wchar_t*>;
5825using wsmatch _LIBCPP_AVAILABILITY_PMR = match_results<std::pmr::wstring::const_iterator>;
5826# endif
5827} // namespace pmr
5828_LIBCPP_END_NAMESPACE_STD
5829# endif
5830
5831_LIBCPP_POP_MACROS
5832
5833# endif // _LIBCPP_HAS_LOCALIZATION
5834
5835# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
5836# include <atomic>
5837# include <concepts>
5838# include <cstdlib>
5839# include <iosfwd>
5840# include <iterator>
5841# include <mutex>
5842# include <new>
5843# include <type_traits>
5844# include <typeinfo>
5845# include <utility>
5846# endif
5847#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
5848
5849#endif // _LIBCPP_REGEX
5850