blob: 5a6c7fbb8e0acc11454cf8283d3b46589635fcab [file] [log] [blame]
Howard Hinnant3257c982010-06-17 00:34:59 +00001// -*- C++ -*-
2//===--------------------------- regex ------------------------------------===//
3//
4// The LLVM Compiler Infrastructure
5//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3257c982010-06-17 00:34:59 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_REGEX
12#define _LIBCPP_REGEX
13
14/*
15 regex synopsis
16
17#include <initializer_list>
18
19namespace std
20{
21
22namespace regex_constants
23{
24
25emum 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};
38
39constexpr syntax_option_type operator~(syntax_option_type f);
40constexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs);
41constexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs);
42
43enum match_flag_type
44{
45 match_default = 0,
46 match_not_bol = unspecified,
47 match_not_eol = unspecified,
48 match_not_bow = unspecified,
49 match_not_eow = unspecified,
50 match_any = unspecified,
51 match_not_null = unspecified,
52 match_continuous = unspecified,
53 match_prev_avail = unspecified,
54 format_default = 0,
55 format_sed = unspecified,
56 format_no_copy = unspecified,
57 format_first_only = unspecified
58};
59
60constexpr match_flag_type operator~(match_flag_type f);
61constexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs);
62constexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs);
63
64enum error_type
65{
66 error_collate = unspecified,
67 error_ctype = unspecified,
68 error_escape = unspecified,
69 error_backref = unspecified,
70 error_brack = unspecified,
71 error_paren = unspecified,
72 error_brace = unspecified,
73 error_badbrace = unspecified,
74 error_range = unspecified,
75 error_space = unspecified,
76 error_badrepeat = unspecified,
77 error_complexity = unspecified,
78 error_stack = unspecified
79};
80
81} // regex_constants
82
83class regex_error
84 : public runtime_error
85{
86public:
87 explicit regex_error(regex_constants::error_type ecode);
88 regex_constants::error_type code() const;
89};
90
91template <class charT>
92struct regex_traits
93{
94public:
95 typedef charT char_type;
96 typedef basic_string<char_type> string_type;
97 typedef locale locale_type;
98 typedef /bitmask_type/ char_class_type;
99
100 regex_traits();
101
102 static size_t length(const char_type* p);
103 charT translate(charT c) const;
104 charT translate_nocase(charT c) const;
105 template <class ForwardIterator>
106 string_type
107 transform(ForwardIterator first, ForwardIterator last) const;
108 template <class ForwardIterator>
109 string_type
110 transform_primary( ForwardIterator first, ForwardIterator last) const;
111 template <class ForwardIterator>
112 string_type
113 lookup_collatename(ForwardIterator first, ForwardIterator last) const;
114 template <class ForwardIterator>
115 char_class_type
116 lookup_classname(ForwardIterator first, ForwardIterator last,
117 bool icase = false) const;
118 bool isctype(charT c, char_class_type f) const;
119 int value(charT ch, int radix) const;
120 locale_type imbue(locale_type l);
121 locale_type getloc()const;
122};
123
124template <class charT, class traits = regex_traits<charT>>
125class basic_regex
126{
127public:
128 // types:
129 typedef charT value_type;
Hubert Tongb49c67f2016-08-02 21:34:48 +0000130 typedef traits traits_type;
131 typedef typename traits::string_type string_type;
Howard Hinnant3257c982010-06-17 00:34:59 +0000132 typedef regex_constants::syntax_option_type flag_type;
133 typedef typename traits::locale_type locale_type;
134
135 // constants:
136 static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
137 static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
138 static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
139 static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
140 static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
141 static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
142 static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
143 static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
144 static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
145 static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
146
147 // construct/copy/destroy:
148 basic_regex();
149 explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
Hubert Tong7f6e8e22016-08-07 22:26:04 +0000150 basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
Howard Hinnant3257c982010-06-17 00:34:59 +0000151 basic_regex(const basic_regex&);
Howard Hinnant46623a02012-07-21 01:31:58 +0000152 basic_regex(basic_regex&&) noexcept;
Howard Hinnant3257c982010-06-17 00:34:59 +0000153 template <class ST, class SA>
154 explicit basic_regex(const basic_string<charT, ST, SA>& p,
155 flag_type f = regex_constants::ECMAScript);
156 template <class ForwardIterator>
157 basic_regex(ForwardIterator first, ForwardIterator last,
158 flag_type f = regex_constants::ECMAScript);
159 basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
160
161 ~basic_regex();
162
163 basic_regex& operator=(const basic_regex&);
Howard Hinnant46623a02012-07-21 01:31:58 +0000164 basic_regex& operator=(basic_regex&&) noexcept;
Howard Hinnant3257c982010-06-17 00:34:59 +0000165 basic_regex& operator=(const charT* ptr);
166 basic_regex& operator=(initializer_list<charT> il);
167 template <class ST, class SA>
168 basic_regex& operator=(const basic_string<charT, ST, SA>& p);
169
170 // assign:
171 basic_regex& assign(const basic_regex& that);
Howard Hinnant46623a02012-07-21 01:31:58 +0000172 basic_regex& assign(basic_regex&& that) noexcept;
Howard Hinnant3257c982010-06-17 00:34:59 +0000173 basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
174 basic_regex& assign(const charT* p, size_t len, flag_type f);
175 template <class string_traits, class A>
176 basic_regex& assign(const basic_string<charT, string_traits, A>& s,
177 flag_type f = regex_constants::ECMAScript);
178 template <class InputIterator>
179 basic_regex& assign(InputIterator first, InputIterator last,
180 flag_type f = regex_constants::ECMAScript);
181 basic_regex& assign(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
182
183 // const operations:
184 unsigned mark_count() const;
185 flag_type flags() const;
186
187 // locale:
188 locale_type imbue(locale_type loc);
189 locale_type getloc() const;
190
191 // swap:
192 void swap(basic_regex&);
193};
194
195typedef basic_regex<char> regex;
196typedef basic_regex<wchar_t> wregex;
197
198template <class charT, class traits>
199 void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
200
201template <class BidirectionalIterator>
202class sub_match
203 : public pair<BidirectionalIterator, BidirectionalIterator>
204{
205public:
206 typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
207 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
208 typedef BidirectionalIterator iterator;
209 typedef basic_string<value_type> string_type;
210
211 bool matched;
212
Howard Hinnant31aaf552010-12-08 21:07:55 +0000213 constexpr sub_match();
214
Howard Hinnant3257c982010-06-17 00:34:59 +0000215 difference_type length() const;
216 operator string_type() const;
217 string_type str() const;
218
219 int compare(const sub_match& s) const;
220 int compare(const string_type& s) const;
221 int compare(const value_type* s) const;
222};
223
224typedef sub_match<const char*> csub_match;
225typedef sub_match<const wchar_t*> wcsub_match;
226typedef sub_match<string::const_iterator> ssub_match;
227typedef sub_match<wstring::const_iterator> wssub_match;
228
229template <class BiIter>
230 bool
231 operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
232
233template <class BiIter>
234 bool
235 operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
236
237template <class BiIter>
238 bool
239 operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
240
241template <class BiIter>
242 bool
243 operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
244
245template <class BiIter>
246 bool
247 operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
248
249template <class BiIter>
250 bool
251 operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
252
253template <class BiIter, class ST, class SA>
254 bool
255 operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
256 const sub_match<BiIter>& rhs);
257
258template <class BiIter, class ST, class SA>
259 bool
260 operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
261 const sub_match<BiIter>& rhs);
262
263template <class BiIter, class ST, class SA>
264 bool
265 operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
266 const sub_match<BiIter>& rhs);
267
268template <class BiIter, class ST, class SA>
269 bool
270 operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
271 const sub_match<BiIter>& rhs);
272
273template <class BiIter, class ST, class SA>
274 bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
275 const sub_match<BiIter>& rhs);
276
277template <class BiIter, class ST, class SA>
278 bool
279 operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
280 const sub_match<BiIter>& rhs);
281
282template <class BiIter, class ST, class SA>
283 bool
284 operator==(const sub_match<BiIter>& lhs,
285 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
286
287template <class BiIter, class ST, class SA>
288 bool
289 operator!=(const sub_match<BiIter>& lhs,
290 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
291
292template <class BiIter, class ST, class SA>
293 bool
294 operator<(const sub_match<BiIter>& lhs,
295 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
296
297template <class BiIter, class ST, class SA>
298 bool operator>(const sub_match<BiIter>& lhs,
299 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
300
301template <class BiIter, class ST, class SA>
302 bool
303 operator>=(const sub_match<BiIter>& lhs,
304 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
305
306template <class BiIter, class ST, class SA>
307 bool
308 operator<=(const sub_match<BiIter>& lhs,
309 const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
310
311template <class BiIter>
312 bool
313 operator==(typename iterator_traits<BiIter>::value_type const* lhs,
314 const sub_match<BiIter>& rhs);
315
316template <class BiIter>
317 bool
318 operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
319 const sub_match<BiIter>& rhs);
320
321template <class BiIter>
322 bool
323 operator<(typename iterator_traits<BiIter>::value_type const* lhs,
324 const sub_match<BiIter>& rhs);
325
326template <class BiIter>
327 bool
328 operator>(typename iterator_traits<BiIter>::value_type const* lhs,
329 const sub_match<BiIter>& rhs);
330
331template <class BiIter>
332 bool
333 operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
334 const sub_match<BiIter>& rhs);
335
336template <class BiIter>
337 bool
338 operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
339 const sub_match<BiIter>& rhs);
340
341template <class BiIter>
342 bool
343 operator==(const sub_match<BiIter>& lhs,
344 typename iterator_traits<BiIter>::value_type const* rhs);
345
346template <class BiIter>
347 bool
348 operator!=(const sub_match<BiIter>& lhs,
349 typename iterator_traits<BiIter>::value_type const* rhs);
350
351template <class BiIter>
352 bool
353 operator<(const sub_match<BiIter>& lhs,
354 typename iterator_traits<BiIter>::value_type const* rhs);
355
356template <class BiIter>
357 bool
358 operator>(const sub_match<BiIter>& lhs,
359 typename iterator_traits<BiIter>::value_type const* rhs);
360
361template <class BiIter>
362 bool
363 operator>=(const sub_match<BiIter>& lhs,
364 typename iterator_traits<BiIter>::value_type const* rhs);
365
366template <class BiIter>
367 bool
368 operator<=(const sub_match<BiIter>& lhs,
369 typename iterator_traits<BiIter>::value_type const* rhs);
370
371template <class BiIter>
372 bool
373 operator==(typename iterator_traits<BiIter>::value_type const& lhs,
374 const sub_match<BiIter>& rhs);
375
376template <class BiIter>
377 bool
378 operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
379 const sub_match<BiIter>& rhs);
380
381template <class BiIter>
382 bool
383 operator<(typename iterator_traits<BiIter>::value_type const& lhs,
384 const sub_match<BiIter>& rhs);
385
386template <class BiIter>
387 bool
388 operator>(typename iterator_traits<BiIter>::value_type const& lhs,
389 const sub_match<BiIter>& rhs);
390
391template <class BiIter>
392 bool
393 operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
394 const sub_match<BiIter>& rhs);
395
396template <class BiIter>
397 bool
398 operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
399 const sub_match<BiIter>& rhs);
400
401template <class BiIter>
402 bool
403 operator==(const sub_match<BiIter>& lhs,
404 typename iterator_traits<BiIter>::value_type const& rhs);
405
406template <class BiIter>
407 bool
408 operator!=(const sub_match<BiIter>& lhs,
409 typename iterator_traits<BiIter>::value_type const& rhs);
410
411template <class BiIter>
412 bool
413 operator<(const sub_match<BiIter>& lhs,
414 typename iterator_traits<BiIter>::value_type const& rhs);
415
416template <class BiIter>
417 bool
418 operator>(const sub_match<BiIter>& lhs,
419 typename iterator_traits<BiIter>::value_type const& rhs);
420
421template <class BiIter>
422 bool
423 operator>=(const sub_match<BiIter>& lhs,
424 typename iterator_traits<BiIter>::value_type const& rhs);
425
426template <class BiIter>
427 bool
428 operator<=(const sub_match<BiIter>& lhs,
429 typename iterator_traits<BiIter>::value_type const& rhs);
430
431template <class charT, class ST, class BiIter>
432 basic_ostream<charT, ST>&
433 operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
434
435template <class BidirectionalIterator,
436 class Allocator = allocator<sub_match<BidirectionalIterator>>>
437class match_results
438{
439public:
440 typedef sub_match<BidirectionalIterator> value_type;
441 typedef const value_type& const_reference;
Marshall Clow103af342014-02-26 01:56:31 +0000442 typedef value_type& reference;
Howard Hinnant3257c982010-06-17 00:34:59 +0000443 typedef /implementation-defined/ const_iterator;
444 typedef const_iterator iterator;
445 typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
446 typedef typename allocator_traits<Allocator>::size_type size_type;
447 typedef Allocator allocator_type;
448 typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
449 typedef basic_string<char_type> string_type;
450
451 // construct/copy/destroy:
452 explicit match_results(const Allocator& a = Allocator());
453 match_results(const match_results& m);
Howard Hinnant46623a02012-07-21 01:31:58 +0000454 match_results(match_results&& m) noexcept;
Howard Hinnant3257c982010-06-17 00:34:59 +0000455 match_results& operator=(const match_results& m);
456 match_results& operator=(match_results&& m);
457 ~match_results();
458
Howard Hinnant31aaf552010-12-08 21:07:55 +0000459 bool ready() const;
460
Howard Hinnant3257c982010-06-17 00:34:59 +0000461 // size:
462 size_type size() const;
463 size_type max_size() const;
464 bool empty() const;
465
466 // element access:
467 difference_type length(size_type sub = 0) const;
468 difference_type position(size_type sub = 0) const;
469 string_type str(size_type sub = 0) const;
470 const_reference operator[](size_type n) const;
471
472 const_reference prefix() const;
473 const_reference suffix() const;
474
475 const_iterator begin() const;
476 const_iterator end() const;
477 const_iterator cbegin() const;
478 const_iterator cend() const;
479
480 // format:
481 template <class OutputIter>
482 OutputIter
483 format(OutputIter out, const char_type* fmt_first,
484 const char_type* fmt_last,
485 regex_constants::match_flag_type flags = regex_constants::format_default) const;
486 template <class OutputIter, class ST, class SA>
487 OutputIter
488 format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
489 regex_constants::match_flag_type flags = regex_constants::format_default) const;
490 template <class ST, class SA>
491 basic_string<char_type, ST, SA>
492 format(const basic_string<char_type, ST, SA>& fmt,
493 regex_constants::match_flag_type flags = regex_constants::format_default) const;
494 string_type
495 format(const char_type* fmt,
496 regex_constants::match_flag_type flags = regex_constants::format_default) const;
497
498 // allocator:
499 allocator_type get_allocator() const;
500
501 // swap:
502 void swap(match_results& that);
503};
504
505typedef match_results<const char*> cmatch;
506typedef match_results<const wchar_t*> wcmatch;
507typedef match_results<string::const_iterator> smatch;
508typedef match_results<wstring::const_iterator> wsmatch;
509
510template <class BidirectionalIterator, class Allocator>
511 bool
512 operator==(const match_results<BidirectionalIterator, Allocator>& m1,
513 const match_results<BidirectionalIterator, Allocator>& m2);
514
515template <class BidirectionalIterator, class Allocator>
516 bool
517 operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
518 const match_results<BidirectionalIterator, Allocator>& m2);
519
520template <class BidirectionalIterator, class Allocator>
521 void
522 swap(match_results<BidirectionalIterator, Allocator>& m1,
523 match_results<BidirectionalIterator, Allocator>& m2);
524
525template <class BidirectionalIterator, class Allocator, class charT, class traits>
526 bool
527 regex_match(BidirectionalIterator first, BidirectionalIterator last,
528 match_results<BidirectionalIterator, Allocator>& m,
529 const basic_regex<charT, traits>& e,
530 regex_constants::match_flag_type flags = regex_constants::match_default);
531
532template <class BidirectionalIterator, class charT, class traits>
533 bool
534 regex_match(BidirectionalIterator first, BidirectionalIterator last,
535 const basic_regex<charT, traits>& e,
536 regex_constants::match_flag_type flags = regex_constants::match_default);
537
538template <class charT, class Allocator, class traits>
539 bool
540 regex_match(const charT* str, match_results<const charT*, Allocator>& m,
541 const basic_regex<charT, traits>& e,
542 regex_constants::match_flag_type flags = regex_constants::match_default);
543
544template <class ST, class SA, class Allocator, class charT, class traits>
545 bool
546 regex_match(const basic_string<charT, ST, SA>& s,
547 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
548 const basic_regex<charT, traits>& e,
549 regex_constants::match_flag_type flags = regex_constants::match_default);
550
Marshall Clowe0f86722014-02-19 21:21:11 +0000551template <class ST, class SA, class Allocator, class charT, class traits>
552 bool
553 regex_match(const basic_string<charT, ST, SA>&& s,
554 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
555 const basic_regex<charT, traits>& e,
556 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
557
Howard Hinnant3257c982010-06-17 00:34:59 +0000558template <class charT, class traits>
559 bool
560 regex_match(const charT* str, const basic_regex<charT, traits>& e,
561 regex_constants::match_flag_type flags = regex_constants::match_default);
562
563template <class ST, class SA, class charT, class traits>
564 bool
565 regex_match(const basic_string<charT, ST, SA>& s,
566 const basic_regex<charT, traits>& e,
567 regex_constants::match_flag_type flags = regex_constants::match_default);
568
569template <class BidirectionalIterator, class Allocator, class charT, class traits>
570 bool
571 regex_search(BidirectionalIterator first, BidirectionalIterator last,
572 match_results<BidirectionalIterator, Allocator>& m,
573 const basic_regex<charT, traits>& e,
574 regex_constants::match_flag_type flags = regex_constants::match_default);
575
576template <class BidirectionalIterator, class charT, class traits>
577 bool
578 regex_search(BidirectionalIterator first, BidirectionalIterator last,
579 const basic_regex<charT, traits>& e,
580 regex_constants::match_flag_type flags = regex_constants::match_default);
581
582template <class charT, class Allocator, class traits>
583 bool
584 regex_search(const charT* str, match_results<const charT*, Allocator>& m,
585 const basic_regex<charT, traits>& e,
586 regex_constants::match_flag_type flags = regex_constants::match_default);
587
588template <class charT, class traits>
589 bool
590 regex_search(const charT* str, const basic_regex<charT, traits>& e,
591 regex_constants::match_flag_type flags = regex_constants::match_default);
592
593template <class ST, class SA, class charT, class traits>
594 bool
595 regex_search(const basic_string<charT, ST, SA>& s,
596 const basic_regex<charT, traits>& e,
597 regex_constants::match_flag_type flags = regex_constants::match_default);
598
599template <class ST, class SA, class Allocator, class charT, class traits>
600 bool
601 regex_search(const basic_string<charT, ST, SA>& s,
602 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
603 const basic_regex<charT, traits>& e,
604 regex_constants::match_flag_type flags = regex_constants::match_default);
605
Marshall Clowe0f86722014-02-19 21:21:11 +0000606template <class ST, class SA, class Allocator, class charT, class traits>
607 bool
608 regex_search(const basic_string<charT, ST, SA>&& s,
609 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
610 const basic_regex<charT, traits>& e,
611 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
612
Howard Hinnant3257c982010-06-17 00:34:59 +0000613template <class OutputIterator, class BidirectionalIterator,
614 class traits, class charT, class ST, class SA>
615 OutputIterator
616 regex_replace(OutputIterator out,
617 BidirectionalIterator first, BidirectionalIterator last,
618 const basic_regex<charT, traits>& e,
619 const basic_string<charT, ST, SA>& fmt,
620 regex_constants::match_flag_type flags = regex_constants::match_default);
621
622template <class OutputIterator, class BidirectionalIterator,
623 class traits, class charT>
624 OutputIterator
625 regex_replace(OutputIterator out,
626 BidirectionalIterator first, BidirectionalIterator last,
627 const basic_regex<charT, traits>& e, const charT* fmt,
628 regex_constants::match_flag_type flags = regex_constants::match_default);
629
630template <class traits, class charT, class ST, class SA, class FST, class FSA>>
631 basic_string<charT, ST, SA>
632 regex_replace(const basic_string<charT, ST, SA>& s,
633 const basic_regex<charT, traits>& e,
634 const basic_string<charT, FST, FSA>& fmt,
635 regex_constants::match_flag_type flags = regex_constants::match_default);
636
637template <class traits, class charT, class ST, class SA>
638 basic_string<charT, ST, SA>
639 regex_replace(const basic_string<charT, ST, SA>& s,
640 const basic_regex<charT, traits>& e, const charT* fmt,
641 regex_constants::match_flag_type flags = regex_constants::match_default);
642
643template <class traits, class charT, class ST, class SA>
644 basic_string<charT>
645 regex_replace(const charT* s,
646 const basic_regex<charT, traits>& e,
647 const basic_string<charT, ST, SA>& fmt,
648 regex_constants::match_flag_type flags = regex_constants::match_default);
649
650template <class traits, class charT>
651 basic_string<charT>
652 regex_replace(const charT* s,
653 const basic_regex<charT, traits>& e,
654 const charT* fmt,
655 regex_constants::match_flag_type flags = regex_constants::match_default);
656
657template <class BidirectionalIterator,
658 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
659 class traits = regex_traits<charT>>
660class regex_iterator
661{
662public:
663 typedef basic_regex<charT, traits> regex_type;
664 typedef match_results<BidirectionalIterator> value_type;
665 typedef ptrdiff_t difference_type;
666 typedef const value_type* pointer;
667 typedef const value_type& reference;
668 typedef forward_iterator_tag iterator_category;
669
670 regex_iterator();
671 regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
672 const regex_type& re,
673 regex_constants::match_flag_type m = regex_constants::match_default);
Marshall Clowe0f86722014-02-19 21:21:11 +0000674 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
675 const regex_type&& __re,
676 regex_constants::match_flag_type __m
677 = regex_constants::match_default) = delete; // C++14
Howard Hinnant3257c982010-06-17 00:34:59 +0000678 regex_iterator(const regex_iterator&);
679 regex_iterator& operator=(const regex_iterator&);
680
681 bool operator==(const regex_iterator&) const;
682 bool operator!=(const regex_iterator&) const;
683
684 const value_type& operator*() const;
685 const value_type* operator->() const;
686
687 regex_iterator& operator++();
688 regex_iterator operator++(int);
689};
690
691typedef regex_iterator<const char*> cregex_iterator;
692typedef regex_iterator<const wchar_t*> wcregex_iterator;
693typedef regex_iterator<string::const_iterator> sregex_iterator;
694typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
695
696template <class BidirectionalIterator,
697 class charT = typename iterator_traits< BidirectionalIterator>::value_type,
698 class traits = regex_traits<charT>>
699class regex_token_iterator
700{
701public:
702 typedef basic_regex<charT, traits> regex_type;
703 typedef sub_match<BidirectionalIterator> value_type;
704 typedef ptrdiff_t difference_type;
705 typedef const value_type* pointer;
706 typedef const value_type& reference;
707 typedef forward_iterator_tag iterator_category;
708
709 regex_token_iterator();
710 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
711 const regex_type& re, int submatch = 0,
712 regex_constants::match_flag_type m = regex_constants::match_default);
713 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
Marshall Clowe0f86722014-02-19 21:21:11 +0000714 const regex_type&& re, int submatch = 0,
715 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
716 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
Howard Hinnant3257c982010-06-17 00:34:59 +0000717 const regex_type& re, const vector<int>& submatches,
718 regex_constants::match_flag_type m = regex_constants::match_default);
719 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
Marshall Clowe0f86722014-02-19 21:21:11 +0000720 const regex_type&& re, const vector<int>& submatches,
721 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
722 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
Howard Hinnant3257c982010-06-17 00:34:59 +0000723 const regex_type& re, initializer_list<int> submatches,
724 regex_constants::match_flag_type m = regex_constants::match_default);
Marshall Clowe0f86722014-02-19 21:21:11 +0000725 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
726 const regex_type&& re, initializer_list<int> submatches,
727 regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
Howard Hinnant3257c982010-06-17 00:34:59 +0000728 template <size_t N>
729 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
730 const regex_type& re, const int (&submatches)[N],
731 regex_constants::match_flag_type m = regex_constants::match_default);
Marshall Clowe0f86722014-02-19 21:21:11 +0000732 template <size_t N>
733 regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
734 const regex_type& re, const int (&submatches)[N],
735 regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14;
Howard Hinnant3257c982010-06-17 00:34:59 +0000736 regex_token_iterator(const regex_token_iterator&);
737 regex_token_iterator& operator=(const regex_token_iterator&);
738
739 bool operator==(const regex_token_iterator&) const;
740 bool operator!=(const regex_token_iterator&) const;
741
742 const value_type& operator*() const;
743 const value_type* operator->() const;
744
745 regex_token_iterator& operator++();
746 regex_token_iterator operator++(int);
747};
748
749typedef regex_token_iterator<const char*> cregex_token_iterator;
750typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
751typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
752typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
753
754} // std
755*/
756
757#include <__config>
758#include <stdexcept>
759#include <__locale>
Howard Hinnant8c2c18d2010-06-24 21:28:00 +0000760#include <initializer_list>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +0000761#include <utility>
762#include <iterator>
763#include <string>
Howard Hinnant7e9d84b2010-06-30 00:21:42 +0000764#include <memory>
765#include <vector>
Howard Hinnantac303862010-07-12 15:51:17 +0000766#include <deque>
Howard Hinnant3257c982010-06-17 00:34:59 +0000767
Howard Hinnant66c6f972011-11-29 16:45:27 +0000768#include <__undef_min_max>
769
Howard Hinnant08e17472011-10-17 20:05:10 +0000770#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3257c982010-06-17 00:34:59 +0000771#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000772#endif
Howard Hinnant3257c982010-06-17 00:34:59 +0000773
774_LIBCPP_BEGIN_NAMESPACE_STD
775
776namespace regex_constants
777{
778
779// syntax_option_type
780
781enum syntax_option_type
782{
783 icase = 1 << 0,
784 nosubs = 1 << 1,
785 optimize = 1 << 2,
786 collate = 1 << 3,
Howard Hinnantad2a7ab2010-07-27 17:24:17 +0000787 ECMAScript = 0,
788 basic = 1 << 4,
789 extended = 1 << 5,
790 awk = 1 << 6,
791 grep = 1 << 7,
792 egrep = 1 << 8
Howard Hinnant3257c982010-06-17 00:34:59 +0000793};
794
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000795inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46623a02012-07-21 01:31:58 +0000796_LIBCPP_CONSTEXPR
Howard Hinnant3257c982010-06-17 00:34:59 +0000797syntax_option_type
798operator~(syntax_option_type __x)
799{
Marshall Clow04bd79b2013-03-22 02:13:55 +0000800 return syntax_option_type(~int(__x) & 0x1FF);
Howard Hinnant3257c982010-06-17 00:34:59 +0000801}
802
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000803inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46623a02012-07-21 01:31:58 +0000804_LIBCPP_CONSTEXPR
Howard Hinnant3257c982010-06-17 00:34:59 +0000805syntax_option_type
806operator&(syntax_option_type __x, syntax_option_type __y)
807{
808 return syntax_option_type(int(__x) & int(__y));
809}
810
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000811inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46623a02012-07-21 01:31:58 +0000812_LIBCPP_CONSTEXPR
Howard Hinnant3257c982010-06-17 00:34:59 +0000813syntax_option_type
814operator|(syntax_option_type __x, syntax_option_type __y)
815{
816 return syntax_option_type(int(__x) | int(__y));
817}
818
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000819inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46623a02012-07-21 01:31:58 +0000820_LIBCPP_CONSTEXPR
Howard Hinnant3257c982010-06-17 00:34:59 +0000821syntax_option_type
822operator^(syntax_option_type __x, syntax_option_type __y)
823{
824 return syntax_option_type(int(__x) ^ int(__y));
825}
826
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000827inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000828syntax_option_type&
829operator&=(syntax_option_type& __x, syntax_option_type __y)
830{
831 __x = __x & __y;
832 return __x;
833}
834
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000835inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000836syntax_option_type&
837operator|=(syntax_option_type& __x, syntax_option_type __y)
838{
839 __x = __x | __y;
840 return __x;
841}
842
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000843inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000844syntax_option_type&
845operator^=(syntax_option_type& __x, syntax_option_type __y)
846{
847 __x = __x ^ __y;
848 return __x;
849}
850
851// match_flag_type
852
853enum match_flag_type
854{
855 match_default = 0,
856 match_not_bol = 1 << 0,
857 match_not_eol = 1 << 1,
858 match_not_bow = 1 << 2,
859 match_not_eow = 1 << 3,
860 match_any = 1 << 4,
861 match_not_null = 1 << 5,
862 match_continuous = 1 << 6,
863 match_prev_avail = 1 << 7,
864 format_default = 0,
865 format_sed = 1 << 8,
866 format_no_copy = 1 << 9,
Howard Hinnanta712c722010-08-16 20:21:16 +0000867 format_first_only = 1 << 10,
Tim Shen38c2a372016-10-27 21:40:34 +0000868 __no_update_pos = 1 << 11,
869 __full_match = 1 << 12
Howard Hinnant3257c982010-06-17 00:34:59 +0000870};
871
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000872inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46623a02012-07-21 01:31:58 +0000873_LIBCPP_CONSTEXPR
Howard Hinnant3257c982010-06-17 00:34:59 +0000874match_flag_type
875operator~(match_flag_type __x)
876{
Marshall Clow04bd79b2013-03-22 02:13:55 +0000877 return match_flag_type(~int(__x) & 0x0FFF);
Howard Hinnant3257c982010-06-17 00:34:59 +0000878}
879
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000880inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46623a02012-07-21 01:31:58 +0000881_LIBCPP_CONSTEXPR
Howard Hinnant3257c982010-06-17 00:34:59 +0000882match_flag_type
883operator&(match_flag_type __x, match_flag_type __y)
884{
885 return match_flag_type(int(__x) & int(__y));
886}
887
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000888inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46623a02012-07-21 01:31:58 +0000889_LIBCPP_CONSTEXPR
Howard Hinnant3257c982010-06-17 00:34:59 +0000890match_flag_type
891operator|(match_flag_type __x, match_flag_type __y)
892{
893 return match_flag_type(int(__x) | int(__y));
894}
895
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000896inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46623a02012-07-21 01:31:58 +0000897_LIBCPP_CONSTEXPR
Howard Hinnant3257c982010-06-17 00:34:59 +0000898match_flag_type
899operator^(match_flag_type __x, match_flag_type __y)
900{
901 return match_flag_type(int(__x) ^ int(__y));
902}
903
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000904inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000905match_flag_type&
906operator&=(match_flag_type& __x, match_flag_type __y)
907{
908 __x = __x & __y;
909 return __x;
910}
911
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000912inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000913match_flag_type&
914operator|=(match_flag_type& __x, match_flag_type __y)
915{
916 __x = __x | __y;
917 return __x;
918}
919
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000920inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000921match_flag_type&
922operator^=(match_flag_type& __x, match_flag_type __y)
923{
924 __x = __x ^ __y;
925 return __x;
926}
927
928enum error_type
929{
930 error_collate = 1,
931 error_ctype,
932 error_escape,
933 error_backref,
934 error_brack,
935 error_paren,
936 error_brace,
937 error_badbrace,
938 error_range,
939 error_space,
940 error_badrepeat,
941 error_complexity,
Howard Hinnant8c2c18d2010-06-24 21:28:00 +0000942 error_stack,
Howard Hinnantad2a7ab2010-07-27 17:24:17 +0000943 __re_err_grammar,
944 __re_err_empty,
945 __re_err_unknown
Howard Hinnant3257c982010-06-17 00:34:59 +0000946};
947
948} // regex_constants
949
950class _LIBCPP_EXCEPTION_ABI regex_error
951 : public runtime_error
952{
953 regex_constants::error_type __code_;
954public:
955 explicit regex_error(regex_constants::error_type __ecode);
956 virtual ~regex_error() throw();
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000958 regex_constants::error_type code() const {return __code_;}
959};
960
Marshall Clow2576c292015-07-28 13:30:47 +0000961template <regex_constants::error_type _Ev>
Marshall Clow14c09a22016-08-25 15:09:01 +0000962_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
Marshall Clow2576c292015-07-28 13:30:47 +0000963void __throw_regex_error()
964{
965#ifndef _LIBCPP_NO_EXCEPTIONS
Marshall Clowfc93ce72015-08-17 21:14:16 +0000966 throw regex_error(_Ev);
967#else
Marshall Clow14c09a22016-08-25 15:09:01 +0000968 _VSTD::abort();
Marshall Clow2576c292015-07-28 13:30:47 +0000969#endif
970}
971
Howard Hinnant3257c982010-06-17 00:34:59 +0000972template <class _CharT>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000973struct _LIBCPP_TYPE_VIS_ONLY regex_traits
Howard Hinnant3257c982010-06-17 00:34:59 +0000974{
975public:
976 typedef _CharT char_type;
977 typedef basic_string<char_type> string_type;
978 typedef locale locale_type;
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000979 typedef ctype_base::mask char_class_type;
Howard Hinnant3257c982010-06-17 00:34:59 +0000980
Daniel Sanders7e87bc92016-02-17 13:16:31 +0000981#if defined(__mips__) && defined(__GLIBC__)
982 static const char_class_type __regex_word = static_cast<char_class_type>(_ISbit(15));
983#else
Howard Hinnantf409d2f2010-06-21 21:01:43 +0000984 static const char_class_type __regex_word = 0x80;
Daniel Sanders7e87bc92016-02-17 13:16:31 +0000985#endif
986
Howard Hinnant3257c982010-06-17 00:34:59 +0000987private:
988 locale __loc_;
989 const ctype<char_type>* __ct_;
990 const collate<char_type>* __col_;
991
992public:
993 regex_traits();
994
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000996 static size_t length(const char_type* __p)
997 {return char_traits<char_type>::length(__p);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +0000998 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +0000999 char_type translate(char_type __c) const {return __c;}
1000 char_type translate_nocase(char_type __c) const;
1001 template <class _ForwardIterator>
1002 string_type
1003 transform(_ForwardIterator __f, _ForwardIterator __l) const;
1004 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001005 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +00001006 string_type
1007 transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
1008 {return __transform_primary(__f, __l, char_type());}
1009 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001010 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +00001011 string_type
1012 lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
1013 {return __lookup_collatename(__f, __l, char_type());}
1014 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +00001016 char_class_type
1017 lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001018 bool __icase = false) const
1019 {return __lookup_classname(__f, __l, __icase, char_type());}
1020 bool isctype(char_type __c, char_class_type __m) const;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001021 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001022 int value(char_type __ch, int __radix) const
Marshall Clow33ae2332013-10-21 15:43:25 +00001023 {return __regex_traits_value(__ch, __radix);}
Howard Hinnant3257c982010-06-17 00:34:59 +00001024 locale_type imbue(locale_type __l);
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3257c982010-06-17 00:34:59 +00001026 locale_type getloc()const {return __loc_;}
1027
1028private:
1029 void __init();
1030
1031 template <class _ForwardIterator>
1032 string_type
1033 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
1034 template <class _ForwardIterator>
1035 string_type
1036 __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1037
1038 template <class _ForwardIterator>
1039 string_type
1040 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
1041 template <class _ForwardIterator>
1042 string_type
1043 __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001044
1045 template <class _ForwardIterator>
1046 char_class_type
1047 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1048 bool __icase, char) const;
1049 template <class _ForwardIterator>
1050 char_class_type
1051 __lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
1052 bool __icase, wchar_t) const;
1053
Marshall Clow33ae2332013-10-21 15:43:25 +00001054 static int __regex_traits_value(unsigned char __ch, int __radix);
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001055 _LIBCPP_INLINE_VISIBILITY
Marshall Clow33ae2332013-10-21 15:43:25 +00001056 int __regex_traits_value(char __ch, int __radix) const
1057 {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001058 _LIBCPP_INLINE_VISIBILITY
Marshall Clow33ae2332013-10-21 15:43:25 +00001059 int __regex_traits_value(wchar_t __ch, int __radix) const;
Howard Hinnant3257c982010-06-17 00:34:59 +00001060};
1061
1062template <class _CharT>
Howard Hinnant23fb9722013-03-07 19:38:08 +00001063const typename regex_traits<_CharT>::char_class_type
1064regex_traits<_CharT>::__regex_word;
1065
1066template <class _CharT>
Howard Hinnant3257c982010-06-17 00:34:59 +00001067regex_traits<_CharT>::regex_traits()
1068{
1069 __init();
1070}
1071
1072template <class _CharT>
1073typename regex_traits<_CharT>::char_type
1074regex_traits<_CharT>::translate_nocase(char_type __c) const
1075{
1076 return __ct_->tolower(__c);
1077}
1078
1079template <class _CharT>
1080template <class _ForwardIterator>
1081typename regex_traits<_CharT>::string_type
1082regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
1083{
1084 string_type __s(__f, __l);
1085 return __col_->transform(__s.data(), __s.data() + __s.size());
1086}
1087
1088template <class _CharT>
1089void
1090regex_traits<_CharT>::__init()
1091{
1092 __ct_ = &use_facet<ctype<char_type> >(__loc_);
1093 __col_ = &use_facet<collate<char_type> >(__loc_);
1094}
1095
1096template <class _CharT>
1097typename regex_traits<_CharT>::locale_type
1098regex_traits<_CharT>::imbue(locale_type __l)
1099{
1100 locale __r = __loc_;
1101 __loc_ = __l;
1102 __init();
1103 return __r;
1104}
1105
1106// transform_primary is very FreeBSD-specific
1107
1108template <class _CharT>
1109template <class _ForwardIterator>
1110typename regex_traits<_CharT>::string_type
1111regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1112 _ForwardIterator __l, char) const
1113{
1114 const string_type __s(__f, __l);
1115 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1116 switch (__d.size())
1117 {
1118 case 1:
1119 break;
1120 case 12:
1121 __d[11] = __d[3];
1122 break;
1123 default:
1124 __d.clear();
1125 break;
1126 }
1127 return __d;
1128}
1129
1130template <class _CharT>
1131template <class _ForwardIterator>
1132typename regex_traits<_CharT>::string_type
1133regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
1134 _ForwardIterator __l, wchar_t) const
1135{
1136 const string_type __s(__f, __l);
1137 string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1138 switch (__d.size())
1139 {
1140 case 1:
1141 break;
1142 case 3:
1143 __d[2] = __d[0];
1144 break;
1145 default:
1146 __d.clear();
1147 break;
1148 }
1149 return __d;
1150}
1151
1152// lookup_collatename is very FreeBSD-specific
1153
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001154_LIBCPP_FUNC_VIS string __get_collation_name(const char* __s);
Howard Hinnant3257c982010-06-17 00:34:59 +00001155
1156template <class _CharT>
1157template <class _ForwardIterator>
1158typename regex_traits<_CharT>::string_type
1159regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1160 _ForwardIterator __l, char) const
1161{
1162 string_type __s(__f, __l);
1163 string_type __r;
1164 if (!__s.empty())
1165 {
1166 __r = __get_collation_name(__s.c_str());
1167 if (__r.empty() && __s.size() <= 2)
1168 {
1169 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1170 if (__r.size() == 1 || __r.size() == 12)
1171 __r = __s;
1172 else
1173 __r.clear();
1174 }
1175 }
1176 return __r;
1177}
1178
1179template <class _CharT>
1180template <class _ForwardIterator>
1181typename regex_traits<_CharT>::string_type
1182regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
1183 _ForwardIterator __l, wchar_t) const
1184{
1185 string_type __s(__f, __l);
1186 string __n;
1187 __n.reserve(__s.size());
1188 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1189 __i != __e; ++__i)
1190 {
1191 if (static_cast<unsigned>(*__i) >= 127)
1192 return string_type();
1193 __n.push_back(char(*__i));
1194 }
1195 string_type __r;
1196 if (!__s.empty())
1197 {
1198 __n = __get_collation_name(__n.c_str());
1199 if (!__n.empty())
1200 __r.assign(__n.begin(), __n.end());
1201 else if (__s.size() <= 2)
1202 {
1203 __r = __col_->transform(__s.data(), __s.data() + __s.size());
1204 if (__r.size() == 1 || __r.size() == 3)
1205 __r = __s;
1206 else
1207 __r.clear();
1208 }
1209 }
1210 return __r;
1211}
1212
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001213// lookup_classname
1214
Dan Albert17573862014-07-29 19:23:39 +00001215regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS
1216__get_classname(const char* __s, bool __icase);
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001217
1218template <class _CharT>
1219template <class _ForwardIterator>
1220typename regex_traits<_CharT>::char_class_type
1221regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1222 _ForwardIterator __l,
1223 bool __icase, char) const
1224{
1225 string_type __s(__f, __l);
1226 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1227 return __get_classname(__s.c_str(), __icase);
1228}
1229
1230template <class _CharT>
1231template <class _ForwardIterator>
1232typename regex_traits<_CharT>::char_class_type
1233regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
1234 _ForwardIterator __l,
1235 bool __icase, wchar_t) const
1236{
1237 string_type __s(__f, __l);
1238 __ct_->tolower(&__s[0], &__s[0] + __s.size());
1239 string __n;
1240 __n.reserve(__s.size());
1241 for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
1242 __i != __e; ++__i)
1243 {
1244 if (static_cast<unsigned>(*__i) >= 127)
1245 return char_class_type();
1246 __n.push_back(char(*__i));
1247 }
1248 return __get_classname(__n.c_str(), __icase);
1249}
1250
1251template <class _CharT>
1252bool
1253regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
1254{
1255 if (__ct_->is(__m, __c))
1256 return true;
1257 return (__c == '_' && (__m & __regex_word));
1258}
1259
1260template <class _CharT>
1261int
Marshall Clow33ae2332013-10-21 15:43:25 +00001262regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001263{
1264 if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
1265 return __ch - '0';
1266 if (__radix != 8)
1267 {
1268 if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
1269 return __ch - '0';
1270 if (__radix == 16)
1271 {
1272 __ch |= 0x20; // tolower
1273 if ('a' <= __ch && __ch <= 'f')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00001274 return __ch - ('a' - 10);
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001275 }
1276 }
1277 return -1;
1278}
1279
1280template <class _CharT>
Evgeniy Stepanova3b25f82015-11-07 01:22:13 +00001281inline
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001282int
Marshall Clow33ae2332013-10-21 15:43:25 +00001283regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001284{
Marshall Clow33ae2332013-10-21 15:43:25 +00001285 return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
Howard Hinnantf409d2f2010-06-21 21:01:43 +00001286}
1287
Howard Hinnantac303862010-07-12 15:51:17 +00001288template <class _CharT> class __node;
1289
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001290template <class _BidirectionalIterator> class _LIBCPP_TYPE_VIS_ONLY sub_match;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001291
Howard Hinnant17615b02010-07-27 01:25:38 +00001292template <class _BidirectionalIterator,
1293 class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001294class _LIBCPP_TYPE_VIS_ONLY match_results;
Howard Hinnant17615b02010-07-27 01:25:38 +00001295
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001296template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001297struct __state
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001298{
1299 enum
1300 {
1301 __end_state = -1000,
1302 __consume_input, // -999
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001303 __begin_marked_expr, // -998
1304 __end_marked_expr, // -997
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001305 __pop_state, // -996
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001306 __accept_and_consume, // -995
1307 __accept_but_not_consume, // -994
1308 __reject, // -993
Howard Hinnantac303862010-07-12 15:51:17 +00001309 __split,
1310 __repeat
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001311 };
1312
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001313 int __do_;
Howard Hinnantac303862010-07-12 15:51:17 +00001314 const _CharT* __first_;
1315 const _CharT* __current_;
1316 const _CharT* __last_;
1317 vector<sub_match<const _CharT*> > __sub_matches_;
1318 vector<pair<size_t, const _CharT*> > __loop_data_;
1319 const __node<_CharT>* __node_;
1320 regex_constants::match_flag_type __flags_;
Howard Hinnant41fb6e12011-03-26 20:02:27 +00001321 bool __at_first_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001322
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001323 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001324 __state()
1325 : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
1326 __node_(nullptr), __flags_() {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001327};
1328
Howard Hinnantac303862010-07-12 15:51:17 +00001329// __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001330
1331template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001332class __node
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001333{
Howard Hinnantac303862010-07-12 15:51:17 +00001334 __node(const __node&);
1335 __node& operator=(const __node&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001336public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001337 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001338
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001340 __node() {}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001341 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001342 virtual ~__node() {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001343
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001344 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001345 virtual void __exec(__state&) const {};
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001346 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001347 virtual void __exec_split(bool, __state&) const {};
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001348};
1349
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001350// __end_state
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001351
1352template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001353class __end_state
Howard Hinnantac303862010-07-12 15:51:17 +00001354 : public __node<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001355{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001356public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001357 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001358
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001359 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001360 __end_state() {}
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001361
Howard Hinnantac303862010-07-12 15:51:17 +00001362 virtual void __exec(__state&) const;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00001363};
1364
1365template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001366void
1367__end_state<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001368{
Howard Hinnantac303862010-07-12 15:51:17 +00001369 __s.__do_ = __state::__end_state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001370}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001371
1372// __has_one_state
1373
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00001374template <class _CharT>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001375class __has_one_state
Howard Hinnantac303862010-07-12 15:51:17 +00001376 : public __node<_CharT>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001377{
Howard Hinnantac303862010-07-12 15:51:17 +00001378 __node<_CharT>* __first_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001379
1380public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001381 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001382 explicit __has_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001383 : __first_(__s) {}
1384
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001385 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001386 __node<_CharT>* first() const {return __first_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001387 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001388 __node<_CharT>*& first() {return __first_;}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001389};
1390
1391// __owns_one_state
1392
1393template <class _CharT>
1394class __owns_one_state
1395 : public __has_one_state<_CharT>
1396{
1397 typedef __has_one_state<_CharT> base;
1398
1399public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001400 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001401 explicit __owns_one_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001402 : base(__s) {}
1403
1404 virtual ~__owns_one_state();
1405};
1406
1407template <class _CharT>
1408__owns_one_state<_CharT>::~__owns_one_state()
1409{
1410 delete this->first();
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00001411}
1412
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001413// __empty_state
1414
1415template <class _CharT>
1416class __empty_state
1417 : public __owns_one_state<_CharT>
1418{
1419 typedef __owns_one_state<_CharT> base;
1420
1421public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001422 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001423
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001425 explicit __empty_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001426 : base(__s) {}
1427
Howard Hinnantac303862010-07-12 15:51:17 +00001428 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001429};
1430
1431template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001432void
1433__empty_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001434{
Howard Hinnantac303862010-07-12 15:51:17 +00001435 __s.__do_ = __state::__accept_but_not_consume;
1436 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001437}
1438
1439// __empty_non_own_state
1440
1441template <class _CharT>
1442class __empty_non_own_state
1443 : public __has_one_state<_CharT>
1444{
1445 typedef __has_one_state<_CharT> base;
1446
1447public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001448 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001449
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001451 explicit __empty_non_own_state(__node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001452 : base(__s) {}
1453
Howard Hinnantac303862010-07-12 15:51:17 +00001454 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001455};
1456
1457template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001458void
1459__empty_non_own_state<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001460{
Howard Hinnantac303862010-07-12 15:51:17 +00001461 __s.__do_ = __state::__accept_but_not_consume;
1462 __s.__node_ = this->first();
1463}
1464
1465// __repeat_one_loop
1466
1467template <class _CharT>
1468class __repeat_one_loop
1469 : public __has_one_state<_CharT>
1470{
1471 typedef __has_one_state<_CharT> base;
1472
1473public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001474 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantac303862010-07-12 15:51:17 +00001475
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001477 explicit __repeat_one_loop(__node<_CharT>* __s)
1478 : base(__s) {}
1479
1480 virtual void __exec(__state&) const;
Howard Hinnantac303862010-07-12 15:51:17 +00001481};
1482
1483template <class _CharT>
1484void
1485__repeat_one_loop<_CharT>::__exec(__state& __s) const
1486{
1487 __s.__do_ = __state::__repeat;
1488 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001489}
1490
1491// __owns_two_states
1492
1493template <class _CharT>
1494class __owns_two_states
1495 : public __owns_one_state<_CharT>
1496{
1497 typedef __owns_one_state<_CharT> base;
1498
1499 base* __second_;
1500
1501public:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001503 explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001504 : base(__s1), __second_(__s2) {}
1505
1506 virtual ~__owns_two_states();
1507
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001508 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001509 base* second() const {return __second_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001511 base*& second() {return __second_;}
1512};
1513
1514template <class _CharT>
1515__owns_two_states<_CharT>::~__owns_two_states()
1516{
1517 delete __second_;
1518}
1519
1520// __loop
1521
1522template <class _CharT>
1523class __loop
1524 : public __owns_two_states<_CharT>
1525{
1526 typedef __owns_two_states<_CharT> base;
1527
1528 size_t __min_;
1529 size_t __max_;
1530 unsigned __loop_id_;
Howard Hinnantac303862010-07-12 15:51:17 +00001531 unsigned __mexp_begin_;
1532 unsigned __mexp_end_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001533 bool __greedy_;
1534
1535public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001536 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001537
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001538 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001539 explicit __loop(unsigned __loop_id,
Howard Hinnantac303862010-07-12 15:51:17 +00001540 __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
1541 unsigned __mexp_begin, unsigned __mexp_end,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001542 bool __greedy = true,
1543 size_t __min = 0,
1544 size_t __max = numeric_limits<size_t>::max())
1545 : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
Howard Hinnantac303862010-07-12 15:51:17 +00001546 __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001547 __greedy_(__greedy) {}
1548
Howard Hinnantac303862010-07-12 15:51:17 +00001549 virtual void __exec(__state& __s) const;
1550 virtual void __exec_split(bool __second, __state& __s) const;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001551
Howard Hinnantac303862010-07-12 15:51:17 +00001552private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001554 void __init_repeat(__state& __s) const
1555 {
1556 __s.__loop_data_[__loop_id_].second = __s.__current_;
1557 for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
1558 {
1559 __s.__sub_matches_[__i].first = __s.__last_;
1560 __s.__sub_matches_[__i].second = __s.__last_;
1561 __s.__sub_matches_[__i].matched = false;
1562 }
1563 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001564};
1565
1566template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001567void
1568__loop<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001569{
Howard Hinnantac303862010-07-12 15:51:17 +00001570 if (__s.__do_ == __state::__repeat)
1571 {
1572 bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
1573 bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
1574 if (__do_repeat && __do_alt &&
1575 __s.__loop_data_[__loop_id_].second == __s.__current_)
1576 __do_repeat = false;
1577 if (__do_repeat && __do_alt)
1578 __s.__do_ = __state::__split;
1579 else if (__do_repeat)
1580 {
1581 __s.__do_ = __state::__accept_but_not_consume;
1582 __s.__node_ = this->first();
1583 __init_repeat(__s);
1584 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001585 else
Howard Hinnantac303862010-07-12 15:51:17 +00001586 {
1587 __s.__do_ = __state::__accept_but_not_consume;
1588 __s.__node_ = this->second();
1589 }
1590 }
1591 else
1592 {
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00001593 __s.__loop_data_[__loop_id_].first = 0;
1594 bool __do_repeat = 0 < __max_;
1595 bool __do_alt = 0 >= __min_;
1596 if (__do_repeat && __do_alt)
Howard Hinnantac303862010-07-12 15:51:17 +00001597 __s.__do_ = __state::__split;
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00001598 else if (__do_repeat)
1599 {
1600 __s.__do_ = __state::__accept_but_not_consume;
1601 __s.__node_ = this->first();
1602 __init_repeat(__s);
1603 }
Howard Hinnantac303862010-07-12 15:51:17 +00001604 else
1605 {
1606 __s.__do_ = __state::__accept_but_not_consume;
1607 __s.__node_ = this->second();
1608 }
1609 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001610}
1611
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001612template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001613void
1614__loop<_CharT>::__exec_split(bool __second, __state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001615{
Howard Hinnantac303862010-07-12 15:51:17 +00001616 __s.__do_ = __state::__accept_but_not_consume;
1617 if (__greedy_ != __second)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001618 {
Howard Hinnantac303862010-07-12 15:51:17 +00001619 __s.__node_ = this->first();
1620 __init_repeat(__s);
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001621 }
Howard Hinnantac303862010-07-12 15:51:17 +00001622 else
1623 __s.__node_ = this->second();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001624}
1625
Howard Hinnantaa698082010-07-16 19:08:36 +00001626// __alternate
1627
1628template <class _CharT>
1629class __alternate
1630 : public __owns_two_states<_CharT>
1631{
1632 typedef __owns_two_states<_CharT> base;
1633
1634public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001635 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantaa698082010-07-16 19:08:36 +00001636
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001637 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantaa698082010-07-16 19:08:36 +00001638 explicit __alternate(__owns_one_state<_CharT>* __s1,
1639 __owns_one_state<_CharT>* __s2)
1640 : base(__s1, __s2) {}
1641
1642 virtual void __exec(__state& __s) const;
1643 virtual void __exec_split(bool __second, __state& __s) const;
Howard Hinnantaa698082010-07-16 19:08:36 +00001644};
1645
1646template <class _CharT>
1647void
1648__alternate<_CharT>::__exec(__state& __s) const
1649{
1650 __s.__do_ = __state::__split;
1651}
1652
1653template <class _CharT>
1654void
1655__alternate<_CharT>::__exec_split(bool __second, __state& __s) const
1656{
1657 __s.__do_ = __state::__accept_but_not_consume;
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001658 if (__second)
Howard Hinnantaa698082010-07-16 19:08:36 +00001659 __s.__node_ = this->second();
Howard Hinnant1371b2e2010-07-22 14:12:20 +00001660 else
1661 __s.__node_ = this->first();
Howard Hinnantaa698082010-07-16 19:08:36 +00001662}
1663
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001664// __begin_marked_subexpression
1665
1666template <class _CharT>
1667class __begin_marked_subexpression
1668 : public __owns_one_state<_CharT>
1669{
1670 typedef __owns_one_state<_CharT> base;
1671
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001672 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001673public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001674 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001675
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001677 explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001678 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001679
Howard Hinnantac303862010-07-12 15:51:17 +00001680 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001681};
1682
1683template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001684void
1685__begin_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001686{
Howard Hinnantac303862010-07-12 15:51:17 +00001687 __s.__do_ = __state::__accept_but_not_consume;
1688 __s.__sub_matches_[__mexp_-1].first = __s.__current_;
1689 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001690}
1691
1692// __end_marked_subexpression
1693
1694template <class _CharT>
1695class __end_marked_subexpression
1696 : public __owns_one_state<_CharT>
1697{
1698 typedef __owns_one_state<_CharT> base;
1699
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001700 unsigned __mexp_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001701public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001702 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001703
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001704 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001705 explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00001706 : base(__s), __mexp_(__mexp) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001707
Howard Hinnantac303862010-07-12 15:51:17 +00001708 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001709};
1710
1711template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00001712void
1713__end_marked_subexpression<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001714{
Howard Hinnantac303862010-07-12 15:51:17 +00001715 __s.__do_ = __state::__accept_but_not_consume;
1716 __s.__sub_matches_[__mexp_-1].second = __s.__current_;
1717 __s.__sub_matches_[__mexp_-1].matched = true;
1718 __s.__node_ = this->first();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001719}
1720
Howard Hinnantcba352d2010-07-12 18:16:05 +00001721// __back_ref
1722
1723template <class _CharT>
1724class __back_ref
1725 : public __owns_one_state<_CharT>
1726{
1727 typedef __owns_one_state<_CharT> base;
1728
1729 unsigned __mexp_;
1730public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001731 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantcba352d2010-07-12 18:16:05 +00001732
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001733 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcba352d2010-07-12 18:16:05 +00001734 explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
1735 : base(__s), __mexp_(__mexp) {}
1736
1737 virtual void __exec(__state&) const;
Howard Hinnantcba352d2010-07-12 18:16:05 +00001738};
1739
1740template <class _CharT>
1741void
1742__back_ref<_CharT>::__exec(__state& __s) const
1743{
Marshall Clow70e8f592015-08-24 15:57:09 +00001744 if (__mexp_ > __s.__sub_matches_.size())
1745 __throw_regex_error<regex_constants::error_backref>();
Howard Hinnantcba352d2010-07-12 18:16:05 +00001746 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1747 if (__sm.matched)
1748 {
1749 ptrdiff_t __len = __sm.second - __sm.first;
1750 if (__s.__last_ - __s.__current_ >= __len &&
Howard Hinnant0949eed2011-06-30 21:18:19 +00001751 _VSTD::equal(__sm.first, __sm.second, __s.__current_))
Howard Hinnantcba352d2010-07-12 18:16:05 +00001752 {
1753 __s.__do_ = __state::__accept_but_not_consume;
1754 __s.__current_ += __len;
1755 __s.__node_ = this->first();
1756 }
1757 else
1758 {
1759 __s.__do_ = __state::__reject;
1760 __s.__node_ = nullptr;
1761 }
1762 }
1763 else
1764 {
1765 __s.__do_ = __state::__reject;
1766 __s.__node_ = nullptr;
1767 }
1768}
1769
Howard Hinnante34f17d2010-07-12 19:11:27 +00001770// __back_ref_icase
1771
1772template <class _CharT, class _Traits>
1773class __back_ref_icase
1774 : public __owns_one_state<_CharT>
1775{
1776 typedef __owns_one_state<_CharT> base;
1777
1778 _Traits __traits_;
1779 unsigned __mexp_;
1780public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001781 typedef _VSTD::__state<_CharT> __state;
Howard Hinnante34f17d2010-07-12 19:11:27 +00001782
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00001784 explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
1785 __node<_CharT>* __s)
1786 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1787
1788 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00001789};
1790
1791template <class _CharT, class _Traits>
1792void
1793__back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
1794{
1795 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1796 if (__sm.matched)
1797 {
1798 ptrdiff_t __len = __sm.second - __sm.first;
1799 if (__s.__last_ - __s.__current_ >= __len)
1800 {
1801 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1802 {
1803 if (__traits_.translate_nocase(__sm.first[__i]) !=
1804 __traits_.translate_nocase(__s.__current_[__i]))
1805 goto __not_equal;
1806 }
1807 __s.__do_ = __state::__accept_but_not_consume;
1808 __s.__current_ += __len;
1809 __s.__node_ = this->first();
1810 }
1811 else
1812 {
1813 __s.__do_ = __state::__reject;
1814 __s.__node_ = nullptr;
1815 }
1816 }
1817 else
1818 {
1819__not_equal:
1820 __s.__do_ = __state::__reject;
1821 __s.__node_ = nullptr;
1822 }
1823}
1824
1825// __back_ref_collate
1826
1827template <class _CharT, class _Traits>
1828class __back_ref_collate
1829 : public __owns_one_state<_CharT>
1830{
1831 typedef __owns_one_state<_CharT> base;
1832
1833 _Traits __traits_;
1834 unsigned __mexp_;
1835public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001836 typedef _VSTD::__state<_CharT> __state;
Howard Hinnante34f17d2010-07-12 19:11:27 +00001837
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00001839 explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
1840 __node<_CharT>* __s)
1841 : base(__s), __traits_(__traits), __mexp_(__mexp) {}
1842
1843 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00001844};
1845
1846template <class _CharT, class _Traits>
1847void
1848__back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
1849{
1850 sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
1851 if (__sm.matched)
1852 {
1853 ptrdiff_t __len = __sm.second - __sm.first;
1854 if (__s.__last_ - __s.__current_ >= __len)
1855 {
1856 for (ptrdiff_t __i = 0; __i < __len; ++__i)
1857 {
1858 if (__traits_.translate(__sm.first[__i]) !=
1859 __traits_.translate(__s.__current_[__i]))
1860 goto __not_equal;
1861 }
1862 __s.__do_ = __state::__accept_but_not_consume;
1863 __s.__current_ += __len;
1864 __s.__node_ = this->first();
1865 }
1866 else
1867 {
1868 __s.__do_ = __state::__reject;
1869 __s.__node_ = nullptr;
1870 }
1871 }
1872 else
1873 {
1874__not_equal:
1875 __s.__do_ = __state::__reject;
1876 __s.__node_ = nullptr;
1877 }
1878}
1879
Howard Hinnant17615b02010-07-27 01:25:38 +00001880// __word_boundary
1881
1882template <class _CharT, class _Traits>
1883class __word_boundary
1884 : public __owns_one_state<_CharT>
1885{
1886 typedef __owns_one_state<_CharT> base;
1887
1888 _Traits __traits_;
1889 bool __invert_;
1890public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001891 typedef _VSTD::__state<_CharT> __state;
Howard Hinnant17615b02010-07-27 01:25:38 +00001892
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant17615b02010-07-27 01:25:38 +00001894 explicit __word_boundary(const _Traits& __traits, bool __invert,
1895 __node<_CharT>* __s)
1896 : base(__s), __traits_(__traits), __invert_(__invert) {}
1897
1898 virtual void __exec(__state&) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00001899};
1900
1901template <class _CharT, class _Traits>
1902void
1903__word_boundary<_CharT, _Traits>::__exec(__state& __s) const
1904{
1905 bool __is_word_b = false;
1906 if (__s.__first_ != __s.__last_)
1907 {
1908 if (__s.__current_ == __s.__last_)
1909 {
1910 if (!(__s.__flags_ & regex_constants::match_not_eow))
1911 {
1912 _CharT __c = __s.__current_[-1];
1913 __is_word_b = __c == '_' ||
1914 __traits_.isctype(__c, ctype_base::alnum);
1915 }
1916 }
Howard Hinnantf3dcca02010-07-29 15:17:28 +00001917 else if (__s.__current_ == __s.__first_ &&
1918 !(__s.__flags_ & regex_constants::match_prev_avail))
Howard Hinnant17615b02010-07-27 01:25:38 +00001919 {
1920 if (!(__s.__flags_ & regex_constants::match_not_bow))
1921 {
1922 _CharT __c = *__s.__current_;
1923 __is_word_b = __c == '_' ||
1924 __traits_.isctype(__c, ctype_base::alnum);
1925 }
1926 }
1927 else
1928 {
1929 _CharT __c1 = __s.__current_[-1];
1930 _CharT __c2 = *__s.__current_;
1931 bool __is_c1_b = __c1 == '_' ||
1932 __traits_.isctype(__c1, ctype_base::alnum);
1933 bool __is_c2_b = __c2 == '_' ||
1934 __traits_.isctype(__c2, ctype_base::alnum);
1935 __is_word_b = __is_c1_b != __is_c2_b;
1936 }
1937 }
1938 if (__is_word_b != __invert_)
1939 {
1940 __s.__do_ = __state::__accept_but_not_consume;
1941 __s.__node_ = this->first();
1942 }
1943 else
1944 {
1945 __s.__do_ = __state::__reject;
1946 __s.__node_ = nullptr;
1947 }
1948}
1949
Howard Hinnant41fb6e12011-03-26 20:02:27 +00001950// __l_anchor
1951
1952template <class _CharT>
1953class __l_anchor
1954 : public __owns_one_state<_CharT>
1955{
1956 typedef __owns_one_state<_CharT> base;
1957
1958public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001959 typedef _VSTD::__state<_CharT> __state;
Howard Hinnant41fb6e12011-03-26 20:02:27 +00001960
1961 _LIBCPP_INLINE_VISIBILITY
1962 __l_anchor(__node<_CharT>* __s)
1963 : base(__s) {}
1964
1965 virtual void __exec(__state&) const;
1966};
1967
1968template <class _CharT>
1969void
1970__l_anchor<_CharT>::__exec(__state& __s) const
1971{
Marshall Clow64befb52015-03-19 17:05:59 +00001972 if (__s.__at_first_ && __s.__current_ == __s.__first_ &&
1973 !(__s.__flags_ & regex_constants::match_not_bol))
Howard Hinnant41fb6e12011-03-26 20:02:27 +00001974 {
1975 __s.__do_ = __state::__accept_but_not_consume;
1976 __s.__node_ = this->first();
1977 }
1978 else
1979 {
1980 __s.__do_ = __state::__reject;
1981 __s.__node_ = nullptr;
1982 }
1983}
1984
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001985// __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001986
1987template <class _CharT>
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001988class __r_anchor
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001989 : public __owns_one_state<_CharT>
1990{
1991 typedef __owns_one_state<_CharT> base;
1992
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001993public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00001994 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001995
Howard Hinnantaef07cb2010-09-23 15:13:20 +00001996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00001997 __r_anchor(__node<_CharT>* __s)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00001998 : base(__s) {}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00001999
Howard Hinnantac303862010-07-12 15:51:17 +00002000 virtual void __exec(__state&) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002001};
2002
2003template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00002004void
2005__r_anchor<_CharT>::__exec(__state& __s) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002006{
Marshall Clow64befb52015-03-19 17:05:59 +00002007 if (__s.__current_ == __s.__last_ &&
2008 !(__s.__flags_ & regex_constants::match_not_eol))
Howard Hinnantac303862010-07-12 15:51:17 +00002009 {
2010 __s.__do_ = __state::__accept_but_not_consume;
2011 __s.__node_ = this->first();
2012 }
2013 else
2014 {
2015 __s.__do_ = __state::__reject;
2016 __s.__node_ = nullptr;
2017 }
2018}
2019
2020// __match_any
2021
2022template <class _CharT>
2023class __match_any
2024 : public __owns_one_state<_CharT>
2025{
2026 typedef __owns_one_state<_CharT> base;
2027
2028public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00002029 typedef _VSTD::__state<_CharT> __state;
Howard Hinnantac303862010-07-12 15:51:17 +00002030
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002031 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00002032 __match_any(__node<_CharT>* __s)
2033 : base(__s) {}
2034
2035 virtual void __exec(__state&) const;
Howard Hinnantac303862010-07-12 15:51:17 +00002036};
2037
2038template <class _CharT>
2039void
2040__match_any<_CharT>::__exec(__state& __s) const
2041{
2042 if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
2043 {
2044 __s.__do_ = __state::__accept_and_consume;
2045 ++__s.__current_;
2046 __s.__node_ = this->first();
2047 }
2048 else
2049 {
2050 __s.__do_ = __state::__reject;
2051 __s.__node_ = nullptr;
2052 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002053}
2054
Howard Hinnant17615b02010-07-27 01:25:38 +00002055// __match_any_but_newline
2056
2057template <class _CharT>
2058class __match_any_but_newline
2059 : public __owns_one_state<_CharT>
2060{
2061 typedef __owns_one_state<_CharT> base;
2062
2063public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00002064 typedef _VSTD::__state<_CharT> __state;
Howard Hinnant17615b02010-07-27 01:25:38 +00002065
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002066 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant17615b02010-07-27 01:25:38 +00002067 __match_any_but_newline(__node<_CharT>* __s)
2068 : base(__s) {}
2069
2070 virtual void __exec(__state&) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00002071};
2072
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002073template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
2074template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
2075
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002076// __match_char
2077
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002078template <class _CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002079class __match_char
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002080 : public __owns_one_state<_CharT>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002081{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002082 typedef __owns_one_state<_CharT> base;
2083
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002084 _CharT __c_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002085
2086 __match_char(const __match_char&);
2087 __match_char& operator=(const __match_char&);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002088public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00002089 typedef _VSTD::__state<_CharT> __state;
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002090
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantac303862010-07-12 15:51:17 +00002092 __match_char(_CharT __c, __node<_CharT>* __s)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002093 : base(__s), __c_(__c) {}
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002094
Howard Hinnantac303862010-07-12 15:51:17 +00002095 virtual void __exec(__state&) const;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002096};
2097
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002098template <class _CharT>
Howard Hinnantac303862010-07-12 15:51:17 +00002099void
2100__match_char<_CharT>::__exec(__state& __s) const
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002101{
Howard Hinnantac303862010-07-12 15:51:17 +00002102 if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
2103 {
2104 __s.__do_ = __state::__accept_and_consume;
2105 ++__s.__current_;
2106 __s.__node_ = this->first();
2107 }
2108 else
2109 {
2110 __s.__do_ = __state::__reject;
2111 __s.__node_ = nullptr;
2112 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002113}
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002114
Howard Hinnante34f17d2010-07-12 19:11:27 +00002115// __match_char_icase
2116
2117template <class _CharT, class _Traits>
2118class __match_char_icase
2119 : public __owns_one_state<_CharT>
2120{
2121 typedef __owns_one_state<_CharT> base;
2122
2123 _Traits __traits_;
2124 _CharT __c_;
2125
2126 __match_char_icase(const __match_char_icase&);
2127 __match_char_icase& operator=(const __match_char_icase&);
2128public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00002129 typedef _VSTD::__state<_CharT> __state;
Howard Hinnante34f17d2010-07-12 19:11:27 +00002130
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00002132 __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2133 : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
2134
2135 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00002136};
2137
2138template <class _CharT, class _Traits>
2139void
2140__match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
2141{
2142 if (__s.__current_ != __s.__last_ &&
2143 __traits_.translate_nocase(*__s.__current_) == __c_)
2144 {
2145 __s.__do_ = __state::__accept_and_consume;
2146 ++__s.__current_;
2147 __s.__node_ = this->first();
2148 }
2149 else
2150 {
2151 __s.__do_ = __state::__reject;
2152 __s.__node_ = nullptr;
2153 }
2154}
2155
2156// __match_char_collate
2157
2158template <class _CharT, class _Traits>
2159class __match_char_collate
2160 : public __owns_one_state<_CharT>
2161{
2162 typedef __owns_one_state<_CharT> base;
2163
2164 _Traits __traits_;
2165 _CharT __c_;
2166
2167 __match_char_collate(const __match_char_collate&);
2168 __match_char_collate& operator=(const __match_char_collate&);
2169public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00002170 typedef _VSTD::__state<_CharT> __state;
Howard Hinnante34f17d2010-07-12 19:11:27 +00002171
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante34f17d2010-07-12 19:11:27 +00002173 __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
2174 : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
2175
2176 virtual void __exec(__state&) const;
Howard Hinnante34f17d2010-07-12 19:11:27 +00002177};
2178
2179template <class _CharT, class _Traits>
2180void
2181__match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
2182{
2183 if (__s.__current_ != __s.__last_ &&
2184 __traits_.translate(*__s.__current_) == __c_)
2185 {
2186 __s.__do_ = __state::__accept_and_consume;
2187 ++__s.__current_;
2188 __s.__node_ = this->first();
2189 }
2190 else
2191 {
2192 __s.__do_ = __state::__reject;
2193 __s.__node_ = nullptr;
2194 }
2195}
2196
Howard Hinnant173968a2010-07-13 21:48:06 +00002197// __bracket_expression
2198
2199template <class _CharT, class _Traits>
2200class __bracket_expression
2201 : public __owns_one_state<_CharT>
2202{
2203 typedef __owns_one_state<_CharT> base;
2204 typedef typename _Traits::string_type string_type;
2205
2206 _Traits __traits_;
2207 vector<_CharT> __chars_;
Howard Hinnant15476f32010-07-28 17:35:27 +00002208 vector<_CharT> __neg_chars_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002209 vector<pair<string_type, string_type> > __ranges_;
2210 vector<pair<_CharT, _CharT> > __digraphs_;
2211 vector<string_type> __equivalences_;
Dan Albert17573862014-07-29 19:23:39 +00002212 typename regex_traits<_CharT>::char_class_type __mask_;
2213 typename regex_traits<_CharT>::char_class_type __neg_mask_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002214 bool __negate_;
2215 bool __icase_;
2216 bool __collate_;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002217 bool __might_have_digraph_;
Howard Hinnant173968a2010-07-13 21:48:06 +00002218
2219 __bracket_expression(const __bracket_expression&);
2220 __bracket_expression& operator=(const __bracket_expression&);
2221public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00002222 typedef _VSTD::__state<_CharT> __state;
Howard Hinnant173968a2010-07-13 21:48:06 +00002223
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002225 __bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
2226 bool __negate, bool __icase, bool __collate)
Howard Hinnant15476f32010-07-28 17:35:27 +00002227 : base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
2228 __negate_(__negate), __icase_(__icase), __collate_(__collate),
Howard Hinnant68025ed2010-07-14 15:45:11 +00002229 __might_have_digraph_(__traits_.getloc().name() != "C") {}
Howard Hinnant173968a2010-07-13 21:48:06 +00002230
2231 virtual void __exec(__state&) const;
2232
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002233 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant15476f32010-07-28 17:35:27 +00002234 bool __negated() const {return __negate_;}
2235
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002236 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002237 void __add_char(_CharT __c)
2238 {
2239 if (__icase_)
2240 __chars_.push_back(__traits_.translate_nocase(__c));
2241 else if (__collate_)
2242 __chars_.push_back(__traits_.translate(__c));
2243 else
2244 __chars_.push_back(__c);
2245 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant15476f32010-07-28 17:35:27 +00002247 void __add_neg_char(_CharT __c)
2248 {
2249 if (__icase_)
2250 __neg_chars_.push_back(__traits_.translate_nocase(__c));
2251 else if (__collate_)
2252 __neg_chars_.push_back(__traits_.translate(__c));
2253 else
2254 __neg_chars_.push_back(__c);
2255 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002257 void __add_range(string_type __b, string_type __e)
2258 {
2259 if (__collate_)
2260 {
2261 if (__icase_)
2262 {
2263 for (size_t __i = 0; __i < __b.size(); ++__i)
2264 __b[__i] = __traits_.translate_nocase(__b[__i]);
2265 for (size_t __i = 0; __i < __e.size(); ++__i)
2266 __e[__i] = __traits_.translate_nocase(__e[__i]);
2267 }
2268 else
2269 {
2270 for (size_t __i = 0; __i < __b.size(); ++__i)
2271 __b[__i] = __traits_.translate(__b[__i]);
2272 for (size_t __i = 0; __i < __e.size(); ++__i)
2273 __e[__i] = __traits_.translate(__e[__i]);
2274 }
2275 __ranges_.push_back(make_pair(
2276 __traits_.transform(__b.begin(), __b.end()),
2277 __traits_.transform(__e.begin(), __e.end())));
2278 }
2279 else
2280 {
2281 if (__b.size() != 1 || __e.size() != 1)
Marshall Clow2576c292015-07-28 13:30:47 +00002282 __throw_regex_error<regex_constants::error_collate>();
Howard Hinnant173968a2010-07-13 21:48:06 +00002283 if (__icase_)
2284 {
2285 __b[0] = __traits_.translate_nocase(__b[0]);
2286 __e[0] = __traits_.translate_nocase(__e[0]);
2287 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002288 __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e)));
Howard Hinnant173968a2010-07-13 21:48:06 +00002289 }
2290 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002292 void __add_digraph(_CharT __c1, _CharT __c2)
2293 {
2294 if (__icase_)
2295 __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
2296 __traits_.translate_nocase(__c2)));
2297 else if (__collate_)
2298 __digraphs_.push_back(make_pair(__traits_.translate(__c1),
2299 __traits_.translate(__c2)));
2300 else
2301 __digraphs_.push_back(make_pair(__c1, __c2));
2302 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002303 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant173968a2010-07-13 21:48:06 +00002304 void __add_equivalence(const string_type& __s)
2305 {__equivalences_.push_back(__s);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002306 _LIBCPP_INLINE_VISIBILITY
Dan Albert17573862014-07-29 19:23:39 +00002307 void __add_class(typename regex_traits<_CharT>::char_class_type __mask)
Howard Hinnant173968a2010-07-13 21:48:06 +00002308 {__mask_ |= __mask;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002309 _LIBCPP_INLINE_VISIBILITY
Dan Albert17573862014-07-29 19:23:39 +00002310 void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask)
Howard Hinnant15476f32010-07-28 17:35:27 +00002311 {__neg_mask_ |= __mask;}
Howard Hinnant173968a2010-07-13 21:48:06 +00002312};
2313
2314template <class _CharT, class _Traits>
2315void
2316__bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
2317{
2318 bool __found = false;
2319 unsigned __consumed = 0;
2320 if (__s.__current_ != __s.__last_)
2321 {
2322 ++__consumed;
Howard Hinnant68025ed2010-07-14 15:45:11 +00002323 if (__might_have_digraph_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002324 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002325 const _CharT* __next = _VSTD::next(__s.__current_);
Howard Hinnant68025ed2010-07-14 15:45:11 +00002326 if (__next != __s.__last_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002327 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002328 pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2329 if (__icase_)
Howard Hinnant173968a2010-07-13 21:48:06 +00002330 {
Howard Hinnant68025ed2010-07-14 15:45:11 +00002331 __ch2.first = __traits_.translate_nocase(__ch2.first);
2332 __ch2.second = __traits_.translate_nocase(__ch2.second);
2333 }
2334 else if (__collate_)
2335 {
2336 __ch2.first = __traits_.translate(__ch2.first);
2337 __ch2.second = __traits_.translate(__ch2.second);
2338 }
2339 if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
2340 {
2341 // __ch2 is a digraph in this locale
2342 ++__consumed;
2343 for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
2344 {
2345 if (__ch2 == __digraphs_[__i])
2346 {
2347 __found = true;
2348 goto __exit;
2349 }
2350 }
2351 if (__collate_ && !__ranges_.empty())
2352 {
2353 string_type __s2 = __traits_.transform(&__ch2.first,
2354 &__ch2.first + 2);
2355 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2356 {
2357 if (__ranges_[__i].first <= __s2 &&
2358 __s2 <= __ranges_[__i].second)
2359 {
2360 __found = true;
2361 goto __exit;
2362 }
2363 }
2364 }
2365 if (!__equivalences_.empty())
2366 {
2367 string_type __s2 = __traits_.transform_primary(&__ch2.first,
2368 &__ch2.first + 2);
2369 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2370 {
2371 if (__s2 == __equivalences_[__i])
2372 {
2373 __found = true;
2374 goto __exit;
2375 }
2376 }
2377 }
2378 if (__traits_.isctype(__ch2.first, __mask_) &&
2379 __traits_.isctype(__ch2.second, __mask_))
Howard Hinnant173968a2010-07-13 21:48:06 +00002380 {
2381 __found = true;
2382 goto __exit;
2383 }
Howard Hinnant15476f32010-07-28 17:35:27 +00002384 if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
2385 !__traits_.isctype(__ch2.second, __neg_mask_))
2386 {
2387 __found = true;
2388 goto __exit;
2389 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002390 goto __exit;
2391 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002392 }
2393 }
2394 // test *__s.__current_ as not a digraph
2395 _CharT __ch = *__s.__current_;
2396 if (__icase_)
2397 __ch = __traits_.translate_nocase(__ch);
2398 else if (__collate_)
2399 __ch = __traits_.translate(__ch);
2400 for (size_t __i = 0; __i < __chars_.size(); ++__i)
2401 {
2402 if (__ch == __chars_[__i])
2403 {
2404 __found = true;
2405 goto __exit;
2406 }
2407 }
Howard Hinnant15476f32010-07-28 17:35:27 +00002408 if (!__neg_chars_.empty())
2409 {
2410 for (size_t __i = 0; __i < __neg_chars_.size(); ++__i)
2411 {
2412 if (__ch == __neg_chars_[__i])
2413 goto __is_neg_char;
2414 }
2415 __found = true;
2416 goto __exit;
2417 }
2418__is_neg_char:
Howard Hinnant173968a2010-07-13 21:48:06 +00002419 if (!__ranges_.empty())
2420 {
2421 string_type __s2 = __collate_ ?
2422 __traits_.transform(&__ch, &__ch + 1) :
2423 string_type(1, __ch);
2424 for (size_t __i = 0; __i < __ranges_.size(); ++__i)
2425 {
2426 if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
2427 {
2428 __found = true;
2429 goto __exit;
2430 }
2431 }
2432 }
2433 if (!__equivalences_.empty())
2434 {
2435 string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2436 for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
2437 {
2438 if (__s2 == __equivalences_[__i])
2439 {
2440 __found = true;
2441 goto __exit;
2442 }
2443 }
2444 }
2445 if (__traits_.isctype(__ch, __mask_))
Howard Hinnant15476f32010-07-28 17:35:27 +00002446 {
Howard Hinnant173968a2010-07-13 21:48:06 +00002447 __found = true;
Howard Hinnant15476f32010-07-28 17:35:27 +00002448 goto __exit;
2449 }
2450 if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_))
2451 {
2452 __found = true;
2453 goto __exit;
2454 }
Howard Hinnant173968a2010-07-13 21:48:06 +00002455 }
2456 else
2457 __found = __negate_; // force reject
2458__exit:
2459 if (__found != __negate_)
2460 {
Howard Hinnant173968a2010-07-13 21:48:06 +00002461 __s.__do_ = __state::__accept_and_consume;
2462 __s.__current_ += __consumed;
2463 __s.__node_ = this->first();
2464 }
2465 else
2466 {
2467 __s.__do_ = __state::__reject;
2468 __s.__node_ = nullptr;
2469 }
2470}
2471
Howard Hinnant2b1b2d42011-06-14 19:58:17 +00002472template <class _CharT, class _Traits> class __lookahead;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002473
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002474template <class _CharT, class _Traits = regex_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002475class _LIBCPP_TYPE_VIS_ONLY basic_regex
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002476{
2477public:
2478 // types:
2479 typedef _CharT value_type;
Hubert Tongb49c67f2016-08-02 21:34:48 +00002480 typedef _Traits traits_type;
2481 typedef typename _Traits::string_type string_type;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002482 typedef regex_constants::syntax_option_type flag_type;
2483 typedef typename _Traits::locale_type locale_type;
2484
2485private:
2486 _Traits __traits_;
2487 flag_type __flags_;
2488 unsigned __marked_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002489 unsigned __loop_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002490 int __open_count_;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002491 shared_ptr<__empty_state<_CharT> > __start_;
2492 __owns_one_state<_CharT>* __end_;
2493
Howard Hinnant0949eed2011-06-30 21:18:19 +00002494 typedef _VSTD::__state<_CharT> __state;
2495 typedef _VSTD::__node<_CharT> __node;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002496
2497public:
2498 // constants:
Howard Hinnant46623a02012-07-21 01:31:58 +00002499 static const regex_constants::syntax_option_type icase = regex_constants::icase;
2500 static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
2501 static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
2502 static const regex_constants::syntax_option_type collate = regex_constants::collate;
2503 static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
2504 static const regex_constants::syntax_option_type basic = regex_constants::basic;
2505 static const regex_constants::syntax_option_type extended = regex_constants::extended;
2506 static const regex_constants::syntax_option_type awk = regex_constants::awk;
2507 static const regex_constants::syntax_option_type grep = regex_constants::grep;
2508 static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002509
2510 // construct/copy/destroy:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002512 basic_regex()
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002513 : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002514 __end_(0)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002515 {}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002517 explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002518 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002519 __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002520 {__parse(__p, __p + __traits_.length(__p));}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002521 _LIBCPP_INLINE_VISIBILITY
Hubert Tong7f6e8e22016-08-07 22:26:04 +00002522 basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002523 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002524 __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002525 {__parse(__p, __p + __len);}
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002526// basic_regex(const basic_regex&) = default;
2527// basic_regex(basic_regex&&) = default;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002528 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002529 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002530 explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
2531 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002532 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002533 __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002534 {__parse(__p.begin(), __p.end());}
2535 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002537 basic_regex(_ForwardIterator __first, _ForwardIterator __last,
2538 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002539 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002540 __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002541 {__parse(__first, __last);}
Howard Hinnante3e32912011-08-12 21:56:02 +00002542#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002544 basic_regex(initializer_list<value_type> __il,
2545 flag_type __f = regex_constants::ECMAScript)
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002546 : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002547 __end_(0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002548 {__parse(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +00002549#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002550
Howard Hinnant7026a172010-08-13 18:11:23 +00002551// ~basic_regex() = default;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002552
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002553// basic_regex& operator=(const basic_regex&) = default;
2554// basic_regex& operator=(basic_regex&&) = default;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002556 basic_regex& operator=(const value_type* __p)
2557 {return assign(__p);}
Howard Hinnante3e32912011-08-12 21:56:02 +00002558#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002559 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002560 basic_regex& operator=(initializer_list<value_type> __il)
2561 {return assign(__il);}
Howard Hinnante3e32912011-08-12 21:56:02 +00002562#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002563 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002564 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002565 basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
2566 {return assign(__p);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002567
2568 // assign:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002570 basic_regex& assign(const basic_regex& __that)
2571 {return *this = __that;}
Howard Hinnant46623a02012-07-21 01:31:58 +00002572#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2573 _LIBCPP_INLINE_VISIBILITY
2574 basic_regex& assign(basic_regex&& __that) _NOEXCEPT
2575 {return *this = _VSTD::move(__that);}
2576#endif
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002577 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002578 basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2579 {return assign(__p, __p + __traits_.length(__p), __f);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002581 basic_regex& assign(const value_type* __p, size_t __len, flag_type __f)
2582 {return assign(__p, __p + __len, __f);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002583 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002585 basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
Howard Hinnant7026a172010-08-13 18:11:23 +00002586 flag_type __f = regex_constants::ECMAScript)
2587 {return assign(__s.begin(), __s.end(), __f);}
2588
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002589 template <class _InputIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002591 typename enable_if
2592 <
2593 __is_input_iterator <_InputIterator>::value &&
2594 !__is_forward_iterator<_InputIterator>::value,
2595 basic_regex&
2596 >::type
2597 assign(_InputIterator __first, _InputIterator __last,
2598 flag_type __f = regex_constants::ECMAScript)
2599 {
2600 basic_string<_CharT> __t(__first, __last);
2601 return assign(__t.begin(), __t.end(), __f);
2602 }
2603
2604private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002605 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002606 void __member_init(flag_type __f)
2607 {
2608 __flags_ = __f;
2609 __marked_count_ = 0;
2610 __loop_count_ = 0;
2611 __open_count_ = 0;
2612 __end_ = nullptr;
Howard Hinnant7026a172010-08-13 18:11:23 +00002613 }
2614public:
2615
2616 template <class _ForwardIterator>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002618 typename enable_if
2619 <
2620 __is_forward_iterator<_ForwardIterator>::value,
2621 basic_regex&
2622 >::type
2623 assign(_ForwardIterator __first, _ForwardIterator __last,
2624 flag_type __f = regex_constants::ECMAScript)
2625 {
Marshall Clow083e0112015-01-13 16:49:52 +00002626 return assign(basic_regex(__first, __last, __f));
Howard Hinnant7026a172010-08-13 18:11:23 +00002627 }
2628
Howard Hinnante3e32912011-08-12 21:56:02 +00002629#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2630
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002632 basic_regex& assign(initializer_list<value_type> __il,
Howard Hinnant7026a172010-08-13 18:11:23 +00002633 flag_type __f = regex_constants::ECMAScript)
2634 {return assign(__il.begin(), __il.end(), __f);}
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002635
Howard Hinnante3e32912011-08-12 21:56:02 +00002636#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
2637
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002638 // const operations:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002640 unsigned mark_count() const {return __marked_count_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002642 flag_type flags() const {return __flags_;}
2643
2644 // locale:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002645 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7026a172010-08-13 18:11:23 +00002646 locale_type imbue(locale_type __loc)
2647 {
2648 __member_init(ECMAScript);
2649 __start_.reset();
2650 return __traits_.imbue(__loc);
2651 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002653 locale_type getloc() const {return __traits_.getloc();}
2654
2655 // swap:
Howard Hinnant7026a172010-08-13 18:11:23 +00002656 void swap(basic_regex& __r);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002657
2658private:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002659 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002660 unsigned __loop_count() const {return __loop_count_;}
2661
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002662 template <class _ForwardIterator>
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002663 _ForwardIterator
2664 __parse(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002665 template <class _ForwardIterator>
2666 _ForwardIterator
2667 __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2668 template <class _ForwardIterator>
2669 _ForwardIterator
2670 __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
2671 template <class _ForwardIterator>
2672 _ForwardIterator
2673 __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
2674 template <class _ForwardIterator>
2675 _ForwardIterator
2676 __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
2677 template <class _ForwardIterator>
2678 _ForwardIterator
2679 __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
2680 template <class _ForwardIterator>
2681 _ForwardIterator
2682 __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
2683 template <class _ForwardIterator>
2684 _ForwardIterator
2685 __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
2686 template <class _ForwardIterator>
2687 _ForwardIterator
2688 __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
2689 template <class _ForwardIterator>
2690 _ForwardIterator
2691 __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
2692 template <class _ForwardIterator>
2693 _ForwardIterator
2694 __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
2695 template <class _ForwardIterator>
2696 _ForwardIterator
2697 __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2698 template <class _ForwardIterator>
2699 _ForwardIterator
2700 __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
2701 template <class _ForwardIterator>
2702 _ForwardIterator
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002703 __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002704 __owns_one_state<_CharT>* __s,
2705 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002706 template <class _ForwardIterator>
2707 _ForwardIterator
Howard Hinnantaa698082010-07-16 19:08:36 +00002708 __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
2709 __owns_one_state<_CharT>* __s,
2710 unsigned __mexp_begin, unsigned __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002711 template <class _ForwardIterator>
2712 _ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00002713 __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
2714 template <class _ForwardIterator>
2715 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002716 __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
2717 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002718 template <class _ForwardIterator>
2719 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002720 __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
2721 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002722 template <class _ForwardIterator>
2723 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002724 __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
2725 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002726 template <class _ForwardIterator>
2727 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002728 __parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
2729 __bracket_expression<_CharT, _Traits>* __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002730 template <class _ForwardIterator>
2731 _ForwardIterator
Howard Hinnant173968a2010-07-13 21:48:06 +00002732 __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
2733 basic_string<_CharT>& __col_sym);
Howard Hinnant0de86b62010-06-25 20:56:08 +00002734 template <class _ForwardIterator>
2735 _ForwardIterator
2736 __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002737 template <class _ForwardIterator>
2738 _ForwardIterator
2739 __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2740 template <class _ForwardIterator>
2741 _ForwardIterator
2742 __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2743 template <class _ForwardIterator>
2744 _ForwardIterator
2745 __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2746 template <class _ForwardIterator>
2747 _ForwardIterator
2748 __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2749 template <class _ForwardIterator>
2750 _ForwardIterator
2751 __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2752 template <class _ForwardIterator>
2753 _ForwardIterator
2754 __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002755 template <class _ForwardIterator>
2756 _ForwardIterator
2757 __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2758 template <class _ForwardIterator>
2759 _ForwardIterator
2760 __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2761 template <class _ForwardIterator>
2762 _ForwardIterator
2763 __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2764 template <class _ForwardIterator>
2765 _ForwardIterator
2766 __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2767 template <class _ForwardIterator>
2768 _ForwardIterator
2769 __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2770 template <class _ForwardIterator>
2771 _ForwardIterator
Howard Hinnant17615b02010-07-27 01:25:38 +00002772 __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2773 template <class _ForwardIterator>
2774 _ForwardIterator
2775 __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2776 template <class _ForwardIterator>
2777 _ForwardIterator
2778 __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
2779 template <class _ForwardIterator>
2780 _ForwardIterator
Howard Hinnant15476f32010-07-28 17:35:27 +00002781 __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
2782 basic_string<_CharT>* __str = nullptr);
Howard Hinnant17615b02010-07-27 01:25:38 +00002783 template <class _ForwardIterator>
2784 _ForwardIterator
2785 __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant856846b2010-07-27 19:53:10 +00002786 template <class _ForwardIterator>
2787 _ForwardIterator
2788 __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
2789 template <class _ForwardIterator>
2790 _ForwardIterator
2791 __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
Howard Hinnant15476f32010-07-28 17:35:27 +00002792 template <class _ForwardIterator>
2793 _ForwardIterator
2794 __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
2795 basic_string<_CharT>& __str,
2796 __bracket_expression<_CharT, _Traits>* __ml);
2797 template <class _ForwardIterator>
2798 _ForwardIterator
2799 __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
2800 basic_string<_CharT>* __str = nullptr);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002801
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002803 void __push_l_anchor();
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00002804 void __push_r_anchor();
Howard Hinnantac303862010-07-12 15:51:17 +00002805 void __push_match_any();
Howard Hinnant17615b02010-07-27 01:25:38 +00002806 void __push_match_any_but_newline();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante77aa5e2010-07-08 17:43:58 +00002808 void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2809 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2810 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2811 __mexp_begin, __mexp_end);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant17615b02010-07-27 01:25:38 +00002813 void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
2814 unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
2815 {__push_loop(__min, numeric_limits<size_t>::max(), __s,
2816 __mexp_begin, __mexp_end, false);}
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002817 void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
2818 size_t __mexp_begin = 0, size_t __mexp_end = 0,
2819 bool __greedy = true);
Howard Hinnant173968a2010-07-13 21:48:06 +00002820 __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00002821 void __push_char(value_type __c);
Howard Hinnantcba352d2010-07-12 18:16:05 +00002822 void __push_back_ref(int __i);
Howard Hinnantaa698082010-07-16 19:08:36 +00002823 void __push_alternation(__owns_one_state<_CharT>* __sa,
2824 __owns_one_state<_CharT>* __sb);
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00002825 void __push_begin_marked_subexpression();
2826 void __push_end_marked_subexpression(unsigned);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00002827 void __push_empty();
Howard Hinnant17615b02010-07-27 01:25:38 +00002828 void __push_word_boundary(bool);
Howard Hinnantcd59acc2013-07-23 16:18:04 +00002829 void __push_lookahead(const basic_regex&, bool, unsigned);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002830
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002831 template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002832 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002833 __search(const _CharT* __first, const _CharT* __last,
2834 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002835 regex_constants::match_flag_type __flags) const;
2836
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002837 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002838 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002839 __match_at_start(const _CharT* __first, const _CharT* __last,
2840 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002841 regex_constants::match_flag_type __flags, bool) const;
Howard Hinnant17615b02010-07-27 01:25:38 +00002842 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002843 bool
Howard Hinnant17615b02010-07-27 01:25:38 +00002844 __match_at_start_ecma(const _CharT* __first, const _CharT* __last,
2845 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002846 regex_constants::match_flag_type __flags, bool) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002847 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002848 bool
2849 __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002850 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002851 regex_constants::match_flag_type __flags, bool) const;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002852 template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002853 bool
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002854 __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
2855 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00002856 regex_constants::match_flag_type __flags, bool) const;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002857
Howard Hinnant99968442011-11-29 18:15:50 +00002858 template <class _Bp, class _Ap, class _Cp, class _Tp>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002859 friend
2860 bool
Howard Hinnant99968442011-11-29 18:15:50 +00002861 regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00002862 regex_constants::match_flag_type);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002863
Howard Hinnant99968442011-11-29 18:15:50 +00002864 template <class _Ap, class _Cp, class _Tp>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002865 friend
2866 bool
Howard Hinnant99968442011-11-29 18:15:50 +00002867 regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&,
2868 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002869
Howard Hinnant99968442011-11-29 18:15:50 +00002870 template <class _Bp, class _Cp, class _Tp>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002871 friend
2872 bool
Howard Hinnant99968442011-11-29 18:15:50 +00002873 regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002874 regex_constants::match_flag_type);
2875
Howard Hinnant99968442011-11-29 18:15:50 +00002876 template <class _Cp, class _Tp>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002877 friend
2878 bool
Howard Hinnant99968442011-11-29 18:15:50 +00002879 regex_search(const _Cp*, const _Cp*,
2880 const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002881
Howard Hinnant99968442011-11-29 18:15:50 +00002882 template <class _Cp, class _Ap, class _Tp>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002883 friend
2884 bool
Howard Hinnant99968442011-11-29 18:15:50 +00002885 regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002886 regex_constants::match_flag_type);
2887
Howard Hinnant99968442011-11-29 18:15:50 +00002888 template <class _ST, class _SA, class _Cp, class _Tp>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002889 friend
2890 bool
Howard Hinnant99968442011-11-29 18:15:50 +00002891 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
2892 const basic_regex<_Cp, _Tp>& __e,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002893 regex_constants::match_flag_type __flags);
2894
Howard Hinnant99968442011-11-29 18:15:50 +00002895 template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002896 friend
2897 bool
Howard Hinnant99968442011-11-29 18:15:50 +00002898 regex_search(const basic_string<_Cp, _ST, _SA>& __s,
2899 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
2900 const basic_regex<_Cp, _Tp>& __e,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00002901 regex_constants::match_flag_type __flags);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002902
Howard Hinnanta9602d52013-06-29 23:45:43 +00002903 template <class _Iter, class _Ap, class _Cp, class _Tp>
2904 friend
2905 bool
2906 regex_search(__wrap_iter<_Iter> __first,
2907 __wrap_iter<_Iter> __last,
2908 match_results<__wrap_iter<_Iter>, _Ap>& __m,
2909 const basic_regex<_Cp, _Tp>& __e,
2910 regex_constants::match_flag_type __flags);
2911
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002912 template <class, class> friend class __lookahead;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00002913};
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002914
2915template <class _CharT, class _Traits>
Howard Hinnant0a69fa12012-12-12 21:14:28 +00002916 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
2917template <class _CharT, class _Traits>
2918 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
2919template <class _CharT, class _Traits>
2920 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
2921template <class _CharT, class _Traits>
2922 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
2923template <class _CharT, class _Traits>
2924 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
2925template <class _CharT, class _Traits>
2926 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
2927template <class _CharT, class _Traits>
2928 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
2929template <class _CharT, class _Traits>
2930 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
2931template <class _CharT, class _Traits>
2932 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
2933template <class _CharT, class _Traits>
2934 const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
2935
2936template <class _CharT, class _Traits>
Howard Hinnant7026a172010-08-13 18:11:23 +00002937void
2938basic_regex<_CharT, _Traits>::swap(basic_regex& __r)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002939{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002940 using _VSTD::swap;
Howard Hinnant7026a172010-08-13 18:11:23 +00002941 swap(__traits_, __r.__traits_);
2942 swap(__flags_, __r.__flags_);
2943 swap(__marked_count_, __r.__marked_count_);
2944 swap(__loop_count_, __r.__loop_count_);
2945 swap(__open_count_, __r.__open_count_);
2946 swap(__start_, __r.__start_);
2947 swap(__end_, __r.__end_);
Howard Hinnant7026a172010-08-13 18:11:23 +00002948}
2949
2950template <class _CharT, class _Traits>
2951inline _LIBCPP_INLINE_VISIBILITY
2952void
2953swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
2954{
2955 return __x.swap(__y);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00002956}
2957
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002958// __lookahead
2959
2960template <class _CharT, class _Traits>
2961class __lookahead
2962 : public __owns_one_state<_CharT>
2963{
2964 typedef __owns_one_state<_CharT> base;
2965
2966 basic_regex<_CharT, _Traits> __exp_;
Howard Hinnantcd59acc2013-07-23 16:18:04 +00002967 unsigned __mexp_;
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002968 bool __invert_;
2969
2970 __lookahead(const __lookahead&);
2971 __lookahead& operator=(const __lookahead&);
2972public:
Howard Hinnant0949eed2011-06-30 21:18:19 +00002973 typedef _VSTD::__state<_CharT> __state;
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002974
Howard Hinnantaef07cb2010-09-23 15:13:20 +00002975 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd59acc2013-07-23 16:18:04 +00002976 __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
Eric Fiselier7cc71062015-07-22 01:29:41 +00002977 : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002978
2979 virtual void __exec(__state&) const;
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002980};
2981
2982template <class _CharT, class _Traits>
2983void
2984__lookahead<_CharT, _Traits>::__exec(__state& __s) const
2985{
2986 match_results<const _CharT*> __m;
2987 __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
Tim Shen38c2a372016-10-27 21:40:34 +00002988 bool __matched = __exp_.__match_at_start_ecma(
2989 __s.__current_, __s.__last_,
2990 __m,
2991 (__s.__flags_ | regex_constants::match_continuous) &
2992 ~regex_constants::__full_match,
2993 __s.__at_first_ && __s.__current_ == __s.__first_);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00002994 if (__matched != __invert_)
2995 {
2996 __s.__do_ = __state::__accept_but_not_consume;
2997 __s.__node_ = this->first();
Howard Hinnantcd59acc2013-07-23 16:18:04 +00002998 for (unsigned __i = 1; __i < __m.size(); ++__i) {
2999 __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
3000 }
Howard Hinnante9de5ff2010-07-27 22:20:32 +00003001 }
3002 else
3003 {
3004 __s.__do_ = __state::__reject;
3005 __s.__node_ = nullptr;
3006 }
3007}
3008
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003009template <class _CharT, class _Traits>
3010template <class _ForwardIterator>
Howard Hinnante9de5ff2010-07-27 22:20:32 +00003011_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003012basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
3013 _ForwardIterator __last)
3014{
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003015 {
Howard Hinnantac303862010-07-12 15:51:17 +00003016 unique_ptr<__node> __h(new __end_state<_CharT>);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003017 __start_.reset(new __empty_state<_CharT>(__h.get()));
3018 __h.release();
3019 __end_ = __start_.get();
3020 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00003021 switch (__flags_ & 0x1F0)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003022 {
3023 case ECMAScript:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00003024 __first = __parse_ecma_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003025 break;
3026 case basic:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00003027 __first = __parse_basic_reg_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003028 break;
3029 case extended:
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003030 case awk:
Howard Hinnant15476f32010-07-28 17:35:27 +00003031 __first = __parse_extended_reg_exp(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003032 break;
3033 case grep:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00003034 __first = __parse_grep(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003035 break;
3036 case egrep:
Howard Hinnante9de5ff2010-07-27 22:20:32 +00003037 __first = __parse_egrep(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003038 break;
3039 default:
Marshall Clow2576c292015-07-28 13:30:47 +00003040 __throw_regex_error<regex_constants::__re_err_grammar>();
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003041 }
Howard Hinnante9de5ff2010-07-27 22:20:32 +00003042 return __first;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003043}
3044
3045template <class _CharT, class _Traits>
3046template <class _ForwardIterator>
3047_ForwardIterator
3048basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
3049 _ForwardIterator __last)
3050{
3051 if (__first != __last)
3052 {
3053 if (*__first == '^')
3054 {
3055 __push_l_anchor();
3056 ++__first;
3057 }
3058 if (__first != __last)
3059 {
3060 __first = __parse_RE_expression(__first, __last);
3061 if (__first != __last)
3062 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003063 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003064 if (__temp == __last && *__first == '$')
3065 {
3066 __push_r_anchor();
3067 ++__first;
3068 }
3069 }
3070 }
3071 if (__first != __last)
Marshall Clow2576c292015-07-28 13:30:47 +00003072 __throw_regex_error<regex_constants::__re_err_empty>();
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003073 }
3074 return __first;
3075}
3076
3077template <class _CharT, class _Traits>
3078template <class _ForwardIterator>
3079_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003080basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
3081 _ForwardIterator __last)
3082{
Howard Hinnantaa698082010-07-16 19:08:36 +00003083 __owns_one_state<_CharT>* __sa = __end_;
3084 _ForwardIterator __temp = __parse_ERE_branch(__first, __last);
3085 if (__temp == __first)
Marshall Clow2576c292015-07-28 13:30:47 +00003086 __throw_regex_error<regex_constants::__re_err_empty>();
Howard Hinnantaa698082010-07-16 19:08:36 +00003087 __first = __temp;
3088 while (__first != __last && *__first == '|')
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003089 {
Howard Hinnantaa698082010-07-16 19:08:36 +00003090 __owns_one_state<_CharT>* __sb = __end_;
3091 __temp = __parse_ERE_branch(++__first, __last);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003092 if (__temp == __first)
Marshall Clow2576c292015-07-28 13:30:47 +00003093 __throw_regex_error<regex_constants::__re_err_empty>();
Howard Hinnantaa698082010-07-16 19:08:36 +00003094 __push_alternation(__sa, __sb);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003095 __first = __temp;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003096 }
3097 return __first;
3098}
3099
3100template <class _CharT, class _Traits>
3101template <class _ForwardIterator>
3102_ForwardIterator
3103basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
3104 _ForwardIterator __last)
3105{
3106 _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
3107 if (__temp == __first)
Marshall Clow2576c292015-07-28 13:30:47 +00003108 __throw_regex_error<regex_constants::__re_err_empty>();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003109 do
3110 {
3111 __first = __temp;
3112 __temp = __parse_ERE_expression(__first, __last);
3113 } while (__temp != __first);
3114 return __first;
3115}
3116
3117template <class _CharT, class _Traits>
3118template <class _ForwardIterator>
3119_ForwardIterator
3120basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
3121 _ForwardIterator __last)
3122{
Howard Hinnantaa698082010-07-16 19:08:36 +00003123 __owns_one_state<_CharT>* __e = __end_;
3124 unsigned __mexp_begin = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003125 _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
3126 if (__temp == __first && __temp != __last)
3127 {
3128 switch (*__temp)
3129 {
3130 case '^':
3131 __push_l_anchor();
3132 ++__temp;
3133 break;
3134 case '$':
3135 __push_r_anchor();
3136 ++__temp;
3137 break;
3138 case '(':
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003139 __push_begin_marked_subexpression();
3140 unsigned __temp_count = __marked_count_;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003141 ++__open_count_;
3142 __temp = __parse_extended_reg_exp(++__temp, __last);
3143 if (__temp == __last || *__temp != ')')
Marshall Clow2576c292015-07-28 13:30:47 +00003144 __throw_regex_error<regex_constants::error_paren>();
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003145 __push_end_marked_subexpression(__temp_count);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003146 --__open_count_;
3147 ++__temp;
3148 break;
3149 }
3150 }
3151 if (__temp != __first)
Howard Hinnantaa698082010-07-16 19:08:36 +00003152 __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
3153 __marked_count_+1);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003154 __first = __temp;
3155 return __first;
3156}
3157
3158template <class _CharT, class _Traits>
3159template <class _ForwardIterator>
3160_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003161basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
3162 _ForwardIterator __last)
3163{
3164 while (true)
3165 {
3166 _ForwardIterator __temp = __parse_simple_RE(__first, __last);
3167 if (__temp == __first)
3168 break;
3169 __first = __temp;
3170 }
3171 return __first;
3172}
3173
3174template <class _CharT, class _Traits>
3175template <class _ForwardIterator>
3176_ForwardIterator
3177basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
3178 _ForwardIterator __last)
3179{
3180 if (__first != __last)
3181 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003182 __owns_one_state<_CharT>* __e = __end_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003183 unsigned __mexp_begin = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003184 _ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
3185 if (__temp != __first)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003186 __first = __parse_RE_dupl_symbol(__temp, __last, __e,
3187 __mexp_begin+1, __marked_count_+1);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003188 }
3189 return __first;
3190}
3191
3192template <class _CharT, class _Traits>
3193template <class _ForwardIterator>
3194_ForwardIterator
3195basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
3196 _ForwardIterator __last)
3197{
3198 _ForwardIterator __temp = __first;
3199 __first = __parse_one_char_or_coll_elem_RE(__first, __last);
3200 if (__temp == __first)
3201 {
3202 __temp = __parse_Back_open_paren(__first, __last);
3203 if (__temp != __first)
3204 {
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003205 __push_begin_marked_subexpression();
3206 unsigned __temp_count = __marked_count_;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003207 __first = __parse_RE_expression(__temp, __last);
3208 __temp = __parse_Back_close_paren(__first, __last);
3209 if (__temp == __first)
Marshall Clow2576c292015-07-28 13:30:47 +00003210 __throw_regex_error<regex_constants::error_paren>();
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00003211 __push_end_marked_subexpression(__temp_count);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003212 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003213 }
3214 else
3215 __first = __parse_BACKREF(__first, __last);
3216 }
3217 return __first;
3218}
3219
3220template <class _CharT, class _Traits>
3221template <class _ForwardIterator>
3222_ForwardIterator
3223basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
3224 _ForwardIterator __first,
3225 _ForwardIterator __last)
3226{
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003227 _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003228 if (__temp == __first)
3229 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003230 __temp = __parse_QUOTED_CHAR(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003231 if (__temp == __first)
3232 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003233 if (__temp != __last && *__temp == '.')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003234 {
3235 __push_match_any();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003236 ++__temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003237 }
3238 else
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003239 __temp = __parse_bracket_expression(__first, __last);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003240 }
3241 }
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003242 __first = __temp;
3243 return __first;
3244}
3245
3246template <class _CharT, class _Traits>
3247template <class _ForwardIterator>
3248_ForwardIterator
3249basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
3250 _ForwardIterator __first,
3251 _ForwardIterator __last)
3252{
3253 _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
3254 if (__temp == __first)
3255 {
3256 __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
3257 if (__temp == __first)
3258 {
3259 if (__temp != __last && *__temp == '.')
3260 {
3261 __push_match_any();
3262 ++__temp;
3263 }
3264 else
3265 __temp = __parse_bracket_expression(__first, __last);
3266 }
3267 }
3268 __first = __temp;
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003269 return __first;
3270}
3271
3272template <class _CharT, class _Traits>
3273template <class _ForwardIterator>
3274_ForwardIterator
3275basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
3276 _ForwardIterator __last)
3277{
3278 if (__first != __last)
3279 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003280 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003281 if (__temp != __last)
3282 {
3283 if (*__first == '\\' && *__temp == '(')
3284 __first = ++__temp;
3285 }
3286 }
3287 return __first;
3288}
3289
3290template <class _CharT, class _Traits>
3291template <class _ForwardIterator>
3292_ForwardIterator
3293basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
3294 _ForwardIterator __last)
3295{
3296 if (__first != __last)
3297 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003298 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003299 if (__temp != __last)
3300 {
3301 if (*__first == '\\' && *__temp == ')')
3302 __first = ++__temp;
3303 }
3304 }
3305 return __first;
3306}
3307
3308template <class _CharT, class _Traits>
3309template <class _ForwardIterator>
3310_ForwardIterator
3311basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
3312 _ForwardIterator __last)
3313{
3314 if (__first != __last)
3315 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003316 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003317 if (__temp != __last)
3318 {
3319 if (*__first == '\\' && *__temp == '{')
3320 __first = ++__temp;
3321 }
3322 }
3323 return __first;
3324}
3325
3326template <class _CharT, class _Traits>
3327template <class _ForwardIterator>
3328_ForwardIterator
3329basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
3330 _ForwardIterator __last)
3331{
3332 if (__first != __last)
3333 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003334 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003335 if (__temp != __last)
3336 {
3337 if (*__first == '\\' && *__temp == '}')
3338 __first = ++__temp;
3339 }
3340 }
3341 return __first;
3342}
3343
3344template <class _CharT, class _Traits>
3345template <class _ForwardIterator>
3346_ForwardIterator
3347basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
3348 _ForwardIterator __last)
3349{
3350 if (__first != __last)
3351 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003352 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003353 if (__temp != __last)
3354 {
Marshall Clow97f50f62014-01-18 03:40:03 +00003355 if (*__first == '\\')
3356 {
3357 int __val = __traits_.value(*__temp, 10);
3358 if (__val >= 1 && __val <= 9)
3359 {
3360 __push_back_ref(__val);
3361 __first = ++__temp;
3362 }
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003363 }
3364 }
3365 }
3366 return __first;
3367}
3368
3369template <class _CharT, class _Traits>
3370template <class _ForwardIterator>
3371_ForwardIterator
3372basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
3373 _ForwardIterator __last)
3374{
3375 if (__first != __last)
3376 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003377 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003378 if (__temp == __last && *__first == '$')
3379 return __first;
3380 // Not called inside a bracket
3381 if (*__first == '.' || *__first == '\\' || *__first == '[')
3382 return __first;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003383 __push_char(*__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003384 ++__first;
3385 }
3386 return __first;
3387}
3388
3389template <class _CharT, class _Traits>
3390template <class _ForwardIterator>
3391_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003392basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
3393 _ForwardIterator __last)
3394{
3395 if (__first != __last)
3396 {
3397 switch (*__first)
3398 {
3399 case '^':
3400 case '.':
3401 case '[':
3402 case '$':
3403 case '(':
3404 case '|':
3405 case '*':
3406 case '+':
3407 case '?':
3408 case '{':
3409 case '\\':
3410 break;
3411 case ')':
3412 if (__open_count_ == 0)
3413 {
3414 __push_char(*__first);
3415 ++__first;
3416 }
3417 break;
3418 default:
3419 __push_char(*__first);
3420 ++__first;
3421 break;
3422 }
3423 }
3424 return __first;
3425}
3426
3427template <class _CharT, class _Traits>
3428template <class _ForwardIterator>
3429_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003430basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
3431 _ForwardIterator __last)
3432{
3433 if (__first != __last)
3434 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003435 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003436 if (__temp != __last)
3437 {
3438 if (*__first == '\\')
3439 {
3440 switch (*__temp)
3441 {
3442 case '^':
3443 case '.':
3444 case '*':
3445 case '[':
3446 case '$':
3447 case '\\':
Howard Hinnant0de86b62010-06-25 20:56:08 +00003448 __push_char(*__temp);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003449 __first = ++__temp;
3450 break;
3451 }
3452 }
3453 }
3454 }
3455 return __first;
3456}
3457
3458template <class _CharT, class _Traits>
3459template <class _ForwardIterator>
3460_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003461basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
3462 _ForwardIterator __last)
3463{
3464 if (__first != __last)
3465 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003466 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003467 if (__temp != __last)
3468 {
3469 if (*__first == '\\')
3470 {
3471 switch (*__temp)
3472 {
3473 case '^':
3474 case '.':
3475 case '*':
3476 case '[':
3477 case '$':
3478 case '\\':
3479 case '(':
3480 case ')':
3481 case '|':
3482 case '+':
3483 case '?':
3484 case '{':
Howard Hinnantc1ecd972013-06-28 20:31:05 +00003485 case '}':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003486 __push_char(*__temp);
3487 __first = ++__temp;
3488 break;
Howard Hinnant15476f32010-07-28 17:35:27 +00003489 default:
3490 if ((__flags_ & 0x1F0) == awk)
3491 __first = __parse_awk_escape(++__first, __last);
3492 break;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003493 }
3494 }
3495 }
3496 }
3497 return __first;
3498}
3499
3500template <class _CharT, class _Traits>
3501template <class _ForwardIterator>
3502_ForwardIterator
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003503basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantf8ce4592010-07-07 19:14:52 +00003504 _ForwardIterator __last,
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003505 __owns_one_state<_CharT>* __s,
3506 unsigned __mexp_begin,
3507 unsigned __mexp_end)
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003508{
3509 if (__first != __last)
3510 {
Howard Hinnant0de86b62010-06-25 20:56:08 +00003511 if (*__first == '*')
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003512 {
Howard Hinnante77aa5e2010-07-08 17:43:58 +00003513 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003514 ++__first;
3515 }
3516 else
3517 {
3518 _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3519 if (__temp != __first)
3520 {
3521 int __min = 0;
3522 __first = __temp;
3523 __temp = __parse_DUP_COUNT(__first, __last, __min);
3524 if (__temp == __first)
Marshall Clow2576c292015-07-28 13:30:47 +00003525 __throw_regex_error<regex_constants::error_badbrace>();
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003526 __first = __temp;
3527 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00003528 __throw_regex_error<regex_constants::error_brace>();
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003529 if (*__first != ',')
3530 {
3531 __temp = __parse_Back_close_brace(__first, __last);
3532 if (__temp == __first)
Marshall Clow2576c292015-07-28 13:30:47 +00003533 __throw_regex_error<regex_constants::error_brace>();
Howard Hinnantcba352d2010-07-12 18:16:05 +00003534 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
3535 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003536 __first = __temp;
3537 }
3538 else
3539 {
3540 ++__first; // consume ','
3541 int __max = -1;
3542 __first = __parse_DUP_COUNT(__first, __last, __max);
3543 __temp = __parse_Back_close_brace(__first, __last);
3544 if (__temp == __first)
Marshall Clow2576c292015-07-28 13:30:47 +00003545 __throw_regex_error<regex_constants::error_brace>();
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003546 if (__max == -1)
Howard Hinnantaa698082010-07-16 19:08:36 +00003547 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003548 else
3549 {
3550 if (__max < __min)
Marshall Clow2576c292015-07-28 13:30:47 +00003551 __throw_regex_error<regex_constants::error_badbrace>();
Howard Hinnantcba352d2010-07-12 18:16:05 +00003552 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
3553 true);
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00003554 }
3555 __first = __temp;
3556 }
3557 }
3558 }
3559 }
3560 return __first;
3561}
3562
Howard Hinnant0de86b62010-06-25 20:56:08 +00003563template <class _CharT, class _Traits>
3564template <class _ForwardIterator>
3565_ForwardIterator
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003566basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
Howard Hinnantaa698082010-07-16 19:08:36 +00003567 _ForwardIterator __last,
3568 __owns_one_state<_CharT>* __s,
3569 unsigned __mexp_begin,
3570 unsigned __mexp_end)
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003571{
3572 if (__first != __last)
3573 {
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003574 unsigned __grammar = __flags_ & 0x1F0;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003575 switch (*__first)
3576 {
3577 case '*':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003578 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003579 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003580 {
3581 ++__first;
3582 __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3583 }
3584 else
3585 __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003586 break;
3587 case '+':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003588 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003589 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003590 {
3591 ++__first;
3592 __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3593 }
3594 else
3595 __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003596 break;
3597 case '?':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003598 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003599 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003600 {
3601 ++__first;
3602 __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3603 }
3604 else
3605 __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003606 break;
3607 case '{':
3608 {
3609 int __min;
Howard Hinnantaa698082010-07-16 19:08:36 +00003610 _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003611 if (__temp == __first)
Marshall Clow2576c292015-07-28 13:30:47 +00003612 __throw_regex_error<regex_constants::error_badbrace>();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003613 __first = __temp;
3614 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00003615 __throw_regex_error<regex_constants::error_brace>();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003616 switch (*__first)
3617 {
3618 case '}':
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003619 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003620 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003621 {
3622 ++__first;
3623 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3624 }
3625 else
3626 __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003627 break;
3628 case ',':
Howard Hinnantd4444702010-08-11 17:04:31 +00003629 ++__first;
Howard Hinnantd4444702010-08-11 17:04:31 +00003630 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00003631 __throw_regex_error<regex_constants::error_badbrace>();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003632 if (*__first == '}')
3633 {
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003634 ++__first;
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003635 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003636 {
3637 ++__first;
3638 __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3639 }
3640 else
3641 __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003642 }
3643 else
3644 {
Howard Hinnantaa698082010-07-16 19:08:36 +00003645 int __max = -1;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003646 __temp = __parse_DUP_COUNT(__first, __last, __max);
3647 if (__temp == __first)
Marshall Clow2576c292015-07-28 13:30:47 +00003648 __throw_regex_error<regex_constants::error_brace>();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003649 __first = __temp;
3650 if (__first == __last || *__first != '}')
Marshall Clow2576c292015-07-28 13:30:47 +00003651 __throw_regex_error<regex_constants::error_brace>();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003652 ++__first;
3653 if (__max < __min)
Marshall Clow2576c292015-07-28 13:30:47 +00003654 __throw_regex_error<regex_constants::error_badbrace>();
Howard Hinnanta0d045b2010-07-29 00:36:00 +00003655 if (__grammar == ECMAScript && __first != __last && *__first == '?')
Howard Hinnant17615b02010-07-27 01:25:38 +00003656 {
3657 ++__first;
3658 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3659 }
3660 else
3661 __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003662 }
Howard Hinnantaa698082010-07-16 19:08:36 +00003663 break;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003664 default:
Marshall Clow2576c292015-07-28 13:30:47 +00003665 __throw_regex_error<regex_constants::error_badbrace>();
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00003666 }
3667 }
3668 break;
3669 }
3670 }
3671 return __first;
3672}
3673
3674template <class _CharT, class _Traits>
3675template <class _ForwardIterator>
3676_ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00003677basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
3678 _ForwardIterator __last)
3679{
3680 if (__first != __last && *__first == '[')
3681 {
Howard Hinnantd4444702010-08-11 17:04:31 +00003682 ++__first;
Howard Hinnantd4444702010-08-11 17:04:31 +00003683 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00003684 __throw_regex_error<regex_constants::error_brack>();
Howard Hinnant173968a2010-07-13 21:48:06 +00003685 bool __negate = false;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003686 if (*__first == '^')
3687 {
3688 ++__first;
Howard Hinnant173968a2010-07-13 21:48:06 +00003689 __negate = true;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003690 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003691 __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
3692 // __ml owned by *this
Howard Hinnant0de86b62010-06-25 20:56:08 +00003693 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00003694 __throw_regex_error<regex_constants::error_brack>();
Howard Hinnant15476f32010-07-28 17:35:27 +00003695 if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']')
Howard Hinnant0de86b62010-06-25 20:56:08 +00003696 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003697 __ml->__add_char(']');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003698 ++__first;
3699 }
Howard Hinnant173968a2010-07-13 21:48:06 +00003700 __first = __parse_follow_list(__first, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003701 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00003702 __throw_regex_error<regex_constants::error_brack>();
Howard Hinnant0de86b62010-06-25 20:56:08 +00003703 if (*__first == '-')
3704 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003705 __ml->__add_char('-');
Howard Hinnant0de86b62010-06-25 20:56:08 +00003706 ++__first;
3707 }
3708 if (__first == __last || *__first != ']')
Marshall Clow2576c292015-07-28 13:30:47 +00003709 __throw_regex_error<regex_constants::error_brack>();
Howard Hinnant0de86b62010-06-25 20:56:08 +00003710 ++__first;
3711 }
3712 return __first;
3713}
3714
3715template <class _CharT, class _Traits>
3716template <class _ForwardIterator>
3717_ForwardIterator
3718basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003719 _ForwardIterator __last,
3720 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003721{
3722 if (__first != __last)
3723 {
3724 while (true)
3725 {
Howard Hinnant173968a2010-07-13 21:48:06 +00003726 _ForwardIterator __temp = __parse_expression_term(__first, __last,
3727 __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003728 if (__temp == __first)
3729 break;
3730 __first = __temp;
3731 }
3732 }
3733 return __first;
3734}
3735
3736template <class _CharT, class _Traits>
3737template <class _ForwardIterator>
3738_ForwardIterator
3739basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003740 _ForwardIterator __last,
3741 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003742{
3743 if (__first != __last && *__first != ']')
3744 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003745 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant173968a2010-07-13 21:48:06 +00003746 basic_string<_CharT> __start_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003747 if (__temp != __last && *__first == '[')
3748 {
3749 if (*__temp == '=')
Howard Hinnant173968a2010-07-13 21:48:06 +00003750 return __parse_equivalence_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003751 else if (*__temp == ':')
Howard Hinnant173968a2010-07-13 21:48:06 +00003752 return __parse_character_class(++__temp, __last, __ml);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003753 else if (*__temp == '.')
Howard Hinnant173968a2010-07-13 21:48:06 +00003754 __first = __parse_collating_symbol(++__temp, __last, __start_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003755 }
Howard Hinnant15476f32010-07-28 17:35:27 +00003756 unsigned __grammar = __flags_ & 0x1F0;
3757 if (__start_range.empty())
Howard Hinnant0de86b62010-06-25 20:56:08 +00003758 {
Howard Hinnant15476f32010-07-28 17:35:27 +00003759 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3760 {
3761 if (__grammar == ECMAScript)
3762 __first = __parse_class_escape(++__first, __last, __start_range, __ml);
3763 else
3764 __first = __parse_awk_escape(++__first, __last, &__start_range);
3765 }
3766 else
3767 {
3768 __start_range = *__first;
3769 ++__first;
3770 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003771 }
3772 if (__first != __last && *__first != ']')
3773 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00003774 __temp = _VSTD::next(__first);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003775 if (__temp != __last && *__first == '-' && *__temp != ']')
3776 {
3777 // parse a range
Howard Hinnant173968a2010-07-13 21:48:06 +00003778 basic_string<_CharT> __end_range;
Howard Hinnant0de86b62010-06-25 20:56:08 +00003779 __first = __temp;
3780 ++__temp;
3781 if (__temp != __last && *__first == '[' && *__temp == '.')
Howard Hinnant173968a2010-07-13 21:48:06 +00003782 __first = __parse_collating_symbol(++__temp, __last, __end_range);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003783 else
3784 {
Howard Hinnant15476f32010-07-28 17:35:27 +00003785 if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
3786 {
3787 if (__grammar == ECMAScript)
3788 __first = __parse_class_escape(++__first, __last,
3789 __end_range, __ml);
3790 else
3791 __first = __parse_awk_escape(++__first, __last,
3792 &__end_range);
3793 }
3794 else
3795 {
3796 __end_range = *__first;
3797 ++__first;
3798 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00003799 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003800 __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range));
Howard Hinnant0de86b62010-06-25 20:56:08 +00003801 }
Howard Hinnant499cea12013-08-23 17:37:05 +00003802 else if (!__start_range.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003803 {
3804 if (__start_range.size() == 1)
3805 __ml->__add_char(__start_range[0]);
3806 else
3807 __ml->__add_digraph(__start_range[0], __start_range[1]);
3808 }
3809 }
Howard Hinnant499cea12013-08-23 17:37:05 +00003810 else if (!__start_range.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003811 {
3812 if (__start_range.size() == 1)
3813 __ml->__add_char(__start_range[0]);
3814 else
3815 __ml->__add_digraph(__start_range[0], __start_range[1]);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003816 }
3817 }
3818 return __first;
3819}
3820
3821template <class _CharT, class _Traits>
3822template <class _ForwardIterator>
3823_ForwardIterator
Howard Hinnant15476f32010-07-28 17:35:27 +00003824basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
3825 _ForwardIterator __last,
3826 basic_string<_CharT>& __str,
3827 __bracket_expression<_CharT, _Traits>* __ml)
3828{
3829 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00003830 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnant15476f32010-07-28 17:35:27 +00003831 switch (*__first)
3832 {
3833 case 0:
3834 __str = *__first;
3835 return ++__first;
3836 case 'b':
3837 __str = _CharT(8);
3838 return ++__first;
3839 case 'd':
3840 __ml->__add_class(ctype_base::digit);
3841 return ++__first;
3842 case 'D':
3843 __ml->__add_neg_class(ctype_base::digit);
3844 return ++__first;
3845 case 's':
3846 __ml->__add_class(ctype_base::space);
3847 return ++__first;
3848 case 'S':
3849 __ml->__add_neg_class(ctype_base::space);
3850 return ++__first;
3851 case 'w':
3852 __ml->__add_class(ctype_base::alnum);
3853 __ml->__add_char('_');
3854 return ++__first;
3855 case 'W':
3856 __ml->__add_neg_class(ctype_base::alnum);
3857 __ml->__add_neg_char('_');
3858 return ++__first;
3859 }
3860 __first = __parse_character_escape(__first, __last, &__str);
3861 return __first;
3862}
3863
3864template <class _CharT, class _Traits>
3865template <class _ForwardIterator>
3866_ForwardIterator
3867basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
3868 _ForwardIterator __last,
3869 basic_string<_CharT>* __str)
3870{
3871 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00003872 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnant15476f32010-07-28 17:35:27 +00003873 switch (*__first)
3874 {
3875 case '\\':
3876 case '"':
3877 case '/':
3878 if (__str)
3879 *__str = *__first;
3880 else
3881 __push_char(*__first);
3882 return ++__first;
3883 case 'a':
3884 if (__str)
3885 *__str = _CharT(7);
3886 else
3887 __push_char(_CharT(7));
3888 return ++__first;
3889 case 'b':
3890 if (__str)
3891 *__str = _CharT(8);
3892 else
3893 __push_char(_CharT(8));
3894 return ++__first;
3895 case 'f':
3896 if (__str)
3897 *__str = _CharT(0xC);
3898 else
3899 __push_char(_CharT(0xC));
3900 return ++__first;
3901 case 'n':
3902 if (__str)
3903 *__str = _CharT(0xA);
3904 else
3905 __push_char(_CharT(0xA));
3906 return ++__first;
3907 case 'r':
3908 if (__str)
3909 *__str = _CharT(0xD);
3910 else
3911 __push_char(_CharT(0xD));
3912 return ++__first;
3913 case 't':
3914 if (__str)
3915 *__str = _CharT(0x9);
3916 else
3917 __push_char(_CharT(0x9));
3918 return ++__first;
3919 case 'v':
3920 if (__str)
3921 *__str = _CharT(0xB);
3922 else
3923 __push_char(_CharT(0xB));
3924 return ++__first;
3925 }
3926 if ('0' <= *__first && *__first <= '7')
3927 {
3928 unsigned __val = *__first - '0';
3929 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
3930 {
3931 __val = 8 * __val + *__first - '0';
3932 if (++__first != __last && ('0' <= *__first && *__first <= '7'))
Howard Hinnantdbc8cf02013-07-02 17:43:31 +00003933 __val = 8 * __val + *__first++ - '0';
Howard Hinnant15476f32010-07-28 17:35:27 +00003934 }
3935 if (__str)
3936 *__str = _CharT(__val);
3937 else
3938 __push_char(_CharT(__val));
3939 }
3940 else
Marshall Clow2576c292015-07-28 13:30:47 +00003941 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnant15476f32010-07-28 17:35:27 +00003942 return __first;
3943}
3944
3945template <class _CharT, class _Traits>
3946template <class _ForwardIterator>
3947_ForwardIterator
Howard Hinnant0de86b62010-06-25 20:56:08 +00003948basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003949 _ForwardIterator __last,
3950 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003951{
3952 // Found [=
3953 // This means =] must exist
3954 value_type _Equal_close[2] = {'=', ']'};
Howard Hinnant0949eed2011-06-30 21:18:19 +00003955 _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close,
Howard Hinnant0de86b62010-06-25 20:56:08 +00003956 _Equal_close+2);
3957 if (__temp == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00003958 __throw_regex_error<regex_constants::error_brack>();
Howard Hinnant0de86b62010-06-25 20:56:08 +00003959 // [__first, __temp) contains all text in [= ... =]
3960 typedef typename _Traits::string_type string_type;
3961 string_type __collate_name =
3962 __traits_.lookup_collatename(__first, __temp);
3963 if (__collate_name.empty())
Marshall Clow2576c292015-07-28 13:30:47 +00003964 __throw_regex_error<regex_constants::error_collate>();
Howard Hinnant0de86b62010-06-25 20:56:08 +00003965 string_type __equiv_name =
3966 __traits_.transform_primary(__collate_name.begin(),
3967 __collate_name.end());
3968 if (!__equiv_name.empty())
Howard Hinnant173968a2010-07-13 21:48:06 +00003969 __ml->__add_equivalence(__equiv_name);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003970 else
Howard Hinnant173968a2010-07-13 21:48:06 +00003971 {
3972 switch (__collate_name.size())
3973 {
3974 case 1:
3975 __ml->__add_char(__collate_name[0]);
3976 break;
3977 case 2:
3978 __ml->__add_digraph(__collate_name[0], __collate_name[1]);
3979 break;
3980 default:
Marshall Clow2576c292015-07-28 13:30:47 +00003981 __throw_regex_error<regex_constants::error_collate>();
Howard Hinnant173968a2010-07-13 21:48:06 +00003982 }
3983 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00003984 __first = _VSTD::next(__temp, 2);
Howard Hinnant0de86b62010-06-25 20:56:08 +00003985 return __first;
3986}
3987
3988template <class _CharT, class _Traits>
3989template <class _ForwardIterator>
3990_ForwardIterator
3991basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00003992 _ForwardIterator __last,
3993 __bracket_expression<_CharT, _Traits>* __ml)
Howard Hinnant0de86b62010-06-25 20:56:08 +00003994{
3995 // Found [:
3996 // This means :] must exist
3997 value_type _Colon_close[2] = {':', ']'};
Howard Hinnant0949eed2011-06-30 21:18:19 +00003998 _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close,
Howard Hinnant0de86b62010-06-25 20:56:08 +00003999 _Colon_close+2);
4000 if (__temp == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00004001 __throw_regex_error<regex_constants::error_brack>();
Howard Hinnant0de86b62010-06-25 20:56:08 +00004002 // [__first, __temp) contains all text in [: ... :]
4003 typedef typename _Traits::char_class_type char_class_type;
4004 char_class_type __class_type =
4005 __traits_.lookup_classname(__first, __temp, __flags_ & icase);
4006 if (__class_type == 0)
Marshall Clow2576c292015-07-28 13:30:47 +00004007 __throw_regex_error<regex_constants::error_brack>();
Howard Hinnant173968a2010-07-13 21:48:06 +00004008 __ml->__add_class(__class_type);
Howard Hinnant0949eed2011-06-30 21:18:19 +00004009 __first = _VSTD::next(__temp, 2);
Howard Hinnant0de86b62010-06-25 20:56:08 +00004010 return __first;
4011}
4012
4013template <class _CharT, class _Traits>
4014template <class _ForwardIterator>
4015_ForwardIterator
4016basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
Howard Hinnant173968a2010-07-13 21:48:06 +00004017 _ForwardIterator __last,
4018 basic_string<_CharT>& __col_sym)
Howard Hinnant0de86b62010-06-25 20:56:08 +00004019{
4020 // Found [.
4021 // This means .] must exist
4022 value_type _Dot_close[2] = {'.', ']'};
Howard Hinnant0949eed2011-06-30 21:18:19 +00004023 _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close,
Howard Hinnant0de86b62010-06-25 20:56:08 +00004024 _Dot_close+2);
4025 if (__temp == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00004026 __throw_regex_error<regex_constants::error_brack>();
Howard Hinnant0de86b62010-06-25 20:56:08 +00004027 // [__first, __temp) contains all text in [. ... .]
Howard Hinnant173968a2010-07-13 21:48:06 +00004028 __col_sym = __traits_.lookup_collatename(__first, __temp);
4029 switch (__col_sym.size())
4030 {
4031 case 1:
4032 case 2:
4033 break;
4034 default:
Marshall Clow2576c292015-07-28 13:30:47 +00004035 __throw_regex_error<regex_constants::error_collate>();
Howard Hinnant173968a2010-07-13 21:48:06 +00004036 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00004037 __first = _VSTD::next(__temp, 2);
Howard Hinnant0de86b62010-06-25 20:56:08 +00004038 return __first;
4039}
4040
4041template <class _CharT, class _Traits>
4042template <class _ForwardIterator>
4043_ForwardIterator
4044basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
4045 _ForwardIterator __last,
4046 int& __c)
4047{
Marshall Clow97f50f62014-01-18 03:40:03 +00004048 if (__first != __last )
Howard Hinnant0de86b62010-06-25 20:56:08 +00004049 {
Marshall Clow97f50f62014-01-18 03:40:03 +00004050 int __val = __traits_.value(*__first, 10);
4051 if ( __val != -1 )
Howard Hinnant0de86b62010-06-25 20:56:08 +00004052 {
Marshall Clow97f50f62014-01-18 03:40:03 +00004053 __c = __val;
4054 for (++__first;
4055 __first != __last && ( __val = __traits_.value(*__first, 10)) != -1;
4056 ++__first)
4057 {
4058 __c *= 10;
4059 __c += __val;
4060 }
Howard Hinnant0de86b62010-06-25 20:56:08 +00004061 }
4062 }
4063 return __first;
4064}
4065
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004066template <class _CharT, class _Traits>
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004067template <class _ForwardIterator>
4068_ForwardIterator
4069basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
4070 _ForwardIterator __last)
4071{
4072 __owns_one_state<_CharT>* __sa = __end_;
4073 _ForwardIterator __temp = __parse_alternative(__first, __last);
4074 if (__temp == __first)
4075 __push_empty();
4076 __first = __temp;
4077 while (__first != __last && *__first == '|')
4078 {
4079 __owns_one_state<_CharT>* __sb = __end_;
4080 __temp = __parse_alternative(++__first, __last);
4081 if (__temp == __first)
4082 __push_empty();
4083 __push_alternation(__sa, __sb);
4084 __first = __temp;
4085 }
4086 return __first;
4087}
4088
4089template <class _CharT, class _Traits>
4090template <class _ForwardIterator>
4091_ForwardIterator
4092basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
4093 _ForwardIterator __last)
4094{
4095 while (true)
4096 {
4097 _ForwardIterator __temp = __parse_term(__first, __last);
4098 if (__temp == __first)
4099 break;
4100 __first = __temp;
4101 }
4102 return __first;
4103}
4104
4105template <class _CharT, class _Traits>
4106template <class _ForwardIterator>
4107_ForwardIterator
4108basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
4109 _ForwardIterator __last)
4110{
4111 _ForwardIterator __temp = __parse_assertion(__first, __last);
4112 if (__temp == __first)
4113 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004114 __owns_one_state<_CharT>* __e = __end_;
4115 unsigned __mexp_begin = __marked_count_;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004116 __temp = __parse_atom(__first, __last);
4117 if (__temp != __first)
Howard Hinnant17615b02010-07-27 01:25:38 +00004118 __first = __parse_ERE_dupl_symbol(__temp, __last, __e,
4119 __mexp_begin+1, __marked_count_+1);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004120 }
Howard Hinnant17615b02010-07-27 01:25:38 +00004121 else
4122 __first = __temp;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004123 return __first;
4124}
4125
4126template <class _CharT, class _Traits>
4127template <class _ForwardIterator>
4128_ForwardIterator
4129basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
4130 _ForwardIterator __last)
4131{
4132 if (__first != __last)
4133 {
4134 switch (*__first)
4135 {
4136 case '^':
4137 __push_l_anchor();
4138 ++__first;
4139 break;
4140 case '$':
4141 __push_r_anchor();
4142 ++__first;
4143 break;
4144 case '\\':
4145 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00004146 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004147 if (__temp != __last)
4148 {
4149 if (*__temp == 'b')
4150 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004151 __push_word_boundary(false);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004152 __first = ++__temp;
4153 }
4154 else if (*__temp == 'B')
4155 {
Howard Hinnant17615b02010-07-27 01:25:38 +00004156 __push_word_boundary(true);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004157 __first = ++__temp;
4158 }
4159 }
4160 }
4161 break;
4162 case '(':
4163 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00004164 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004165 if (__temp != __last && *__temp == '?')
4166 {
4167 if (++__temp != __last)
4168 {
4169 switch (*__temp)
4170 {
4171 case '=':
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004172 {
4173 basic_regex __exp;
4174 __exp.__flags_ = __flags_;
4175 __temp = __exp.__parse(++__temp, __last);
Howard Hinnantcd59acc2013-07-23 16:18:04 +00004176 unsigned __mexp = __exp.__marked_count_;
4177 __push_lookahead(_VSTD::move(__exp), false, __marked_count_);
4178 __marked_count_ += __mexp;
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004179 if (__temp == __last || *__temp != ')')
Marshall Clow2576c292015-07-28 13:30:47 +00004180 __throw_regex_error<regex_constants::error_paren>();
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004181 __first = ++__temp;
4182 }
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004183 break;
4184 case '!':
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004185 {
4186 basic_regex __exp;
4187 __exp.__flags_ = __flags_;
4188 __temp = __exp.__parse(++__temp, __last);
Howard Hinnantcd59acc2013-07-23 16:18:04 +00004189 unsigned __mexp = __exp.__marked_count_;
4190 __push_lookahead(_VSTD::move(__exp), true, __marked_count_);
4191 __marked_count_ += __mexp;
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004192 if (__temp == __last || *__temp != ')')
Marshall Clow2576c292015-07-28 13:30:47 +00004193 __throw_regex_error<regex_constants::error_paren>();
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004194 __first = ++__temp;
4195 }
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004196 break;
4197 }
4198 }
4199 }
4200 }
4201 break;
4202 }
4203 }
4204 return __first;
4205}
4206
4207template <class _CharT, class _Traits>
4208template <class _ForwardIterator>
4209_ForwardIterator
4210basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
4211 _ForwardIterator __last)
4212{
Howard Hinnant17615b02010-07-27 01:25:38 +00004213 if (__first != __last)
4214 {
4215 switch (*__first)
4216 {
4217 case '.':
4218 __push_match_any_but_newline();
4219 ++__first;
4220 break;
4221 case '\\':
4222 __first = __parse_atom_escape(__first, __last);
4223 break;
4224 case '[':
4225 __first = __parse_bracket_expression(__first, __last);
4226 break;
4227 case '(':
4228 {
Howard Hinnantd4444702010-08-11 17:04:31 +00004229 ++__first;
Howard Hinnantd4444702010-08-11 17:04:31 +00004230 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00004231 __throw_regex_error<regex_constants::error_paren>();
Howard Hinnant0949eed2011-06-30 21:18:19 +00004232 _ForwardIterator __temp = _VSTD::next(__first);
Howard Hinnant17615b02010-07-27 01:25:38 +00004233 if (__temp != __last && *__first == '?' && *__temp == ':')
4234 {
4235 ++__open_count_;
4236 __first = __parse_ecma_exp(++__temp, __last);
4237 if (__first == __last || *__first != ')')
Marshall Clow2576c292015-07-28 13:30:47 +00004238 __throw_regex_error<regex_constants::error_paren>();
Howard Hinnant17615b02010-07-27 01:25:38 +00004239 --__open_count_;
4240 ++__first;
4241 }
4242 else
4243 {
4244 __push_begin_marked_subexpression();
4245 unsigned __temp_count = __marked_count_;
4246 ++__open_count_;
4247 __first = __parse_ecma_exp(__first, __last);
4248 if (__first == __last || *__first != ')')
Marshall Clow2576c292015-07-28 13:30:47 +00004249 __throw_regex_error<regex_constants::error_paren>();
Howard Hinnant17615b02010-07-27 01:25:38 +00004250 __push_end_marked_subexpression(__temp_count);
4251 --__open_count_;
4252 ++__first;
4253 }
4254 }
4255 break;
Marshall Clow568bd022015-07-23 18:27:51 +00004256 case '*':
4257 case '+':
4258 case '?':
4259 case '{':
Marshall Clow2576c292015-07-28 13:30:47 +00004260 __throw_regex_error<regex_constants::error_badrepeat>();
Marshall Clow568bd022015-07-23 18:27:51 +00004261 break;
Howard Hinnant17615b02010-07-27 01:25:38 +00004262 default:
4263 __first = __parse_pattern_character(__first, __last);
4264 break;
4265 }
4266 }
4267 return __first;
4268}
4269
4270template <class _CharT, class _Traits>
4271template <class _ForwardIterator>
4272_ForwardIterator
4273basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
4274 _ForwardIterator __last)
4275{
4276 if (__first != __last && *__first == '\\')
4277 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00004278 _ForwardIterator __t1 = _VSTD::next(__first);
Marshall Clow685cdca2016-01-19 00:50:37 +00004279 if (__t1 == __last)
4280 __throw_regex_error<regex_constants::error_escape>();
4281
Howard Hinnant17615b02010-07-27 01:25:38 +00004282 _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
4283 if (__t2 != __t1)
4284 __first = __t2;
4285 else
4286 {
4287 __t2 = __parse_character_class_escape(__t1, __last);
4288 if (__t2 != __t1)
4289 __first = __t2;
4290 else
4291 {
4292 __t2 = __parse_character_escape(__t1, __last);
4293 if (__t2 != __t1)
4294 __first = __t2;
4295 }
4296 }
4297 }
4298 return __first;
4299}
4300
4301template <class _CharT, class _Traits>
4302template <class _ForwardIterator>
4303_ForwardIterator
4304basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
4305 _ForwardIterator __last)
4306{
4307 if (__first != __last)
4308 {
4309 if (*__first == '0')
4310 {
4311 __push_char(_CharT());
4312 ++__first;
4313 }
4314 else if ('1' <= *__first && *__first <= '9')
4315 {
4316 unsigned __v = *__first - '0';
Marshall Clow99447c82016-12-24 17:21:03 +00004317 for (++__first;
4318 __first != __last && '0' <= *__first && *__first <= '9'; ++__first)
Howard Hinnant17615b02010-07-27 01:25:38 +00004319 __v = 10 * __v + *__first - '0';
4320 if (__v > mark_count())
Marshall Clow2576c292015-07-28 13:30:47 +00004321 __throw_regex_error<regex_constants::error_backref>();
Howard Hinnant17615b02010-07-27 01:25:38 +00004322 __push_back_ref(__v);
4323 }
4324 }
4325 return __first;
4326}
4327
4328template <class _CharT, class _Traits>
4329template <class _ForwardIterator>
4330_ForwardIterator
4331basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
4332 _ForwardIterator __last)
4333{
4334 if (__first != __last)
4335 {
4336 __bracket_expression<_CharT, _Traits>* __ml;
4337 switch (*__first)
4338 {
4339 case 'd':
4340 __ml = __start_matching_list(false);
4341 __ml->__add_class(ctype_base::digit);
4342 ++__first;
4343 break;
4344 case 'D':
4345 __ml = __start_matching_list(true);
4346 __ml->__add_class(ctype_base::digit);
4347 ++__first;
4348 break;
4349 case 's':
4350 __ml = __start_matching_list(false);
4351 __ml->__add_class(ctype_base::space);
4352 ++__first;
4353 break;
4354 case 'S':
4355 __ml = __start_matching_list(true);
4356 __ml->__add_class(ctype_base::space);
4357 ++__first;
4358 break;
4359 case 'w':
4360 __ml = __start_matching_list(false);
4361 __ml->__add_class(ctype_base::alnum);
4362 __ml->__add_char('_');
4363 ++__first;
4364 break;
4365 case 'W':
4366 __ml = __start_matching_list(true);
4367 __ml->__add_class(ctype_base::alnum);
4368 __ml->__add_char('_');
4369 ++__first;
4370 break;
4371 }
4372 }
4373 return __first;
4374}
4375
4376template <class _CharT, class _Traits>
4377template <class _ForwardIterator>
4378_ForwardIterator
4379basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
Howard Hinnant15476f32010-07-28 17:35:27 +00004380 _ForwardIterator __last,
4381 basic_string<_CharT>* __str)
Howard Hinnant17615b02010-07-27 01:25:38 +00004382{
4383 if (__first != __last)
4384 {
4385 _ForwardIterator __t;
4386 unsigned __sum = 0;
4387 int __hd;
4388 switch (*__first)
4389 {
4390 case 'f':
Howard Hinnant15476f32010-07-28 17:35:27 +00004391 if (__str)
4392 *__str = _CharT(0xC);
4393 else
4394 __push_char(_CharT(0xC));
Howard Hinnant17615b02010-07-27 01:25:38 +00004395 ++__first;
4396 break;
4397 case 'n':
Howard Hinnant15476f32010-07-28 17:35:27 +00004398 if (__str)
4399 *__str = _CharT(0xA);
4400 else
4401 __push_char(_CharT(0xA));
Howard Hinnant17615b02010-07-27 01:25:38 +00004402 ++__first;
4403 break;
4404 case 'r':
Howard Hinnant15476f32010-07-28 17:35:27 +00004405 if (__str)
4406 *__str = _CharT(0xD);
4407 else
4408 __push_char(_CharT(0xD));
Howard Hinnant17615b02010-07-27 01:25:38 +00004409 ++__first;
4410 break;
4411 case 't':
Howard Hinnant15476f32010-07-28 17:35:27 +00004412 if (__str)
4413 *__str = _CharT(0x9);
4414 else
4415 __push_char(_CharT(0x9));
Howard Hinnant17615b02010-07-27 01:25:38 +00004416 ++__first;
4417 break;
4418 case 'v':
Howard Hinnant15476f32010-07-28 17:35:27 +00004419 if (__str)
4420 *__str = _CharT(0xB);
4421 else
4422 __push_char(_CharT(0xB));
Howard Hinnant17615b02010-07-27 01:25:38 +00004423 ++__first;
4424 break;
4425 case 'c':
Howard Hinnant0949eed2011-06-30 21:18:19 +00004426 if ((__t = _VSTD::next(__first)) != __last)
Howard Hinnant17615b02010-07-27 01:25:38 +00004427 {
Howard Hinnant1e1d0512013-07-15 18:21:11 +00004428 if (('A' <= *__t && *__t <= 'Z') ||
4429 ('a' <= *__t && *__t <= 'z'))
Howard Hinnant17615b02010-07-27 01:25:38 +00004430 {
Howard Hinnant15476f32010-07-28 17:35:27 +00004431 if (__str)
4432 *__str = _CharT(*__t % 32);
4433 else
4434 __push_char(_CharT(*__t % 32));
Howard Hinnant17615b02010-07-27 01:25:38 +00004435 __first = ++__t;
4436 }
Howard Hinnant1e1d0512013-07-15 18:21:11 +00004437 else
Marshall Clow2576c292015-07-28 13:30:47 +00004438 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnant17615b02010-07-27 01:25:38 +00004439 }
Howard Hinnant1e1d0512013-07-15 18:21:11 +00004440 else
Marshall Clow2576c292015-07-28 13:30:47 +00004441 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnant17615b02010-07-27 01:25:38 +00004442 break;
4443 case 'u':
Howard Hinnantd4444702010-08-11 17:04:31 +00004444 ++__first;
Howard Hinnantd4444702010-08-11 17:04:31 +00004445 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00004446 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnant17615b02010-07-27 01:25:38 +00004447 __hd = __traits_.value(*__first, 16);
4448 if (__hd == -1)
Marshall Clow2576c292015-07-28 13:30:47 +00004449 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnantec3773c2011-12-01 20:21:04 +00004450 __sum = 16 * __sum + static_cast<unsigned>(__hd);
Howard Hinnantd4444702010-08-11 17:04:31 +00004451 ++__first;
Howard Hinnantd4444702010-08-11 17:04:31 +00004452 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00004453 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnant17615b02010-07-27 01:25:38 +00004454 __hd = __traits_.value(*__first, 16);
4455 if (__hd == -1)
Marshall Clow2576c292015-07-28 13:30:47 +00004456 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnantec3773c2011-12-01 20:21:04 +00004457 __sum = 16 * __sum + static_cast<unsigned>(__hd);
Howard Hinnant17615b02010-07-27 01:25:38 +00004458 // drop through
4459 case 'x':
Howard Hinnantd4444702010-08-11 17:04:31 +00004460 ++__first;
Howard Hinnantd4444702010-08-11 17:04:31 +00004461 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00004462 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnant17615b02010-07-27 01:25:38 +00004463 __hd = __traits_.value(*__first, 16);
4464 if (__hd == -1)
Marshall Clow2576c292015-07-28 13:30:47 +00004465 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnantec3773c2011-12-01 20:21:04 +00004466 __sum = 16 * __sum + static_cast<unsigned>(__hd);
Howard Hinnantd4444702010-08-11 17:04:31 +00004467 ++__first;
Howard Hinnantd4444702010-08-11 17:04:31 +00004468 if (__first == __last)
Marshall Clow2576c292015-07-28 13:30:47 +00004469 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnant17615b02010-07-27 01:25:38 +00004470 __hd = __traits_.value(*__first, 16);
4471 if (__hd == -1)
Marshall Clow2576c292015-07-28 13:30:47 +00004472 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnantec3773c2011-12-01 20:21:04 +00004473 __sum = 16 * __sum + static_cast<unsigned>(__hd);
Howard Hinnant15476f32010-07-28 17:35:27 +00004474 if (__str)
4475 *__str = _CharT(__sum);
4476 else
4477 __push_char(_CharT(__sum));
Howard Hinnant17615b02010-07-27 01:25:38 +00004478 ++__first;
4479 break;
Marshall Clow6b7e6922014-05-21 16:29:50 +00004480 case '0':
4481 if (__str)
4482 *__str = _CharT(0);
4483 else
4484 __push_char(_CharT(0));
4485 ++__first;
4486 break;
Howard Hinnant17615b02010-07-27 01:25:38 +00004487 default:
4488 if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
4489 {
Howard Hinnant15476f32010-07-28 17:35:27 +00004490 if (__str)
4491 *__str = *__first;
4492 else
4493 __push_char(*__first);
Howard Hinnant17615b02010-07-27 01:25:38 +00004494 ++__first;
4495 }
Howard Hinnant918f2a82013-06-28 18:57:30 +00004496 else
Marshall Clow2576c292015-07-28 13:30:47 +00004497 __throw_regex_error<regex_constants::error_escape>();
Howard Hinnant17615b02010-07-27 01:25:38 +00004498 break;
4499 }
4500 }
4501 return __first;
4502}
4503
4504template <class _CharT, class _Traits>
4505template <class _ForwardIterator>
4506_ForwardIterator
4507basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
4508 _ForwardIterator __last)
4509{
4510 if (__first != __last)
4511 {
4512 switch (*__first)
4513 {
4514 case '^':
4515 case '$':
4516 case '\\':
4517 case '.':
4518 case '*':
4519 case '+':
4520 case '?':
4521 case '(':
4522 case ')':
4523 case '[':
4524 case ']':
4525 case '{':
4526 case '}':
4527 case '|':
4528 break;
4529 default:
4530 __push_char(*__first);
4531 ++__first;
4532 break;
4533 }
4534 }
4535 return __first;
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004536}
4537
4538template <class _CharT, class _Traits>
Howard Hinnant856846b2010-07-27 19:53:10 +00004539template <class _ForwardIterator>
4540_ForwardIterator
4541basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
4542 _ForwardIterator __last)
4543{
4544 __owns_one_state<_CharT>* __sa = __end_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00004545 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
Howard Hinnant856846b2010-07-27 19:53:10 +00004546 if (__t1 != __first)
4547 __parse_basic_reg_exp(__first, __t1);
4548 else
4549 __push_empty();
4550 __first = __t1;
4551 if (__first != __last)
4552 ++__first;
4553 while (__first != __last)
4554 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00004555 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
Howard Hinnant856846b2010-07-27 19:53:10 +00004556 __owns_one_state<_CharT>* __sb = __end_;
4557 if (__t1 != __first)
4558 __parse_basic_reg_exp(__first, __t1);
4559 else
4560 __push_empty();
4561 __push_alternation(__sa, __sb);
4562 __first = __t1;
4563 if (__first != __last)
4564 ++__first;
4565 }
4566 return __first;
4567}
4568
4569template <class _CharT, class _Traits>
4570template <class _ForwardIterator>
4571_ForwardIterator
4572basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
4573 _ForwardIterator __last)
4574{
4575 __owns_one_state<_CharT>* __sa = __end_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00004576 _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
Howard Hinnant856846b2010-07-27 19:53:10 +00004577 if (__t1 != __first)
4578 __parse_extended_reg_exp(__first, __t1);
4579 else
4580 __push_empty();
4581 __first = __t1;
4582 if (__first != __last)
4583 ++__first;
4584 while (__first != __last)
4585 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00004586 __t1 = _VSTD::find(__first, __last, _CharT('\n'));
Howard Hinnant856846b2010-07-27 19:53:10 +00004587 __owns_one_state<_CharT>* __sb = __end_;
4588 if (__t1 != __first)
4589 __parse_extended_reg_exp(__first, __t1);
4590 else
4591 __push_empty();
4592 __push_alternation(__sa, __sb);
4593 __first = __t1;
4594 if (__first != __last)
4595 ++__first;
4596 }
4597 return __first;
4598}
4599
4600template <class _CharT, class _Traits>
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004601void
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004602basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
4603 __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
4604 bool __greedy)
4605{
4606 unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
4607 __end_->first() = nullptr;
Howard Hinnantac303862010-07-12 15:51:17 +00004608 unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
4609 __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
4610 __min, __max));
4611 __s->first() = nullptr;
4612 __e1.release();
4613 __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004614 __end_ = __e2->second();
Howard Hinnantac303862010-07-12 15:51:17 +00004615 __s->first() = __e2.release();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00004616 ++__loop_count_;
4617}
4618
4619template <class _CharT, class _Traits>
4620void
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004621basic_regex<_CharT, _Traits>::__push_char(value_type __c)
4622{
Howard Hinnant173968a2010-07-13 21:48:06 +00004623 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004624 __end_->first() = new __match_char_icase<_CharT, _Traits>
4625 (__traits_, __c, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004626 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004627 __end_->first() = new __match_char_collate<_CharT, _Traits>
4628 (__traits_, __c, __end_->first());
4629 else
4630 __end_->first() = new __match_char<_CharT>(__c, __end_->first());
Howard Hinnante77aa5e2010-07-08 17:43:58 +00004631 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004632}
4633
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004634template <class _CharT, class _Traits>
4635void
4636basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
4637{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004638 if (!(__flags_ & nosubs))
4639 {
4640 __end_->first() =
4641 new __begin_marked_subexpression<_CharT>(++__marked_count_,
4642 __end_->first());
4643 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4644 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004645}
4646
4647template <class _CharT, class _Traits>
4648void
4649basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
4650{
Howard Hinnant68025ed2010-07-14 15:45:11 +00004651 if (!(__flags_ & nosubs))
4652 {
4653 __end_->first() =
4654 new __end_marked_subexpression<_CharT>(__sub, __end_->first());
4655 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4656 }
Howard Hinnant0dca5fc2010-06-30 20:30:19 +00004657}
4658
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004659template <class _CharT, class _Traits>
4660void
Howard Hinnant41fb6e12011-03-26 20:02:27 +00004661basic_regex<_CharT, _Traits>::__push_l_anchor()
4662{
4663 __end_->first() = new __l_anchor<_CharT>(__end_->first());
4664 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4665}
4666
4667template <class _CharT, class _Traits>
4668void
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004669basic_regex<_CharT, _Traits>::__push_r_anchor()
4670{
4671 __end_->first() = new __r_anchor<_CharT>(__end_->first());
4672 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4673}
4674
Howard Hinnantac303862010-07-12 15:51:17 +00004675template <class _CharT, class _Traits>
4676void
4677basic_regex<_CharT, _Traits>::__push_match_any()
4678{
4679 __end_->first() = new __match_any<_CharT>(__end_->first());
4680 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4681}
Howard Hinnant37f9f9c2010-07-09 00:15:26 +00004682
Howard Hinnantcba352d2010-07-12 18:16:05 +00004683template <class _CharT, class _Traits>
4684void
Howard Hinnant17615b02010-07-27 01:25:38 +00004685basic_regex<_CharT, _Traits>::__push_match_any_but_newline()
4686{
4687 __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
4688 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4689}
4690
4691template <class _CharT, class _Traits>
4692void
Howard Hinnant2ade7c22010-07-22 17:53:24 +00004693basic_regex<_CharT, _Traits>::__push_empty()
4694{
4695 __end_->first() = new __empty_state<_CharT>(__end_->first());
4696 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4697}
4698
4699template <class _CharT, class _Traits>
4700void
Howard Hinnant17615b02010-07-27 01:25:38 +00004701basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
4702{
4703 __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
4704 __end_->first());
4705 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4706}
4707
4708template <class _CharT, class _Traits>
4709void
Howard Hinnantcba352d2010-07-12 18:16:05 +00004710basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
4711{
Howard Hinnant173968a2010-07-13 21:48:06 +00004712 if (flags() & icase)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004713 __end_->first() = new __back_ref_icase<_CharT, _Traits>
4714 (__traits_, __i, __end_->first());
Howard Hinnant173968a2010-07-13 21:48:06 +00004715 else if (flags() & collate)
Howard Hinnante34f17d2010-07-12 19:11:27 +00004716 __end_->first() = new __back_ref_collate<_CharT, _Traits>
4717 (__traits_, __i, __end_->first());
4718 else
4719 __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
Howard Hinnantcba352d2010-07-12 18:16:05 +00004720 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4721}
4722
Howard Hinnant173968a2010-07-13 21:48:06 +00004723template <class _CharT, class _Traits>
Howard Hinnantaa698082010-07-16 19:08:36 +00004724void
4725basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
4726 __owns_one_state<_CharT>* __ea)
4727{
4728 __sa->first() = new __alternate<_CharT>(
4729 static_cast<__owns_one_state<_CharT>*>(__sa->first()),
4730 static_cast<__owns_one_state<_CharT>*>(__ea->first()));
4731 __ea->first() = nullptr;
4732 __ea->first() = new __empty_state<_CharT>(__end_->first());
4733 __end_->first() = nullptr;
4734 __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
4735 __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
4736}
4737
4738template <class _CharT, class _Traits>
Howard Hinnant173968a2010-07-13 21:48:06 +00004739__bracket_expression<_CharT, _Traits>*
4740basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
4741{
4742 __bracket_expression<_CharT, _Traits>* __r =
4743 new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
4744 __negate, __flags_ & icase,
4745 __flags_ & collate);
4746 __end_->first() = __r;
4747 __end_ = __r;
4748 return __r;
4749}
4750
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004751template <class _CharT, class _Traits>
4752void
4753basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
Howard Hinnantcd59acc2013-07-23 16:18:04 +00004754 bool __invert,
4755 unsigned __mexp)
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004756{
4757 __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
Howard Hinnantcd59acc2013-07-23 16:18:04 +00004758 __end_->first(), __mexp);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00004759 __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
4760}
4761
Howard Hinnant8c2c18d2010-06-24 21:28:00 +00004762typedef basic_regex<char> regex;
4763typedef basic_regex<wchar_t> wregex;
4764
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004765// sub_match
4766
4767template <class _BidirectionalIterator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00004768class _LIBCPP_TYPE_VIS_ONLY sub_match
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004769 : public pair<_BidirectionalIterator, _BidirectionalIterator>
4770{
4771public:
4772 typedef _BidirectionalIterator iterator;
4773 typedef typename iterator_traits<iterator>::value_type value_type;
4774 typedef typename iterator_traits<iterator>::difference_type difference_type;
4775 typedef basic_string<value_type> string_type;
4776
4777 bool matched;
4778
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004779 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant46623a02012-07-21 01:31:58 +00004780 _LIBCPP_CONSTEXPR sub_match() : matched() {}
Howard Hinnant31aaf552010-12-08 21:07:55 +00004781
4782 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004783 difference_type length() const
Howard Hinnant0949eed2011-06-30 21:18:19 +00004784 {return matched ? _VSTD::distance(this->first, this->second) : 0;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004785 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004786 string_type str() const
4787 {return matched ? string_type(this->first, this->second) : string_type();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004789 operator string_type() const
4790 {return str();}
4791
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004792 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004793 int compare(const sub_match& __s) const
4794 {return str().compare(__s.str());}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004795 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004796 int compare(const string_type& __s) const
4797 {return str().compare(__s);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00004798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004799 int compare(const value_type* __s) const
4800 {return str().compare(__s);}
4801};
4802
4803typedef sub_match<const char*> csub_match;
4804typedef sub_match<const wchar_t*> wcsub_match;
4805typedef sub_match<string::const_iterator> ssub_match;
4806typedef sub_match<wstring::const_iterator> wssub_match;
4807
4808template <class _BiIter>
4809inline _LIBCPP_INLINE_VISIBILITY
4810bool
4811operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4812{
4813 return __x.compare(__y) == 0;
4814}
4815
4816template <class _BiIter>
4817inline _LIBCPP_INLINE_VISIBILITY
4818bool
4819operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4820{
4821 return !(__x == __y);
4822}
4823
4824template <class _BiIter>
4825inline _LIBCPP_INLINE_VISIBILITY
4826bool
4827operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4828{
4829 return __x.compare(__y) < 0;
4830}
4831
4832template <class _BiIter>
4833inline _LIBCPP_INLINE_VISIBILITY
4834bool
4835operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4836{
4837 return !(__y < __x);
4838}
4839
4840template <class _BiIter>
4841inline _LIBCPP_INLINE_VISIBILITY
4842bool
4843operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4844{
4845 return !(__x < __y);
4846}
4847
4848template <class _BiIter>
4849inline _LIBCPP_INLINE_VISIBILITY
4850bool
4851operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
4852{
4853 return __y < __x;
4854}
4855
4856template <class _BiIter, class _ST, class _SA>
4857inline _LIBCPP_INLINE_VISIBILITY
4858bool
4859operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4860 const sub_match<_BiIter>& __y)
4861{
Marshall Clowe3e70542014-12-15 23:57:56 +00004862 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004863}
4864
4865template <class _BiIter, class _ST, class _SA>
4866inline _LIBCPP_INLINE_VISIBILITY
4867bool
4868operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4869 const sub_match<_BiIter>& __y)
4870{
4871 return !(__x == __y);
4872}
4873
4874template <class _BiIter, class _ST, class _SA>
4875inline _LIBCPP_INLINE_VISIBILITY
4876bool
4877operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4878 const sub_match<_BiIter>& __y)
4879{
Marshall Clowe3e70542014-12-15 23:57:56 +00004880 return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004881}
4882
4883template <class _BiIter, class _ST, class _SA>
4884inline _LIBCPP_INLINE_VISIBILITY
4885bool
4886operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4887 const sub_match<_BiIter>& __y)
4888{
4889 return __y < __x;
4890}
4891
4892template <class _BiIter, class _ST, class _SA>
4893inline _LIBCPP_INLINE_VISIBILITY
4894bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4895 const sub_match<_BiIter>& __y)
4896{
4897 return !(__x < __y);
4898}
4899
4900template <class _BiIter, class _ST, class _SA>
4901inline _LIBCPP_INLINE_VISIBILITY
4902bool
4903operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4904 const sub_match<_BiIter>& __y)
4905{
4906 return !(__y < __x);
4907}
4908
4909template <class _BiIter, class _ST, class _SA>
4910inline _LIBCPP_INLINE_VISIBILITY
4911bool
4912operator==(const sub_match<_BiIter>& __x,
4913 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4914{
Marshall Clowe3e70542014-12-15 23:57:56 +00004915 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004916}
4917
4918template <class _BiIter, class _ST, class _SA>
4919inline _LIBCPP_INLINE_VISIBILITY
4920bool
4921operator!=(const sub_match<_BiIter>& __x,
4922 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4923{
4924 return !(__x == __y);
4925}
4926
4927template <class _BiIter, class _ST, class _SA>
4928inline _LIBCPP_INLINE_VISIBILITY
4929bool
4930operator<(const sub_match<_BiIter>& __x,
4931 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4932{
Marshall Clowe3e70542014-12-15 23:57:56 +00004933 return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
Howard Hinnantcd85b9e2010-06-29 18:37:43 +00004934}
4935
4936template <class _BiIter, class _ST, class _SA>
4937inline _LIBCPP_INLINE_VISIBILITY
4938bool operator>(const sub_match<_BiIter>& __x,
4939 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4940{
4941 return __y < __x;
4942}
4943
4944template <class _BiIter, class _ST, class _SA>
4945inline _LIBCPP_INLINE_VISIBILITY
4946bool
4947operator>=(const sub_match<_BiIter>& __x,
4948 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4949{
4950 return !(__x < __y);
4951}
4952
4953template <class _BiIter, class _ST, class _SA>
4954inline _LIBCPP_INLINE_VISIBILITY
4955bool
4956operator<=(const sub_match<_BiIter>& __x,
4957 const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
4958{
4959 return !(__y < __x);
4960}
4961
4962template <class _BiIter>
4963inline _LIBCPP_INLINE_VISIBILITY
4964bool
4965operator==(typename iterator_traits<_BiIter>::value_type const* __x,
4966 const sub_match<_BiIter>& __y)
4967{
4968 return __y.compare(__x) == 0;
4969}
4970
4971template <class _BiIter>
4972inline _LIBCPP_INLINE_VISIBILITY
4973bool
4974operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
4975 const sub_match<_BiIter>& __y)
4976{
4977 return !(__x == __y);
4978}
4979
4980template <class _BiIter>
4981inline _LIBCPP_INLINE_VISIBILITY
4982bool
4983operator<(typename iterator_traits<_BiIter>::value_type const* __x,
4984 const sub_match<_BiIter>& __y)
4985{
4986 return __y.compare(__x) > 0;
4987}
4988
4989template <class _BiIter>
4990inline _LIBCPP_INLINE_VISIBILITY
4991bool
4992operator>(typename iterator_traits<_BiIter>::value_type const* __x,
4993 const sub_match<_BiIter>& __y)
4994{
4995 return __y < __x;
4996}
4997
4998template <class _BiIter>
4999inline _LIBCPP_INLINE_VISIBILITY
5000bool
5001operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
5002 const sub_match<_BiIter>& __y)
5003{
5004 return !(__x < __y);
5005}
5006
5007template <class _BiIter>
5008inline _LIBCPP_INLINE_VISIBILITY
5009bool
5010operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
5011 const sub_match<_BiIter>& __y)
5012{
5013 return !(__y < __x);
5014}
5015
5016template <class _BiIter>
5017inline _LIBCPP_INLINE_VISIBILITY
5018bool
5019operator==(const sub_match<_BiIter>& __x,
5020 typename iterator_traits<_BiIter>::value_type const* __y)
5021{
5022 return __x.compare(__y) == 0;
5023}
5024
5025template <class _BiIter>
5026inline _LIBCPP_INLINE_VISIBILITY
5027bool
5028operator!=(const sub_match<_BiIter>& __x,
5029 typename iterator_traits<_BiIter>::value_type const* __y)
5030{
5031 return !(__x == __y);
5032}
5033
5034template <class _BiIter>
5035inline _LIBCPP_INLINE_VISIBILITY
5036bool
5037operator<(const sub_match<_BiIter>& __x,
5038 typename iterator_traits<_BiIter>::value_type const* __y)
5039{
5040 return __x.compare(__y) < 0;
5041}
5042
5043template <class _BiIter>
5044inline _LIBCPP_INLINE_VISIBILITY
5045bool
5046operator>(const sub_match<_BiIter>& __x,
5047 typename iterator_traits<_BiIter>::value_type const* __y)
5048{
5049 return __y < __x;
5050}
5051
5052template <class _BiIter>
5053inline _LIBCPP_INLINE_VISIBILITY
5054bool
5055operator>=(const sub_match<_BiIter>& __x,
5056 typename iterator_traits<_BiIter>::value_type const* __y)
5057{
5058 return !(__x < __y);
5059}
5060
5061template <class _BiIter>
5062inline _LIBCPP_INLINE_VISIBILITY
5063bool
5064operator<=(const sub_match<_BiIter>& __x,
5065 typename iterator_traits<_BiIter>::value_type const* __y)
5066{
5067 return !(__y < __x);
5068}
5069
5070template <class _BiIter>
5071inline _LIBCPP_INLINE_VISIBILITY
5072bool
5073operator==(typename iterator_traits<_BiIter>::value_type const& __x,
5074 const sub_match<_BiIter>& __y)
5075{
5076 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5077 return __y.compare(string_type(1, __x)) == 0;
5078}
5079
5080template <class _BiIter>
5081inline _LIBCPP_INLINE_VISIBILITY
5082bool
5083operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
5084 const sub_match<_BiIter>& __y)
5085{
5086 return !(__x == __y);
5087}
5088
5089template <class _BiIter>
5090inline _LIBCPP_INLINE_VISIBILITY
5091bool
5092operator<(typename iterator_traits<_BiIter>::value_type const& __x,
5093 const sub_match<_BiIter>& __y)
5094{
5095 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5096 return __y.compare(string_type(1, __x)) > 0;
5097}
5098
5099template <class _BiIter>
5100inline _LIBCPP_INLINE_VISIBILITY
5101bool
5102operator>(typename iterator_traits<_BiIter>::value_type const& __x,
5103 const sub_match<_BiIter>& __y)
5104{
5105 return __y < __x;
5106}
5107
5108template <class _BiIter>
5109inline _LIBCPP_INLINE_VISIBILITY
5110bool
5111operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
5112 const sub_match<_BiIter>& __y)
5113{
5114 return !(__x < __y);
5115}
5116
5117template <class _BiIter>
5118inline _LIBCPP_INLINE_VISIBILITY
5119bool
5120operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
5121 const sub_match<_BiIter>& __y)
5122{
5123 return !(__y < __x);
5124}
5125
5126template <class _BiIter>
5127inline _LIBCPP_INLINE_VISIBILITY
5128bool
5129operator==(const sub_match<_BiIter>& __x,
5130 typename iterator_traits<_BiIter>::value_type const& __y)
5131{
5132 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5133 return __x.compare(string_type(1, __y)) == 0;
5134}
5135
5136template <class _BiIter>
5137inline _LIBCPP_INLINE_VISIBILITY
5138bool
5139operator!=(const sub_match<_BiIter>& __x,
5140 typename iterator_traits<_BiIter>::value_type const& __y)
5141{
5142 return !(__x == __y);
5143}
5144
5145template <class _BiIter>
5146inline _LIBCPP_INLINE_VISIBILITY
5147bool
5148operator<(const sub_match<_BiIter>& __x,
5149 typename iterator_traits<_BiIter>::value_type const& __y)
5150{
5151 typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
5152 return __x.compare(string_type(1, __y)) < 0;
5153}
5154
5155template <class _BiIter>
5156inline _LIBCPP_INLINE_VISIBILITY
5157bool
5158operator>(const sub_match<_BiIter>& __x,
5159 typename iterator_traits<_BiIter>::value_type const& __y)
5160{
5161 return __y < __x;
5162}
5163
5164template <class _BiIter>
5165inline _LIBCPP_INLINE_VISIBILITY
5166bool
5167operator>=(const sub_match<_BiIter>& __x,
5168 typename iterator_traits<_BiIter>::value_type const& __y)
5169{
5170 return !(__x < __y);
5171}
5172
5173template <class _BiIter>
5174inline _LIBCPP_INLINE_VISIBILITY
5175bool
5176operator<=(const sub_match<_BiIter>& __x,
5177 typename iterator_traits<_BiIter>::value_type const& __y)
5178{
5179 return !(__y < __x);
5180}
5181
5182template <class _CharT, class _ST, class _BiIter>
5183inline _LIBCPP_INLINE_VISIBILITY
5184basic_ostream<_CharT, _ST>&
5185operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
5186{
5187 return __os << __m.str();
5188}
5189
Howard Hinnant17615b02010-07-27 01:25:38 +00005190template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00005191class _LIBCPP_TYPE_VIS_ONLY match_results
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005192{
5193public:
5194 typedef _Allocator allocator_type;
5195 typedef sub_match<_BidirectionalIterator> value_type;
5196private:
5197 typedef vector<value_type, allocator_type> __container_type;
5198
5199 __container_type __matches_;
5200 value_type __unmatched_;
5201 value_type __prefix_;
5202 value_type __suffix_;
Howard Hinnant31aaf552010-12-08 21:07:55 +00005203 bool __ready_;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005204public:
Howard Hinnanta712c722010-08-16 20:21:16 +00005205 _BidirectionalIterator __position_start_;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005206 typedef const value_type& const_reference;
Marshall Clow103af342014-02-26 01:56:31 +00005207 typedef value_type& reference;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005208 typedef typename __container_type::const_iterator const_iterator;
5209 typedef const_iterator iterator;
5210 typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
5211 typedef typename allocator_traits<allocator_type>::size_type size_type;
5212 typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
5213 typedef basic_string<char_type> string_type;
5214
5215 // construct/copy/destroy:
5216 explicit match_results(const allocator_type& __a = allocator_type());
5217// match_results(const match_results&) = default;
5218// match_results& operator=(const match_results&) = default;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005219// match_results(match_results&& __m) = default;
5220// match_results& operator=(match_results&& __m) = default;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005221// ~match_results() = default;
5222
Howard Hinnant31aaf552010-12-08 21:07:55 +00005223 _LIBCPP_INLINE_VISIBILITY
5224 bool ready() const {return __ready_;}
5225
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005226 // size:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005227 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005228 size_type size() const {return __matches_.size();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005230 size_type max_size() const {return __matches_.max_size();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005231 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005232 bool empty() const {return size() == 0;}
5233
5234 // element access:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005236 difference_type length(size_type __sub = 0) const
5237 {return (*this)[__sub].length();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005239 difference_type position(size_type __sub = 0) const
Howard Hinnant0949eed2011-06-30 21:18:19 +00005240 {return _VSTD::distance(__position_start_, (*this)[__sub].first);}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005242 string_type str(size_type __sub = 0) const
5243 {return (*this)[__sub].str();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005245 const_reference operator[](size_type __n) const
5246 {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
5247
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005249 const_reference prefix() const {return __prefix_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005251 const_reference suffix() const {return __suffix_;}
5252
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc6fe8ca2011-10-08 14:36:16 +00005254 const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005256 const_iterator end() const {return __matches_.end();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005257 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc6fe8ca2011-10-08 14:36:16 +00005258 const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005260 const_iterator cend() const {return __matches_.end();}
5261
5262 // format:
5263 template <class _OutputIter>
5264 _OutputIter
5265 format(_OutputIter __out, const char_type* __fmt_first,
5266 const char_type* __fmt_last,
5267 regex_constants::match_flag_type __flags = regex_constants::format_default) const;
5268 template <class _OutputIter, class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005269 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005270 _OutputIter
5271 format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005272 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5273 {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005274 template <class _ST, class _SA>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005275 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005276 basic_string<char_type, _ST, _SA>
5277 format(const basic_string<char_type, _ST, _SA>& __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005278 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5279 {
5280 basic_string<char_type, _ST, _SA> __r;
5281 format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
5282 __flags);
5283 return __r;
5284 }
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005286 string_type
5287 format(const char_type* __fmt,
Howard Hinnant27405f92010-08-14 18:14:02 +00005288 regex_constants::match_flag_type __flags = regex_constants::format_default) const
5289 {
5290 string_type __r;
5291 format(back_inserter(__r), __fmt,
5292 __fmt + char_traits<char_type>::length(__fmt), __flags);
5293 return __r;
5294 }
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005295
5296 // allocator:
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005297 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005298 allocator_type get_allocator() const {return __matches_.get_allocator();}
5299
5300 // swap:
5301 void swap(match_results& __m);
5302
Howard Hinnant99968442011-11-29 18:15:50 +00005303 template <class _Bp, class _Ap>
Howard Hinnantaef07cb2010-09-23 15:13:20 +00005304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005305 void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
Howard Hinnant99968442011-11-29 18:15:50 +00005306 const match_results<_Bp, _Ap>& __m, bool __no_update_pos)
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005307 {
Howard Hinnant99968442011-11-29 18:15:50 +00005308 _Bp __mf = __m.prefix().first;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005309 __matches_.resize(__m.size());
5310 for (size_type __i = 0; __i < __matches_.size(); ++__i)
5311 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00005312 __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first));
5313 __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second));
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005314 __matches_[__i].matched = __m[__i].matched;
5315 }
5316 __unmatched_.first = __l;
5317 __unmatched_.second = __l;
5318 __unmatched_.matched = false;
Howard Hinnant0949eed2011-06-30 21:18:19 +00005319 __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first));
5320 __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second));
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005321 __prefix_.matched = __m.prefix().matched;
Howard Hinnant0949eed2011-06-30 21:18:19 +00005322 __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first));
5323 __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second));
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005324 __suffix_.matched = __m.suffix().matched;
Howard Hinnanta712c722010-08-16 20:21:16 +00005325 if (!__no_update_pos)
5326 __position_start_ = __prefix_.first;
Howard Hinnant31aaf552010-12-08 21:07:55 +00005327 __ready_ = __m.ready();
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005328 }
5329
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005330private:
5331 void __init(unsigned __s,
Howard Hinnanta712c722010-08-16 20:21:16 +00005332 _BidirectionalIterator __f, _BidirectionalIterator __l,
5333 bool __no_update_pos = false);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005334
5335 template <class, class> friend class basic_regex;
5336
Howard Hinnant99968442011-11-29 18:15:50 +00005337 template <class _Bp, class _Ap, class _Cp, class _Tp>
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005338 friend
5339 bool
Howard Hinnant99968442011-11-29 18:15:50 +00005340 regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005341 regex_constants::match_flag_type);
Howard Hinnante9de5ff2010-07-27 22:20:32 +00005342
Howard Hinnant99968442011-11-29 18:15:50 +00005343 template <class _Bp, class _Ap>
Howard Hinnant27405f92010-08-14 18:14:02 +00005344 friend
5345 bool
Howard Hinnant99968442011-11-29 18:15:50 +00005346 operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
Howard Hinnant27405f92010-08-14 18:14:02 +00005347
Howard Hinnante9de5ff2010-07-27 22:20:32 +00005348 template <class, class> friend class __lookahead;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005349};
5350
5351template <class _BidirectionalIterator, class _Allocator>
5352match_results<_BidirectionalIterator, _Allocator>::match_results(
5353 const allocator_type& __a)
5354 : __matches_(__a),
5355 __unmatched_(),
5356 __prefix_(),
Howard Hinnanta712c722010-08-16 20:21:16 +00005357 __suffix_(),
Eric Fiselier7cc71062015-07-22 01:29:41 +00005358 __ready_(false),
5359 __position_start_()
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005360{
5361}
5362
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005363template <class _BidirectionalIterator, class _Allocator>
5364void
5365match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
Howard Hinnanta712c722010-08-16 20:21:16 +00005366 _BidirectionalIterator __f, _BidirectionalIterator __l,
5367 bool __no_update_pos)
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005368{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005369 __unmatched_.first = __l;
5370 __unmatched_.second = __l;
5371 __unmatched_.matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005372 __matches_.assign(__s, __unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005373 __prefix_.first = __f;
5374 __prefix_.second = __f;
5375 __prefix_.matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005376 __suffix_ = __unmatched_;
Howard Hinnanta712c722010-08-16 20:21:16 +00005377 if (!__no_update_pos)
5378 __position_start_ = __prefix_.first;
Howard Hinnant31aaf552010-12-08 21:07:55 +00005379 __ready_ = true;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005380}
5381
Howard Hinnant27405f92010-08-14 18:14:02 +00005382template <class _BidirectionalIterator, class _Allocator>
5383template <class _OutputIter>
5384_OutputIter
5385match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out,
5386 const char_type* __fmt_first, const char_type* __fmt_last,
5387 regex_constants::match_flag_type __flags) const
5388{
5389 if (__flags & regex_constants::format_sed)
5390 {
5391 for (; __fmt_first != __fmt_last; ++__fmt_first)
5392 {
5393 if (*__fmt_first == '&')
Howard Hinnant0949eed2011-06-30 21:18:19 +00005394 __out = _VSTD::copy(__matches_[0].first, __matches_[0].second,
Howard Hinnant27405f92010-08-14 18:14:02 +00005395 __out);
5396 else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
5397 {
5398 ++__fmt_first;
5399 if ('0' <= *__fmt_first && *__fmt_first <= '9')
5400 {
5401 size_t __i = *__fmt_first - '0';
Duncan P. N. Exon Smithe784f572016-02-03 19:30:20 +00005402 __out = _VSTD::copy((*this)[__i].first,
5403 (*this)[__i].second, __out);
Howard Hinnant27405f92010-08-14 18:14:02 +00005404 }
5405 else
5406 {
5407 *__out = *__fmt_first;
5408 ++__out;
5409 }
5410 }
5411 else
5412 {
5413 *__out = *__fmt_first;
5414 ++__out;
5415 }
5416 }
5417 }
5418 else
5419 {
5420 for (; __fmt_first != __fmt_last; ++__fmt_first)
5421 {
5422 if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
5423 {
5424 switch (__fmt_first[1])
5425 {
5426 case '$':
5427 *__out = *++__fmt_first;
5428 ++__out;
5429 break;
5430 case '&':
5431 ++__fmt_first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00005432 __out = _VSTD::copy(__matches_[0].first, __matches_[0].second,
Howard Hinnant27405f92010-08-14 18:14:02 +00005433 __out);
5434 break;
5435 case '`':
5436 ++__fmt_first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00005437 __out = _VSTD::copy(__prefix_.first, __prefix_.second, __out);
Howard Hinnant27405f92010-08-14 18:14:02 +00005438 break;
5439 case '\'':
5440 ++__fmt_first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00005441 __out = _VSTD::copy(__suffix_.first, __suffix_.second, __out);
Howard Hinnant27405f92010-08-14 18:14:02 +00005442 break;
5443 default:
5444 if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5445 {
5446 ++__fmt_first;
5447 size_t __i = *__fmt_first - '0';
5448 if (__fmt_first + 1 != __fmt_last &&
5449 '0' <= __fmt_first[1] && __fmt_first[1] <= '9')
5450 {
5451 ++__fmt_first;
5452 __i = 10 * __i + *__fmt_first - '0';
5453 }
Duncan P. N. Exon Smithe784f572016-02-03 19:30:20 +00005454 __out = _VSTD::copy((*this)[__i].first,
5455 (*this)[__i].second, __out);
Howard Hinnant27405f92010-08-14 18:14:02 +00005456 }
5457 else
5458 {
5459 *__out = *__fmt_first;
5460 ++__out;
5461 }
5462 break;
5463 }
5464 }
5465 else
5466 {
5467 *__out = *__fmt_first;
5468 ++__out;
5469 }
5470 }
5471 }
5472 return __out;
5473}
5474
5475template <class _BidirectionalIterator, class _Allocator>
5476void
5477match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
5478{
Howard Hinnant0949eed2011-06-30 21:18:19 +00005479 using _VSTD::swap;
Howard Hinnant27405f92010-08-14 18:14:02 +00005480 swap(__matches_, __m.__matches_);
5481 swap(__unmatched_, __m.__unmatched_);
5482 swap(__prefix_, __m.__prefix_);
5483 swap(__suffix_, __m.__suffix_);
Howard Hinnanta712c722010-08-16 20:21:16 +00005484 swap(__position_start_, __m.__position_start_);
Howard Hinnant31aaf552010-12-08 21:07:55 +00005485 swap(__ready_, __m.__ready_);
Howard Hinnant27405f92010-08-14 18:14:02 +00005486}
5487
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005488typedef match_results<const char*> cmatch;
5489typedef match_results<const wchar_t*> wcmatch;
5490typedef match_results<string::const_iterator> smatch;
5491typedef match_results<wstring::const_iterator> wsmatch;
5492
5493template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005494bool
5495operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
5496 const match_results<_BidirectionalIterator, _Allocator>& __y)
5497{
Howard Hinnant31aaf552010-12-08 21:07:55 +00005498 if (__x.__ready_ != __y.__ready_)
5499 return false;
5500 if (!__x.__ready_)
5501 return true;
Howard Hinnant27405f92010-08-14 18:14:02 +00005502 return __x.__matches_ == __y.__matches_ &&
5503 __x.__prefix_ == __y.__prefix_ &&
Howard Hinnant31aaf552010-12-08 21:07:55 +00005504 __x.__suffix_ == __y.__suffix_;
Howard Hinnant27405f92010-08-14 18:14:02 +00005505}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005506
5507template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005508inline _LIBCPP_INLINE_VISIBILITY
5509bool
5510operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
5511 const match_results<_BidirectionalIterator, _Allocator>& __y)
5512{
5513 return !(__x == __y);
5514}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005515
5516template <class _BidirectionalIterator, class _Allocator>
Howard Hinnant27405f92010-08-14 18:14:02 +00005517inline _LIBCPP_INLINE_VISIBILITY
5518void
5519swap(match_results<_BidirectionalIterator, _Allocator>& __x,
5520 match_results<_BidirectionalIterator, _Allocator>& __y)
5521{
5522 __x.swap(__y);
5523}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005524
5525// regex_search
5526
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005527template <class _CharT, class _Traits>
Howard Hinnant17615b02010-07-27 01:25:38 +00005528template <class _Allocator>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005529bool
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005530basic_regex<_CharT, _Traits>::__match_at_start_ecma(
Howard Hinnant17615b02010-07-27 01:25:38 +00005531 const _CharT* __first, const _CharT* __last,
5532 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005533 regex_constants::match_flag_type __flags, bool __at_first) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005534{
Howard Hinnant17615b02010-07-27 01:25:38 +00005535 vector<__state> __states;
Howard Hinnant17615b02010-07-27 01:25:38 +00005536 __node* __st = __start_.get();
5537 if (__st)
5538 {
Marshall Clow5e56c302015-01-28 22:22:35 +00005539 sub_match<const _CharT*> __unmatched;
5540 __unmatched.first = __last;
5541 __unmatched.second = __last;
5542 __unmatched.matched = false;
5543
Howard Hinnant17615b02010-07-27 01:25:38 +00005544 __states.push_back(__state());
5545 __states.back().__do_ = 0;
5546 __states.back().__first_ = __first;
5547 __states.back().__current_ = __first;
5548 __states.back().__last_ = __last;
Marshall Clow5e56c302015-01-28 22:22:35 +00005549 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
Howard Hinnant17615b02010-07-27 01:25:38 +00005550 __states.back().__loop_data_.resize(__loop_count());
5551 __states.back().__node_ = __st;
5552 __states.back().__flags_ = __flags;
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005553 __states.back().__at_first_ = __at_first;
Howard Hinnant17615b02010-07-27 01:25:38 +00005554 do
5555 {
5556 __state& __s = __states.back();
5557 if (__s.__node_)
5558 __s.__node_->__exec(__s);
5559 switch (__s.__do_)
5560 {
5561 case __state::__end_state:
Tim Shen38c2a372016-10-27 21:40:34 +00005562 if ((__flags & regex_constants::match_not_null) &&
Tim Shen741cb8b2016-10-21 20:41:47 +00005563 __s.__current_ == __first)
5564 {
5565 __states.pop_back();
5566 break;
5567 }
Tim Shen38c2a372016-10-27 21:40:34 +00005568 if ((__flags & regex_constants::__full_match) &&
5569 __s.__current_ != __last)
5570 {
5571 __states.pop_back();
5572 break;
5573 }
Howard Hinnant17615b02010-07-27 01:25:38 +00005574 __m.__matches_[0].first = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00005575 __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
Howard Hinnant17615b02010-07-27 01:25:38 +00005576 __m.__matches_[0].matched = true;
5577 for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
5578 __m.__matches_[__i+1] = __s.__sub_matches_[__i];
5579 return true;
5580 case __state::__accept_and_consume:
5581 case __state::__repeat:
5582 case __state::__accept_but_not_consume:
5583 break;
5584 case __state::__split:
5585 {
5586 __state __snext = __s;
5587 __s.__node_->__exec_split(true, __s);
5588 __snext.__node_->__exec_split(false, __snext);
Howard Hinnant0949eed2011-06-30 21:18:19 +00005589 __states.push_back(_VSTD::move(__snext));
Howard Hinnant17615b02010-07-27 01:25:38 +00005590 }
5591 break;
5592 case __state::__reject:
5593 __states.pop_back();
5594 break;
5595 default:
Marshall Clow2576c292015-07-28 13:30:47 +00005596 __throw_regex_error<regex_constants::__re_err_unknown>();
Howard Hinnant17615b02010-07-27 01:25:38 +00005597 break;
Howard Hinnantd4444702010-08-11 17:04:31 +00005598
Howard Hinnant17615b02010-07-27 01:25:38 +00005599 }
5600 } while (!__states.empty());
5601 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005602 return false;
5603}
5604
5605template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005606template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005607bool
5608basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
5609 const _CharT* __first, const _CharT* __last,
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005610 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005611 regex_constants::match_flag_type __flags, bool __at_first) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005612{
Howard Hinnantac303862010-07-12 15:51:17 +00005613 deque<__state> __states;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005614 ptrdiff_t __highest_j = 0;
Howard Hinnant99968442011-11-29 18:15:50 +00005615 ptrdiff_t _Np = _VSTD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00005616 __node* __st = __start_.get();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005617 if (__st)
5618 {
Howard Hinnantac303862010-07-12 15:51:17 +00005619 __states.push_back(__state());
Howard Hinnantac303862010-07-12 15:51:17 +00005620 __states.back().__do_ = 0;
5621 __states.back().__first_ = __first;
5622 __states.back().__current_ = __first;
5623 __states.back().__last_ = __last;
5624 __states.back().__loop_data_.resize(__loop_count());
5625 __states.back().__node_ = __st;
5626 __states.back().__flags_ = __flags;
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005627 __states.back().__at_first_ = __at_first;
Howard Hinnant68025ed2010-07-14 15:45:11 +00005628 bool __matched = false;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005629 do
5630 {
Howard Hinnantac303862010-07-12 15:51:17 +00005631 __state& __s = __states.back();
5632 if (__s.__node_)
5633 __s.__node_->__exec(__s);
5634 switch (__s.__do_)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005635 {
Howard Hinnantac303862010-07-12 15:51:17 +00005636 case __state::__end_state:
Tim Shen38c2a372016-10-27 21:40:34 +00005637 if ((__flags & regex_constants::match_not_null) &&
Tim Shen741cb8b2016-10-21 20:41:47 +00005638 __s.__current_ == __first)
5639 {
5640 __states.pop_back();
5641 break;
5642 }
Tim Shen38c2a372016-10-27 21:40:34 +00005643 if ((__flags & regex_constants::__full_match) &&
5644 __s.__current_ != __last)
5645 {
5646 __states.pop_back();
5647 break;
5648 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005649 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
Howard Hinnant68025ed2010-07-14 15:45:11 +00005650 __highest_j = __s.__current_ - __s.__first_;
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005651 __matched = true;
Howard Hinnant99968442011-11-29 18:15:50 +00005652 if (__highest_j == _Np)
Howard Hinnantac303862010-07-12 15:51:17 +00005653 __states.clear();
5654 else
5655 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005656 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005657 case __state::__consume_input:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005658 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005659 case __state::__accept_and_consume:
Howard Hinnant0949eed2011-06-30 21:18:19 +00005660 __states.push_front(_VSTD::move(__s));
Howard Hinnantac303862010-07-12 15:51:17 +00005661 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005662 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005663 case __state::__repeat:
5664 case __state::__accept_but_not_consume:
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005665 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005666 case __state::__split:
5667 {
5668 __state __snext = __s;
5669 __s.__node_->__exec_split(true, __s);
5670 __snext.__node_->__exec_split(false, __snext);
Howard Hinnant0949eed2011-06-30 21:18:19 +00005671 __states.push_back(_VSTD::move(__snext));
Howard Hinnantac303862010-07-12 15:51:17 +00005672 }
5673 break;
5674 case __state::__reject:
5675 __states.pop_back();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005676 break;
5677 default:
Marshall Clow2576c292015-07-28 13:30:47 +00005678 __throw_regex_error<regex_constants::__re_err_unknown>();
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005679 break;
5680 }
Howard Hinnantac303862010-07-12 15:51:17 +00005681 } while (!__states.empty());
Howard Hinnant68025ed2010-07-14 15:45:11 +00005682 if (__matched)
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005683 {
5684 __m.__matches_[0].first = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00005685 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005686 __m.__matches_[0].matched = true;
5687 return true;
5688 }
5689 }
5690 return false;
5691}
5692
5693template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005694template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005695bool
5696basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005697 const _CharT* __first, const _CharT* __last,
5698 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005699 regex_constants::match_flag_type __flags, bool __at_first) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005700{
Howard Hinnantac303862010-07-12 15:51:17 +00005701 vector<__state> __states;
Howard Hinnantac303862010-07-12 15:51:17 +00005702 __state __best_state;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005703 ptrdiff_t __j = 0;
5704 ptrdiff_t __highest_j = 0;
Howard Hinnant99968442011-11-29 18:15:50 +00005705 ptrdiff_t _Np = _VSTD::distance(__first, __last);
Howard Hinnantac303862010-07-12 15:51:17 +00005706 __node* __st = __start_.get();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005707 if (__st)
5708 {
Marshall Clow5e56c302015-01-28 22:22:35 +00005709 sub_match<const _CharT*> __unmatched;
5710 __unmatched.first = __last;
5711 __unmatched.second = __last;
5712 __unmatched.matched = false;
5713
Howard Hinnantac303862010-07-12 15:51:17 +00005714 __states.push_back(__state());
5715 __states.back().__do_ = 0;
5716 __states.back().__first_ = __first;
5717 __states.back().__current_ = __first;
5718 __states.back().__last_ = __last;
Marshall Clow5e56c302015-01-28 22:22:35 +00005719 __states.back().__sub_matches_.resize(mark_count(), __unmatched);
Howard Hinnantac303862010-07-12 15:51:17 +00005720 __states.back().__loop_data_.resize(__loop_count());
5721 __states.back().__node_ = __st;
5722 __states.back().__flags_ = __flags;
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005723 __states.back().__at_first_ = __at_first;
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005724 const _CharT* __current = __first;
Howard Hinnantac303862010-07-12 15:51:17 +00005725 bool __matched = false;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005726 do
5727 {
Howard Hinnantac303862010-07-12 15:51:17 +00005728 __state& __s = __states.back();
5729 if (__s.__node_)
5730 __s.__node_->__exec(__s);
5731 switch (__s.__do_)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005732 {
Howard Hinnantac303862010-07-12 15:51:17 +00005733 case __state::__end_state:
Tim Shen38c2a372016-10-27 21:40:34 +00005734 if ((__flags & regex_constants::match_not_null) &&
Tim Shen741cb8b2016-10-21 20:41:47 +00005735 __s.__current_ == __first)
5736 {
5737 __states.pop_back();
5738 break;
5739 }
Tim Shen38c2a372016-10-27 21:40:34 +00005740 if ((__flags & regex_constants::__full_match) &&
5741 __s.__current_ != __last)
5742 {
5743 __states.pop_back();
5744 break;
5745 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005746 if (!__matched || __highest_j < __s.__current_ - __s.__first_)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005747 {
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005748 __highest_j = __s.__current_ - __s.__first_;
Howard Hinnantac303862010-07-12 15:51:17 +00005749 __best_state = __s;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005750 }
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005751 __matched = true;
Howard Hinnant99968442011-11-29 18:15:50 +00005752 if (__highest_j == _Np)
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005753 __states.clear();
5754 else
5755 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005756 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005757 case __state::__accept_and_consume:
Howard Hinnantcba352d2010-07-12 18:16:05 +00005758 __j += __s.__current_ - __current;
5759 __current = __s.__current_;
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005760 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005761 case __state::__repeat:
5762 case __state::__accept_but_not_consume:
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005763 break;
Howard Hinnantac303862010-07-12 15:51:17 +00005764 case __state::__split:
5765 {
5766 __state __snext = __s;
5767 __s.__node_->__exec_split(true, __s);
5768 __snext.__node_->__exec_split(false, __snext);
Howard Hinnant0949eed2011-06-30 21:18:19 +00005769 __states.push_back(_VSTD::move(__snext));
Howard Hinnantac303862010-07-12 15:51:17 +00005770 }
5771 break;
5772 case __state::__reject:
5773 __states.pop_back();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005774 break;
5775 default:
Marshall Clow2576c292015-07-28 13:30:47 +00005776 __throw_regex_error<regex_constants::__re_err_unknown>();
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005777 break;
5778 }
Howard Hinnantac303862010-07-12 15:51:17 +00005779 } while (!__states.empty());
5780 if (__matched)
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005781 {
5782 __m.__matches_[0].first = __first;
Howard Hinnant0949eed2011-06-30 21:18:19 +00005783 __m.__matches_[0].second = _VSTD::next(__first, __highest_j);
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005784 __m.__matches_[0].matched = true;
Howard Hinnantac303862010-07-12 15:51:17 +00005785 for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
5786 __m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
Howard Hinnante77aa5e2010-07-08 17:43:58 +00005787 return true;
5788 }
5789 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005790 return false;
5791}
5792
5793template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005794template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005795bool
5796basic_regex<_CharT, _Traits>::__match_at_start(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005797 const _CharT* __first, const _CharT* __last,
5798 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005799 regex_constants::match_flag_type __flags, bool __at_first) const
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005800{
Howard Hinnantad2a7ab2010-07-27 17:24:17 +00005801 if ((__flags_ & 0x1F0) == ECMAScript)
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005802 return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005803 if (mark_count() == 0)
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005804 return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
5805 return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005806}
5807
5808template <class _CharT, class _Traits>
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005809template <class _Allocator>
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005810bool
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005811basic_regex<_CharT, _Traits>::__search(
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005812 const _CharT* __first, const _CharT* __last,
5813 match_results<const _CharT*, _Allocator>& __m,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005814 regex_constants::match_flag_type __flags) const
5815{
Howard Hinnanta712c722010-08-16 20:21:16 +00005816 __m.__init(1 + mark_count(), __first, __last,
5817 __flags & regex_constants::__no_update_pos);
Howard Hinnant7670f7d2013-07-09 17:29:09 +00005818 if (__match_at_start(__first, __last, __m, __flags,
5819 !(__flags & regex_constants::__no_update_pos)))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005820 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005821 __m.__prefix_.second = __m[0].first;
5822 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5823 __m.__suffix_.first = __m[0].second;
5824 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5825 return true;
5826 }
Howard Hinnant8daa7332010-07-29 01:15:27 +00005827 if (__first != __last && !(__flags & regex_constants::match_continuous))
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005828 {
Howard Hinnantf3dcca02010-07-29 15:17:28 +00005829 __flags |= regex_constants::match_prev_avail;
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005830 for (++__first; __first != __last; ++__first)
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005831 {
Howard Hinnantf3dcca02010-07-29 15:17:28 +00005832 __m.__matches_.assign(__m.size(), __m.__unmatched_);
Howard Hinnant41fb6e12011-03-26 20:02:27 +00005833 if (__match_at_start(__first, __last, __m, __flags, false))
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005834 {
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005835 __m.__prefix_.second = __m[0].first;
5836 __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
5837 __m.__suffix_.first = __m[0].second;
5838 __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
5839 return true;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005840 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005841 __m.__matches_.assign(__m.size(), __m.__unmatched_);
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005842 }
5843 }
Howard Hinnantf8ce4592010-07-07 19:14:52 +00005844 __m.__matches_.clear();
5845 return false;
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005846}
5847
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005848template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005849inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005850bool
5851regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5852 match_results<_BidirectionalIterator, _Allocator>& __m,
5853 const basic_regex<_CharT, _Traits>& __e,
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005854 regex_constants::match_flag_type __flags = regex_constants::match_default)
5855{
Howard Hinnante8402082013-07-11 15:32:55 +00005856 int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
5857 basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last);
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005858 match_results<const _CharT*> __mc;
Howard Hinnante8402082013-07-11 15:32:55 +00005859 bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
Howard Hinnanta712c722010-08-16 20:21:16 +00005860 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005861 return __r;
5862}
5863
Howard Hinnanta9602d52013-06-29 23:45:43 +00005864template <class _Iter, class _Allocator, class _CharT, class _Traits>
5865inline _LIBCPP_INLINE_VISIBILITY
5866bool
5867regex_search(__wrap_iter<_Iter> __first,
5868 __wrap_iter<_Iter> __last,
5869 match_results<__wrap_iter<_Iter>, _Allocator>& __m,
5870 const basic_regex<_CharT, _Traits>& __e,
5871 regex_constants::match_flag_type __flags = regex_constants::match_default)
5872{
5873 match_results<const _CharT*> __mc;
5874 bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
5875 __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
5876 return __r;
5877}
5878
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005879template <class _Allocator, class _CharT, class _Traits>
5880inline _LIBCPP_INLINE_VISIBILITY
5881bool
5882regex_search(const _CharT* __first, const _CharT* __last,
5883 match_results<const _CharT*, _Allocator>& __m,
5884 const basic_regex<_CharT, _Traits>& __e,
5885 regex_constants::match_flag_type __flags = regex_constants::match_default)
5886{
Howard Hinnant9b80f2b2010-06-30 17:22:19 +00005887 return __e.__search(__first, __last, __m, __flags);
5888}
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005889
5890template <class _BidirectionalIterator, class _CharT, class _Traits>
5891inline _LIBCPP_INLINE_VISIBILITY
5892bool
5893regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
5894 const basic_regex<_CharT, _Traits>& __e,
5895 regex_constants::match_flag_type __flags = regex_constants::match_default)
5896{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005897 basic_string<_CharT> __s(__first, __last);
5898 match_results<const _CharT*> __mc;
5899 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
5900}
5901
5902template <class _CharT, class _Traits>
5903inline _LIBCPP_INLINE_VISIBILITY
5904bool
5905regex_search(const _CharT* __first, const _CharT* __last,
5906 const basic_regex<_CharT, _Traits>& __e,
5907 regex_constants::match_flag_type __flags = regex_constants::match_default)
5908{
5909 match_results<const _CharT*> __mc;
5910 return __e.__search(__first, __last, __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005911}
5912
5913template <class _CharT, class _Allocator, class _Traits>
5914inline _LIBCPP_INLINE_VISIBILITY
5915bool
5916regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
5917 const basic_regex<_CharT, _Traits>& __e,
5918 regex_constants::match_flag_type __flags = regex_constants::match_default)
5919{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005920 return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005921}
5922
5923template <class _CharT, class _Traits>
5924inline _LIBCPP_INLINE_VISIBILITY
5925bool
5926regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
5927 regex_constants::match_flag_type __flags = regex_constants::match_default)
5928{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005929 match_results<const _CharT*> __m;
Howard Hinnant0949eed2011-06-30 21:18:19 +00005930 return _VSTD::regex_search(__str, __m, __e, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005931}
5932
5933template <class _ST, class _SA, class _CharT, class _Traits>
5934inline _LIBCPP_INLINE_VISIBILITY
5935bool
5936regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5937 const basic_regex<_CharT, _Traits>& __e,
5938 regex_constants::match_flag_type __flags = regex_constants::match_default)
5939{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005940 match_results<const _CharT*> __mc;
5941 return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005942}
5943
5944template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5945inline _LIBCPP_INLINE_VISIBILITY
5946bool
5947regex_search(const basic_string<_CharT, _ST, _SA>& __s,
5948 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
5949 const basic_regex<_CharT, _Traits>& __e,
5950 regex_constants::match_flag_type __flags = regex_constants::match_default)
5951{
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005952 match_results<const _CharT*> __mc;
5953 bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
Howard Hinnanta712c722010-08-16 20:21:16 +00005954 __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
Howard Hinnant22ce0b42010-07-14 21:14:52 +00005955 return __r;
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005956}
5957
Marshall Clowe0f86722014-02-19 21:21:11 +00005958#if _LIBCPP_STD_VER > 11
5959template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
5960bool
5961regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
5962 match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
5963 const basic_regex<_Cp, _Tp>& __e,
5964 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
5965#endif
5966
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005967// regex_match
5968
5969template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5970bool
5971regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5972 match_results<_BidirectionalIterator, _Allocator>& __m,
5973 const basic_regex<_CharT, _Traits>& __e,
5974 regex_constants::match_flag_type __flags = regex_constants::match_default)
5975{
Tim Shen38c2a372016-10-27 21:40:34 +00005976 bool __r = _VSTD::regex_search(
5977 __first, __last, __m, __e,
5978 __flags | regex_constants::match_continuous |
5979 regex_constants::__full_match);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005980 if (__r)
5981 {
5982 __r = !__m.suffix().matched;
5983 if (!__r)
5984 __m.__matches_.clear();
5985 }
5986 return __r;
5987}
5988
5989template <class _BidirectionalIterator, class _CharT, class _Traits>
5990inline _LIBCPP_INLINE_VISIBILITY
5991bool
5992regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
5993 const basic_regex<_CharT, _Traits>& __e,
5994 regex_constants::match_flag_type __flags = regex_constants::match_default)
5995{
5996 match_results<_BidirectionalIterator> __m;
Howard Hinnant0949eed2011-06-30 21:18:19 +00005997 return _VSTD::regex_match(__first, __last, __m, __e, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00005998}
5999
6000template <class _CharT, class _Allocator, class _Traits>
6001inline _LIBCPP_INLINE_VISIBILITY
6002bool
6003regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
6004 const basic_regex<_CharT, _Traits>& __e,
6005 regex_constants::match_flag_type __flags = regex_constants::match_default)
6006{
Howard Hinnant0949eed2011-06-30 21:18:19 +00006007 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00006008}
6009
6010template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
6011inline _LIBCPP_INLINE_VISIBILITY
6012bool
6013regex_match(const basic_string<_CharT, _ST, _SA>& __s,
6014 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
6015 const basic_regex<_CharT, _Traits>& __e,
6016 regex_constants::match_flag_type __flags = regex_constants::match_default)
6017{
Howard Hinnant0949eed2011-06-30 21:18:19 +00006018 return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00006019}
6020
Marshall Clowe0f86722014-02-19 21:21:11 +00006021#if _LIBCPP_STD_VER > 11
6022template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
6023inline _LIBCPP_INLINE_VISIBILITY
6024bool
6025regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
6026 match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
6027 const basic_regex<_CharT, _Traits>& __e,
6028 regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
6029#endif
6030
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00006031template <class _CharT, class _Traits>
6032inline _LIBCPP_INLINE_VISIBILITY
6033bool
6034regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
6035 regex_constants::match_flag_type __flags = regex_constants::match_default)
6036{
Howard Hinnant0949eed2011-06-30 21:18:19 +00006037 return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00006038}
6039
6040template <class _ST, class _SA, class _CharT, class _Traits>
6041inline _LIBCPP_INLINE_VISIBILITY
6042bool
6043regex_match(const basic_string<_CharT, _ST, _SA>& __s,
6044 const basic_regex<_CharT, _Traits>& __e,
6045 regex_constants::match_flag_type __flags = regex_constants::match_default)
6046{
Howard Hinnant0949eed2011-06-30 21:18:19 +00006047 return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags);
Howard Hinnant7e9d84b2010-06-30 00:21:42 +00006048}
6049
Howard Hinnanta712c722010-08-16 20:21:16 +00006050// regex_iterator
6051
6052template <class _BidirectionalIterator,
6053 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6054 class _Traits = regex_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00006055class _LIBCPP_TYPE_VIS_ONLY regex_iterator
Howard Hinnanta712c722010-08-16 20:21:16 +00006056{
6057public:
6058 typedef basic_regex<_CharT, _Traits> regex_type;
6059 typedef match_results<_BidirectionalIterator> value_type;
6060 typedef ptrdiff_t difference_type;
6061 typedef const value_type* pointer;
6062 typedef const value_type& reference;
6063 typedef forward_iterator_tag iterator_category;
6064
6065private:
6066 _BidirectionalIterator __begin_;
6067 _BidirectionalIterator __end_;
6068 const regex_type* __pregex_;
6069 regex_constants::match_flag_type __flags_;
6070 value_type __match_;
6071
6072public:
6073 regex_iterator();
6074 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6075 const regex_type& __re,
Marshall Clowe0f86722014-02-19 21:21:11 +00006076 regex_constants::match_flag_type __m
6077 = regex_constants::match_default);
6078#if _LIBCPP_STD_VER > 11
6079 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6080 const regex_type&& __re,
6081 regex_constants::match_flag_type __m
6082 = regex_constants::match_default) = delete;
6083#endif
Howard Hinnanta712c722010-08-16 20:21:16 +00006084
6085 bool operator==(const regex_iterator& __x) const;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006086 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00006087 bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
6088
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006089 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00006090 reference operator*() const {return __match_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006091 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00006092 pointer operator->() const {return &__match_;}
6093
6094 regex_iterator& operator++();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006095 _LIBCPP_INLINE_VISIBILITY
Howard Hinnanta712c722010-08-16 20:21:16 +00006096 regex_iterator operator++(int)
6097 {
6098 regex_iterator __t(*this);
6099 ++(*this);
6100 return __t;
6101 }
6102};
6103
6104template <class _BidirectionalIterator, class _CharT, class _Traits>
6105regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
6106 : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
6107{
6108}
6109
6110template <class _BidirectionalIterator, class _CharT, class _Traits>
6111regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6112 regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6113 const regex_type& __re, regex_constants::match_flag_type __m)
6114 : __begin_(__a),
6115 __end_(__b),
6116 __pregex_(&__re),
6117 __flags_(__m)
6118{
Howard Hinnant0949eed2011-06-30 21:18:19 +00006119 _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
Howard Hinnanta712c722010-08-16 20:21:16 +00006120}
6121
6122template <class _BidirectionalIterator, class _CharT, class _Traits>
6123bool
6124regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
6125 operator==(const regex_iterator& __x) const
6126{
6127 if (__match_.empty() && __x.__match_.empty())
6128 return true;
6129 if (__match_.empty() || __x.__match_.empty())
6130 return false;
6131 return __begin_ == __x.__begin_ &&
6132 __end_ == __x.__end_ &&
6133 __pregex_ == __x.__pregex_ &&
6134 __flags_ == __x.__flags_ &&
6135 __match_[0] == __x.__match_[0];
6136}
6137
6138template <class _BidirectionalIterator, class _CharT, class _Traits>
6139regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
6140regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6141{
6142 __flags_ |= regex_constants::__no_update_pos;
6143 _BidirectionalIterator __start = __match_[0].second;
Howard Hinnanta9602d52013-06-29 23:45:43 +00006144 if (__match_.empty())
Howard Hinnanta712c722010-08-16 20:21:16 +00006145 {
6146 if (__start == __end_)
6147 {
6148 __match_ = value_type();
6149 return *this;
6150 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00006151 else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_,
Howard Hinnanta712c722010-08-16 20:21:16 +00006152 __flags_ | regex_constants::match_not_null |
6153 regex_constants::match_continuous))
6154 return *this;
6155 else
6156 ++__start;
6157 }
6158 __flags_ |= regex_constants::match_prev_avail;
Howard Hinnant0949eed2011-06-30 21:18:19 +00006159 if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
Howard Hinnanta712c722010-08-16 20:21:16 +00006160 __match_ = value_type();
6161 return *this;
6162}
6163
6164typedef regex_iterator<const char*> cregex_iterator;
6165typedef regex_iterator<const wchar_t*> wcregex_iterator;
6166typedef regex_iterator<string::const_iterator> sregex_iterator;
6167typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
6168
6169// regex_token_iterator
6170
6171template <class _BidirectionalIterator,
6172 class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
6173 class _Traits = regex_traits<_CharT> >
Howard Hinnant0f678bd2013-08-12 18:38:34 +00006174class _LIBCPP_TYPE_VIS_ONLY regex_token_iterator
Howard Hinnanta712c722010-08-16 20:21:16 +00006175{
6176public:
6177 typedef basic_regex<_CharT, _Traits> regex_type;
6178 typedef sub_match<_BidirectionalIterator> value_type;
6179 typedef ptrdiff_t difference_type;
6180 typedef const value_type* pointer;
6181 typedef const value_type& reference;
6182 typedef forward_iterator_tag iterator_category;
6183
Howard Hinnant262b7792010-08-17 20:42:03 +00006184private:
6185 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
6186
6187 _Position __position_;
6188 const value_type* __result_;
6189 value_type __suffix_;
Eric Fiselier50f65792016-12-24 00:24:44 +00006190 ptrdiff_t __n_;
Howard Hinnant262b7792010-08-17 20:42:03 +00006191 vector<int> __subs_;
6192
6193public:
Howard Hinnanta712c722010-08-16 20:21:16 +00006194 regex_token_iterator();
6195 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6196 const regex_type& __re, int __submatch = 0,
Howard Hinnant262b7792010-08-17 20:42:03 +00006197 regex_constants::match_flag_type __m =
6198 regex_constants::match_default);
Marshall Clowe0f86722014-02-19 21:21:11 +00006199#if _LIBCPP_STD_VER > 11
6200 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6201 const regex_type&& __re, int __submatch = 0,
6202 regex_constants::match_flag_type __m =
6203 regex_constants::match_default) = delete;
6204#endif
6205
Howard Hinnanta712c722010-08-16 20:21:16 +00006206 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6207 const regex_type& __re, const vector<int>& __submatches,
Howard Hinnant262b7792010-08-17 20:42:03 +00006208 regex_constants::match_flag_type __m =
6209 regex_constants::match_default);
Marshall Clowe0f86722014-02-19 21:21:11 +00006210#if _LIBCPP_STD_VER > 11
6211 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6212 const regex_type&& __re, const vector<int>& __submatches,
6213 regex_constants::match_flag_type __m =
6214 regex_constants::match_default) = delete;
6215#endif
6216
Howard Hinnante3e32912011-08-12 21:56:02 +00006217#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnanta712c722010-08-16 20:21:16 +00006218 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
Howard Hinnant262b7792010-08-17 20:42:03 +00006219 const regex_type& __re,
6220 initializer_list<int> __submatches,
6221 regex_constants::match_flag_type __m =
6222 regex_constants::match_default);
Marshall Clowe0f86722014-02-19 21:21:11 +00006223
6224#if _LIBCPP_STD_VER > 11
6225 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6226 const regex_type&& __re,
6227 initializer_list<int> __submatches,
6228 regex_constants::match_flag_type __m =
6229 regex_constants::match_default) = delete;
6230#endif
Howard Hinnante3e32912011-08-12 21:56:02 +00006231#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant99968442011-11-29 18:15:50 +00006232 template <size_t _Np>
Howard Hinnant262b7792010-08-17 20:42:03 +00006233 regex_token_iterator(_BidirectionalIterator __a,
6234 _BidirectionalIterator __b,
6235 const regex_type& __re,
Howard Hinnant99968442011-11-29 18:15:50 +00006236 const int (&__submatches)[_Np],
Howard Hinnant262b7792010-08-17 20:42:03 +00006237 regex_constants::match_flag_type __m =
6238 regex_constants::match_default);
Marshall Clowe0f86722014-02-19 21:21:11 +00006239#if _LIBCPP_STD_VER > 11
6240 template <std::size_t _Np>
6241 regex_token_iterator(_BidirectionalIterator __a,
6242 _BidirectionalIterator __b,
6243 const regex_type&& __re,
6244 const int (&__submatches)[_Np],
6245 regex_constants::match_flag_type __m =
6246 regex_constants::match_default) = delete;
6247#endif
6248
Howard Hinnanta712c722010-08-16 20:21:16 +00006249 regex_token_iterator(const regex_token_iterator&);
6250 regex_token_iterator& operator=(const regex_token_iterator&);
6251
Howard Hinnant262b7792010-08-17 20:42:03 +00006252 bool operator==(const regex_token_iterator& __x) const;
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006254 bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
Howard Hinnanta712c722010-08-16 20:21:16 +00006255
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006257 const value_type& operator*() const {return *__result_;}
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006259 const value_type* operator->() const {return __result_;}
Howard Hinnanta712c722010-08-16 20:21:16 +00006260
6261 regex_token_iterator& operator++();
Howard Hinnantaef07cb2010-09-23 15:13:20 +00006262 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant262b7792010-08-17 20:42:03 +00006263 regex_token_iterator operator++(int)
6264 {
6265 regex_token_iterator __t(*this);
6266 ++(*this);
6267 return __t;
6268 }
6269
6270private:
6271 void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
Marshall Clow0efd9dc2014-01-09 18:25:57 +00006272 void __establish_result () {
Eric Fiselier50f65792016-12-24 00:24:44 +00006273 if (__subs_[__n_] == -1)
Marshall Clow0efd9dc2014-01-09 18:25:57 +00006274 __result_ = &__position_->prefix();
6275 else
Eric Fiselier50f65792016-12-24 00:24:44 +00006276 __result_ = &(*__position_)[__subs_[__n_]];
Marshall Clow0efd9dc2014-01-09 18:25:57 +00006277 }
Howard Hinnanta712c722010-08-16 20:21:16 +00006278};
6279
Howard Hinnant262b7792010-08-17 20:42:03 +00006280template <class _BidirectionalIterator, class _CharT, class _Traits>
6281regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6282 regex_token_iterator()
6283 : __result_(nullptr),
6284 __suffix_(),
Eric Fiselier50f65792016-12-24 00:24:44 +00006285 __n_(0)
Howard Hinnant262b7792010-08-17 20:42:03 +00006286{
6287}
6288
6289template <class _BidirectionalIterator, class _CharT, class _Traits>
6290void
6291regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6292 __init(_BidirectionalIterator __a, _BidirectionalIterator __b)
6293{
6294 if (__position_ != _Position())
Marshall Clow0efd9dc2014-01-09 18:25:57 +00006295 __establish_result ();
Eric Fiselier50f65792016-12-24 00:24:44 +00006296 else if (__subs_[__n_] == -1)
Howard Hinnant262b7792010-08-17 20:42:03 +00006297 {
6298 __suffix_.matched = true;
6299 __suffix_.first = __a;
6300 __suffix_.second = __b;
6301 __result_ = &__suffix_;
6302 }
6303 else
6304 __result_ = nullptr;
6305}
6306
6307template <class _BidirectionalIterator, class _CharT, class _Traits>
6308regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6309 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6310 const regex_type& __re, int __submatch,
6311 regex_constants::match_flag_type __m)
6312 : __position_(__a, __b, __re, __m),
Eric Fiselier50f65792016-12-24 00:24:44 +00006313 __n_(0),
Howard Hinnant262b7792010-08-17 20:42:03 +00006314 __subs_(1, __submatch)
6315{
6316 __init(__a, __b);
6317}
6318
6319template <class _BidirectionalIterator, class _CharT, class _Traits>
6320regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6321 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6322 const regex_type& __re, const vector<int>& __submatches,
6323 regex_constants::match_flag_type __m)
6324 : __position_(__a, __b, __re, __m),
Eric Fiselier50f65792016-12-24 00:24:44 +00006325 __n_(0),
Howard Hinnant262b7792010-08-17 20:42:03 +00006326 __subs_(__submatches)
6327{
6328 __init(__a, __b);
6329}
6330
Howard Hinnante3e32912011-08-12 21:56:02 +00006331#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6332
Howard Hinnant262b7792010-08-17 20:42:03 +00006333template <class _BidirectionalIterator, class _CharT, class _Traits>
6334regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6335 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6336 const regex_type& __re,
6337 initializer_list<int> __submatches,
6338 regex_constants::match_flag_type __m)
6339 : __position_(__a, __b, __re, __m),
Eric Fiselier50f65792016-12-24 00:24:44 +00006340 __n_(0),
Howard Hinnant262b7792010-08-17 20:42:03 +00006341 __subs_(__submatches)
6342{
6343 __init(__a, __b);
6344}
6345
Howard Hinnante3e32912011-08-12 21:56:02 +00006346#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
6347
Howard Hinnant262b7792010-08-17 20:42:03 +00006348template <class _BidirectionalIterator, class _CharT, class _Traits>
Howard Hinnant99968442011-11-29 18:15:50 +00006349template <size_t _Np>
Howard Hinnant262b7792010-08-17 20:42:03 +00006350regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6351 regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
6352 const regex_type& __re,
Howard Hinnant99968442011-11-29 18:15:50 +00006353 const int (&__submatches)[_Np],
Howard Hinnant262b7792010-08-17 20:42:03 +00006354 regex_constants::match_flag_type __m)
6355 : __position_(__a, __b, __re, __m),
Eric Fiselier50f65792016-12-24 00:24:44 +00006356 __n_(0),
Howard Hinnant99968442011-11-29 18:15:50 +00006357 __subs_(__submatches, __submatches + _Np)
Howard Hinnant262b7792010-08-17 20:42:03 +00006358{
6359 __init(__a, __b);
6360}
6361
6362template <class _BidirectionalIterator, class _CharT, class _Traits>
6363regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6364 regex_token_iterator(const regex_token_iterator& __x)
6365 : __position_(__x.__position_),
6366 __result_(__x.__result_),
6367 __suffix_(__x.__suffix_),
Eric Fiselier50f65792016-12-24 00:24:44 +00006368 __n_(__x.__n_),
Howard Hinnant262b7792010-08-17 20:42:03 +00006369 __subs_(__x.__subs_)
6370{
6371 if (__x.__result_ == &__x.__suffix_)
Marshall Clow72fe0ae2014-01-13 17:47:08 +00006372 __result_ = &__suffix_;
Marshall Clow0efd9dc2014-01-09 18:25:57 +00006373 else if ( __result_ != nullptr )
6374 __establish_result ();
Howard Hinnant262b7792010-08-17 20:42:03 +00006375}
6376
6377template <class _BidirectionalIterator, class _CharT, class _Traits>
6378regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6379regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6380 operator=(const regex_token_iterator& __x)
6381{
6382 if (this != &__x)
6383 {
6384 __position_ = __x.__position_;
6385 if (__x.__result_ == &__x.__suffix_)
Marshall Clow0efd9dc2014-01-09 18:25:57 +00006386 __result_ = &__suffix_;
Howard Hinnant262b7792010-08-17 20:42:03 +00006387 else
6388 __result_ = __x.__result_;
6389 __suffix_ = __x.__suffix_;
Eric Fiselier50f65792016-12-24 00:24:44 +00006390 __n_ = __x.__n_;
Howard Hinnant262b7792010-08-17 20:42:03 +00006391 __subs_ = __x.__subs_;
Marshall Clow0efd9dc2014-01-09 18:25:57 +00006392
6393 if ( __result_ != nullptr && __result_ != &__suffix_ )
6394 __establish_result();
Howard Hinnant262b7792010-08-17 20:42:03 +00006395 }
6396 return *this;
6397}
6398
6399template <class _BidirectionalIterator, class _CharT, class _Traits>
6400bool
6401regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
6402 operator==(const regex_token_iterator& __x) const
6403{
6404 if (__result_ == nullptr && __x.__result_ == nullptr)
6405 return true;
6406 if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
6407 __suffix_ == __x.__suffix_)
6408 return true;
6409 if (__result_ == nullptr || __x.__result_ == nullptr)
6410 return false;
6411 if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
6412 return false;
Eric Fiselier50f65792016-12-24 00:24:44 +00006413 return __position_ == __x.__position_ && __n_ == __x.__n_ &&
Howard Hinnant262b7792010-08-17 20:42:03 +00006414 __subs_ == __x.__subs_;
6415}
6416
6417template <class _BidirectionalIterator, class _CharT, class _Traits>
6418regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
6419regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
6420{
6421 _Position __prev = __position_;
6422 if (__result_ == &__suffix_)
6423 __result_ = nullptr;
Eric Fiselier50f65792016-12-24 00:24:44 +00006424 else if (static_cast<size_t>(__n_ + 1) < __subs_.size())
Howard Hinnant262b7792010-08-17 20:42:03 +00006425 {
Eric Fiselier50f65792016-12-24 00:24:44 +00006426 ++__n_;
Marshall Clow0efd9dc2014-01-09 18:25:57 +00006427 __establish_result();
Howard Hinnant262b7792010-08-17 20:42:03 +00006428 }
6429 else
6430 {
Eric Fiselier50f65792016-12-24 00:24:44 +00006431 __n_ = 0;
Howard Hinnant262b7792010-08-17 20:42:03 +00006432 ++__position_;
6433 if (__position_ != _Position())
Marshall Clow0efd9dc2014-01-09 18:25:57 +00006434 __establish_result();
Howard Hinnant262b7792010-08-17 20:42:03 +00006435 else
6436 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00006437 if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
Howard Hinnant262b7792010-08-17 20:42:03 +00006438 && __prev->suffix().length() != 0)
6439 {
6440 __suffix_.matched = true;
6441 __suffix_.first = __prev->suffix().first;
6442 __suffix_.second = __prev->suffix().second;
6443 __result_ = &__suffix_;
6444 }
6445 else
6446 __result_ = nullptr;
6447 }
6448 }
6449 return *this;
6450}
6451
Howard Hinnanta712c722010-08-16 20:21:16 +00006452typedef regex_token_iterator<const char*> cregex_token_iterator;
6453typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
6454typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
6455typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
6456
Howard Hinnanta8d77592010-08-18 00:13:08 +00006457// regex_replace
6458
6459template <class _OutputIterator, class _BidirectionalIterator,
6460 class _Traits, class _CharT>
6461_OutputIterator
6462regex_replace(_OutputIterator __out,
6463 _BidirectionalIterator __first, _BidirectionalIterator __last,
6464 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6465 regex_constants::match_flag_type __flags = regex_constants::match_default)
6466{
6467 typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
6468 _Iter __i(__first, __last, __e, __flags);
6469 _Iter __eof;
6470 if (__i == __eof)
6471 {
6472 if (!(__flags & regex_constants::format_no_copy))
Howard Hinnant0949eed2011-06-30 21:18:19 +00006473 __out = _VSTD::copy(__first, __last, __out);
Howard Hinnanta8d77592010-08-18 00:13:08 +00006474 }
6475 else
6476 {
6477 sub_match<_BidirectionalIterator> __lm;
6478 for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
6479 {
6480 if (!(__flags & regex_constants::format_no_copy))
Howard Hinnant0949eed2011-06-30 21:18:19 +00006481 __out = _VSTD::copy(__i->prefix().first, __i->prefix().second, __out);
Howard Hinnanta8d77592010-08-18 00:13:08 +00006482 __out = __i->format(__out, __fmt, __fmt + __len, __flags);
6483 __lm = __i->suffix();
6484 if (__flags & regex_constants::format_first_only)
6485 break;
6486 }
6487 if (!(__flags & regex_constants::format_no_copy))
Howard Hinnant0949eed2011-06-30 21:18:19 +00006488 __out = _VSTD::copy(__lm.first, __lm.second, __out);
Howard Hinnanta8d77592010-08-18 00:13:08 +00006489 }
6490 return __out;
6491}
6492
6493template <class _OutputIterator, class _BidirectionalIterator,
6494 class _Traits, class _CharT, class _ST, class _SA>
6495inline _LIBCPP_INLINE_VISIBILITY
6496_OutputIterator
6497regex_replace(_OutputIterator __out,
6498 _BidirectionalIterator __first, _BidirectionalIterator __last,
6499 const basic_regex<_CharT, _Traits>& __e,
6500 const basic_string<_CharT, _ST, _SA>& __fmt,
6501 regex_constants::match_flag_type __flags = regex_constants::match_default)
6502{
Howard Hinnant0949eed2011-06-30 21:18:19 +00006503 return _VSTD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
Howard Hinnanta8d77592010-08-18 00:13:08 +00006504}
6505
6506template <class _Traits, class _CharT, class _ST, class _SA, class _FST,
6507 class _FSA>
6508inline _LIBCPP_INLINE_VISIBILITY
6509basic_string<_CharT, _ST, _SA>
6510regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6511 const basic_regex<_CharT, _Traits>& __e,
6512 const basic_string<_CharT, _FST, _FSA>& __fmt,
6513 regex_constants::match_flag_type __flags = regex_constants::match_default)
6514{
6515 basic_string<_CharT, _ST, _SA> __r;
Howard Hinnant0949eed2011-06-30 21:18:19 +00006516 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
Howard Hinnanta8d77592010-08-18 00:13:08 +00006517 __fmt.c_str(), __flags);
6518 return __r;
6519}
6520
6521template <class _Traits, class _CharT, class _ST, class _SA>
6522inline _LIBCPP_INLINE_VISIBILITY
6523basic_string<_CharT, _ST, _SA>
6524regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
6525 const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
6526 regex_constants::match_flag_type __flags = regex_constants::match_default)
6527{
6528 basic_string<_CharT, _ST, _SA> __r;
Howard Hinnant0949eed2011-06-30 21:18:19 +00006529 _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
Howard Hinnanta8d77592010-08-18 00:13:08 +00006530 __fmt, __flags);
6531 return __r;
6532}
6533
6534template <class _Traits, class _CharT, class _ST, class _SA>
6535inline _LIBCPP_INLINE_VISIBILITY
6536basic_string<_CharT>
6537regex_replace(const _CharT* __s,
6538 const basic_regex<_CharT, _Traits>& __e,
6539 const basic_string<_CharT, _ST, _SA>& __fmt,
6540 regex_constants::match_flag_type __flags = regex_constants::match_default)
6541{
6542 basic_string<_CharT> __r;
Howard Hinnant0949eed2011-06-30 21:18:19 +00006543 _VSTD::regex_replace(back_inserter(__r), __s,
Howard Hinnanta8d77592010-08-18 00:13:08 +00006544 __s + char_traits<_CharT>::length(__s), __e,
6545 __fmt.c_str(), __flags);
6546 return __r;
6547}
6548
6549template <class _Traits, class _CharT>
6550inline _LIBCPP_INLINE_VISIBILITY
6551basic_string<_CharT>
6552regex_replace(const _CharT* __s,
6553 const basic_regex<_CharT, _Traits>& __e,
6554 const _CharT* __fmt,
6555 regex_constants::match_flag_type __flags = regex_constants::match_default)
6556{
6557 basic_string<_CharT> __r;
Howard Hinnant0949eed2011-06-30 21:18:19 +00006558 _VSTD::regex_replace(back_inserter(__r), __s,
Howard Hinnanta8d77592010-08-18 00:13:08 +00006559 __s + char_traits<_CharT>::length(__s), __e,
6560 __fmt, __flags);
6561 return __r;
6562}
6563
Howard Hinnant3257c982010-06-17 00:34:59 +00006564_LIBCPP_END_NAMESPACE_STD
6565
6566#endif // _LIBCPP_REGEX