Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- regex ------------------------------------===// |
| 3 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 | [diff] [blame] | 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_REGEX |
| 11 | #define _LIBCPP_REGEX |
| 12 | |
| 13 | /* |
| 14 | regex synopsis |
| 15 | |
| 16 | #include <initializer_list> |
| 17 | |
| 18 | namespace std |
| 19 | { |
| 20 | |
| 21 | namespace regex_constants |
| 22 | { |
| 23 | |
| 24 | emum syntax_option_type |
| 25 | { |
| 26 | icase = unspecified, |
| 27 | nosubs = unspecified, |
| 28 | optimize = unspecified, |
| 29 | collate = unspecified, |
| 30 | ECMAScript = unspecified, |
| 31 | basic = unspecified, |
| 32 | extended = unspecified, |
| 33 | awk = unspecified, |
| 34 | grep = unspecified, |
| 35 | egrep = unspecified |
| 36 | }; |
| 37 | |
| 38 | constexpr syntax_option_type operator~(syntax_option_type f); |
| 39 | constexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs); |
| 40 | constexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs); |
| 41 | |
| 42 | enum match_flag_type |
| 43 | { |
| 44 | match_default = 0, |
| 45 | match_not_bol = unspecified, |
| 46 | match_not_eol = unspecified, |
| 47 | match_not_bow = unspecified, |
| 48 | match_not_eow = unspecified, |
| 49 | match_any = unspecified, |
| 50 | match_not_null = unspecified, |
| 51 | match_continuous = unspecified, |
| 52 | match_prev_avail = unspecified, |
| 53 | format_default = 0, |
| 54 | format_sed = unspecified, |
| 55 | format_no_copy = unspecified, |
| 56 | format_first_only = unspecified |
| 57 | }; |
| 58 | |
| 59 | constexpr match_flag_type operator~(match_flag_type f); |
| 60 | constexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs); |
| 61 | constexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs); |
| 62 | |
| 63 | enum error_type |
| 64 | { |
| 65 | error_collate = unspecified, |
| 66 | error_ctype = unspecified, |
| 67 | error_escape = unspecified, |
| 68 | error_backref = unspecified, |
| 69 | error_brack = unspecified, |
| 70 | error_paren = unspecified, |
| 71 | error_brace = unspecified, |
| 72 | error_badbrace = unspecified, |
| 73 | error_range = unspecified, |
| 74 | error_space = unspecified, |
| 75 | error_badrepeat = unspecified, |
| 76 | error_complexity = unspecified, |
| 77 | error_stack = unspecified |
| 78 | }; |
| 79 | |
| 80 | } // regex_constants |
| 81 | |
| 82 | class regex_error |
| 83 | : public runtime_error |
| 84 | { |
| 85 | public: |
| 86 | explicit regex_error(regex_constants::error_type ecode); |
| 87 | regex_constants::error_type code() const; |
| 88 | }; |
| 89 | |
| 90 | template <class charT> |
| 91 | struct regex_traits |
| 92 | { |
| 93 | public: |
| 94 | typedef charT char_type; |
| 95 | typedef basic_string<char_type> string_type; |
| 96 | typedef locale locale_type; |
| 97 | typedef /bitmask_type/ char_class_type; |
| 98 | |
| 99 | regex_traits(); |
| 100 | |
| 101 | static size_t length(const char_type* p); |
| 102 | charT translate(charT c) const; |
| 103 | charT translate_nocase(charT c) const; |
| 104 | template <class ForwardIterator> |
| 105 | string_type |
| 106 | transform(ForwardIterator first, ForwardIterator last) const; |
| 107 | template <class ForwardIterator> |
| 108 | string_type |
| 109 | transform_primary( ForwardIterator first, ForwardIterator last) const; |
| 110 | template <class ForwardIterator> |
| 111 | string_type |
| 112 | lookup_collatename(ForwardIterator first, ForwardIterator last) const; |
| 113 | template <class ForwardIterator> |
| 114 | char_class_type |
| 115 | lookup_classname(ForwardIterator first, ForwardIterator last, |
| 116 | bool icase = false) const; |
| 117 | bool isctype(charT c, char_class_type f) const; |
| 118 | int value(charT ch, int radix) const; |
| 119 | locale_type imbue(locale_type l); |
| 120 | locale_type getloc()const; |
| 121 | }; |
| 122 | |
| 123 | template <class charT, class traits = regex_traits<charT>> |
| 124 | class basic_regex |
| 125 | { |
| 126 | public: |
| 127 | // types: |
| 128 | typedef charT value_type; |
Hubert Tong | ac98d59 | 2016-08-02 21:34:48 | [diff] [blame] | 129 | typedef traits traits_type; |
| 130 | typedef typename traits::string_type string_type; |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 131 | typedef regex_constants::syntax_option_type flag_type; |
| 132 | typedef typename traits::locale_type locale_type; |
| 133 | |
| 134 | // constants: |
| 135 | static constexpr regex_constants::syntax_option_type icase = regex_constants::icase; |
| 136 | static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 137 | static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 138 | static constexpr regex_constants::syntax_option_type collate = regex_constants::collate; |
| 139 | static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 140 | static constexpr regex_constants::syntax_option_type basic = regex_constants::basic; |
| 141 | static constexpr regex_constants::syntax_option_type extended = regex_constants::extended; |
| 142 | static constexpr regex_constants::syntax_option_type awk = regex_constants::awk; |
| 143 | static constexpr regex_constants::syntax_option_type grep = regex_constants::grep; |
| 144 | static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep; |
| 145 | |
| 146 | // construct/copy/destroy: |
| 147 | basic_regex(); |
| 148 | explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript); |
Hubert Tong | 2fdf202 | 2016-08-07 22:26:04 | [diff] [blame] | 149 | basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript); |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 150 | basic_regex(const basic_regex&); |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 151 | basic_regex(basic_regex&&) noexcept; |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 152 | template <class ST, class SA> |
| 153 | explicit basic_regex(const basic_string<charT, ST, SA>& p, |
| 154 | flag_type f = regex_constants::ECMAScript); |
| 155 | template <class ForwardIterator> |
| 156 | basic_regex(ForwardIterator first, ForwardIterator last, |
| 157 | flag_type f = regex_constants::ECMAScript); |
| 158 | basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript); |
| 159 | |
| 160 | ~basic_regex(); |
| 161 | |
| 162 | basic_regex& operator=(const basic_regex&); |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 163 | basic_regex& operator=(basic_regex&&) noexcept; |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 164 | basic_regex& operator=(const charT* ptr); |
| 165 | basic_regex& operator=(initializer_list<charT> il); |
| 166 | template <class ST, class SA> |
| 167 | basic_regex& operator=(const basic_string<charT, ST, SA>& p); |
| 168 | |
| 169 | // assign: |
| 170 | basic_regex& assign(const basic_regex& that); |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 171 | basic_regex& assign(basic_regex&& that) noexcept; |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 172 | basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript); |
| 173 | basic_regex& assign(const charT* p, size_t len, flag_type f); |
| 174 | template <class string_traits, class A> |
| 175 | basic_regex& assign(const basic_string<charT, string_traits, A>& s, |
| 176 | flag_type f = regex_constants::ECMAScript); |
| 177 | template <class InputIterator> |
| 178 | basic_regex& assign(InputIterator first, InputIterator last, |
| 179 | flag_type f = regex_constants::ECMAScript); |
| 180 | basic_regex& assign(initializer_list<charT>, flag_type = regex_constants::ECMAScript); |
| 181 | |
| 182 | // const operations: |
| 183 | unsigned mark_count() const; |
| 184 | flag_type flags() const; |
| 185 | |
| 186 | // locale: |
| 187 | locale_type imbue(locale_type loc); |
| 188 | locale_type getloc() const; |
| 189 | |
| 190 | // swap: |
| 191 | void swap(basic_regex&); |
| 192 | }; |
| 193 | |
Marshall Clow | edd5e29 | 2018-05-23 01:57:02 | [diff] [blame] | 194 | template<class ForwardIterator> |
| 195 | basic_regex(ForwardIterator, ForwardIterator, |
| 196 | regex_constants::syntax_option_type = regex_constants::ECMAScript) |
| 197 | -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; // C++17 |
| 198 | |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 199 | typedef basic_regex<char> regex; |
| 200 | typedef basic_regex<wchar_t> wregex; |
| 201 | |
| 202 | template <class charT, class traits> |
| 203 | void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2); |
| 204 | |
| 205 | template <class BidirectionalIterator> |
| 206 | class sub_match |
| 207 | : public pair<BidirectionalIterator, BidirectionalIterator> |
| 208 | { |
| 209 | public: |
| 210 | typedef typename iterator_traits<BidirectionalIterator>::value_type value_type; |
| 211 | typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; |
| 212 | typedef BidirectionalIterator iterator; |
| 213 | typedef basic_string<value_type> string_type; |
| 214 | |
| 215 | bool matched; |
| 216 | |
Howard Hinnant | 966b5a3 | 2010-12-08 21:07:55 | [diff] [blame] | 217 | constexpr sub_match(); |
| 218 | |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 219 | difference_type length() const; |
| 220 | operator string_type() const; |
| 221 | string_type str() const; |
| 222 | |
| 223 | int compare(const sub_match& s) const; |
| 224 | int compare(const string_type& s) const; |
| 225 | int compare(const value_type* s) const; |
| 226 | }; |
| 227 | |
| 228 | typedef sub_match<const char*> csub_match; |
| 229 | typedef sub_match<const wchar_t*> wcsub_match; |
| 230 | typedef sub_match<string::const_iterator> ssub_match; |
| 231 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 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> |
| 254 | bool |
| 255 | operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 256 | |
| 257 | template <class BiIter, class ST, class SA> |
| 258 | bool |
| 259 | operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 260 | const sub_match<BiIter>& rhs); |
| 261 | |
| 262 | template <class BiIter, class ST, class SA> |
| 263 | bool |
| 264 | operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 265 | const sub_match<BiIter>& rhs); |
| 266 | |
| 267 | template <class BiIter, class ST, class SA> |
| 268 | bool |
| 269 | operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 270 | const sub_match<BiIter>& rhs); |
| 271 | |
| 272 | template <class BiIter, class ST, class SA> |
| 273 | bool |
| 274 | operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 275 | const sub_match<BiIter>& rhs); |
| 276 | |
| 277 | template <class BiIter, class ST, class SA> |
| 278 | bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 279 | const sub_match<BiIter>& rhs); |
| 280 | |
| 281 | template <class BiIter, class ST, class SA> |
| 282 | bool |
| 283 | operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 284 | const sub_match<BiIter>& rhs); |
| 285 | |
| 286 | template <class BiIter, class ST, class SA> |
| 287 | bool |
| 288 | operator==(const sub_match<BiIter>& lhs, |
| 289 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 290 | |
| 291 | template <class BiIter, class ST, class SA> |
| 292 | bool |
| 293 | operator!=(const sub_match<BiIter>& lhs, |
| 294 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 295 | |
| 296 | template <class BiIter, class ST, class SA> |
| 297 | bool |
| 298 | operator<(const sub_match<BiIter>& lhs, |
| 299 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 300 | |
| 301 | template <class BiIter, class ST, class SA> |
| 302 | bool operator>(const sub_match<BiIter>& lhs, |
| 303 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 304 | |
| 305 | template <class BiIter, class ST, class SA> |
| 306 | bool |
| 307 | operator>=(const sub_match<BiIter>& lhs, |
| 308 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 309 | |
| 310 | template <class BiIter, class ST, class SA> |
| 311 | bool |
| 312 | operator<=(const sub_match<BiIter>& lhs, |
| 313 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 314 | |
| 315 | template <class BiIter> |
| 316 | bool |
| 317 | operator==(typename iterator_traits<BiIter>::value_type const* lhs, |
| 318 | const sub_match<BiIter>& rhs); |
| 319 | |
| 320 | template <class BiIter> |
| 321 | bool |
| 322 | operator!=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 323 | const sub_match<BiIter>& rhs); |
| 324 | |
| 325 | template <class BiIter> |
| 326 | bool |
| 327 | operator<(typename iterator_traits<BiIter>::value_type const* lhs, |
| 328 | const sub_match<BiIter>& rhs); |
| 329 | |
| 330 | template <class BiIter> |
| 331 | bool |
| 332 | operator>(typename iterator_traits<BiIter>::value_type const* lhs, |
| 333 | const sub_match<BiIter>& rhs); |
| 334 | |
| 335 | template <class BiIter> |
| 336 | bool |
| 337 | operator>=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 338 | const sub_match<BiIter>& rhs); |
| 339 | |
| 340 | template <class BiIter> |
| 341 | bool |
| 342 | operator<=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 343 | const sub_match<BiIter>& rhs); |
| 344 | |
| 345 | template <class BiIter> |
| 346 | bool |
| 347 | operator==(const sub_match<BiIter>& lhs, |
| 348 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 349 | |
| 350 | template <class BiIter> |
| 351 | bool |
| 352 | operator!=(const sub_match<BiIter>& lhs, |
| 353 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 354 | |
| 355 | template <class BiIter> |
| 356 | bool |
| 357 | operator<(const sub_match<BiIter>& lhs, |
| 358 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 359 | |
| 360 | template <class BiIter> |
| 361 | bool |
| 362 | operator>(const sub_match<BiIter>& lhs, |
| 363 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 364 | |
| 365 | template <class BiIter> |
| 366 | bool |
| 367 | operator>=(const sub_match<BiIter>& lhs, |
| 368 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 369 | |
| 370 | template <class BiIter> |
| 371 | bool |
| 372 | operator<=(const sub_match<BiIter>& lhs, |
| 373 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 374 | |
| 375 | template <class BiIter> |
| 376 | bool |
| 377 | operator==(typename iterator_traits<BiIter>::value_type const& lhs, |
| 378 | const sub_match<BiIter>& rhs); |
| 379 | |
| 380 | template <class BiIter> |
| 381 | bool |
| 382 | operator!=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 383 | const sub_match<BiIter>& rhs); |
| 384 | |
| 385 | template <class BiIter> |
| 386 | bool |
| 387 | operator<(typename iterator_traits<BiIter>::value_type const& lhs, |
| 388 | const sub_match<BiIter>& rhs); |
| 389 | |
| 390 | template <class BiIter> |
| 391 | bool |
| 392 | operator>(typename iterator_traits<BiIter>::value_type const& lhs, |
| 393 | const sub_match<BiIter>& rhs); |
| 394 | |
| 395 | template <class BiIter> |
| 396 | bool |
| 397 | operator>=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 398 | const sub_match<BiIter>& rhs); |
| 399 | |
| 400 | template <class BiIter> |
| 401 | bool |
| 402 | operator<=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 403 | const sub_match<BiIter>& rhs); |
| 404 | |
| 405 | template <class BiIter> |
| 406 | bool |
| 407 | operator==(const sub_match<BiIter>& lhs, |
| 408 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 409 | |
| 410 | template <class BiIter> |
| 411 | bool |
| 412 | operator!=(const sub_match<BiIter>& lhs, |
| 413 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 414 | |
| 415 | template <class BiIter> |
| 416 | bool |
| 417 | operator<(const sub_match<BiIter>& lhs, |
| 418 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 419 | |
| 420 | template <class BiIter> |
| 421 | bool |
| 422 | operator>(const sub_match<BiIter>& lhs, |
| 423 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 424 | |
| 425 | template <class BiIter> |
| 426 | bool |
| 427 | operator>=(const sub_match<BiIter>& lhs, |
| 428 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 429 | |
| 430 | template <class BiIter> |
| 431 | bool |
| 432 | operator<=(const sub_match<BiIter>& lhs, |
| 433 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 434 | |
| 435 | template <class charT, class ST, class BiIter> |
| 436 | basic_ostream<charT, ST>& |
| 437 | operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m); |
| 438 | |
| 439 | template <class BidirectionalIterator, |
| 440 | class Allocator = allocator<sub_match<BidirectionalIterator>>> |
| 441 | class match_results |
| 442 | { |
| 443 | public: |
| 444 | typedef sub_match<BidirectionalIterator> value_type; |
| 445 | typedef const value_type& const_reference; |
Marshall Clow | 16da324 | 2014-02-26 01:56:31 | [diff] [blame] | 446 | typedef value_type& reference; |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 447 | typedef /implementation-defined/ const_iterator; |
| 448 | typedef const_iterator iterator; |
| 449 | typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; |
| 450 | typedef typename allocator_traits<Allocator>::size_type size_type; |
| 451 | typedef Allocator allocator_type; |
| 452 | typedef typename iterator_traits<BidirectionalIterator>::value_type char_type; |
| 453 | typedef basic_string<char_type> string_type; |
| 454 | |
| 455 | // construct/copy/destroy: |
| 456 | explicit match_results(const Allocator& a = Allocator()); |
| 457 | match_results(const match_results& m); |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 458 | match_results(match_results&& m) noexcept; |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 459 | match_results& operator=(const match_results& m); |
| 460 | match_results& operator=(match_results&& m); |
| 461 | ~match_results(); |
| 462 | |
Howard Hinnant | 966b5a3 | 2010-12-08 21:07:55 | [diff] [blame] | 463 | bool ready() const; |
| 464 | |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 465 | // size: |
| 466 | size_type size() const; |
| 467 | size_type max_size() const; |
| 468 | bool empty() const; |
| 469 | |
| 470 | // element access: |
| 471 | difference_type length(size_type sub = 0) const; |
| 472 | difference_type position(size_type sub = 0) const; |
| 473 | string_type str(size_type sub = 0) const; |
| 474 | const_reference operator[](size_type n) const; |
| 475 | |
| 476 | const_reference prefix() const; |
| 477 | const_reference suffix() const; |
| 478 | |
| 479 | const_iterator begin() const; |
| 480 | const_iterator end() const; |
| 481 | const_iterator cbegin() const; |
| 482 | const_iterator cend() const; |
| 483 | |
| 484 | // format: |
| 485 | template <class OutputIter> |
| 486 | OutputIter |
| 487 | format(OutputIter out, const char_type* fmt_first, |
| 488 | const char_type* fmt_last, |
| 489 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 490 | template <class OutputIter, class ST, class SA> |
| 491 | OutputIter |
| 492 | format(OutputIter out, const basic_string<char_type, ST, SA>& fmt, |
| 493 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 494 | template <class ST, class SA> |
| 495 | basic_string<char_type, ST, SA> |
| 496 | format(const basic_string<char_type, ST, SA>& fmt, |
| 497 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 498 | string_type |
| 499 | format(const char_type* fmt, |
| 500 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 501 | |
| 502 | // allocator: |
| 503 | allocator_type get_allocator() const; |
| 504 | |
| 505 | // swap: |
| 506 | void swap(match_results& that); |
| 507 | }; |
| 508 | |
| 509 | typedef match_results<const char*> cmatch; |
| 510 | typedef match_results<const wchar_t*> wcmatch; |
| 511 | typedef match_results<string::const_iterator> smatch; |
| 512 | typedef match_results<wstring::const_iterator> wsmatch; |
| 513 | |
| 514 | template <class BidirectionalIterator, class Allocator> |
| 515 | bool |
| 516 | operator==(const match_results<BidirectionalIterator, Allocator>& m1, |
| 517 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 518 | |
| 519 | template <class BidirectionalIterator, class Allocator> |
| 520 | bool |
| 521 | operator!=(const match_results<BidirectionalIterator, Allocator>& m1, |
| 522 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 523 | |
| 524 | template <class BidirectionalIterator, class Allocator> |
| 525 | void |
| 526 | swap(match_results<BidirectionalIterator, Allocator>& m1, |
| 527 | match_results<BidirectionalIterator, Allocator>& m2); |
| 528 | |
| 529 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 530 | bool |
| 531 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 532 | match_results<BidirectionalIterator, Allocator>& m, |
| 533 | const basic_regex<charT, traits>& e, |
| 534 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 535 | |
| 536 | template <class BidirectionalIterator, class charT, class traits> |
| 537 | bool |
| 538 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 539 | const basic_regex<charT, traits>& e, |
| 540 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 541 | |
| 542 | template <class charT, class Allocator, class traits> |
| 543 | bool |
| 544 | regex_match(const charT* str, match_results<const charT*, Allocator>& m, |
| 545 | const basic_regex<charT, traits>& e, |
| 546 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 547 | |
| 548 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 549 | bool |
| 550 | regex_match(const basic_string<charT, ST, SA>& s, |
| 551 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 552 | const basic_regex<charT, traits>& e, |
| 553 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 554 | |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 555 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 556 | bool |
| 557 | regex_match(const basic_string<charT, ST, SA>&& s, |
| 558 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 559 | const basic_regex<charT, traits>& e, |
| 560 | regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 |
| 561 | |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 562 | template <class charT, class traits> |
| 563 | bool |
| 564 | regex_match(const charT* str, const basic_regex<charT, traits>& e, |
| 565 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 566 | |
| 567 | template <class ST, class SA, class charT, class traits> |
| 568 | bool |
| 569 | regex_match(const basic_string<charT, ST, SA>& s, |
| 570 | const basic_regex<charT, traits>& e, |
| 571 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 572 | |
| 573 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 574 | bool |
| 575 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 576 | match_results<BidirectionalIterator, Allocator>& m, |
| 577 | const basic_regex<charT, traits>& e, |
| 578 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 579 | |
| 580 | template <class BidirectionalIterator, class charT, class traits> |
| 581 | bool |
| 582 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 583 | const basic_regex<charT, traits>& e, |
| 584 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 585 | |
| 586 | template <class charT, class Allocator, class traits> |
| 587 | bool |
| 588 | regex_search(const charT* str, match_results<const charT*, Allocator>& m, |
| 589 | const basic_regex<charT, traits>& e, |
| 590 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 591 | |
| 592 | template <class charT, class traits> |
| 593 | bool |
| 594 | regex_search(const charT* str, const basic_regex<charT, traits>& e, |
| 595 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 596 | |
| 597 | template <class ST, class SA, class charT, class traits> |
| 598 | bool |
| 599 | regex_search(const basic_string<charT, ST, SA>& s, |
| 600 | const basic_regex<charT, traits>& e, |
| 601 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 602 | |
| 603 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 604 | bool |
| 605 | regex_search(const basic_string<charT, ST, SA>& s, |
| 606 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 607 | const basic_regex<charT, traits>& e, |
| 608 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 609 | |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 610 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 611 | bool |
| 612 | regex_search(const basic_string<charT, ST, SA>&& s, |
| 613 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 614 | const basic_regex<charT, traits>& e, |
| 615 | regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 |
| 616 | |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 617 | template <class OutputIterator, class BidirectionalIterator, |
| 618 | class traits, class charT, class ST, class SA> |
| 619 | OutputIterator |
| 620 | regex_replace(OutputIterator out, |
| 621 | BidirectionalIterator first, BidirectionalIterator last, |
| 622 | const basic_regex<charT, traits>& e, |
| 623 | const basic_string<charT, ST, SA>& fmt, |
| 624 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 625 | |
| 626 | template <class OutputIterator, class BidirectionalIterator, |
| 627 | class traits, class charT> |
| 628 | OutputIterator |
| 629 | regex_replace(OutputIterator out, |
| 630 | BidirectionalIterator first, BidirectionalIterator last, |
| 631 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 632 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 633 | |
| 634 | template <class traits, class charT, class ST, class SA, class FST, class FSA>> |
| 635 | basic_string<charT, ST, SA> |
| 636 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 637 | const basic_regex<charT, traits>& e, |
| 638 | const basic_string<charT, FST, FSA>& fmt, |
| 639 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 640 | |
| 641 | template <class traits, class charT, class ST, class SA> |
| 642 | basic_string<charT, ST, SA> |
| 643 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 644 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 645 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 646 | |
| 647 | template <class traits, class charT, class ST, class SA> |
| 648 | basic_string<charT> |
| 649 | regex_replace(const charT* s, |
| 650 | const basic_regex<charT, traits>& e, |
| 651 | const basic_string<charT, ST, SA>& fmt, |
| 652 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 653 | |
| 654 | template <class traits, class charT> |
| 655 | basic_string<charT> |
| 656 | regex_replace(const charT* s, |
| 657 | const basic_regex<charT, traits>& e, |
| 658 | const charT* fmt, |
| 659 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 660 | |
| 661 | template <class BidirectionalIterator, |
| 662 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 663 | class traits = regex_traits<charT>> |
| 664 | class regex_iterator |
| 665 | { |
| 666 | public: |
| 667 | typedef basic_regex<charT, traits> regex_type; |
| 668 | typedef match_results<BidirectionalIterator> value_type; |
| 669 | typedef ptrdiff_t difference_type; |
| 670 | typedef const value_type* pointer; |
| 671 | typedef const value_type& reference; |
| 672 | typedef forward_iterator_tag iterator_category; |
| 673 | |
| 674 | regex_iterator(); |
| 675 | regex_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 676 | const regex_type& re, |
| 677 | regex_constants::match_flag_type m = regex_constants::match_default); |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 678 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 679 | const regex_type&& __re, |
| 680 | regex_constants::match_flag_type __m |
| 681 | = regex_constants::match_default) = delete; // C++14 |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 682 | regex_iterator(const regex_iterator&); |
| 683 | regex_iterator& operator=(const regex_iterator&); |
| 684 | |
| 685 | bool operator==(const regex_iterator&) const; |
| 686 | bool operator!=(const regex_iterator&) const; |
| 687 | |
| 688 | const value_type& operator*() const; |
| 689 | const value_type* operator->() const; |
| 690 | |
| 691 | regex_iterator& operator++(); |
| 692 | regex_iterator operator++(int); |
| 693 | }; |
| 694 | |
| 695 | typedef regex_iterator<const char*> cregex_iterator; |
| 696 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 697 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 698 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 699 | |
| 700 | template <class BidirectionalIterator, |
| 701 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 702 | class traits = regex_traits<charT>> |
| 703 | class regex_token_iterator |
| 704 | { |
| 705 | public: |
| 706 | typedef basic_regex<charT, traits> regex_type; |
| 707 | typedef sub_match<BidirectionalIterator> value_type; |
| 708 | typedef ptrdiff_t difference_type; |
| 709 | typedef const value_type* pointer; |
| 710 | typedef const value_type& reference; |
| 711 | typedef forward_iterator_tag iterator_category; |
| 712 | |
| 713 | regex_token_iterator(); |
| 714 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 715 | const regex_type& re, int submatch = 0, |
| 716 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 717 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 718 | const regex_type&& re, int submatch = 0, |
| 719 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
| 720 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 721 | const regex_type& re, const vector<int>& submatches, |
| 722 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 723 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 724 | const regex_type&& re, const vector<int>& submatches, |
| 725 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
| 726 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 727 | const regex_type& re, initializer_list<int> submatches, |
| 728 | regex_constants::match_flag_type m = regex_constants::match_default); |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 729 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 730 | const regex_type&& re, initializer_list<int> submatches, |
| 731 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 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); |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 736 | template <size_t N> |
| 737 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 738 | const regex_type& re, const int (&submatches)[N], |
| 739 | regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14; |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 740 | regex_token_iterator(const regex_token_iterator&); |
| 741 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 742 | |
| 743 | bool operator==(const regex_token_iterator&) const; |
| 744 | bool operator!=(const regex_token_iterator&) const; |
| 745 | |
| 746 | const value_type& operator*() const; |
| 747 | const value_type* operator->() const; |
| 748 | |
| 749 | regex_token_iterator& operator++(); |
| 750 | regex_token_iterator operator++(int); |
| 751 | }; |
| 752 | |
| 753 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 754 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 755 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 756 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 757 | |
| 758 | } // std |
| 759 | */ |
| 760 | |
| 761 | #include <__config> |
| 762 | #include <stdexcept> |
| 763 | #include <__locale> |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 764 | #include <initializer_list> |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 765 | #include <utility> |
| 766 | #include <iterator> |
| 767 | #include <string> |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 768 | #include <memory> |
| 769 | #include <vector> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 770 | #include <deque> |
Marshall Clow | f56972e | 2018-09-12 19:41:40 | [diff] [blame] | 771 | #include <version> |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 772 | |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 | [diff] [blame] | 773 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 774 | #pragma GCC system_header |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 | [diff] [blame] | 775 | #endif |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 776 | |
Eric Fiselier | a016efb | 2017-05-31 22:07:49 | [diff] [blame] | 777 | _LIBCPP_PUSH_MACROS |
| 778 | #include <__undef_macros> |
| 779 | |
| 780 | |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 | [diff] [blame] | 781 | #define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096 |
| 782 | |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 783 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 784 | |
| 785 | namespace regex_constants |
| 786 | { |
| 787 | |
| 788 | // syntax_option_type |
| 789 | |
| 790 | enum syntax_option_type |
| 791 | { |
| 792 | icase = 1 << 0, |
| 793 | nosubs = 1 << 1, |
| 794 | optimize = 1 << 2, |
| 795 | collate = 1 << 3, |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 796 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 797 | ECMAScript = 1 << 9, |
| 798 | #else |
Howard Hinnant | 6afe8b0 | 2010-07-27 17:24:17 | [diff] [blame] | 799 | ECMAScript = 0, |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 800 | #endif |
Howard Hinnant | 6afe8b0 | 2010-07-27 17:24:17 | [diff] [blame] | 801 | basic = 1 << 4, |
| 802 | extended = 1 << 5, |
| 803 | awk = 1 << 6, |
| 804 | grep = 1 << 7, |
| 805 | egrep = 1 << 8 |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 806 | }; |
| 807 | |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 808 | inline _LIBCPP_CONSTEXPR |
| 809 | syntax_option_type __get_grammar(syntax_option_type __g) |
| 810 | { |
| 811 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 812 | return static_cast<syntax_option_type>(__g & 0x3F0); |
| 813 | #else |
| 814 | return static_cast<syntax_option_type>(__g & 0x1F0); |
| 815 | #endif |
| 816 | } |
| 817 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 818 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 819 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 820 | syntax_option_type |
| 821 | operator~(syntax_option_type __x) |
| 822 | { |
Marshall Clow | 1c2c986 | 2013-03-22 02:13:55 | [diff] [blame] | 823 | return syntax_option_type(~int(__x) & 0x1FF); |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 824 | } |
| 825 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 826 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 827 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 828 | syntax_option_type |
| 829 | operator&(syntax_option_type __x, syntax_option_type __y) |
| 830 | { |
| 831 | return syntax_option_type(int(__x) & int(__y)); |
| 832 | } |
| 833 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 834 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 835 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 836 | syntax_option_type |
| 837 | operator|(syntax_option_type __x, syntax_option_type __y) |
| 838 | { |
| 839 | return syntax_option_type(int(__x) | int(__y)); |
| 840 | } |
| 841 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 842 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 843 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 844 | syntax_option_type |
| 845 | operator^(syntax_option_type __x, syntax_option_type __y) |
| 846 | { |
| 847 | return syntax_option_type(int(__x) ^ int(__y)); |
| 848 | } |
| 849 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 850 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 851 | syntax_option_type& |
| 852 | operator&=(syntax_option_type& __x, syntax_option_type __y) |
| 853 | { |
| 854 | __x = __x & __y; |
| 855 | return __x; |
| 856 | } |
| 857 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 858 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 859 | syntax_option_type& |
| 860 | operator|=(syntax_option_type& __x, syntax_option_type __y) |
| 861 | { |
| 862 | __x = __x | __y; |
| 863 | return __x; |
| 864 | } |
| 865 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 866 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 867 | syntax_option_type& |
| 868 | operator^=(syntax_option_type& __x, syntax_option_type __y) |
| 869 | { |
| 870 | __x = __x ^ __y; |
| 871 | return __x; |
| 872 | } |
| 873 | |
| 874 | // match_flag_type |
| 875 | |
| 876 | enum match_flag_type |
| 877 | { |
| 878 | match_default = 0, |
| 879 | match_not_bol = 1 << 0, |
| 880 | match_not_eol = 1 << 1, |
| 881 | match_not_bow = 1 << 2, |
| 882 | match_not_eow = 1 << 3, |
| 883 | match_any = 1 << 4, |
| 884 | match_not_null = 1 << 5, |
| 885 | match_continuous = 1 << 6, |
| 886 | match_prev_avail = 1 << 7, |
| 887 | format_default = 0, |
| 888 | format_sed = 1 << 8, |
| 889 | format_no_copy = 1 << 9, |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 890 | format_first_only = 1 << 10, |
Tim Shen | e776667 | 2016-10-27 21:40:34 | [diff] [blame] | 891 | __no_update_pos = 1 << 11, |
| 892 | __full_match = 1 << 12 |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 893 | }; |
| 894 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 895 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 896 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 897 | match_flag_type |
| 898 | operator~(match_flag_type __x) |
| 899 | { |
Marshall Clow | 1c2c986 | 2013-03-22 02:13:55 | [diff] [blame] | 900 | return match_flag_type(~int(__x) & 0x0FFF); |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 901 | } |
| 902 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 903 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 904 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 905 | match_flag_type |
| 906 | operator&(match_flag_type __x, match_flag_type __y) |
| 907 | { |
| 908 | return match_flag_type(int(__x) & int(__y)); |
| 909 | } |
| 910 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 911 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 912 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 913 | match_flag_type |
| 914 | operator|(match_flag_type __x, match_flag_type __y) |
| 915 | { |
| 916 | return match_flag_type(int(__x) | int(__y)); |
| 917 | } |
| 918 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 919 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 920 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 921 | match_flag_type |
| 922 | operator^(match_flag_type __x, match_flag_type __y) |
| 923 | { |
| 924 | return match_flag_type(int(__x) ^ int(__y)); |
| 925 | } |
| 926 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 927 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 928 | match_flag_type& |
| 929 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 930 | { |
| 931 | __x = __x & __y; |
| 932 | return __x; |
| 933 | } |
| 934 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 935 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 936 | match_flag_type& |
| 937 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 938 | { |
| 939 | __x = __x | __y; |
| 940 | return __x; |
| 941 | } |
| 942 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 943 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 944 | match_flag_type& |
| 945 | operator^=(match_flag_type& __x, match_flag_type __y) |
| 946 | { |
| 947 | __x = __x ^ __y; |
| 948 | return __x; |
| 949 | } |
| 950 | |
| 951 | enum error_type |
| 952 | { |
| 953 | error_collate = 1, |
| 954 | error_ctype, |
| 955 | error_escape, |
| 956 | error_backref, |
| 957 | error_brack, |
| 958 | error_paren, |
| 959 | error_brace, |
| 960 | error_badbrace, |
| 961 | error_range, |
| 962 | error_space, |
| 963 | error_badrepeat, |
| 964 | error_complexity, |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 965 | error_stack, |
Howard Hinnant | 6afe8b0 | 2010-07-27 17:24:17 | [diff] [blame] | 966 | __re_err_grammar, |
| 967 | __re_err_empty, |
| 968 | __re_err_unknown |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 969 | }; |
| 970 | |
| 971 | } // regex_constants |
| 972 | |
| 973 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 974 | : public runtime_error |
| 975 | { |
| 976 | regex_constants::error_type __code_; |
| 977 | public: |
| 978 | explicit regex_error(regex_constants::error_type __ecode); |
| 979 | virtual ~regex_error() throw(); |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 980 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 981 | regex_constants::error_type code() const {return __code_;} |
| 982 | }; |
| 983 | |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 984 | template <regex_constants::error_type _Ev> |
Louis Dionne | dc7200b | 2018-07-11 23:14:33 | [diff] [blame] | 985 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 986 | void __throw_regex_error() |
| 987 | { |
| 988 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Marshall Clow | 05ddbff | 2015-08-17 21:14:16 | [diff] [blame] | 989 | throw regex_error(_Ev); |
| 990 | #else |
Marshall Clow | d437fa5 | 2016-08-25 15:09:01 | [diff] [blame] | 991 | _VSTD::abort(); |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 992 | #endif |
| 993 | } |
| 994 | |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 995 | template <class _CharT> |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 996 | struct _LIBCPP_TEMPLATE_VIS regex_traits |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 997 | { |
| 998 | public: |
| 999 | typedef _CharT char_type; |
| 1000 | typedef basic_string<char_type> string_type; |
| 1001 | typedef locale locale_type; |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1002 | typedef ctype_base::mask char_class_type; |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1003 | |
Daniel Sanders | 4788179 | 2016-02-17 13:16:31 | [diff] [blame] | 1004 | #if defined(__mips__) && defined(__GLIBC__) |
| 1005 | static const char_class_type __regex_word = static_cast<char_class_type>(_ISbit(15)); |
Michal Gorny | a25cd0c | 2018-12-16 09:18:26 | [diff] [blame] | 1006 | #elif defined(__NetBSD__) |
| 1007 | // NetBSD defines classes up to 0x2000 |
| 1008 | // see sys/ctype_bits.h, _CTYPE_Q |
| 1009 | static const char_class_type __regex_word = 0x8000; |
Daniel Sanders | 4788179 | 2016-02-17 13:16:31 | [diff] [blame] | 1010 | #else |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1011 | static const char_class_type __regex_word = 0x80; |
Daniel Sanders | 4788179 | 2016-02-17 13:16:31 | [diff] [blame] | 1012 | #endif |
| 1013 | |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1014 | private: |
| 1015 | locale __loc_; |
| 1016 | const ctype<char_type>* __ct_; |
| 1017 | const collate<char_type>* __col_; |
| 1018 | |
| 1019 | public: |
| 1020 | regex_traits(); |
| 1021 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1022 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1023 | static size_t length(const char_type* __p) |
| 1024 | {return char_traits<char_type>::length(__p);} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1025 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1026 | char_type translate(char_type __c) const {return __c;} |
| 1027 | char_type translate_nocase(char_type __c) const; |
| 1028 | template <class _ForwardIterator> |
| 1029 | string_type |
| 1030 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 1031 | template <class _ForwardIterator> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1032 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1033 | string_type |
| 1034 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 1035 | {return __transform_primary(__f, __l, char_type());} |
| 1036 | template <class _ForwardIterator> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1037 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1038 | string_type |
| 1039 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 1040 | {return __lookup_collatename(__f, __l, char_type());} |
| 1041 | template <class _ForwardIterator> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1042 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1043 | char_class_type |
| 1044 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1045 | bool __icase = false) const |
| 1046 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 1047 | bool isctype(char_type __c, char_class_type __m) const; |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1048 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1049 | int value(char_type __ch, int __radix) const |
Marshall Clow | e604469 | 2013-10-21 15:43:25 | [diff] [blame] | 1050 | {return __regex_traits_value(__ch, __radix);} |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1051 | locale_type imbue(locale_type __l); |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1052 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1053 | locale_type getloc()const {return __loc_;} |
| 1054 | |
| 1055 | private: |
| 1056 | void __init(); |
| 1057 | |
| 1058 | template <class _ForwardIterator> |
| 1059 | string_type |
| 1060 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 1061 | template <class _ForwardIterator> |
| 1062 | string_type |
| 1063 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
| 1064 | |
| 1065 | template <class _ForwardIterator> |
| 1066 | string_type |
| 1067 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 1068 | template <class _ForwardIterator> |
| 1069 | string_type |
| 1070 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1071 | |
| 1072 | template <class _ForwardIterator> |
| 1073 | char_class_type |
| 1074 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1075 | bool __icase, char) const; |
| 1076 | template <class _ForwardIterator> |
| 1077 | char_class_type |
| 1078 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1079 | bool __icase, wchar_t) const; |
| 1080 | |
Marshall Clow | e604469 | 2013-10-21 15:43:25 | [diff] [blame] | 1081 | static int __regex_traits_value(unsigned char __ch, int __radix); |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1082 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e604469 | 2013-10-21 15:43:25 | [diff] [blame] | 1083 | int __regex_traits_value(char __ch, int __radix) const |
| 1084 | {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);} |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 | [diff] [blame] | 1085 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | e604469 | 2013-10-21 15:43:25 | [diff] [blame] | 1086 | int __regex_traits_value(wchar_t __ch, int __radix) const; |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1087 | }; |
| 1088 | |
| 1089 | template <class _CharT> |
Howard Hinnant | c60bf54 | 2013-03-07 19:38:08 | [diff] [blame] | 1090 | const typename regex_traits<_CharT>::char_class_type |
| 1091 | regex_traits<_CharT>::__regex_word; |
| 1092 | |
| 1093 | template <class _CharT> |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1094 | regex_traits<_CharT>::regex_traits() |
| 1095 | { |
| 1096 | __init(); |
| 1097 | } |
| 1098 | |
| 1099 | template <class _CharT> |
| 1100 | typename regex_traits<_CharT>::char_type |
| 1101 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1102 | { |
| 1103 | return __ct_->tolower(__c); |
| 1104 | } |
| 1105 | |
| 1106 | template <class _CharT> |
| 1107 | template <class _ForwardIterator> |
| 1108 | typename regex_traits<_CharT>::string_type |
| 1109 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1110 | { |
| 1111 | string_type __s(__f, __l); |
| 1112 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1113 | } |
| 1114 | |
| 1115 | template <class _CharT> |
| 1116 | void |
| 1117 | regex_traits<_CharT>::__init() |
| 1118 | { |
| 1119 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1120 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1121 | } |
| 1122 | |
| 1123 | template <class _CharT> |
| 1124 | typename regex_traits<_CharT>::locale_type |
| 1125 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1126 | { |
| 1127 | locale __r = __loc_; |
| 1128 | __loc_ = __l; |
| 1129 | __init(); |
| 1130 | return __r; |
| 1131 | } |
| 1132 | |
| 1133 | // transform_primary is very FreeBSD-specific |
| 1134 | |
| 1135 | template <class _CharT> |
| 1136 | template <class _ForwardIterator> |
| 1137 | typename regex_traits<_CharT>::string_type |
| 1138 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1139 | _ForwardIterator __l, char) const |
| 1140 | { |
| 1141 | const string_type __s(__f, __l); |
| 1142 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1143 | switch (__d.size()) |
| 1144 | { |
| 1145 | case 1: |
| 1146 | break; |
| 1147 | case 12: |
| 1148 | __d[11] = __d[3]; |
| 1149 | break; |
| 1150 | default: |
| 1151 | __d.clear(); |
| 1152 | break; |
| 1153 | } |
| 1154 | return __d; |
| 1155 | } |
| 1156 | |
| 1157 | template <class _CharT> |
| 1158 | template <class _ForwardIterator> |
| 1159 | typename regex_traits<_CharT>::string_type |
| 1160 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1161 | _ForwardIterator __l, wchar_t) const |
| 1162 | { |
| 1163 | const string_type __s(__f, __l); |
| 1164 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1165 | switch (__d.size()) |
| 1166 | { |
| 1167 | case 1: |
| 1168 | break; |
| 1169 | case 3: |
| 1170 | __d[2] = __d[0]; |
| 1171 | break; |
| 1172 | default: |
| 1173 | __d.clear(); |
| 1174 | break; |
| 1175 | } |
| 1176 | return __d; |
| 1177 | } |
| 1178 | |
| 1179 | // lookup_collatename is very FreeBSD-specific |
| 1180 | |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 | [diff] [blame] | 1181 | _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s); |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 1182 | |
| 1183 | template <class _CharT> |
| 1184 | template <class _ForwardIterator> |
| 1185 | typename regex_traits<_CharT>::string_type |
| 1186 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1187 | _ForwardIterator __l, char) const |
| 1188 | { |
| 1189 | string_type __s(__f, __l); |
| 1190 | string_type __r; |
| 1191 | if (!__s.empty()) |
| 1192 | { |
| 1193 | __r = __get_collation_name(__s.c_str()); |
| 1194 | if (__r.empty() && __s.size() <= 2) |
| 1195 | { |
| 1196 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1197 | if (__r.size() == 1 || __r.size() == 12) |
| 1198 | __r = __s; |
| 1199 | else |
| 1200 | __r.clear(); |
| 1201 | } |
| 1202 | } |
| 1203 | return __r; |
| 1204 | } |
| 1205 | |
| 1206 | template <class _CharT> |
| 1207 | template <class _ForwardIterator> |
| 1208 | typename regex_traits<_CharT>::string_type |
| 1209 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1210 | _ForwardIterator __l, wchar_t) const |
| 1211 | { |
| 1212 | string_type __s(__f, __l); |
| 1213 | string __n; |
| 1214 | __n.reserve(__s.size()); |
| 1215 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1216 | __i != __e; ++__i) |
| 1217 | { |
| 1218 | if (static_cast<unsigned>(*__i) >= 127) |
| 1219 | return string_type(); |
| 1220 | __n.push_back(char(*__i)); |
| 1221 | } |
| 1222 | string_type __r; |
| 1223 | if (!__s.empty()) |
| 1224 | { |
| 1225 | __n = __get_collation_name(__n.c_str()); |
| 1226 | if (!__n.empty()) |
| 1227 | __r.assign(__n.begin(), __n.end()); |
| 1228 | else if (__s.size() <= 2) |
| 1229 | { |
| 1230 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1231 | if (__r.size() == 1 || __r.size() == 3) |
| 1232 | __r = __s; |
| 1233 | else |
| 1234 | __r.clear(); |
| 1235 | } |
| 1236 | } |
| 1237 | return __r; |
| 1238 | } |
| 1239 | |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1240 | // lookup_classname |
| 1241 | |
Dan Albert | 15c010a | 2014-07-29 19:23:39 | [diff] [blame] | 1242 | regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS |
| 1243 | __get_classname(const char* __s, bool __icase); |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1244 | |
| 1245 | template <class _CharT> |
| 1246 | template <class _ForwardIterator> |
| 1247 | typename regex_traits<_CharT>::char_class_type |
| 1248 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1249 | _ForwardIterator __l, |
| 1250 | bool __icase, char) const |
| 1251 | { |
| 1252 | string_type __s(__f, __l); |
| 1253 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1254 | return __get_classname(__s.c_str(), __icase); |
| 1255 | } |
| 1256 | |
| 1257 | template <class _CharT> |
| 1258 | template <class _ForwardIterator> |
| 1259 | typename regex_traits<_CharT>::char_class_type |
| 1260 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1261 | _ForwardIterator __l, |
| 1262 | bool __icase, wchar_t) const |
| 1263 | { |
| 1264 | string_type __s(__f, __l); |
| 1265 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1266 | string __n; |
| 1267 | __n.reserve(__s.size()); |
| 1268 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1269 | __i != __e; ++__i) |
| 1270 | { |
| 1271 | if (static_cast<unsigned>(*__i) >= 127) |
| 1272 | return char_class_type(); |
| 1273 | __n.push_back(char(*__i)); |
| 1274 | } |
| 1275 | return __get_classname(__n.c_str(), __icase); |
| 1276 | } |
| 1277 | |
| 1278 | template <class _CharT> |
| 1279 | bool |
| 1280 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1281 | { |
| 1282 | if (__ct_->is(__m, __c)) |
| 1283 | return true; |
| 1284 | return (__c == '_' && (__m & __regex_word)); |
| 1285 | } |
| 1286 | |
| 1287 | template <class _CharT> |
| 1288 | int |
Marshall Clow | e604469 | 2013-10-21 15:43:25 | [diff] [blame] | 1289 | regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1290 | { |
| 1291 | if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7' |
| 1292 | return __ch - '0'; |
| 1293 | if (__radix != 8) |
| 1294 | { |
| 1295 | if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9' |
| 1296 | return __ch - '0'; |
| 1297 | if (__radix == 16) |
| 1298 | { |
| 1299 | __ch |= 0x20; // tolower |
| 1300 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 1301 | return __ch - ('a' - 10); |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1302 | } |
| 1303 | } |
| 1304 | return -1; |
| 1305 | } |
| 1306 | |
| 1307 | template <class _CharT> |
Evgeniy Stepanov | 906c872 | 2015-11-07 01:22:13 | [diff] [blame] | 1308 | inline |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1309 | int |
Marshall Clow | e604469 | 2013-10-21 15:43:25 | [diff] [blame] | 1310 | regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1311 | { |
Marshall Clow | e604469 | 2013-10-21 15:43:25 | [diff] [blame] | 1312 | return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); |
Howard Hinnant | 24757ff | 2010-06-21 21:01:43 | [diff] [blame] | 1313 | } |
| 1314 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1315 | template <class _CharT> class __node; |
| 1316 | |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 1317 | template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1318 | |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 1319 | template <class _BidirectionalIterator, |
| 1320 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 1321 | class _LIBCPP_TEMPLATE_VIS match_results; |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 1322 | |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1323 | template <class _CharT> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1324 | struct __state |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1325 | { |
| 1326 | enum |
| 1327 | { |
| 1328 | __end_state = -1000, |
| 1329 | __consume_input, // -999 |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1330 | __begin_marked_expr, // -998 |
| 1331 | __end_marked_expr, // -997 |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 1332 | __pop_state, // -996 |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1333 | __accept_and_consume, // -995 |
| 1334 | __accept_but_not_consume, // -994 |
| 1335 | __reject, // -993 |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1336 | __split, |
| 1337 | __repeat |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1338 | }; |
| 1339 | |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1340 | int __do_; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1341 | const _CharT* __first_; |
| 1342 | const _CharT* __current_; |
| 1343 | const _CharT* __last_; |
| 1344 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1345 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1346 | const __node<_CharT>* __node_; |
| 1347 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 1348 | bool __at_first_; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1349 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1350 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1351 | __state() |
| 1352 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1353 | __node_(nullptr), __flags_() {} |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1354 | }; |
| 1355 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1356 | // __node |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 1357 | |
| 1358 | template <class _CharT> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1359 | class __node |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 1360 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1361 | __node(const __node&); |
| 1362 | __node& operator=(const __node&); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 1363 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1364 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 1365 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1366 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1367 | __node() {} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1368 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1369 | virtual ~__node() {} |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 1370 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1371 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 0b485f3 | 2018-10-01 01:59:37 | [diff] [blame] | 1372 | virtual void __exec(__state&) const {} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1373 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 0b485f3 | 2018-10-01 01:59:37 | [diff] [blame] | 1374 | virtual void __exec_split(bool, __state&) const {} |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 1375 | }; |
| 1376 | |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1377 | // __end_state |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 1378 | |
| 1379 | template <class _CharT> |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1380 | class __end_state |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1381 | : public __node<_CharT> |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 1382 | { |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 1383 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1384 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 1385 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1386 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1387 | __end_state() {} |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 1388 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1389 | virtual void __exec(__state&) const; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 1390 | }; |
| 1391 | |
| 1392 | template <class _CharT> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1393 | void |
| 1394 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 1395 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1396 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 1397 | } |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1398 | |
| 1399 | // __has_one_state |
| 1400 | |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 1401 | template <class _CharT> |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1402 | class __has_one_state |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1403 | : public __node<_CharT> |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 1404 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1405 | __node<_CharT>* __first_; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1406 | |
| 1407 | public: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1408 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1409 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1410 | : __first_(__s) {} |
| 1411 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1412 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1413 | __node<_CharT>* first() const {return __first_;} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1414 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1415 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1416 | }; |
| 1417 | |
| 1418 | // __owns_one_state |
| 1419 | |
| 1420 | template <class _CharT> |
| 1421 | class __owns_one_state |
| 1422 | : public __has_one_state<_CharT> |
| 1423 | { |
| 1424 | typedef __has_one_state<_CharT> base; |
| 1425 | |
| 1426 | public: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1427 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1428 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1429 | : base(__s) {} |
| 1430 | |
| 1431 | virtual ~__owns_one_state(); |
| 1432 | }; |
| 1433 | |
| 1434 | template <class _CharT> |
| 1435 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1436 | { |
| 1437 | delete this->first(); |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 1438 | } |
| 1439 | |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1440 | // __empty_state |
| 1441 | |
| 1442 | template <class _CharT> |
| 1443 | class __empty_state |
| 1444 | : public __owns_one_state<_CharT> |
| 1445 | { |
| 1446 | typedef __owns_one_state<_CharT> base; |
| 1447 | |
| 1448 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1449 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1450 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1451 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1452 | explicit __empty_state(__node<_CharT>* __s) |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1453 | : base(__s) {} |
| 1454 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1455 | virtual void __exec(__state&) const; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1456 | }; |
| 1457 | |
| 1458 | template <class _CharT> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1459 | void |
| 1460 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1461 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1462 | __s.__do_ = __state::__accept_but_not_consume; |
| 1463 | __s.__node_ = this->first(); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | // __empty_non_own_state |
| 1467 | |
| 1468 | template <class _CharT> |
| 1469 | class __empty_non_own_state |
| 1470 | : public __has_one_state<_CharT> |
| 1471 | { |
| 1472 | typedef __has_one_state<_CharT> base; |
| 1473 | |
| 1474 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1475 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1476 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1477 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1478 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1479 | : base(__s) {} |
| 1480 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1481 | virtual void __exec(__state&) const; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1482 | }; |
| 1483 | |
| 1484 | template <class _CharT> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1485 | void |
| 1486 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1487 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1488 | __s.__do_ = __state::__accept_but_not_consume; |
| 1489 | __s.__node_ = this->first(); |
| 1490 | } |
| 1491 | |
| 1492 | // __repeat_one_loop |
| 1493 | |
| 1494 | template <class _CharT> |
| 1495 | class __repeat_one_loop |
| 1496 | : public __has_one_state<_CharT> |
| 1497 | { |
| 1498 | typedef __has_one_state<_CharT> base; |
| 1499 | |
| 1500 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1501 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1502 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1503 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1504 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1505 | : base(__s) {} |
| 1506 | |
| 1507 | virtual void __exec(__state&) const; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1508 | }; |
| 1509 | |
| 1510 | template <class _CharT> |
| 1511 | void |
| 1512 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1513 | { |
| 1514 | __s.__do_ = __state::__repeat; |
| 1515 | __s.__node_ = this->first(); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | // __owns_two_states |
| 1519 | |
| 1520 | template <class _CharT> |
| 1521 | class __owns_two_states |
| 1522 | : public __owns_one_state<_CharT> |
| 1523 | { |
| 1524 | typedef __owns_one_state<_CharT> base; |
| 1525 | |
| 1526 | base* __second_; |
| 1527 | |
| 1528 | public: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1529 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1530 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1531 | : base(__s1), __second_(__s2) {} |
| 1532 | |
| 1533 | virtual ~__owns_two_states(); |
| 1534 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1535 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1536 | base* second() const {return __second_;} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1537 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1538 | base*& second() {return __second_;} |
| 1539 | }; |
| 1540 | |
| 1541 | template <class _CharT> |
| 1542 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1543 | { |
| 1544 | delete __second_; |
| 1545 | } |
| 1546 | |
| 1547 | // __loop |
| 1548 | |
| 1549 | template <class _CharT> |
| 1550 | class __loop |
| 1551 | : public __owns_two_states<_CharT> |
| 1552 | { |
| 1553 | typedef __owns_two_states<_CharT> base; |
| 1554 | |
| 1555 | size_t __min_; |
| 1556 | size_t __max_; |
| 1557 | unsigned __loop_id_; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1558 | unsigned __mexp_begin_; |
| 1559 | unsigned __mexp_end_; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1560 | bool __greedy_; |
| 1561 | |
| 1562 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1563 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1564 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1565 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1566 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1567 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1568 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1569 | bool __greedy = true, |
| 1570 | size_t __min = 0, |
| 1571 | size_t __max = numeric_limits<size_t>::max()) |
| 1572 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1573 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1574 | __greedy_(__greedy) {} |
| 1575 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1576 | virtual void __exec(__state& __s) const; |
| 1577 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 1578 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1579 | private: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1580 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1581 | void __init_repeat(__state& __s) const |
| 1582 | { |
| 1583 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1584 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1585 | { |
| 1586 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1587 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1588 | __s.__sub_matches_[__i].matched = false; |
| 1589 | } |
| 1590 | } |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1591 | }; |
| 1592 | |
| 1593 | template <class _CharT> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1594 | void |
| 1595 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1596 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1597 | if (__s.__do_ == __state::__repeat) |
| 1598 | { |
| 1599 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1600 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1601 | if (__do_repeat && __do_alt && |
| 1602 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1603 | __do_repeat = false; |
| 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 | } |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1612 | else |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1613 | { |
| 1614 | __s.__do_ = __state::__accept_but_not_consume; |
| 1615 | __s.__node_ = this->second(); |
| 1616 | } |
| 1617 | } |
| 1618 | else |
| 1619 | { |
Howard Hinnant | 6afe8b0 | 2010-07-27 17:24:17 | [diff] [blame] | 1620 | __s.__loop_data_[__loop_id_].first = 0; |
| 1621 | bool __do_repeat = 0 < __max_; |
| 1622 | bool __do_alt = 0 >= __min_; |
| 1623 | if (__do_repeat && __do_alt) |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1624 | __s.__do_ = __state::__split; |
Howard Hinnant | 6afe8b0 | 2010-07-27 17:24:17 | [diff] [blame] | 1625 | else if (__do_repeat) |
| 1626 | { |
| 1627 | __s.__do_ = __state::__accept_but_not_consume; |
| 1628 | __s.__node_ = this->first(); |
| 1629 | __init_repeat(__s); |
| 1630 | } |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1631 | else |
| 1632 | { |
| 1633 | __s.__do_ = __state::__accept_but_not_consume; |
| 1634 | __s.__node_ = this->second(); |
| 1635 | } |
| 1636 | } |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1637 | } |
| 1638 | |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1639 | template <class _CharT> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1640 | void |
| 1641 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1642 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1643 | __s.__do_ = __state::__accept_but_not_consume; |
| 1644 | if (__greedy_ != __second) |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 1645 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1646 | __s.__node_ = this->first(); |
| 1647 | __init_repeat(__s); |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 1648 | } |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1649 | else |
| 1650 | __s.__node_ = this->second(); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1651 | } |
| 1652 | |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 1653 | // __alternate |
| 1654 | |
| 1655 | template <class _CharT> |
| 1656 | class __alternate |
| 1657 | : public __owns_two_states<_CharT> |
| 1658 | { |
| 1659 | typedef __owns_two_states<_CharT> base; |
| 1660 | |
| 1661 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1662 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 1663 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1664 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 1665 | explicit __alternate(__owns_one_state<_CharT>* __s1, |
| 1666 | __owns_one_state<_CharT>* __s2) |
| 1667 | : base(__s1, __s2) {} |
| 1668 | |
| 1669 | virtual void __exec(__state& __s) const; |
| 1670 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 1671 | }; |
| 1672 | |
| 1673 | template <class _CharT> |
| 1674 | void |
| 1675 | __alternate<_CharT>::__exec(__state& __s) const |
| 1676 | { |
| 1677 | __s.__do_ = __state::__split; |
| 1678 | } |
| 1679 | |
| 1680 | template <class _CharT> |
| 1681 | void |
| 1682 | __alternate<_CharT>::__exec_split(bool __second, __state& __s) const |
| 1683 | { |
| 1684 | __s.__do_ = __state::__accept_but_not_consume; |
Howard Hinnant | b762bea | 2010-07-22 14:12:20 | [diff] [blame] | 1685 | if (__second) |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 1686 | __s.__node_ = this->second(); |
Howard Hinnant | b762bea | 2010-07-22 14:12:20 | [diff] [blame] | 1687 | else |
| 1688 | __s.__node_ = this->first(); |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 1689 | } |
| 1690 | |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1691 | // __begin_marked_subexpression |
| 1692 | |
| 1693 | template <class _CharT> |
| 1694 | class __begin_marked_subexpression |
| 1695 | : public __owns_one_state<_CharT> |
| 1696 | { |
| 1697 | typedef __owns_one_state<_CharT> base; |
| 1698 | |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 1699 | unsigned __mexp_; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1700 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1701 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1702 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1703 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1704 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 1705 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1706 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1707 | virtual void __exec(__state&) const; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1708 | }; |
| 1709 | |
| 1710 | template <class _CharT> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1711 | void |
| 1712 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1713 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1714 | __s.__do_ = __state::__accept_but_not_consume; |
| 1715 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1716 | __s.__node_ = this->first(); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | // __end_marked_subexpression |
| 1720 | |
| 1721 | template <class _CharT> |
| 1722 | class __end_marked_subexpression |
| 1723 | : public __owns_one_state<_CharT> |
| 1724 | { |
| 1725 | typedef __owns_one_state<_CharT> base; |
| 1726 | |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 1727 | unsigned __mexp_; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1728 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1729 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1730 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1731 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1732 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 1733 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1734 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1735 | virtual void __exec(__state&) const; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1736 | }; |
| 1737 | |
| 1738 | template <class _CharT> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1739 | void |
| 1740 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1741 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 1742 | __s.__do_ = __state::__accept_but_not_consume; |
| 1743 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1744 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1745 | __s.__node_ = this->first(); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 1746 | } |
| 1747 | |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 1748 | // __back_ref |
| 1749 | |
| 1750 | template <class _CharT> |
| 1751 | class __back_ref |
| 1752 | : public __owns_one_state<_CharT> |
| 1753 | { |
| 1754 | typedef __owns_one_state<_CharT> base; |
| 1755 | |
| 1756 | unsigned __mexp_; |
| 1757 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1758 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 1759 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1760 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 1761 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1762 | : base(__s), __mexp_(__mexp) {} |
| 1763 | |
| 1764 | virtual void __exec(__state&) const; |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 1765 | }; |
| 1766 | |
| 1767 | template <class _CharT> |
| 1768 | void |
| 1769 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1770 | { |
Marshall Clow | 550dfe7 | 2015-08-24 15:57:09 | [diff] [blame] | 1771 | if (__mexp_ > __s.__sub_matches_.size()) |
| 1772 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 1773 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1774 | if (__sm.matched) |
| 1775 | { |
| 1776 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1777 | if (__s.__last_ - __s.__current_ >= __len && |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1778 | _VSTD::equal(__sm.first, __sm.second, __s.__current_)) |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 1779 | { |
| 1780 | __s.__do_ = __state::__accept_but_not_consume; |
| 1781 | __s.__current_ += __len; |
| 1782 | __s.__node_ = this->first(); |
| 1783 | } |
| 1784 | else |
| 1785 | { |
| 1786 | __s.__do_ = __state::__reject; |
| 1787 | __s.__node_ = nullptr; |
| 1788 | } |
| 1789 | } |
| 1790 | else |
| 1791 | { |
| 1792 | __s.__do_ = __state::__reject; |
| 1793 | __s.__node_ = nullptr; |
| 1794 | } |
| 1795 | } |
| 1796 | |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 1797 | // __back_ref_icase |
| 1798 | |
| 1799 | template <class _CharT, class _Traits> |
| 1800 | class __back_ref_icase |
| 1801 | : public __owns_one_state<_CharT> |
| 1802 | { |
| 1803 | typedef __owns_one_state<_CharT> base; |
| 1804 | |
| 1805 | _Traits __traits_; |
| 1806 | unsigned __mexp_; |
| 1807 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1808 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 1809 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1810 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 1811 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1812 | __node<_CharT>* __s) |
| 1813 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1814 | |
| 1815 | virtual void __exec(__state&) const; |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 1816 | }; |
| 1817 | |
| 1818 | template <class _CharT, class _Traits> |
| 1819 | void |
| 1820 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1821 | { |
| 1822 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1823 | if (__sm.matched) |
| 1824 | { |
| 1825 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1826 | if (__s.__last_ - __s.__current_ >= __len) |
| 1827 | { |
| 1828 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1829 | { |
| 1830 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1831 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1832 | goto __not_equal; |
| 1833 | } |
| 1834 | __s.__do_ = __state::__accept_but_not_consume; |
| 1835 | __s.__current_ += __len; |
| 1836 | __s.__node_ = this->first(); |
| 1837 | } |
| 1838 | else |
| 1839 | { |
| 1840 | __s.__do_ = __state::__reject; |
| 1841 | __s.__node_ = nullptr; |
| 1842 | } |
| 1843 | } |
| 1844 | else |
| 1845 | { |
| 1846 | __not_equal: |
| 1847 | __s.__do_ = __state::__reject; |
| 1848 | __s.__node_ = nullptr; |
| 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | // __back_ref_collate |
| 1853 | |
| 1854 | template <class _CharT, class _Traits> |
| 1855 | class __back_ref_collate |
| 1856 | : public __owns_one_state<_CharT> |
| 1857 | { |
| 1858 | typedef __owns_one_state<_CharT> base; |
| 1859 | |
| 1860 | _Traits __traits_; |
| 1861 | unsigned __mexp_; |
| 1862 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1863 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 1864 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1865 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 1866 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1867 | __node<_CharT>* __s) |
| 1868 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1869 | |
| 1870 | virtual void __exec(__state&) const; |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 1871 | }; |
| 1872 | |
| 1873 | template <class _CharT, class _Traits> |
| 1874 | void |
| 1875 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1876 | { |
| 1877 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1878 | if (__sm.matched) |
| 1879 | { |
| 1880 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1881 | if (__s.__last_ - __s.__current_ >= __len) |
| 1882 | { |
| 1883 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1884 | { |
| 1885 | if (__traits_.translate(__sm.first[__i]) != |
| 1886 | __traits_.translate(__s.__current_[__i])) |
| 1887 | goto __not_equal; |
| 1888 | } |
| 1889 | __s.__do_ = __state::__accept_but_not_consume; |
| 1890 | __s.__current_ += __len; |
| 1891 | __s.__node_ = this->first(); |
| 1892 | } |
| 1893 | else |
| 1894 | { |
| 1895 | __s.__do_ = __state::__reject; |
| 1896 | __s.__node_ = nullptr; |
| 1897 | } |
| 1898 | } |
| 1899 | else |
| 1900 | { |
| 1901 | __not_equal: |
| 1902 | __s.__do_ = __state::__reject; |
| 1903 | __s.__node_ = nullptr; |
| 1904 | } |
| 1905 | } |
| 1906 | |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 1907 | // __word_boundary |
| 1908 | |
| 1909 | template <class _CharT, class _Traits> |
| 1910 | class __word_boundary |
| 1911 | : public __owns_one_state<_CharT> |
| 1912 | { |
| 1913 | typedef __owns_one_state<_CharT> base; |
| 1914 | |
| 1915 | _Traits __traits_; |
| 1916 | bool __invert_; |
| 1917 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1918 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 1919 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 1920 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 1921 | explicit __word_boundary(const _Traits& __traits, bool __invert, |
| 1922 | __node<_CharT>* __s) |
| 1923 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 1924 | |
| 1925 | virtual void __exec(__state&) const; |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 1926 | }; |
| 1927 | |
| 1928 | template <class _CharT, class _Traits> |
| 1929 | void |
| 1930 | __word_boundary<_CharT, _Traits>::__exec(__state& __s) const |
| 1931 | { |
| 1932 | bool __is_word_b = false; |
| 1933 | if (__s.__first_ != __s.__last_) |
| 1934 | { |
| 1935 | if (__s.__current_ == __s.__last_) |
| 1936 | { |
| 1937 | if (!(__s.__flags_ & regex_constants::match_not_eow)) |
| 1938 | { |
| 1939 | _CharT __c = __s.__current_[-1]; |
| 1940 | __is_word_b = __c == '_' || |
| 1941 | __traits_.isctype(__c, ctype_base::alnum); |
| 1942 | } |
| 1943 | } |
Howard Hinnant | 7189782 | 2010-07-29 15:17:28 | [diff] [blame] | 1944 | else if (__s.__current_ == __s.__first_ && |
| 1945 | !(__s.__flags_ & regex_constants::match_prev_avail)) |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 1946 | { |
| 1947 | if (!(__s.__flags_ & regex_constants::match_not_bow)) |
| 1948 | { |
| 1949 | _CharT __c = *__s.__current_; |
| 1950 | __is_word_b = __c == '_' || |
| 1951 | __traits_.isctype(__c, ctype_base::alnum); |
| 1952 | } |
| 1953 | } |
| 1954 | else |
| 1955 | { |
| 1956 | _CharT __c1 = __s.__current_[-1]; |
| 1957 | _CharT __c2 = *__s.__current_; |
| 1958 | bool __is_c1_b = __c1 == '_' || |
| 1959 | __traits_.isctype(__c1, ctype_base::alnum); |
| 1960 | bool __is_c2_b = __c2 == '_' || |
| 1961 | __traits_.isctype(__c2, ctype_base::alnum); |
| 1962 | __is_word_b = __is_c1_b != __is_c2_b; |
| 1963 | } |
| 1964 | } |
| 1965 | if (__is_word_b != __invert_) |
| 1966 | { |
| 1967 | __s.__do_ = __state::__accept_but_not_consume; |
| 1968 | __s.__node_ = this->first(); |
| 1969 | } |
| 1970 | else |
| 1971 | { |
| 1972 | __s.__do_ = __state::__reject; |
| 1973 | __s.__node_ = nullptr; |
| 1974 | } |
| 1975 | } |
| 1976 | |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 1977 | // __l_anchor |
| 1978 | |
| 1979 | template <class _CharT> |
| 1980 | class __l_anchor |
| 1981 | : public __owns_one_state<_CharT> |
| 1982 | { |
| 1983 | typedef __owns_one_state<_CharT> base; |
| 1984 | |
| 1985 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 1986 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 1987 | |
| 1988 | _LIBCPP_INLINE_VISIBILITY |
| 1989 | __l_anchor(__node<_CharT>* __s) |
| 1990 | : base(__s) {} |
| 1991 | |
| 1992 | virtual void __exec(__state&) const; |
| 1993 | }; |
| 1994 | |
| 1995 | template <class _CharT> |
| 1996 | void |
| 1997 | __l_anchor<_CharT>::__exec(__state& __s) const |
| 1998 | { |
Marshall Clow | 8fa8e5f | 2015-03-19 17:05:59 | [diff] [blame] | 1999 | if (__s.__at_first_ && __s.__current_ == __s.__first_ && |
| 2000 | !(__s.__flags_ & regex_constants::match_not_bol)) |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2001 | { |
| 2002 | __s.__do_ = __state::__accept_but_not_consume; |
| 2003 | __s.__node_ = this->first(); |
| 2004 | } |
| 2005 | else |
| 2006 | { |
| 2007 | __s.__do_ = __state::__reject; |
| 2008 | __s.__node_ = nullptr; |
| 2009 | } |
| 2010 | } |
| 2011 | |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 2012 | // __r_anchor |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2013 | |
| 2014 | template <class _CharT> |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 2015 | class __r_anchor |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2016 | : public __owns_one_state<_CharT> |
| 2017 | { |
| 2018 | typedef __owns_one_state<_CharT> base; |
| 2019 | |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2020 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2021 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2022 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2023 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2024 | __r_anchor(__node<_CharT>* __s) |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 2025 | : base(__s) {} |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2026 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2027 | virtual void __exec(__state&) const; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2028 | }; |
| 2029 | |
| 2030 | template <class _CharT> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2031 | void |
| 2032 | __r_anchor<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2033 | { |
Marshall Clow | 8fa8e5f | 2015-03-19 17:05:59 | [diff] [blame] | 2034 | if (__s.__current_ == __s.__last_ && |
| 2035 | !(__s.__flags_ & regex_constants::match_not_eol)) |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2036 | { |
| 2037 | __s.__do_ = __state::__accept_but_not_consume; |
| 2038 | __s.__node_ = this->first(); |
| 2039 | } |
| 2040 | else |
| 2041 | { |
| 2042 | __s.__do_ = __state::__reject; |
| 2043 | __s.__node_ = nullptr; |
| 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | // __match_any |
| 2048 | |
| 2049 | template <class _CharT> |
| 2050 | class __match_any |
| 2051 | : public __owns_one_state<_CharT> |
| 2052 | { |
| 2053 | typedef __owns_one_state<_CharT> base; |
| 2054 | |
| 2055 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2056 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2057 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2058 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2059 | __match_any(__node<_CharT>* __s) |
| 2060 | : base(__s) {} |
| 2061 | |
| 2062 | virtual void __exec(__state&) const; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2063 | }; |
| 2064 | |
| 2065 | template <class _CharT> |
| 2066 | void |
| 2067 | __match_any<_CharT>::__exec(__state& __s) const |
| 2068 | { |
| 2069 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 2070 | { |
| 2071 | __s.__do_ = __state::__accept_and_consume; |
| 2072 | ++__s.__current_; |
| 2073 | __s.__node_ = this->first(); |
| 2074 | } |
| 2075 | else |
| 2076 | { |
| 2077 | __s.__do_ = __state::__reject; |
| 2078 | __s.__node_ = nullptr; |
| 2079 | } |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2080 | } |
| 2081 | |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 2082 | // __match_any_but_newline |
| 2083 | |
| 2084 | template <class _CharT> |
| 2085 | class __match_any_but_newline |
| 2086 | : public __owns_one_state<_CharT> |
| 2087 | { |
| 2088 | typedef __owns_one_state<_CharT> base; |
| 2089 | |
| 2090 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2091 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 2092 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2093 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 2094 | __match_any_but_newline(__node<_CharT>* __s) |
| 2095 | : base(__s) {} |
| 2096 | |
| 2097 | virtual void __exec(__state&) const; |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 2098 | }; |
| 2099 | |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 | [diff] [blame] | 2100 | template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const; |
| 2101 | template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const; |
| 2102 | |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2103 | // __match_char |
| 2104 | |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 2105 | template <class _CharT> |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 2106 | class __match_char |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2107 | : public __owns_one_state<_CharT> |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 2108 | { |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2109 | typedef __owns_one_state<_CharT> base; |
| 2110 | |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 2111 | _CharT __c_; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2112 | |
| 2113 | __match_char(const __match_char&); |
| 2114 | __match_char& operator=(const __match_char&); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 2115 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2116 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 2117 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2118 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2119 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2120 | : base(__s), __c_(__c) {} |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 2121 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2122 | virtual void __exec(__state&) const; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 2123 | }; |
| 2124 | |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 2125 | template <class _CharT> |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2126 | void |
| 2127 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 2128 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2129 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2130 | { |
| 2131 | __s.__do_ = __state::__accept_and_consume; |
| 2132 | ++__s.__current_; |
| 2133 | __s.__node_ = this->first(); |
| 2134 | } |
| 2135 | else |
| 2136 | { |
| 2137 | __s.__do_ = __state::__reject; |
| 2138 | __s.__node_ = nullptr; |
| 2139 | } |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 2140 | } |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 2141 | |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 2142 | // __match_char_icase |
| 2143 | |
| 2144 | template <class _CharT, class _Traits> |
| 2145 | class __match_char_icase |
| 2146 | : public __owns_one_state<_CharT> |
| 2147 | { |
| 2148 | typedef __owns_one_state<_CharT> base; |
| 2149 | |
| 2150 | _Traits __traits_; |
| 2151 | _CharT __c_; |
| 2152 | |
| 2153 | __match_char_icase(const __match_char_icase&); |
| 2154 | __match_char_icase& operator=(const __match_char_icase&); |
| 2155 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2156 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 2157 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2158 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 2159 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2160 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2161 | |
| 2162 | virtual void __exec(__state&) const; |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 2163 | }; |
| 2164 | |
| 2165 | template <class _CharT, class _Traits> |
| 2166 | void |
| 2167 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2168 | { |
| 2169 | if (__s.__current_ != __s.__last_ && |
| 2170 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2171 | { |
| 2172 | __s.__do_ = __state::__accept_and_consume; |
| 2173 | ++__s.__current_; |
| 2174 | __s.__node_ = this->first(); |
| 2175 | } |
| 2176 | else |
| 2177 | { |
| 2178 | __s.__do_ = __state::__reject; |
| 2179 | __s.__node_ = nullptr; |
| 2180 | } |
| 2181 | } |
| 2182 | |
| 2183 | // __match_char_collate |
| 2184 | |
| 2185 | template <class _CharT, class _Traits> |
| 2186 | class __match_char_collate |
| 2187 | : public __owns_one_state<_CharT> |
| 2188 | { |
| 2189 | typedef __owns_one_state<_CharT> base; |
| 2190 | |
| 2191 | _Traits __traits_; |
| 2192 | _CharT __c_; |
| 2193 | |
| 2194 | __match_char_collate(const __match_char_collate&); |
| 2195 | __match_char_collate& operator=(const __match_char_collate&); |
| 2196 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2197 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 2198 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2199 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 2200 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2201 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2202 | |
| 2203 | virtual void __exec(__state&) const; |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 2204 | }; |
| 2205 | |
| 2206 | template <class _CharT, class _Traits> |
| 2207 | void |
| 2208 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2209 | { |
| 2210 | if (__s.__current_ != __s.__last_ && |
| 2211 | __traits_.translate(*__s.__current_) == __c_) |
| 2212 | { |
| 2213 | __s.__do_ = __state::__accept_and_consume; |
| 2214 | ++__s.__current_; |
| 2215 | __s.__node_ = this->first(); |
| 2216 | } |
| 2217 | else |
| 2218 | { |
| 2219 | __s.__do_ = __state::__reject; |
| 2220 | __s.__node_ = nullptr; |
| 2221 | } |
| 2222 | } |
| 2223 | |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2224 | // __bracket_expression |
| 2225 | |
| 2226 | template <class _CharT, class _Traits> |
| 2227 | class __bracket_expression |
| 2228 | : public __owns_one_state<_CharT> |
| 2229 | { |
| 2230 | typedef __owns_one_state<_CharT> base; |
| 2231 | typedef typename _Traits::string_type string_type; |
| 2232 | |
| 2233 | _Traits __traits_; |
| 2234 | vector<_CharT> __chars_; |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2235 | vector<_CharT> __neg_chars_; |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2236 | vector<pair<string_type, string_type> > __ranges_; |
| 2237 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2238 | vector<string_type> __equivalences_; |
Dan Albert | 15c010a | 2014-07-29 19:23:39 | [diff] [blame] | 2239 | typename regex_traits<_CharT>::char_class_type __mask_; |
| 2240 | typename regex_traits<_CharT>::char_class_type __neg_mask_; |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2241 | bool __negate_; |
| 2242 | bool __icase_; |
| 2243 | bool __collate_; |
Howard Hinnant | 5699358 | 2010-07-14 15:45:11 | [diff] [blame] | 2244 | bool __might_have_digraph_; |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2245 | |
| 2246 | __bracket_expression(const __bracket_expression&); |
| 2247 | __bracket_expression& operator=(const __bracket_expression&); |
| 2248 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2249 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2250 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2251 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2252 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2253 | bool __negate, bool __icase, bool __collate) |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2254 | : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), |
| 2255 | __negate_(__negate), __icase_(__icase), __collate_(__collate), |
Howard Hinnant | 5699358 | 2010-07-14 15:45:11 | [diff] [blame] | 2256 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2257 | |
| 2258 | virtual void __exec(__state&) const; |
| 2259 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2260 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2261 | bool __negated() const {return __negate_;} |
| 2262 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2263 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2264 | void __add_char(_CharT __c) |
| 2265 | { |
| 2266 | if (__icase_) |
| 2267 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2268 | else if (__collate_) |
| 2269 | __chars_.push_back(__traits_.translate(__c)); |
| 2270 | else |
| 2271 | __chars_.push_back(__c); |
| 2272 | } |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2273 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2274 | void __add_neg_char(_CharT __c) |
| 2275 | { |
| 2276 | if (__icase_) |
| 2277 | __neg_chars_.push_back(__traits_.translate_nocase(__c)); |
| 2278 | else if (__collate_) |
| 2279 | __neg_chars_.push_back(__traits_.translate(__c)); |
| 2280 | else |
| 2281 | __neg_chars_.push_back(__c); |
| 2282 | } |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2283 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2284 | void __add_range(string_type __b, string_type __e) |
| 2285 | { |
| 2286 | if (__collate_) |
| 2287 | { |
| 2288 | if (__icase_) |
| 2289 | { |
| 2290 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2291 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2292 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2293 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2294 | } |
| 2295 | else |
| 2296 | { |
| 2297 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2298 | __b[__i] = __traits_.translate(__b[__i]); |
| 2299 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2300 | __e[__i] = __traits_.translate(__e[__i]); |
| 2301 | } |
| 2302 | __ranges_.push_back(make_pair( |
| 2303 | __traits_.transform(__b.begin(), __b.end()), |
| 2304 | __traits_.transform(__e.begin(), __e.end()))); |
| 2305 | } |
| 2306 | else |
| 2307 | { |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2308 | if (__b.size() != 1 || __e.size() != 1) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 2309 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2310 | if (__icase_) |
| 2311 | { |
| 2312 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2313 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2314 | } |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2315 | __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e))); |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2316 | } |
| 2317 | } |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2318 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2319 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2320 | { |
| 2321 | if (__icase_) |
| 2322 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2323 | __traits_.translate_nocase(__c2))); |
| 2324 | else if (__collate_) |
| 2325 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2326 | __traits_.translate(__c2))); |
| 2327 | else |
| 2328 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2329 | } |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2330 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2331 | void __add_equivalence(const string_type& __s) |
| 2332 | {__equivalences_.push_back(__s);} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2333 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 15c010a | 2014-07-29 19:23:39 | [diff] [blame] | 2334 | void __add_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2335 | {__mask_ |= __mask;} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2336 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 15c010a | 2014-07-29 19:23:39 | [diff] [blame] | 2337 | void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2338 | {__neg_mask_ |= __mask;} |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2339 | }; |
| 2340 | |
| 2341 | template <class _CharT, class _Traits> |
| 2342 | void |
| 2343 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2344 | { |
| 2345 | bool __found = false; |
| 2346 | unsigned __consumed = 0; |
| 2347 | if (__s.__current_ != __s.__last_) |
| 2348 | { |
| 2349 | ++__consumed; |
Howard Hinnant | 5699358 | 2010-07-14 15:45:11 | [diff] [blame] | 2350 | if (__might_have_digraph_) |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2351 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2352 | const _CharT* __next = _VSTD::next(__s.__current_); |
Howard Hinnant | 5699358 | 2010-07-14 15:45:11 | [diff] [blame] | 2353 | if (__next != __s.__last_) |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2354 | { |
Howard Hinnant | 5699358 | 2010-07-14 15:45:11 | [diff] [blame] | 2355 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2356 | if (__icase_) |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2357 | { |
Howard Hinnant | 5699358 | 2010-07-14 15:45:11 | [diff] [blame] | 2358 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2359 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2360 | } |
| 2361 | else if (__collate_) |
| 2362 | { |
| 2363 | __ch2.first = __traits_.translate(__ch2.first); |
| 2364 | __ch2.second = __traits_.translate(__ch2.second); |
| 2365 | } |
| 2366 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2367 | { |
| 2368 | // __ch2 is a digraph in this locale |
| 2369 | ++__consumed; |
| 2370 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2371 | { |
| 2372 | if (__ch2 == __digraphs_[__i]) |
| 2373 | { |
| 2374 | __found = true; |
| 2375 | goto __exit; |
| 2376 | } |
| 2377 | } |
| 2378 | if (__collate_ && !__ranges_.empty()) |
| 2379 | { |
| 2380 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2381 | &__ch2.first + 2); |
| 2382 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2383 | { |
| 2384 | if (__ranges_[__i].first <= __s2 && |
| 2385 | __s2 <= __ranges_[__i].second) |
| 2386 | { |
| 2387 | __found = true; |
| 2388 | goto __exit; |
| 2389 | } |
| 2390 | } |
| 2391 | } |
| 2392 | if (!__equivalences_.empty()) |
| 2393 | { |
| 2394 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2395 | &__ch2.first + 2); |
| 2396 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2397 | { |
| 2398 | if (__s2 == __equivalences_[__i]) |
| 2399 | { |
| 2400 | __found = true; |
| 2401 | goto __exit; |
| 2402 | } |
| 2403 | } |
| 2404 | } |
| 2405 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2406 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2407 | { |
| 2408 | __found = true; |
| 2409 | goto __exit; |
| 2410 | } |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2411 | if (!__traits_.isctype(__ch2.first, __neg_mask_) && |
| 2412 | !__traits_.isctype(__ch2.second, __neg_mask_)) |
| 2413 | { |
| 2414 | __found = true; |
| 2415 | goto __exit; |
| 2416 | } |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2417 | goto __exit; |
| 2418 | } |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2419 | } |
| 2420 | } |
| 2421 | // test *__s.__current_ as not a digraph |
| 2422 | _CharT __ch = *__s.__current_; |
| 2423 | if (__icase_) |
| 2424 | __ch = __traits_.translate_nocase(__ch); |
| 2425 | else if (__collate_) |
| 2426 | __ch = __traits_.translate(__ch); |
| 2427 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2428 | { |
| 2429 | if (__ch == __chars_[__i]) |
| 2430 | { |
| 2431 | __found = true; |
| 2432 | goto __exit; |
| 2433 | } |
| 2434 | } |
Louis Dionne | 954d4a2 | 2018-08-24 14:10:28 | [diff] [blame] | 2435 | // When there's at least one of __neg_chars_ and __neg_mask_, the set |
| 2436 | // of "__found" chars is |
Marshall Clow | 77623cb | 2017-10-18 16:49:22 | [diff] [blame] | 2437 | // union(complement(union(__neg_chars_, __neg_mask_)), |
| 2438 | // other cases...) |
| 2439 | // |
Louis Dionne | 954d4a2 | 2018-08-24 14:10:28 | [diff] [blame] | 2440 | // It doesn't make sense to check this when there are no __neg_chars_ |
| 2441 | // and no __neg_mask_. |
| 2442 | if (!(__neg_mask_ == 0 && __neg_chars_.empty())) |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2443 | { |
Louis Dionne | 954d4a2 | 2018-08-24 14:10:28 | [diff] [blame] | 2444 | const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_); |
Marshall Clow | 77623cb | 2017-10-18 16:49:22 | [diff] [blame] | 2445 | const bool __in_neg_chars = |
Marshall Clow | 77623cb | 2017-10-18 16:49:22 | [diff] [blame] | 2446 | std::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != |
| 2447 | __neg_chars_.end(); |
| 2448 | if (!(__in_neg_mask || __in_neg_chars)) |
| 2449 | { |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2450 | __found = true; |
| 2451 | goto __exit; |
Marshall Clow | 77623cb | 2017-10-18 16:49:22 | [diff] [blame] | 2452 | } |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2453 | } |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2454 | if (!__ranges_.empty()) |
| 2455 | { |
| 2456 | string_type __s2 = __collate_ ? |
| 2457 | __traits_.transform(&__ch, &__ch + 1) : |
| 2458 | string_type(1, __ch); |
| 2459 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2460 | { |
| 2461 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2462 | { |
| 2463 | __found = true; |
| 2464 | goto __exit; |
| 2465 | } |
| 2466 | } |
| 2467 | } |
| 2468 | if (!__equivalences_.empty()) |
| 2469 | { |
| 2470 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2471 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2472 | { |
| 2473 | if (__s2 == __equivalences_[__i]) |
| 2474 | { |
| 2475 | __found = true; |
| 2476 | goto __exit; |
| 2477 | } |
| 2478 | } |
| 2479 | } |
| 2480 | if (__traits_.isctype(__ch, __mask_)) |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2481 | { |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2482 | __found = true; |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2483 | goto __exit; |
| 2484 | } |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2485 | } |
| 2486 | else |
| 2487 | __found = __negate_; // force reject |
| 2488 | __exit: |
| 2489 | if (__found != __negate_) |
| 2490 | { |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2491 | __s.__do_ = __state::__accept_and_consume; |
| 2492 | __s.__current_ += __consumed; |
| 2493 | __s.__node_ = this->first(); |
| 2494 | } |
| 2495 | else |
| 2496 | { |
| 2497 | __s.__do_ = __state::__reject; |
| 2498 | __s.__node_ = nullptr; |
| 2499 | } |
| 2500 | } |
| 2501 | |
Howard Hinnant | ce53420 | 2011-06-14 19:58:17 | [diff] [blame] | 2502 | template <class _CharT, class _Traits> class __lookahead; |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 2503 | |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2504 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 2505 | class _LIBCPP_TEMPLATE_VIS basic_regex |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2506 | { |
| 2507 | public: |
| 2508 | // types: |
| 2509 | typedef _CharT value_type; |
Hubert Tong | ac98d59 | 2016-08-02 21:34:48 | [diff] [blame] | 2510 | typedef _Traits traits_type; |
| 2511 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2512 | typedef regex_constants::syntax_option_type flag_type; |
| 2513 | typedef typename _Traits::locale_type locale_type; |
| 2514 | |
| 2515 | private: |
| 2516 | _Traits __traits_; |
| 2517 | flag_type __flags_; |
| 2518 | unsigned __marked_count_; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2519 | unsigned __loop_count_; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 2520 | int __open_count_; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2521 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2522 | __owns_one_state<_CharT>* __end_; |
| 2523 | |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2524 | typedef _VSTD::__state<_CharT> __state; |
| 2525 | typedef _VSTD::__node<_CharT> __node; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2526 | |
| 2527 | public: |
| 2528 | // constants: |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 2529 | static const regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2530 | static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2531 | static const regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2532 | static const regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2533 | static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2534 | static const regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2535 | static const regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2536 | static const regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2537 | static const regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2538 | static const regex_constants::syntax_option_type egrep = regex_constants::egrep; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2539 | |
| 2540 | // construct/copy/destroy: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2541 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2542 | basic_regex() |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 2543 | : __flags_(regex_constants::ECMAScript), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2544 | __end_(0) |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2545 | {} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2546 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2547 | explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 2548 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2549 | __end_(0) |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 2550 | { |
| 2551 | if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; |
| 2552 | __parse(__p, __p + __traits_.length(__p)); |
| 2553 | } |
| 2554 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2555 | _LIBCPP_INLINE_VISIBILITY |
Hubert Tong | 2fdf202 | 2016-08-07 22:26:04 | [diff] [blame] | 2556 | basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 2557 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2558 | __end_(0) |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 2559 | { |
| 2560 | if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; |
| 2561 | __parse(__p, __p + __len); |
| 2562 | } |
| 2563 | |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 2564 | // basic_regex(const basic_regex&) = default; |
| 2565 | // basic_regex(basic_regex&&) = default; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2566 | template <class _ST, class _SA> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2567 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2568 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2569 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 2570 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2571 | __end_(0) |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 2572 | { |
| 2573 | if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; |
| 2574 | __parse(__p.begin(), __p.end()); |
| 2575 | } |
| 2576 | |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2577 | template <class _ForwardIterator> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2578 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2579 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 2580 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 2581 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2582 | __end_(0) |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 2583 | { |
| 2584 | if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; |
| 2585 | __parse(__first, __last); |
| 2586 | } |
Eric Fiselier | 9f7cc58 | 2017-04-18 23:42:15 | [diff] [blame] | 2587 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2588 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2589 | basic_regex(initializer_list<value_type> __il, |
| 2590 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 2591 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2592 | __end_(0) |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 2593 | { |
| 2594 | if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; |
| 2595 | __parse(__il.begin(), __il.end()); |
| 2596 | } |
Eric Fiselier | 9f7cc58 | 2017-04-18 23:42:15 | [diff] [blame] | 2597 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2598 | |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2599 | // ~basic_regex() = default; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2600 | |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 2601 | // basic_regex& operator=(const basic_regex&) = default; |
| 2602 | // basic_regex& operator=(basic_regex&&) = default; |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2603 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2604 | basic_regex& operator=(const value_type* __p) |
| 2605 | {return assign(__p);} |
Eric Fiselier | 9f7cc58 | 2017-04-18 23:42:15 | [diff] [blame] | 2606 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2607 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2608 | basic_regex& operator=(initializer_list<value_type> __il) |
| 2609 | {return assign(__il);} |
Eric Fiselier | 9f7cc58 | 2017-04-18 23:42:15 | [diff] [blame] | 2610 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2611 | template <class _ST, class _SA> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2612 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2613 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) |
| 2614 | {return assign(__p);} |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2615 | |
| 2616 | // assign: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2617 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2618 | basic_regex& assign(const basic_regex& __that) |
| 2619 | {return *this = __that;} |
Eric Fiselier | 9f7cc58 | 2017-04-18 23:42:15 | [diff] [blame] | 2620 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 2621 | _LIBCPP_INLINE_VISIBILITY |
| 2622 | basic_regex& assign(basic_regex&& __that) _NOEXCEPT |
| 2623 | {return *this = _VSTD::move(__that);} |
| 2624 | #endif |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2625 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2626 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
| 2627 | {return assign(__p, __p + __traits_.length(__p), __f);} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2628 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2629 | basic_regex& assign(const value_type* __p, size_t __len, flag_type __f) |
| 2630 | {return assign(__p, __p + __len, __f);} |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2631 | template <class _ST, class _SA> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2632 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2633 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2634 | flag_type __f = regex_constants::ECMAScript) |
| 2635 | {return assign(__s.begin(), __s.end(), __f);} |
| 2636 | |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2637 | template <class _InputIterator> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2638 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2639 | typename enable_if |
| 2640 | < |
| 2641 | __is_input_iterator <_InputIterator>::value && |
| 2642 | !__is_forward_iterator<_InputIterator>::value, |
| 2643 | basic_regex& |
| 2644 | >::type |
| 2645 | assign(_InputIterator __first, _InputIterator __last, |
| 2646 | flag_type __f = regex_constants::ECMAScript) |
| 2647 | { |
| 2648 | basic_string<_CharT> __t(__first, __last); |
| 2649 | return assign(__t.begin(), __t.end(), __f); |
| 2650 | } |
| 2651 | |
| 2652 | private: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2653 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2654 | void __member_init(flag_type __f) |
| 2655 | { |
| 2656 | __flags_ = __f; |
| 2657 | __marked_count_ = 0; |
| 2658 | __loop_count_ = 0; |
| 2659 | __open_count_ = 0; |
| 2660 | __end_ = nullptr; |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2661 | } |
| 2662 | public: |
| 2663 | |
| 2664 | template <class _ForwardIterator> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2665 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2666 | typename enable_if |
| 2667 | < |
| 2668 | __is_forward_iterator<_ForwardIterator>::value, |
| 2669 | basic_regex& |
| 2670 | >::type |
| 2671 | assign(_ForwardIterator __first, _ForwardIterator __last, |
| 2672 | flag_type __f = regex_constants::ECMAScript) |
| 2673 | { |
Marshall Clow | 9db9069 | 2015-01-13 16:49:52 | [diff] [blame] | 2674 | return assign(basic_regex(__first, __last, __f)); |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2675 | } |
| 2676 | |
Eric Fiselier | 9f7cc58 | 2017-04-18 23:42:15 | [diff] [blame] | 2677 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 | [diff] [blame] | 2678 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2679 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2680 | basic_regex& assign(initializer_list<value_type> __il, |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2681 | flag_type __f = regex_constants::ECMAScript) |
| 2682 | {return assign(__il.begin(), __il.end(), __f);} |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2683 | |
Eric Fiselier | 9f7cc58 | 2017-04-18 23:42:15 | [diff] [blame] | 2684 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 | [diff] [blame] | 2685 | |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2686 | // const operations: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2687 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2688 | unsigned mark_count() const {return __marked_count_;} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2689 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2690 | flag_type flags() const {return __flags_;} |
| 2691 | |
| 2692 | // locale: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2693 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2694 | locale_type imbue(locale_type __loc) |
| 2695 | { |
| 2696 | __member_init(ECMAScript); |
| 2697 | __start_.reset(); |
| 2698 | return __traits_.imbue(__loc); |
| 2699 | } |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2700 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2701 | locale_type getloc() const {return __traits_.getloc();} |
| 2702 | |
| 2703 | // swap: |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2704 | void swap(basic_regex& __r); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2705 | |
| 2706 | private: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2707 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2708 | unsigned __loop_count() const {return __loop_count_;} |
| 2709 | |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2710 | template <class _ForwardIterator> |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 2711 | _ForwardIterator |
| 2712 | __parse(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2713 | template <class _ForwardIterator> |
| 2714 | _ForwardIterator |
| 2715 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2716 | template <class _ForwardIterator> |
| 2717 | _ForwardIterator |
| 2718 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2719 | template <class _ForwardIterator> |
| 2720 | _ForwardIterator |
| 2721 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2722 | template <class _ForwardIterator> |
| 2723 | _ForwardIterator |
| 2724 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2725 | template <class _ForwardIterator> |
| 2726 | _ForwardIterator |
| 2727 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2728 | template <class _ForwardIterator> |
| 2729 | _ForwardIterator |
| 2730 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2731 | template <class _ForwardIterator> |
| 2732 | _ForwardIterator |
| 2733 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2734 | template <class _ForwardIterator> |
| 2735 | _ForwardIterator |
| 2736 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2737 | template <class _ForwardIterator> |
| 2738 | _ForwardIterator |
| 2739 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2740 | template <class _ForwardIterator> |
| 2741 | _ForwardIterator |
| 2742 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2743 | template <class _ForwardIterator> |
| 2744 | _ForwardIterator |
| 2745 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2746 | template <class _ForwardIterator> |
| 2747 | _ForwardIterator |
| 2748 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2749 | template <class _ForwardIterator> |
| 2750 | _ForwardIterator |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2751 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 2752 | __owns_one_state<_CharT>* __s, |
| 2753 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 2754 | template <class _ForwardIterator> |
| 2755 | _ForwardIterator |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 2756 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2757 | __owns_one_state<_CharT>* __s, |
| 2758 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 2759 | template <class _ForwardIterator> |
| 2760 | _ForwardIterator |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 2761 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2762 | template <class _ForwardIterator> |
| 2763 | _ForwardIterator |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2764 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2765 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 2766 | template <class _ForwardIterator> |
| 2767 | _ForwardIterator |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2768 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2769 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 2770 | template <class _ForwardIterator> |
| 2771 | _ForwardIterator |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2772 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2773 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 2774 | template <class _ForwardIterator> |
| 2775 | _ForwardIterator |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2776 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2777 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 2778 | template <class _ForwardIterator> |
| 2779 | _ForwardIterator |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2780 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2781 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 2782 | template <class _ForwardIterator> |
| 2783 | _ForwardIterator |
| 2784 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 2785 | template <class _ForwardIterator> |
| 2786 | _ForwardIterator |
| 2787 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2788 | template <class _ForwardIterator> |
| 2789 | _ForwardIterator |
| 2790 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2791 | template <class _ForwardIterator> |
| 2792 | _ForwardIterator |
| 2793 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2794 | template <class _ForwardIterator> |
| 2795 | _ForwardIterator |
| 2796 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2797 | template <class _ForwardIterator> |
| 2798 | _ForwardIterator |
| 2799 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2800 | template <class _ForwardIterator> |
| 2801 | _ForwardIterator |
| 2802 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 2803 | template <class _ForwardIterator> |
| 2804 | _ForwardIterator |
| 2805 | __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2806 | template <class _ForwardIterator> |
| 2807 | _ForwardIterator |
| 2808 | __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); |
| 2809 | template <class _ForwardIterator> |
| 2810 | _ForwardIterator |
| 2811 | __parse_term(_ForwardIterator __first, _ForwardIterator __last); |
| 2812 | template <class _ForwardIterator> |
| 2813 | _ForwardIterator |
| 2814 | __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); |
| 2815 | template <class _ForwardIterator> |
| 2816 | _ForwardIterator |
| 2817 | __parse_atom(_ForwardIterator __first, _ForwardIterator __last); |
| 2818 | template <class _ForwardIterator> |
| 2819 | _ForwardIterator |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 2820 | __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2821 | template <class _ForwardIterator> |
| 2822 | _ForwardIterator |
| 2823 | __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2824 | template <class _ForwardIterator> |
| 2825 | _ForwardIterator |
| 2826 | __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2827 | template <class _ForwardIterator> |
| 2828 | _ForwardIterator |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2829 | __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2830 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 2831 | template <class _ForwardIterator> |
| 2832 | _ForwardIterator |
| 2833 | __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 93da3b2 | 2010-07-27 19:53:10 | [diff] [blame] | 2834 | template <class _ForwardIterator> |
| 2835 | _ForwardIterator |
| 2836 | __parse_grep(_ForwardIterator __first, _ForwardIterator __last); |
| 2837 | template <class _ForwardIterator> |
| 2838 | _ForwardIterator |
| 2839 | __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 2840 | template <class _ForwardIterator> |
| 2841 | _ForwardIterator |
| 2842 | __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2843 | basic_string<_CharT>& __str, |
| 2844 | __bracket_expression<_CharT, _Traits>* __ml); |
| 2845 | template <class _ForwardIterator> |
| 2846 | _ForwardIterator |
| 2847 | __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2848 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2849 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2850 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2851 | void __push_l_anchor(); |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 2852 | void __push_r_anchor(); |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 2853 | void __push_match_any(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 2854 | void __push_match_any_but_newline(); |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2855 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 2856 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2857 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2858 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2859 | __mexp_begin, __mexp_end);} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 2860 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 2861 | void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2862 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2863 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2864 | __mexp_begin, __mexp_end, false);} |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2865 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2866 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2867 | bool __greedy = true); |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 2868 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 2869 | void __push_char(value_type __c); |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 2870 | void __push_back_ref(int __i); |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 2871 | void __push_alternation(__owns_one_state<_CharT>* __sa, |
| 2872 | __owns_one_state<_CharT>* __sb); |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 2873 | void __push_begin_marked_subexpression(); |
| 2874 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 2875 | void __push_empty(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 2876 | void __push_word_boundary(bool); |
Howard Hinnant | 7491a16 | 2013-07-23 16:18:04 | [diff] [blame] | 2877 | void __push_lookahead(const basic_regex&, bool, unsigned); |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 2878 | |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2879 | template <class _Allocator> |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 2880 | bool |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2881 | __search(const _CharT* __first, const _CharT* __last, |
| 2882 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 2883 | regex_constants::match_flag_type __flags) const; |
| 2884 | |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2885 | template <class _Allocator> |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2886 | bool |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2887 | __match_at_start(const _CharT* __first, const _CharT* __last, |
| 2888 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2889 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 2890 | template <class _Allocator> |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2891 | bool |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 2892 | __match_at_start_ecma(const _CharT* __first, const _CharT* __last, |
| 2893 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2894 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2895 | template <class _Allocator> |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2896 | bool |
| 2897 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2898 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2899 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2900 | template <class _Allocator> |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2901 | bool |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2902 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 2903 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 2904 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2905 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2906 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 2907 | friend |
| 2908 | bool |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2909 | regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 2910 | regex_constants::match_flag_type); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2911 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2912 | template <class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2913 | friend |
| 2914 | bool |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2915 | regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&, |
| 2916 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2917 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2918 | template <class _Bp, class _Cp, class _Tp> |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2919 | friend |
| 2920 | bool |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2921 | regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2922 | regex_constants::match_flag_type); |
| 2923 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2924 | template <class _Cp, class _Tp> |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2925 | friend |
| 2926 | bool |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2927 | regex_search(const _Cp*, const _Cp*, |
| 2928 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2929 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2930 | template <class _Cp, class _Ap, class _Tp> |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2931 | friend |
| 2932 | bool |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2933 | regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2934 | regex_constants::match_flag_type); |
| 2935 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2936 | template <class _ST, class _SA, class _Cp, class _Tp> |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2937 | friend |
| 2938 | bool |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2939 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 2940 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2941 | regex_constants::match_flag_type __flags); |
| 2942 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2943 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2944 | friend |
| 2945 | bool |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 2946 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 2947 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 2948 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 2949 | regex_constants::match_flag_type __flags); |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 2950 | |
Howard Hinnant | 660f2ae | 2013-06-29 23:45:43 | [diff] [blame] | 2951 | template <class _Iter, class _Ap, class _Cp, class _Tp> |
| 2952 | friend |
| 2953 | bool |
| 2954 | regex_search(__wrap_iter<_Iter> __first, |
| 2955 | __wrap_iter<_Iter> __last, |
| 2956 | match_results<__wrap_iter<_Iter>, _Ap>& __m, |
| 2957 | const basic_regex<_Cp, _Tp>& __e, |
| 2958 | regex_constants::match_flag_type __flags); |
| 2959 | |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 2960 | template <class, class> friend class __lookahead; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 2961 | }; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2962 | |
Marshall Clow | edd5e29 | 2018-05-23 01:57:02 | [diff] [blame] | 2963 | #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES |
| 2964 | template <class _ForwardIterator, |
| 2965 | class = typename enable_if<__is_forward_iterator<_ForwardIterator>::value, nullptr_t>::type |
| 2966 | > |
| 2967 | basic_regex(_ForwardIterator, _ForwardIterator, |
| 2968 | regex_constants::syntax_option_type = regex_constants::ECMAScript) |
| 2969 | -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>; |
| 2970 | #endif |
| 2971 | |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2972 | template <class _CharT, class _Traits> |
Howard Hinnant | 16694b5 | 2012-12-12 21:14:28 | [diff] [blame] | 2973 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase; |
| 2974 | template <class _CharT, class _Traits> |
| 2975 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs; |
| 2976 | template <class _CharT, class _Traits> |
| 2977 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize; |
| 2978 | template <class _CharT, class _Traits> |
| 2979 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate; |
| 2980 | template <class _CharT, class _Traits> |
| 2981 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript; |
| 2982 | template <class _CharT, class _Traits> |
| 2983 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic; |
| 2984 | template <class _CharT, class _Traits> |
| 2985 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended; |
| 2986 | template <class _CharT, class _Traits> |
| 2987 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk; |
| 2988 | template <class _CharT, class _Traits> |
| 2989 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep; |
| 2990 | template <class _CharT, class _Traits> |
| 2991 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep; |
| 2992 | |
| 2993 | template <class _CharT, class _Traits> |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2994 | void |
| 2995 | basic_regex<_CharT, _Traits>::swap(basic_regex& __r) |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 2996 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 2997 | using _VSTD::swap; |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 2998 | swap(__traits_, __r.__traits_); |
| 2999 | swap(__flags_, __r.__flags_); |
| 3000 | swap(__marked_count_, __r.__marked_count_); |
| 3001 | swap(__loop_count_, __r.__loop_count_); |
| 3002 | swap(__open_count_, __r.__open_count_); |
| 3003 | swap(__start_, __r.__start_); |
| 3004 | swap(__end_, __r.__end_); |
Howard Hinnant | 5cd6658 | 2010-08-13 18:11:23 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | template <class _CharT, class _Traits> |
| 3008 | inline _LIBCPP_INLINE_VISIBILITY |
| 3009 | void |
| 3010 | swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) |
| 3011 | { |
| 3012 | return __x.swap(__y); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3013 | } |
| 3014 | |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3015 | // __lookahead |
| 3016 | |
| 3017 | template <class _CharT, class _Traits> |
| 3018 | class __lookahead |
| 3019 | : public __owns_one_state<_CharT> |
| 3020 | { |
| 3021 | typedef __owns_one_state<_CharT> base; |
| 3022 | |
| 3023 | basic_regex<_CharT, _Traits> __exp_; |
Howard Hinnant | 7491a16 | 2013-07-23 16:18:04 | [diff] [blame] | 3024 | unsigned __mexp_; |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3025 | bool __invert_; |
| 3026 | |
| 3027 | __lookahead(const __lookahead&); |
| 3028 | __lookahead& operator=(const __lookahead&); |
| 3029 | public: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3030 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3031 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 3032 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7491a16 | 2013-07-23 16:18:04 | [diff] [blame] | 3033 | __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp) |
Eric Fiselier | b50f8f9 | 2015-07-22 01:29:41 | [diff] [blame] | 3034 | : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {} |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3035 | |
| 3036 | virtual void __exec(__state&) const; |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3037 | }; |
| 3038 | |
| 3039 | template <class _CharT, class _Traits> |
| 3040 | void |
| 3041 | __lookahead<_CharT, _Traits>::__exec(__state& __s) const |
| 3042 | { |
| 3043 | match_results<const _CharT*> __m; |
| 3044 | __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); |
Tim Shen | e776667 | 2016-10-27 21:40:34 | [diff] [blame] | 3045 | bool __matched = __exp_.__match_at_start_ecma( |
| 3046 | __s.__current_, __s.__last_, |
| 3047 | __m, |
| 3048 | (__s.__flags_ | regex_constants::match_continuous) & |
| 3049 | ~regex_constants::__full_match, |
| 3050 | __s.__at_first_ && __s.__current_ == __s.__first_); |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3051 | if (__matched != __invert_) |
| 3052 | { |
| 3053 | __s.__do_ = __state::__accept_but_not_consume; |
| 3054 | __s.__node_ = this->first(); |
Howard Hinnant | 7491a16 | 2013-07-23 16:18:04 | [diff] [blame] | 3055 | for (unsigned __i = 1; __i < __m.size(); ++__i) { |
| 3056 | __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i]; |
| 3057 | } |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3058 | } |
| 3059 | else |
| 3060 | { |
| 3061 | __s.__do_ = __state::__reject; |
| 3062 | __s.__node_ = nullptr; |
| 3063 | } |
| 3064 | } |
| 3065 | |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3066 | template <class _CharT, class _Traits> |
| 3067 | template <class _ForwardIterator> |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3068 | _ForwardIterator |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3069 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 3070 | _ForwardIterator __last) |
| 3071 | { |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 3072 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 3073 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 3074 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 3075 | __h.release(); |
| 3076 | __end_ = __start_.get(); |
| 3077 | } |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 3078 | switch (__get_grammar(__flags_)) |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3079 | { |
| 3080 | case ECMAScript: |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3081 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3082 | break; |
| 3083 | case basic: |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3084 | __first = __parse_basic_reg_exp(__first, __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3085 | break; |
| 3086 | case extended: |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3087 | case awk: |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3088 | __first = __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3089 | break; |
| 3090 | case grep: |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3091 | __first = __parse_grep(__first, __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3092 | break; |
| 3093 | case egrep: |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3094 | __first = __parse_egrep(__first, __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3095 | break; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3096 | default: |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3097 | __throw_regex_error<regex_constants::__re_err_grammar>(); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3098 | } |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 3099 | return __first; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3100 | } |
| 3101 | |
| 3102 | template <class _CharT, class _Traits> |
| 3103 | template <class _ForwardIterator> |
| 3104 | _ForwardIterator |
| 3105 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 3106 | _ForwardIterator __last) |
| 3107 | { |
| 3108 | if (__first != __last) |
| 3109 | { |
| 3110 | if (*__first == '^') |
| 3111 | { |
| 3112 | __push_l_anchor(); |
| 3113 | ++__first; |
| 3114 | } |
| 3115 | if (__first != __last) |
| 3116 | { |
| 3117 | __first = __parse_RE_expression(__first, __last); |
| 3118 | if (__first != __last) |
| 3119 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3120 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3121 | if (__temp == __last && *__first == '$') |
| 3122 | { |
| 3123 | __push_r_anchor(); |
| 3124 | ++__first; |
| 3125 | } |
| 3126 | } |
| 3127 | } |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3128 | if (__first != __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3129 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3130 | } |
| 3131 | return __first; |
| 3132 | } |
| 3133 | |
| 3134 | template <class _CharT, class _Traits> |
| 3135 | template <class _ForwardIterator> |
| 3136 | _ForwardIterator |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3137 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 3138 | _ForwardIterator __last) |
| 3139 | { |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3140 | __owns_one_state<_CharT>* __sa = __end_; |
| 3141 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3142 | if (__temp == __first) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3143 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3144 | __first = __temp; |
| 3145 | while (__first != __last && *__first == '|') |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3146 | { |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3147 | __owns_one_state<_CharT>* __sb = __end_; |
| 3148 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3149 | if (__temp == __first) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3150 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3151 | __push_alternation(__sa, __sb); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3152 | __first = __temp; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3153 | } |
| 3154 | return __first; |
| 3155 | } |
| 3156 | |
| 3157 | template <class _CharT, class _Traits> |
| 3158 | template <class _ForwardIterator> |
| 3159 | _ForwardIterator |
| 3160 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 3161 | _ForwardIterator __last) |
| 3162 | { |
| 3163 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3164 | if (__temp == __first) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3165 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3166 | do |
| 3167 | { |
| 3168 | __first = __temp; |
| 3169 | __temp = __parse_ERE_expression(__first, __last); |
| 3170 | } while (__temp != __first); |
| 3171 | return __first; |
| 3172 | } |
| 3173 | |
| 3174 | template <class _CharT, class _Traits> |
| 3175 | template <class _ForwardIterator> |
| 3176 | _ForwardIterator |
| 3177 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 3178 | _ForwardIterator __last) |
| 3179 | { |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3180 | __owns_one_state<_CharT>* __e = __end_; |
| 3181 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3182 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 3183 | if (__temp == __first && __temp != __last) |
| 3184 | { |
| 3185 | switch (*__temp) |
| 3186 | { |
| 3187 | case '^': |
| 3188 | __push_l_anchor(); |
| 3189 | ++__temp; |
| 3190 | break; |
| 3191 | case '$': |
| 3192 | __push_r_anchor(); |
| 3193 | ++__temp; |
| 3194 | break; |
| 3195 | case '(': |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 3196 | __push_begin_marked_subexpression(); |
| 3197 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3198 | ++__open_count_; |
| 3199 | __temp = __parse_extended_reg_exp(++__temp, __last); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3200 | if (__temp == __last || *__temp != ')') |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3201 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 3202 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3203 | --__open_count_; |
| 3204 | ++__temp; |
| 3205 | break; |
| 3206 | } |
| 3207 | } |
| 3208 | if (__temp != __first) |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3209 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 3210 | __marked_count_+1); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3211 | __first = __temp; |
| 3212 | return __first; |
| 3213 | } |
| 3214 | |
| 3215 | template <class _CharT, class _Traits> |
| 3216 | template <class _ForwardIterator> |
| 3217 | _ForwardIterator |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3218 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 3219 | _ForwardIterator __last) |
| 3220 | { |
| 3221 | while (true) |
| 3222 | { |
| 3223 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 3224 | if (__temp == __first) |
| 3225 | break; |
| 3226 | __first = __temp; |
| 3227 | } |
| 3228 | return __first; |
| 3229 | } |
| 3230 | |
| 3231 | template <class _CharT, class _Traits> |
| 3232 | template <class _ForwardIterator> |
| 3233 | _ForwardIterator |
| 3234 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 3235 | _ForwardIterator __last) |
| 3236 | { |
| 3237 | if (__first != __last) |
| 3238 | { |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 3239 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 3240 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3241 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 3242 | if (__temp != __first) |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 3243 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 3244 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3245 | } |
| 3246 | return __first; |
| 3247 | } |
| 3248 | |
| 3249 | template <class _CharT, class _Traits> |
| 3250 | template <class _ForwardIterator> |
| 3251 | _ForwardIterator |
| 3252 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 3253 | _ForwardIterator __last) |
| 3254 | { |
| 3255 | _ForwardIterator __temp = __first; |
| 3256 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 3257 | if (__temp == __first) |
| 3258 | { |
| 3259 | __temp = __parse_Back_open_paren(__first, __last); |
| 3260 | if (__temp != __first) |
| 3261 | { |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 3262 | __push_begin_marked_subexpression(); |
| 3263 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3264 | __first = __parse_RE_expression(__temp, __last); |
| 3265 | __temp = __parse_Back_close_paren(__first, __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3266 | if (__temp == __first) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3267 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 3268 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3269 | __first = __temp; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3270 | } |
| 3271 | else |
| 3272 | __first = __parse_BACKREF(__first, __last); |
| 3273 | } |
| 3274 | return __first; |
| 3275 | } |
| 3276 | |
| 3277 | template <class _CharT, class _Traits> |
| 3278 | template <class _ForwardIterator> |
| 3279 | _ForwardIterator |
| 3280 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3281 | _ForwardIterator __first, |
| 3282 | _ForwardIterator __last) |
| 3283 | { |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3284 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3285 | if (__temp == __first) |
| 3286 | { |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3287 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3288 | if (__temp == __first) |
| 3289 | { |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3290 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3291 | { |
| 3292 | __push_match_any(); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3293 | ++__temp; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3294 | } |
| 3295 | else |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3296 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3297 | } |
| 3298 | } |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3299 | __first = __temp; |
| 3300 | return __first; |
| 3301 | } |
| 3302 | |
| 3303 | template <class _CharT, class _Traits> |
| 3304 | template <class _ForwardIterator> |
| 3305 | _ForwardIterator |
| 3306 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3307 | _ForwardIterator __first, |
| 3308 | _ForwardIterator __last) |
| 3309 | { |
| 3310 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3311 | if (__temp == __first) |
| 3312 | { |
| 3313 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3314 | if (__temp == __first) |
| 3315 | { |
| 3316 | if (__temp != __last && *__temp == '.') |
| 3317 | { |
| 3318 | __push_match_any(); |
| 3319 | ++__temp; |
| 3320 | } |
| 3321 | else |
| 3322 | __temp = __parse_bracket_expression(__first, __last); |
| 3323 | } |
| 3324 | } |
| 3325 | __first = __temp; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3326 | return __first; |
| 3327 | } |
| 3328 | |
| 3329 | template <class _CharT, class _Traits> |
| 3330 | template <class _ForwardIterator> |
| 3331 | _ForwardIterator |
| 3332 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3333 | _ForwardIterator __last) |
| 3334 | { |
| 3335 | if (__first != __last) |
| 3336 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3337 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3338 | if (__temp != __last) |
| 3339 | { |
| 3340 | if (*__first == '\\' && *__temp == '(') |
| 3341 | __first = ++__temp; |
| 3342 | } |
| 3343 | } |
| 3344 | return __first; |
| 3345 | } |
| 3346 | |
| 3347 | template <class _CharT, class _Traits> |
| 3348 | template <class _ForwardIterator> |
| 3349 | _ForwardIterator |
| 3350 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3351 | _ForwardIterator __last) |
| 3352 | { |
| 3353 | if (__first != __last) |
| 3354 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3355 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3356 | if (__temp != __last) |
| 3357 | { |
| 3358 | if (*__first == '\\' && *__temp == ')') |
| 3359 | __first = ++__temp; |
| 3360 | } |
| 3361 | } |
| 3362 | return __first; |
| 3363 | } |
| 3364 | |
| 3365 | template <class _CharT, class _Traits> |
| 3366 | template <class _ForwardIterator> |
| 3367 | _ForwardIterator |
| 3368 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3369 | _ForwardIterator __last) |
| 3370 | { |
| 3371 | if (__first != __last) |
| 3372 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3373 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3374 | if (__temp != __last) |
| 3375 | { |
| 3376 | if (*__first == '\\' && *__temp == '{') |
| 3377 | __first = ++__temp; |
| 3378 | } |
| 3379 | } |
| 3380 | return __first; |
| 3381 | } |
| 3382 | |
| 3383 | template <class _CharT, class _Traits> |
| 3384 | template <class _ForwardIterator> |
| 3385 | _ForwardIterator |
| 3386 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3387 | _ForwardIterator __last) |
| 3388 | { |
| 3389 | if (__first != __last) |
| 3390 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3391 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3392 | if (__temp != __last) |
| 3393 | { |
| 3394 | if (*__first == '\\' && *__temp == '}') |
| 3395 | __first = ++__temp; |
| 3396 | } |
| 3397 | } |
| 3398 | return __first; |
| 3399 | } |
| 3400 | |
| 3401 | template <class _CharT, class _Traits> |
| 3402 | template <class _ForwardIterator> |
| 3403 | _ForwardIterator |
| 3404 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 3405 | _ForwardIterator __last) |
| 3406 | { |
| 3407 | if (__first != __last) |
| 3408 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3409 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3410 | if (__temp != __last) |
| 3411 | { |
Marshall Clow | 9aafa898 | 2014-01-18 03:40:03 | [diff] [blame] | 3412 | if (*__first == '\\') |
| 3413 | { |
| 3414 | int __val = __traits_.value(*__temp, 10); |
| 3415 | if (__val >= 1 && __val <= 9) |
| 3416 | { |
| 3417 | __push_back_ref(__val); |
| 3418 | __first = ++__temp; |
| 3419 | } |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3420 | } |
| 3421 | } |
| 3422 | } |
| 3423 | return __first; |
| 3424 | } |
| 3425 | |
| 3426 | template <class _CharT, class _Traits> |
| 3427 | template <class _ForwardIterator> |
| 3428 | _ForwardIterator |
| 3429 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3430 | _ForwardIterator __last) |
| 3431 | { |
| 3432 | if (__first != __last) |
| 3433 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3434 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3435 | if (__temp == __last && *__first == '$') |
| 3436 | return __first; |
| 3437 | // Not called inside a bracket |
| 3438 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3439 | return __first; |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3440 | __push_char(*__first); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3441 | ++__first; |
| 3442 | } |
| 3443 | return __first; |
| 3444 | } |
| 3445 | |
| 3446 | template <class _CharT, class _Traits> |
| 3447 | template <class _ForwardIterator> |
| 3448 | _ForwardIterator |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3449 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3450 | _ForwardIterator __last) |
| 3451 | { |
| 3452 | if (__first != __last) |
| 3453 | { |
| 3454 | switch (*__first) |
| 3455 | { |
| 3456 | case '^': |
| 3457 | case '.': |
| 3458 | case '[': |
| 3459 | case '$': |
| 3460 | case '(': |
| 3461 | case '|': |
| 3462 | case '*': |
| 3463 | case '+': |
| 3464 | case '?': |
| 3465 | case '{': |
| 3466 | case '\\': |
| 3467 | break; |
| 3468 | case ')': |
| 3469 | if (__open_count_ == 0) |
| 3470 | { |
| 3471 | __push_char(*__first); |
| 3472 | ++__first; |
| 3473 | } |
| 3474 | break; |
| 3475 | default: |
| 3476 | __push_char(*__first); |
| 3477 | ++__first; |
| 3478 | break; |
| 3479 | } |
| 3480 | } |
| 3481 | return __first; |
| 3482 | } |
| 3483 | |
| 3484 | template <class _CharT, class _Traits> |
| 3485 | template <class _ForwardIterator> |
| 3486 | _ForwardIterator |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3487 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3488 | _ForwardIterator __last) |
| 3489 | { |
| 3490 | if (__first != __last) |
| 3491 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3492 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3493 | if (__temp != __last) |
| 3494 | { |
| 3495 | if (*__first == '\\') |
| 3496 | { |
| 3497 | switch (*__temp) |
| 3498 | { |
| 3499 | case '^': |
| 3500 | case '.': |
| 3501 | case '*': |
| 3502 | case '[': |
| 3503 | case '$': |
| 3504 | case '\\': |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3505 | __push_char(*__temp); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3506 | __first = ++__temp; |
| 3507 | break; |
| 3508 | } |
| 3509 | } |
| 3510 | } |
| 3511 | } |
| 3512 | return __first; |
| 3513 | } |
| 3514 | |
| 3515 | template <class _CharT, class _Traits> |
| 3516 | template <class _ForwardIterator> |
| 3517 | _ForwardIterator |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3518 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3519 | _ForwardIterator __last) |
| 3520 | { |
| 3521 | if (__first != __last) |
| 3522 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3523 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3524 | if (__temp != __last) |
| 3525 | { |
| 3526 | if (*__first == '\\') |
| 3527 | { |
| 3528 | switch (*__temp) |
| 3529 | { |
| 3530 | case '^': |
| 3531 | case '.': |
| 3532 | case '*': |
| 3533 | case '[': |
| 3534 | case '$': |
| 3535 | case '\\': |
| 3536 | case '(': |
| 3537 | case ')': |
| 3538 | case '|': |
| 3539 | case '+': |
| 3540 | case '?': |
| 3541 | case '{': |
Howard Hinnant | 3f75953 | 2013-06-28 20:31:05 | [diff] [blame] | 3542 | case '}': |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3543 | __push_char(*__temp); |
| 3544 | __first = ++__temp; |
| 3545 | break; |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3546 | default: |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 3547 | if (__get_grammar(__flags_) == awk) |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3548 | __first = __parse_awk_escape(++__first, __last); |
| 3549 | break; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3550 | } |
| 3551 | } |
| 3552 | } |
| 3553 | } |
| 3554 | return __first; |
| 3555 | } |
| 3556 | |
| 3557 | template <class _CharT, class _Traits> |
| 3558 | template <class _ForwardIterator> |
| 3559 | _ForwardIterator |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3560 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 3561 | _ForwardIterator __last, |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 3562 | __owns_one_state<_CharT>* __s, |
| 3563 | unsigned __mexp_begin, |
| 3564 | unsigned __mexp_end) |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3565 | { |
| 3566 | if (__first != __last) |
| 3567 | { |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3568 | if (*__first == '*') |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3569 | { |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 3570 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3571 | ++__first; |
| 3572 | } |
| 3573 | else |
| 3574 | { |
| 3575 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3576 | if (__temp != __first) |
| 3577 | { |
| 3578 | int __min = 0; |
| 3579 | __first = __temp; |
| 3580 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3581 | if (__temp == __first) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3582 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3583 | __first = __temp; |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3584 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3585 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3586 | if (*__first != ',') |
| 3587 | { |
| 3588 | __temp = __parse_Back_close_brace(__first, __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3589 | if (__temp == __first) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3590 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 3591 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3592 | true); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3593 | __first = __temp; |
| 3594 | } |
| 3595 | else |
| 3596 | { |
| 3597 | ++__first; // consume ',' |
| 3598 | int __max = -1; |
| 3599 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3600 | __temp = __parse_Back_close_brace(__first, __last); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3601 | if (__temp == __first) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3602 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3603 | if (__max == -1) |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3604 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3605 | else |
| 3606 | { |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3607 | if (__max < __min) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3608 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 3609 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3610 | true); |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 3611 | } |
| 3612 | __first = __temp; |
| 3613 | } |
| 3614 | } |
| 3615 | } |
| 3616 | } |
| 3617 | return __first; |
| 3618 | } |
| 3619 | |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3620 | template <class _CharT, class _Traits> |
| 3621 | template <class _ForwardIterator> |
| 3622 | _ForwardIterator |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3623 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3624 | _ForwardIterator __last, |
| 3625 | __owns_one_state<_CharT>* __s, |
| 3626 | unsigned __mexp_begin, |
| 3627 | unsigned __mexp_end) |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3628 | { |
| 3629 | if (__first != __last) |
| 3630 | { |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 3631 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3632 | switch (*__first) |
| 3633 | { |
| 3634 | case '*': |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3635 | ++__first; |
Howard Hinnant | 4ea5240 | 2010-07-29 00:36:00 | [diff] [blame] | 3636 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 3637 | { |
| 3638 | ++__first; |
| 3639 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3640 | } |
| 3641 | else |
| 3642 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3643 | break; |
| 3644 | case '+': |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3645 | ++__first; |
Howard Hinnant | 4ea5240 | 2010-07-29 00:36:00 | [diff] [blame] | 3646 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 3647 | { |
| 3648 | ++__first; |
| 3649 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3650 | } |
| 3651 | else |
| 3652 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3653 | break; |
| 3654 | case '?': |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3655 | ++__first; |
Howard Hinnant | 4ea5240 | 2010-07-29 00:36:00 | [diff] [blame] | 3656 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 3657 | { |
| 3658 | ++__first; |
| 3659 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3660 | } |
| 3661 | else |
| 3662 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3663 | break; |
| 3664 | case '{': |
| 3665 | { |
| 3666 | int __min; |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3667 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3668 | if (__temp == __first) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3669 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3670 | __first = __temp; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3671 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3672 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3673 | switch (*__first) |
| 3674 | { |
| 3675 | case '}': |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3676 | ++__first; |
Howard Hinnant | 4ea5240 | 2010-07-29 00:36:00 | [diff] [blame] | 3677 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 3678 | { |
| 3679 | ++__first; |
| 3680 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3681 | } |
| 3682 | else |
| 3683 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3684 | break; |
| 3685 | case ',': |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 3686 | ++__first; |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 3687 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3688 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3689 | if (*__first == '}') |
| 3690 | { |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3691 | ++__first; |
Howard Hinnant | 4ea5240 | 2010-07-29 00:36:00 | [diff] [blame] | 3692 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 3693 | { |
| 3694 | ++__first; |
| 3695 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3696 | } |
| 3697 | else |
| 3698 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3699 | } |
| 3700 | else |
| 3701 | { |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3702 | int __max = -1; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3703 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3704 | if (__temp == __first) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3705 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3706 | __first = __temp; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3707 | if (__first == __last || *__first != '}') |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3708 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3709 | ++__first; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3710 | if (__max < __min) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3711 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 4ea5240 | 2010-07-29 00:36:00 | [diff] [blame] | 3712 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 3713 | { |
| 3714 | ++__first; |
| 3715 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3716 | } |
| 3717 | else |
| 3718 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3719 | } |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 3720 | break; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3721 | default: |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3722 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 3723 | } |
| 3724 | } |
| 3725 | break; |
| 3726 | } |
| 3727 | } |
| 3728 | return __first; |
| 3729 | } |
| 3730 | |
| 3731 | template <class _CharT, class _Traits> |
| 3732 | template <class _ForwardIterator> |
| 3733 | _ForwardIterator |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3734 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3735 | _ForwardIterator __last) |
| 3736 | { |
| 3737 | if (__first != __last && *__first == '[') |
| 3738 | { |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 3739 | ++__first; |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 3740 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3741 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3742 | bool __negate = false; |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3743 | if (*__first == '^') |
| 3744 | { |
| 3745 | ++__first; |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3746 | __negate = true; |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3747 | } |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3748 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3749 | // __ml owned by *this |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3750 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3751 | __throw_regex_error<regex_constants::error_brack>(); |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 3752 | if (__get_grammar(__flags_) != ECMAScript && *__first == ']') |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3753 | { |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3754 | __ml->__add_char(']'); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3755 | ++__first; |
| 3756 | } |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3757 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3758 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3759 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3760 | if (*__first == '-') |
| 3761 | { |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3762 | __ml->__add_char('-'); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3763 | ++__first; |
| 3764 | } |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3765 | if (__first == __last || *__first != ']') |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3766 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3767 | ++__first; |
| 3768 | } |
| 3769 | return __first; |
| 3770 | } |
| 3771 | |
| 3772 | template <class _CharT, class _Traits> |
| 3773 | template <class _ForwardIterator> |
| 3774 | _ForwardIterator |
| 3775 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3776 | _ForwardIterator __last, |
| 3777 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3778 | { |
| 3779 | if (__first != __last) |
| 3780 | { |
| 3781 | while (true) |
| 3782 | { |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3783 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3784 | __ml); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3785 | if (__temp == __first) |
| 3786 | break; |
| 3787 | __first = __temp; |
| 3788 | } |
| 3789 | } |
| 3790 | return __first; |
| 3791 | } |
| 3792 | |
| 3793 | template <class _CharT, class _Traits> |
| 3794 | template <class _ForwardIterator> |
| 3795 | _ForwardIterator |
| 3796 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3797 | _ForwardIterator __last, |
| 3798 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3799 | { |
| 3800 | if (__first != __last && *__first != ']') |
| 3801 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3802 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3803 | basic_string<_CharT> __start_range; |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3804 | if (__temp != __last && *__first == '[') |
| 3805 | { |
| 3806 | if (*__temp == '=') |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3807 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3808 | else if (*__temp == ':') |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3809 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3810 | else if (*__temp == '.') |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3811 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3812 | } |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 3813 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3814 | if (__start_range.empty()) |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3815 | { |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3816 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3817 | { |
| 3818 | if (__grammar == ECMAScript) |
| 3819 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3820 | else |
| 3821 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3822 | } |
| 3823 | else |
| 3824 | { |
| 3825 | __start_range = *__first; |
| 3826 | ++__first; |
| 3827 | } |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3828 | } |
| 3829 | if (__first != __last && *__first != ']') |
| 3830 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3831 | __temp = _VSTD::next(__first); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3832 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3833 | { |
| 3834 | // parse a range |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3835 | basic_string<_CharT> __end_range; |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3836 | __first = __temp; |
| 3837 | ++__temp; |
| 3838 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3839 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3840 | else |
| 3841 | { |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3842 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3843 | { |
| 3844 | if (__grammar == ECMAScript) |
| 3845 | __first = __parse_class_escape(++__first, __last, |
| 3846 | __end_range, __ml); |
| 3847 | else |
| 3848 | __first = __parse_awk_escape(++__first, __last, |
| 3849 | &__end_range); |
| 3850 | } |
| 3851 | else |
| 3852 | { |
| 3853 | __end_range = *__first; |
| 3854 | ++__first; |
| 3855 | } |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3856 | } |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 3857 | __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3858 | } |
Howard Hinnant | fc88dbd | 2013-08-23 17:37:05 | [diff] [blame] | 3859 | else if (!__start_range.empty()) |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3860 | { |
| 3861 | if (__start_range.size() == 1) |
| 3862 | __ml->__add_char(__start_range[0]); |
| 3863 | else |
| 3864 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3865 | } |
| 3866 | } |
Howard Hinnant | fc88dbd | 2013-08-23 17:37:05 | [diff] [blame] | 3867 | else if (!__start_range.empty()) |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 3868 | { |
| 3869 | if (__start_range.size() == 1) |
| 3870 | __ml->__add_char(__start_range[0]); |
| 3871 | else |
| 3872 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 3873 | } |
| 3874 | } |
| 3875 | return __first; |
| 3876 | } |
| 3877 | |
| 3878 | template <class _CharT, class _Traits> |
| 3879 | template <class _ForwardIterator> |
| 3880 | _ForwardIterator |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3881 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 3882 | _ForwardIterator __last, |
| 3883 | basic_string<_CharT>& __str, |
| 3884 | __bracket_expression<_CharT, _Traits>* __ml) |
| 3885 | { |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3886 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3887 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3888 | switch (*__first) |
| 3889 | { |
| 3890 | case 0: |
| 3891 | __str = *__first; |
| 3892 | return ++__first; |
| 3893 | case 'b': |
| 3894 | __str = _CharT(8); |
| 3895 | return ++__first; |
| 3896 | case 'd': |
| 3897 | __ml->__add_class(ctype_base::digit); |
| 3898 | return ++__first; |
| 3899 | case 'D': |
| 3900 | __ml->__add_neg_class(ctype_base::digit); |
| 3901 | return ++__first; |
| 3902 | case 's': |
| 3903 | __ml->__add_class(ctype_base::space); |
| 3904 | return ++__first; |
| 3905 | case 'S': |
| 3906 | __ml->__add_neg_class(ctype_base::space); |
| 3907 | return ++__first; |
| 3908 | case 'w': |
| 3909 | __ml->__add_class(ctype_base::alnum); |
| 3910 | __ml->__add_char('_'); |
| 3911 | return ++__first; |
| 3912 | case 'W': |
| 3913 | __ml->__add_neg_class(ctype_base::alnum); |
| 3914 | __ml->__add_neg_char('_'); |
| 3915 | return ++__first; |
| 3916 | } |
| 3917 | __first = __parse_character_escape(__first, __last, &__str); |
| 3918 | return __first; |
| 3919 | } |
| 3920 | |
| 3921 | template <class _CharT, class _Traits> |
| 3922 | template <class _ForwardIterator> |
| 3923 | _ForwardIterator |
| 3924 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 3925 | _ForwardIterator __last, |
| 3926 | basic_string<_CharT>* __str) |
| 3927 | { |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3928 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3929 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3930 | switch (*__first) |
| 3931 | { |
| 3932 | case '\\': |
| 3933 | case '"': |
| 3934 | case '/': |
| 3935 | if (__str) |
| 3936 | *__str = *__first; |
| 3937 | else |
| 3938 | __push_char(*__first); |
| 3939 | return ++__first; |
| 3940 | case 'a': |
| 3941 | if (__str) |
| 3942 | *__str = _CharT(7); |
| 3943 | else |
| 3944 | __push_char(_CharT(7)); |
| 3945 | return ++__first; |
| 3946 | case 'b': |
| 3947 | if (__str) |
| 3948 | *__str = _CharT(8); |
| 3949 | else |
| 3950 | __push_char(_CharT(8)); |
| 3951 | return ++__first; |
| 3952 | case 'f': |
| 3953 | if (__str) |
| 3954 | *__str = _CharT(0xC); |
| 3955 | else |
| 3956 | __push_char(_CharT(0xC)); |
| 3957 | return ++__first; |
| 3958 | case 'n': |
| 3959 | if (__str) |
| 3960 | *__str = _CharT(0xA); |
| 3961 | else |
| 3962 | __push_char(_CharT(0xA)); |
| 3963 | return ++__first; |
| 3964 | case 'r': |
| 3965 | if (__str) |
| 3966 | *__str = _CharT(0xD); |
| 3967 | else |
| 3968 | __push_char(_CharT(0xD)); |
| 3969 | return ++__first; |
| 3970 | case 't': |
| 3971 | if (__str) |
| 3972 | *__str = _CharT(0x9); |
| 3973 | else |
| 3974 | __push_char(_CharT(0x9)); |
| 3975 | return ++__first; |
| 3976 | case 'v': |
| 3977 | if (__str) |
| 3978 | *__str = _CharT(0xB); |
| 3979 | else |
| 3980 | __push_char(_CharT(0xB)); |
| 3981 | return ++__first; |
| 3982 | } |
| 3983 | if ('0' <= *__first && *__first <= '7') |
| 3984 | { |
| 3985 | unsigned __val = *__first - '0'; |
| 3986 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 3987 | { |
| 3988 | __val = 8 * __val + *__first - '0'; |
| 3989 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
Howard Hinnant | 43bbdd2 | 2013-07-02 17:43:31 | [diff] [blame] | 3990 | __val = 8 * __val + *__first++ - '0'; |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3991 | } |
| 3992 | if (__str) |
| 3993 | *__str = _CharT(__val); |
| 3994 | else |
| 3995 | __push_char(_CharT(__val)); |
| 3996 | } |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3997 | else |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 3998 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 3999 | return __first; |
| 4000 | } |
| 4001 | |
| 4002 | template <class _CharT, class _Traits> |
| 4003 | template <class _ForwardIterator> |
| 4004 | _ForwardIterator |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4005 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4006 | _ForwardIterator __last, |
| 4007 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4008 | { |
| 4009 | // Found [= |
| 4010 | // This means =] must exist |
| 4011 | value_type _Equal_close[2] = {'=', ']'}; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4012 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4013 | _Equal_close+2); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4014 | if (__temp == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4015 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4016 | // [__first, __temp) contains all text in [= ... =] |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4017 | string_type __collate_name = |
| 4018 | __traits_.lookup_collatename(__first, __temp); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4019 | if (__collate_name.empty()) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4020 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4021 | string_type __equiv_name = |
| 4022 | __traits_.transform_primary(__collate_name.begin(), |
| 4023 | __collate_name.end()); |
| 4024 | if (!__equiv_name.empty()) |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4025 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4026 | else |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4027 | { |
| 4028 | switch (__collate_name.size()) |
| 4029 | { |
| 4030 | case 1: |
| 4031 | __ml->__add_char(__collate_name[0]); |
| 4032 | break; |
| 4033 | case 2: |
| 4034 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 4035 | break; |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4036 | default: |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4037 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4038 | } |
| 4039 | } |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4040 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4041 | return __first; |
| 4042 | } |
| 4043 | |
| 4044 | template <class _CharT, class _Traits> |
| 4045 | template <class _ForwardIterator> |
| 4046 | _ForwardIterator |
| 4047 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4048 | _ForwardIterator __last, |
| 4049 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4050 | { |
| 4051 | // Found [: |
| 4052 | // This means :] must exist |
| 4053 | value_type _Colon_close[2] = {':', ']'}; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4054 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4055 | _Colon_close+2); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4056 | if (__temp == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4057 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4058 | // [__first, __temp) contains all text in [: ... :] |
| 4059 | typedef typename _Traits::char_class_type char_class_type; |
| 4060 | char_class_type __class_type = |
| 4061 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4062 | if (__class_type == 0) |
Mikhail Maltsev | 48c63d8 | 2018-01-24 12:45:18 | [diff] [blame] | 4063 | __throw_regex_error<regex_constants::error_ctype>(); |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4064 | __ml->__add_class(__class_type); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4065 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4066 | return __first; |
| 4067 | } |
| 4068 | |
| 4069 | template <class _CharT, class _Traits> |
| 4070 | template <class _ForwardIterator> |
| 4071 | _ForwardIterator |
| 4072 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4073 | _ForwardIterator __last, |
| 4074 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4075 | { |
| 4076 | // Found [. |
| 4077 | // This means .] must exist |
| 4078 | value_type _Dot_close[2] = {'.', ']'}; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4079 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4080 | _Dot_close+2); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4081 | if (__temp == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4082 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4083 | // [__first, __temp) contains all text in [. ... .] |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4084 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 4085 | switch (__col_sym.size()) |
| 4086 | { |
| 4087 | case 1: |
| 4088 | case 2: |
| 4089 | break; |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4090 | default: |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4091 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4092 | } |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4093 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4094 | return __first; |
| 4095 | } |
| 4096 | |
| 4097 | template <class _CharT, class _Traits> |
| 4098 | template <class _ForwardIterator> |
| 4099 | _ForwardIterator |
| 4100 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 4101 | _ForwardIterator __last, |
| 4102 | int& __c) |
| 4103 | { |
Marshall Clow | 9aafa898 | 2014-01-18 03:40:03 | [diff] [blame] | 4104 | if (__first != __last ) |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4105 | { |
Marshall Clow | 9aafa898 | 2014-01-18 03:40:03 | [diff] [blame] | 4106 | int __val = __traits_.value(*__first, 10); |
| 4107 | if ( __val != -1 ) |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4108 | { |
Marshall Clow | 9aafa898 | 2014-01-18 03:40:03 | [diff] [blame] | 4109 | __c = __val; |
| 4110 | for (++__first; |
| 4111 | __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; |
| 4112 | ++__first) |
| 4113 | { |
Marshall Clow | 52f0885 | 2017-10-19 17:39:16 | [diff] [blame] | 4114 | if (__c >= std::numeric_limits<int>::max() / 10) |
| 4115 | __throw_regex_error<regex_constants::error_badbrace>(); |
Marshall Clow | 9aafa898 | 2014-01-18 03:40:03 | [diff] [blame] | 4116 | __c *= 10; |
| 4117 | __c += __val; |
| 4118 | } |
Howard Hinnant | 853aff8 | 2010-06-25 20:56:08 | [diff] [blame] | 4119 | } |
| 4120 | } |
| 4121 | return __first; |
| 4122 | } |
| 4123 | |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4124 | template <class _CharT, class _Traits> |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4125 | template <class _ForwardIterator> |
| 4126 | _ForwardIterator |
| 4127 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 4128 | _ForwardIterator __last) |
| 4129 | { |
| 4130 | __owns_one_state<_CharT>* __sa = __end_; |
| 4131 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 4132 | if (__temp == __first) |
| 4133 | __push_empty(); |
| 4134 | __first = __temp; |
| 4135 | while (__first != __last && *__first == '|') |
| 4136 | { |
| 4137 | __owns_one_state<_CharT>* __sb = __end_; |
| 4138 | __temp = __parse_alternative(++__first, __last); |
| 4139 | if (__temp == __first) |
| 4140 | __push_empty(); |
| 4141 | __push_alternation(__sa, __sb); |
| 4142 | __first = __temp; |
| 4143 | } |
| 4144 | return __first; |
| 4145 | } |
| 4146 | |
| 4147 | template <class _CharT, class _Traits> |
| 4148 | template <class _ForwardIterator> |
| 4149 | _ForwardIterator |
| 4150 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 4151 | _ForwardIterator __last) |
| 4152 | { |
| 4153 | while (true) |
| 4154 | { |
| 4155 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 4156 | if (__temp == __first) |
| 4157 | break; |
| 4158 | __first = __temp; |
| 4159 | } |
| 4160 | return __first; |
| 4161 | } |
| 4162 | |
| 4163 | template <class _CharT, class _Traits> |
| 4164 | template <class _ForwardIterator> |
| 4165 | _ForwardIterator |
| 4166 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 4167 | _ForwardIterator __last) |
| 4168 | { |
| 4169 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 4170 | if (__temp == __first) |
| 4171 | { |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4172 | __owns_one_state<_CharT>* __e = __end_; |
| 4173 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4174 | __temp = __parse_atom(__first, __last); |
| 4175 | if (__temp != __first) |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4176 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 4177 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4178 | } |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4179 | else |
| 4180 | __first = __temp; |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4181 | return __first; |
| 4182 | } |
| 4183 | |
| 4184 | template <class _CharT, class _Traits> |
| 4185 | template <class _ForwardIterator> |
| 4186 | _ForwardIterator |
| 4187 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 4188 | _ForwardIterator __last) |
| 4189 | { |
| 4190 | if (__first != __last) |
| 4191 | { |
| 4192 | switch (*__first) |
| 4193 | { |
| 4194 | case '^': |
| 4195 | __push_l_anchor(); |
| 4196 | ++__first; |
| 4197 | break; |
| 4198 | case '$': |
| 4199 | __push_r_anchor(); |
| 4200 | ++__first; |
| 4201 | break; |
| 4202 | case '\\': |
| 4203 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4204 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4205 | if (__temp != __last) |
| 4206 | { |
| 4207 | if (*__temp == 'b') |
| 4208 | { |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4209 | __push_word_boundary(false); |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4210 | __first = ++__temp; |
| 4211 | } |
| 4212 | else if (*__temp == 'B') |
| 4213 | { |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4214 | __push_word_boundary(true); |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4215 | __first = ++__temp; |
| 4216 | } |
| 4217 | } |
| 4218 | } |
| 4219 | break; |
| 4220 | case '(': |
| 4221 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4222 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4223 | if (__temp != __last && *__temp == '?') |
| 4224 | { |
| 4225 | if (++__temp != __last) |
| 4226 | { |
| 4227 | switch (*__temp) |
| 4228 | { |
| 4229 | case '=': |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 4230 | { |
| 4231 | basic_regex __exp; |
| 4232 | __exp.__flags_ = __flags_; |
| 4233 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 7491a16 | 2013-07-23 16:18:04 | [diff] [blame] | 4234 | unsigned __mexp = __exp.__marked_count_; |
| 4235 | __push_lookahead(_VSTD::move(__exp), false, __marked_count_); |
| 4236 | __marked_count_ += __mexp; |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 4237 | if (__temp == __last || *__temp != ')') |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4238 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 4239 | __first = ++__temp; |
| 4240 | } |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4241 | break; |
| 4242 | case '!': |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 4243 | { |
| 4244 | basic_regex __exp; |
| 4245 | __exp.__flags_ = __flags_; |
| 4246 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 7491a16 | 2013-07-23 16:18:04 | [diff] [blame] | 4247 | unsigned __mexp = __exp.__marked_count_; |
| 4248 | __push_lookahead(_VSTD::move(__exp), true, __marked_count_); |
| 4249 | __marked_count_ += __mexp; |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 4250 | if (__temp == __last || *__temp != ')') |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4251 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 4252 | __first = ++__temp; |
| 4253 | } |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4254 | break; |
| 4255 | } |
| 4256 | } |
| 4257 | } |
| 4258 | } |
| 4259 | break; |
| 4260 | } |
| 4261 | } |
| 4262 | return __first; |
| 4263 | } |
| 4264 | |
| 4265 | template <class _CharT, class _Traits> |
| 4266 | template <class _ForwardIterator> |
| 4267 | _ForwardIterator |
| 4268 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4269 | _ForwardIterator __last) |
| 4270 | { |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4271 | if (__first != __last) |
| 4272 | { |
| 4273 | switch (*__first) |
| 4274 | { |
| 4275 | case '.': |
| 4276 | __push_match_any_but_newline(); |
| 4277 | ++__first; |
| 4278 | break; |
| 4279 | case '\\': |
| 4280 | __first = __parse_atom_escape(__first, __last); |
| 4281 | break; |
| 4282 | case '[': |
| 4283 | __first = __parse_bracket_expression(__first, __last); |
| 4284 | break; |
| 4285 | case '(': |
| 4286 | { |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 4287 | ++__first; |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 4288 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4289 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4290 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4291 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4292 | { |
| 4293 | ++__open_count_; |
| 4294 | __first = __parse_ecma_exp(++__temp, __last); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4295 | if (__first == __last || *__first != ')') |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4296 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4297 | --__open_count_; |
| 4298 | ++__first; |
| 4299 | } |
| 4300 | else |
| 4301 | { |
| 4302 | __push_begin_marked_subexpression(); |
| 4303 | unsigned __temp_count = __marked_count_; |
| 4304 | ++__open_count_; |
| 4305 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4306 | if (__first == __last || *__first != ')') |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4307 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4308 | __push_end_marked_subexpression(__temp_count); |
| 4309 | --__open_count_; |
| 4310 | ++__first; |
| 4311 | } |
| 4312 | } |
| 4313 | break; |
Marshall Clow | 983d178 | 2015-07-23 18:27:51 | [diff] [blame] | 4314 | case '*': |
| 4315 | case '+': |
| 4316 | case '?': |
| 4317 | case '{': |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4318 | __throw_regex_error<regex_constants::error_badrepeat>(); |
Marshall Clow | 983d178 | 2015-07-23 18:27:51 | [diff] [blame] | 4319 | break; |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4320 | default: |
| 4321 | __first = __parse_pattern_character(__first, __last); |
| 4322 | break; |
| 4323 | } |
| 4324 | } |
| 4325 | return __first; |
| 4326 | } |
| 4327 | |
| 4328 | template <class _CharT, class _Traits> |
| 4329 | template <class _ForwardIterator> |
| 4330 | _ForwardIterator |
| 4331 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4332 | _ForwardIterator __last) |
| 4333 | { |
| 4334 | if (__first != __last && *__first == '\\') |
| 4335 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4336 | _ForwardIterator __t1 = _VSTD::next(__first); |
Marshall Clow | b414b2f | 2016-01-19 00:50:37 | [diff] [blame] | 4337 | if (__t1 == __last) |
| 4338 | __throw_regex_error<regex_constants::error_escape>(); |
| 4339 | |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4340 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4341 | if (__t2 != __t1) |
| 4342 | __first = __t2; |
| 4343 | else |
| 4344 | { |
| 4345 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4346 | if (__t2 != __t1) |
| 4347 | __first = __t2; |
| 4348 | else |
| 4349 | { |
| 4350 | __t2 = __parse_character_escape(__t1, __last); |
| 4351 | if (__t2 != __t1) |
| 4352 | __first = __t2; |
| 4353 | } |
| 4354 | } |
| 4355 | } |
| 4356 | return __first; |
| 4357 | } |
| 4358 | |
| 4359 | template <class _CharT, class _Traits> |
| 4360 | template <class _ForwardIterator> |
| 4361 | _ForwardIterator |
| 4362 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4363 | _ForwardIterator __last) |
| 4364 | { |
| 4365 | if (__first != __last) |
| 4366 | { |
| 4367 | if (*__first == '0') |
| 4368 | { |
| 4369 | __push_char(_CharT()); |
| 4370 | ++__first; |
| 4371 | } |
| 4372 | else if ('1' <= *__first && *__first <= '9') |
| 4373 | { |
| 4374 | unsigned __v = *__first - '0'; |
Marshall Clow | da520dc | 2016-12-24 17:21:03 | [diff] [blame] | 4375 | for (++__first; |
| 4376 | __first != __last && '0' <= *__first && *__first <= '9'; ++__first) |
Marshall Clow | 55b9e44 | 2017-10-19 22:10:41 | [diff] [blame] | 4377 | { |
| 4378 | if (__v >= std::numeric_limits<unsigned>::max() / 10) |
| 4379 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4380 | __v = 10 * __v + *__first - '0'; |
Marshall Clow | 55b9e44 | 2017-10-19 22:10:41 | [diff] [blame] | 4381 | } |
| 4382 | if (__v == 0 || __v > mark_count()) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4383 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4384 | __push_back_ref(__v); |
| 4385 | } |
| 4386 | } |
| 4387 | return __first; |
| 4388 | } |
| 4389 | |
| 4390 | template <class _CharT, class _Traits> |
| 4391 | template <class _ForwardIterator> |
| 4392 | _ForwardIterator |
| 4393 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4394 | _ForwardIterator __last) |
| 4395 | { |
| 4396 | if (__first != __last) |
| 4397 | { |
| 4398 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4399 | switch (*__first) |
| 4400 | { |
| 4401 | case 'd': |
| 4402 | __ml = __start_matching_list(false); |
| 4403 | __ml->__add_class(ctype_base::digit); |
| 4404 | ++__first; |
| 4405 | break; |
| 4406 | case 'D': |
| 4407 | __ml = __start_matching_list(true); |
| 4408 | __ml->__add_class(ctype_base::digit); |
| 4409 | ++__first; |
| 4410 | break; |
| 4411 | case 's': |
| 4412 | __ml = __start_matching_list(false); |
| 4413 | __ml->__add_class(ctype_base::space); |
| 4414 | ++__first; |
| 4415 | break; |
| 4416 | case 'S': |
| 4417 | __ml = __start_matching_list(true); |
| 4418 | __ml->__add_class(ctype_base::space); |
| 4419 | ++__first; |
| 4420 | break; |
| 4421 | case 'w': |
| 4422 | __ml = __start_matching_list(false); |
| 4423 | __ml->__add_class(ctype_base::alnum); |
| 4424 | __ml->__add_char('_'); |
| 4425 | ++__first; |
| 4426 | break; |
| 4427 | case 'W': |
| 4428 | __ml = __start_matching_list(true); |
| 4429 | __ml->__add_class(ctype_base::alnum); |
| 4430 | __ml->__add_char('_'); |
| 4431 | ++__first; |
| 4432 | break; |
| 4433 | } |
| 4434 | } |
| 4435 | return __first; |
| 4436 | } |
| 4437 | |
| 4438 | template <class _CharT, class _Traits> |
| 4439 | template <class _ForwardIterator> |
| 4440 | _ForwardIterator |
| 4441 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 4442 | _ForwardIterator __last, |
| 4443 | basic_string<_CharT>* __str) |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4444 | { |
| 4445 | if (__first != __last) |
| 4446 | { |
| 4447 | _ForwardIterator __t; |
| 4448 | unsigned __sum = 0; |
| 4449 | int __hd; |
| 4450 | switch (*__first) |
| 4451 | { |
| 4452 | case 'f': |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 4453 | if (__str) |
| 4454 | *__str = _CharT(0xC); |
| 4455 | else |
| 4456 | __push_char(_CharT(0xC)); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4457 | ++__first; |
| 4458 | break; |
| 4459 | case 'n': |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 4460 | if (__str) |
| 4461 | *__str = _CharT(0xA); |
| 4462 | else |
| 4463 | __push_char(_CharT(0xA)); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4464 | ++__first; |
| 4465 | break; |
| 4466 | case 'r': |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 4467 | if (__str) |
| 4468 | *__str = _CharT(0xD); |
| 4469 | else |
| 4470 | __push_char(_CharT(0xD)); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4471 | ++__first; |
| 4472 | break; |
| 4473 | case 't': |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 4474 | if (__str) |
| 4475 | *__str = _CharT(0x9); |
| 4476 | else |
| 4477 | __push_char(_CharT(0x9)); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4478 | ++__first; |
| 4479 | break; |
| 4480 | case 'v': |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 4481 | if (__str) |
| 4482 | *__str = _CharT(0xB); |
| 4483 | else |
| 4484 | __push_char(_CharT(0xB)); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4485 | ++__first; |
| 4486 | break; |
| 4487 | case 'c': |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4488 | if ((__t = _VSTD::next(__first)) != __last) |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4489 | { |
Howard Hinnant | 2216140 | 2013-07-15 18:21:11 | [diff] [blame] | 4490 | if (('A' <= *__t && *__t <= 'Z') || |
| 4491 | ('a' <= *__t && *__t <= 'z')) |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4492 | { |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 4493 | if (__str) |
| 4494 | *__str = _CharT(*__t % 32); |
| 4495 | else |
| 4496 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4497 | __first = ++__t; |
| 4498 | } |
Howard Hinnant | 2216140 | 2013-07-15 18:21:11 | [diff] [blame] | 4499 | else |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4500 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4501 | } |
Howard Hinnant | 2216140 | 2013-07-15 18:21:11 | [diff] [blame] | 4502 | else |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4503 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4504 | break; |
| 4505 | case 'u': |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 4506 | ++__first; |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 4507 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4508 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4509 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4510 | if (__hd == -1) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4511 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | c206366 | 2011-12-01 20:21:04 | [diff] [blame] | 4512 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 4513 | ++__first; |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 4514 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4515 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4516 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4517 | if (__hd == -1) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4518 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | c206366 | 2011-12-01 20:21:04 | [diff] [blame] | 4519 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4520 | // drop through |
| 4521 | case 'x': |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 4522 | ++__first; |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 4523 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4524 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4525 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4526 | if (__hd == -1) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4527 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | c206366 | 2011-12-01 20:21:04 | [diff] [blame] | 4528 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 4529 | ++__first; |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 4530 | if (__first == __last) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4531 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4532 | __hd = __traits_.value(*__first, 16); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4533 | if (__hd == -1) |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4534 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | c206366 | 2011-12-01 20:21:04 | [diff] [blame] | 4535 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 4536 | if (__str) |
| 4537 | *__str = _CharT(__sum); |
| 4538 | else |
| 4539 | __push_char(_CharT(__sum)); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4540 | ++__first; |
| 4541 | break; |
Marshall Clow | 9393b51 | 2014-05-21 16:29:50 | [diff] [blame] | 4542 | case '0': |
| 4543 | if (__str) |
| 4544 | *__str = _CharT(0); |
| 4545 | else |
| 4546 | __push_char(_CharT(0)); |
| 4547 | ++__first; |
| 4548 | break; |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4549 | default: |
| 4550 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4551 | { |
Howard Hinnant | 6e156af | 2010-07-28 17:35:27 | [diff] [blame] | 4552 | if (__str) |
| 4553 | *__str = *__first; |
| 4554 | else |
| 4555 | __push_char(*__first); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4556 | ++__first; |
| 4557 | } |
Howard Hinnant | 21246e3 | 2013-06-28 18:57:30 | [diff] [blame] | 4558 | else |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 4559 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4560 | break; |
| 4561 | } |
| 4562 | } |
| 4563 | return __first; |
| 4564 | } |
| 4565 | |
| 4566 | template <class _CharT, class _Traits> |
| 4567 | template <class _ForwardIterator> |
| 4568 | _ForwardIterator |
| 4569 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4570 | _ForwardIterator __last) |
| 4571 | { |
| 4572 | if (__first != __last) |
| 4573 | { |
| 4574 | switch (*__first) |
| 4575 | { |
| 4576 | case '^': |
| 4577 | case '$': |
| 4578 | case '\\': |
| 4579 | case '.': |
| 4580 | case '*': |
| 4581 | case '+': |
| 4582 | case '?': |
| 4583 | case '(': |
| 4584 | case ')': |
| 4585 | case '[': |
| 4586 | case ']': |
| 4587 | case '{': |
| 4588 | case '}': |
| 4589 | case '|': |
| 4590 | break; |
| 4591 | default: |
| 4592 | __push_char(*__first); |
| 4593 | ++__first; |
| 4594 | break; |
| 4595 | } |
| 4596 | } |
| 4597 | return __first; |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4598 | } |
| 4599 | |
| 4600 | template <class _CharT, class _Traits> |
Howard Hinnant | 93da3b2 | 2010-07-27 19:53:10 | [diff] [blame] | 4601 | template <class _ForwardIterator> |
| 4602 | _ForwardIterator |
| 4603 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4604 | _ForwardIterator __last) |
| 4605 | { |
| 4606 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4607 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 93da3b2 | 2010-07-27 19:53:10 | [diff] [blame] | 4608 | if (__t1 != __first) |
| 4609 | __parse_basic_reg_exp(__first, __t1); |
| 4610 | else |
| 4611 | __push_empty(); |
| 4612 | __first = __t1; |
| 4613 | if (__first != __last) |
| 4614 | ++__first; |
| 4615 | while (__first != __last) |
| 4616 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4617 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 93da3b2 | 2010-07-27 19:53:10 | [diff] [blame] | 4618 | __owns_one_state<_CharT>* __sb = __end_; |
| 4619 | if (__t1 != __first) |
| 4620 | __parse_basic_reg_exp(__first, __t1); |
| 4621 | else |
| 4622 | __push_empty(); |
| 4623 | __push_alternation(__sa, __sb); |
| 4624 | __first = __t1; |
| 4625 | if (__first != __last) |
| 4626 | ++__first; |
| 4627 | } |
| 4628 | return __first; |
| 4629 | } |
| 4630 | |
| 4631 | template <class _CharT, class _Traits> |
| 4632 | template <class _ForwardIterator> |
| 4633 | _ForwardIterator |
| 4634 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4635 | _ForwardIterator __last) |
| 4636 | { |
| 4637 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4638 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 93da3b2 | 2010-07-27 19:53:10 | [diff] [blame] | 4639 | if (__t1 != __first) |
| 4640 | __parse_extended_reg_exp(__first, __t1); |
| 4641 | else |
| 4642 | __push_empty(); |
| 4643 | __first = __t1; |
| 4644 | if (__first != __last) |
| 4645 | ++__first; |
| 4646 | while (__first != __last) |
| 4647 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4648 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 93da3b2 | 2010-07-27 19:53:10 | [diff] [blame] | 4649 | __owns_one_state<_CharT>* __sb = __end_; |
| 4650 | if (__t1 != __first) |
| 4651 | __parse_extended_reg_exp(__first, __t1); |
| 4652 | else |
| 4653 | __push_empty(); |
| 4654 | __push_alternation(__sa, __sb); |
| 4655 | __first = __t1; |
| 4656 | if (__first != __last) |
| 4657 | ++__first; |
| 4658 | } |
| 4659 | return __first; |
| 4660 | } |
| 4661 | |
| 4662 | template <class _CharT, class _Traits> |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4663 | void |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 4664 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4665 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4666 | bool __greedy) |
| 4667 | { |
| 4668 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4669 | __end_->first() = nullptr; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 4670 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4671 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4672 | __min, __max)); |
| 4673 | __s->first() = nullptr; |
| 4674 | __e1.release(); |
| 4675 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 4676 | __end_ = __e2->second(); |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 4677 | __s->first() = __e2.release(); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 4678 | ++__loop_count_; |
| 4679 | } |
| 4680 | |
| 4681 | template <class _CharT, class _Traits> |
| 4682 | void |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4683 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4684 | { |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4685 | if (flags() & icase) |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 4686 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4687 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4688 | else if (flags() & collate) |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 4689 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4690 | (__traits_, __c, __end_->first()); |
| 4691 | else |
| 4692 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 4693 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4694 | } |
| 4695 | |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 4696 | template <class _CharT, class _Traits> |
| 4697 | void |
| 4698 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4699 | { |
Howard Hinnant | 5699358 | 2010-07-14 15:45:11 | [diff] [blame] | 4700 | if (!(__flags_ & nosubs)) |
| 4701 | { |
| 4702 | __end_->first() = |
| 4703 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4704 | __end_->first()); |
| 4705 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4706 | } |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | template <class _CharT, class _Traits> |
| 4710 | void |
| 4711 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4712 | { |
Howard Hinnant | 5699358 | 2010-07-14 15:45:11 | [diff] [blame] | 4713 | if (!(__flags_ & nosubs)) |
| 4714 | { |
| 4715 | __end_->first() = |
| 4716 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4717 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4718 | } |
Howard Hinnant | 928658c | 2010-06-30 20:30:19 | [diff] [blame] | 4719 | } |
| 4720 | |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 4721 | template <class _CharT, class _Traits> |
| 4722 | void |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 4723 | basic_regex<_CharT, _Traits>::__push_l_anchor() |
| 4724 | { |
| 4725 | __end_->first() = new __l_anchor<_CharT>(__end_->first()); |
| 4726 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4727 | } |
| 4728 | |
| 4729 | template <class _CharT, class _Traits> |
| 4730 | void |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 4731 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4732 | { |
| 4733 | __end_->first() = new __r_anchor<_CharT>(__end_->first()); |
| 4734 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4735 | } |
| 4736 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 4737 | template <class _CharT, class _Traits> |
| 4738 | void |
| 4739 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4740 | { |
| 4741 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4742 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4743 | } |
Howard Hinnant | 87ec03a | 2010-07-09 00:15:26 | [diff] [blame] | 4744 | |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 4745 | template <class _CharT, class _Traits> |
| 4746 | void |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4747 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4748 | { |
| 4749 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4750 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4751 | } |
| 4752 | |
| 4753 | template <class _CharT, class _Traits> |
| 4754 | void |
Howard Hinnant | f710943 | 2010-07-22 17:53:24 | [diff] [blame] | 4755 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4756 | { |
| 4757 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4758 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4759 | } |
| 4760 | |
| 4761 | template <class _CharT, class _Traits> |
| 4762 | void |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 4763 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4764 | { |
| 4765 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4766 | __end_->first()); |
| 4767 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4768 | } |
| 4769 | |
| 4770 | template <class _CharT, class _Traits> |
| 4771 | void |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 4772 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4773 | { |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4774 | if (flags() & icase) |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 4775 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4776 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4777 | else if (flags() & collate) |
Howard Hinnant | fdec08bd | 2010-07-12 19:11:27 | [diff] [blame] | 4778 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4779 | (__traits_, __i, __end_->first()); |
| 4780 | else |
| 4781 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 4782 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4783 | } |
| 4784 | |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4785 | template <class _CharT, class _Traits> |
Howard Hinnant | c1198c3 | 2010-07-16 19:08:36 | [diff] [blame] | 4786 | void |
| 4787 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4788 | __owns_one_state<_CharT>* __ea) |
| 4789 | { |
| 4790 | __sa->first() = new __alternate<_CharT>( |
| 4791 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4792 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4793 | __ea->first() = nullptr; |
| 4794 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4795 | __end_->first() = nullptr; |
| 4796 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4797 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4798 | } |
| 4799 | |
| 4800 | template <class _CharT, class _Traits> |
Howard Hinnant | 8ab959c | 2010-07-13 21:48:06 | [diff] [blame] | 4801 | __bracket_expression<_CharT, _Traits>* |
| 4802 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4803 | { |
| 4804 | __bracket_expression<_CharT, _Traits>* __r = |
| 4805 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4806 | __negate, __flags_ & icase, |
| 4807 | __flags_ & collate); |
| 4808 | __end_->first() = __r; |
| 4809 | __end_ = __r; |
| 4810 | return __r; |
| 4811 | } |
| 4812 | |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 4813 | template <class _CharT, class _Traits> |
| 4814 | void |
| 4815 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
Howard Hinnant | 7491a16 | 2013-07-23 16:18:04 | [diff] [blame] | 4816 | bool __invert, |
| 4817 | unsigned __mexp) |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 4818 | { |
| 4819 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
Howard Hinnant | 7491a16 | 2013-07-23 16:18:04 | [diff] [blame] | 4820 | __end_->first(), __mexp); |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 4821 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4822 | } |
| 4823 | |
Howard Hinnant | 24e9848 | 2010-06-24 21:28:00 | [diff] [blame] | 4824 | typedef basic_regex<char> regex; |
| 4825 | typedef basic_regex<wchar_t> wregex; |
| 4826 | |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4827 | // sub_match |
| 4828 | |
| 4829 | template <class _BidirectionalIterator> |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 4830 | class _LIBCPP_TEMPLATE_VIS sub_match |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4831 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4832 | { |
| 4833 | public: |
| 4834 | typedef _BidirectionalIterator iterator; |
| 4835 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4836 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4837 | typedef basic_string<value_type> string_type; |
| 4838 | |
| 4839 | bool matched; |
| 4840 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 4841 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 42be98a | 2012-07-21 01:31:58 | [diff] [blame] | 4842 | _LIBCPP_CONSTEXPR sub_match() : matched() {} |
Howard Hinnant | 966b5a3 | 2010-12-08 21:07:55 | [diff] [blame] | 4843 | |
| 4844 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4845 | difference_type length() const |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 4846 | {return matched ? _VSTD::distance(this->first, this->second) : 0;} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 4847 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4848 | string_type str() const |
| 4849 | {return matched ? string_type(this->first, this->second) : string_type();} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 4850 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4851 | operator string_type() const |
| 4852 | {return str();} |
| 4853 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 4854 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4855 | int compare(const sub_match& __s) const |
| 4856 | {return str().compare(__s.str());} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 4857 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4858 | int compare(const string_type& __s) const |
| 4859 | {return str().compare(__s);} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 4860 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4861 | int compare(const value_type* __s) const |
| 4862 | {return str().compare(__s);} |
| 4863 | }; |
| 4864 | |
| 4865 | typedef sub_match<const char*> csub_match; |
| 4866 | typedef sub_match<const wchar_t*> wcsub_match; |
| 4867 | typedef sub_match<string::const_iterator> ssub_match; |
| 4868 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 4869 | |
| 4870 | template <class _BiIter> |
| 4871 | inline _LIBCPP_INLINE_VISIBILITY |
| 4872 | bool |
| 4873 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4874 | { |
| 4875 | return __x.compare(__y) == 0; |
| 4876 | } |
| 4877 | |
| 4878 | template <class _BiIter> |
| 4879 | inline _LIBCPP_INLINE_VISIBILITY |
| 4880 | bool |
| 4881 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4882 | { |
| 4883 | return !(__x == __y); |
| 4884 | } |
| 4885 | |
| 4886 | template <class _BiIter> |
| 4887 | inline _LIBCPP_INLINE_VISIBILITY |
| 4888 | bool |
| 4889 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4890 | { |
| 4891 | return __x.compare(__y) < 0; |
| 4892 | } |
| 4893 | |
| 4894 | template <class _BiIter> |
| 4895 | inline _LIBCPP_INLINE_VISIBILITY |
| 4896 | bool |
| 4897 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4898 | { |
| 4899 | return !(__y < __x); |
| 4900 | } |
| 4901 | |
| 4902 | template <class _BiIter> |
| 4903 | inline _LIBCPP_INLINE_VISIBILITY |
| 4904 | bool |
| 4905 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4906 | { |
| 4907 | return !(__x < __y); |
| 4908 | } |
| 4909 | |
| 4910 | template <class _BiIter> |
| 4911 | inline _LIBCPP_INLINE_VISIBILITY |
| 4912 | bool |
| 4913 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4914 | { |
| 4915 | return __y < __x; |
| 4916 | } |
| 4917 | |
| 4918 | template <class _BiIter, class _ST, class _SA> |
| 4919 | inline _LIBCPP_INLINE_VISIBILITY |
| 4920 | bool |
| 4921 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4922 | const sub_match<_BiIter>& __y) |
| 4923 | { |
Marshall Clow | b04058e | 2014-12-15 23:57:56 | [diff] [blame] | 4924 | return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | template <class _BiIter, class _ST, class _SA> |
| 4928 | inline _LIBCPP_INLINE_VISIBILITY |
| 4929 | bool |
| 4930 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4931 | const sub_match<_BiIter>& __y) |
| 4932 | { |
| 4933 | return !(__x == __y); |
| 4934 | } |
| 4935 | |
| 4936 | template <class _BiIter, class _ST, class _SA> |
| 4937 | inline _LIBCPP_INLINE_VISIBILITY |
| 4938 | bool |
| 4939 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4940 | const sub_match<_BiIter>& __y) |
| 4941 | { |
Marshall Clow | b04058e | 2014-12-15 23:57:56 | [diff] [blame] | 4942 | return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4943 | } |
| 4944 | |
| 4945 | template <class _BiIter, class _ST, class _SA> |
| 4946 | inline _LIBCPP_INLINE_VISIBILITY |
| 4947 | bool |
| 4948 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4949 | const sub_match<_BiIter>& __y) |
| 4950 | { |
| 4951 | return __y < __x; |
| 4952 | } |
| 4953 | |
| 4954 | template <class _BiIter, class _ST, class _SA> |
| 4955 | inline _LIBCPP_INLINE_VISIBILITY |
| 4956 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4957 | const sub_match<_BiIter>& __y) |
| 4958 | { |
| 4959 | return !(__x < __y); |
| 4960 | } |
| 4961 | |
| 4962 | template <class _BiIter, class _ST, class _SA> |
| 4963 | inline _LIBCPP_INLINE_VISIBILITY |
| 4964 | bool |
| 4965 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4966 | const sub_match<_BiIter>& __y) |
| 4967 | { |
| 4968 | return !(__y < __x); |
| 4969 | } |
| 4970 | |
| 4971 | template <class _BiIter, class _ST, class _SA> |
| 4972 | inline _LIBCPP_INLINE_VISIBILITY |
| 4973 | bool |
| 4974 | operator==(const sub_match<_BiIter>& __x, |
| 4975 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4976 | { |
Marshall Clow | b04058e | 2014-12-15 23:57:56 | [diff] [blame] | 4977 | return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4978 | } |
| 4979 | |
| 4980 | template <class _BiIter, class _ST, class _SA> |
| 4981 | inline _LIBCPP_INLINE_VISIBILITY |
| 4982 | bool |
| 4983 | operator!=(const sub_match<_BiIter>& __x, |
| 4984 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4985 | { |
| 4986 | return !(__x == __y); |
| 4987 | } |
| 4988 | |
| 4989 | template <class _BiIter, class _ST, class _SA> |
| 4990 | inline _LIBCPP_INLINE_VISIBILITY |
| 4991 | bool |
| 4992 | operator<(const sub_match<_BiIter>& __x, |
| 4993 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4994 | { |
Marshall Clow | b04058e | 2014-12-15 23:57:56 | [diff] [blame] | 4995 | return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0; |
Howard Hinnant | e5561b0 | 2010-06-29 18:37:43 | [diff] [blame] | 4996 | } |
| 4997 | |
| 4998 | template <class _BiIter, class _ST, class _SA> |
| 4999 | inline _LIBCPP_INLINE_VISIBILITY |
| 5000 | bool operator>(const sub_match<_BiIter>& __x, |
| 5001 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5002 | { |
| 5003 | return __y < __x; |
| 5004 | } |
| 5005 | |
| 5006 | template <class _BiIter, class _ST, class _SA> |
| 5007 | inline _LIBCPP_INLINE_VISIBILITY |
| 5008 | bool |
| 5009 | operator>=(const sub_match<_BiIter>& __x, |
| 5010 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5011 | { |
| 5012 | return !(__x < __y); |
| 5013 | } |
| 5014 | |
| 5015 | template <class _BiIter, class _ST, class _SA> |
| 5016 | inline _LIBCPP_INLINE_VISIBILITY |
| 5017 | bool |
| 5018 | operator<=(const sub_match<_BiIter>& __x, |
| 5019 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5020 | { |
| 5021 | return !(__y < __x); |
| 5022 | } |
| 5023 | |
| 5024 | template <class _BiIter> |
| 5025 | inline _LIBCPP_INLINE_VISIBILITY |
| 5026 | bool |
| 5027 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5028 | const sub_match<_BiIter>& __y) |
| 5029 | { |
| 5030 | return __y.compare(__x) == 0; |
| 5031 | } |
| 5032 | |
| 5033 | template <class _BiIter> |
| 5034 | inline _LIBCPP_INLINE_VISIBILITY |
| 5035 | bool |
| 5036 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5037 | const sub_match<_BiIter>& __y) |
| 5038 | { |
| 5039 | return !(__x == __y); |
| 5040 | } |
| 5041 | |
| 5042 | template <class _BiIter> |
| 5043 | inline _LIBCPP_INLINE_VISIBILITY |
| 5044 | bool |
| 5045 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5046 | const sub_match<_BiIter>& __y) |
| 5047 | { |
| 5048 | return __y.compare(__x) > 0; |
| 5049 | } |
| 5050 | |
| 5051 | template <class _BiIter> |
| 5052 | inline _LIBCPP_INLINE_VISIBILITY |
| 5053 | bool |
| 5054 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5055 | const sub_match<_BiIter>& __y) |
| 5056 | { |
| 5057 | return __y < __x; |
| 5058 | } |
| 5059 | |
| 5060 | template <class _BiIter> |
| 5061 | inline _LIBCPP_INLINE_VISIBILITY |
| 5062 | bool |
| 5063 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5064 | const sub_match<_BiIter>& __y) |
| 5065 | { |
| 5066 | return !(__x < __y); |
| 5067 | } |
| 5068 | |
| 5069 | template <class _BiIter> |
| 5070 | inline _LIBCPP_INLINE_VISIBILITY |
| 5071 | bool |
| 5072 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5073 | const sub_match<_BiIter>& __y) |
| 5074 | { |
| 5075 | return !(__y < __x); |
| 5076 | } |
| 5077 | |
| 5078 | template <class _BiIter> |
| 5079 | inline _LIBCPP_INLINE_VISIBILITY |
| 5080 | bool |
| 5081 | operator==(const sub_match<_BiIter>& __x, |
| 5082 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5083 | { |
| 5084 | return __x.compare(__y) == 0; |
| 5085 | } |
| 5086 | |
| 5087 | template <class _BiIter> |
| 5088 | inline _LIBCPP_INLINE_VISIBILITY |
| 5089 | bool |
| 5090 | operator!=(const sub_match<_BiIter>& __x, |
| 5091 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5092 | { |
| 5093 | return !(__x == __y); |
| 5094 | } |
| 5095 | |
| 5096 | template <class _BiIter> |
| 5097 | inline _LIBCPP_INLINE_VISIBILITY |
| 5098 | bool |
| 5099 | operator<(const sub_match<_BiIter>& __x, |
| 5100 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5101 | { |
| 5102 | return __x.compare(__y) < 0; |
| 5103 | } |
| 5104 | |
| 5105 | template <class _BiIter> |
| 5106 | inline _LIBCPP_INLINE_VISIBILITY |
| 5107 | bool |
| 5108 | operator>(const sub_match<_BiIter>& __x, |
| 5109 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5110 | { |
| 5111 | return __y < __x; |
| 5112 | } |
| 5113 | |
| 5114 | template <class _BiIter> |
| 5115 | inline _LIBCPP_INLINE_VISIBILITY |
| 5116 | bool |
| 5117 | operator>=(const sub_match<_BiIter>& __x, |
| 5118 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5119 | { |
| 5120 | return !(__x < __y); |
| 5121 | } |
| 5122 | |
| 5123 | template <class _BiIter> |
| 5124 | inline _LIBCPP_INLINE_VISIBILITY |
| 5125 | bool |
| 5126 | operator<=(const sub_match<_BiIter>& __x, |
| 5127 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5128 | { |
| 5129 | return !(__y < __x); |
| 5130 | } |
| 5131 | |
| 5132 | template <class _BiIter> |
| 5133 | inline _LIBCPP_INLINE_VISIBILITY |
| 5134 | bool |
| 5135 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5136 | const sub_match<_BiIter>& __y) |
| 5137 | { |
| 5138 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5139 | return __y.compare(string_type(1, __x)) == 0; |
| 5140 | } |
| 5141 | |
| 5142 | template <class _BiIter> |
| 5143 | inline _LIBCPP_INLINE_VISIBILITY |
| 5144 | bool |
| 5145 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5146 | const sub_match<_BiIter>& __y) |
| 5147 | { |
| 5148 | return !(__x == __y); |
| 5149 | } |
| 5150 | |
| 5151 | template <class _BiIter> |
| 5152 | inline _LIBCPP_INLINE_VISIBILITY |
| 5153 | bool |
| 5154 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5155 | const sub_match<_BiIter>& __y) |
| 5156 | { |
| 5157 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5158 | return __y.compare(string_type(1, __x)) > 0; |
| 5159 | } |
| 5160 | |
| 5161 | template <class _BiIter> |
| 5162 | inline _LIBCPP_INLINE_VISIBILITY |
| 5163 | bool |
| 5164 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5165 | const sub_match<_BiIter>& __y) |
| 5166 | { |
| 5167 | return __y < __x; |
| 5168 | } |
| 5169 | |
| 5170 | template <class _BiIter> |
| 5171 | inline _LIBCPP_INLINE_VISIBILITY |
| 5172 | bool |
| 5173 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5174 | const sub_match<_BiIter>& __y) |
| 5175 | { |
| 5176 | return !(__x < __y); |
| 5177 | } |
| 5178 | |
| 5179 | template <class _BiIter> |
| 5180 | inline _LIBCPP_INLINE_VISIBILITY |
| 5181 | bool |
| 5182 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5183 | const sub_match<_BiIter>& __y) |
| 5184 | { |
| 5185 | return !(__y < __x); |
| 5186 | } |
| 5187 | |
| 5188 | template <class _BiIter> |
| 5189 | inline _LIBCPP_INLINE_VISIBILITY |
| 5190 | bool |
| 5191 | operator==(const sub_match<_BiIter>& __x, |
| 5192 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5193 | { |
| 5194 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5195 | return __x.compare(string_type(1, __y)) == 0; |
| 5196 | } |
| 5197 | |
| 5198 | template <class _BiIter> |
| 5199 | inline _LIBCPP_INLINE_VISIBILITY |
| 5200 | bool |
| 5201 | operator!=(const sub_match<_BiIter>& __x, |
| 5202 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5203 | { |
| 5204 | return !(__x == __y); |
| 5205 | } |
| 5206 | |
| 5207 | template <class _BiIter> |
| 5208 | inline _LIBCPP_INLINE_VISIBILITY |
| 5209 | bool |
| 5210 | operator<(const sub_match<_BiIter>& __x, |
| 5211 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5212 | { |
| 5213 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5214 | return __x.compare(string_type(1, __y)) < 0; |
| 5215 | } |
| 5216 | |
| 5217 | template <class _BiIter> |
| 5218 | inline _LIBCPP_INLINE_VISIBILITY |
| 5219 | bool |
| 5220 | operator>(const sub_match<_BiIter>& __x, |
| 5221 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5222 | { |
| 5223 | return __y < __x; |
| 5224 | } |
| 5225 | |
| 5226 | template <class _BiIter> |
| 5227 | inline _LIBCPP_INLINE_VISIBILITY |
| 5228 | bool |
| 5229 | operator>=(const sub_match<_BiIter>& __x, |
| 5230 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5231 | { |
| 5232 | return !(__x < __y); |
| 5233 | } |
| 5234 | |
| 5235 | template <class _BiIter> |
| 5236 | inline _LIBCPP_INLINE_VISIBILITY |
| 5237 | bool |
| 5238 | operator<=(const sub_match<_BiIter>& __x, |
| 5239 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5240 | { |
| 5241 | return !(__y < __x); |
| 5242 | } |
| 5243 | |
| 5244 | template <class _CharT, class _ST, class _BiIter> |
| 5245 | inline _LIBCPP_INLINE_VISIBILITY |
| 5246 | basic_ostream<_CharT, _ST>& |
| 5247 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 5248 | { |
| 5249 | return __os << __m.str(); |
| 5250 | } |
| 5251 | |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5252 | template <class _BidirectionalIterator, class _Allocator> |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 5253 | class _LIBCPP_TEMPLATE_VIS match_results |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5254 | { |
| 5255 | public: |
| 5256 | typedef _Allocator allocator_type; |
| 5257 | typedef sub_match<_BidirectionalIterator> value_type; |
| 5258 | private: |
| 5259 | typedef vector<value_type, allocator_type> __container_type; |
| 5260 | |
| 5261 | __container_type __matches_; |
| 5262 | value_type __unmatched_; |
| 5263 | value_type __prefix_; |
| 5264 | value_type __suffix_; |
Howard Hinnant | 966b5a3 | 2010-12-08 21:07:55 | [diff] [blame] | 5265 | bool __ready_; |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5266 | public: |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 5267 | _BidirectionalIterator __position_start_; |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5268 | typedef const value_type& const_reference; |
Marshall Clow | 16da324 | 2014-02-26 01:56:31 | [diff] [blame] | 5269 | typedef value_type& reference; |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5270 | typedef typename __container_type::const_iterator const_iterator; |
| 5271 | typedef const_iterator iterator; |
| 5272 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5273 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5274 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5275 | typedef basic_string<char_type> string_type; |
| 5276 | |
| 5277 | // construct/copy/destroy: |
| 5278 | explicit match_results(const allocator_type& __a = allocator_type()); |
| 5279 | // match_results(const match_results&) = default; |
| 5280 | // match_results& operator=(const match_results&) = default; |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5281 | // match_results(match_results&& __m) = default; |
| 5282 | // match_results& operator=(match_results&& __m) = default; |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5283 | // ~match_results() = default; |
| 5284 | |
Howard Hinnant | 966b5a3 | 2010-12-08 21:07:55 | [diff] [blame] | 5285 | _LIBCPP_INLINE_VISIBILITY |
| 5286 | bool ready() const {return __ready_;} |
| 5287 | |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5288 | // size: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5289 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 80ebbb1 | 2017-11-16 04:48:34 | [diff] [blame] | 5290 | size_type size() const _NOEXCEPT {return __matches_.size();} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5291 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 80ebbb1 | 2017-11-16 04:48:34 | [diff] [blame] | 5292 | size_type max_size() const _NOEXCEPT {return __matches_.max_size();} |
| 5293 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 5294 | bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5295 | |
| 5296 | // element access: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5297 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5298 | difference_type length(size_type __sub = 0) const |
Marshall Clow | c29db2d83 | 2019-04-26 17:10:03 | [diff] [blame^] | 5299 | { |
| 5300 | _LIBCPP_ASSERT(ready(), "match_results::length() called when not ready"); |
| 5301 | return (*this)[__sub].length(); |
| 5302 | } |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5303 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5304 | difference_type position(size_type __sub = 0) const |
Marshall Clow | c29db2d83 | 2019-04-26 17:10:03 | [diff] [blame^] | 5305 | { |
| 5306 | _LIBCPP_ASSERT(ready(), "match_results::position() called when not ready"); |
| 5307 | return _VSTD::distance(__position_start_, (*this)[__sub].first); |
| 5308 | } |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5309 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5310 | string_type str(size_type __sub = 0) const |
Marshall Clow | c29db2d83 | 2019-04-26 17:10:03 | [diff] [blame^] | 5311 | { |
| 5312 | _LIBCPP_ASSERT(ready(), "match_results::str() called when not ready"); |
| 5313 | return (*this)[__sub].str(); |
| 5314 | } |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5315 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5316 | const_reference operator[](size_type __n) const |
Marshall Clow | c29db2d83 | 2019-04-26 17:10:03 | [diff] [blame^] | 5317 | { |
| 5318 | _LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready"); |
| 5319 | return __n < __matches_.size() ? __matches_[__n] : __unmatched_; |
| 5320 | } |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5321 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5322 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | c29db2d83 | 2019-04-26 17:10:03 | [diff] [blame^] | 5323 | const_reference prefix() const |
| 5324 | { |
| 5325 | _LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready"); |
| 5326 | return __prefix_; |
| 5327 | } |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5328 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | c29db2d83 | 2019-04-26 17:10:03 | [diff] [blame^] | 5329 | const_reference suffix() const |
| 5330 | { |
| 5331 | _LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready"); |
| 5332 | return __suffix_; |
| 5333 | } |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5334 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5335 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2a4812f | 2011-10-08 14:36:16 | [diff] [blame] | 5336 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5337 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5338 | const_iterator end() const {return __matches_.end();} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5339 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2a4812f | 2011-10-08 14:36:16 | [diff] [blame] | 5340 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5341 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5342 | const_iterator cend() const {return __matches_.end();} |
| 5343 | |
| 5344 | // format: |
| 5345 | template <class _OutputIter> |
| 5346 | _OutputIter |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5347 | format(_OutputIter __output_iter, const char_type* __fmt_first, |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5348 | const char_type* __fmt_last, |
| 5349 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5350 | template <class _OutputIter, class _ST, class _SA> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5351 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5352 | _OutputIter |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5353 | format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5354 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5355 | {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5356 | template <class _ST, class _SA> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5357 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5358 | basic_string<char_type, _ST, _SA> |
| 5359 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5360 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5361 | { |
| 5362 | basic_string<char_type, _ST, _SA> __r; |
| 5363 | format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), |
| 5364 | __flags); |
| 5365 | return __r; |
| 5366 | } |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5367 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5368 | string_type |
| 5369 | format(const char_type* __fmt, |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5370 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5371 | { |
| 5372 | string_type __r; |
| 5373 | format(back_inserter(__r), __fmt, |
| 5374 | __fmt + char_traits<char_type>::length(__fmt), __flags); |
| 5375 | return __r; |
| 5376 | } |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5377 | |
| 5378 | // allocator: |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5379 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5380 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5381 | |
| 5382 | // swap: |
| 5383 | void swap(match_results& __m); |
| 5384 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 5385 | template <class _Bp, class _Ap> |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 5386 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5387 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 5388 | const match_results<_Bp, _Ap>& __m, bool __no_update_pos) |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5389 | { |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 5390 | _Bp __mf = __m.prefix().first; |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5391 | __matches_.resize(__m.size()); |
| 5392 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5393 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 5394 | __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); |
| 5395 | __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5396 | __matches_[__i].matched = __m[__i].matched; |
| 5397 | } |
| 5398 | __unmatched_.first = __l; |
| 5399 | __unmatched_.second = __l; |
| 5400 | __unmatched_.matched = false; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 5401 | __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); |
| 5402 | __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5403 | __prefix_.matched = __m.prefix().matched; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 5404 | __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); |
| 5405 | __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5406 | __suffix_.matched = __m.suffix().matched; |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 5407 | if (!__no_update_pos) |
| 5408 | __position_start_ = __prefix_.first; |
Howard Hinnant | 966b5a3 | 2010-12-08 21:07:55 | [diff] [blame] | 5409 | __ready_ = __m.ready(); |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5410 | } |
| 5411 | |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5412 | private: |
| 5413 | void __init(unsigned __s, |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 5414 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5415 | bool __no_update_pos = false); |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5416 | |
| 5417 | template <class, class> friend class basic_regex; |
| 5418 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 5419 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5420 | friend |
| 5421 | bool |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 5422 | regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5423 | regex_constants::match_flag_type); |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 5424 | |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 5425 | template <class _Bp, class _Ap> |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5426 | friend |
| 5427 | bool |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 5428 | operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&); |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5429 | |
Howard Hinnant | c112430 | 2010-07-27 22:20:32 | [diff] [blame] | 5430 | template <class, class> friend class __lookahead; |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5431 | }; |
| 5432 | |
| 5433 | template <class _BidirectionalIterator, class _Allocator> |
| 5434 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5435 | const allocator_type& __a) |
| 5436 | : __matches_(__a), |
| 5437 | __unmatched_(), |
| 5438 | __prefix_(), |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 5439 | __suffix_(), |
Eric Fiselier | b50f8f9 | 2015-07-22 01:29:41 | [diff] [blame] | 5440 | __ready_(false), |
| 5441 | __position_start_() |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5442 | { |
| 5443 | } |
| 5444 | |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5445 | template <class _BidirectionalIterator, class _Allocator> |
| 5446 | void |
| 5447 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 5448 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5449 | bool __no_update_pos) |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5450 | { |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5451 | __unmatched_.first = __l; |
| 5452 | __unmatched_.second = __l; |
| 5453 | __unmatched_.matched = false; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5454 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5455 | __prefix_.first = __f; |
| 5456 | __prefix_.second = __f; |
| 5457 | __prefix_.matched = false; |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5458 | __suffix_ = __unmatched_; |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 5459 | if (!__no_update_pos) |
| 5460 | __position_start_ = __prefix_.first; |
Howard Hinnant | 966b5a3 | 2010-12-08 21:07:55 | [diff] [blame] | 5461 | __ready_ = true; |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5462 | } |
| 5463 | |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5464 | template <class _BidirectionalIterator, class _Allocator> |
| 5465 | template <class _OutputIter> |
| 5466 | _OutputIter |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5467 | match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter, |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5468 | const char_type* __fmt_first, const char_type* __fmt_last, |
| 5469 | regex_constants::match_flag_type __flags) const |
| 5470 | { |
Marshall Clow | c29db2d83 | 2019-04-26 17:10:03 | [diff] [blame^] | 5471 | _LIBCPP_ASSERT(ready(), "match_results::format() called when not ready"); |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5472 | if (__flags & regex_constants::format_sed) |
| 5473 | { |
| 5474 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5475 | { |
| 5476 | if (*__fmt_first == '&') |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5477 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 5478 | __output_iter); |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5479 | else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) |
| 5480 | { |
| 5481 | ++__fmt_first; |
| 5482 | if ('0' <= *__fmt_first && *__fmt_first <= '9') |
| 5483 | { |
| 5484 | size_t __i = *__fmt_first - '0'; |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5485 | __output_iter = _VSTD::copy((*this)[__i].first, |
| 5486 | (*this)[__i].second, __output_iter); |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5487 | } |
| 5488 | else |
| 5489 | { |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5490 | *__output_iter = *__fmt_first; |
| 5491 | ++__output_iter; |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5492 | } |
| 5493 | } |
| 5494 | else |
| 5495 | { |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5496 | *__output_iter = *__fmt_first; |
| 5497 | ++__output_iter; |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5498 | } |
| 5499 | } |
| 5500 | } |
| 5501 | else |
| 5502 | { |
| 5503 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5504 | { |
| 5505 | if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) |
| 5506 | { |
| 5507 | switch (__fmt_first[1]) |
| 5508 | { |
| 5509 | case '$': |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5510 | *__output_iter = *++__fmt_first; |
| 5511 | ++__output_iter; |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5512 | break; |
| 5513 | case '&': |
| 5514 | ++__fmt_first; |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5515 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 5516 | __output_iter); |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5517 | break; |
| 5518 | case '`': |
| 5519 | ++__fmt_first; |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5520 | __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter); |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5521 | break; |
| 5522 | case '\'': |
| 5523 | ++__fmt_first; |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5524 | __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter); |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5525 | break; |
| 5526 | default: |
| 5527 | if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5528 | { |
| 5529 | ++__fmt_first; |
Marshall Clow | 55b9e44 | 2017-10-19 22:10:41 | [diff] [blame] | 5530 | size_t __idx = *__fmt_first - '0'; |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5531 | if (__fmt_first + 1 != __fmt_last && |
| 5532 | '0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5533 | { |
| 5534 | ++__fmt_first; |
Marshall Clow | 55b9e44 | 2017-10-19 22:10:41 | [diff] [blame] | 5535 | if (__idx >= std::numeric_limits<size_t>::max() / 10) |
| 5536 | __throw_regex_error<regex_constants::error_escape>(); |
| 5537 | __idx = 10 * __idx + *__fmt_first - '0'; |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5538 | } |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5539 | __output_iter = _VSTD::copy((*this)[__idx].first, |
| 5540 | (*this)[__idx].second, __output_iter); |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5541 | } |
| 5542 | else |
| 5543 | { |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5544 | *__output_iter = *__fmt_first; |
| 5545 | ++__output_iter; |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5546 | } |
| 5547 | break; |
| 5548 | } |
| 5549 | } |
| 5550 | else |
| 5551 | { |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5552 | *__output_iter = *__fmt_first; |
| 5553 | ++__output_iter; |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5554 | } |
| 5555 | } |
| 5556 | } |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 5557 | return __output_iter; |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5558 | } |
| 5559 | |
| 5560 | template <class _BidirectionalIterator, class _Allocator> |
| 5561 | void |
| 5562 | match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) |
| 5563 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 5564 | using _VSTD::swap; |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5565 | swap(__matches_, __m.__matches_); |
| 5566 | swap(__unmatched_, __m.__unmatched_); |
| 5567 | swap(__prefix_, __m.__prefix_); |
| 5568 | swap(__suffix_, __m.__suffix_); |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 5569 | swap(__position_start_, __m.__position_start_); |
Howard Hinnant | 966b5a3 | 2010-12-08 21:07:55 | [diff] [blame] | 5570 | swap(__ready_, __m.__ready_); |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5571 | } |
| 5572 | |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5573 | typedef match_results<const char*> cmatch; |
| 5574 | typedef match_results<const wchar_t*> wcmatch; |
| 5575 | typedef match_results<string::const_iterator> smatch; |
| 5576 | typedef match_results<wstring::const_iterator> wsmatch; |
| 5577 | |
| 5578 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5579 | bool |
| 5580 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5581 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5582 | { |
Howard Hinnant | 966b5a3 | 2010-12-08 21:07:55 | [diff] [blame] | 5583 | if (__x.__ready_ != __y.__ready_) |
| 5584 | return false; |
| 5585 | if (!__x.__ready_) |
| 5586 | return true; |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5587 | return __x.__matches_ == __y.__matches_ && |
| 5588 | __x.__prefix_ == __y.__prefix_ && |
Howard Hinnant | 966b5a3 | 2010-12-08 21:07:55 | [diff] [blame] | 5589 | __x.__suffix_ == __y.__suffix_; |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5590 | } |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5591 | |
| 5592 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5593 | inline _LIBCPP_INLINE_VISIBILITY |
| 5594 | bool |
| 5595 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5596 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5597 | { |
| 5598 | return !(__x == __y); |
| 5599 | } |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5600 | |
| 5601 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 48b242a | 2010-08-14 18:14:02 | [diff] [blame] | 5602 | inline _LIBCPP_INLINE_VISIBILITY |
| 5603 | void |
| 5604 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5605 | match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5606 | { |
| 5607 | __x.swap(__y); |
| 5608 | } |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5609 | |
| 5610 | // regex_search |
| 5611 | |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5612 | template <class _CharT, class _Traits> |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5613 | template <class _Allocator> |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5614 | bool |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5615 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5616 | const _CharT* __first, const _CharT* __last, |
| 5617 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 5618 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5619 | { |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5620 | vector<__state> __states; |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5621 | __node* __st = __start_.get(); |
| 5622 | if (__st) |
| 5623 | { |
Marshall Clow | 538fec0 | 2015-01-28 22:22:35 | [diff] [blame] | 5624 | sub_match<const _CharT*> __unmatched; |
| 5625 | __unmatched.first = __last; |
| 5626 | __unmatched.second = __last; |
| 5627 | __unmatched.matched = false; |
| 5628 | |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5629 | __states.push_back(__state()); |
| 5630 | __states.back().__do_ = 0; |
| 5631 | __states.back().__first_ = __first; |
| 5632 | __states.back().__current_ = __first; |
| 5633 | __states.back().__last_ = __last; |
Marshall Clow | 538fec0 | 2015-01-28 22:22:35 | [diff] [blame] | 5634 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5635 | __states.back().__loop_data_.resize(__loop_count()); |
| 5636 | __states.back().__node_ = __st; |
| 5637 | __states.back().__flags_ = __flags; |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 5638 | __states.back().__at_first_ = __at_first; |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 | [diff] [blame] | 5639 | int __counter = 0; |
| 5640 | int __length = __last - __first; |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5641 | do |
| 5642 | { |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 | [diff] [blame] | 5643 | ++__counter; |
| 5644 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5645 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5646 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5647 | __state& __s = __states.back(); |
| 5648 | if (__s.__node_) |
| 5649 | __s.__node_->__exec(__s); |
| 5650 | switch (__s.__do_) |
| 5651 | { |
| 5652 | case __state::__end_state: |
Tim Shen | e776667 | 2016-10-27 21:40:34 | [diff] [blame] | 5653 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | abd1a6e | 2016-10-21 20:41:47 | [diff] [blame] | 5654 | __s.__current_ == __first) |
| 5655 | { |
| 5656 | __states.pop_back(); |
| 5657 | break; |
| 5658 | } |
Tim Shen | e776667 | 2016-10-27 21:40:34 | [diff] [blame] | 5659 | if ((__flags & regex_constants::__full_match) && |
| 5660 | __s.__current_ != __last) |
| 5661 | { |
| 5662 | __states.pop_back(); |
| 5663 | break; |
| 5664 | } |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5665 | __m.__matches_[0].first = __first; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 5666 | __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5667 | __m.__matches_[0].matched = true; |
| 5668 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5669 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5670 | return true; |
| 5671 | case __state::__accept_and_consume: |
| 5672 | case __state::__repeat: |
| 5673 | case __state::__accept_but_not_consume: |
| 5674 | break; |
| 5675 | case __state::__split: |
| 5676 | { |
| 5677 | __state __snext = __s; |
| 5678 | __s.__node_->__exec_split(true, __s); |
| 5679 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 5680 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5681 | } |
| 5682 | break; |
| 5683 | case __state::__reject: |
| 5684 | __states.pop_back(); |
| 5685 | break; |
| 5686 | default: |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 5687 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5688 | break; |
Howard Hinnant | 54b409f | 2010-08-11 17:04:31 | [diff] [blame] | 5689 | |
Howard Hinnant | 5c67986 | 2010-07-27 01:25:38 | [diff] [blame] | 5690 | } |
| 5691 | } while (!__states.empty()); |
| 5692 | } |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5693 | return false; |
| 5694 | } |
| 5695 | |
| 5696 | template <class _CharT, class _Traits> |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5697 | template <class _Allocator> |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5698 | bool |
| 5699 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5700 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5701 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 5702 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5703 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5704 | deque<__state> __states; |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5705 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 5706 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5707 | __node* __st = __start_.get(); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5708 | if (__st) |
| 5709 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5710 | __states.push_back(__state()); |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5711 | __states.back().__do_ = 0; |
| 5712 | __states.back().__first_ = __first; |
| 5713 | __states.back().__current_ = __first; |
| 5714 | __states.back().__last_ = __last; |
| 5715 | __states.back().__loop_data_.resize(__loop_count()); |
| 5716 | __states.back().__node_ = __st; |
| 5717 | __states.back().__flags_ = __flags; |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 5718 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 5699358 | 2010-07-14 15:45:11 | [diff] [blame] | 5719 | bool __matched = false; |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 | [diff] [blame] | 5720 | int __counter = 0; |
| 5721 | int __length = __last - __first; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5722 | do |
| 5723 | { |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 | [diff] [blame] | 5724 | ++__counter; |
| 5725 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5726 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5727 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5728 | __state& __s = __states.back(); |
| 5729 | if (__s.__node_) |
| 5730 | __s.__node_->__exec(__s); |
| 5731 | switch (__s.__do_) |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5732 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5733 | case __state::__end_state: |
Tim Shen | e776667 | 2016-10-27 21:40:34 | [diff] [blame] | 5734 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | abd1a6e | 2016-10-21 20:41:47 | [diff] [blame] | 5735 | __s.__current_ == __first) |
| 5736 | { |
| 5737 | __states.pop_back(); |
| 5738 | break; |
| 5739 | } |
Tim Shen | e776667 | 2016-10-27 21:40:34 | [diff] [blame] | 5740 | if ((__flags & regex_constants::__full_match) && |
| 5741 | __s.__current_ != __last) |
| 5742 | { |
| 5743 | __states.pop_back(); |
| 5744 | break; |
| 5745 | } |
Howard Hinnant | 6afe8b0 | 2010-07-27 17:24:17 | [diff] [blame] | 5746 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 5699358 | 2010-07-14 15:45:11 | [diff] [blame] | 5747 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | 6afe8b0 | 2010-07-27 17:24:17 | [diff] [blame] | 5748 | __matched = true; |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 5749 | if (__highest_j == _Np) |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5750 | __states.clear(); |
| 5751 | else |
| 5752 | __states.pop_back(); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5753 | break; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5754 | case __state::__consume_input: |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5755 | break; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5756 | case __state::__accept_and_consume: |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 5757 | __states.push_front(_VSTD::move(__s)); |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5758 | __states.pop_back(); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5759 | break; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5760 | case __state::__repeat: |
| 5761 | case __state::__accept_but_not_consume: |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5762 | break; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5763 | case __state::__split: |
| 5764 | { |
| 5765 | __state __snext = __s; |
| 5766 | __s.__node_->__exec_split(true, __s); |
| 5767 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 5768 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5769 | } |
| 5770 | break; |
| 5771 | case __state::__reject: |
| 5772 | __states.pop_back(); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5773 | break; |
| 5774 | default: |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 5775 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5776 | break; |
| 5777 | } |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5778 | } while (!__states.empty()); |
Howard Hinnant | 5699358 | 2010-07-14 15:45:11 | [diff] [blame] | 5779 | if (__matched) |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5780 | { |
| 5781 | __m.__matches_[0].first = __first; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 5782 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5783 | __m.__matches_[0].matched = true; |
| 5784 | return true; |
| 5785 | } |
| 5786 | } |
| 5787 | return false; |
| 5788 | } |
| 5789 | |
| 5790 | template <class _CharT, class _Traits> |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5791 | template <class _Allocator> |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5792 | bool |
| 5793 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5794 | const _CharT* __first, const _CharT* __last, |
| 5795 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 5796 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5797 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5798 | vector<__state> __states; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5799 | __state __best_state; |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5800 | ptrdiff_t __j = 0; |
| 5801 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 5802 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5803 | __node* __st = __start_.get(); |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5804 | if (__st) |
| 5805 | { |
Marshall Clow | 538fec0 | 2015-01-28 22:22:35 | [diff] [blame] | 5806 | sub_match<const _CharT*> __unmatched; |
| 5807 | __unmatched.first = __last; |
| 5808 | __unmatched.second = __last; |
| 5809 | __unmatched.matched = false; |
| 5810 | |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5811 | __states.push_back(__state()); |
| 5812 | __states.back().__do_ = 0; |
| 5813 | __states.back().__first_ = __first; |
| 5814 | __states.back().__current_ = __first; |
| 5815 | __states.back().__last_ = __last; |
Marshall Clow | 538fec0 | 2015-01-28 22:22:35 | [diff] [blame] | 5816 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5817 | __states.back().__loop_data_.resize(__loop_count()); |
| 5818 | __states.back().__node_ = __st; |
| 5819 | __states.back().__flags_ = __flags; |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 5820 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5821 | const _CharT* __current = __first; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5822 | bool __matched = false; |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 | [diff] [blame] | 5823 | int __counter = 0; |
| 5824 | int __length = __last - __first; |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5825 | do |
| 5826 | { |
Marshall Clow | 5a72679 | 2017-09-12 17:56:59 | [diff] [blame] | 5827 | ++__counter; |
| 5828 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5829 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5830 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5831 | __state& __s = __states.back(); |
| 5832 | if (__s.__node_) |
| 5833 | __s.__node_->__exec(__s); |
| 5834 | switch (__s.__do_) |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5835 | { |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5836 | case __state::__end_state: |
Tim Shen | e776667 | 2016-10-27 21:40:34 | [diff] [blame] | 5837 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | abd1a6e | 2016-10-21 20:41:47 | [diff] [blame] | 5838 | __s.__current_ == __first) |
| 5839 | { |
| 5840 | __states.pop_back(); |
| 5841 | break; |
| 5842 | } |
Tim Shen | e776667 | 2016-10-27 21:40:34 | [diff] [blame] | 5843 | if ((__flags & regex_constants::__full_match) && |
| 5844 | __s.__current_ != __last) |
| 5845 | { |
| 5846 | __states.pop_back(); |
| 5847 | break; |
| 5848 | } |
Howard Hinnant | 6afe8b0 | 2010-07-27 17:24:17 | [diff] [blame] | 5849 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5850 | { |
Howard Hinnant | 6afe8b0 | 2010-07-27 17:24:17 | [diff] [blame] | 5851 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5852 | __best_state = __s; |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5853 | } |
Howard Hinnant | 6afe8b0 | 2010-07-27 17:24:17 | [diff] [blame] | 5854 | __matched = true; |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 5855 | if (__highest_j == _Np) |
Howard Hinnant | 6afe8b0 | 2010-07-27 17:24:17 | [diff] [blame] | 5856 | __states.clear(); |
| 5857 | else |
| 5858 | __states.pop_back(); |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5859 | break; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5860 | case __state::__accept_and_consume: |
Howard Hinnant | aea2afe | 2010-07-12 18:16:05 | [diff] [blame] | 5861 | __j += __s.__current_ - __current; |
| 5862 | __current = __s.__current_; |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5863 | break; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5864 | case __state::__repeat: |
| 5865 | case __state::__accept_but_not_consume: |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5866 | break; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5867 | case __state::__split: |
| 5868 | { |
| 5869 | __state __snext = __s; |
| 5870 | __s.__node_->__exec_split(true, __s); |
| 5871 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 5872 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5873 | } |
| 5874 | break; |
| 5875 | case __state::__reject: |
| 5876 | __states.pop_back(); |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5877 | break; |
| 5878 | default: |
Marshall Clow | bcbc37d | 2015-07-28 13:30:47 | [diff] [blame] | 5879 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5880 | break; |
| 5881 | } |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5882 | } while (!__states.empty()); |
| 5883 | if (__matched) |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5884 | { |
| 5885 | __m.__matches_[0].first = __first; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 5886 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5887 | __m.__matches_[0].matched = true; |
Howard Hinnant | 0cbed7e | 2010-07-12 15:51:17 | [diff] [blame] | 5888 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 5889 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | 8c459a1 | 2010-07-08 17:43:58 | [diff] [blame] | 5890 | return true; |
| 5891 | } |
| 5892 | } |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5893 | return false; |
| 5894 | } |
| 5895 | |
| 5896 | template <class _CharT, class _Traits> |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5897 | template <class _Allocator> |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5898 | bool |
| 5899 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5900 | const _CharT* __first, const _CharT* __last, |
| 5901 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 5902 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5903 | { |
Marshall Clow | 1931c43 | 2019-03-28 17:30:23 | [diff] [blame] | 5904 | if (__get_grammar(__flags_) == ECMAScript) |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 5905 | return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5906 | if (mark_count() == 0) |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 5907 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |
| 5908 | return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5909 | } |
| 5910 | |
| 5911 | template <class _CharT, class _Traits> |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5912 | template <class _Allocator> |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5913 | bool |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5914 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5915 | const _CharT* __first, const _CharT* __last, |
| 5916 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5917 | regex_constants::match_flag_type __flags) const |
| 5918 | { |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 5919 | __m.__init(1 + mark_count(), __first, __last, |
| 5920 | __flags & regex_constants::__no_update_pos); |
Howard Hinnant | dbdeb15 | 2013-07-09 17:29:09 | [diff] [blame] | 5921 | if (__match_at_start(__first, __last, __m, __flags, |
| 5922 | !(__flags & regex_constants::__no_update_pos))) |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5923 | { |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5924 | __m.__prefix_.second = __m[0].first; |
| 5925 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5926 | __m.__suffix_.first = __m[0].second; |
| 5927 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5928 | return true; |
| 5929 | } |
Howard Hinnant | 7949ab0 | 2010-07-29 01:15:27 | [diff] [blame] | 5930 | if (__first != __last && !(__flags & regex_constants::match_continuous)) |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5931 | { |
Howard Hinnant | 7189782 | 2010-07-29 15:17:28 | [diff] [blame] | 5932 | __flags |= regex_constants::match_prev_avail; |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5933 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5934 | { |
Howard Hinnant | 7189782 | 2010-07-29 15:17:28 | [diff] [blame] | 5935 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 382600f | 2011-03-26 20:02:27 | [diff] [blame] | 5936 | if (__match_at_start(__first, __last, __m, __flags, false)) |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5937 | { |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5938 | __m.__prefix_.second = __m[0].first; |
| 5939 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5940 | __m.__suffix_.first = __m[0].second; |
| 5941 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5942 | return true; |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5943 | } |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5944 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5945 | } |
| 5946 | } |
Howard Hinnant | 189b212 | 2010-07-07 19:14:52 | [diff] [blame] | 5947 | __m.__matches_.clear(); |
| 5948 | return false; |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5949 | } |
| 5950 | |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5951 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5952 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5953 | bool |
| 5954 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5955 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5956 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5957 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5958 | { |
Howard Hinnant | c815a4e | 2013-07-11 15:32:55 | [diff] [blame] | 5959 | int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0; |
| 5960 | basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last); |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5961 | match_results<const _CharT*> __mc; |
Howard Hinnant | c815a4e | 2013-07-11 15:32:55 | [diff] [blame] | 5962 | bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 5963 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5964 | return __r; |
| 5965 | } |
| 5966 | |
Howard Hinnant | 660f2ae | 2013-06-29 23:45:43 | [diff] [blame] | 5967 | template <class _Iter, class _Allocator, class _CharT, class _Traits> |
| 5968 | inline _LIBCPP_INLINE_VISIBILITY |
| 5969 | bool |
| 5970 | regex_search(__wrap_iter<_Iter> __first, |
| 5971 | __wrap_iter<_Iter> __last, |
| 5972 | match_results<__wrap_iter<_Iter>, _Allocator>& __m, |
| 5973 | const basic_regex<_CharT, _Traits>& __e, |
| 5974 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5975 | { |
| 5976 | match_results<const _CharT*> __mc; |
| 5977 | bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags); |
| 5978 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
| 5979 | return __r; |
| 5980 | } |
| 5981 | |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 5982 | template <class _Allocator, class _CharT, class _Traits> |
| 5983 | inline _LIBCPP_INLINE_VISIBILITY |
| 5984 | bool |
| 5985 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5986 | match_results<const _CharT*, _Allocator>& __m, |
| 5987 | const basic_regex<_CharT, _Traits>& __e, |
| 5988 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5989 | { |
Howard Hinnant | 237ee6f | 2010-06-30 17:22:19 | [diff] [blame] | 5990 | return __e.__search(__first, __last, __m, __flags); |
| 5991 | } |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 5992 | |
| 5993 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5994 | inline _LIBCPP_INLINE_VISIBILITY |
| 5995 | bool |
| 5996 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5997 | const basic_regex<_CharT, _Traits>& __e, |
| 5998 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5999 | { |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 6000 | basic_string<_CharT> __s(__first, __last); |
| 6001 | match_results<const _CharT*> __mc; |
| 6002 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 6003 | } |
| 6004 | |
| 6005 | template <class _CharT, class _Traits> |
| 6006 | inline _LIBCPP_INLINE_VISIBILITY |
| 6007 | bool |
| 6008 | regex_search(const _CharT* __first, const _CharT* __last, |
| 6009 | const basic_regex<_CharT, _Traits>& __e, |
| 6010 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6011 | { |
| 6012 | match_results<const _CharT*> __mc; |
| 6013 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6014 | } |
| 6015 | |
| 6016 | template <class _CharT, class _Allocator, class _Traits> |
| 6017 | inline _LIBCPP_INLINE_VISIBILITY |
| 6018 | bool |
| 6019 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6020 | const basic_regex<_CharT, _Traits>& __e, |
| 6021 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6022 | { |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 6023 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6024 | } |
| 6025 | |
| 6026 | template <class _CharT, class _Traits> |
| 6027 | inline _LIBCPP_INLINE_VISIBILITY |
| 6028 | bool |
| 6029 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6030 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6031 | { |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 6032 | match_results<const _CharT*> __m; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6033 | return _VSTD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6034 | } |
| 6035 | |
| 6036 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6037 | inline _LIBCPP_INLINE_VISIBILITY |
| 6038 | bool |
| 6039 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6040 | const basic_regex<_CharT, _Traits>& __e, |
| 6041 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6042 | { |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 6043 | match_results<const _CharT*> __mc; |
| 6044 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6045 | } |
| 6046 | |
| 6047 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6048 | inline _LIBCPP_INLINE_VISIBILITY |
| 6049 | bool |
| 6050 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6051 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6052 | const basic_regex<_CharT, _Traits>& __e, |
| 6053 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6054 | { |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 6055 | match_results<const _CharT*> __mc; |
| 6056 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6057 | __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 5d695f0 | 2010-07-14 21:14:52 | [diff] [blame] | 6058 | return __r; |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6059 | } |
| 6060 | |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 6061 | #if _LIBCPP_STD_VER > 11 |
| 6062 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
| 6063 | bool |
| 6064 | regex_search(const basic_string<_Cp, _ST, _SA>&& __s, |
| 6065 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 6066 | const basic_regex<_Cp, _Tp>& __e, |
| 6067 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
| 6068 | #endif |
| 6069 | |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6070 | // regex_match |
| 6071 | |
| 6072 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 6073 | bool |
| 6074 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6075 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6076 | const basic_regex<_CharT, _Traits>& __e, |
| 6077 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6078 | { |
Tim Shen | e776667 | 2016-10-27 21:40:34 | [diff] [blame] | 6079 | bool __r = _VSTD::regex_search( |
| 6080 | __first, __last, __m, __e, |
| 6081 | __flags | regex_constants::match_continuous | |
| 6082 | regex_constants::__full_match); |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6083 | if (__r) |
| 6084 | { |
| 6085 | __r = !__m.suffix().matched; |
| 6086 | if (!__r) |
| 6087 | __m.__matches_.clear(); |
| 6088 | } |
| 6089 | return __r; |
| 6090 | } |
| 6091 | |
| 6092 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6093 | inline _LIBCPP_INLINE_VISIBILITY |
| 6094 | bool |
| 6095 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6096 | const basic_regex<_CharT, _Traits>& __e, |
| 6097 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6098 | { |
| 6099 | match_results<_BidirectionalIterator> __m; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6100 | return _VSTD::regex_match(__first, __last, __m, __e, __flags); |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | template <class _CharT, class _Allocator, class _Traits> |
| 6104 | inline _LIBCPP_INLINE_VISIBILITY |
| 6105 | bool |
| 6106 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6107 | const basic_regex<_CharT, _Traits>& __e, |
| 6108 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6109 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6110 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6111 | } |
| 6112 | |
| 6113 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6114 | inline _LIBCPP_INLINE_VISIBILITY |
| 6115 | bool |
| 6116 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6117 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6118 | const basic_regex<_CharT, _Traits>& __e, |
| 6119 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6120 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6121 | return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6122 | } |
| 6123 | |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 6124 | #if _LIBCPP_STD_VER > 11 |
| 6125 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6126 | inline _LIBCPP_INLINE_VISIBILITY |
| 6127 | bool |
| 6128 | regex_match(const basic_string<_CharT, _ST, _SA>&& __s, |
| 6129 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6130 | const basic_regex<_CharT, _Traits>& __e, |
| 6131 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
| 6132 | #endif |
| 6133 | |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6134 | template <class _CharT, class _Traits> |
| 6135 | inline _LIBCPP_INLINE_VISIBILITY |
| 6136 | bool |
| 6137 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6138 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6139 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6140 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6144 | inline _LIBCPP_INLINE_VISIBILITY |
| 6145 | bool |
| 6146 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6147 | const basic_regex<_CharT, _Traits>& __e, |
| 6148 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6149 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6150 | return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); |
Howard Hinnant | cdefdee | 2010-06-30 00:21:42 | [diff] [blame] | 6151 | } |
| 6152 | |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6153 | // regex_iterator |
| 6154 | |
| 6155 | template <class _BidirectionalIterator, |
| 6156 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6157 | class _Traits = regex_traits<_CharT> > |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 6158 | class _LIBCPP_TEMPLATE_VIS regex_iterator |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6159 | { |
| 6160 | public: |
| 6161 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6162 | typedef match_results<_BidirectionalIterator> value_type; |
| 6163 | typedef ptrdiff_t difference_type; |
| 6164 | typedef const value_type* pointer; |
| 6165 | typedef const value_type& reference; |
| 6166 | typedef forward_iterator_tag iterator_category; |
| 6167 | |
| 6168 | private: |
| 6169 | _BidirectionalIterator __begin_; |
| 6170 | _BidirectionalIterator __end_; |
| 6171 | const regex_type* __pregex_; |
| 6172 | regex_constants::match_flag_type __flags_; |
| 6173 | value_type __match_; |
| 6174 | |
| 6175 | public: |
| 6176 | regex_iterator(); |
| 6177 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6178 | const regex_type& __re, |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 6179 | regex_constants::match_flag_type __m |
| 6180 | = regex_constants::match_default); |
| 6181 | #if _LIBCPP_STD_VER > 11 |
| 6182 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6183 | const regex_type&& __re, |
| 6184 | regex_constants::match_flag_type __m |
| 6185 | = regex_constants::match_default) = delete; |
| 6186 | #endif |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6187 | |
| 6188 | bool operator==(const regex_iterator& __x) const; |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 6189 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6190 | bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} |
| 6191 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 6192 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6193 | reference operator*() const {return __match_;} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 6194 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 6973bb0 | 2019-01-24 02:02:50 | [diff] [blame] | 6195 | pointer operator->() const {return _VSTD::addressof(__match_);} |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6196 | |
| 6197 | regex_iterator& operator++(); |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 6198 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6199 | regex_iterator operator++(int) |
| 6200 | { |
| 6201 | regex_iterator __t(*this); |
| 6202 | ++(*this); |
| 6203 | return __t; |
| 6204 | } |
| 6205 | }; |
| 6206 | |
| 6207 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6208 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() |
| 6209 | : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() |
| 6210 | { |
| 6211 | } |
| 6212 | |
| 6213 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6214 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6215 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6216 | const regex_type& __re, regex_constants::match_flag_type __m) |
| 6217 | : __begin_(__a), |
| 6218 | __end_(__b), |
Marshall Clow | 6973bb0 | 2019-01-24 02:02:50 | [diff] [blame] | 6219 | __pregex_(_VSTD::addressof(__re)), |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6220 | __flags_(__m) |
| 6221 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6222 | _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6226 | bool |
| 6227 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6228 | operator==(const regex_iterator& __x) const |
| 6229 | { |
| 6230 | if (__match_.empty() && __x.__match_.empty()) |
| 6231 | return true; |
| 6232 | if (__match_.empty() || __x.__match_.empty()) |
| 6233 | return false; |
| 6234 | return __begin_ == __x.__begin_ && |
| 6235 | __end_ == __x.__end_ && |
| 6236 | __pregex_ == __x.__pregex_ && |
| 6237 | __flags_ == __x.__flags_ && |
| 6238 | __match_[0] == __x.__match_[0]; |
| 6239 | } |
| 6240 | |
| 6241 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6242 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6243 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6244 | { |
| 6245 | __flags_ |= regex_constants::__no_update_pos; |
| 6246 | _BidirectionalIterator __start = __match_[0].second; |
Marshall Clow | 52f4f72 | 2017-07-05 16:37:19 | [diff] [blame] | 6247 | if (__match_[0].first == __match_[0].second) |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6248 | { |
| 6249 | if (__start == __end_) |
| 6250 | { |
| 6251 | __match_ = value_type(); |
| 6252 | return *this; |
| 6253 | } |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6254 | else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6255 | __flags_ | regex_constants::match_not_null | |
| 6256 | regex_constants::match_continuous)) |
| 6257 | return *this; |
| 6258 | else |
| 6259 | ++__start; |
| 6260 | } |
| 6261 | __flags_ |= regex_constants::match_prev_avail; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6262 | if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6263 | __match_ = value_type(); |
| 6264 | return *this; |
| 6265 | } |
| 6266 | |
| 6267 | typedef regex_iterator<const char*> cregex_iterator; |
| 6268 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 6269 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 6270 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 6271 | |
| 6272 | // regex_token_iterator |
| 6273 | |
| 6274 | template <class _BidirectionalIterator, |
| 6275 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6276 | class _Traits = regex_traits<_CharT> > |
Eric Fiselier | e2f2d1ed | 2017-01-04 23:56:00 | [diff] [blame] | 6277 | class _LIBCPP_TEMPLATE_VIS regex_token_iterator |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6278 | { |
| 6279 | public: |
| 6280 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6281 | typedef sub_match<_BidirectionalIterator> value_type; |
| 6282 | typedef ptrdiff_t difference_type; |
| 6283 | typedef const value_type* pointer; |
| 6284 | typedef const value_type& reference; |
| 6285 | typedef forward_iterator_tag iterator_category; |
| 6286 | |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6287 | private: |
| 6288 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; |
| 6289 | |
| 6290 | _Position __position_; |
| 6291 | const value_type* __result_; |
| 6292 | value_type __suffix_; |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6293 | ptrdiff_t __n_; |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6294 | vector<int> __subs_; |
| 6295 | |
| 6296 | public: |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6297 | regex_token_iterator(); |
| 6298 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6299 | const regex_type& __re, int __submatch = 0, |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6300 | regex_constants::match_flag_type __m = |
| 6301 | regex_constants::match_default); |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 6302 | #if _LIBCPP_STD_VER > 11 |
| 6303 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6304 | const regex_type&& __re, int __submatch = 0, |
| 6305 | regex_constants::match_flag_type __m = |
| 6306 | regex_constants::match_default) = delete; |
| 6307 | #endif |
| 6308 | |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6309 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6310 | const regex_type& __re, const vector<int>& __submatches, |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6311 | regex_constants::match_flag_type __m = |
| 6312 | regex_constants::match_default); |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 6313 | #if _LIBCPP_STD_VER > 11 |
| 6314 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6315 | const regex_type&& __re, const vector<int>& __submatches, |
| 6316 | regex_constants::match_flag_type __m = |
| 6317 | regex_constants::match_default) = delete; |
| 6318 | #endif |
| 6319 | |
Eric Fiselier | 9f7cc58 | 2017-04-18 23:42:15 | [diff] [blame] | 6320 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6321 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6322 | const regex_type& __re, |
| 6323 | initializer_list<int> __submatches, |
| 6324 | regex_constants::match_flag_type __m = |
| 6325 | regex_constants::match_default); |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 6326 | |
| 6327 | #if _LIBCPP_STD_VER > 11 |
| 6328 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6329 | const regex_type&& __re, |
| 6330 | initializer_list<int> __submatches, |
| 6331 | regex_constants::match_flag_type __m = |
| 6332 | regex_constants::match_default) = delete; |
| 6333 | #endif |
Eric Fiselier | 9f7cc58 | 2017-04-18 23:42:15 | [diff] [blame] | 6334 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 6335 | template <size_t _Np> |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6336 | regex_token_iterator(_BidirectionalIterator __a, |
| 6337 | _BidirectionalIterator __b, |
| 6338 | const regex_type& __re, |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 6339 | const int (&__submatches)[_Np], |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6340 | regex_constants::match_flag_type __m = |
| 6341 | regex_constants::match_default); |
Marshall Clow | 7d35711 | 2014-02-19 21:21:11 | [diff] [blame] | 6342 | #if _LIBCPP_STD_VER > 11 |
| 6343 | template <std::size_t _Np> |
| 6344 | regex_token_iterator(_BidirectionalIterator __a, |
| 6345 | _BidirectionalIterator __b, |
| 6346 | const regex_type&& __re, |
| 6347 | const int (&__submatches)[_Np], |
| 6348 | regex_constants::match_flag_type __m = |
| 6349 | regex_constants::match_default) = delete; |
| 6350 | #endif |
| 6351 | |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6352 | regex_token_iterator(const regex_token_iterator&); |
| 6353 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 6354 | |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6355 | bool operator==(const regex_token_iterator& __x) const; |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 6356 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6357 | bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6358 | |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 6359 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6360 | const value_type& operator*() const {return *__result_;} |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 6361 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6362 | const value_type* operator->() const {return __result_;} |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6363 | |
| 6364 | regex_token_iterator& operator++(); |
Howard Hinnant | 3e84caa | 2010-09-23 15:13:20 | [diff] [blame] | 6365 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6366 | regex_token_iterator operator++(int) |
| 6367 | { |
| 6368 | regex_token_iterator __t(*this); |
| 6369 | ++(*this); |
| 6370 | return __t; |
| 6371 | } |
| 6372 | |
| 6373 | private: |
| 6374 | void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); |
Marshall Clow | 79b0fee | 2014-01-09 18:25:57 | [diff] [blame] | 6375 | void __establish_result () { |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6376 | if (__subs_[__n_] == -1) |
Marshall Clow | 79b0fee | 2014-01-09 18:25:57 | [diff] [blame] | 6377 | __result_ = &__position_->prefix(); |
| 6378 | else |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6379 | __result_ = &(*__position_)[__subs_[__n_]]; |
Marshall Clow | 79b0fee | 2014-01-09 18:25:57 | [diff] [blame] | 6380 | } |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6381 | }; |
| 6382 | |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6383 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6384 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6385 | regex_token_iterator() |
| 6386 | : __result_(nullptr), |
| 6387 | __suffix_(), |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6388 | __n_(0) |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6389 | { |
| 6390 | } |
| 6391 | |
| 6392 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6393 | void |
| 6394 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6395 | __init(_BidirectionalIterator __a, _BidirectionalIterator __b) |
| 6396 | { |
| 6397 | if (__position_ != _Position()) |
Marshall Clow | 79b0fee | 2014-01-09 18:25:57 | [diff] [blame] | 6398 | __establish_result (); |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6399 | else if (__subs_[__n_] == -1) |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6400 | { |
| 6401 | __suffix_.matched = true; |
| 6402 | __suffix_.first = __a; |
| 6403 | __suffix_.second = __b; |
| 6404 | __result_ = &__suffix_; |
| 6405 | } |
| 6406 | else |
| 6407 | __result_ = nullptr; |
| 6408 | } |
| 6409 | |
| 6410 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6411 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6412 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6413 | const regex_type& __re, int __submatch, |
| 6414 | regex_constants::match_flag_type __m) |
| 6415 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6416 | __n_(0), |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6417 | __subs_(1, __submatch) |
| 6418 | { |
| 6419 | __init(__a, __b); |
| 6420 | } |
| 6421 | |
| 6422 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6423 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6424 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6425 | const regex_type& __re, const vector<int>& __submatches, |
| 6426 | regex_constants::match_flag_type __m) |
| 6427 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6428 | __n_(0), |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6429 | __subs_(__submatches) |
| 6430 | { |
| 6431 | __init(__a, __b); |
| 6432 | } |
| 6433 | |
Eric Fiselier | 9f7cc58 | 2017-04-18 23:42:15 | [diff] [blame] | 6434 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 | [diff] [blame] | 6435 | |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6436 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6437 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6438 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6439 | const regex_type& __re, |
| 6440 | initializer_list<int> __submatches, |
| 6441 | regex_constants::match_flag_type __m) |
| 6442 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6443 | __n_(0), |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6444 | __subs_(__submatches) |
| 6445 | { |
| 6446 | __init(__a, __b); |
| 6447 | } |
| 6448 | |
Eric Fiselier | 9f7cc58 | 2017-04-18 23:42:15 | [diff] [blame] | 6449 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 | [diff] [blame] | 6450 | |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6451 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 6452 | template <size_t _Np> |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6453 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6454 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6455 | const regex_type& __re, |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 | [diff] [blame] | 6456 | const int (&__submatches)[_Np], |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6457 | regex_constants::match_flag_type __m) |
| 6458 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6459 | __n_(0), |
Marshall Clow | 6973bb0 | 2019-01-24 02:02:50 | [diff] [blame] | 6460 | __subs_(begin(__submatches), end(__submatches)) |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6461 | { |
| 6462 | __init(__a, __b); |
| 6463 | } |
| 6464 | |
| 6465 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6466 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6467 | regex_token_iterator(const regex_token_iterator& __x) |
| 6468 | : __position_(__x.__position_), |
| 6469 | __result_(__x.__result_), |
| 6470 | __suffix_(__x.__suffix_), |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6471 | __n_(__x.__n_), |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6472 | __subs_(__x.__subs_) |
| 6473 | { |
| 6474 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 54f6bd5 | 2014-01-13 17:47:08 | [diff] [blame] | 6475 | __result_ = &__suffix_; |
Marshall Clow | 79b0fee | 2014-01-09 18:25:57 | [diff] [blame] | 6476 | else if ( __result_ != nullptr ) |
| 6477 | __establish_result (); |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6478 | } |
| 6479 | |
| 6480 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6481 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6482 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6483 | operator=(const regex_token_iterator& __x) |
| 6484 | { |
| 6485 | if (this != &__x) |
| 6486 | { |
| 6487 | __position_ = __x.__position_; |
| 6488 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 79b0fee | 2014-01-09 18:25:57 | [diff] [blame] | 6489 | __result_ = &__suffix_; |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6490 | else |
| 6491 | __result_ = __x.__result_; |
| 6492 | __suffix_ = __x.__suffix_; |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6493 | __n_ = __x.__n_; |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6494 | __subs_ = __x.__subs_; |
Marshall Clow | 79b0fee | 2014-01-09 18:25:57 | [diff] [blame] | 6495 | |
| 6496 | if ( __result_ != nullptr && __result_ != &__suffix_ ) |
| 6497 | __establish_result(); |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6498 | } |
| 6499 | return *this; |
| 6500 | } |
| 6501 | |
| 6502 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6503 | bool |
| 6504 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6505 | operator==(const regex_token_iterator& __x) const |
| 6506 | { |
| 6507 | if (__result_ == nullptr && __x.__result_ == nullptr) |
| 6508 | return true; |
| 6509 | if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && |
| 6510 | __suffix_ == __x.__suffix_) |
| 6511 | return true; |
| 6512 | if (__result_ == nullptr || __x.__result_ == nullptr) |
| 6513 | return false; |
| 6514 | if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) |
| 6515 | return false; |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6516 | return __position_ == __x.__position_ && __n_ == __x.__n_ && |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6517 | __subs_ == __x.__subs_; |
| 6518 | } |
| 6519 | |
| 6520 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6521 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6522 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6523 | { |
| 6524 | _Position __prev = __position_; |
| 6525 | if (__result_ == &__suffix_) |
| 6526 | __result_ = nullptr; |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6527 | else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6528 | { |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6529 | ++__n_; |
Marshall Clow | 79b0fee | 2014-01-09 18:25:57 | [diff] [blame] | 6530 | __establish_result(); |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6531 | } |
| 6532 | else |
| 6533 | { |
Eric Fiselier | aec0878 | 2016-12-24 00:24:44 | [diff] [blame] | 6534 | __n_ = 0; |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6535 | ++__position_; |
| 6536 | if (__position_ != _Position()) |
Marshall Clow | 79b0fee | 2014-01-09 18:25:57 | [diff] [blame] | 6537 | __establish_result(); |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6538 | else |
| 6539 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6540 | if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() |
Howard Hinnant | 14dcd3d | 2010-08-17 20:42:03 | [diff] [blame] | 6541 | && __prev->suffix().length() != 0) |
| 6542 | { |
| 6543 | __suffix_.matched = true; |
| 6544 | __suffix_.first = __prev->suffix().first; |
| 6545 | __suffix_.second = __prev->suffix().second; |
| 6546 | __result_ = &__suffix_; |
| 6547 | } |
| 6548 | else |
| 6549 | __result_ = nullptr; |
| 6550 | } |
| 6551 | } |
| 6552 | return *this; |
| 6553 | } |
| 6554 | |
Howard Hinnant | 2bf1fd9 | 2010-08-16 20:21:16 | [diff] [blame] | 6555 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 6556 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 6557 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 6558 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 6559 | |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6560 | // regex_replace |
| 6561 | |
| 6562 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6563 | class _Traits, class _CharT> |
| 6564 | _OutputIterator |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 6565 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6566 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6567 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6568 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6569 | { |
| 6570 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; |
| 6571 | _Iter __i(__first, __last, __e, __flags); |
| 6572 | _Iter __eof; |
| 6573 | if (__i == __eof) |
| 6574 | { |
| 6575 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 6576 | __output_iter = _VSTD::copy(__first, __last, __output_iter); |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6577 | } |
| 6578 | else |
| 6579 | { |
| 6580 | sub_match<_BidirectionalIterator> __lm; |
| 6581 | for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) |
| 6582 | { |
| 6583 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 6584 | __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter); |
| 6585 | __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags); |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6586 | __lm = __i->suffix(); |
| 6587 | if (__flags & regex_constants::format_first_only) |
| 6588 | break; |
| 6589 | } |
| 6590 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 6591 | __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter); |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6592 | } |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 6593 | return __output_iter; |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6594 | } |
| 6595 | |
| 6596 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6597 | class _Traits, class _CharT, class _ST, class _SA> |
| 6598 | inline _LIBCPP_INLINE_VISIBILITY |
| 6599 | _OutputIterator |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 6600 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6601 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6602 | const basic_regex<_CharT, _Traits>& __e, |
| 6603 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6604 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6605 | { |
Alexander Richardson | 42bfedd | 2017-11-14 11:14:25 | [diff] [blame] | 6606 | return _VSTD::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags); |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6607 | } |
| 6608 | |
| 6609 | template <class _Traits, class _CharT, class _ST, class _SA, class _FST, |
| 6610 | class _FSA> |
| 6611 | inline _LIBCPP_INLINE_VISIBILITY |
| 6612 | basic_string<_CharT, _ST, _SA> |
| 6613 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6614 | const basic_regex<_CharT, _Traits>& __e, |
| 6615 | const basic_string<_CharT, _FST, _FSA>& __fmt, |
| 6616 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6617 | { |
| 6618 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6619 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6620 | __fmt.c_str(), __flags); |
| 6621 | return __r; |
| 6622 | } |
| 6623 | |
| 6624 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6625 | inline _LIBCPP_INLINE_VISIBILITY |
| 6626 | basic_string<_CharT, _ST, _SA> |
| 6627 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6628 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6629 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6630 | { |
| 6631 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6632 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6633 | __fmt, __flags); |
| 6634 | return __r; |
| 6635 | } |
| 6636 | |
| 6637 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6638 | inline _LIBCPP_INLINE_VISIBILITY |
| 6639 | basic_string<_CharT> |
| 6640 | regex_replace(const _CharT* __s, |
| 6641 | const basic_regex<_CharT, _Traits>& __e, |
| 6642 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6643 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6644 | { |
| 6645 | basic_string<_CharT> __r; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6646 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6647 | __s + char_traits<_CharT>::length(__s), __e, |
| 6648 | __fmt.c_str(), __flags); |
| 6649 | return __r; |
| 6650 | } |
| 6651 | |
| 6652 | template <class _Traits, class _CharT> |
| 6653 | inline _LIBCPP_INLINE_VISIBILITY |
| 6654 | basic_string<_CharT> |
| 6655 | regex_replace(const _CharT* __s, |
| 6656 | const basic_regex<_CharT, _Traits>& __e, |
| 6657 | const _CharT* __fmt, |
| 6658 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6659 | { |
| 6660 | basic_string<_CharT> __r; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 | [diff] [blame] | 6661 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | 86550b0 | 2010-08-18 00:13:08 | [diff] [blame] | 6662 | __s + char_traits<_CharT>::length(__s), __e, |
| 6663 | __fmt, __flags); |
| 6664 | return __r; |
| 6665 | } |
| 6666 | |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 6667 | _LIBCPP_END_NAMESPACE_STD |
| 6668 | |
Eric Fiselier | a016efb | 2017-05-31 22:07:49 | [diff] [blame] | 6669 | _LIBCPP_POP_MACROS |
| 6670 | |
Howard Hinnant | 7050530 | 2010-06-17 00:34:59 | [diff] [blame] | 6671 | #endif // _LIBCPP_REGEX |