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