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