Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
Louis Dionne | 9bd9388 | 2021-11-17 16:25:01 -0500 | [diff] [blame] | 2 | //===----------------------------------------------------------------------===// |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [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 | a3af5a3 | 2010-06-17 00:34:59 +0000 | [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 | |
Arthur O'Dwyer | 4f98113 | 2020-06-25 15:31:03 -0400 | [diff] [blame] | 24 | enum syntax_option_type |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 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, |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 35 | egrep = unspecified, |
| 36 | multiline = unspecified |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | constexpr syntax_option_type operator~(syntax_option_type f); |
| 40 | constexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs); |
| 41 | constexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs); |
| 42 | |
| 43 | enum match_flag_type |
| 44 | { |
| 45 | match_default = 0, |
| 46 | match_not_bol = unspecified, |
| 47 | match_not_eol = unspecified, |
| 48 | match_not_bow = unspecified, |
| 49 | match_not_eow = unspecified, |
| 50 | match_any = unspecified, |
| 51 | match_not_null = unspecified, |
| 52 | match_continuous = unspecified, |
| 53 | match_prev_avail = unspecified, |
| 54 | format_default = 0, |
| 55 | format_sed = unspecified, |
| 56 | format_no_copy = unspecified, |
| 57 | format_first_only = unspecified |
| 58 | }; |
| 59 | |
| 60 | constexpr match_flag_type operator~(match_flag_type f); |
| 61 | constexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs); |
| 62 | constexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs); |
| 63 | |
| 64 | enum error_type |
| 65 | { |
| 66 | error_collate = unspecified, |
| 67 | error_ctype = unspecified, |
| 68 | error_escape = unspecified, |
| 69 | error_backref = unspecified, |
| 70 | error_brack = unspecified, |
| 71 | error_paren = unspecified, |
| 72 | error_brace = unspecified, |
| 73 | error_badbrace = unspecified, |
| 74 | error_range = unspecified, |
| 75 | error_space = unspecified, |
| 76 | error_badrepeat = unspecified, |
| 77 | error_complexity = unspecified, |
| 78 | error_stack = unspecified |
| 79 | }; |
| 80 | |
| 81 | } // regex_constants |
| 82 | |
| 83 | class regex_error |
| 84 | : public runtime_error |
| 85 | { |
| 86 | public: |
| 87 | explicit regex_error(regex_constants::error_type ecode); |
| 88 | regex_constants::error_type code() const; |
| 89 | }; |
| 90 | |
| 91 | template <class charT> |
| 92 | struct regex_traits |
| 93 | { |
| 94 | public: |
| 95 | typedef charT char_type; |
| 96 | typedef basic_string<char_type> string_type; |
| 97 | typedef locale locale_type; |
| 98 | typedef /bitmask_type/ char_class_type; |
| 99 | |
| 100 | regex_traits(); |
| 101 | |
| 102 | static size_t length(const char_type* p); |
| 103 | charT translate(charT c) const; |
| 104 | charT translate_nocase(charT c) const; |
| 105 | template <class ForwardIterator> |
| 106 | string_type |
| 107 | transform(ForwardIterator first, ForwardIterator last) const; |
| 108 | template <class ForwardIterator> |
| 109 | string_type |
| 110 | transform_primary( ForwardIterator first, ForwardIterator last) const; |
| 111 | template <class ForwardIterator> |
| 112 | string_type |
| 113 | lookup_collatename(ForwardIterator first, ForwardIterator last) const; |
| 114 | template <class ForwardIterator> |
| 115 | char_class_type |
| 116 | lookup_classname(ForwardIterator first, ForwardIterator last, |
| 117 | bool icase = false) const; |
| 118 | bool isctype(charT c, char_class_type f) const; |
| 119 | int value(charT ch, int radix) const; |
| 120 | locale_type imbue(locale_type l); |
| 121 | locale_type getloc()const; |
| 122 | }; |
| 123 | |
| 124 | template <class charT, class traits = regex_traits<charT>> |
| 125 | class basic_regex |
| 126 | { |
| 127 | public: |
| 128 | // types: |
| 129 | typedef charT value_type; |
Hubert Tong | 1f1ae9c | 2016-08-02 21:34:48 +0000 | [diff] [blame] | 130 | typedef traits traits_type; |
| 131 | typedef typename traits::string_type string_type; |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 132 | typedef regex_constants::syntax_option_type flag_type; |
| 133 | typedef typename traits::locale_type locale_type; |
| 134 | |
| 135 | // constants: |
| 136 | static constexpr regex_constants::syntax_option_type icase = regex_constants::icase; |
| 137 | static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 138 | static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 139 | static constexpr regex_constants::syntax_option_type collate = regex_constants::collate; |
| 140 | static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 141 | static constexpr regex_constants::syntax_option_type basic = regex_constants::basic; |
| 142 | static constexpr regex_constants::syntax_option_type extended = regex_constants::extended; |
| 143 | static constexpr regex_constants::syntax_option_type awk = regex_constants::awk; |
| 144 | static constexpr regex_constants::syntax_option_type grep = regex_constants::grep; |
| 145 | static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 146 | static constexpr regex_constants::syntax_option_type multiline = regex_constants::multiline; |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 147 | |
| 148 | // construct/copy/destroy: |
| 149 | basic_regex(); |
| 150 | explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript); |
Hubert Tong | 1966286 | 2016-08-07 22:26:04 +0000 | [diff] [blame] | 151 | basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 152 | basic_regex(const basic_regex&); |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 153 | basic_regex(basic_regex&&) noexcept; |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 154 | template <class ST, class SA> |
| 155 | explicit basic_regex(const basic_string<charT, ST, SA>& p, |
| 156 | flag_type f = regex_constants::ECMAScript); |
| 157 | template <class ForwardIterator> |
| 158 | basic_regex(ForwardIterator first, ForwardIterator last, |
| 159 | flag_type f = regex_constants::ECMAScript); |
| 160 | basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript); |
| 161 | |
| 162 | ~basic_regex(); |
| 163 | |
| 164 | basic_regex& operator=(const basic_regex&); |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 165 | basic_regex& operator=(basic_regex&&) noexcept; |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 166 | basic_regex& operator=(const charT* ptr); |
| 167 | basic_regex& operator=(initializer_list<charT> il); |
| 168 | template <class ST, class SA> |
| 169 | basic_regex& operator=(const basic_string<charT, ST, SA>& p); |
| 170 | |
| 171 | // assign: |
| 172 | basic_regex& assign(const basic_regex& that); |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 173 | basic_regex& assign(basic_regex&& that) noexcept; |
Marshall Clow | d402893 | 2019-09-25 16:40:30 +0000 | [diff] [blame] | 174 | basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript); |
| 175 | basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 176 | template <class string_traits, class A> |
| 177 | basic_regex& assign(const basic_string<charT, string_traits, A>& s, |
Marshall Clow | d402893 | 2019-09-25 16:40:30 +0000 | [diff] [blame] | 178 | flag_type f = regex_constants::ECMAScript); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 179 | template <class InputIterator> |
| 180 | basic_regex& assign(InputIterator first, InputIterator last, |
Marshall Clow | d402893 | 2019-09-25 16:40:30 +0000 | [diff] [blame] | 181 | flag_type f = regex_constants::ECMAScript); |
| 182 | basic_regex& assign(initializer_list<charT>, flag_type f = regex_constants::ECMAScript); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 183 | |
| 184 | // const operations: |
| 185 | unsigned mark_count() const; |
| 186 | flag_type flags() const; |
| 187 | |
| 188 | // locale: |
| 189 | locale_type imbue(locale_type loc); |
| 190 | locale_type getloc() const; |
| 191 | |
| 192 | // swap: |
| 193 | void swap(basic_regex&); |
| 194 | }; |
| 195 | |
Marshall Clow | 2dce1f4 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 196 | template<class ForwardIterator> |
| 197 | basic_regex(ForwardIterator, ForwardIterator, |
| 198 | regex_constants::syntax_option_type = regex_constants::ECMAScript) |
| 199 | -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; // C++17 |
| 200 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 201 | typedef basic_regex<char> regex; |
| 202 | typedef basic_regex<wchar_t> wregex; |
| 203 | |
| 204 | template <class charT, class traits> |
| 205 | void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2); |
| 206 | |
| 207 | template <class BidirectionalIterator> |
| 208 | class sub_match |
| 209 | : public pair<BidirectionalIterator, BidirectionalIterator> |
| 210 | { |
| 211 | public: |
| 212 | typedef typename iterator_traits<BidirectionalIterator>::value_type value_type; |
| 213 | typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; |
| 214 | typedef BidirectionalIterator iterator; |
| 215 | typedef basic_string<value_type> string_type; |
| 216 | |
| 217 | bool matched; |
| 218 | |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 219 | constexpr sub_match(); |
| 220 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 221 | difference_type length() const; |
| 222 | operator string_type() const; |
| 223 | string_type str() const; |
| 224 | |
| 225 | int compare(const sub_match& s) const; |
| 226 | int compare(const string_type& s) const; |
| 227 | int compare(const value_type* s) const; |
| 228 | }; |
| 229 | |
| 230 | typedef sub_match<const char*> csub_match; |
| 231 | typedef sub_match<const wchar_t*> wcsub_match; |
| 232 | typedef sub_match<string::const_iterator> ssub_match; |
| 233 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 234 | |
| 235 | template <class BiIter> |
| 236 | bool |
| 237 | operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 238 | |
| 239 | template <class BiIter> |
| 240 | bool |
| 241 | operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 242 | |
| 243 | template <class BiIter> |
| 244 | bool |
| 245 | operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 246 | |
| 247 | template <class BiIter> |
| 248 | bool |
| 249 | operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 250 | |
| 251 | template <class BiIter> |
| 252 | bool |
| 253 | operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 254 | |
| 255 | template <class BiIter> |
| 256 | bool |
| 257 | operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 258 | |
| 259 | template <class BiIter, class ST, class SA> |
| 260 | bool |
| 261 | operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 262 | const sub_match<BiIter>& rhs); |
| 263 | |
| 264 | template <class BiIter, class ST, class SA> |
| 265 | bool |
| 266 | operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 267 | const sub_match<BiIter>& rhs); |
| 268 | |
| 269 | template <class BiIter, class ST, class SA> |
| 270 | bool |
| 271 | operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 272 | const sub_match<BiIter>& rhs); |
| 273 | |
| 274 | template <class BiIter, class ST, class SA> |
| 275 | bool |
| 276 | operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 277 | const sub_match<BiIter>& rhs); |
| 278 | |
| 279 | template <class BiIter, class ST, class SA> |
| 280 | bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 281 | const sub_match<BiIter>& rhs); |
| 282 | |
| 283 | template <class BiIter, class ST, class SA> |
| 284 | bool |
| 285 | operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 286 | const sub_match<BiIter>& rhs); |
| 287 | |
| 288 | template <class BiIter, class ST, class SA> |
| 289 | bool |
| 290 | operator==(const sub_match<BiIter>& lhs, |
| 291 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 292 | |
| 293 | template <class BiIter, class ST, class SA> |
| 294 | bool |
| 295 | operator!=(const sub_match<BiIter>& lhs, |
| 296 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 297 | |
| 298 | template <class BiIter, class ST, class SA> |
| 299 | bool |
| 300 | operator<(const sub_match<BiIter>& lhs, |
| 301 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 302 | |
| 303 | template <class BiIter, class ST, class SA> |
| 304 | bool operator>(const sub_match<BiIter>& lhs, |
| 305 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 306 | |
| 307 | template <class BiIter, class ST, class SA> |
| 308 | bool |
| 309 | operator>=(const sub_match<BiIter>& lhs, |
| 310 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 311 | |
| 312 | template <class BiIter, class ST, class SA> |
| 313 | bool |
| 314 | operator<=(const sub_match<BiIter>& lhs, |
| 315 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 316 | |
| 317 | template <class BiIter> |
| 318 | bool |
| 319 | operator==(typename iterator_traits<BiIter>::value_type const* lhs, |
| 320 | const sub_match<BiIter>& rhs); |
| 321 | |
| 322 | template <class BiIter> |
| 323 | bool |
| 324 | operator!=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 325 | const sub_match<BiIter>& rhs); |
| 326 | |
| 327 | template <class BiIter> |
| 328 | bool |
| 329 | operator<(typename iterator_traits<BiIter>::value_type const* lhs, |
| 330 | const sub_match<BiIter>& rhs); |
| 331 | |
| 332 | template <class BiIter> |
| 333 | bool |
| 334 | operator>(typename iterator_traits<BiIter>::value_type const* lhs, |
| 335 | const sub_match<BiIter>& rhs); |
| 336 | |
| 337 | template <class BiIter> |
| 338 | bool |
| 339 | operator>=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 340 | const sub_match<BiIter>& rhs); |
| 341 | |
| 342 | template <class BiIter> |
| 343 | bool |
| 344 | operator<=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 345 | const sub_match<BiIter>& rhs); |
| 346 | |
| 347 | template <class BiIter> |
| 348 | bool |
| 349 | operator==(const sub_match<BiIter>& lhs, |
| 350 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 351 | |
| 352 | template <class BiIter> |
| 353 | bool |
| 354 | operator!=(const sub_match<BiIter>& lhs, |
| 355 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 356 | |
| 357 | template <class BiIter> |
| 358 | bool |
| 359 | operator<(const sub_match<BiIter>& lhs, |
| 360 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 361 | |
| 362 | template <class BiIter> |
| 363 | bool |
| 364 | operator>(const sub_match<BiIter>& lhs, |
| 365 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 366 | |
| 367 | template <class BiIter> |
| 368 | bool |
| 369 | operator>=(const sub_match<BiIter>& lhs, |
| 370 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 371 | |
| 372 | template <class BiIter> |
| 373 | bool |
| 374 | operator<=(const sub_match<BiIter>& lhs, |
| 375 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 376 | |
| 377 | template <class BiIter> |
| 378 | bool |
| 379 | operator==(typename iterator_traits<BiIter>::value_type const& lhs, |
| 380 | const sub_match<BiIter>& rhs); |
| 381 | |
| 382 | template <class BiIter> |
| 383 | bool |
| 384 | operator!=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 385 | const sub_match<BiIter>& rhs); |
| 386 | |
| 387 | template <class BiIter> |
| 388 | bool |
| 389 | operator<(typename iterator_traits<BiIter>::value_type const& lhs, |
| 390 | const sub_match<BiIter>& rhs); |
| 391 | |
| 392 | template <class BiIter> |
| 393 | bool |
| 394 | operator>(typename iterator_traits<BiIter>::value_type const& lhs, |
| 395 | const sub_match<BiIter>& rhs); |
| 396 | |
| 397 | template <class BiIter> |
| 398 | bool |
| 399 | operator>=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 400 | const sub_match<BiIter>& rhs); |
| 401 | |
| 402 | template <class BiIter> |
| 403 | bool |
| 404 | operator<=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 405 | const sub_match<BiIter>& rhs); |
| 406 | |
| 407 | template <class BiIter> |
| 408 | bool |
| 409 | operator==(const sub_match<BiIter>& lhs, |
| 410 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 411 | |
| 412 | template <class BiIter> |
| 413 | bool |
| 414 | operator!=(const sub_match<BiIter>& lhs, |
| 415 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 416 | |
| 417 | template <class BiIter> |
| 418 | bool |
| 419 | operator<(const sub_match<BiIter>& lhs, |
| 420 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 421 | |
| 422 | template <class BiIter> |
| 423 | bool |
| 424 | operator>(const sub_match<BiIter>& lhs, |
| 425 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 426 | |
| 427 | template <class BiIter> |
| 428 | bool |
| 429 | operator>=(const sub_match<BiIter>& lhs, |
| 430 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 431 | |
| 432 | template <class BiIter> |
| 433 | bool |
| 434 | operator<=(const sub_match<BiIter>& lhs, |
| 435 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 436 | |
| 437 | template <class charT, class ST, class BiIter> |
| 438 | basic_ostream<charT, ST>& |
| 439 | operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m); |
| 440 | |
| 441 | template <class BidirectionalIterator, |
| 442 | class Allocator = allocator<sub_match<BidirectionalIterator>>> |
| 443 | class match_results |
| 444 | { |
| 445 | public: |
| 446 | typedef sub_match<BidirectionalIterator> value_type; |
| 447 | typedef const value_type& const_reference; |
Marshall Clow | 96e0614 | 2014-02-26 01:56:31 +0000 | [diff] [blame] | 448 | typedef value_type& reference; |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 449 | typedef /implementation-defined/ const_iterator; |
| 450 | typedef const_iterator iterator; |
| 451 | typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; |
| 452 | typedef typename allocator_traits<Allocator>::size_type size_type; |
| 453 | typedef Allocator allocator_type; |
| 454 | typedef typename iterator_traits<BidirectionalIterator>::value_type char_type; |
| 455 | typedef basic_string<char_type> string_type; |
| 456 | |
| 457 | // construct/copy/destroy: |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 458 | explicit match_results(const Allocator& a = Allocator()); // before C++20 |
| 459 | match_results() : match_results(Allocator()) {} // C++20 |
| 460 | explicit match_results(const Allocator& a); // C++20 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 461 | match_results(const match_results& m); |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 462 | match_results(match_results&& m) noexcept; |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 463 | match_results& operator=(const match_results& m); |
| 464 | match_results& operator=(match_results&& m); |
| 465 | ~match_results(); |
| 466 | |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 467 | bool ready() const; |
| 468 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 469 | // size: |
| 470 | size_type size() const; |
| 471 | size_type max_size() const; |
| 472 | bool empty() const; |
| 473 | |
| 474 | // element access: |
| 475 | difference_type length(size_type sub = 0) const; |
| 476 | difference_type position(size_type sub = 0) const; |
| 477 | string_type str(size_type sub = 0) const; |
| 478 | const_reference operator[](size_type n) const; |
| 479 | |
| 480 | const_reference prefix() const; |
| 481 | const_reference suffix() const; |
| 482 | |
| 483 | const_iterator begin() const; |
| 484 | const_iterator end() const; |
| 485 | const_iterator cbegin() const; |
| 486 | const_iterator cend() const; |
| 487 | |
| 488 | // format: |
| 489 | template <class OutputIter> |
| 490 | OutputIter |
| 491 | format(OutputIter out, const char_type* fmt_first, |
| 492 | const char_type* fmt_last, |
| 493 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 494 | template <class OutputIter, class ST, class SA> |
| 495 | OutputIter |
| 496 | format(OutputIter out, const basic_string<char_type, ST, SA>& fmt, |
| 497 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 498 | template <class ST, class SA> |
| 499 | basic_string<char_type, ST, SA> |
| 500 | format(const basic_string<char_type, ST, SA>& fmt, |
| 501 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 502 | string_type |
| 503 | format(const char_type* fmt, |
| 504 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 505 | |
| 506 | // allocator: |
| 507 | allocator_type get_allocator() const; |
| 508 | |
| 509 | // swap: |
| 510 | void swap(match_results& that); |
| 511 | }; |
| 512 | |
| 513 | typedef match_results<const char*> cmatch; |
| 514 | typedef match_results<const wchar_t*> wcmatch; |
| 515 | typedef match_results<string::const_iterator> smatch; |
| 516 | typedef match_results<wstring::const_iterator> wsmatch; |
| 517 | |
| 518 | template <class BidirectionalIterator, class Allocator> |
| 519 | bool |
| 520 | operator==(const match_results<BidirectionalIterator, Allocator>& m1, |
| 521 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 522 | |
| 523 | template <class BidirectionalIterator, class Allocator> |
| 524 | bool |
| 525 | operator!=(const match_results<BidirectionalIterator, Allocator>& m1, |
| 526 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 527 | |
| 528 | template <class BidirectionalIterator, class Allocator> |
| 529 | void |
| 530 | swap(match_results<BidirectionalIterator, Allocator>& m1, |
| 531 | match_results<BidirectionalIterator, Allocator>& m2); |
| 532 | |
| 533 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 534 | bool |
| 535 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 536 | match_results<BidirectionalIterator, Allocator>& m, |
| 537 | const basic_regex<charT, traits>& e, |
| 538 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 539 | |
| 540 | template <class BidirectionalIterator, class charT, class traits> |
| 541 | bool |
| 542 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 543 | const basic_regex<charT, traits>& e, |
| 544 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 545 | |
| 546 | template <class charT, class Allocator, class traits> |
| 547 | bool |
| 548 | regex_match(const charT* str, match_results<const charT*, Allocator>& m, |
| 549 | const basic_regex<charT, traits>& e, |
| 550 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 551 | |
| 552 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 553 | bool |
| 554 | regex_match(const basic_string<charT, ST, SA>& s, |
| 555 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 556 | const basic_regex<charT, traits>& e, |
| 557 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 558 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 559 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 560 | bool |
| 561 | regex_match(const basic_string<charT, ST, SA>&& s, |
| 562 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 563 | const basic_regex<charT, traits>& e, |
| 564 | regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 |
| 565 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 566 | template <class charT, class traits> |
| 567 | bool |
| 568 | regex_match(const charT* str, const basic_regex<charT, traits>& e, |
| 569 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 570 | |
| 571 | template <class ST, class SA, class charT, class traits> |
| 572 | bool |
| 573 | regex_match(const basic_string<charT, ST, SA>& s, |
| 574 | const basic_regex<charT, traits>& e, |
| 575 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 576 | |
| 577 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 578 | bool |
| 579 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 580 | match_results<BidirectionalIterator, Allocator>& m, |
| 581 | const basic_regex<charT, traits>& e, |
| 582 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 583 | |
| 584 | template <class BidirectionalIterator, class charT, class traits> |
| 585 | bool |
| 586 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 587 | const basic_regex<charT, traits>& e, |
| 588 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 589 | |
| 590 | template <class charT, class Allocator, class traits> |
| 591 | bool |
| 592 | regex_search(const charT* str, match_results<const charT*, Allocator>& m, |
| 593 | const basic_regex<charT, traits>& e, |
| 594 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 595 | |
| 596 | template <class charT, class traits> |
| 597 | bool |
| 598 | regex_search(const charT* str, const basic_regex<charT, traits>& e, |
| 599 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 600 | |
| 601 | template <class ST, class SA, class charT, class traits> |
| 602 | bool |
| 603 | regex_search(const basic_string<charT, ST, SA>& s, |
| 604 | const basic_regex<charT, traits>& e, |
| 605 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 606 | |
| 607 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 608 | bool |
| 609 | regex_search(const basic_string<charT, ST, SA>& s, |
| 610 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 611 | const basic_regex<charT, traits>& e, |
| 612 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 613 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 614 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 615 | bool |
| 616 | regex_search(const basic_string<charT, ST, SA>&& s, |
| 617 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 618 | const basic_regex<charT, traits>& e, |
| 619 | regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 |
| 620 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 621 | template <class OutputIterator, class BidirectionalIterator, |
| 622 | class traits, class charT, class ST, class SA> |
| 623 | OutputIterator |
| 624 | regex_replace(OutputIterator out, |
| 625 | BidirectionalIterator first, BidirectionalIterator last, |
| 626 | const basic_regex<charT, traits>& e, |
| 627 | const basic_string<charT, ST, SA>& fmt, |
| 628 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 629 | |
| 630 | template <class OutputIterator, class BidirectionalIterator, |
| 631 | class traits, class charT> |
| 632 | OutputIterator |
| 633 | regex_replace(OutputIterator out, |
| 634 | BidirectionalIterator first, BidirectionalIterator last, |
| 635 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 636 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 637 | |
Arthur O'Dwyer | 4f98113 | 2020-06-25 15:31:03 -0400 | [diff] [blame] | 638 | template <class traits, class charT, class ST, class SA, class FST, class FSA> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 639 | basic_string<charT, ST, SA> |
| 640 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 641 | const basic_regex<charT, traits>& e, |
| 642 | const basic_string<charT, FST, FSA>& fmt, |
| 643 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 644 | |
| 645 | template <class traits, class charT, class ST, class SA> |
| 646 | basic_string<charT, ST, SA> |
| 647 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 648 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 649 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 650 | |
| 651 | template <class traits, class charT, class ST, class SA> |
| 652 | basic_string<charT> |
| 653 | regex_replace(const charT* s, |
| 654 | const basic_regex<charT, traits>& e, |
| 655 | const basic_string<charT, ST, SA>& fmt, |
| 656 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 657 | |
| 658 | template <class traits, class charT> |
| 659 | basic_string<charT> |
| 660 | regex_replace(const charT* s, |
| 661 | const basic_regex<charT, traits>& e, |
| 662 | const charT* fmt, |
| 663 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 664 | |
| 665 | template <class BidirectionalIterator, |
| 666 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 667 | class traits = regex_traits<charT>> |
| 668 | class regex_iterator |
| 669 | { |
| 670 | public: |
| 671 | typedef basic_regex<charT, traits> regex_type; |
| 672 | typedef match_results<BidirectionalIterator> value_type; |
| 673 | typedef ptrdiff_t difference_type; |
| 674 | typedef const value_type* pointer; |
| 675 | typedef const value_type& reference; |
| 676 | typedef forward_iterator_tag iterator_category; |
| 677 | |
| 678 | regex_iterator(); |
| 679 | regex_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 680 | const regex_type& re, |
| 681 | regex_constants::match_flag_type m = regex_constants::match_default); |
Arthur O'Dwyer | 4f98113 | 2020-06-25 15:31:03 -0400 | [diff] [blame] | 682 | regex_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 683 | const regex_type&& re, |
| 684 | regex_constants::match_flag_type m |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 685 | = regex_constants::match_default) = delete; // C++14 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 686 | regex_iterator(const regex_iterator&); |
| 687 | regex_iterator& operator=(const regex_iterator&); |
| 688 | |
| 689 | bool operator==(const regex_iterator&) const; |
| 690 | bool operator!=(const regex_iterator&) const; |
| 691 | |
| 692 | const value_type& operator*() const; |
| 693 | const value_type* operator->() const; |
| 694 | |
| 695 | regex_iterator& operator++(); |
| 696 | regex_iterator operator++(int); |
| 697 | }; |
| 698 | |
| 699 | typedef regex_iterator<const char*> cregex_iterator; |
| 700 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 701 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 702 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 703 | |
| 704 | template <class BidirectionalIterator, |
Arthur O'Dwyer | 4f98113 | 2020-06-25 15:31:03 -0400 | [diff] [blame] | 705 | class charT = typename iterator_traits<BidirectionalIterator>::value_type, |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 706 | class traits = regex_traits<charT>> |
| 707 | class regex_token_iterator |
| 708 | { |
| 709 | public: |
| 710 | typedef basic_regex<charT, traits> regex_type; |
| 711 | typedef sub_match<BidirectionalIterator> value_type; |
| 712 | typedef ptrdiff_t difference_type; |
| 713 | typedef const value_type* pointer; |
| 714 | typedef const value_type& reference; |
| 715 | typedef forward_iterator_tag iterator_category; |
| 716 | |
| 717 | regex_token_iterator(); |
| 718 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 719 | const regex_type& re, int submatch = 0, |
| 720 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 721 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 722 | const regex_type&& re, int submatch = 0, |
| 723 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
| 724 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 725 | const regex_type& re, const vector<int>& submatches, |
| 726 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 727 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 728 | const regex_type&& re, const vector<int>& submatches, |
| 729 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
| 730 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 731 | const regex_type& re, initializer_list<int> submatches, |
| 732 | regex_constants::match_flag_type m = regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 733 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 734 | const regex_type&& re, initializer_list<int> submatches, |
| 735 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [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); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 740 | template <size_t N> |
| 741 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Arthur O'Dwyer | 4f98113 | 2020-06-25 15:31:03 -0400 | [diff] [blame] | 742 | const regex_type&& re, const int (&submatches)[N], |
| 743 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 744 | regex_token_iterator(const regex_token_iterator&); |
| 745 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 746 | |
| 747 | bool operator==(const regex_token_iterator&) const; |
| 748 | bool operator!=(const regex_token_iterator&) const; |
| 749 | |
| 750 | const value_type& operator*() const; |
| 751 | const value_type* operator->() const; |
| 752 | |
| 753 | regex_token_iterator& operator++(); |
| 754 | regex_token_iterator operator++(int); |
| 755 | }; |
| 756 | |
| 757 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 758 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 759 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 760 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 761 | |
| 762 | } // std |
| 763 | */ |
| 764 | |
Nikolas Klauser | f210d8a | 2022-02-15 18:18:08 +0100 | [diff] [blame^] | 765 | #include <__algorithm/find.h> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 766 | #include <__config> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 767 | #include <__debug> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 768 | #include <__iterator/wrap_iter.h> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 769 | #include <__locale> |
Arthur O'Dwyer | 7deec12 | 2021-03-24 18:19:12 -0400 | [diff] [blame] | 770 | #include <compare> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 771 | #include <deque> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 772 | #include <initializer_list> |
| 773 | #include <iterator> |
| 774 | #include <memory> |
| 775 | #include <stdexcept> |
| 776 | #include <string> |
| 777 | #include <utility> |
| 778 | #include <vector> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 779 | #include <version> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 780 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 781 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 782 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 783 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 784 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 785 | _LIBCPP_PUSH_MACROS |
| 786 | #include <__undef_macros> |
| 787 | |
| 788 | |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 789 | #define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096 |
| 790 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 791 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 792 | |
| 793 | namespace regex_constants |
| 794 | { |
| 795 | |
| 796 | // syntax_option_type |
| 797 | |
| 798 | enum syntax_option_type |
| 799 | { |
| 800 | icase = 1 << 0, |
| 801 | nosubs = 1 << 1, |
| 802 | optimize = 1 << 2, |
| 803 | collate = 1 << 3, |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 804 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 805 | ECMAScript = 1 << 9, |
| 806 | #else |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 807 | ECMAScript = 0, |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 808 | #endif |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 809 | basic = 1 << 4, |
| 810 | extended = 1 << 5, |
| 811 | awk = 1 << 6, |
| 812 | grep = 1 << 7, |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 813 | egrep = 1 << 8, |
| 814 | // 1 << 9 may be used by ECMAScript |
| 815 | multiline = 1 << 10 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 816 | }; |
| 817 | |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 818 | inline _LIBCPP_CONSTEXPR |
| 819 | syntax_option_type __get_grammar(syntax_option_type __g) |
| 820 | { |
| 821 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 822 | return static_cast<syntax_option_type>(__g & 0x3F0); |
| 823 | #else |
| 824 | return static_cast<syntax_option_type>(__g & 0x1F0); |
| 825 | #endif |
| 826 | } |
| 827 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 828 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 829 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 830 | syntax_option_type |
| 831 | operator~(syntax_option_type __x) |
| 832 | { |
Marshall Clow | 924cffa | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 833 | return syntax_option_type(~int(__x) & 0x1FF); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 836 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 837 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 838 | syntax_option_type |
| 839 | operator&(syntax_option_type __x, syntax_option_type __y) |
| 840 | { |
| 841 | return syntax_option_type(int(__x) & int(__y)); |
| 842 | } |
| 843 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 844 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 845 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 846 | syntax_option_type |
| 847 | operator|(syntax_option_type __x, syntax_option_type __y) |
| 848 | { |
| 849 | return syntax_option_type(int(__x) | int(__y)); |
| 850 | } |
| 851 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 852 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 853 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 854 | syntax_option_type |
| 855 | operator^(syntax_option_type __x, syntax_option_type __y) |
| 856 | { |
| 857 | return syntax_option_type(int(__x) ^ int(__y)); |
| 858 | } |
| 859 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 860 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 861 | syntax_option_type& |
| 862 | operator&=(syntax_option_type& __x, syntax_option_type __y) |
| 863 | { |
| 864 | __x = __x & __y; |
| 865 | return __x; |
| 866 | } |
| 867 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 868 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 869 | syntax_option_type& |
| 870 | operator|=(syntax_option_type& __x, syntax_option_type __y) |
| 871 | { |
| 872 | __x = __x | __y; |
| 873 | return __x; |
| 874 | } |
| 875 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 876 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 877 | syntax_option_type& |
| 878 | operator^=(syntax_option_type& __x, syntax_option_type __y) |
| 879 | { |
| 880 | __x = __x ^ __y; |
| 881 | return __x; |
| 882 | } |
| 883 | |
| 884 | // match_flag_type |
| 885 | |
| 886 | enum match_flag_type |
| 887 | { |
| 888 | match_default = 0, |
| 889 | match_not_bol = 1 << 0, |
| 890 | match_not_eol = 1 << 1, |
| 891 | match_not_bow = 1 << 2, |
| 892 | match_not_eow = 1 << 3, |
| 893 | match_any = 1 << 4, |
| 894 | match_not_null = 1 << 5, |
| 895 | match_continuous = 1 << 6, |
| 896 | match_prev_avail = 1 << 7, |
| 897 | format_default = 0, |
| 898 | format_sed = 1 << 8, |
| 899 | format_no_copy = 1 << 9, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 900 | format_first_only = 1 << 10, |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 901 | __no_update_pos = 1 << 11, |
| 902 | __full_match = 1 << 12 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 903 | }; |
| 904 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 905 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 906 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 907 | match_flag_type |
| 908 | operator~(match_flag_type __x) |
| 909 | { |
Marshall Clow | 924cffa | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 910 | return match_flag_type(~int(__x) & 0x0FFF); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 911 | } |
| 912 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 913 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 914 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 915 | match_flag_type |
| 916 | operator&(match_flag_type __x, match_flag_type __y) |
| 917 | { |
| 918 | return match_flag_type(int(__x) & int(__y)); |
| 919 | } |
| 920 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 921 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 922 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 923 | match_flag_type |
| 924 | operator|(match_flag_type __x, match_flag_type __y) |
| 925 | { |
| 926 | return match_flag_type(int(__x) | int(__y)); |
| 927 | } |
| 928 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 929 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 930 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 931 | match_flag_type |
| 932 | operator^(match_flag_type __x, match_flag_type __y) |
| 933 | { |
| 934 | return match_flag_type(int(__x) ^ int(__y)); |
| 935 | } |
| 936 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 937 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 938 | match_flag_type& |
| 939 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 940 | { |
| 941 | __x = __x & __y; |
| 942 | return __x; |
| 943 | } |
| 944 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 945 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 946 | match_flag_type& |
| 947 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 948 | { |
| 949 | __x = __x | __y; |
| 950 | return __x; |
| 951 | } |
| 952 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 953 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 954 | match_flag_type& |
| 955 | operator^=(match_flag_type& __x, match_flag_type __y) |
| 956 | { |
| 957 | __x = __x ^ __y; |
| 958 | return __x; |
| 959 | } |
| 960 | |
| 961 | enum error_type |
| 962 | { |
| 963 | error_collate = 1, |
| 964 | error_ctype, |
| 965 | error_escape, |
| 966 | error_backref, |
| 967 | error_brack, |
| 968 | error_paren, |
| 969 | error_brace, |
| 970 | error_badbrace, |
| 971 | error_range, |
| 972 | error_space, |
| 973 | error_badrepeat, |
| 974 | error_complexity, |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 975 | error_stack, |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 976 | __re_err_grammar, |
| 977 | __re_err_empty, |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 978 | __re_err_unknown, |
| 979 | __re_err_parse |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 980 | }; |
| 981 | |
Nikolas Klauser | d26407a | 2021-12-02 14:12:51 +0100 | [diff] [blame] | 982 | } // namespace regex_constants |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 983 | |
| 984 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 985 | : public runtime_error |
| 986 | { |
| 987 | regex_constants::error_type __code_; |
| 988 | public: |
| 989 | explicit regex_error(regex_constants::error_type __ecode); |
Dimitry Andric | 47269ce | 2020-03-13 19:36:26 +0100 | [diff] [blame] | 990 | regex_error(const regex_error&) _NOEXCEPT = default; |
| 991 | virtual ~regex_error() _NOEXCEPT; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 992 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 993 | regex_constants::error_type code() const {return __code_;} |
| 994 | }; |
| 995 | |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 996 | template <regex_constants::error_type _Ev> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 997 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 998 | void __throw_regex_error() |
| 999 | { |
| 1000 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Marshall Clow | 8bf61bb | 2015-08-17 21:14:16 +0000 | [diff] [blame] | 1001 | throw regex_error(_Ev); |
| 1002 | #else |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 1003 | _VSTD::abort(); |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 1004 | #endif |
| 1005 | } |
| 1006 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1007 | template <class _CharT> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1008 | struct _LIBCPP_TEMPLATE_VIS regex_traits |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1009 | { |
| 1010 | public: |
| 1011 | typedef _CharT char_type; |
| 1012 | typedef basic_string<char_type> string_type; |
| 1013 | typedef locale locale_type; |
Dan Albert | 70ee07e | 2020-04-06 13:34:27 -0700 | [diff] [blame] | 1014 | #ifdef __BIONIC__ |
| 1015 | // Originally bionic's ctype_base used its own ctype masks because the |
| 1016 | // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask |
| 1017 | // was only 8 bits wide and already saturated, so it used a wider type here |
| 1018 | // to make room for __regex_word (then a part of this class rather than |
| 1019 | // ctype_base). Bionic has since moved to the builtin ctype_base |
| 1020 | // implementation, but this was not updated to match. Since then Android has |
| 1021 | // needed to maintain a stable libc++ ABI, and this can't be changed without |
| 1022 | // an ABI break. |
| 1023 | typedef uint16_t char_class_type; |
| 1024 | #else |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1025 | typedef ctype_base::mask char_class_type; |
Dan Albert | 70ee07e | 2020-04-06 13:34:27 -0700 | [diff] [blame] | 1026 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1027 | |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 1028 | static const char_class_type __regex_word = ctype_base::__regex_word; |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1029 | private: |
| 1030 | locale __loc_; |
| 1031 | const ctype<char_type>* __ct_; |
| 1032 | const collate<char_type>* __col_; |
| 1033 | |
| 1034 | public: |
| 1035 | regex_traits(); |
| 1036 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1037 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1038 | static size_t length(const char_type* __p) |
| 1039 | {return char_traits<char_type>::length(__p);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1040 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1041 | char_type translate(char_type __c) const {return __c;} |
| 1042 | char_type translate_nocase(char_type __c) const; |
| 1043 | template <class _ForwardIterator> |
| 1044 | string_type |
| 1045 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 1046 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1047 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1048 | string_type |
| 1049 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 1050 | {return __transform_primary(__f, __l, char_type());} |
| 1051 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1052 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1053 | string_type |
| 1054 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 1055 | {return __lookup_collatename(__f, __l, char_type());} |
| 1056 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1057 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1058 | char_class_type |
| 1059 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1060 | bool __icase = false) const |
| 1061 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 1062 | bool isctype(char_type __c, char_class_type __m) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1063 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1064 | int value(char_type __ch, int __radix) const |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1065 | {return __regex_traits_value(__ch, __radix);} |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1066 | locale_type imbue(locale_type __l); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1067 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1068 | locale_type getloc()const {return __loc_;} |
| 1069 | |
| 1070 | private: |
| 1071 | void __init(); |
| 1072 | |
| 1073 | template <class _ForwardIterator> |
| 1074 | string_type |
| 1075 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1076 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1077 | template <class _ForwardIterator> |
| 1078 | string_type |
| 1079 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1080 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1081 | template <class _ForwardIterator> |
| 1082 | string_type |
| 1083 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1084 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1085 | template <class _ForwardIterator> |
| 1086 | string_type |
| 1087 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1088 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1089 | template <class _ForwardIterator> |
| 1090 | char_class_type |
| 1091 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1092 | bool __icase, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1093 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1094 | template <class _ForwardIterator> |
| 1095 | char_class_type |
| 1096 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1097 | bool __icase, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1098 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1099 | |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1100 | static int __regex_traits_value(unsigned char __ch, int __radix); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1101 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1102 | int __regex_traits_value(char __ch, int __radix) const |
| 1103 | {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);} |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1104 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1105 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1106 | int __regex_traits_value(wchar_t __ch, int __radix) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1107 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1108 | }; |
| 1109 | |
| 1110 | template <class _CharT> |
Howard Hinnant | 592cb61 | 2013-03-07 19:38:08 +0000 | [diff] [blame] | 1111 | const typename regex_traits<_CharT>::char_class_type |
| 1112 | regex_traits<_CharT>::__regex_word; |
| 1113 | |
| 1114 | template <class _CharT> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1115 | regex_traits<_CharT>::regex_traits() |
| 1116 | { |
| 1117 | __init(); |
| 1118 | } |
| 1119 | |
| 1120 | template <class _CharT> |
| 1121 | typename regex_traits<_CharT>::char_type |
| 1122 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1123 | { |
| 1124 | return __ct_->tolower(__c); |
| 1125 | } |
| 1126 | |
| 1127 | template <class _CharT> |
| 1128 | template <class _ForwardIterator> |
| 1129 | typename regex_traits<_CharT>::string_type |
| 1130 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1131 | { |
| 1132 | string_type __s(__f, __l); |
| 1133 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1134 | } |
| 1135 | |
| 1136 | template <class _CharT> |
| 1137 | void |
| 1138 | regex_traits<_CharT>::__init() |
| 1139 | { |
| 1140 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1141 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1142 | } |
| 1143 | |
| 1144 | template <class _CharT> |
| 1145 | typename regex_traits<_CharT>::locale_type |
| 1146 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1147 | { |
| 1148 | locale __r = __loc_; |
| 1149 | __loc_ = __l; |
| 1150 | __init(); |
| 1151 | return __r; |
| 1152 | } |
| 1153 | |
| 1154 | // transform_primary is very FreeBSD-specific |
| 1155 | |
| 1156 | template <class _CharT> |
| 1157 | template <class _ForwardIterator> |
| 1158 | typename regex_traits<_CharT>::string_type |
| 1159 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1160 | _ForwardIterator __l, char) const |
| 1161 | { |
| 1162 | const string_type __s(__f, __l); |
| 1163 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1164 | switch (__d.size()) |
| 1165 | { |
| 1166 | case 1: |
| 1167 | break; |
| 1168 | case 12: |
| 1169 | __d[11] = __d[3]; |
| 1170 | break; |
| 1171 | default: |
| 1172 | __d.clear(); |
| 1173 | break; |
| 1174 | } |
| 1175 | return __d; |
| 1176 | } |
| 1177 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1178 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1179 | template <class _CharT> |
| 1180 | template <class _ForwardIterator> |
| 1181 | typename regex_traits<_CharT>::string_type |
| 1182 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1183 | _ForwardIterator __l, wchar_t) const |
| 1184 | { |
| 1185 | const string_type __s(__f, __l); |
| 1186 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1187 | switch (__d.size()) |
| 1188 | { |
| 1189 | case 1: |
| 1190 | break; |
| 1191 | case 3: |
| 1192 | __d[2] = __d[0]; |
| 1193 | break; |
| 1194 | default: |
| 1195 | __d.clear(); |
| 1196 | break; |
| 1197 | } |
| 1198 | return __d; |
| 1199 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1200 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1201 | |
| 1202 | // lookup_collatename is very FreeBSD-specific |
| 1203 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1204 | _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1205 | |
| 1206 | template <class _CharT> |
| 1207 | template <class _ForwardIterator> |
| 1208 | typename regex_traits<_CharT>::string_type |
| 1209 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1210 | _ForwardIterator __l, char) const |
| 1211 | { |
| 1212 | string_type __s(__f, __l); |
| 1213 | string_type __r; |
| 1214 | if (!__s.empty()) |
| 1215 | { |
| 1216 | __r = __get_collation_name(__s.c_str()); |
| 1217 | if (__r.empty() && __s.size() <= 2) |
| 1218 | { |
| 1219 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1220 | if (__r.size() == 1 || __r.size() == 12) |
| 1221 | __r = __s; |
| 1222 | else |
| 1223 | __r.clear(); |
| 1224 | } |
| 1225 | } |
| 1226 | return __r; |
| 1227 | } |
| 1228 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1229 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1230 | template <class _CharT> |
| 1231 | template <class _ForwardIterator> |
| 1232 | typename regex_traits<_CharT>::string_type |
| 1233 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1234 | _ForwardIterator __l, wchar_t) const |
| 1235 | { |
| 1236 | string_type __s(__f, __l); |
| 1237 | string __n; |
| 1238 | __n.reserve(__s.size()); |
| 1239 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1240 | __i != __e; ++__i) |
| 1241 | { |
| 1242 | if (static_cast<unsigned>(*__i) >= 127) |
| 1243 | return string_type(); |
| 1244 | __n.push_back(char(*__i)); |
| 1245 | } |
| 1246 | string_type __r; |
| 1247 | if (!__s.empty()) |
| 1248 | { |
| 1249 | __n = __get_collation_name(__n.c_str()); |
| 1250 | if (!__n.empty()) |
| 1251 | __r.assign(__n.begin(), __n.end()); |
| 1252 | else if (__s.size() <= 2) |
| 1253 | { |
| 1254 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1255 | if (__r.size() == 1 || __r.size() == 3) |
| 1256 | __r = __s; |
| 1257 | else |
| 1258 | __r.clear(); |
| 1259 | } |
| 1260 | } |
| 1261 | return __r; |
| 1262 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1263 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1264 | |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1265 | // lookup_classname |
| 1266 | |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 1267 | regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS |
| 1268 | __get_classname(const char* __s, bool __icase); |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1269 | |
| 1270 | template <class _CharT> |
| 1271 | template <class _ForwardIterator> |
| 1272 | typename regex_traits<_CharT>::char_class_type |
| 1273 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1274 | _ForwardIterator __l, |
| 1275 | bool __icase, char) const |
| 1276 | { |
| 1277 | string_type __s(__f, __l); |
| 1278 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1279 | return __get_classname(__s.c_str(), __icase); |
| 1280 | } |
| 1281 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1282 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1283 | template <class _CharT> |
| 1284 | template <class _ForwardIterator> |
| 1285 | typename regex_traits<_CharT>::char_class_type |
| 1286 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1287 | _ForwardIterator __l, |
| 1288 | bool __icase, wchar_t) const |
| 1289 | { |
| 1290 | string_type __s(__f, __l); |
| 1291 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1292 | string __n; |
| 1293 | __n.reserve(__s.size()); |
| 1294 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1295 | __i != __e; ++__i) |
| 1296 | { |
| 1297 | if (static_cast<unsigned>(*__i) >= 127) |
| 1298 | return char_class_type(); |
| 1299 | __n.push_back(char(*__i)); |
| 1300 | } |
| 1301 | return __get_classname(__n.c_str(), __icase); |
| 1302 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1303 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1304 | |
| 1305 | template <class _CharT> |
| 1306 | bool |
| 1307 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1308 | { |
| 1309 | if (__ct_->is(__m, __c)) |
| 1310 | return true; |
| 1311 | return (__c == '_' && (__m & __regex_word)); |
| 1312 | } |
| 1313 | |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1314 | inline _LIBCPP_INLINE_VISIBILITY |
| 1315 | bool __is_07(unsigned char c) |
| 1316 | { |
| 1317 | return (c & 0xF8u) == |
| 1318 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1319 | 0xF0; |
| 1320 | #else |
| 1321 | 0x30; |
| 1322 | #endif |
| 1323 | } |
| 1324 | |
| 1325 | inline _LIBCPP_INLINE_VISIBILITY |
| 1326 | bool __is_89(unsigned char c) |
| 1327 | { |
| 1328 | return (c & 0xFEu) == |
| 1329 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1330 | 0xF8; |
| 1331 | #else |
| 1332 | 0x38; |
| 1333 | #endif |
| 1334 | } |
| 1335 | |
| 1336 | inline _LIBCPP_INLINE_VISIBILITY |
| 1337 | unsigned char __to_lower(unsigned char c) |
| 1338 | { |
| 1339 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1340 | return c & 0xBF; |
| 1341 | #else |
| 1342 | return c | 0x20; |
| 1343 | #endif |
| 1344 | } |
| 1345 | |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1346 | template <class _CharT> |
| 1347 | int |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1348 | regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1349 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1350 | if (__is_07(__ch)) // '0' <= __ch && __ch <= '7' |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1351 | return __ch - '0'; |
| 1352 | if (__radix != 8) |
| 1353 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1354 | if (__is_89(__ch)) // '8' <= __ch && __ch <= '9' |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1355 | return __ch - '0'; |
| 1356 | if (__radix == 16) |
| 1357 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1358 | __ch = __to_lower(__ch); // tolower |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1359 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1360 | return __ch - ('a' - 10); |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1361 | } |
| 1362 | } |
| 1363 | return -1; |
| 1364 | } |
| 1365 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1366 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1367 | template <class _CharT> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1368 | inline |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1369 | int |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1370 | regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1371 | { |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1372 | return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1373 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1374 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1375 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1376 | template <class _CharT> class __node; |
| 1377 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1378 | template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1379 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1380 | template <class _BidirectionalIterator, |
| 1381 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1382 | class _LIBCPP_TEMPLATE_VIS match_results; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1383 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1384 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1385 | struct __state |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1386 | { |
| 1387 | enum |
| 1388 | { |
| 1389 | __end_state = -1000, |
| 1390 | __consume_input, // -999 |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1391 | __begin_marked_expr, // -998 |
| 1392 | __end_marked_expr, // -997 |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1393 | __pop_state, // -996 |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1394 | __accept_and_consume, // -995 |
| 1395 | __accept_but_not_consume, // -994 |
| 1396 | __reject, // -993 |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1397 | __split, |
| 1398 | __repeat |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1399 | }; |
| 1400 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1401 | int __do_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1402 | const _CharT* __first_; |
| 1403 | const _CharT* __current_; |
| 1404 | const _CharT* __last_; |
| 1405 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1406 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1407 | const __node<_CharT>* __node_; |
| 1408 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1409 | bool __at_first_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1410 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1411 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1412 | __state() |
| 1413 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1414 | __node_(nullptr), __flags_() {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1415 | }; |
| 1416 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1417 | // __node |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1418 | |
| 1419 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1420 | class __node |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1421 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1422 | __node(const __node&); |
| 1423 | __node& operator=(const __node&); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1424 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1425 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1426 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1427 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1428 | __node() {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1429 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1430 | virtual ~__node() {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1431 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1432 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 1433 | virtual void __exec(__state&) const {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1434 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 1435 | virtual void __exec_split(bool, __state&) const {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1436 | }; |
| 1437 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1438 | // __end_state |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1439 | |
| 1440 | template <class _CharT> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1441 | class __end_state |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1442 | : public __node<_CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1443 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1444 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1445 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1446 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1447 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1448 | __end_state() {} |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1449 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1450 | virtual void __exec(__state&) const; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1451 | }; |
| 1452 | |
| 1453 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1454 | void |
| 1455 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1456 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1457 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1458 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1459 | |
| 1460 | // __has_one_state |
| 1461 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1462 | template <class _CharT> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1463 | class __has_one_state |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1464 | : public __node<_CharT> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1465 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1466 | __node<_CharT>* __first_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1467 | |
| 1468 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1469 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1470 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1471 | : __first_(__s) {} |
| 1472 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1473 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1474 | __node<_CharT>* first() const {return __first_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1475 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1476 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1477 | }; |
| 1478 | |
| 1479 | // __owns_one_state |
| 1480 | |
| 1481 | template <class _CharT> |
| 1482 | class __owns_one_state |
| 1483 | : public __has_one_state<_CharT> |
| 1484 | { |
| 1485 | typedef __has_one_state<_CharT> base; |
| 1486 | |
| 1487 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1488 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1489 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1490 | : base(__s) {} |
| 1491 | |
| 1492 | virtual ~__owns_one_state(); |
| 1493 | }; |
| 1494 | |
| 1495 | template <class _CharT> |
| 1496 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1497 | { |
| 1498 | delete this->first(); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1501 | // __empty_state |
| 1502 | |
| 1503 | template <class _CharT> |
| 1504 | class __empty_state |
| 1505 | : public __owns_one_state<_CharT> |
| 1506 | { |
| 1507 | typedef __owns_one_state<_CharT> base; |
| 1508 | |
| 1509 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1510 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1511 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1512 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1513 | explicit __empty_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1514 | : base(__s) {} |
| 1515 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1516 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1517 | }; |
| 1518 | |
| 1519 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1520 | void |
| 1521 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1522 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1523 | __s.__do_ = __state::__accept_but_not_consume; |
| 1524 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | // __empty_non_own_state |
| 1528 | |
| 1529 | template <class _CharT> |
| 1530 | class __empty_non_own_state |
| 1531 | : public __has_one_state<_CharT> |
| 1532 | { |
| 1533 | typedef __has_one_state<_CharT> base; |
| 1534 | |
| 1535 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1536 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1537 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1538 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1539 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1540 | : base(__s) {} |
| 1541 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1542 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1543 | }; |
| 1544 | |
| 1545 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1546 | void |
| 1547 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1548 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1549 | __s.__do_ = __state::__accept_but_not_consume; |
| 1550 | __s.__node_ = this->first(); |
| 1551 | } |
| 1552 | |
| 1553 | // __repeat_one_loop |
| 1554 | |
| 1555 | template <class _CharT> |
| 1556 | class __repeat_one_loop |
| 1557 | : public __has_one_state<_CharT> |
| 1558 | { |
| 1559 | typedef __has_one_state<_CharT> base; |
| 1560 | |
| 1561 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1562 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1563 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1564 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1565 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1566 | : base(__s) {} |
| 1567 | |
| 1568 | virtual void __exec(__state&) const; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1569 | }; |
| 1570 | |
| 1571 | template <class _CharT> |
| 1572 | void |
| 1573 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1574 | { |
| 1575 | __s.__do_ = __state::__repeat; |
| 1576 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | // __owns_two_states |
| 1580 | |
| 1581 | template <class _CharT> |
| 1582 | class __owns_two_states |
| 1583 | : public __owns_one_state<_CharT> |
| 1584 | { |
| 1585 | typedef __owns_one_state<_CharT> base; |
| 1586 | |
| 1587 | base* __second_; |
| 1588 | |
| 1589 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1590 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1591 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1592 | : base(__s1), __second_(__s2) {} |
| 1593 | |
| 1594 | virtual ~__owns_two_states(); |
| 1595 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1596 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1597 | base* second() const {return __second_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1598 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1599 | base*& second() {return __second_;} |
| 1600 | }; |
| 1601 | |
| 1602 | template <class _CharT> |
| 1603 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1604 | { |
| 1605 | delete __second_; |
| 1606 | } |
| 1607 | |
| 1608 | // __loop |
| 1609 | |
| 1610 | template <class _CharT> |
| 1611 | class __loop |
| 1612 | : public __owns_two_states<_CharT> |
| 1613 | { |
| 1614 | typedef __owns_two_states<_CharT> base; |
| 1615 | |
| 1616 | size_t __min_; |
| 1617 | size_t __max_; |
| 1618 | unsigned __loop_id_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1619 | unsigned __mexp_begin_; |
| 1620 | unsigned __mexp_end_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1621 | bool __greedy_; |
| 1622 | |
| 1623 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1624 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1625 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1626 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1627 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1628 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1629 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1630 | bool __greedy = true, |
| 1631 | size_t __min = 0, |
| 1632 | size_t __max = numeric_limits<size_t>::max()) |
| 1633 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1634 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1635 | __greedy_(__greedy) {} |
| 1636 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1637 | virtual void __exec(__state& __s) const; |
| 1638 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1639 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1640 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1641 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1642 | void __init_repeat(__state& __s) const |
| 1643 | { |
| 1644 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1645 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1646 | { |
| 1647 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1648 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1649 | __s.__sub_matches_[__i].matched = false; |
| 1650 | } |
| 1651 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1652 | }; |
| 1653 | |
| 1654 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1655 | void |
| 1656 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1657 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1658 | if (__s.__do_ == __state::__repeat) |
| 1659 | { |
| 1660 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1661 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1662 | if (__do_repeat && __do_alt && |
| 1663 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1664 | __do_repeat = false; |
| 1665 | if (__do_repeat && __do_alt) |
| 1666 | __s.__do_ = __state::__split; |
| 1667 | else if (__do_repeat) |
| 1668 | { |
| 1669 | __s.__do_ = __state::__accept_but_not_consume; |
| 1670 | __s.__node_ = this->first(); |
| 1671 | __init_repeat(__s); |
| 1672 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1673 | else |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1674 | { |
| 1675 | __s.__do_ = __state::__accept_but_not_consume; |
| 1676 | __s.__node_ = this->second(); |
| 1677 | } |
| 1678 | } |
| 1679 | else |
| 1680 | { |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1681 | __s.__loop_data_[__loop_id_].first = 0; |
| 1682 | bool __do_repeat = 0 < __max_; |
| 1683 | bool __do_alt = 0 >= __min_; |
| 1684 | if (__do_repeat && __do_alt) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1685 | __s.__do_ = __state::__split; |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1686 | else if (__do_repeat) |
| 1687 | { |
| 1688 | __s.__do_ = __state::__accept_but_not_consume; |
| 1689 | __s.__node_ = this->first(); |
| 1690 | __init_repeat(__s); |
| 1691 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1692 | else |
| 1693 | { |
| 1694 | __s.__do_ = __state::__accept_but_not_consume; |
| 1695 | __s.__node_ = this->second(); |
| 1696 | } |
| 1697 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1700 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1701 | void |
| 1702 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1703 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1704 | __s.__do_ = __state::__accept_but_not_consume; |
| 1705 | if (__greedy_ != __second) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1706 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1707 | __s.__node_ = this->first(); |
| 1708 | __init_repeat(__s); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1709 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1710 | else |
| 1711 | __s.__node_ = this->second(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1714 | // __alternate |
| 1715 | |
| 1716 | template <class _CharT> |
| 1717 | class __alternate |
| 1718 | : public __owns_two_states<_CharT> |
| 1719 | { |
| 1720 | typedef __owns_two_states<_CharT> base; |
| 1721 | |
| 1722 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1723 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1724 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1725 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1726 | explicit __alternate(__owns_one_state<_CharT>* __s1, |
| 1727 | __owns_one_state<_CharT>* __s2) |
| 1728 | : base(__s1, __s2) {} |
| 1729 | |
| 1730 | virtual void __exec(__state& __s) const; |
| 1731 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1732 | }; |
| 1733 | |
| 1734 | template <class _CharT> |
| 1735 | void |
| 1736 | __alternate<_CharT>::__exec(__state& __s) const |
| 1737 | { |
| 1738 | __s.__do_ = __state::__split; |
| 1739 | } |
| 1740 | |
| 1741 | template <class _CharT> |
| 1742 | void |
| 1743 | __alternate<_CharT>::__exec_split(bool __second, __state& __s) const |
| 1744 | { |
| 1745 | __s.__do_ = __state::__accept_but_not_consume; |
Howard Hinnant | cbf2f3f | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1746 | if (__second) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1747 | __s.__node_ = this->second(); |
Howard Hinnant | cbf2f3f | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1748 | else |
| 1749 | __s.__node_ = this->first(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1752 | // __begin_marked_subexpression |
| 1753 | |
| 1754 | template <class _CharT> |
| 1755 | class __begin_marked_subexpression |
| 1756 | : public __owns_one_state<_CharT> |
| 1757 | { |
| 1758 | typedef __owns_one_state<_CharT> base; |
| 1759 | |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1760 | unsigned __mexp_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1761 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1762 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1763 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1764 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1765 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1766 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1767 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1768 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1769 | }; |
| 1770 | |
| 1771 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1772 | void |
| 1773 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1774 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1775 | __s.__do_ = __state::__accept_but_not_consume; |
| 1776 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1777 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | // __end_marked_subexpression |
| 1781 | |
| 1782 | template <class _CharT> |
| 1783 | class __end_marked_subexpression |
| 1784 | : public __owns_one_state<_CharT> |
| 1785 | { |
| 1786 | typedef __owns_one_state<_CharT> base; |
| 1787 | |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1788 | unsigned __mexp_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1789 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1790 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1791 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1792 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1793 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1794 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1795 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1796 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1797 | }; |
| 1798 | |
| 1799 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1800 | void |
| 1801 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1802 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1803 | __s.__do_ = __state::__accept_but_not_consume; |
| 1804 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1805 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1806 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1809 | // __back_ref |
| 1810 | |
| 1811 | template <class _CharT> |
| 1812 | class __back_ref |
| 1813 | : public __owns_one_state<_CharT> |
| 1814 | { |
| 1815 | typedef __owns_one_state<_CharT> base; |
| 1816 | |
| 1817 | unsigned __mexp_; |
| 1818 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1819 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1820 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1821 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1822 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1823 | : base(__s), __mexp_(__mexp) {} |
| 1824 | |
| 1825 | virtual void __exec(__state&) const; |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1826 | }; |
| 1827 | |
| 1828 | template <class _CharT> |
| 1829 | void |
| 1830 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1831 | { |
Marshall Clow | 360e839 | 2015-08-24 15:57:09 +0000 | [diff] [blame] | 1832 | if (__mexp_ > __s.__sub_matches_.size()) |
| 1833 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1834 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1835 | if (__sm.matched) |
| 1836 | { |
| 1837 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1838 | if (__s.__last_ - __s.__current_ >= __len && |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1839 | _VSTD::equal(__sm.first, __sm.second, __s.__current_)) |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1840 | { |
| 1841 | __s.__do_ = __state::__accept_but_not_consume; |
| 1842 | __s.__current_ += __len; |
| 1843 | __s.__node_ = this->first(); |
| 1844 | } |
| 1845 | else |
| 1846 | { |
| 1847 | __s.__do_ = __state::__reject; |
| 1848 | __s.__node_ = nullptr; |
| 1849 | } |
| 1850 | } |
| 1851 | else |
| 1852 | { |
| 1853 | __s.__do_ = __state::__reject; |
| 1854 | __s.__node_ = nullptr; |
| 1855 | } |
| 1856 | } |
| 1857 | |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1858 | // __back_ref_icase |
| 1859 | |
| 1860 | template <class _CharT, class _Traits> |
| 1861 | class __back_ref_icase |
| 1862 | : public __owns_one_state<_CharT> |
| 1863 | { |
| 1864 | typedef __owns_one_state<_CharT> base; |
| 1865 | |
| 1866 | _Traits __traits_; |
| 1867 | unsigned __mexp_; |
| 1868 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1869 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1870 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1871 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1872 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1873 | __node<_CharT>* __s) |
| 1874 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1875 | |
| 1876 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1877 | }; |
| 1878 | |
| 1879 | template <class _CharT, class _Traits> |
| 1880 | void |
| 1881 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1882 | { |
| 1883 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1884 | if (__sm.matched) |
| 1885 | { |
| 1886 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1887 | if (__s.__last_ - __s.__current_ >= __len) |
| 1888 | { |
| 1889 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1890 | { |
| 1891 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1892 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1893 | goto __not_equal; |
| 1894 | } |
| 1895 | __s.__do_ = __state::__accept_but_not_consume; |
| 1896 | __s.__current_ += __len; |
| 1897 | __s.__node_ = this->first(); |
| 1898 | } |
| 1899 | else |
| 1900 | { |
| 1901 | __s.__do_ = __state::__reject; |
| 1902 | __s.__node_ = nullptr; |
| 1903 | } |
| 1904 | } |
| 1905 | else |
| 1906 | { |
| 1907 | __not_equal: |
| 1908 | __s.__do_ = __state::__reject; |
| 1909 | __s.__node_ = nullptr; |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | // __back_ref_collate |
| 1914 | |
| 1915 | template <class _CharT, class _Traits> |
| 1916 | class __back_ref_collate |
| 1917 | : public __owns_one_state<_CharT> |
| 1918 | { |
| 1919 | typedef __owns_one_state<_CharT> base; |
| 1920 | |
| 1921 | _Traits __traits_; |
| 1922 | unsigned __mexp_; |
| 1923 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1924 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1925 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1926 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1927 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1928 | __node<_CharT>* __s) |
| 1929 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1930 | |
| 1931 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1932 | }; |
| 1933 | |
| 1934 | template <class _CharT, class _Traits> |
| 1935 | void |
| 1936 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1937 | { |
| 1938 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1939 | if (__sm.matched) |
| 1940 | { |
| 1941 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1942 | if (__s.__last_ - __s.__current_ >= __len) |
| 1943 | { |
| 1944 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1945 | { |
| 1946 | if (__traits_.translate(__sm.first[__i]) != |
| 1947 | __traits_.translate(__s.__current_[__i])) |
| 1948 | goto __not_equal; |
| 1949 | } |
| 1950 | __s.__do_ = __state::__accept_but_not_consume; |
| 1951 | __s.__current_ += __len; |
| 1952 | __s.__node_ = this->first(); |
| 1953 | } |
| 1954 | else |
| 1955 | { |
| 1956 | __s.__do_ = __state::__reject; |
| 1957 | __s.__node_ = nullptr; |
| 1958 | } |
| 1959 | } |
| 1960 | else |
| 1961 | { |
| 1962 | __not_equal: |
| 1963 | __s.__do_ = __state::__reject; |
| 1964 | __s.__node_ = nullptr; |
| 1965 | } |
| 1966 | } |
| 1967 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1968 | // __word_boundary |
| 1969 | |
| 1970 | template <class _CharT, class _Traits> |
| 1971 | class __word_boundary |
| 1972 | : public __owns_one_state<_CharT> |
| 1973 | { |
| 1974 | typedef __owns_one_state<_CharT> base; |
| 1975 | |
| 1976 | _Traits __traits_; |
| 1977 | bool __invert_; |
| 1978 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1979 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1980 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1981 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1982 | explicit __word_boundary(const _Traits& __traits, bool __invert, |
| 1983 | __node<_CharT>* __s) |
| 1984 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 1985 | |
| 1986 | virtual void __exec(__state&) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1987 | }; |
| 1988 | |
| 1989 | template <class _CharT, class _Traits> |
| 1990 | void |
| 1991 | __word_boundary<_CharT, _Traits>::__exec(__state& __s) const |
| 1992 | { |
| 1993 | bool __is_word_b = false; |
| 1994 | if (__s.__first_ != __s.__last_) |
| 1995 | { |
| 1996 | if (__s.__current_ == __s.__last_) |
| 1997 | { |
| 1998 | if (!(__s.__flags_ & regex_constants::match_not_eow)) |
| 1999 | { |
| 2000 | _CharT __c = __s.__current_[-1]; |
| 2001 | __is_word_b = __c == '_' || |
| 2002 | __traits_.isctype(__c, ctype_base::alnum); |
| 2003 | } |
| 2004 | } |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 2005 | else if (__s.__current_ == __s.__first_ && |
| 2006 | !(__s.__flags_ & regex_constants::match_prev_avail)) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2007 | { |
| 2008 | if (!(__s.__flags_ & regex_constants::match_not_bow)) |
| 2009 | { |
| 2010 | _CharT __c = *__s.__current_; |
| 2011 | __is_word_b = __c == '_' || |
| 2012 | __traits_.isctype(__c, ctype_base::alnum); |
| 2013 | } |
| 2014 | } |
| 2015 | else |
| 2016 | { |
| 2017 | _CharT __c1 = __s.__current_[-1]; |
| 2018 | _CharT __c2 = *__s.__current_; |
| 2019 | bool __is_c1_b = __c1 == '_' || |
| 2020 | __traits_.isctype(__c1, ctype_base::alnum); |
| 2021 | bool __is_c2_b = __c2 == '_' || |
| 2022 | __traits_.isctype(__c2, ctype_base::alnum); |
| 2023 | __is_word_b = __is_c1_b != __is_c2_b; |
| 2024 | } |
| 2025 | } |
| 2026 | if (__is_word_b != __invert_) |
| 2027 | { |
| 2028 | __s.__do_ = __state::__accept_but_not_consume; |
| 2029 | __s.__node_ = this->first(); |
| 2030 | } |
| 2031 | else |
| 2032 | { |
| 2033 | __s.__do_ = __state::__reject; |
| 2034 | __s.__node_ = nullptr; |
| 2035 | } |
| 2036 | } |
| 2037 | |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2038 | // __l_anchor |
| 2039 | |
| 2040 | template <class _CharT> |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2041 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 2042 | bool __is_eol(_CharT c) |
| 2043 | { |
| 2044 | return c == '\r' || c == '\n'; |
| 2045 | } |
| 2046 | |
| 2047 | template <class _CharT> |
| 2048 | class __l_anchor_multiline |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2049 | : public __owns_one_state<_CharT> |
| 2050 | { |
| 2051 | typedef __owns_one_state<_CharT> base; |
| 2052 | |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2053 | bool __multiline_; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2054 | |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2055 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2056 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2057 | |
| 2058 | _LIBCPP_INLINE_VISIBILITY |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2059 | __l_anchor_multiline(bool __multiline, __node<_CharT>* __s) |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2060 | : base(__s), __multiline_(__multiline) {} |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2061 | |
| 2062 | virtual void __exec(__state&) const; |
| 2063 | }; |
| 2064 | |
| 2065 | template <class _CharT> |
| 2066 | void |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2067 | __l_anchor_multiline<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2068 | { |
Marshall Clow | 5440439 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 2069 | if (__s.__at_first_ && __s.__current_ == __s.__first_ && |
| 2070 | !(__s.__flags_ & regex_constants::match_not_bol)) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2071 | { |
| 2072 | __s.__do_ = __state::__accept_but_not_consume; |
| 2073 | __s.__node_ = this->first(); |
| 2074 | } |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2075 | else if (__multiline_ && |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2076 | !__s.__at_first_ && |
| 2077 | __is_eol(*_VSTD::prev(__s.__current_))) |
| 2078 | { |
| 2079 | __s.__do_ = __state::__accept_but_not_consume; |
| 2080 | __s.__node_ = this->first(); |
| 2081 | } |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2082 | else |
| 2083 | { |
| 2084 | __s.__do_ = __state::__reject; |
| 2085 | __s.__node_ = nullptr; |
| 2086 | } |
| 2087 | } |
| 2088 | |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2089 | // __r_anchor |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2090 | |
| 2091 | template <class _CharT> |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2092 | class __r_anchor_multiline |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2093 | : public __owns_one_state<_CharT> |
| 2094 | { |
| 2095 | typedef __owns_one_state<_CharT> base; |
| 2096 | |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2097 | bool __multiline; |
| 2098 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2099 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2100 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2101 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2102 | _LIBCPP_INLINE_VISIBILITY |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2103 | __r_anchor_multiline(bool __multiline, __node<_CharT>* __s) |
| 2104 | : base(__s), __multiline(__multiline) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2105 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2106 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2107 | }; |
| 2108 | |
| 2109 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2110 | void |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2111 | __r_anchor_multiline<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2112 | { |
Marshall Clow | 5440439 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 2113 | if (__s.__current_ == __s.__last_ && |
| 2114 | !(__s.__flags_ & regex_constants::match_not_eol)) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2115 | { |
| 2116 | __s.__do_ = __state::__accept_but_not_consume; |
| 2117 | __s.__node_ = this->first(); |
| 2118 | } |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2119 | else if (__multiline && __is_eol(*__s.__current_)) |
| 2120 | { |
| 2121 | __s.__do_ = __state::__accept_but_not_consume; |
| 2122 | __s.__node_ = this->first(); |
| 2123 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2124 | else |
| 2125 | { |
| 2126 | __s.__do_ = __state::__reject; |
| 2127 | __s.__node_ = nullptr; |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | // __match_any |
| 2132 | |
| 2133 | template <class _CharT> |
| 2134 | class __match_any |
| 2135 | : public __owns_one_state<_CharT> |
| 2136 | { |
| 2137 | typedef __owns_one_state<_CharT> base; |
| 2138 | |
| 2139 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2140 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2141 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2142 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2143 | __match_any(__node<_CharT>* __s) |
| 2144 | : base(__s) {} |
| 2145 | |
| 2146 | virtual void __exec(__state&) const; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2147 | }; |
| 2148 | |
| 2149 | template <class _CharT> |
| 2150 | void |
| 2151 | __match_any<_CharT>::__exec(__state& __s) const |
| 2152 | { |
| 2153 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 2154 | { |
| 2155 | __s.__do_ = __state::__accept_and_consume; |
| 2156 | ++__s.__current_; |
| 2157 | __s.__node_ = this->first(); |
| 2158 | } |
| 2159 | else |
| 2160 | { |
| 2161 | __s.__do_ = __state::__reject; |
| 2162 | __s.__node_ = nullptr; |
| 2163 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2164 | } |
| 2165 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2166 | // __match_any_but_newline |
| 2167 | |
| 2168 | template <class _CharT> |
| 2169 | class __match_any_but_newline |
| 2170 | : public __owns_one_state<_CharT> |
| 2171 | { |
| 2172 | typedef __owns_one_state<_CharT> base; |
| 2173 | |
| 2174 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2175 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2176 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2177 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2178 | __match_any_but_newline(__node<_CharT>* __s) |
| 2179 | : base(__s) {} |
| 2180 | |
| 2181 | virtual void __exec(__state&) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2182 | }; |
| 2183 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2184 | template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2185 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2186 | template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2187 | #endif |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2188 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2189 | // __match_char |
| 2190 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2191 | template <class _CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2192 | class __match_char |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2193 | : public __owns_one_state<_CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2194 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2195 | typedef __owns_one_state<_CharT> base; |
| 2196 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2197 | _CharT __c_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2198 | |
| 2199 | __match_char(const __match_char&); |
| 2200 | __match_char& operator=(const __match_char&); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2201 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2202 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2203 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2204 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2205 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2206 | : base(__s), __c_(__c) {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2207 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2208 | virtual void __exec(__state&) const; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2209 | }; |
| 2210 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2211 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2212 | void |
| 2213 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2214 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2215 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2216 | { |
| 2217 | __s.__do_ = __state::__accept_and_consume; |
| 2218 | ++__s.__current_; |
| 2219 | __s.__node_ = this->first(); |
| 2220 | } |
| 2221 | else |
| 2222 | { |
| 2223 | __s.__do_ = __state::__reject; |
| 2224 | __s.__node_ = nullptr; |
| 2225 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2226 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2227 | |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2228 | // __match_char_icase |
| 2229 | |
| 2230 | template <class _CharT, class _Traits> |
| 2231 | class __match_char_icase |
| 2232 | : public __owns_one_state<_CharT> |
| 2233 | { |
| 2234 | typedef __owns_one_state<_CharT> base; |
| 2235 | |
| 2236 | _Traits __traits_; |
| 2237 | _CharT __c_; |
| 2238 | |
| 2239 | __match_char_icase(const __match_char_icase&); |
| 2240 | __match_char_icase& operator=(const __match_char_icase&); |
| 2241 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2242 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2243 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2244 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2245 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2246 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2247 | |
| 2248 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2249 | }; |
| 2250 | |
| 2251 | template <class _CharT, class _Traits> |
| 2252 | void |
| 2253 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2254 | { |
| 2255 | if (__s.__current_ != __s.__last_ && |
| 2256 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2257 | { |
| 2258 | __s.__do_ = __state::__accept_and_consume; |
| 2259 | ++__s.__current_; |
| 2260 | __s.__node_ = this->first(); |
| 2261 | } |
| 2262 | else |
| 2263 | { |
| 2264 | __s.__do_ = __state::__reject; |
| 2265 | __s.__node_ = nullptr; |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | // __match_char_collate |
| 2270 | |
| 2271 | template <class _CharT, class _Traits> |
| 2272 | class __match_char_collate |
| 2273 | : public __owns_one_state<_CharT> |
| 2274 | { |
| 2275 | typedef __owns_one_state<_CharT> base; |
| 2276 | |
| 2277 | _Traits __traits_; |
| 2278 | _CharT __c_; |
| 2279 | |
| 2280 | __match_char_collate(const __match_char_collate&); |
| 2281 | __match_char_collate& operator=(const __match_char_collate&); |
| 2282 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2283 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2284 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2285 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2286 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2287 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2288 | |
| 2289 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2290 | }; |
| 2291 | |
| 2292 | template <class _CharT, class _Traits> |
| 2293 | void |
| 2294 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2295 | { |
| 2296 | if (__s.__current_ != __s.__last_ && |
| 2297 | __traits_.translate(*__s.__current_) == __c_) |
| 2298 | { |
| 2299 | __s.__do_ = __state::__accept_and_consume; |
| 2300 | ++__s.__current_; |
| 2301 | __s.__node_ = this->first(); |
| 2302 | } |
| 2303 | else |
| 2304 | { |
| 2305 | __s.__do_ = __state::__reject; |
| 2306 | __s.__node_ = nullptr; |
| 2307 | } |
| 2308 | } |
| 2309 | |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2310 | // __bracket_expression |
| 2311 | |
| 2312 | template <class _CharT, class _Traits> |
| 2313 | class __bracket_expression |
| 2314 | : public __owns_one_state<_CharT> |
| 2315 | { |
| 2316 | typedef __owns_one_state<_CharT> base; |
| 2317 | typedef typename _Traits::string_type string_type; |
| 2318 | |
| 2319 | _Traits __traits_; |
| 2320 | vector<_CharT> __chars_; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2321 | vector<_CharT> __neg_chars_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2322 | vector<pair<string_type, string_type> > __ranges_; |
| 2323 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2324 | vector<string_type> __equivalences_; |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2325 | typename regex_traits<_CharT>::char_class_type __mask_; |
| 2326 | typename regex_traits<_CharT>::char_class_type __neg_mask_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2327 | bool __negate_; |
| 2328 | bool __icase_; |
| 2329 | bool __collate_; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2330 | bool __might_have_digraph_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2331 | |
| 2332 | __bracket_expression(const __bracket_expression&); |
| 2333 | __bracket_expression& operator=(const __bracket_expression&); |
| 2334 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2335 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2336 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2337 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2338 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2339 | bool __negate, bool __icase, bool __collate) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2340 | : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), |
| 2341 | __negate_(__negate), __icase_(__icase), __collate_(__collate), |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2342 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2343 | |
| 2344 | virtual void __exec(__state&) const; |
| 2345 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2346 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2347 | bool __negated() const {return __negate_;} |
| 2348 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2349 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2350 | void __add_char(_CharT __c) |
| 2351 | { |
| 2352 | if (__icase_) |
| 2353 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2354 | else if (__collate_) |
| 2355 | __chars_.push_back(__traits_.translate(__c)); |
| 2356 | else |
| 2357 | __chars_.push_back(__c); |
| 2358 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2359 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2360 | void __add_neg_char(_CharT __c) |
| 2361 | { |
| 2362 | if (__icase_) |
| 2363 | __neg_chars_.push_back(__traits_.translate_nocase(__c)); |
| 2364 | else if (__collate_) |
| 2365 | __neg_chars_.push_back(__traits_.translate(__c)); |
| 2366 | else |
| 2367 | __neg_chars_.push_back(__c); |
| 2368 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2369 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2370 | void __add_range(string_type __b, string_type __e) |
| 2371 | { |
| 2372 | if (__collate_) |
| 2373 | { |
| 2374 | if (__icase_) |
| 2375 | { |
| 2376 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2377 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2378 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2379 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2380 | } |
| 2381 | else |
| 2382 | { |
| 2383 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2384 | __b[__i] = __traits_.translate(__b[__i]); |
| 2385 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2386 | __e[__i] = __traits_.translate(__e[__i]); |
| 2387 | } |
| 2388 | __ranges_.push_back(make_pair( |
| 2389 | __traits_.transform(__b.begin(), __b.end()), |
| 2390 | __traits_.transform(__e.begin(), __e.end()))); |
| 2391 | } |
| 2392 | else |
| 2393 | { |
| 2394 | if (__b.size() != 1 || __e.size() != 1) |
Marshall Clow | a521211 | 2019-05-28 22:42:32 +0000 | [diff] [blame] | 2395 | __throw_regex_error<regex_constants::error_range>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2396 | if (__icase_) |
| 2397 | { |
| 2398 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2399 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2400 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2401 | __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e))); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2402 | } |
| 2403 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2404 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2405 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2406 | { |
| 2407 | if (__icase_) |
| 2408 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2409 | __traits_.translate_nocase(__c2))); |
| 2410 | else if (__collate_) |
| 2411 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2412 | __traits_.translate(__c2))); |
| 2413 | else |
| 2414 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2415 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2416 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2417 | void __add_equivalence(const string_type& __s) |
| 2418 | {__equivalences_.push_back(__s);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2419 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2420 | void __add_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2421 | {__mask_ |= __mask;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2422 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2423 | void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2424 | {__neg_mask_ |= __mask;} |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2425 | }; |
| 2426 | |
| 2427 | template <class _CharT, class _Traits> |
| 2428 | void |
| 2429 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2430 | { |
| 2431 | bool __found = false; |
| 2432 | unsigned __consumed = 0; |
| 2433 | if (__s.__current_ != __s.__last_) |
| 2434 | { |
| 2435 | ++__consumed; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2436 | if (__might_have_digraph_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2437 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2438 | const _CharT* __next = _VSTD::next(__s.__current_); |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2439 | if (__next != __s.__last_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2440 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2441 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2442 | if (__icase_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2443 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2444 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2445 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2446 | } |
| 2447 | else if (__collate_) |
| 2448 | { |
| 2449 | __ch2.first = __traits_.translate(__ch2.first); |
| 2450 | __ch2.second = __traits_.translate(__ch2.second); |
| 2451 | } |
| 2452 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2453 | { |
| 2454 | // __ch2 is a digraph in this locale |
| 2455 | ++__consumed; |
| 2456 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2457 | { |
| 2458 | if (__ch2 == __digraphs_[__i]) |
| 2459 | { |
| 2460 | __found = true; |
| 2461 | goto __exit; |
| 2462 | } |
| 2463 | } |
| 2464 | if (__collate_ && !__ranges_.empty()) |
| 2465 | { |
| 2466 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2467 | &__ch2.first + 2); |
| 2468 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2469 | { |
| 2470 | if (__ranges_[__i].first <= __s2 && |
| 2471 | __s2 <= __ranges_[__i].second) |
| 2472 | { |
| 2473 | __found = true; |
| 2474 | goto __exit; |
| 2475 | } |
| 2476 | } |
| 2477 | } |
| 2478 | if (!__equivalences_.empty()) |
| 2479 | { |
| 2480 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2481 | &__ch2.first + 2); |
| 2482 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2483 | { |
| 2484 | if (__s2 == __equivalences_[__i]) |
| 2485 | { |
| 2486 | __found = true; |
| 2487 | goto __exit; |
| 2488 | } |
| 2489 | } |
| 2490 | } |
| 2491 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2492 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2493 | { |
| 2494 | __found = true; |
| 2495 | goto __exit; |
| 2496 | } |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2497 | if (!__traits_.isctype(__ch2.first, __neg_mask_) && |
| 2498 | !__traits_.isctype(__ch2.second, __neg_mask_)) |
| 2499 | { |
| 2500 | __found = true; |
| 2501 | goto __exit; |
| 2502 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2503 | goto __exit; |
| 2504 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2505 | } |
| 2506 | } |
| 2507 | // test *__s.__current_ as not a digraph |
| 2508 | _CharT __ch = *__s.__current_; |
| 2509 | if (__icase_) |
| 2510 | __ch = __traits_.translate_nocase(__ch); |
| 2511 | else if (__collate_) |
| 2512 | __ch = __traits_.translate(__ch); |
| 2513 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2514 | { |
| 2515 | if (__ch == __chars_[__i]) |
| 2516 | { |
| 2517 | __found = true; |
| 2518 | goto __exit; |
| 2519 | } |
| 2520 | } |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2521 | // When there's at least one of __neg_chars_ and __neg_mask_, the set |
| 2522 | // of "__found" chars is |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2523 | // union(complement(union(__neg_chars_, __neg_mask_)), |
| 2524 | // other cases...) |
| 2525 | // |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2526 | // It doesn't make sense to check this when there are no __neg_chars_ |
| 2527 | // and no __neg_mask_. |
| 2528 | if (!(__neg_mask_ == 0 && __neg_chars_.empty())) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2529 | { |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2530 | const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_); |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2531 | const bool __in_neg_chars = |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 2532 | _VSTD::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2533 | __neg_chars_.end(); |
| 2534 | if (!(__in_neg_mask || __in_neg_chars)) |
| 2535 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2536 | __found = true; |
| 2537 | goto __exit; |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2538 | } |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2539 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2540 | if (!__ranges_.empty()) |
| 2541 | { |
| 2542 | string_type __s2 = __collate_ ? |
| 2543 | __traits_.transform(&__ch, &__ch + 1) : |
| 2544 | string_type(1, __ch); |
| 2545 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2546 | { |
| 2547 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2548 | { |
| 2549 | __found = true; |
| 2550 | goto __exit; |
| 2551 | } |
| 2552 | } |
| 2553 | } |
| 2554 | if (!__equivalences_.empty()) |
| 2555 | { |
| 2556 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2557 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2558 | { |
| 2559 | if (__s2 == __equivalences_[__i]) |
| 2560 | { |
| 2561 | __found = true; |
| 2562 | goto __exit; |
| 2563 | } |
| 2564 | } |
| 2565 | } |
| 2566 | if (__traits_.isctype(__ch, __mask_)) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2567 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2568 | __found = true; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2569 | goto __exit; |
| 2570 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2571 | } |
| 2572 | else |
| 2573 | __found = __negate_; // force reject |
| 2574 | __exit: |
| 2575 | if (__found != __negate_) |
| 2576 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2577 | __s.__do_ = __state::__accept_and_consume; |
| 2578 | __s.__current_ += __consumed; |
| 2579 | __s.__node_ = this->first(); |
| 2580 | } |
| 2581 | else |
| 2582 | { |
| 2583 | __s.__do_ = __state::__reject; |
| 2584 | __s.__node_ = nullptr; |
| 2585 | } |
| 2586 | } |
| 2587 | |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 2588 | template <class _CharT, class _Traits> class __lookahead; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2589 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2590 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2591 | class _LIBCPP_TEMPLATE_VIS basic_regex; |
| 2592 | |
| 2593 | typedef basic_regex<char> regex; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2594 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2595 | typedef basic_regex<wchar_t> wregex; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2596 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2597 | |
| 2598 | template <class _CharT, class _Traits> |
| 2599 | class |
| 2600 | _LIBCPP_TEMPLATE_VIS |
| 2601 | _LIBCPP_PREFERRED_NAME(regex) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2602 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2603 | basic_regex |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2604 | { |
| 2605 | public: |
| 2606 | // types: |
| 2607 | typedef _CharT value_type; |
Hubert Tong | 1f1ae9c | 2016-08-02 21:34:48 +0000 | [diff] [blame] | 2608 | typedef _Traits traits_type; |
| 2609 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2610 | typedef regex_constants::syntax_option_type flag_type; |
| 2611 | typedef typename _Traits::locale_type locale_type; |
| 2612 | |
| 2613 | private: |
| 2614 | _Traits __traits_; |
| 2615 | flag_type __flags_; |
| 2616 | unsigned __marked_count_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2617 | unsigned __loop_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2618 | int __open_count_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2619 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2620 | __owns_one_state<_CharT>* __end_; |
| 2621 | |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2622 | typedef _VSTD::__state<_CharT> __state; |
| 2623 | typedef _VSTD::__node<_CharT> __node; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2624 | |
| 2625 | public: |
| 2626 | // constants: |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2627 | static const regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2628 | static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2629 | static const regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2630 | static const regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2631 | static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2632 | static const regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2633 | static const regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2634 | static const regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2635 | static const regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2636 | static const regex_constants::syntax_option_type egrep = regex_constants::egrep; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2637 | static const regex_constants::syntax_option_type multiline = regex_constants::multiline; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2638 | |
| 2639 | // construct/copy/destroy: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2640 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2641 | basic_regex() |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2642 | : __flags_(regex_constants::ECMAScript), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2643 | __end_(nullptr) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2644 | {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2645 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2646 | explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2647 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2648 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2649 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2650 | __init(__p, __p + __traits_.length(__p)); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2651 | } |
| 2652 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2653 | _LIBCPP_INLINE_VISIBILITY |
Hubert Tong | 1966286 | 2016-08-07 22:26:04 +0000 | [diff] [blame] | 2654 | basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2655 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2656 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2657 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2658 | __init(__p, __p + __len); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2659 | } |
| 2660 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2661 | // basic_regex(const basic_regex&) = default; |
| 2662 | // basic_regex(basic_regex&&) = default; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2663 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2664 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2665 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2666 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2667 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2668 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2669 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2670 | __init(__p.begin(), __p.end()); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2673 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2674 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2675 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 2676 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2677 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2678 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2679 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2680 | __init(__first, __last); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2681 | } |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2682 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2683 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2684 | basic_regex(initializer_list<value_type> __il, |
| 2685 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2686 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2687 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2688 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2689 | __init(__il.begin(), __il.end()); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2690 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2691 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2692 | |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2693 | // ~basic_regex() = default; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2694 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2695 | // basic_regex& operator=(const basic_regex&) = default; |
| 2696 | // basic_regex& operator=(basic_regex&&) = default; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2697 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2698 | basic_regex& operator=(const value_type* __p) |
| 2699 | {return assign(__p);} |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2700 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2701 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2702 | basic_regex& operator=(initializer_list<value_type> __il) |
| 2703 | {return assign(__il);} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2704 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2705 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2706 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2707 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) |
| 2708 | {return assign(__p);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2709 | |
| 2710 | // assign: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2711 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2712 | basic_regex& assign(const basic_regex& __that) |
| 2713 | {return *this = __that;} |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2714 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2715 | _LIBCPP_INLINE_VISIBILITY |
| 2716 | basic_regex& assign(basic_regex&& __that) _NOEXCEPT |
| 2717 | {return *this = _VSTD::move(__that);} |
| 2718 | #endif |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2719 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2720 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
| 2721 | {return assign(__p, __p + __traits_.length(__p), __f);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2722 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | d402893 | 2019-09-25 16:40:30 +0000 | [diff] [blame] | 2723 | basic_regex& assign(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2724 | {return assign(__p, __p + __len, __f);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2725 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2726 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2727 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2728 | flag_type __f = regex_constants::ECMAScript) |
| 2729 | {return assign(__s.begin(), __s.end(), __f);} |
| 2730 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2731 | template <class _InputIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2732 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2733 | typename enable_if |
| 2734 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2735 | __is_cpp17_input_iterator <_InputIterator>::value && |
| 2736 | !__is_cpp17_forward_iterator<_InputIterator>::value, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2737 | basic_regex& |
| 2738 | >::type |
| 2739 | assign(_InputIterator __first, _InputIterator __last, |
| 2740 | flag_type __f = regex_constants::ECMAScript) |
| 2741 | { |
| 2742 | basic_string<_CharT> __t(__first, __last); |
| 2743 | return assign(__t.begin(), __t.end(), __f); |
| 2744 | } |
| 2745 | |
| 2746 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2747 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2748 | void __member_init(flag_type __f) |
| 2749 | { |
| 2750 | __flags_ = __f; |
| 2751 | __marked_count_ = 0; |
| 2752 | __loop_count_ = 0; |
| 2753 | __open_count_ = 0; |
| 2754 | __end_ = nullptr; |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2755 | } |
| 2756 | public: |
| 2757 | |
| 2758 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2759 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2760 | typename enable_if |
| 2761 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2762 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2763 | basic_regex& |
| 2764 | >::type |
| 2765 | assign(_ForwardIterator __first, _ForwardIterator __last, |
| 2766 | flag_type __f = regex_constants::ECMAScript) |
| 2767 | { |
Marshall Clow | ce03dc1 | 2015-01-13 16:49:52 +0000 | [diff] [blame] | 2768 | return assign(basic_regex(__first, __last, __f)); |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2769 | } |
| 2770 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2771 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2772 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2773 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2774 | basic_regex& assign(initializer_list<value_type> __il, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2775 | flag_type __f = regex_constants::ECMAScript) |
| 2776 | {return assign(__il.begin(), __il.end(), __f);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2777 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2778 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2779 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2780 | // const operations: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2781 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2782 | unsigned mark_count() const {return __marked_count_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2783 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2784 | flag_type flags() const {return __flags_;} |
| 2785 | |
| 2786 | // locale: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2787 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2788 | locale_type imbue(locale_type __loc) |
| 2789 | { |
| 2790 | __member_init(ECMAScript); |
| 2791 | __start_.reset(); |
| 2792 | return __traits_.imbue(__loc); |
| 2793 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2794 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2795 | locale_type getloc() const {return __traits_.getloc();} |
| 2796 | |
| 2797 | // swap: |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2798 | void swap(basic_regex& __r); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2799 | |
| 2800 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2801 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2802 | unsigned __loop_count() const {return __loop_count_;} |
| 2803 | |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2804 | _LIBCPP_INLINE_VISIBILITY |
| 2805 | bool __use_multiline() const |
| 2806 | { |
| 2807 | return __get_grammar(__flags_) == ECMAScript && (__flags_ & multiline); |
| 2808 | } |
| 2809 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2810 | template <class _ForwardIterator> |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2811 | void |
| 2812 | __init(_ForwardIterator __first, _ForwardIterator __last); |
| 2813 | template <class _ForwardIterator> |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2814 | _ForwardIterator |
| 2815 | __parse(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2816 | template <class _ForwardIterator> |
| 2817 | _ForwardIterator |
| 2818 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2819 | template <class _ForwardIterator> |
| 2820 | _ForwardIterator |
| 2821 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2822 | template <class _ForwardIterator> |
| 2823 | _ForwardIterator |
| 2824 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2825 | template <class _ForwardIterator> |
| 2826 | _ForwardIterator |
| 2827 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2828 | template <class _ForwardIterator> |
| 2829 | _ForwardIterator |
| 2830 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2831 | template <class _ForwardIterator> |
| 2832 | _ForwardIterator |
| 2833 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2834 | template <class _ForwardIterator> |
| 2835 | _ForwardIterator |
| 2836 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2837 | template <class _ForwardIterator> |
| 2838 | _ForwardIterator |
| 2839 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2840 | template <class _ForwardIterator> |
| 2841 | _ForwardIterator |
| 2842 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2843 | template <class _ForwardIterator> |
| 2844 | _ForwardIterator |
| 2845 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2846 | template <class _ForwardIterator> |
| 2847 | _ForwardIterator |
| 2848 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2849 | template <class _ForwardIterator> |
| 2850 | _ForwardIterator |
| 2851 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2852 | template <class _ForwardIterator> |
| 2853 | _ForwardIterator |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2854 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2855 | __owns_one_state<_CharT>* __s, |
| 2856 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2857 | template <class _ForwardIterator> |
| 2858 | _ForwardIterator |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2859 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2860 | __owns_one_state<_CharT>* __s, |
| 2861 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2862 | template <class _ForwardIterator> |
| 2863 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2864 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2865 | template <class _ForwardIterator> |
| 2866 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2867 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2868 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2869 | template <class _ForwardIterator> |
| 2870 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2871 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2872 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2873 | template <class _ForwardIterator> |
| 2874 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2875 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2876 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2877 | template <class _ForwardIterator> |
| 2878 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2879 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2880 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2881 | template <class _ForwardIterator> |
| 2882 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2883 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2884 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2885 | template <class _ForwardIterator> |
| 2886 | _ForwardIterator |
| 2887 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2888 | template <class _ForwardIterator> |
| 2889 | _ForwardIterator |
| 2890 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2891 | template <class _ForwardIterator> |
| 2892 | _ForwardIterator |
| 2893 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2894 | template <class _ForwardIterator> |
| 2895 | _ForwardIterator |
| 2896 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2897 | template <class _ForwardIterator> |
| 2898 | _ForwardIterator |
| 2899 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2900 | template <class _ForwardIterator> |
| 2901 | _ForwardIterator |
| 2902 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2903 | template <class _ForwardIterator> |
| 2904 | _ForwardIterator |
| 2905 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2906 | template <class _ForwardIterator> |
| 2907 | _ForwardIterator |
| 2908 | __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2909 | template <class _ForwardIterator> |
| 2910 | _ForwardIterator |
| 2911 | __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); |
| 2912 | template <class _ForwardIterator> |
| 2913 | _ForwardIterator |
| 2914 | __parse_term(_ForwardIterator __first, _ForwardIterator __last); |
| 2915 | template <class _ForwardIterator> |
| 2916 | _ForwardIterator |
| 2917 | __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); |
| 2918 | template <class _ForwardIterator> |
| 2919 | _ForwardIterator |
| 2920 | __parse_atom(_ForwardIterator __first, _ForwardIterator __last); |
| 2921 | template <class _ForwardIterator> |
| 2922 | _ForwardIterator |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2923 | __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2924 | template <class _ForwardIterator> |
| 2925 | _ForwardIterator |
| 2926 | __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2927 | template <class _ForwardIterator> |
| 2928 | _ForwardIterator |
| 2929 | __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2930 | template <class _ForwardIterator> |
| 2931 | _ForwardIterator |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2932 | __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2933 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2934 | template <class _ForwardIterator> |
| 2935 | _ForwardIterator |
| 2936 | __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 2937 | template <class _ForwardIterator> |
| 2938 | _ForwardIterator |
| 2939 | __parse_grep(_ForwardIterator __first, _ForwardIterator __last); |
| 2940 | template <class _ForwardIterator> |
| 2941 | _ForwardIterator |
| 2942 | __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2943 | template <class _ForwardIterator> |
| 2944 | _ForwardIterator |
| 2945 | __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2946 | basic_string<_CharT>& __str, |
| 2947 | __bracket_expression<_CharT, _Traits>* __ml); |
| 2948 | template <class _ForwardIterator> |
| 2949 | _ForwardIterator |
| 2950 | __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2951 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2952 | |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 2953 | bool __test_back_ref(_CharT c); |
| 2954 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2955 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2956 | void __push_l_anchor(); |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2957 | void __push_r_anchor(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2958 | void __push_match_any(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2959 | void __push_match_any_but_newline(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2960 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2961 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2962 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2963 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2964 | __mexp_begin, __mexp_end);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2965 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2966 | void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2967 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2968 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2969 | __mexp_begin, __mexp_end, false);} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2970 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2971 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2972 | bool __greedy = true); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2973 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2974 | void __push_char(value_type __c); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 2975 | void __push_back_ref(int __i); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2976 | void __push_alternation(__owns_one_state<_CharT>* __sa, |
| 2977 | __owns_one_state<_CharT>* __sb); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2978 | void __push_begin_marked_subexpression(); |
| 2979 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2980 | void __push_empty(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2981 | void __push_word_boundary(bool); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2982 | void __push_lookahead(const basic_regex&, bool, unsigned); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2983 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2984 | template <class _Allocator> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2985 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2986 | __search(const _CharT* __first, const _CharT* __last, |
| 2987 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2988 | regex_constants::match_flag_type __flags) const; |
| 2989 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2990 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2991 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2992 | __match_at_start(const _CharT* __first, const _CharT* __last, |
| 2993 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2994 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2995 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2996 | bool |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2997 | __match_at_start_ecma(const _CharT* __first, const _CharT* __last, |
| 2998 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2999 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3000 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3001 | bool |
| 3002 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3003 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3004 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3005 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3006 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3007 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 3008 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3009 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3010 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3011 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3012 | friend |
| 3013 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3014 | regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3015 | regex_constants::match_flag_type); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3016 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3017 | template <class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3018 | friend |
| 3019 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3020 | regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&, |
| 3021 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3022 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3023 | template <class _Bp, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3024 | friend |
| 3025 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3026 | regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3027 | regex_constants::match_flag_type); |
| 3028 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3029 | template <class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3030 | friend |
| 3031 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3032 | regex_search(const _Cp*, const _Cp*, |
| 3033 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3034 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3035 | template <class _Cp, class _Ap, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3036 | friend |
| 3037 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3038 | regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3039 | regex_constants::match_flag_type); |
| 3040 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3041 | template <class _ST, class _SA, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3042 | friend |
| 3043 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3044 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 3045 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3046 | regex_constants::match_flag_type __flags); |
| 3047 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3048 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3049 | friend |
| 3050 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3051 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 3052 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 3053 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3054 | regex_constants::match_flag_type __flags); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3055 | |
Howard Hinnant | 4018c48 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 3056 | template <class _Iter, class _Ap, class _Cp, class _Tp> |
| 3057 | friend |
| 3058 | bool |
| 3059 | regex_search(__wrap_iter<_Iter> __first, |
| 3060 | __wrap_iter<_Iter> __last, |
| 3061 | match_results<__wrap_iter<_Iter>, _Ap>& __m, |
| 3062 | const basic_regex<_Cp, _Tp>& __e, |
| 3063 | regex_constants::match_flag_type __flags); |
| 3064 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3065 | template <class, class> friend class __lookahead; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3066 | }; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3067 | |
Louis Dionne | d59f8a5 | 2021-08-17 11:59:07 -0400 | [diff] [blame] | 3068 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | 2dce1f4 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 3069 | template <class _ForwardIterator, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3070 | class = typename enable_if<__is_cpp17_forward_iterator<_ForwardIterator>::value, nullptr_t>::type |
Marshall Clow | 2dce1f4 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 3071 | > |
| 3072 | basic_regex(_ForwardIterator, _ForwardIterator, |
| 3073 | regex_constants::syntax_option_type = regex_constants::ECMAScript) |
| 3074 | -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>; |
| 3075 | #endif |
| 3076 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3077 | template <class _CharT, class _Traits> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 3078 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase; |
| 3079 | template <class _CharT, class _Traits> |
| 3080 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs; |
| 3081 | template <class _CharT, class _Traits> |
| 3082 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize; |
| 3083 | template <class _CharT, class _Traits> |
| 3084 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate; |
| 3085 | template <class _CharT, class _Traits> |
| 3086 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript; |
| 3087 | template <class _CharT, class _Traits> |
| 3088 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic; |
| 3089 | template <class _CharT, class _Traits> |
| 3090 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended; |
| 3091 | template <class _CharT, class _Traits> |
| 3092 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk; |
| 3093 | template <class _CharT, class _Traits> |
| 3094 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep; |
| 3095 | template <class _CharT, class _Traits> |
| 3096 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep; |
| 3097 | |
| 3098 | template <class _CharT, class _Traits> |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3099 | void |
| 3100 | basic_regex<_CharT, _Traits>::swap(basic_regex& __r) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3101 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3102 | using _VSTD::swap; |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3103 | swap(__traits_, __r.__traits_); |
| 3104 | swap(__flags_, __r.__flags_); |
| 3105 | swap(__marked_count_, __r.__marked_count_); |
| 3106 | swap(__loop_count_, __r.__loop_count_); |
| 3107 | swap(__open_count_, __r.__open_count_); |
| 3108 | swap(__start_, __r.__start_); |
| 3109 | swap(__end_, __r.__end_); |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | template <class _CharT, class _Traits> |
| 3113 | inline _LIBCPP_INLINE_VISIBILITY |
| 3114 | void |
| 3115 | swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) |
| 3116 | { |
| 3117 | return __x.swap(__y); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3120 | // __lookahead |
| 3121 | |
| 3122 | template <class _CharT, class _Traits> |
| 3123 | class __lookahead |
| 3124 | : public __owns_one_state<_CharT> |
| 3125 | { |
| 3126 | typedef __owns_one_state<_CharT> base; |
| 3127 | |
| 3128 | basic_regex<_CharT, _Traits> __exp_; |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3129 | unsigned __mexp_; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3130 | bool __invert_; |
| 3131 | |
| 3132 | __lookahead(const __lookahead&); |
| 3133 | __lookahead& operator=(const __lookahead&); |
| 3134 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3135 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3136 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 3137 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3138 | __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp) |
Eric Fiselier | a75ee26 | 2015-07-22 01:29:41 +0000 | [diff] [blame] | 3139 | : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {} |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3140 | |
| 3141 | virtual void __exec(__state&) const; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3142 | }; |
| 3143 | |
| 3144 | template <class _CharT, class _Traits> |
| 3145 | void |
| 3146 | __lookahead<_CharT, _Traits>::__exec(__state& __s) const |
| 3147 | { |
| 3148 | match_results<const _CharT*> __m; |
| 3149 | __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 3150 | bool __matched = __exp_.__match_at_start_ecma( |
| 3151 | __s.__current_, __s.__last_, |
| 3152 | __m, |
| 3153 | (__s.__flags_ | regex_constants::match_continuous) & |
| 3154 | ~regex_constants::__full_match, |
| 3155 | __s.__at_first_ && __s.__current_ == __s.__first_); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3156 | if (__matched != __invert_) |
| 3157 | { |
| 3158 | __s.__do_ = __state::__accept_but_not_consume; |
| 3159 | __s.__node_ = this->first(); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3160 | for (unsigned __i = 1; __i < __m.size(); ++__i) { |
| 3161 | __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i]; |
| 3162 | } |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3163 | } |
| 3164 | else |
| 3165 | { |
| 3166 | __s.__do_ = __state::__reject; |
| 3167 | __s.__node_ = nullptr; |
| 3168 | } |
| 3169 | } |
| 3170 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3171 | template <class _CharT, class _Traits> |
| 3172 | template <class _ForwardIterator> |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 3173 | void |
| 3174 | basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last) |
| 3175 | { |
| 3176 | if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; |
| 3177 | _ForwardIterator __temp = __parse(__first, __last); |
| 3178 | if ( __temp != __last) |
| 3179 | __throw_regex_error<regex_constants::__re_err_parse>(); |
| 3180 | } |
| 3181 | |
| 3182 | template <class _CharT, class _Traits> |
| 3183 | template <class _ForwardIterator> |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3184 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3185 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 3186 | _ForwardIterator __last) |
| 3187 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3188 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 3189 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3190 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 3191 | __h.release(); |
| 3192 | __end_ = __start_.get(); |
| 3193 | } |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3194 | switch (__get_grammar(__flags_)) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3195 | { |
| 3196 | case ECMAScript: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3197 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3198 | break; |
| 3199 | case basic: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3200 | __first = __parse_basic_reg_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3201 | break; |
| 3202 | case extended: |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3203 | case awk: |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3204 | __first = __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3205 | break; |
| 3206 | case grep: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3207 | __first = __parse_grep(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3208 | break; |
| 3209 | case egrep: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3210 | __first = __parse_egrep(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3211 | break; |
| 3212 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3213 | __throw_regex_error<regex_constants::__re_err_grammar>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3214 | } |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3215 | return __first; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | template <class _CharT, class _Traits> |
| 3219 | template <class _ForwardIterator> |
| 3220 | _ForwardIterator |
| 3221 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 3222 | _ForwardIterator __last) |
| 3223 | { |
| 3224 | if (__first != __last) |
| 3225 | { |
| 3226 | if (*__first == '^') |
| 3227 | { |
| 3228 | __push_l_anchor(); |
| 3229 | ++__first; |
| 3230 | } |
| 3231 | if (__first != __last) |
| 3232 | { |
| 3233 | __first = __parse_RE_expression(__first, __last); |
| 3234 | if (__first != __last) |
| 3235 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3236 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3237 | if (__temp == __last && *__first == '$') |
| 3238 | { |
| 3239 | __push_r_anchor(); |
| 3240 | ++__first; |
| 3241 | } |
| 3242 | } |
| 3243 | } |
| 3244 | if (__first != __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3245 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3246 | } |
| 3247 | return __first; |
| 3248 | } |
| 3249 | |
| 3250 | template <class _CharT, class _Traits> |
| 3251 | template <class _ForwardIterator> |
| 3252 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3253 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 3254 | _ForwardIterator __last) |
| 3255 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3256 | __owns_one_state<_CharT>* __sa = __end_; |
| 3257 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
| 3258 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3259 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3260 | __first = __temp; |
| 3261 | while (__first != __last && *__first == '|') |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3262 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3263 | __owns_one_state<_CharT>* __sb = __end_; |
| 3264 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3265 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3266 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3267 | __push_alternation(__sa, __sb); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3268 | __first = __temp; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3269 | } |
| 3270 | return __first; |
| 3271 | } |
| 3272 | |
| 3273 | template <class _CharT, class _Traits> |
| 3274 | template <class _ForwardIterator> |
| 3275 | _ForwardIterator |
| 3276 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 3277 | _ForwardIterator __last) |
| 3278 | { |
| 3279 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
| 3280 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3281 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3282 | do |
| 3283 | { |
| 3284 | __first = __temp; |
| 3285 | __temp = __parse_ERE_expression(__first, __last); |
| 3286 | } while (__temp != __first); |
| 3287 | return __first; |
| 3288 | } |
| 3289 | |
| 3290 | template <class _CharT, class _Traits> |
| 3291 | template <class _ForwardIterator> |
| 3292 | _ForwardIterator |
| 3293 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 3294 | _ForwardIterator __last) |
| 3295 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3296 | __owns_one_state<_CharT>* __e = __end_; |
| 3297 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3298 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 3299 | if (__temp == __first && __temp != __last) |
| 3300 | { |
| 3301 | switch (*__temp) |
| 3302 | { |
| 3303 | case '^': |
| 3304 | __push_l_anchor(); |
| 3305 | ++__temp; |
| 3306 | break; |
| 3307 | case '$': |
| 3308 | __push_r_anchor(); |
| 3309 | ++__temp; |
| 3310 | break; |
| 3311 | case '(': |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3312 | __push_begin_marked_subexpression(); |
| 3313 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3314 | ++__open_count_; |
| 3315 | __temp = __parse_extended_reg_exp(++__temp, __last); |
| 3316 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3317 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3318 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3319 | --__open_count_; |
| 3320 | ++__temp; |
| 3321 | break; |
| 3322 | } |
| 3323 | } |
| 3324 | if (__temp != __first) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3325 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 3326 | __marked_count_+1); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3327 | __first = __temp; |
| 3328 | return __first; |
| 3329 | } |
| 3330 | |
| 3331 | template <class _CharT, class _Traits> |
| 3332 | template <class _ForwardIterator> |
| 3333 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3334 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 3335 | _ForwardIterator __last) |
| 3336 | { |
| 3337 | while (true) |
| 3338 | { |
| 3339 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 3340 | if (__temp == __first) |
| 3341 | break; |
| 3342 | __first = __temp; |
| 3343 | } |
| 3344 | return __first; |
| 3345 | } |
| 3346 | |
| 3347 | template <class _CharT, class _Traits> |
| 3348 | template <class _ForwardIterator> |
| 3349 | _ForwardIterator |
| 3350 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 3351 | _ForwardIterator __last) |
| 3352 | { |
| 3353 | if (__first != __last) |
| 3354 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3355 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3356 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3357 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 3358 | if (__temp != __first) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3359 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 3360 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3361 | } |
| 3362 | return __first; |
| 3363 | } |
| 3364 | |
| 3365 | template <class _CharT, class _Traits> |
| 3366 | template <class _ForwardIterator> |
| 3367 | _ForwardIterator |
| 3368 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 3369 | _ForwardIterator __last) |
| 3370 | { |
| 3371 | _ForwardIterator __temp = __first; |
| 3372 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 3373 | if (__temp == __first) |
| 3374 | { |
| 3375 | __temp = __parse_Back_open_paren(__first, __last); |
| 3376 | if (__temp != __first) |
| 3377 | { |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3378 | __push_begin_marked_subexpression(); |
| 3379 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3380 | __first = __parse_RE_expression(__temp, __last); |
| 3381 | __temp = __parse_Back_close_paren(__first, __last); |
| 3382 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3383 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3384 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3385 | __first = __temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3386 | } |
| 3387 | else |
| 3388 | __first = __parse_BACKREF(__first, __last); |
| 3389 | } |
| 3390 | return __first; |
| 3391 | } |
| 3392 | |
| 3393 | template <class _CharT, class _Traits> |
| 3394 | template <class _ForwardIterator> |
| 3395 | _ForwardIterator |
| 3396 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3397 | _ForwardIterator __first, |
| 3398 | _ForwardIterator __last) |
| 3399 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3400 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3401 | if (__temp == __first) |
| 3402 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3403 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3404 | if (__temp == __first) |
| 3405 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3406 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3407 | { |
| 3408 | __push_match_any(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3409 | ++__temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3410 | } |
| 3411 | else |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3412 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3413 | } |
| 3414 | } |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3415 | __first = __temp; |
| 3416 | return __first; |
| 3417 | } |
| 3418 | |
| 3419 | template <class _CharT, class _Traits> |
| 3420 | template <class _ForwardIterator> |
| 3421 | _ForwardIterator |
| 3422 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3423 | _ForwardIterator __first, |
| 3424 | _ForwardIterator __last) |
| 3425 | { |
| 3426 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3427 | if (__temp == __first) |
| 3428 | { |
| 3429 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3430 | if (__temp == __first) |
| 3431 | { |
| 3432 | if (__temp != __last && *__temp == '.') |
| 3433 | { |
| 3434 | __push_match_any(); |
| 3435 | ++__temp; |
| 3436 | } |
| 3437 | else |
| 3438 | __temp = __parse_bracket_expression(__first, __last); |
| 3439 | } |
| 3440 | } |
| 3441 | __first = __temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3442 | return __first; |
| 3443 | } |
| 3444 | |
| 3445 | template <class _CharT, class _Traits> |
| 3446 | template <class _ForwardIterator> |
| 3447 | _ForwardIterator |
| 3448 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3449 | _ForwardIterator __last) |
| 3450 | { |
| 3451 | if (__first != __last) |
| 3452 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3453 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3454 | if (__temp != __last) |
| 3455 | { |
| 3456 | if (*__first == '\\' && *__temp == '(') |
| 3457 | __first = ++__temp; |
| 3458 | } |
| 3459 | } |
| 3460 | return __first; |
| 3461 | } |
| 3462 | |
| 3463 | template <class _CharT, class _Traits> |
| 3464 | template <class _ForwardIterator> |
| 3465 | _ForwardIterator |
| 3466 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3467 | _ForwardIterator __last) |
| 3468 | { |
| 3469 | if (__first != __last) |
| 3470 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3471 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3472 | if (__temp != __last) |
| 3473 | { |
| 3474 | if (*__first == '\\' && *__temp == ')') |
| 3475 | __first = ++__temp; |
| 3476 | } |
| 3477 | } |
| 3478 | return __first; |
| 3479 | } |
| 3480 | |
| 3481 | template <class _CharT, class _Traits> |
| 3482 | template <class _ForwardIterator> |
| 3483 | _ForwardIterator |
| 3484 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3485 | _ForwardIterator __last) |
| 3486 | { |
| 3487 | if (__first != __last) |
| 3488 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3489 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3490 | if (__temp != __last) |
| 3491 | { |
| 3492 | if (*__first == '\\' && *__temp == '{') |
| 3493 | __first = ++__temp; |
| 3494 | } |
| 3495 | } |
| 3496 | return __first; |
| 3497 | } |
| 3498 | |
| 3499 | template <class _CharT, class _Traits> |
| 3500 | template <class _ForwardIterator> |
| 3501 | _ForwardIterator |
| 3502 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3503 | _ForwardIterator __last) |
| 3504 | { |
| 3505 | if (__first != __last) |
| 3506 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3507 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3508 | if (__temp != __last) |
| 3509 | { |
| 3510 | if (*__first == '\\' && *__temp == '}') |
| 3511 | __first = ++__temp; |
| 3512 | } |
| 3513 | } |
| 3514 | return __first; |
| 3515 | } |
| 3516 | |
| 3517 | template <class _CharT, class _Traits> |
| 3518 | template <class _ForwardIterator> |
| 3519 | _ForwardIterator |
| 3520 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 3521 | _ForwardIterator __last) |
| 3522 | { |
| 3523 | if (__first != __last) |
| 3524 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3525 | _ForwardIterator __temp = _VSTD::next(__first); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 3526 | if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp)) |
| 3527 | __first = ++__temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3528 | } |
| 3529 | return __first; |
| 3530 | } |
| 3531 | |
| 3532 | template <class _CharT, class _Traits> |
| 3533 | template <class _ForwardIterator> |
| 3534 | _ForwardIterator |
| 3535 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3536 | _ForwardIterator __last) |
| 3537 | { |
| 3538 | if (__first != __last) |
| 3539 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3540 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3541 | if (__temp == __last && *__first == '$') |
| 3542 | return __first; |
| 3543 | // Not called inside a bracket |
| 3544 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3545 | return __first; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3546 | __push_char(*__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3547 | ++__first; |
| 3548 | } |
| 3549 | return __first; |
| 3550 | } |
| 3551 | |
| 3552 | template <class _CharT, class _Traits> |
| 3553 | template <class _ForwardIterator> |
| 3554 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3555 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3556 | _ForwardIterator __last) |
| 3557 | { |
| 3558 | if (__first != __last) |
| 3559 | { |
| 3560 | switch (*__first) |
| 3561 | { |
| 3562 | case '^': |
| 3563 | case '.': |
| 3564 | case '[': |
| 3565 | case '$': |
| 3566 | case '(': |
| 3567 | case '|': |
| 3568 | case '*': |
| 3569 | case '+': |
| 3570 | case '?': |
| 3571 | case '{': |
| 3572 | case '\\': |
| 3573 | break; |
| 3574 | case ')': |
| 3575 | if (__open_count_ == 0) |
| 3576 | { |
| 3577 | __push_char(*__first); |
| 3578 | ++__first; |
| 3579 | } |
| 3580 | break; |
| 3581 | default: |
| 3582 | __push_char(*__first); |
| 3583 | ++__first; |
| 3584 | break; |
| 3585 | } |
| 3586 | } |
| 3587 | return __first; |
| 3588 | } |
| 3589 | |
| 3590 | template <class _CharT, class _Traits> |
| 3591 | template <class _ForwardIterator> |
| 3592 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3593 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3594 | _ForwardIterator __last) |
| 3595 | { |
| 3596 | if (__first != __last) |
| 3597 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3598 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3599 | if (__temp != __last) |
| 3600 | { |
| 3601 | if (*__first == '\\') |
| 3602 | { |
| 3603 | switch (*__temp) |
| 3604 | { |
| 3605 | case '^': |
| 3606 | case '.': |
| 3607 | case '*': |
| 3608 | case '[': |
| 3609 | case '$': |
| 3610 | case '\\': |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3611 | __push_char(*__temp); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3612 | __first = ++__temp; |
| 3613 | break; |
| 3614 | } |
| 3615 | } |
| 3616 | } |
| 3617 | } |
| 3618 | return __first; |
| 3619 | } |
| 3620 | |
| 3621 | template <class _CharT, class _Traits> |
| 3622 | template <class _ForwardIterator> |
| 3623 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3624 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3625 | _ForwardIterator __last) |
| 3626 | { |
| 3627 | if (__first != __last) |
| 3628 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3629 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3630 | if (__temp != __last) |
| 3631 | { |
| 3632 | if (*__first == '\\') |
| 3633 | { |
| 3634 | switch (*__temp) |
| 3635 | { |
| 3636 | case '^': |
| 3637 | case '.': |
| 3638 | case '*': |
| 3639 | case '[': |
| 3640 | case '$': |
| 3641 | case '\\': |
| 3642 | case '(': |
| 3643 | case ')': |
| 3644 | case '|': |
| 3645 | case '+': |
| 3646 | case '?': |
| 3647 | case '{': |
Howard Hinnant | 73072eb | 2013-06-28 20:31:05 +0000 | [diff] [blame] | 3648 | case '}': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3649 | __push_char(*__temp); |
| 3650 | __first = ++__temp; |
| 3651 | break; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3652 | default: |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3653 | if (__get_grammar(__flags_) == awk) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3654 | __first = __parse_awk_escape(++__first, __last); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 3655 | else if(__test_back_ref(*__temp)) |
| 3656 | __first = ++__temp; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3657 | break; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3658 | } |
| 3659 | } |
| 3660 | } |
| 3661 | } |
| 3662 | return __first; |
| 3663 | } |
| 3664 | |
| 3665 | template <class _CharT, class _Traits> |
| 3666 | template <class _ForwardIterator> |
| 3667 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3668 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3669 | _ForwardIterator __last, |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3670 | __owns_one_state<_CharT>* __s, |
| 3671 | unsigned __mexp_begin, |
| 3672 | unsigned __mexp_end) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3673 | { |
| 3674 | if (__first != __last) |
| 3675 | { |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3676 | if (*__first == '*') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3677 | { |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3678 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3679 | ++__first; |
| 3680 | } |
| 3681 | else |
| 3682 | { |
| 3683 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3684 | if (__temp != __first) |
| 3685 | { |
| 3686 | int __min = 0; |
| 3687 | __first = __temp; |
| 3688 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 3689 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3690 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3691 | __first = __temp; |
| 3692 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3693 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3694 | if (*__first != ',') |
| 3695 | { |
| 3696 | __temp = __parse_Back_close_brace(__first, __last); |
| 3697 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3698 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3699 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3700 | true); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3701 | __first = __temp; |
| 3702 | } |
| 3703 | else |
| 3704 | { |
| 3705 | ++__first; // consume ',' |
| 3706 | int __max = -1; |
| 3707 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3708 | __temp = __parse_Back_close_brace(__first, __last); |
| 3709 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3710 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3711 | if (__max == -1) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3712 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3713 | else |
| 3714 | { |
| 3715 | if (__max < __min) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3716 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3717 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3718 | true); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3719 | } |
| 3720 | __first = __temp; |
| 3721 | } |
| 3722 | } |
| 3723 | } |
| 3724 | } |
| 3725 | return __first; |
| 3726 | } |
| 3727 | |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3728 | template <class _CharT, class _Traits> |
| 3729 | template <class _ForwardIterator> |
| 3730 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3731 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3732 | _ForwardIterator __last, |
| 3733 | __owns_one_state<_CharT>* __s, |
| 3734 | unsigned __mexp_begin, |
| 3735 | unsigned __mexp_end) |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3736 | { |
| 3737 | if (__first != __last) |
| 3738 | { |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3739 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3740 | switch (*__first) |
| 3741 | { |
| 3742 | case '*': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3743 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3744 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3745 | { |
| 3746 | ++__first; |
| 3747 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3748 | } |
| 3749 | else |
| 3750 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3751 | break; |
| 3752 | case '+': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3753 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3754 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3755 | { |
| 3756 | ++__first; |
| 3757 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3758 | } |
| 3759 | else |
| 3760 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3761 | break; |
| 3762 | case '?': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3763 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3764 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3765 | { |
| 3766 | ++__first; |
| 3767 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3768 | } |
| 3769 | else |
| 3770 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3771 | break; |
| 3772 | case '{': |
| 3773 | { |
| 3774 | int __min; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3775 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3776 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3777 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3778 | __first = __temp; |
| 3779 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3780 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3781 | switch (*__first) |
| 3782 | { |
| 3783 | case '}': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3784 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3785 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3786 | { |
| 3787 | ++__first; |
| 3788 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3789 | } |
| 3790 | else |
| 3791 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3792 | break; |
| 3793 | case ',': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3794 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3795 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3796 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3797 | if (*__first == '}') |
| 3798 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3799 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3800 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3801 | { |
| 3802 | ++__first; |
| 3803 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3804 | } |
| 3805 | else |
| 3806 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3807 | } |
| 3808 | else |
| 3809 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3810 | int __max = -1; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3811 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 3812 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3813 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3814 | __first = __temp; |
| 3815 | if (__first == __last || *__first != '}') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3816 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3817 | ++__first; |
| 3818 | if (__max < __min) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3819 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3820 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3821 | { |
| 3822 | ++__first; |
| 3823 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3824 | } |
| 3825 | else |
| 3826 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3827 | } |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3828 | break; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3829 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3830 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3831 | } |
| 3832 | } |
| 3833 | break; |
| 3834 | } |
| 3835 | } |
| 3836 | return __first; |
| 3837 | } |
| 3838 | |
| 3839 | template <class _CharT, class _Traits> |
| 3840 | template <class _ForwardIterator> |
| 3841 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3842 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3843 | _ForwardIterator __last) |
| 3844 | { |
| 3845 | if (__first != __last && *__first == '[') |
| 3846 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3847 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3848 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3849 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3850 | bool __negate = false; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3851 | if (*__first == '^') |
| 3852 | { |
| 3853 | ++__first; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3854 | __negate = true; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3855 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3856 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3857 | // __ml owned by *this |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3858 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3859 | __throw_regex_error<regex_constants::error_brack>(); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3860 | if (__get_grammar(__flags_) != ECMAScript && *__first == ']') |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3861 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3862 | __ml->__add_char(']'); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3863 | ++__first; |
| 3864 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3865 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3866 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3867 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3868 | if (*__first == '-') |
| 3869 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3870 | __ml->__add_char('-'); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3871 | ++__first; |
| 3872 | } |
| 3873 | if (__first == __last || *__first != ']') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3874 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3875 | ++__first; |
| 3876 | } |
| 3877 | return __first; |
| 3878 | } |
| 3879 | |
| 3880 | template <class _CharT, class _Traits> |
| 3881 | template <class _ForwardIterator> |
| 3882 | _ForwardIterator |
| 3883 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3884 | _ForwardIterator __last, |
| 3885 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3886 | { |
| 3887 | if (__first != __last) |
| 3888 | { |
| 3889 | while (true) |
| 3890 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3891 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3892 | __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3893 | if (__temp == __first) |
| 3894 | break; |
| 3895 | __first = __temp; |
| 3896 | } |
| 3897 | } |
| 3898 | return __first; |
| 3899 | } |
| 3900 | |
| 3901 | template <class _CharT, class _Traits> |
| 3902 | template <class _ForwardIterator> |
| 3903 | _ForwardIterator |
| 3904 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3905 | _ForwardIterator __last, |
| 3906 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3907 | { |
| 3908 | if (__first != __last && *__first != ']') |
| 3909 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3910 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3911 | basic_string<_CharT> __start_range; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3912 | if (__temp != __last && *__first == '[') |
| 3913 | { |
| 3914 | if (*__temp == '=') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3915 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3916 | else if (*__temp == ':') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3917 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3918 | else if (*__temp == '.') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3919 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3920 | } |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3921 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3922 | if (__start_range.empty()) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3923 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3924 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3925 | { |
| 3926 | if (__grammar == ECMAScript) |
| 3927 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3928 | else |
| 3929 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3930 | } |
| 3931 | else |
| 3932 | { |
| 3933 | __start_range = *__first; |
| 3934 | ++__first; |
| 3935 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3936 | } |
| 3937 | if (__first != __last && *__first != ']') |
| 3938 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3939 | __temp = _VSTD::next(__first); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3940 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3941 | { |
| 3942 | // parse a range |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3943 | basic_string<_CharT> __end_range; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3944 | __first = __temp; |
| 3945 | ++__temp; |
| 3946 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3947 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3948 | else |
| 3949 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3950 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3951 | { |
| 3952 | if (__grammar == ECMAScript) |
| 3953 | __first = __parse_class_escape(++__first, __last, |
| 3954 | __end_range, __ml); |
| 3955 | else |
| 3956 | __first = __parse_awk_escape(++__first, __last, |
| 3957 | &__end_range); |
| 3958 | } |
| 3959 | else |
| 3960 | { |
| 3961 | __end_range = *__first; |
| 3962 | ++__first; |
| 3963 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3964 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3965 | __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3966 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3967 | else if (!__start_range.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3968 | { |
| 3969 | if (__start_range.size() == 1) |
| 3970 | __ml->__add_char(__start_range[0]); |
| 3971 | else |
| 3972 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3973 | } |
| 3974 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3975 | else if (!__start_range.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3976 | { |
| 3977 | if (__start_range.size() == 1) |
| 3978 | __ml->__add_char(__start_range[0]); |
| 3979 | else |
| 3980 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3981 | } |
| 3982 | } |
| 3983 | return __first; |
| 3984 | } |
| 3985 | |
| 3986 | template <class _CharT, class _Traits> |
| 3987 | template <class _ForwardIterator> |
| 3988 | _ForwardIterator |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3989 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 3990 | _ForwardIterator __last, |
| 3991 | basic_string<_CharT>& __str, |
| 3992 | __bracket_expression<_CharT, _Traits>* __ml) |
| 3993 | { |
| 3994 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3995 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3996 | switch (*__first) |
| 3997 | { |
| 3998 | case 0: |
| 3999 | __str = *__first; |
| 4000 | return ++__first; |
| 4001 | case 'b': |
| 4002 | __str = _CharT(8); |
| 4003 | return ++__first; |
| 4004 | case 'd': |
| 4005 | __ml->__add_class(ctype_base::digit); |
| 4006 | return ++__first; |
| 4007 | case 'D': |
| 4008 | __ml->__add_neg_class(ctype_base::digit); |
| 4009 | return ++__first; |
| 4010 | case 's': |
| 4011 | __ml->__add_class(ctype_base::space); |
| 4012 | return ++__first; |
| 4013 | case 'S': |
| 4014 | __ml->__add_neg_class(ctype_base::space); |
| 4015 | return ++__first; |
| 4016 | case 'w': |
| 4017 | __ml->__add_class(ctype_base::alnum); |
| 4018 | __ml->__add_char('_'); |
| 4019 | return ++__first; |
| 4020 | case 'W': |
| 4021 | __ml->__add_neg_class(ctype_base::alnum); |
| 4022 | __ml->__add_neg_char('_'); |
| 4023 | return ++__first; |
| 4024 | } |
| 4025 | __first = __parse_character_escape(__first, __last, &__str); |
| 4026 | return __first; |
| 4027 | } |
| 4028 | |
| 4029 | template <class _CharT, class _Traits> |
| 4030 | template <class _ForwardIterator> |
| 4031 | _ForwardIterator |
| 4032 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 4033 | _ForwardIterator __last, |
| 4034 | basic_string<_CharT>* __str) |
| 4035 | { |
| 4036 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4037 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4038 | switch (*__first) |
| 4039 | { |
| 4040 | case '\\': |
| 4041 | case '"': |
| 4042 | case '/': |
| 4043 | if (__str) |
| 4044 | *__str = *__first; |
| 4045 | else |
| 4046 | __push_char(*__first); |
| 4047 | return ++__first; |
| 4048 | case 'a': |
| 4049 | if (__str) |
| 4050 | *__str = _CharT(7); |
| 4051 | else |
| 4052 | __push_char(_CharT(7)); |
| 4053 | return ++__first; |
| 4054 | case 'b': |
| 4055 | if (__str) |
| 4056 | *__str = _CharT(8); |
| 4057 | else |
| 4058 | __push_char(_CharT(8)); |
| 4059 | return ++__first; |
| 4060 | case 'f': |
| 4061 | if (__str) |
| 4062 | *__str = _CharT(0xC); |
| 4063 | else |
| 4064 | __push_char(_CharT(0xC)); |
| 4065 | return ++__first; |
| 4066 | case 'n': |
| 4067 | if (__str) |
| 4068 | *__str = _CharT(0xA); |
| 4069 | else |
| 4070 | __push_char(_CharT(0xA)); |
| 4071 | return ++__first; |
| 4072 | case 'r': |
| 4073 | if (__str) |
| 4074 | *__str = _CharT(0xD); |
| 4075 | else |
| 4076 | __push_char(_CharT(0xD)); |
| 4077 | return ++__first; |
| 4078 | case 't': |
| 4079 | if (__str) |
| 4080 | *__str = _CharT(0x9); |
| 4081 | else |
| 4082 | __push_char(_CharT(0x9)); |
| 4083 | return ++__first; |
| 4084 | case 'v': |
| 4085 | if (__str) |
| 4086 | *__str = _CharT(0xB); |
| 4087 | else |
| 4088 | __push_char(_CharT(0xB)); |
| 4089 | return ++__first; |
| 4090 | } |
| 4091 | if ('0' <= *__first && *__first <= '7') |
| 4092 | { |
| 4093 | unsigned __val = *__first - '0'; |
| 4094 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 4095 | { |
| 4096 | __val = 8 * __val + *__first - '0'; |
| 4097 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
Howard Hinnant | a309687 | 2013-07-02 17:43:31 +0000 | [diff] [blame] | 4098 | __val = 8 * __val + *__first++ - '0'; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4099 | } |
| 4100 | if (__str) |
| 4101 | *__str = _CharT(__val); |
| 4102 | else |
| 4103 | __push_char(_CharT(__val)); |
| 4104 | } |
| 4105 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4106 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4107 | return __first; |
| 4108 | } |
| 4109 | |
| 4110 | template <class _CharT, class _Traits> |
| 4111 | template <class _ForwardIterator> |
| 4112 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4113 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4114 | _ForwardIterator __last, |
| 4115 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4116 | { |
| 4117 | // Found [= |
| 4118 | // This means =] must exist |
| 4119 | value_type _Equal_close[2] = {'=', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4120 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4121 | _Equal_close+2); |
| 4122 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4123 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4124 | // [__first, __temp) contains all text in [= ... =] |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4125 | string_type __collate_name = |
| 4126 | __traits_.lookup_collatename(__first, __temp); |
| 4127 | if (__collate_name.empty()) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4128 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4129 | string_type __equiv_name = |
| 4130 | __traits_.transform_primary(__collate_name.begin(), |
| 4131 | __collate_name.end()); |
| 4132 | if (!__equiv_name.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4133 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4134 | else |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4135 | { |
| 4136 | switch (__collate_name.size()) |
| 4137 | { |
| 4138 | case 1: |
| 4139 | __ml->__add_char(__collate_name[0]); |
| 4140 | break; |
| 4141 | case 2: |
| 4142 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 4143 | break; |
| 4144 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4145 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4146 | } |
| 4147 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4148 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4149 | return __first; |
| 4150 | } |
| 4151 | |
| 4152 | template <class _CharT, class _Traits> |
| 4153 | template <class _ForwardIterator> |
| 4154 | _ForwardIterator |
| 4155 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4156 | _ForwardIterator __last, |
| 4157 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4158 | { |
| 4159 | // Found [: |
| 4160 | // This means :] must exist |
| 4161 | value_type _Colon_close[2] = {':', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4162 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4163 | _Colon_close+2); |
| 4164 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4165 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4166 | // [__first, __temp) contains all text in [: ... :] |
| 4167 | typedef typename _Traits::char_class_type char_class_type; |
| 4168 | char_class_type __class_type = |
| 4169 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 4170 | if (__class_type == 0) |
Mikhail Maltsev | 6ef945b | 2018-01-24 12:45:18 +0000 | [diff] [blame] | 4171 | __throw_regex_error<regex_constants::error_ctype>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4172 | __ml->__add_class(__class_type); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4173 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4174 | return __first; |
| 4175 | } |
| 4176 | |
| 4177 | template <class _CharT, class _Traits> |
| 4178 | template <class _ForwardIterator> |
| 4179 | _ForwardIterator |
| 4180 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4181 | _ForwardIterator __last, |
| 4182 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4183 | { |
| 4184 | // Found [. |
| 4185 | // This means .] must exist |
| 4186 | value_type _Dot_close[2] = {'.', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4187 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4188 | _Dot_close+2); |
| 4189 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4190 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4191 | // [__first, __temp) contains all text in [. ... .] |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4192 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 4193 | switch (__col_sym.size()) |
| 4194 | { |
| 4195 | case 1: |
| 4196 | case 2: |
| 4197 | break; |
| 4198 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4199 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4200 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4201 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4202 | return __first; |
| 4203 | } |
| 4204 | |
| 4205 | template <class _CharT, class _Traits> |
| 4206 | template <class _ForwardIterator> |
| 4207 | _ForwardIterator |
| 4208 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 4209 | _ForwardIterator __last, |
| 4210 | int& __c) |
| 4211 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4212 | if (__first != __last ) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4213 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4214 | int __val = __traits_.value(*__first, 10); |
| 4215 | if ( __val != -1 ) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4216 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4217 | __c = __val; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4218 | for (++__first; |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4219 | __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; |
| 4220 | ++__first) |
| 4221 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4222 | if (__c >= numeric_limits<int>::max() / 10) |
Marshall Clow | 863ae38 | 2017-10-19 17:39:16 +0000 | [diff] [blame] | 4223 | __throw_regex_error<regex_constants::error_badbrace>(); |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4224 | __c *= 10; |
| 4225 | __c += __val; |
| 4226 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4227 | } |
| 4228 | } |
| 4229 | return __first; |
| 4230 | } |
| 4231 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4232 | template <class _CharT, class _Traits> |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4233 | template <class _ForwardIterator> |
| 4234 | _ForwardIterator |
| 4235 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 4236 | _ForwardIterator __last) |
| 4237 | { |
| 4238 | __owns_one_state<_CharT>* __sa = __end_; |
| 4239 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 4240 | if (__temp == __first) |
| 4241 | __push_empty(); |
| 4242 | __first = __temp; |
| 4243 | while (__first != __last && *__first == '|') |
| 4244 | { |
| 4245 | __owns_one_state<_CharT>* __sb = __end_; |
| 4246 | __temp = __parse_alternative(++__first, __last); |
| 4247 | if (__temp == __first) |
| 4248 | __push_empty(); |
| 4249 | __push_alternation(__sa, __sb); |
| 4250 | __first = __temp; |
| 4251 | } |
| 4252 | return __first; |
| 4253 | } |
| 4254 | |
| 4255 | template <class _CharT, class _Traits> |
| 4256 | template <class _ForwardIterator> |
| 4257 | _ForwardIterator |
| 4258 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 4259 | _ForwardIterator __last) |
| 4260 | { |
| 4261 | while (true) |
| 4262 | { |
| 4263 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 4264 | if (__temp == __first) |
| 4265 | break; |
| 4266 | __first = __temp; |
| 4267 | } |
| 4268 | return __first; |
| 4269 | } |
| 4270 | |
| 4271 | template <class _CharT, class _Traits> |
| 4272 | template <class _ForwardIterator> |
| 4273 | _ForwardIterator |
| 4274 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 4275 | _ForwardIterator __last) |
| 4276 | { |
| 4277 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 4278 | if (__temp == __first) |
| 4279 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4280 | __owns_one_state<_CharT>* __e = __end_; |
| 4281 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4282 | __temp = __parse_atom(__first, __last); |
| 4283 | if (__temp != __first) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4284 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 4285 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4286 | } |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4287 | else |
| 4288 | __first = __temp; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4289 | return __first; |
| 4290 | } |
| 4291 | |
| 4292 | template <class _CharT, class _Traits> |
| 4293 | template <class _ForwardIterator> |
| 4294 | _ForwardIterator |
| 4295 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 4296 | _ForwardIterator __last) |
| 4297 | { |
| 4298 | if (__first != __last) |
| 4299 | { |
| 4300 | switch (*__first) |
| 4301 | { |
| 4302 | case '^': |
| 4303 | __push_l_anchor(); |
| 4304 | ++__first; |
| 4305 | break; |
| 4306 | case '$': |
| 4307 | __push_r_anchor(); |
| 4308 | ++__first; |
| 4309 | break; |
| 4310 | case '\\': |
| 4311 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4312 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4313 | if (__temp != __last) |
| 4314 | { |
| 4315 | if (*__temp == 'b') |
| 4316 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4317 | __push_word_boundary(false); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4318 | __first = ++__temp; |
| 4319 | } |
| 4320 | else if (*__temp == 'B') |
| 4321 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4322 | __push_word_boundary(true); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4323 | __first = ++__temp; |
| 4324 | } |
| 4325 | } |
| 4326 | } |
| 4327 | break; |
| 4328 | case '(': |
| 4329 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4330 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4331 | if (__temp != __last && *__temp == '?') |
| 4332 | { |
| 4333 | if (++__temp != __last) |
| 4334 | { |
| 4335 | switch (*__temp) |
| 4336 | { |
| 4337 | case '=': |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4338 | { |
| 4339 | basic_regex __exp; |
| 4340 | __exp.__flags_ = __flags_; |
| 4341 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4342 | unsigned __mexp = __exp.__marked_count_; |
| 4343 | __push_lookahead(_VSTD::move(__exp), false, __marked_count_); |
| 4344 | __marked_count_ += __mexp; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4345 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4346 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4347 | __first = ++__temp; |
| 4348 | } |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4349 | break; |
| 4350 | case '!': |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4351 | { |
| 4352 | basic_regex __exp; |
| 4353 | __exp.__flags_ = __flags_; |
| 4354 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4355 | unsigned __mexp = __exp.__marked_count_; |
| 4356 | __push_lookahead(_VSTD::move(__exp), true, __marked_count_); |
| 4357 | __marked_count_ += __mexp; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4358 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4359 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4360 | __first = ++__temp; |
| 4361 | } |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4362 | break; |
| 4363 | } |
| 4364 | } |
| 4365 | } |
| 4366 | } |
| 4367 | break; |
| 4368 | } |
| 4369 | } |
| 4370 | return __first; |
| 4371 | } |
| 4372 | |
| 4373 | template <class _CharT, class _Traits> |
| 4374 | template <class _ForwardIterator> |
| 4375 | _ForwardIterator |
| 4376 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4377 | _ForwardIterator __last) |
| 4378 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4379 | if (__first != __last) |
| 4380 | { |
| 4381 | switch (*__first) |
| 4382 | { |
| 4383 | case '.': |
| 4384 | __push_match_any_but_newline(); |
| 4385 | ++__first; |
| 4386 | break; |
| 4387 | case '\\': |
| 4388 | __first = __parse_atom_escape(__first, __last); |
| 4389 | break; |
| 4390 | case '[': |
| 4391 | __first = __parse_bracket_expression(__first, __last); |
| 4392 | break; |
| 4393 | case '(': |
| 4394 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4395 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4396 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4397 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4398 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4399 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4400 | { |
| 4401 | ++__open_count_; |
| 4402 | __first = __parse_ecma_exp(++__temp, __last); |
| 4403 | if (__first == __last || *__first != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4404 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4405 | --__open_count_; |
| 4406 | ++__first; |
| 4407 | } |
| 4408 | else |
| 4409 | { |
| 4410 | __push_begin_marked_subexpression(); |
| 4411 | unsigned __temp_count = __marked_count_; |
| 4412 | ++__open_count_; |
| 4413 | __first = __parse_ecma_exp(__first, __last); |
| 4414 | if (__first == __last || *__first != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4415 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4416 | __push_end_marked_subexpression(__temp_count); |
| 4417 | --__open_count_; |
| 4418 | ++__first; |
| 4419 | } |
| 4420 | } |
| 4421 | break; |
Marshall Clow | 8205821 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4422 | case '*': |
| 4423 | case '+': |
| 4424 | case '?': |
| 4425 | case '{': |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4426 | __throw_regex_error<regex_constants::error_badrepeat>(); |
Marshall Clow | 8205821 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4427 | break; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4428 | default: |
| 4429 | __first = __parse_pattern_character(__first, __last); |
| 4430 | break; |
| 4431 | } |
| 4432 | } |
| 4433 | return __first; |
| 4434 | } |
| 4435 | |
| 4436 | template <class _CharT, class _Traits> |
| 4437 | template <class _ForwardIterator> |
| 4438 | _ForwardIterator |
| 4439 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4440 | _ForwardIterator __last) |
| 4441 | { |
| 4442 | if (__first != __last && *__first == '\\') |
| 4443 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4444 | _ForwardIterator __t1 = _VSTD::next(__first); |
Marshall Clow | db9633c | 2016-01-19 00:50:37 +0000 | [diff] [blame] | 4445 | if (__t1 == __last) |
| 4446 | __throw_regex_error<regex_constants::error_escape>(); |
| 4447 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4448 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4449 | if (__t2 != __t1) |
| 4450 | __first = __t2; |
| 4451 | else |
| 4452 | { |
| 4453 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4454 | if (__t2 != __t1) |
| 4455 | __first = __t2; |
| 4456 | else |
| 4457 | { |
| 4458 | __t2 = __parse_character_escape(__t1, __last); |
| 4459 | if (__t2 != __t1) |
| 4460 | __first = __t2; |
| 4461 | } |
| 4462 | } |
| 4463 | } |
| 4464 | return __first; |
| 4465 | } |
| 4466 | |
| 4467 | template <class _CharT, class _Traits> |
| 4468 | template <class _ForwardIterator> |
| 4469 | _ForwardIterator |
| 4470 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4471 | _ForwardIterator __last) |
| 4472 | { |
| 4473 | if (__first != __last) |
| 4474 | { |
| 4475 | if (*__first == '0') |
| 4476 | { |
| 4477 | __push_char(_CharT()); |
| 4478 | ++__first; |
| 4479 | } |
| 4480 | else if ('1' <= *__first && *__first <= '9') |
| 4481 | { |
| 4482 | unsigned __v = *__first - '0'; |
Marshall Clow | dc03ec7 | 2016-12-24 17:21:03 +0000 | [diff] [blame] | 4483 | for (++__first; |
| 4484 | __first != __last && '0' <= *__first && *__first <= '9'; ++__first) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4485 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4486 | if (__v >= numeric_limits<unsigned>::max() / 10) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4487 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4488 | __v = 10 * __v + *__first - '0'; |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4489 | } |
| 4490 | if (__v == 0 || __v > mark_count()) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4491 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4492 | __push_back_ref(__v); |
| 4493 | } |
| 4494 | } |
| 4495 | return __first; |
| 4496 | } |
| 4497 | |
| 4498 | template <class _CharT, class _Traits> |
| 4499 | template <class _ForwardIterator> |
| 4500 | _ForwardIterator |
| 4501 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4502 | _ForwardIterator __last) |
| 4503 | { |
| 4504 | if (__first != __last) |
| 4505 | { |
| 4506 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4507 | switch (*__first) |
| 4508 | { |
| 4509 | case 'd': |
| 4510 | __ml = __start_matching_list(false); |
| 4511 | __ml->__add_class(ctype_base::digit); |
| 4512 | ++__first; |
| 4513 | break; |
| 4514 | case 'D': |
| 4515 | __ml = __start_matching_list(true); |
| 4516 | __ml->__add_class(ctype_base::digit); |
| 4517 | ++__first; |
| 4518 | break; |
| 4519 | case 's': |
| 4520 | __ml = __start_matching_list(false); |
| 4521 | __ml->__add_class(ctype_base::space); |
| 4522 | ++__first; |
| 4523 | break; |
| 4524 | case 'S': |
| 4525 | __ml = __start_matching_list(true); |
| 4526 | __ml->__add_class(ctype_base::space); |
| 4527 | ++__first; |
| 4528 | break; |
| 4529 | case 'w': |
| 4530 | __ml = __start_matching_list(false); |
| 4531 | __ml->__add_class(ctype_base::alnum); |
| 4532 | __ml->__add_char('_'); |
| 4533 | ++__first; |
| 4534 | break; |
| 4535 | case 'W': |
| 4536 | __ml = __start_matching_list(true); |
| 4537 | __ml->__add_class(ctype_base::alnum); |
| 4538 | __ml->__add_char('_'); |
| 4539 | ++__first; |
| 4540 | break; |
| 4541 | } |
| 4542 | } |
| 4543 | return __first; |
| 4544 | } |
| 4545 | |
| 4546 | template <class _CharT, class _Traits> |
| 4547 | template <class _ForwardIterator> |
| 4548 | _ForwardIterator |
| 4549 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4550 | _ForwardIterator __last, |
| 4551 | basic_string<_CharT>* __str) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4552 | { |
| 4553 | if (__first != __last) |
| 4554 | { |
| 4555 | _ForwardIterator __t; |
| 4556 | unsigned __sum = 0; |
| 4557 | int __hd; |
| 4558 | switch (*__first) |
| 4559 | { |
| 4560 | case 'f': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4561 | if (__str) |
| 4562 | *__str = _CharT(0xC); |
| 4563 | else |
| 4564 | __push_char(_CharT(0xC)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4565 | ++__first; |
| 4566 | break; |
| 4567 | case 'n': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4568 | if (__str) |
| 4569 | *__str = _CharT(0xA); |
| 4570 | else |
| 4571 | __push_char(_CharT(0xA)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4572 | ++__first; |
| 4573 | break; |
| 4574 | case 'r': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4575 | if (__str) |
| 4576 | *__str = _CharT(0xD); |
| 4577 | else |
| 4578 | __push_char(_CharT(0xD)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4579 | ++__first; |
| 4580 | break; |
| 4581 | case 't': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4582 | if (__str) |
| 4583 | *__str = _CharT(0x9); |
| 4584 | else |
| 4585 | __push_char(_CharT(0x9)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4586 | ++__first; |
| 4587 | break; |
| 4588 | case 'v': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4589 | if (__str) |
| 4590 | *__str = _CharT(0xB); |
| 4591 | else |
| 4592 | __push_char(_CharT(0xB)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4593 | ++__first; |
| 4594 | break; |
| 4595 | case 'c': |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4596 | if ((__t = _VSTD::next(__first)) != __last) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4597 | { |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4598 | if (('A' <= *__t && *__t <= 'Z') || |
Howard Hinnant | d04741b | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4599 | ('a' <= *__t && *__t <= 'z')) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4600 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4601 | if (__str) |
| 4602 | *__str = _CharT(*__t % 32); |
| 4603 | else |
| 4604 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4605 | __first = ++__t; |
| 4606 | } |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4607 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4608 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4609 | } |
Howard Hinnant | d04741b | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4610 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4611 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4612 | break; |
| 4613 | case 'u': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4614 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4615 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4616 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4617 | __hd = __traits_.value(*__first, 16); |
| 4618 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4619 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4620 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4621 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4622 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4623 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4624 | __hd = __traits_.value(*__first, 16); |
| 4625 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4626 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4627 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 4628 | // fallthrough |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4629 | case 'x': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4630 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4631 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4632 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4633 | __hd = __traits_.value(*__first, 16); |
| 4634 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4635 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4636 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4637 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4638 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4639 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4640 | __hd = __traits_.value(*__first, 16); |
| 4641 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4642 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4643 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4644 | if (__str) |
| 4645 | *__str = _CharT(__sum); |
| 4646 | else |
| 4647 | __push_char(_CharT(__sum)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4648 | ++__first; |
| 4649 | break; |
Marshall Clow | f6cef0d | 2014-05-21 16:29:50 +0000 | [diff] [blame] | 4650 | case '0': |
| 4651 | if (__str) |
| 4652 | *__str = _CharT(0); |
| 4653 | else |
| 4654 | __push_char(_CharT(0)); |
| 4655 | ++__first; |
| 4656 | break; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4657 | default: |
| 4658 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4659 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4660 | if (__str) |
| 4661 | *__str = *__first; |
| 4662 | else |
| 4663 | __push_char(*__first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4664 | ++__first; |
| 4665 | } |
Howard Hinnant | 4f7a1f5 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 4666 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4667 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4668 | break; |
| 4669 | } |
| 4670 | } |
| 4671 | return __first; |
| 4672 | } |
| 4673 | |
| 4674 | template <class _CharT, class _Traits> |
| 4675 | template <class _ForwardIterator> |
| 4676 | _ForwardIterator |
| 4677 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4678 | _ForwardIterator __last) |
| 4679 | { |
| 4680 | if (__first != __last) |
| 4681 | { |
| 4682 | switch (*__first) |
| 4683 | { |
| 4684 | case '^': |
| 4685 | case '$': |
| 4686 | case '\\': |
| 4687 | case '.': |
| 4688 | case '*': |
| 4689 | case '+': |
| 4690 | case '?': |
| 4691 | case '(': |
| 4692 | case ')': |
| 4693 | case '[': |
| 4694 | case ']': |
| 4695 | case '{': |
| 4696 | case '}': |
| 4697 | case '|': |
| 4698 | break; |
| 4699 | default: |
| 4700 | __push_char(*__first); |
| 4701 | ++__first; |
| 4702 | break; |
| 4703 | } |
| 4704 | } |
| 4705 | return __first; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4706 | } |
| 4707 | |
| 4708 | template <class _CharT, class _Traits> |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4709 | template <class _ForwardIterator> |
| 4710 | _ForwardIterator |
| 4711 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4712 | _ForwardIterator __last) |
| 4713 | { |
| 4714 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4715 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4716 | if (__t1 != __first) |
| 4717 | __parse_basic_reg_exp(__first, __t1); |
| 4718 | else |
| 4719 | __push_empty(); |
| 4720 | __first = __t1; |
| 4721 | if (__first != __last) |
| 4722 | ++__first; |
| 4723 | while (__first != __last) |
| 4724 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4725 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4726 | __owns_one_state<_CharT>* __sb = __end_; |
| 4727 | if (__t1 != __first) |
| 4728 | __parse_basic_reg_exp(__first, __t1); |
| 4729 | else |
| 4730 | __push_empty(); |
| 4731 | __push_alternation(__sa, __sb); |
| 4732 | __first = __t1; |
| 4733 | if (__first != __last) |
| 4734 | ++__first; |
| 4735 | } |
| 4736 | return __first; |
| 4737 | } |
| 4738 | |
| 4739 | template <class _CharT, class _Traits> |
| 4740 | template <class _ForwardIterator> |
| 4741 | _ForwardIterator |
| 4742 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4743 | _ForwardIterator __last) |
| 4744 | { |
| 4745 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4746 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4747 | if (__t1 != __first) |
| 4748 | __parse_extended_reg_exp(__first, __t1); |
| 4749 | else |
| 4750 | __push_empty(); |
| 4751 | __first = __t1; |
| 4752 | if (__first != __last) |
| 4753 | ++__first; |
| 4754 | while (__first != __last) |
| 4755 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4756 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4757 | __owns_one_state<_CharT>* __sb = __end_; |
| 4758 | if (__t1 != __first) |
| 4759 | __parse_extended_reg_exp(__first, __t1); |
| 4760 | else |
| 4761 | __push_empty(); |
| 4762 | __push_alternation(__sa, __sb); |
| 4763 | __first = __t1; |
| 4764 | if (__first != __last) |
| 4765 | ++__first; |
| 4766 | } |
| 4767 | return __first; |
| 4768 | } |
| 4769 | |
| 4770 | template <class _CharT, class _Traits> |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4771 | bool |
| 4772 | basic_regex<_CharT, _Traits>::__test_back_ref(_CharT c) |
| 4773 | { |
| 4774 | unsigned __val = __traits_.value(c, 10); |
| 4775 | if (__val >= 1 && __val <= 9) |
| 4776 | { |
Mark de Wever | d324e5f | 2020-02-20 18:13:38 -0500 | [diff] [blame] | 4777 | if (__val > mark_count()) |
| 4778 | __throw_regex_error<regex_constants::error_backref>(); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4779 | __push_back_ref(__val); |
| 4780 | return true; |
| 4781 | } |
| 4782 | |
| 4783 | return false; |
| 4784 | } |
| 4785 | |
| 4786 | template <class _CharT, class _Traits> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4787 | void |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4788 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4789 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4790 | bool __greedy) |
| 4791 | { |
| 4792 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4793 | __end_->first() = nullptr; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4794 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4795 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4796 | __min, __max)); |
| 4797 | __s->first() = nullptr; |
| 4798 | __e1.release(); |
| 4799 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4800 | __end_ = __e2->second(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4801 | __s->first() = __e2.release(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4802 | ++__loop_count_; |
| 4803 | } |
| 4804 | |
| 4805 | template <class _CharT, class _Traits> |
| 4806 | void |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4807 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4808 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4809 | if (flags() & icase) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4810 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4811 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4812 | else if (flags() & collate) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4813 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4814 | (__traits_, __c, __end_->first()); |
| 4815 | else |
| 4816 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4817 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4818 | } |
| 4819 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4820 | template <class _CharT, class _Traits> |
| 4821 | void |
| 4822 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4823 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4824 | if (!(__flags_ & nosubs)) |
| 4825 | { |
| 4826 | __end_->first() = |
| 4827 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4828 | __end_->first()); |
| 4829 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4830 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4831 | } |
| 4832 | |
| 4833 | template <class _CharT, class _Traits> |
| 4834 | void |
| 4835 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4836 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4837 | if (!(__flags_ & nosubs)) |
| 4838 | { |
| 4839 | __end_->first() = |
| 4840 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4841 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4842 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4843 | } |
| 4844 | |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4845 | template <class _CharT, class _Traits> |
| 4846 | void |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4847 | basic_regex<_CharT, _Traits>::__push_l_anchor() |
| 4848 | { |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 4849 | __end_->first() = new __l_anchor_multiline<_CharT>(__use_multiline(), __end_->first()); |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4850 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4851 | } |
| 4852 | |
| 4853 | template <class _CharT, class _Traits> |
| 4854 | void |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4855 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4856 | { |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 4857 | __end_->first() = new __r_anchor_multiline<_CharT>(__use_multiline(), __end_->first()); |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4858 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4859 | } |
| 4860 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4861 | template <class _CharT, class _Traits> |
| 4862 | void |
| 4863 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4864 | { |
| 4865 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4866 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4867 | } |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4868 | |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4869 | template <class _CharT, class _Traits> |
| 4870 | void |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4871 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4872 | { |
| 4873 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4874 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4875 | } |
| 4876 | |
| 4877 | template <class _CharT, class _Traits> |
| 4878 | void |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4879 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4880 | { |
| 4881 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4882 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4883 | } |
| 4884 | |
| 4885 | template <class _CharT, class _Traits> |
| 4886 | void |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4887 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4888 | { |
| 4889 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4890 | __end_->first()); |
| 4891 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4892 | } |
| 4893 | |
| 4894 | template <class _CharT, class _Traits> |
| 4895 | void |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4896 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4897 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4898 | if (flags() & icase) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4899 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4900 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4901 | else if (flags() & collate) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4902 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4903 | (__traits_, __i, __end_->first()); |
| 4904 | else |
| 4905 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4906 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4907 | } |
| 4908 | |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4909 | template <class _CharT, class _Traits> |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4910 | void |
| 4911 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4912 | __owns_one_state<_CharT>* __ea) |
| 4913 | { |
| 4914 | __sa->first() = new __alternate<_CharT>( |
| 4915 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4916 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4917 | __ea->first() = nullptr; |
| 4918 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4919 | __end_->first() = nullptr; |
| 4920 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4921 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4922 | } |
| 4923 | |
| 4924 | template <class _CharT, class _Traits> |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4925 | __bracket_expression<_CharT, _Traits>* |
| 4926 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4927 | { |
| 4928 | __bracket_expression<_CharT, _Traits>* __r = |
| 4929 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4930 | __negate, __flags_ & icase, |
| 4931 | __flags_ & collate); |
| 4932 | __end_->first() = __r; |
| 4933 | __end_ = __r; |
| 4934 | return __r; |
| 4935 | } |
| 4936 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4937 | template <class _CharT, class _Traits> |
| 4938 | void |
| 4939 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4940 | bool __invert, |
| 4941 | unsigned __mexp) |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4942 | { |
| 4943 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4944 | __end_->first(), __mexp); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4945 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4946 | } |
| 4947 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4948 | // sub_match |
| 4949 | |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4950 | typedef sub_match<const char*> csub_match; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4951 | typedef sub_match<string::const_iterator> ssub_match; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4952 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4953 | typedef sub_match<const wchar_t*> wcsub_match; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4954 | typedef sub_match<wstring::const_iterator> wssub_match; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4955 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4956 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4957 | template <class _BidirectionalIterator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4958 | class |
| 4959 | _LIBCPP_TEMPLATE_VIS |
| 4960 | _LIBCPP_PREFERRED_NAME(csub_match) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4961 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4962 | _LIBCPP_PREFERRED_NAME(ssub_match) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4963 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4964 | sub_match |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4965 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4966 | { |
| 4967 | public: |
| 4968 | typedef _BidirectionalIterator iterator; |
| 4969 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4970 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4971 | typedef basic_string<value_type> string_type; |
| 4972 | |
| 4973 | bool matched; |
| 4974 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4975 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 4976 | _LIBCPP_CONSTEXPR sub_match() : matched() {} |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 4977 | |
| 4978 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4979 | difference_type length() const |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4980 | {return matched ? _VSTD::distance(this->first, this->second) : 0;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4981 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4982 | string_type str() const |
| 4983 | {return matched ? string_type(this->first, this->second) : string_type();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4984 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4985 | operator string_type() const |
| 4986 | {return str();} |
| 4987 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4988 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4989 | int compare(const sub_match& __s) const |
| 4990 | {return str().compare(__s.str());} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4991 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4992 | int compare(const string_type& __s) const |
| 4993 | {return str().compare(__s);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4994 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4995 | int compare(const value_type* __s) const |
| 4996 | {return str().compare(__s);} |
| 4997 | }; |
| 4998 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4999 | template <class _BiIter> |
| 5000 | inline _LIBCPP_INLINE_VISIBILITY |
| 5001 | bool |
| 5002 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5003 | { |
| 5004 | return __x.compare(__y) == 0; |
| 5005 | } |
| 5006 | |
| 5007 | template <class _BiIter> |
| 5008 | inline _LIBCPP_INLINE_VISIBILITY |
| 5009 | bool |
| 5010 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5011 | { |
| 5012 | return !(__x == __y); |
| 5013 | } |
| 5014 | |
| 5015 | template <class _BiIter> |
| 5016 | inline _LIBCPP_INLINE_VISIBILITY |
| 5017 | bool |
| 5018 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5019 | { |
| 5020 | return __x.compare(__y) < 0; |
| 5021 | } |
| 5022 | |
| 5023 | template <class _BiIter> |
| 5024 | inline _LIBCPP_INLINE_VISIBILITY |
| 5025 | bool |
| 5026 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5027 | { |
| 5028 | return !(__y < __x); |
| 5029 | } |
| 5030 | |
| 5031 | template <class _BiIter> |
| 5032 | inline _LIBCPP_INLINE_VISIBILITY |
| 5033 | bool |
| 5034 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5035 | { |
| 5036 | return !(__x < __y); |
| 5037 | } |
| 5038 | |
| 5039 | template <class _BiIter> |
| 5040 | inline _LIBCPP_INLINE_VISIBILITY |
| 5041 | bool |
| 5042 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5043 | { |
| 5044 | return __y < __x; |
| 5045 | } |
| 5046 | |
| 5047 | template <class _BiIter, class _ST, class _SA> |
| 5048 | inline _LIBCPP_INLINE_VISIBILITY |
| 5049 | bool |
| 5050 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5051 | const sub_match<_BiIter>& __y) |
| 5052 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5053 | return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | template <class _BiIter, class _ST, class _SA> |
| 5057 | inline _LIBCPP_INLINE_VISIBILITY |
| 5058 | bool |
| 5059 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5060 | const sub_match<_BiIter>& __y) |
| 5061 | { |
| 5062 | return !(__x == __y); |
| 5063 | } |
| 5064 | |
| 5065 | template <class _BiIter, class _ST, class _SA> |
| 5066 | inline _LIBCPP_INLINE_VISIBILITY |
| 5067 | bool |
| 5068 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5069 | const sub_match<_BiIter>& __y) |
| 5070 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5071 | return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | template <class _BiIter, class _ST, class _SA> |
| 5075 | inline _LIBCPP_INLINE_VISIBILITY |
| 5076 | bool |
| 5077 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5078 | const sub_match<_BiIter>& __y) |
| 5079 | { |
| 5080 | return __y < __x; |
| 5081 | } |
| 5082 | |
| 5083 | template <class _BiIter, class _ST, class _SA> |
| 5084 | inline _LIBCPP_INLINE_VISIBILITY |
| 5085 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5086 | const sub_match<_BiIter>& __y) |
| 5087 | { |
| 5088 | return !(__x < __y); |
| 5089 | } |
| 5090 | |
| 5091 | template <class _BiIter, class _ST, class _SA> |
| 5092 | inline _LIBCPP_INLINE_VISIBILITY |
| 5093 | bool |
| 5094 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5095 | const sub_match<_BiIter>& __y) |
| 5096 | { |
| 5097 | return !(__y < __x); |
| 5098 | } |
| 5099 | |
| 5100 | template <class _BiIter, class _ST, class _SA> |
| 5101 | inline _LIBCPP_INLINE_VISIBILITY |
| 5102 | bool |
| 5103 | operator==(const sub_match<_BiIter>& __x, |
| 5104 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5105 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5106 | return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5107 | } |
| 5108 | |
| 5109 | template <class _BiIter, class _ST, class _SA> |
| 5110 | inline _LIBCPP_INLINE_VISIBILITY |
| 5111 | bool |
| 5112 | operator!=(const sub_match<_BiIter>& __x, |
| 5113 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5114 | { |
| 5115 | return !(__x == __y); |
| 5116 | } |
| 5117 | |
| 5118 | template <class _BiIter, class _ST, class _SA> |
| 5119 | inline _LIBCPP_INLINE_VISIBILITY |
| 5120 | bool |
| 5121 | operator<(const sub_match<_BiIter>& __x, |
| 5122 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5123 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5124 | return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5125 | } |
| 5126 | |
| 5127 | template <class _BiIter, class _ST, class _SA> |
| 5128 | inline _LIBCPP_INLINE_VISIBILITY |
| 5129 | bool operator>(const sub_match<_BiIter>& __x, |
| 5130 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5131 | { |
| 5132 | return __y < __x; |
| 5133 | } |
| 5134 | |
| 5135 | template <class _BiIter, class _ST, class _SA> |
| 5136 | inline _LIBCPP_INLINE_VISIBILITY |
| 5137 | bool |
| 5138 | operator>=(const sub_match<_BiIter>& __x, |
| 5139 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5140 | { |
| 5141 | return !(__x < __y); |
| 5142 | } |
| 5143 | |
| 5144 | template <class _BiIter, class _ST, class _SA> |
| 5145 | inline _LIBCPP_INLINE_VISIBILITY |
| 5146 | bool |
| 5147 | operator<=(const sub_match<_BiIter>& __x, |
| 5148 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5149 | { |
| 5150 | return !(__y < __x); |
| 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 __y.compare(__x) == 0; |
| 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 | return !(__x == __y); |
| 5169 | } |
| 5170 | |
| 5171 | template <class _BiIter> |
| 5172 | inline _LIBCPP_INLINE_VISIBILITY |
| 5173 | bool |
| 5174 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5175 | const sub_match<_BiIter>& __y) |
| 5176 | { |
| 5177 | return __y.compare(__x) > 0; |
| 5178 | } |
| 5179 | |
| 5180 | template <class _BiIter> |
| 5181 | inline _LIBCPP_INLINE_VISIBILITY |
| 5182 | bool |
| 5183 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5184 | const sub_match<_BiIter>& __y) |
| 5185 | { |
| 5186 | return __y < __x; |
| 5187 | } |
| 5188 | |
| 5189 | template <class _BiIter> |
| 5190 | inline _LIBCPP_INLINE_VISIBILITY |
| 5191 | bool |
| 5192 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5193 | const sub_match<_BiIter>& __y) |
| 5194 | { |
| 5195 | return !(__x < __y); |
| 5196 | } |
| 5197 | |
| 5198 | template <class _BiIter> |
| 5199 | inline _LIBCPP_INLINE_VISIBILITY |
| 5200 | bool |
| 5201 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5202 | const sub_match<_BiIter>& __y) |
| 5203 | { |
| 5204 | return !(__y < __x); |
| 5205 | } |
| 5206 | |
| 5207 | template <class _BiIter> |
| 5208 | inline _LIBCPP_INLINE_VISIBILITY |
| 5209 | bool |
| 5210 | operator==(const sub_match<_BiIter>& __x, |
| 5211 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5212 | { |
| 5213 | return __x.compare(__y) == 0; |
| 5214 | } |
| 5215 | |
| 5216 | template <class _BiIter> |
| 5217 | inline _LIBCPP_INLINE_VISIBILITY |
| 5218 | bool |
| 5219 | operator!=(const sub_match<_BiIter>& __x, |
| 5220 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5221 | { |
| 5222 | return !(__x == __y); |
| 5223 | } |
| 5224 | |
| 5225 | template <class _BiIter> |
| 5226 | inline _LIBCPP_INLINE_VISIBILITY |
| 5227 | bool |
| 5228 | operator<(const sub_match<_BiIter>& __x, |
| 5229 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5230 | { |
| 5231 | return __x.compare(__y) < 0; |
| 5232 | } |
| 5233 | |
| 5234 | template <class _BiIter> |
| 5235 | inline _LIBCPP_INLINE_VISIBILITY |
| 5236 | bool |
| 5237 | operator>(const sub_match<_BiIter>& __x, |
| 5238 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5239 | { |
| 5240 | return __y < __x; |
| 5241 | } |
| 5242 | |
| 5243 | template <class _BiIter> |
| 5244 | inline _LIBCPP_INLINE_VISIBILITY |
| 5245 | bool |
| 5246 | operator>=(const sub_match<_BiIter>& __x, |
| 5247 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5248 | { |
| 5249 | return !(__x < __y); |
| 5250 | } |
| 5251 | |
| 5252 | template <class _BiIter> |
| 5253 | inline _LIBCPP_INLINE_VISIBILITY |
| 5254 | bool |
| 5255 | operator<=(const sub_match<_BiIter>& __x, |
| 5256 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5257 | { |
| 5258 | return !(__y < __x); |
| 5259 | } |
| 5260 | |
| 5261 | template <class _BiIter> |
| 5262 | inline _LIBCPP_INLINE_VISIBILITY |
| 5263 | bool |
| 5264 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5265 | const sub_match<_BiIter>& __y) |
| 5266 | { |
| 5267 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5268 | return __y.compare(string_type(1, __x)) == 0; |
| 5269 | } |
| 5270 | |
| 5271 | template <class _BiIter> |
| 5272 | inline _LIBCPP_INLINE_VISIBILITY |
| 5273 | bool |
| 5274 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5275 | const sub_match<_BiIter>& __y) |
| 5276 | { |
| 5277 | return !(__x == __y); |
| 5278 | } |
| 5279 | |
| 5280 | template <class _BiIter> |
| 5281 | inline _LIBCPP_INLINE_VISIBILITY |
| 5282 | bool |
| 5283 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5284 | const sub_match<_BiIter>& __y) |
| 5285 | { |
| 5286 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5287 | return __y.compare(string_type(1, __x)) > 0; |
| 5288 | } |
| 5289 | |
| 5290 | template <class _BiIter> |
| 5291 | inline _LIBCPP_INLINE_VISIBILITY |
| 5292 | bool |
| 5293 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5294 | const sub_match<_BiIter>& __y) |
| 5295 | { |
| 5296 | return __y < __x; |
| 5297 | } |
| 5298 | |
| 5299 | template <class _BiIter> |
| 5300 | inline _LIBCPP_INLINE_VISIBILITY |
| 5301 | bool |
| 5302 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5303 | const sub_match<_BiIter>& __y) |
| 5304 | { |
| 5305 | return !(__x < __y); |
| 5306 | } |
| 5307 | |
| 5308 | template <class _BiIter> |
| 5309 | inline _LIBCPP_INLINE_VISIBILITY |
| 5310 | bool |
| 5311 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5312 | const sub_match<_BiIter>& __y) |
| 5313 | { |
| 5314 | return !(__y < __x); |
| 5315 | } |
| 5316 | |
| 5317 | template <class _BiIter> |
| 5318 | inline _LIBCPP_INLINE_VISIBILITY |
| 5319 | bool |
| 5320 | operator==(const sub_match<_BiIter>& __x, |
| 5321 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5322 | { |
| 5323 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5324 | return __x.compare(string_type(1, __y)) == 0; |
| 5325 | } |
| 5326 | |
| 5327 | template <class _BiIter> |
| 5328 | inline _LIBCPP_INLINE_VISIBILITY |
| 5329 | bool |
| 5330 | operator!=(const sub_match<_BiIter>& __x, |
| 5331 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5332 | { |
| 5333 | return !(__x == __y); |
| 5334 | } |
| 5335 | |
| 5336 | template <class _BiIter> |
| 5337 | inline _LIBCPP_INLINE_VISIBILITY |
| 5338 | bool |
| 5339 | operator<(const sub_match<_BiIter>& __x, |
| 5340 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5341 | { |
| 5342 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5343 | return __x.compare(string_type(1, __y)) < 0; |
| 5344 | } |
| 5345 | |
| 5346 | template <class _BiIter> |
| 5347 | inline _LIBCPP_INLINE_VISIBILITY |
| 5348 | bool |
| 5349 | operator>(const sub_match<_BiIter>& __x, |
| 5350 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5351 | { |
| 5352 | return __y < __x; |
| 5353 | } |
| 5354 | |
| 5355 | template <class _BiIter> |
| 5356 | inline _LIBCPP_INLINE_VISIBILITY |
| 5357 | bool |
| 5358 | operator>=(const sub_match<_BiIter>& __x, |
| 5359 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5360 | { |
| 5361 | return !(__x < __y); |
| 5362 | } |
| 5363 | |
| 5364 | template <class _BiIter> |
| 5365 | inline _LIBCPP_INLINE_VISIBILITY |
| 5366 | bool |
| 5367 | operator<=(const sub_match<_BiIter>& __x, |
| 5368 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5369 | { |
| 5370 | return !(__y < __x); |
| 5371 | } |
| 5372 | |
| 5373 | template <class _CharT, class _ST, class _BiIter> |
| 5374 | inline _LIBCPP_INLINE_VISIBILITY |
| 5375 | basic_ostream<_CharT, _ST>& |
| 5376 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 5377 | { |
| 5378 | return __os << __m.str(); |
| 5379 | } |
| 5380 | |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5381 | typedef match_results<const char*> cmatch; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5382 | typedef match_results<string::const_iterator> smatch; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5383 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 5384 | typedef match_results<const wchar_t*> wcmatch; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5385 | typedef match_results<wstring::const_iterator> wsmatch; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5386 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5387 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5388 | template <class _BidirectionalIterator, class _Allocator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5389 | class |
| 5390 | _LIBCPP_TEMPLATE_VIS |
| 5391 | _LIBCPP_PREFERRED_NAME(cmatch) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5392 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5393 | _LIBCPP_PREFERRED_NAME(smatch) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5394 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5395 | match_results |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5396 | { |
| 5397 | public: |
| 5398 | typedef _Allocator allocator_type; |
| 5399 | typedef sub_match<_BidirectionalIterator> value_type; |
| 5400 | private: |
| 5401 | typedef vector<value_type, allocator_type> __container_type; |
| 5402 | |
| 5403 | __container_type __matches_; |
| 5404 | value_type __unmatched_; |
| 5405 | value_type __prefix_; |
| 5406 | value_type __suffix_; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5407 | bool __ready_; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5408 | public: |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5409 | _BidirectionalIterator __position_start_; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5410 | typedef const value_type& const_reference; |
Marshall Clow | 96e0614 | 2014-02-26 01:56:31 +0000 | [diff] [blame] | 5411 | typedef value_type& reference; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5412 | typedef typename __container_type::const_iterator const_iterator; |
| 5413 | typedef const_iterator iterator; |
| 5414 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5415 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5416 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5417 | typedef basic_string<char_type> string_type; |
| 5418 | |
| 5419 | // construct/copy/destroy: |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5420 | #ifndef _LIBCPP_CXX03_LANG |
| 5421 | match_results() : match_results(allocator_type()) {} |
| 5422 | explicit match_results(const allocator_type& __a); |
| 5423 | #else |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5424 | explicit match_results(const allocator_type& __a = allocator_type()); |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5425 | #endif |
| 5426 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5427 | // match_results(const match_results&) = default; |
| 5428 | // match_results& operator=(const match_results&) = default; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5429 | // match_results(match_results&& __m) = default; |
| 5430 | // match_results& operator=(match_results&& __m) = default; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5431 | // ~match_results() = default; |
| 5432 | |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5433 | _LIBCPP_INLINE_VISIBILITY |
| 5434 | bool ready() const {return __ready_;} |
| 5435 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5436 | // size: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5437 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 081bcd2 | 2017-11-16 04:48:34 +0000 | [diff] [blame] | 5438 | size_type size() const _NOEXCEPT {return __matches_.size();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5439 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 081bcd2 | 2017-11-16 04:48:34 +0000 | [diff] [blame] | 5440 | size_type max_size() const _NOEXCEPT {return __matches_.max_size();} |
| 5441 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 5442 | bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5443 | |
| 5444 | // element access: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5445 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5446 | difference_type length(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5447 | { |
| 5448 | _LIBCPP_ASSERT(ready(), "match_results::length() called when not ready"); |
| 5449 | return (*this)[__sub].length(); |
| 5450 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5451 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5452 | difference_type position(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5453 | { |
| 5454 | _LIBCPP_ASSERT(ready(), "match_results::position() called when not ready"); |
| 5455 | return _VSTD::distance(__position_start_, (*this)[__sub].first); |
| 5456 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5457 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5458 | string_type str(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5459 | { |
| 5460 | _LIBCPP_ASSERT(ready(), "match_results::str() called when not ready"); |
| 5461 | return (*this)[__sub].str(); |
| 5462 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5463 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5464 | const_reference operator[](size_type __n) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5465 | { |
| 5466 | _LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready"); |
| 5467 | return __n < __matches_.size() ? __matches_[__n] : __unmatched_; |
| 5468 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5469 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5470 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5471 | const_reference prefix() const |
| 5472 | { |
| 5473 | _LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready"); |
| 5474 | return __prefix_; |
| 5475 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5476 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5477 | const_reference suffix() const |
| 5478 | { |
| 5479 | _LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready"); |
| 5480 | return __suffix_; |
| 5481 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5482 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5483 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f4191f | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5484 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5485 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5486 | const_iterator end() const {return __matches_.end();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5487 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f4191f | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5488 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5489 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5490 | const_iterator cend() const {return __matches_.end();} |
| 5491 | |
| 5492 | // format: |
| 5493 | template <class _OutputIter> |
| 5494 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5495 | format(_OutputIter __output_iter, const char_type* __fmt_first, |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5496 | const char_type* __fmt_last, |
| 5497 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5498 | template <class _OutputIter, class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5499 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5500 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5501 | format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5502 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5503 | {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5504 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5505 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5506 | basic_string<char_type, _ST, _SA> |
| 5507 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5508 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5509 | { |
| 5510 | basic_string<char_type, _ST, _SA> __r; |
| 5511 | format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), |
| 5512 | __flags); |
| 5513 | return __r; |
| 5514 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5515 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5516 | string_type |
| 5517 | format(const char_type* __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5518 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5519 | { |
| 5520 | string_type __r; |
| 5521 | format(back_inserter(__r), __fmt, |
| 5522 | __fmt + char_traits<char_type>::length(__fmt), __flags); |
| 5523 | return __r; |
| 5524 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5525 | |
| 5526 | // allocator: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5527 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5528 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5529 | |
| 5530 | // swap: |
| 5531 | void swap(match_results& __m); |
| 5532 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5533 | template <class _Bp, class _Ap> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5534 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5535 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5536 | const match_results<_Bp, _Ap>& __m, bool __no_update_pos) |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5537 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5538 | _Bp __mf = __m.prefix().first; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5539 | __matches_.resize(__m.size()); |
| 5540 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5541 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5542 | __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); |
| 5543 | __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5544 | __matches_[__i].matched = __m[__i].matched; |
| 5545 | } |
| 5546 | __unmatched_.first = __l; |
| 5547 | __unmatched_.second = __l; |
| 5548 | __unmatched_.matched = false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5549 | __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); |
| 5550 | __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5551 | __prefix_.matched = __m.prefix().matched; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5552 | __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); |
| 5553 | __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5554 | __suffix_.matched = __m.suffix().matched; |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5555 | if (!__no_update_pos) |
| 5556 | __position_start_ = __prefix_.first; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5557 | __ready_ = __m.ready(); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5558 | } |
| 5559 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5560 | private: |
| 5561 | void __init(unsigned __s, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5562 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5563 | bool __no_update_pos = false); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5564 | |
| 5565 | template <class, class> friend class basic_regex; |
| 5566 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5567 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5568 | friend |
| 5569 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5570 | regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5571 | regex_constants::match_flag_type); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5572 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5573 | template <class _Bp, class _Ap> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5574 | friend |
| 5575 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5576 | operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5577 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5578 | template <class, class> friend class __lookahead; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5579 | }; |
| 5580 | |
| 5581 | template <class _BidirectionalIterator, class _Allocator> |
| 5582 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5583 | const allocator_type& __a) |
| 5584 | : __matches_(__a), |
| 5585 | __unmatched_(), |
| 5586 | __prefix_(), |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5587 | __suffix_(), |
Eric Fiselier | a75ee26 | 2015-07-22 01:29:41 +0000 | [diff] [blame] | 5588 | __ready_(false), |
| 5589 | __position_start_() |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5590 | { |
| 5591 | } |
| 5592 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5593 | template <class _BidirectionalIterator, class _Allocator> |
| 5594 | void |
| 5595 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5596 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5597 | bool __no_update_pos) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5598 | { |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5599 | __unmatched_.first = __l; |
| 5600 | __unmatched_.second = __l; |
| 5601 | __unmatched_.matched = false; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5602 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5603 | __prefix_.first = __f; |
| 5604 | __prefix_.second = __f; |
| 5605 | __prefix_.matched = false; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5606 | __suffix_ = __unmatched_; |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5607 | if (!__no_update_pos) |
| 5608 | __position_start_ = __prefix_.first; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5609 | __ready_ = true; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5610 | } |
| 5611 | |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5612 | template <class _BidirectionalIterator, class _Allocator> |
| 5613 | template <class _OutputIter> |
| 5614 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5615 | match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5616 | const char_type* __fmt_first, const char_type* __fmt_last, |
| 5617 | regex_constants::match_flag_type __flags) const |
| 5618 | { |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5619 | _LIBCPP_ASSERT(ready(), "match_results::format() called when not ready"); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5620 | if (__flags & regex_constants::format_sed) |
| 5621 | { |
| 5622 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5623 | { |
| 5624 | if (*__fmt_first == '&') |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5625 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 5626 | __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5627 | else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) |
| 5628 | { |
| 5629 | ++__fmt_first; |
| 5630 | if ('0' <= *__fmt_first && *__fmt_first <= '9') |
| 5631 | { |
| 5632 | size_t __i = *__fmt_first - '0'; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5633 | __output_iter = _VSTD::copy((*this)[__i].first, |
| 5634 | (*this)[__i].second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5635 | } |
| 5636 | else |
| 5637 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5638 | *__output_iter = *__fmt_first; |
| 5639 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5640 | } |
| 5641 | } |
| 5642 | else |
| 5643 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5644 | *__output_iter = *__fmt_first; |
| 5645 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5646 | } |
| 5647 | } |
| 5648 | } |
| 5649 | else |
| 5650 | { |
| 5651 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5652 | { |
| 5653 | if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) |
| 5654 | { |
| 5655 | switch (__fmt_first[1]) |
| 5656 | { |
| 5657 | case '$': |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5658 | *__output_iter = *++__fmt_first; |
| 5659 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5660 | break; |
| 5661 | case '&': |
| 5662 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5663 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 5664 | __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5665 | break; |
| 5666 | case '`': |
| 5667 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5668 | __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5669 | break; |
| 5670 | case '\'': |
| 5671 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5672 | __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5673 | break; |
| 5674 | default: |
| 5675 | if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5676 | { |
| 5677 | ++__fmt_first; |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 5678 | size_t __idx = *__fmt_first - '0'; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5679 | if (__fmt_first + 1 != __fmt_last && |
| 5680 | '0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5681 | { |
| 5682 | ++__fmt_first; |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 5683 | if (__idx >= numeric_limits<size_t>::max() / 10) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 5684 | __throw_regex_error<regex_constants::error_escape>(); |
| 5685 | __idx = 10 * __idx + *__fmt_first - '0'; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5686 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5687 | __output_iter = _VSTD::copy((*this)[__idx].first, |
| 5688 | (*this)[__idx].second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5689 | } |
| 5690 | else |
| 5691 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5692 | *__output_iter = *__fmt_first; |
| 5693 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5694 | } |
| 5695 | break; |
| 5696 | } |
| 5697 | } |
| 5698 | else |
| 5699 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5700 | *__output_iter = *__fmt_first; |
| 5701 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5702 | } |
| 5703 | } |
| 5704 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5705 | return __output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | template <class _BidirectionalIterator, class _Allocator> |
| 5709 | void |
| 5710 | match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) |
| 5711 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5712 | using _VSTD::swap; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5713 | swap(__matches_, __m.__matches_); |
| 5714 | swap(__unmatched_, __m.__unmatched_); |
| 5715 | swap(__prefix_, __m.__prefix_); |
| 5716 | swap(__suffix_, __m.__suffix_); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5717 | swap(__position_start_, __m.__position_start_); |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5718 | swap(__ready_, __m.__ready_); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5719 | } |
| 5720 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5721 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5722 | bool |
| 5723 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5724 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5725 | { |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5726 | if (__x.__ready_ != __y.__ready_) |
| 5727 | return false; |
| 5728 | if (!__x.__ready_) |
| 5729 | return true; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5730 | return __x.__matches_ == __y.__matches_ && |
| 5731 | __x.__prefix_ == __y.__prefix_ && |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5732 | __x.__suffix_ == __y.__suffix_; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5733 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5734 | |
| 5735 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5736 | inline _LIBCPP_INLINE_VISIBILITY |
| 5737 | bool |
| 5738 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5739 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5740 | { |
| 5741 | return !(__x == __y); |
| 5742 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5743 | |
| 5744 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5745 | inline _LIBCPP_INLINE_VISIBILITY |
| 5746 | void |
| 5747 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5748 | match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5749 | { |
| 5750 | __x.swap(__y); |
| 5751 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5752 | |
| 5753 | // regex_search |
| 5754 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5755 | template <class _CharT, class _Traits> |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5756 | template <class _Allocator> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5757 | bool |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5758 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5759 | const _CharT* __first, const _CharT* __last, |
| 5760 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5761 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5762 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5763 | vector<__state> __states; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5764 | __node* __st = __start_.get(); |
| 5765 | if (__st) |
| 5766 | { |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5767 | sub_match<const _CharT*> __unmatched; |
| 5768 | __unmatched.first = __last; |
| 5769 | __unmatched.second = __last; |
| 5770 | __unmatched.matched = false; |
| 5771 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5772 | __states.push_back(__state()); |
| 5773 | __states.back().__do_ = 0; |
| 5774 | __states.back().__first_ = __first; |
| 5775 | __states.back().__current_ = __first; |
| 5776 | __states.back().__last_ = __last; |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5777 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5778 | __states.back().__loop_data_.resize(__loop_count()); |
| 5779 | __states.back().__node_ = __st; |
| 5780 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5781 | __states.back().__at_first_ = __at_first; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5782 | int __counter = 0; |
| 5783 | int __length = __last - __first; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5784 | do |
| 5785 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5786 | ++__counter; |
| 5787 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5788 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5789 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5790 | __state& __s = __states.back(); |
| 5791 | if (__s.__node_) |
| 5792 | __s.__node_->__exec(__s); |
| 5793 | switch (__s.__do_) |
| 5794 | { |
| 5795 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5796 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5797 | __s.__current_ == __first) |
| 5798 | { |
| 5799 | __states.pop_back(); |
| 5800 | break; |
| 5801 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5802 | if ((__flags & regex_constants::__full_match) && |
| 5803 | __s.__current_ != __last) |
| 5804 | { |
| 5805 | __states.pop_back(); |
| 5806 | break; |
| 5807 | } |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5808 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5809 | __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5810 | __m.__matches_[0].matched = true; |
| 5811 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5812 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5813 | return true; |
| 5814 | case __state::__accept_and_consume: |
| 5815 | case __state::__repeat: |
| 5816 | case __state::__accept_but_not_consume: |
| 5817 | break; |
| 5818 | case __state::__split: |
| 5819 | { |
| 5820 | __state __snext = __s; |
| 5821 | __s.__node_->__exec_split(true, __s); |
| 5822 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5823 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5824 | } |
| 5825 | break; |
| 5826 | case __state::__reject: |
| 5827 | __states.pop_back(); |
| 5828 | break; |
| 5829 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5830 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5831 | break; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5832 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5833 | } |
| 5834 | } while (!__states.empty()); |
| 5835 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5836 | return false; |
| 5837 | } |
| 5838 | |
| 5839 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5840 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5841 | bool |
| 5842 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5843 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5844 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5845 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5846 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5847 | deque<__state> __states; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5848 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5849 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5850 | __node* __st = __start_.get(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5851 | if (__st) |
| 5852 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5853 | __states.push_back(__state()); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5854 | __states.back().__do_ = 0; |
| 5855 | __states.back().__first_ = __first; |
| 5856 | __states.back().__current_ = __first; |
| 5857 | __states.back().__last_ = __last; |
| 5858 | __states.back().__loop_data_.resize(__loop_count()); |
| 5859 | __states.back().__node_ = __st; |
| 5860 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5861 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5862 | bool __matched = false; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5863 | int __counter = 0; |
| 5864 | int __length = __last - __first; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5865 | do |
| 5866 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5867 | ++__counter; |
| 5868 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5869 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5870 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5871 | __state& __s = __states.back(); |
| 5872 | if (__s.__node_) |
| 5873 | __s.__node_->__exec(__s); |
| 5874 | switch (__s.__do_) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5875 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5876 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5877 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5878 | __s.__current_ == __first) |
| 5879 | { |
| 5880 | __states.pop_back(); |
| 5881 | break; |
| 5882 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5883 | if ((__flags & regex_constants::__full_match) && |
| 5884 | __s.__current_ != __last) |
| 5885 | { |
| 5886 | __states.pop_back(); |
| 5887 | break; |
| 5888 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5889 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5890 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5891 | __matched = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5892 | if (__highest_j == _Np) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5893 | __states.clear(); |
| 5894 | else |
| 5895 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5896 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5897 | case __state::__consume_input: |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5898 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5899 | case __state::__accept_and_consume: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5900 | __states.push_front(_VSTD::move(__s)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5901 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5902 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5903 | case __state::__repeat: |
| 5904 | case __state::__accept_but_not_consume: |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5905 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5906 | case __state::__split: |
| 5907 | { |
| 5908 | __state __snext = __s; |
| 5909 | __s.__node_->__exec_split(true, __s); |
| 5910 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5911 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5912 | } |
| 5913 | break; |
| 5914 | case __state::__reject: |
| 5915 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5916 | break; |
| 5917 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5918 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5919 | break; |
| 5920 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5921 | } while (!__states.empty()); |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5922 | if (__matched) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5923 | { |
| 5924 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5925 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5926 | __m.__matches_[0].matched = true; |
| 5927 | return true; |
| 5928 | } |
| 5929 | } |
| 5930 | return false; |
| 5931 | } |
| 5932 | |
| 5933 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5934 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5935 | bool |
| 5936 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5937 | const _CharT* __first, const _CharT* __last, |
| 5938 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5939 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5940 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5941 | vector<__state> __states; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5942 | __state __best_state; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5943 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5944 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5945 | __node* __st = __start_.get(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5946 | if (__st) |
| 5947 | { |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5948 | sub_match<const _CharT*> __unmatched; |
| 5949 | __unmatched.first = __last; |
| 5950 | __unmatched.second = __last; |
| 5951 | __unmatched.matched = false; |
| 5952 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5953 | __states.push_back(__state()); |
| 5954 | __states.back().__do_ = 0; |
| 5955 | __states.back().__first_ = __first; |
| 5956 | __states.back().__current_ = __first; |
| 5957 | __states.back().__last_ = __last; |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5958 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5959 | __states.back().__loop_data_.resize(__loop_count()); |
| 5960 | __states.back().__node_ = __st; |
| 5961 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5962 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5963 | bool __matched = false; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5964 | int __counter = 0; |
| 5965 | int __length = __last - __first; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5966 | do |
| 5967 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5968 | ++__counter; |
| 5969 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5970 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5971 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5972 | __state& __s = __states.back(); |
| 5973 | if (__s.__node_) |
| 5974 | __s.__node_->__exec(__s); |
| 5975 | switch (__s.__do_) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5976 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5977 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5978 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5979 | __s.__current_ == __first) |
| 5980 | { |
| 5981 | __states.pop_back(); |
| 5982 | break; |
| 5983 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5984 | if ((__flags & regex_constants::__full_match) && |
| 5985 | __s.__current_ != __last) |
| 5986 | { |
| 5987 | __states.pop_back(); |
| 5988 | break; |
| 5989 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5990 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5991 | { |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5992 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5993 | __best_state = __s; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5994 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5995 | __matched = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5996 | if (__highest_j == _Np) |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5997 | __states.clear(); |
| 5998 | else |
| 5999 | __states.pop_back(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6000 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6001 | case __state::__accept_and_consume: |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6002 | case __state::__repeat: |
| 6003 | case __state::__accept_but_not_consume: |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6004 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6005 | case __state::__split: |
| 6006 | { |
| 6007 | __state __snext = __s; |
| 6008 | __s.__node_->__exec_split(true, __s); |
| 6009 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6010 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6011 | } |
| 6012 | break; |
| 6013 | case __state::__reject: |
| 6014 | __states.pop_back(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6015 | break; |
| 6016 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 6017 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6018 | break; |
| 6019 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6020 | } while (!__states.empty()); |
| 6021 | if (__matched) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6022 | { |
| 6023 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6024 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6025 | __m.__matches_[0].matched = true; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6026 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 6027 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6028 | return true; |
| 6029 | } |
| 6030 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6031 | return false; |
| 6032 | } |
| 6033 | |
| 6034 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6035 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6036 | bool |
| 6037 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6038 | const _CharT* __first, const _CharT* __last, |
| 6039 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6040 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6041 | { |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 6042 | if (__get_grammar(__flags_) == ECMAScript) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6043 | return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6044 | if (mark_count() == 0) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6045 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |
| 6046 | return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6047 | } |
| 6048 | |
| 6049 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6050 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6051 | bool |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6052 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6053 | const _CharT* __first, const _CharT* __last, |
| 6054 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6055 | regex_constants::match_flag_type __flags) const |
| 6056 | { |
Diogo Sampaio | 300ade7 | 2020-04-30 23:34:01 +0100 | [diff] [blame] | 6057 | if (__flags & regex_constants::match_prev_avail) |
| 6058 | __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow); |
| 6059 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6060 | __m.__init(1 + mark_count(), __first, __last, |
| 6061 | __flags & regex_constants::__no_update_pos); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6062 | if (__match_at_start(__first, __last, __m, __flags, |
Howard Hinnant | 38d14f7 | 2013-07-09 17:29:09 +0000 | [diff] [blame] | 6063 | !(__flags & regex_constants::__no_update_pos))) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6064 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6065 | __m.__prefix_.second = __m[0].first; |
| 6066 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 6067 | __m.__suffix_.first = __m[0].second; |
| 6068 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 6069 | return true; |
| 6070 | } |
Howard Hinnant | 22cf486 | 2010-07-29 01:15:27 +0000 | [diff] [blame] | 6071 | if (__first != __last && !(__flags & regex_constants::match_continuous)) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6072 | { |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 6073 | __flags |= regex_constants::match_prev_avail; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6074 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6075 | { |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 6076 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6077 | if (__match_at_start(__first, __last, __m, __flags, false)) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6078 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6079 | __m.__prefix_.second = __m[0].first; |
| 6080 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 6081 | __m.__suffix_.first = __m[0].second; |
| 6082 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 6083 | return true; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6084 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6085 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6086 | } |
| 6087 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6088 | __m.__matches_.clear(); |
| 6089 | return false; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6090 | } |
| 6091 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6092 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6093 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6094 | bool |
| 6095 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6096 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6097 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6098 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6099 | { |
Howard Hinnant | 1e5de64 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 6100 | int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0; |
| 6101 | basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6102 | match_results<const _CharT*> __mc; |
Howard Hinnant | 1e5de64 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 6103 | bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6104 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6105 | return __r; |
| 6106 | } |
| 6107 | |
Howard Hinnant | 4018c48 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 6108 | template <class _Iter, class _Allocator, class _CharT, class _Traits> |
| 6109 | inline _LIBCPP_INLINE_VISIBILITY |
| 6110 | bool |
| 6111 | regex_search(__wrap_iter<_Iter> __first, |
| 6112 | __wrap_iter<_Iter> __last, |
| 6113 | match_results<__wrap_iter<_Iter>, _Allocator>& __m, |
| 6114 | const basic_regex<_CharT, _Traits>& __e, |
| 6115 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6116 | { |
| 6117 | match_results<const _CharT*> __mc; |
| 6118 | bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags); |
| 6119 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
| 6120 | return __r; |
| 6121 | } |
| 6122 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6123 | template <class _Allocator, class _CharT, class _Traits> |
| 6124 | inline _LIBCPP_INLINE_VISIBILITY |
| 6125 | bool |
| 6126 | regex_search(const _CharT* __first, const _CharT* __last, |
| 6127 | match_results<const _CharT*, _Allocator>& __m, |
| 6128 | const basic_regex<_CharT, _Traits>& __e, |
| 6129 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6130 | { |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6131 | return __e.__search(__first, __last, __m, __flags); |
| 6132 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6133 | |
| 6134 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6135 | inline _LIBCPP_INLINE_VISIBILITY |
| 6136 | bool |
| 6137 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6138 | const basic_regex<_CharT, _Traits>& __e, |
| 6139 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6140 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6141 | basic_string<_CharT> __s(__first, __last); |
| 6142 | match_results<const _CharT*> __mc; |
| 6143 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 6144 | } |
| 6145 | |
| 6146 | template <class _CharT, class _Traits> |
| 6147 | inline _LIBCPP_INLINE_VISIBILITY |
| 6148 | bool |
| 6149 | regex_search(const _CharT* __first, const _CharT* __last, |
| 6150 | const basic_regex<_CharT, _Traits>& __e, |
| 6151 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6152 | { |
| 6153 | match_results<const _CharT*> __mc; |
| 6154 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | template <class _CharT, class _Allocator, class _Traits> |
| 6158 | inline _LIBCPP_INLINE_VISIBILITY |
| 6159 | bool |
| 6160 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6161 | const basic_regex<_CharT, _Traits>& __e, |
| 6162 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6163 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6164 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6165 | } |
| 6166 | |
| 6167 | template <class _CharT, class _Traits> |
| 6168 | inline _LIBCPP_INLINE_VISIBILITY |
| 6169 | bool |
| 6170 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6171 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6172 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6173 | match_results<const _CharT*> __m; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6174 | return _VSTD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6175 | } |
| 6176 | |
| 6177 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6178 | inline _LIBCPP_INLINE_VISIBILITY |
| 6179 | bool |
| 6180 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6181 | const basic_regex<_CharT, _Traits>& __e, |
| 6182 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6183 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6184 | match_results<const _CharT*> __mc; |
| 6185 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6186 | } |
| 6187 | |
| 6188 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6189 | inline _LIBCPP_INLINE_VISIBILITY |
| 6190 | bool |
| 6191 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6192 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6193 | const basic_regex<_CharT, _Traits>& __e, |
| 6194 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6195 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6196 | match_results<const _CharT*> __mc; |
| 6197 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6198 | __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6199 | return __r; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6200 | } |
| 6201 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6202 | #if _LIBCPP_STD_VER > 11 |
| 6203 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
| 6204 | bool |
| 6205 | regex_search(const basic_string<_Cp, _ST, _SA>&& __s, |
| 6206 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 6207 | const basic_regex<_Cp, _Tp>& __e, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6208 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6209 | #endif |
| 6210 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6211 | // regex_match |
| 6212 | |
| 6213 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 6214 | bool |
| 6215 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6216 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6217 | const basic_regex<_CharT, _Traits>& __e, |
| 6218 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6219 | { |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 6220 | bool __r = _VSTD::regex_search( |
| 6221 | __first, __last, __m, __e, |
| 6222 | __flags | regex_constants::match_continuous | |
| 6223 | regex_constants::__full_match); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6224 | if (__r) |
| 6225 | { |
| 6226 | __r = !__m.suffix().matched; |
| 6227 | if (!__r) |
| 6228 | __m.__matches_.clear(); |
| 6229 | } |
| 6230 | return __r; |
| 6231 | } |
| 6232 | |
| 6233 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6234 | inline _LIBCPP_INLINE_VISIBILITY |
| 6235 | bool |
| 6236 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6237 | const basic_regex<_CharT, _Traits>& __e, |
| 6238 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6239 | { |
| 6240 | match_results<_BidirectionalIterator> __m; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6241 | return _VSTD::regex_match(__first, __last, __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6242 | } |
| 6243 | |
| 6244 | template <class _CharT, class _Allocator, class _Traits> |
| 6245 | inline _LIBCPP_INLINE_VISIBILITY |
| 6246 | bool |
| 6247 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6248 | const basic_regex<_CharT, _Traits>& __e, |
| 6249 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6250 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6251 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6255 | inline _LIBCPP_INLINE_VISIBILITY |
| 6256 | bool |
| 6257 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6258 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6259 | const basic_regex<_CharT, _Traits>& __e, |
| 6260 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6261 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6262 | return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6263 | } |
| 6264 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6265 | #if _LIBCPP_STD_VER > 11 |
| 6266 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6267 | inline _LIBCPP_INLINE_VISIBILITY |
| 6268 | bool |
| 6269 | regex_match(const basic_string<_CharT, _ST, _SA>&& __s, |
| 6270 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6271 | const basic_regex<_CharT, _Traits>& __e, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6272 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6273 | #endif |
| 6274 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6275 | template <class _CharT, class _Traits> |
| 6276 | inline _LIBCPP_INLINE_VISIBILITY |
| 6277 | bool |
| 6278 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6279 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6280 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6281 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6285 | inline _LIBCPP_INLINE_VISIBILITY |
| 6286 | bool |
| 6287 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6288 | const basic_regex<_CharT, _Traits>& __e, |
| 6289 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6290 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6291 | return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6292 | } |
| 6293 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6294 | // regex_iterator |
| 6295 | |
| 6296 | template <class _BidirectionalIterator, |
| 6297 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6298 | class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6299 | class _LIBCPP_TEMPLATE_VIS regex_iterator; |
| 6300 | |
| 6301 | typedef regex_iterator<const char*> cregex_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6302 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6303 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6304 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6305 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6306 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6307 | |
| 6308 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6309 | class |
| 6310 | _LIBCPP_TEMPLATE_VIS |
| 6311 | _LIBCPP_PREFERRED_NAME(cregex_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6312 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6313 | _LIBCPP_PREFERRED_NAME(sregex_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6314 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6315 | regex_iterator |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6316 | { |
| 6317 | public: |
| 6318 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6319 | typedef match_results<_BidirectionalIterator> value_type; |
| 6320 | typedef ptrdiff_t difference_type; |
| 6321 | typedef const value_type* pointer; |
| 6322 | typedef const value_type& reference; |
| 6323 | typedef forward_iterator_tag iterator_category; |
| 6324 | |
| 6325 | private: |
| 6326 | _BidirectionalIterator __begin_; |
| 6327 | _BidirectionalIterator __end_; |
| 6328 | const regex_type* __pregex_; |
| 6329 | regex_constants::match_flag_type __flags_; |
| 6330 | value_type __match_; |
| 6331 | |
| 6332 | public: |
| 6333 | regex_iterator(); |
| 6334 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6335 | const regex_type& __re, |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6336 | regex_constants::match_flag_type __m |
| 6337 | = regex_constants::match_default); |
| 6338 | #if _LIBCPP_STD_VER > 11 |
| 6339 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6340 | const regex_type&& __re, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6341 | regex_constants::match_flag_type __m |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6342 | = regex_constants::match_default) = delete; |
| 6343 | #endif |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6344 | |
| 6345 | bool operator==(const regex_iterator& __x) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6346 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6347 | bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} |
| 6348 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6349 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6350 | reference operator*() const {return __match_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6351 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6352 | pointer operator->() const {return _VSTD::addressof(__match_);} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6353 | |
| 6354 | regex_iterator& operator++(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6355 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6356 | regex_iterator operator++(int) |
| 6357 | { |
| 6358 | regex_iterator __t(*this); |
| 6359 | ++(*this); |
| 6360 | return __t; |
| 6361 | } |
| 6362 | }; |
| 6363 | |
| 6364 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6365 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() |
| 6366 | : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() |
| 6367 | { |
| 6368 | } |
| 6369 | |
| 6370 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6371 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6372 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6373 | const regex_type& __re, regex_constants::match_flag_type __m) |
| 6374 | : __begin_(__a), |
| 6375 | __end_(__b), |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6376 | __pregex_(_VSTD::addressof(__re)), |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6377 | __flags_(__m) |
| 6378 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6379 | _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6380 | } |
| 6381 | |
| 6382 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6383 | bool |
| 6384 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6385 | operator==(const regex_iterator& __x) const |
| 6386 | { |
| 6387 | if (__match_.empty() && __x.__match_.empty()) |
| 6388 | return true; |
| 6389 | if (__match_.empty() || __x.__match_.empty()) |
| 6390 | return false; |
| 6391 | return __begin_ == __x.__begin_ && |
| 6392 | __end_ == __x.__end_ && |
| 6393 | __pregex_ == __x.__pregex_ && |
| 6394 | __flags_ == __x.__flags_ && |
| 6395 | __match_[0] == __x.__match_[0]; |
| 6396 | } |
| 6397 | |
| 6398 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6399 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6400 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6401 | { |
| 6402 | __flags_ |= regex_constants::__no_update_pos; |
| 6403 | _BidirectionalIterator __start = __match_[0].second; |
Marshall Clow | faa964d | 2017-07-05 16:37:19 +0000 | [diff] [blame] | 6404 | if (__match_[0].first == __match_[0].second) |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6405 | { |
| 6406 | if (__start == __end_) |
| 6407 | { |
| 6408 | __match_ = value_type(); |
| 6409 | return *this; |
| 6410 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6411 | else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6412 | __flags_ | regex_constants::match_not_null | |
| 6413 | regex_constants::match_continuous)) |
| 6414 | return *this; |
| 6415 | else |
| 6416 | ++__start; |
| 6417 | } |
| 6418 | __flags_ |= regex_constants::match_prev_avail; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6419 | if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6420 | __match_ = value_type(); |
| 6421 | return *this; |
| 6422 | } |
| 6423 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6424 | // regex_token_iterator |
| 6425 | |
| 6426 | template <class _BidirectionalIterator, |
| 6427 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6428 | class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6429 | class _LIBCPP_TEMPLATE_VIS regex_token_iterator; |
| 6430 | |
| 6431 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6432 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6433 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6434 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6435 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6436 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6437 | |
| 6438 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6439 | class |
| 6440 | _LIBCPP_TEMPLATE_VIS |
| 6441 | _LIBCPP_PREFERRED_NAME(cregex_token_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6442 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6443 | _LIBCPP_PREFERRED_NAME(sregex_token_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6444 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6445 | regex_token_iterator |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6446 | { |
| 6447 | public: |
| 6448 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6449 | typedef sub_match<_BidirectionalIterator> value_type; |
| 6450 | typedef ptrdiff_t difference_type; |
| 6451 | typedef const value_type* pointer; |
| 6452 | typedef const value_type& reference; |
| 6453 | typedef forward_iterator_tag iterator_category; |
| 6454 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6455 | private: |
| 6456 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; |
| 6457 | |
| 6458 | _Position __position_; |
| 6459 | const value_type* __result_; |
| 6460 | value_type __suffix_; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6461 | ptrdiff_t __n_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6462 | vector<int> __subs_; |
| 6463 | |
| 6464 | public: |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6465 | regex_token_iterator(); |
| 6466 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6467 | const regex_type& __re, int __submatch = 0, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6468 | regex_constants::match_flag_type __m = |
| 6469 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6470 | #if _LIBCPP_STD_VER > 11 |
| 6471 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6472 | const regex_type&& __re, int __submatch = 0, |
| 6473 | regex_constants::match_flag_type __m = |
| 6474 | regex_constants::match_default) = delete; |
| 6475 | #endif |
| 6476 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6477 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6478 | const regex_type& __re, const vector<int>& __submatches, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6479 | regex_constants::match_flag_type __m = |
| 6480 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6481 | #if _LIBCPP_STD_VER > 11 |
| 6482 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6483 | const regex_type&& __re, const vector<int>& __submatches, |
| 6484 | regex_constants::match_flag_type __m = |
| 6485 | regex_constants::match_default) = delete; |
| 6486 | #endif |
| 6487 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 6488 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6489 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6490 | const regex_type& __re, |
| 6491 | initializer_list<int> __submatches, |
| 6492 | regex_constants::match_flag_type __m = |
| 6493 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6494 | |
| 6495 | #if _LIBCPP_STD_VER > 11 |
| 6496 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6497 | const regex_type&& __re, |
| 6498 | initializer_list<int> __submatches, |
| 6499 | regex_constants::match_flag_type __m = |
| 6500 | regex_constants::match_default) = delete; |
| 6501 | #endif |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6502 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6503 | template <size_t _Np> |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6504 | regex_token_iterator(_BidirectionalIterator __a, |
| 6505 | _BidirectionalIterator __b, |
| 6506 | const regex_type& __re, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6507 | const int (&__submatches)[_Np], |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6508 | regex_constants::match_flag_type __m = |
| 6509 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6510 | #if _LIBCPP_STD_VER > 11 |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 6511 | template <size_t _Np> |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6512 | regex_token_iterator(_BidirectionalIterator __a, |
| 6513 | _BidirectionalIterator __b, |
| 6514 | const regex_type&& __re, |
| 6515 | const int (&__submatches)[_Np], |
| 6516 | regex_constants::match_flag_type __m = |
| 6517 | regex_constants::match_default) = delete; |
| 6518 | #endif |
| 6519 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6520 | regex_token_iterator(const regex_token_iterator&); |
| 6521 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 6522 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6523 | bool operator==(const regex_token_iterator& __x) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6524 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6525 | bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6526 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6527 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6528 | const value_type& operator*() const {return *__result_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6529 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6530 | const value_type* operator->() const {return __result_;} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6531 | |
| 6532 | regex_token_iterator& operator++(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6533 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6534 | regex_token_iterator operator++(int) |
| 6535 | { |
| 6536 | regex_token_iterator __t(*this); |
| 6537 | ++(*this); |
| 6538 | return __t; |
| 6539 | } |
| 6540 | |
| 6541 | private: |
| 6542 | void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6543 | void __establish_result () { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6544 | if (__subs_[__n_] == -1) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6545 | __result_ = &__position_->prefix(); |
| 6546 | else |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6547 | __result_ = &(*__position_)[__subs_[__n_]]; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6548 | } |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6549 | }; |
| 6550 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6551 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6552 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6553 | regex_token_iterator() |
| 6554 | : __result_(nullptr), |
| 6555 | __suffix_(), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6556 | __n_(0) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6557 | { |
| 6558 | } |
| 6559 | |
| 6560 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6561 | void |
| 6562 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6563 | __init(_BidirectionalIterator __a, _BidirectionalIterator __b) |
| 6564 | { |
| 6565 | if (__position_ != _Position()) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6566 | __establish_result (); |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6567 | else if (__subs_[__n_] == -1) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6568 | { |
| 6569 | __suffix_.matched = true; |
| 6570 | __suffix_.first = __a; |
| 6571 | __suffix_.second = __b; |
| 6572 | __result_ = &__suffix_; |
| 6573 | } |
| 6574 | else |
| 6575 | __result_ = nullptr; |
| 6576 | } |
| 6577 | |
| 6578 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6579 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6580 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6581 | const regex_type& __re, int __submatch, |
| 6582 | regex_constants::match_flag_type __m) |
| 6583 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6584 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6585 | __subs_(1, __submatch) |
| 6586 | { |
| 6587 | __init(__a, __b); |
| 6588 | } |
| 6589 | |
| 6590 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6591 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6592 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6593 | const regex_type& __re, const vector<int>& __submatches, |
| 6594 | regex_constants::match_flag_type __m) |
| 6595 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6596 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6597 | __subs_(__submatches) |
| 6598 | { |
| 6599 | __init(__a, __b); |
| 6600 | } |
| 6601 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 6602 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6603 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6604 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6605 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6606 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6607 | const regex_type& __re, |
| 6608 | initializer_list<int> __submatches, |
| 6609 | regex_constants::match_flag_type __m) |
| 6610 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6611 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6612 | __subs_(__submatches) |
| 6613 | { |
| 6614 | __init(__a, __b); |
| 6615 | } |
| 6616 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6617 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6618 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6619 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6620 | template <size_t _Np> |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6621 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6622 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6623 | const regex_type& __re, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6624 | const int (&__submatches)[_Np], |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6625 | regex_constants::match_flag_type __m) |
| 6626 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6627 | __n_(0), |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6628 | __subs_(begin(__submatches), end(__submatches)) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6629 | { |
| 6630 | __init(__a, __b); |
| 6631 | } |
| 6632 | |
| 6633 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6634 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6635 | regex_token_iterator(const regex_token_iterator& __x) |
| 6636 | : __position_(__x.__position_), |
| 6637 | __result_(__x.__result_), |
| 6638 | __suffix_(__x.__suffix_), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6639 | __n_(__x.__n_), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6640 | __subs_(__x.__subs_) |
| 6641 | { |
| 6642 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 20756ac | 2014-01-13 17:47:08 +0000 | [diff] [blame] | 6643 | __result_ = &__suffix_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6644 | else if ( __result_ != nullptr ) |
| 6645 | __establish_result (); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6646 | } |
| 6647 | |
| 6648 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6649 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6650 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6651 | operator=(const regex_token_iterator& __x) |
| 6652 | { |
| 6653 | if (this != &__x) |
| 6654 | { |
| 6655 | __position_ = __x.__position_; |
| 6656 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6657 | __result_ = &__suffix_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6658 | else |
| 6659 | __result_ = __x.__result_; |
| 6660 | __suffix_ = __x.__suffix_; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6661 | __n_ = __x.__n_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6662 | __subs_ = __x.__subs_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6663 | |
| 6664 | if ( __result_ != nullptr && __result_ != &__suffix_ ) |
| 6665 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6666 | } |
| 6667 | return *this; |
| 6668 | } |
| 6669 | |
| 6670 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6671 | bool |
| 6672 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6673 | operator==(const regex_token_iterator& __x) const |
| 6674 | { |
| 6675 | if (__result_ == nullptr && __x.__result_ == nullptr) |
| 6676 | return true; |
| 6677 | if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && |
| 6678 | __suffix_ == __x.__suffix_) |
| 6679 | return true; |
| 6680 | if (__result_ == nullptr || __x.__result_ == nullptr) |
| 6681 | return false; |
| 6682 | if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) |
| 6683 | return false; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6684 | return __position_ == __x.__position_ && __n_ == __x.__n_ && |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6685 | __subs_ == __x.__subs_; |
| 6686 | } |
| 6687 | |
| 6688 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6689 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6690 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6691 | { |
| 6692 | _Position __prev = __position_; |
| 6693 | if (__result_ == &__suffix_) |
| 6694 | __result_ = nullptr; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6695 | else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6696 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6697 | ++__n_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6698 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6699 | } |
| 6700 | else |
| 6701 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6702 | __n_ = 0; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6703 | ++__position_; |
| 6704 | if (__position_ != _Position()) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6705 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6706 | else |
| 6707 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6708 | if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6709 | && __prev->suffix().length() != 0) |
| 6710 | { |
| 6711 | __suffix_.matched = true; |
| 6712 | __suffix_.first = __prev->suffix().first; |
| 6713 | __suffix_.second = __prev->suffix().second; |
| 6714 | __result_ = &__suffix_; |
| 6715 | } |
| 6716 | else |
| 6717 | __result_ = nullptr; |
| 6718 | } |
| 6719 | } |
| 6720 | return *this; |
| 6721 | } |
| 6722 | |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6723 | // regex_replace |
| 6724 | |
| 6725 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6726 | class _Traits, class _CharT> |
| 6727 | _OutputIterator |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6728 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6729 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6730 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6731 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6732 | { |
| 6733 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; |
| 6734 | _Iter __i(__first, __last, __e, __flags); |
| 6735 | _Iter __eof; |
| 6736 | if (__i == __eof) |
| 6737 | { |
| 6738 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6739 | __output_iter = _VSTD::copy(__first, __last, __output_iter); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6740 | } |
| 6741 | else |
| 6742 | { |
| 6743 | sub_match<_BidirectionalIterator> __lm; |
| 6744 | for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) |
| 6745 | { |
| 6746 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6747 | __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter); |
| 6748 | __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6749 | __lm = __i->suffix(); |
| 6750 | if (__flags & regex_constants::format_first_only) |
| 6751 | break; |
| 6752 | } |
| 6753 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6754 | __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6755 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6756 | return __output_iter; |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6757 | } |
| 6758 | |
| 6759 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6760 | class _Traits, class _CharT, class _ST, class _SA> |
| 6761 | inline _LIBCPP_INLINE_VISIBILITY |
| 6762 | _OutputIterator |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6763 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6764 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6765 | const basic_regex<_CharT, _Traits>& __e, |
| 6766 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6767 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6768 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6769 | return _VSTD::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6770 | } |
| 6771 | |
| 6772 | template <class _Traits, class _CharT, class _ST, class _SA, class _FST, |
| 6773 | class _FSA> |
| 6774 | inline _LIBCPP_INLINE_VISIBILITY |
| 6775 | basic_string<_CharT, _ST, _SA> |
| 6776 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6777 | const basic_regex<_CharT, _Traits>& __e, |
| 6778 | const basic_string<_CharT, _FST, _FSA>& __fmt, |
| 6779 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6780 | { |
| 6781 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6782 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6783 | __fmt.c_str(), __flags); |
| 6784 | return __r; |
| 6785 | } |
| 6786 | |
| 6787 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6788 | inline _LIBCPP_INLINE_VISIBILITY |
| 6789 | basic_string<_CharT, _ST, _SA> |
| 6790 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6791 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6792 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6793 | { |
| 6794 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6795 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6796 | __fmt, __flags); |
| 6797 | return __r; |
| 6798 | } |
| 6799 | |
| 6800 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6801 | inline _LIBCPP_INLINE_VISIBILITY |
| 6802 | basic_string<_CharT> |
| 6803 | regex_replace(const _CharT* __s, |
| 6804 | const basic_regex<_CharT, _Traits>& __e, |
| 6805 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6806 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6807 | { |
| 6808 | basic_string<_CharT> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6809 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6810 | __s + char_traits<_CharT>::length(__s), __e, |
| 6811 | __fmt.c_str(), __flags); |
| 6812 | return __r; |
| 6813 | } |
| 6814 | |
| 6815 | template <class _Traits, class _CharT> |
| 6816 | inline _LIBCPP_INLINE_VISIBILITY |
| 6817 | basic_string<_CharT> |
| 6818 | regex_replace(const _CharT* __s, |
| 6819 | const basic_regex<_CharT, _Traits>& __e, |
| 6820 | const _CharT* __fmt, |
| 6821 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6822 | { |
| 6823 | basic_string<_CharT> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6824 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6825 | __s + char_traits<_CharT>::length(__s), __e, |
| 6826 | __fmt, __flags); |
| 6827 | return __r; |
| 6828 | } |
| 6829 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 6830 | _LIBCPP_END_NAMESPACE_STD |
| 6831 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 6832 | _LIBCPP_POP_MACROS |
| 6833 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6834 | #endif // _LIBCPP_REGEX |