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