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> |
Nikolas Klauser | ee2dbc3 | 2022-04-17 16:01:38 +0200 | [diff] [blame] | 766 | #include <__algorithm/search.h> |
Louis Dionne | b4fce35 | 2022-03-25 12:55:36 -0400 | [diff] [blame] | 767 | #include <__assert> // all public C++ headers provide the assertion handler |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 768 | #include <__config> |
Nikolas Klauser | fb1b067 | 2022-06-10 19:53:10 +0200 | [diff] [blame] | 769 | #include <__iterator/back_insert_iterator.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 770 | #include <__iterator/wrap_iter.h> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 771 | #include <__locale> |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 772 | #include <__memory_resource/polymorphic_allocator.h> |
Nikolas Klauser | 8fccd62 | 2022-03-05 19:17:07 +0100 | [diff] [blame] | 773 | #include <__utility/move.h> |
Nikolas Klauser | 0b5df93 | 2022-09-05 00:01:15 +0200 | [diff] [blame] | 774 | #include <__utility/pair.h> |
Nikolas Klauser | 8fccd62 | 2022-03-05 19:17:07 +0100 | [diff] [blame] | 775 | #include <__utility/swap.h> |
Nikolas Klauser | d858e75 | 2022-09-22 21:53:13 +0200 | [diff] [blame] | 776 | #include <cstring> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 777 | #include <deque> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 778 | #include <stdexcept> |
| 779 | #include <string> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 780 | #include <vector> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 781 | #include <version> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 782 | |
Nikolas Klauser | a0e0edb | 2022-06-16 22:43:46 +0200 | [diff] [blame] | 783 | // standard-mandated includes |
| 784 | |
| 785 | // [iterator.range] |
| 786 | #include <__iterator/access.h> |
| 787 | #include <__iterator/data.h> |
| 788 | #include <__iterator/empty.h> |
| 789 | #include <__iterator/reverse_access.h> |
| 790 | #include <__iterator/size.h> |
| 791 | |
| 792 | // [re.syn] |
| 793 | #include <compare> |
| 794 | #include <initializer_list> |
| 795 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 796 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 797 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 798 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 799 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 800 | _LIBCPP_PUSH_MACROS |
| 801 | #include <__undef_macros> |
| 802 | |
| 803 | |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 804 | #define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096 |
| 805 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 806 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 807 | |
| 808 | namespace regex_constants |
| 809 | { |
| 810 | |
| 811 | // syntax_option_type |
| 812 | |
| 813 | enum syntax_option_type |
| 814 | { |
| 815 | icase = 1 << 0, |
| 816 | nosubs = 1 << 1, |
| 817 | optimize = 1 << 2, |
| 818 | collate = 1 << 3, |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 819 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 820 | ECMAScript = 1 << 9, |
| 821 | #else |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 822 | ECMAScript = 0, |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 823 | #endif |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 824 | basic = 1 << 4, |
| 825 | extended = 1 << 5, |
| 826 | awk = 1 << 6, |
| 827 | grep = 1 << 7, |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 828 | egrep = 1 << 8, |
| 829 | // 1 << 9 may be used by ECMAScript |
| 830 | multiline = 1 << 10 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 831 | }; |
| 832 | |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 833 | _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 834 | syntax_option_type __get_grammar(syntax_option_type __g) |
| 835 | { |
| 836 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 837 | return static_cast<syntax_option_type>(__g & 0x3F0); |
| 838 | #else |
| 839 | return static_cast<syntax_option_type>(__g & 0x1F0); |
| 840 | #endif |
| 841 | } |
| 842 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 843 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 844 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 845 | syntax_option_type |
| 846 | operator~(syntax_option_type __x) |
| 847 | { |
Marshall Clow | 924cffa | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 848 | return syntax_option_type(~int(__x) & 0x1FF); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 851 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 852 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 853 | syntax_option_type |
| 854 | operator&(syntax_option_type __x, syntax_option_type __y) |
| 855 | { |
| 856 | return syntax_option_type(int(__x) & int(__y)); |
| 857 | } |
| 858 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 859 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 860 | _LIBCPP_CONSTEXPR |
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 | return syntax_option_type(int(__x) | int(__y)); |
| 865 | } |
| 866 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 867 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 868 | _LIBCPP_CONSTEXPR |
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 | return syntax_option_type(int(__x) ^ int(__y)); |
| 873 | } |
| 874 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 875 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 876 | syntax_option_type& |
| 877 | operator&=(syntax_option_type& __x, syntax_option_type __y) |
| 878 | { |
| 879 | __x = __x & __y; |
| 880 | return __x; |
| 881 | } |
| 882 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 883 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 884 | syntax_option_type& |
| 885 | operator|=(syntax_option_type& __x, syntax_option_type __y) |
| 886 | { |
| 887 | __x = __x | __y; |
| 888 | return __x; |
| 889 | } |
| 890 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 891 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 892 | syntax_option_type& |
| 893 | operator^=(syntax_option_type& __x, syntax_option_type __y) |
| 894 | { |
| 895 | __x = __x ^ __y; |
| 896 | return __x; |
| 897 | } |
| 898 | |
| 899 | // match_flag_type |
| 900 | |
| 901 | enum match_flag_type |
| 902 | { |
| 903 | match_default = 0, |
| 904 | match_not_bol = 1 << 0, |
| 905 | match_not_eol = 1 << 1, |
| 906 | match_not_bow = 1 << 2, |
| 907 | match_not_eow = 1 << 3, |
| 908 | match_any = 1 << 4, |
| 909 | match_not_null = 1 << 5, |
| 910 | match_continuous = 1 << 6, |
| 911 | match_prev_avail = 1 << 7, |
| 912 | format_default = 0, |
| 913 | format_sed = 1 << 8, |
| 914 | format_no_copy = 1 << 9, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 915 | format_first_only = 1 << 10, |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 916 | __no_update_pos = 1 << 11, |
| 917 | __full_match = 1 << 12 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 918 | }; |
| 919 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 920 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 921 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 922 | match_flag_type |
| 923 | operator~(match_flag_type __x) |
| 924 | { |
Marshall Clow | 924cffa | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 925 | return match_flag_type(~int(__x) & 0x0FFF); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 928 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 929 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 930 | match_flag_type |
| 931 | operator&(match_flag_type __x, match_flag_type __y) |
| 932 | { |
| 933 | return match_flag_type(int(__x) & int(__y)); |
| 934 | } |
| 935 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 936 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 937 | _LIBCPP_CONSTEXPR |
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 | return match_flag_type(int(__x) | int(__y)); |
| 942 | } |
| 943 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 944 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 945 | _LIBCPP_CONSTEXPR |
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 | return match_flag_type(int(__x) ^ int(__y)); |
| 950 | } |
| 951 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 952 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 953 | match_flag_type& |
| 954 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 955 | { |
| 956 | __x = __x & __y; |
| 957 | return __x; |
| 958 | } |
| 959 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 960 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 961 | match_flag_type& |
| 962 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 963 | { |
| 964 | __x = __x | __y; |
| 965 | return __x; |
| 966 | } |
| 967 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 968 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 969 | match_flag_type& |
| 970 | operator^=(match_flag_type& __x, match_flag_type __y) |
| 971 | { |
| 972 | __x = __x ^ __y; |
| 973 | return __x; |
| 974 | } |
| 975 | |
| 976 | enum error_type |
| 977 | { |
| 978 | error_collate = 1, |
| 979 | error_ctype, |
| 980 | error_escape, |
| 981 | error_backref, |
| 982 | error_brack, |
| 983 | error_paren, |
| 984 | error_brace, |
| 985 | error_badbrace, |
| 986 | error_range, |
| 987 | error_space, |
| 988 | error_badrepeat, |
| 989 | error_complexity, |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 990 | error_stack, |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 991 | __re_err_grammar, |
| 992 | __re_err_empty, |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 993 | __re_err_unknown, |
| 994 | __re_err_parse |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 995 | }; |
| 996 | |
Nikolas Klauser | d26407a | 2021-12-02 14:12:51 +0100 | [diff] [blame] | 997 | } // namespace regex_constants |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 998 | |
| 999 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 1000 | : public runtime_error |
| 1001 | { |
| 1002 | regex_constants::error_type __code_; |
| 1003 | public: |
| 1004 | explicit regex_error(regex_constants::error_type __ecode); |
Dimitry Andric | 47269ce | 2020-03-13 19:36:26 +0100 | [diff] [blame] | 1005 | regex_error(const regex_error&) _NOEXCEPT = default; |
Nikolas Klauser | aa3a6cd | 2022-08-24 02:14:29 +0200 | [diff] [blame] | 1006 | ~regex_error() _NOEXCEPT override; |
| 1007 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1008 | regex_constants::error_type code() const {return __code_;} |
| 1009 | }; |
| 1010 | |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 1011 | template <regex_constants::error_type _Ev> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1012 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 1013 | void __throw_regex_error() |
| 1014 | { |
| 1015 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Marshall Clow | 8bf61bb | 2015-08-17 21:14:16 +0000 | [diff] [blame] | 1016 | throw regex_error(_Ev); |
| 1017 | #else |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 1018 | _VSTD::abort(); |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 1019 | #endif |
| 1020 | } |
| 1021 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1022 | template <class _CharT> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1023 | struct _LIBCPP_TEMPLATE_VIS regex_traits |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1024 | { |
| 1025 | public: |
| 1026 | typedef _CharT char_type; |
| 1027 | typedef basic_string<char_type> string_type; |
| 1028 | typedef locale locale_type; |
Alex Richardson | f7e00ca | 2022-06-20 15:44:57 +0100 | [diff] [blame^] | 1029 | #if defined(__BIONIC__) || defined(_NEWLIB_VERSION) |
Dan Albert | 70ee07e | 2020-04-06 13:34:27 -0700 | [diff] [blame] | 1030 | // Originally bionic's ctype_base used its own ctype masks because the |
| 1031 | // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask |
| 1032 | // was only 8 bits wide and already saturated, so it used a wider type here |
| 1033 | // to make room for __regex_word (then a part of this class rather than |
| 1034 | // ctype_base). Bionic has since moved to the builtin ctype_base |
| 1035 | // implementation, but this was not updated to match. Since then Android has |
| 1036 | // needed to maintain a stable libc++ ABI, and this can't be changed without |
| 1037 | // an ABI break. |
Alex Richardson | f7e00ca | 2022-06-20 15:44:57 +0100 | [diff] [blame^] | 1038 | // We also need this workaround for newlib since _NEWLIB_VERSION is not |
| 1039 | // defined yet inside __config, so we can't set the |
| 1040 | // _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE macro. Additionally, newlib is |
| 1041 | // often used for space constrained environments, so it makes sense not to |
| 1042 | // duplicate the ctype table. |
Dan Albert | 70ee07e | 2020-04-06 13:34:27 -0700 | [diff] [blame] | 1043 | typedef uint16_t char_class_type; |
| 1044 | #else |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1045 | typedef ctype_base::mask char_class_type; |
Dan Albert | 70ee07e | 2020-04-06 13:34:27 -0700 | [diff] [blame] | 1046 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1047 | |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 1048 | static const char_class_type __regex_word = ctype_base::__regex_word; |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1049 | private: |
| 1050 | locale __loc_; |
| 1051 | const ctype<char_type>* __ct_; |
| 1052 | const collate<char_type>* __col_; |
| 1053 | |
| 1054 | public: |
| 1055 | regex_traits(); |
| 1056 | |
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 | static size_t length(const char_type* __p) |
| 1059 | {return char_traits<char_type>::length(__p);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1060 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1061 | char_type translate(char_type __c) const {return __c;} |
| 1062 | char_type translate_nocase(char_type __c) const; |
| 1063 | template <class _ForwardIterator> |
| 1064 | string_type |
| 1065 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 1066 | template <class _ForwardIterator> |
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 | string_type |
| 1069 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 1070 | {return __transform_primary(__f, __l, char_type());} |
| 1071 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1072 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1073 | string_type |
| 1074 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 1075 | {return __lookup_collatename(__f, __l, char_type());} |
| 1076 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1077 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1078 | char_class_type |
| 1079 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1080 | bool __icase = false) const |
| 1081 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 1082 | bool isctype(char_type __c, char_class_type __m) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1083 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1084 | int value(char_type __ch, int __radix) const |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1085 | {return __regex_traits_value(__ch, __radix);} |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1086 | locale_type imbue(locale_type __l); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1087 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1088 | locale_type getloc()const {return __loc_;} |
| 1089 | |
| 1090 | private: |
| 1091 | void __init(); |
| 1092 | |
| 1093 | template <class _ForwardIterator> |
| 1094 | string_type |
| 1095 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1096 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1097 | template <class _ForwardIterator> |
| 1098 | string_type |
| 1099 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1100 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1101 | template <class _ForwardIterator> |
| 1102 | string_type |
| 1103 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1104 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1105 | template <class _ForwardIterator> |
| 1106 | string_type |
| 1107 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1108 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1109 | template <class _ForwardIterator> |
| 1110 | char_class_type |
| 1111 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1112 | bool __icase, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1113 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1114 | template <class _ForwardIterator> |
| 1115 | char_class_type |
| 1116 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1117 | bool __icase, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1118 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1119 | |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1120 | static int __regex_traits_value(unsigned char __ch, int __radix); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1121 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1122 | int __regex_traits_value(char __ch, int __radix) const |
| 1123 | {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);} |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1124 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1125 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1126 | int __regex_traits_value(wchar_t __ch, int __radix) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1127 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1128 | }; |
| 1129 | |
| 1130 | template <class _CharT> |
Howard Hinnant | 592cb61 | 2013-03-07 19:38:08 +0000 | [diff] [blame] | 1131 | const typename regex_traits<_CharT>::char_class_type |
| 1132 | regex_traits<_CharT>::__regex_word; |
| 1133 | |
| 1134 | template <class _CharT> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1135 | regex_traits<_CharT>::regex_traits() |
| 1136 | { |
| 1137 | __init(); |
| 1138 | } |
| 1139 | |
| 1140 | template <class _CharT> |
| 1141 | typename regex_traits<_CharT>::char_type |
| 1142 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1143 | { |
| 1144 | return __ct_->tolower(__c); |
| 1145 | } |
| 1146 | |
| 1147 | template <class _CharT> |
| 1148 | template <class _ForwardIterator> |
| 1149 | typename regex_traits<_CharT>::string_type |
| 1150 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1151 | { |
| 1152 | string_type __s(__f, __l); |
| 1153 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1154 | } |
| 1155 | |
| 1156 | template <class _CharT> |
| 1157 | void |
| 1158 | regex_traits<_CharT>::__init() |
| 1159 | { |
| 1160 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1161 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1162 | } |
| 1163 | |
| 1164 | template <class _CharT> |
| 1165 | typename regex_traits<_CharT>::locale_type |
| 1166 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1167 | { |
| 1168 | locale __r = __loc_; |
| 1169 | __loc_ = __l; |
| 1170 | __init(); |
| 1171 | return __r; |
| 1172 | } |
| 1173 | |
| 1174 | // transform_primary is very FreeBSD-specific |
| 1175 | |
| 1176 | template <class _CharT> |
| 1177 | template <class _ForwardIterator> |
| 1178 | typename regex_traits<_CharT>::string_type |
| 1179 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1180 | _ForwardIterator __l, char) const |
| 1181 | { |
| 1182 | const string_type __s(__f, __l); |
| 1183 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1184 | switch (__d.size()) |
| 1185 | { |
| 1186 | case 1: |
| 1187 | break; |
| 1188 | case 12: |
| 1189 | __d[11] = __d[3]; |
| 1190 | break; |
| 1191 | default: |
| 1192 | __d.clear(); |
| 1193 | break; |
| 1194 | } |
| 1195 | return __d; |
| 1196 | } |
| 1197 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1198 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1199 | template <class _CharT> |
| 1200 | template <class _ForwardIterator> |
| 1201 | typename regex_traits<_CharT>::string_type |
| 1202 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1203 | _ForwardIterator __l, wchar_t) const |
| 1204 | { |
| 1205 | const string_type __s(__f, __l); |
| 1206 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1207 | switch (__d.size()) |
| 1208 | { |
| 1209 | case 1: |
| 1210 | break; |
| 1211 | case 3: |
| 1212 | __d[2] = __d[0]; |
| 1213 | break; |
| 1214 | default: |
| 1215 | __d.clear(); |
| 1216 | break; |
| 1217 | } |
| 1218 | return __d; |
| 1219 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1220 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1221 | |
| 1222 | // lookup_collatename is very FreeBSD-specific |
| 1223 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1224 | _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1225 | |
| 1226 | template <class _CharT> |
| 1227 | template <class _ForwardIterator> |
| 1228 | typename regex_traits<_CharT>::string_type |
| 1229 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1230 | _ForwardIterator __l, char) const |
| 1231 | { |
| 1232 | string_type __s(__f, __l); |
| 1233 | string_type __r; |
| 1234 | if (!__s.empty()) |
| 1235 | { |
| 1236 | __r = __get_collation_name(__s.c_str()); |
| 1237 | if (__r.empty() && __s.size() <= 2) |
| 1238 | { |
| 1239 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1240 | if (__r.size() == 1 || __r.size() == 12) |
| 1241 | __r = __s; |
| 1242 | else |
| 1243 | __r.clear(); |
| 1244 | } |
| 1245 | } |
| 1246 | return __r; |
| 1247 | } |
| 1248 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1249 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1250 | template <class _CharT> |
| 1251 | template <class _ForwardIterator> |
| 1252 | typename regex_traits<_CharT>::string_type |
| 1253 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1254 | _ForwardIterator __l, wchar_t) const |
| 1255 | { |
| 1256 | string_type __s(__f, __l); |
| 1257 | string __n; |
| 1258 | __n.reserve(__s.size()); |
| 1259 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1260 | __i != __e; ++__i) |
| 1261 | { |
| 1262 | if (static_cast<unsigned>(*__i) >= 127) |
| 1263 | return string_type(); |
| 1264 | __n.push_back(char(*__i)); |
| 1265 | } |
| 1266 | string_type __r; |
| 1267 | if (!__s.empty()) |
| 1268 | { |
| 1269 | __n = __get_collation_name(__n.c_str()); |
| 1270 | if (!__n.empty()) |
| 1271 | __r.assign(__n.begin(), __n.end()); |
| 1272 | else if (__s.size() <= 2) |
| 1273 | { |
| 1274 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1275 | if (__r.size() == 1 || __r.size() == 3) |
| 1276 | __r = __s; |
| 1277 | else |
| 1278 | __r.clear(); |
| 1279 | } |
| 1280 | } |
| 1281 | return __r; |
| 1282 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1283 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1284 | |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1285 | // lookup_classname |
| 1286 | |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 1287 | regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS |
| 1288 | __get_classname(const char* __s, bool __icase); |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1289 | |
| 1290 | template <class _CharT> |
| 1291 | template <class _ForwardIterator> |
| 1292 | typename regex_traits<_CharT>::char_class_type |
| 1293 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1294 | _ForwardIterator __l, |
| 1295 | bool __icase, char) const |
| 1296 | { |
| 1297 | string_type __s(__f, __l); |
| 1298 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1299 | return __get_classname(__s.c_str(), __icase); |
| 1300 | } |
| 1301 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1302 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1303 | template <class _CharT> |
| 1304 | template <class _ForwardIterator> |
| 1305 | typename regex_traits<_CharT>::char_class_type |
| 1306 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1307 | _ForwardIterator __l, |
| 1308 | bool __icase, wchar_t) const |
| 1309 | { |
| 1310 | string_type __s(__f, __l); |
| 1311 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1312 | string __n; |
| 1313 | __n.reserve(__s.size()); |
| 1314 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1315 | __i != __e; ++__i) |
| 1316 | { |
| 1317 | if (static_cast<unsigned>(*__i) >= 127) |
| 1318 | return char_class_type(); |
| 1319 | __n.push_back(char(*__i)); |
| 1320 | } |
| 1321 | return __get_classname(__n.c_str(), __icase); |
| 1322 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1323 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1324 | |
| 1325 | template <class _CharT> |
| 1326 | bool |
| 1327 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1328 | { |
| 1329 | if (__ct_->is(__m, __c)) |
| 1330 | return true; |
| 1331 | return (__c == '_' && (__m & __regex_word)); |
| 1332 | } |
| 1333 | |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1334 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1335 | bool __is_07(unsigned char __c) |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1336 | { |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1337 | return (__c & 0xF8u) == |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1338 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1339 | 0xF0; |
| 1340 | #else |
| 1341 | 0x30; |
| 1342 | #endif |
| 1343 | } |
| 1344 | |
| 1345 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1346 | bool __is_89(unsigned char __c) |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1347 | { |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1348 | return (__c & 0xFEu) == |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1349 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1350 | 0xF8; |
| 1351 | #else |
| 1352 | 0x38; |
| 1353 | #endif |
| 1354 | } |
| 1355 | |
| 1356 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1357 | unsigned char __to_lower(unsigned char __c) |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1358 | { |
| 1359 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
Muiez Ahmed | 42e738f | 2022-08-30 14:18:44 -0400 | [diff] [blame] | 1360 | return __c & 0xBF; |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1361 | #else |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1362 | return __c | 0x20; |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1363 | #endif |
| 1364 | } |
| 1365 | |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1366 | template <class _CharT> |
| 1367 | int |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1368 | regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1369 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1370 | if (__is_07(__ch)) // '0' <= __ch && __ch <= '7' |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1371 | return __ch - '0'; |
| 1372 | if (__radix != 8) |
| 1373 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1374 | if (__is_89(__ch)) // '8' <= __ch && __ch <= '9' |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1375 | return __ch - '0'; |
| 1376 | if (__radix == 16) |
| 1377 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1378 | __ch = __to_lower(__ch); // tolower |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1379 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1380 | return __ch - ('a' - 10); |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1381 | } |
| 1382 | } |
| 1383 | return -1; |
| 1384 | } |
| 1385 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1386 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1387 | template <class _CharT> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1388 | inline |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1389 | int |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1390 | regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1391 | { |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1392 | 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] | 1393 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1394 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1395 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1396 | template <class _CharT> class __node; |
| 1397 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1398 | template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1399 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1400 | template <class _BidirectionalIterator, |
| 1401 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1402 | class _LIBCPP_TEMPLATE_VIS match_results; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1403 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1404 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1405 | struct __state |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1406 | { |
| 1407 | enum |
| 1408 | { |
| 1409 | __end_state = -1000, |
| 1410 | __consume_input, // -999 |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1411 | __begin_marked_expr, // -998 |
| 1412 | __end_marked_expr, // -997 |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1413 | __pop_state, // -996 |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1414 | __accept_and_consume, // -995 |
| 1415 | __accept_but_not_consume, // -994 |
| 1416 | __reject, // -993 |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1417 | __split, |
| 1418 | __repeat |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1419 | }; |
| 1420 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1421 | int __do_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1422 | const _CharT* __first_; |
| 1423 | const _CharT* __current_; |
| 1424 | const _CharT* __last_; |
| 1425 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1426 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1427 | const __node<_CharT>* __node_; |
| 1428 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1429 | bool __at_first_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1430 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1431 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1432 | __state() |
| 1433 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1434 | __node_(nullptr), __flags_() {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1435 | }; |
| 1436 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1437 | // __node |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1438 | |
| 1439 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1440 | class __node |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1441 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1442 | __node(const __node&); |
| 1443 | __node& operator=(const __node&); |
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 | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1448 | __node() {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1449 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1450 | virtual ~__node() {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1451 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1452 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 1453 | virtual void __exec(__state&) const {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1454 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 1455 | virtual void __exec_split(bool, __state&) const {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1456 | }; |
| 1457 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1458 | // __end_state |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1459 | |
| 1460 | template <class _CharT> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1461 | class __end_state |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1462 | : public __node<_CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1463 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1464 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1465 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1466 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1467 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1468 | __end_state() {} |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1469 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1470 | virtual void __exec(__state&) const; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1471 | }; |
| 1472 | |
| 1473 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1474 | void |
| 1475 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1476 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1477 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1478 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1479 | |
| 1480 | // __has_one_state |
| 1481 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1482 | template <class _CharT> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1483 | class __has_one_state |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1484 | : public __node<_CharT> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1485 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1486 | __node<_CharT>* __first_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1487 | |
| 1488 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1489 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1490 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1491 | : __first_(__s) {} |
| 1492 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1493 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1494 | __node<_CharT>* first() const {return __first_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1495 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1496 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1497 | }; |
| 1498 | |
| 1499 | // __owns_one_state |
| 1500 | |
| 1501 | template <class _CharT> |
| 1502 | class __owns_one_state |
| 1503 | : public __has_one_state<_CharT> |
| 1504 | { |
| 1505 | typedef __has_one_state<_CharT> base; |
| 1506 | |
| 1507 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1508 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1509 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1510 | : base(__s) {} |
| 1511 | |
Nikolas Klauser | aa3a6cd | 2022-08-24 02:14:29 +0200 | [diff] [blame] | 1512 | ~__owns_one_state() override; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1513 | }; |
| 1514 | |
| 1515 | template <class _CharT> |
| 1516 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1517 | { |
| 1518 | delete this->first(); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1521 | // __empty_state |
| 1522 | |
| 1523 | template <class _CharT> |
| 1524 | class __empty_state |
| 1525 | : public __owns_one_state<_CharT> |
| 1526 | { |
| 1527 | typedef __owns_one_state<_CharT> base; |
| 1528 | |
| 1529 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1530 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1531 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1532 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1533 | explicit __empty_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1534 | : base(__s) {} |
| 1535 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1536 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1537 | }; |
| 1538 | |
| 1539 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1540 | void |
| 1541 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1542 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1543 | __s.__do_ = __state::__accept_but_not_consume; |
| 1544 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | // __empty_non_own_state |
| 1548 | |
| 1549 | template <class _CharT> |
| 1550 | class __empty_non_own_state |
| 1551 | : public __has_one_state<_CharT> |
| 1552 | { |
| 1553 | typedef __has_one_state<_CharT> base; |
| 1554 | |
| 1555 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1556 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1557 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1558 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1559 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1560 | : base(__s) {} |
| 1561 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1562 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1563 | }; |
| 1564 | |
| 1565 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1566 | void |
| 1567 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1568 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1569 | __s.__do_ = __state::__accept_but_not_consume; |
| 1570 | __s.__node_ = this->first(); |
| 1571 | } |
| 1572 | |
| 1573 | // __repeat_one_loop |
| 1574 | |
| 1575 | template <class _CharT> |
| 1576 | class __repeat_one_loop |
| 1577 | : public __has_one_state<_CharT> |
| 1578 | { |
| 1579 | typedef __has_one_state<_CharT> base; |
| 1580 | |
| 1581 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1582 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1583 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1584 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1585 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1586 | : base(__s) {} |
| 1587 | |
| 1588 | virtual void __exec(__state&) const; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1589 | }; |
| 1590 | |
| 1591 | template <class _CharT> |
| 1592 | void |
| 1593 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1594 | { |
| 1595 | __s.__do_ = __state::__repeat; |
| 1596 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | // __owns_two_states |
| 1600 | |
| 1601 | template <class _CharT> |
| 1602 | class __owns_two_states |
| 1603 | : public __owns_one_state<_CharT> |
| 1604 | { |
| 1605 | typedef __owns_one_state<_CharT> base; |
| 1606 | |
| 1607 | base* __second_; |
| 1608 | |
| 1609 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1610 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1611 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1612 | : base(__s1), __second_(__s2) {} |
| 1613 | |
| 1614 | virtual ~__owns_two_states(); |
| 1615 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1616 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1617 | base* second() const {return __second_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1618 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1619 | base*& second() {return __second_;} |
| 1620 | }; |
| 1621 | |
| 1622 | template <class _CharT> |
| 1623 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1624 | { |
| 1625 | delete __second_; |
| 1626 | } |
| 1627 | |
| 1628 | // __loop |
| 1629 | |
| 1630 | template <class _CharT> |
| 1631 | class __loop |
| 1632 | : public __owns_two_states<_CharT> |
| 1633 | { |
| 1634 | typedef __owns_two_states<_CharT> base; |
| 1635 | |
| 1636 | size_t __min_; |
| 1637 | size_t __max_; |
| 1638 | unsigned __loop_id_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1639 | unsigned __mexp_begin_; |
| 1640 | unsigned __mexp_end_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1641 | bool __greedy_; |
| 1642 | |
| 1643 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1644 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1645 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1646 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1647 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1648 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1649 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1650 | bool __greedy = true, |
| 1651 | size_t __min = 0, |
| 1652 | size_t __max = numeric_limits<size_t>::max()) |
| 1653 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1654 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1655 | __greedy_(__greedy) {} |
| 1656 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1657 | virtual void __exec(__state& __s) const; |
| 1658 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1659 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1660 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1661 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1662 | void __init_repeat(__state& __s) const |
| 1663 | { |
| 1664 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1665 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1666 | { |
| 1667 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1668 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1669 | __s.__sub_matches_[__i].matched = false; |
| 1670 | } |
| 1671 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1672 | }; |
| 1673 | |
| 1674 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1675 | void |
| 1676 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1677 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1678 | if (__s.__do_ == __state::__repeat) |
| 1679 | { |
| 1680 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1681 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1682 | if (__do_repeat && __do_alt && |
| 1683 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1684 | __do_repeat = false; |
| 1685 | if (__do_repeat && __do_alt) |
| 1686 | __s.__do_ = __state::__split; |
| 1687 | else if (__do_repeat) |
| 1688 | { |
| 1689 | __s.__do_ = __state::__accept_but_not_consume; |
| 1690 | __s.__node_ = this->first(); |
| 1691 | __init_repeat(__s); |
| 1692 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1693 | else |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1694 | { |
| 1695 | __s.__do_ = __state::__accept_but_not_consume; |
| 1696 | __s.__node_ = this->second(); |
| 1697 | } |
| 1698 | } |
| 1699 | else |
| 1700 | { |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1701 | __s.__loop_data_[__loop_id_].first = 0; |
| 1702 | bool __do_repeat = 0 < __max_; |
| 1703 | bool __do_alt = 0 >= __min_; |
| 1704 | if (__do_repeat && __do_alt) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1705 | __s.__do_ = __state::__split; |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1706 | else if (__do_repeat) |
| 1707 | { |
| 1708 | __s.__do_ = __state::__accept_but_not_consume; |
| 1709 | __s.__node_ = this->first(); |
| 1710 | __init_repeat(__s); |
| 1711 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1712 | else |
| 1713 | { |
| 1714 | __s.__do_ = __state::__accept_but_not_consume; |
| 1715 | __s.__node_ = this->second(); |
| 1716 | } |
| 1717 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1720 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1721 | void |
| 1722 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1723 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1724 | __s.__do_ = __state::__accept_but_not_consume; |
| 1725 | if (__greedy_ != __second) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1726 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1727 | __s.__node_ = this->first(); |
| 1728 | __init_repeat(__s); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1729 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1730 | else |
| 1731 | __s.__node_ = this->second(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1732 | } |
| 1733 | |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1734 | // __alternate |
| 1735 | |
| 1736 | template <class _CharT> |
| 1737 | class __alternate |
| 1738 | : public __owns_two_states<_CharT> |
| 1739 | { |
| 1740 | typedef __owns_two_states<_CharT> base; |
| 1741 | |
| 1742 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1743 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1744 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1745 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1746 | explicit __alternate(__owns_one_state<_CharT>* __s1, |
| 1747 | __owns_one_state<_CharT>* __s2) |
| 1748 | : base(__s1, __s2) {} |
| 1749 | |
| 1750 | virtual void __exec(__state& __s) const; |
| 1751 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1752 | }; |
| 1753 | |
| 1754 | template <class _CharT> |
| 1755 | void |
| 1756 | __alternate<_CharT>::__exec(__state& __s) const |
| 1757 | { |
| 1758 | __s.__do_ = __state::__split; |
| 1759 | } |
| 1760 | |
| 1761 | template <class _CharT> |
| 1762 | void |
| 1763 | __alternate<_CharT>::__exec_split(bool __second, __state& __s) const |
| 1764 | { |
| 1765 | __s.__do_ = __state::__accept_but_not_consume; |
Howard Hinnant | cbf2f3f | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1766 | if (__second) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1767 | __s.__node_ = this->second(); |
Howard Hinnant | cbf2f3f | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1768 | else |
| 1769 | __s.__node_ = this->first(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1772 | // __begin_marked_subexpression |
| 1773 | |
| 1774 | template <class _CharT> |
| 1775 | class __begin_marked_subexpression |
| 1776 | : public __owns_one_state<_CharT> |
| 1777 | { |
| 1778 | typedef __owns_one_state<_CharT> base; |
| 1779 | |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1780 | unsigned __mexp_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1781 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1782 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1783 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1784 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1785 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1786 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1787 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1788 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1789 | }; |
| 1790 | |
| 1791 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1792 | void |
| 1793 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1794 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1795 | __s.__do_ = __state::__accept_but_not_consume; |
| 1796 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1797 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | // __end_marked_subexpression |
| 1801 | |
| 1802 | template <class _CharT> |
| 1803 | class __end_marked_subexpression |
| 1804 | : public __owns_one_state<_CharT> |
| 1805 | { |
| 1806 | typedef __owns_one_state<_CharT> base; |
| 1807 | |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1808 | unsigned __mexp_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1809 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1810 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1811 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1812 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1813 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1814 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1815 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1816 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1817 | }; |
| 1818 | |
| 1819 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1820 | void |
| 1821 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1822 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1823 | __s.__do_ = __state::__accept_but_not_consume; |
| 1824 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1825 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1826 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1829 | // __back_ref |
| 1830 | |
| 1831 | template <class _CharT> |
| 1832 | class __back_ref |
| 1833 | : public __owns_one_state<_CharT> |
| 1834 | { |
| 1835 | typedef __owns_one_state<_CharT> base; |
| 1836 | |
| 1837 | unsigned __mexp_; |
| 1838 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1839 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1840 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1841 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1842 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1843 | : base(__s), __mexp_(__mexp) {} |
| 1844 | |
| 1845 | virtual void __exec(__state&) const; |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1846 | }; |
| 1847 | |
| 1848 | template <class _CharT> |
| 1849 | void |
| 1850 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1851 | { |
Marshall Clow | 360e839 | 2015-08-24 15:57:09 +0000 | [diff] [blame] | 1852 | if (__mexp_ > __s.__sub_matches_.size()) |
| 1853 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1854 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1855 | if (__sm.matched) |
| 1856 | { |
| 1857 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1858 | if (__s.__last_ - __s.__current_ >= __len && |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1859 | _VSTD::equal(__sm.first, __sm.second, __s.__current_)) |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1860 | { |
| 1861 | __s.__do_ = __state::__accept_but_not_consume; |
| 1862 | __s.__current_ += __len; |
| 1863 | __s.__node_ = this->first(); |
| 1864 | } |
| 1865 | else |
| 1866 | { |
| 1867 | __s.__do_ = __state::__reject; |
| 1868 | __s.__node_ = nullptr; |
| 1869 | } |
| 1870 | } |
| 1871 | else |
| 1872 | { |
| 1873 | __s.__do_ = __state::__reject; |
| 1874 | __s.__node_ = nullptr; |
| 1875 | } |
| 1876 | } |
| 1877 | |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1878 | // __back_ref_icase |
| 1879 | |
| 1880 | template <class _CharT, class _Traits> |
| 1881 | class __back_ref_icase |
| 1882 | : public __owns_one_state<_CharT> |
| 1883 | { |
| 1884 | typedef __owns_one_state<_CharT> base; |
| 1885 | |
| 1886 | _Traits __traits_; |
| 1887 | unsigned __mexp_; |
| 1888 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1889 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1890 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1891 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1892 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1893 | __node<_CharT>* __s) |
| 1894 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1895 | |
| 1896 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1897 | }; |
| 1898 | |
| 1899 | template <class _CharT, class _Traits> |
| 1900 | void |
| 1901 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1902 | { |
| 1903 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1904 | if (__sm.matched) |
| 1905 | { |
| 1906 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1907 | if (__s.__last_ - __s.__current_ >= __len) |
| 1908 | { |
| 1909 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1910 | { |
| 1911 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1912 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1913 | goto __not_equal; |
| 1914 | } |
| 1915 | __s.__do_ = __state::__accept_but_not_consume; |
| 1916 | __s.__current_ += __len; |
| 1917 | __s.__node_ = this->first(); |
| 1918 | } |
| 1919 | else |
| 1920 | { |
| 1921 | __s.__do_ = __state::__reject; |
| 1922 | __s.__node_ = nullptr; |
| 1923 | } |
| 1924 | } |
| 1925 | else |
| 1926 | { |
| 1927 | __not_equal: |
| 1928 | __s.__do_ = __state::__reject; |
| 1929 | __s.__node_ = nullptr; |
| 1930 | } |
| 1931 | } |
| 1932 | |
| 1933 | // __back_ref_collate |
| 1934 | |
| 1935 | template <class _CharT, class _Traits> |
| 1936 | class __back_ref_collate |
| 1937 | : public __owns_one_state<_CharT> |
| 1938 | { |
| 1939 | typedef __owns_one_state<_CharT> base; |
| 1940 | |
| 1941 | _Traits __traits_; |
| 1942 | unsigned __mexp_; |
| 1943 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1944 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1945 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1946 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1947 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1948 | __node<_CharT>* __s) |
| 1949 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1950 | |
| 1951 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1952 | }; |
| 1953 | |
| 1954 | template <class _CharT, class _Traits> |
| 1955 | void |
| 1956 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1957 | { |
| 1958 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1959 | if (__sm.matched) |
| 1960 | { |
| 1961 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1962 | if (__s.__last_ - __s.__current_ >= __len) |
| 1963 | { |
| 1964 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1965 | { |
| 1966 | if (__traits_.translate(__sm.first[__i]) != |
| 1967 | __traits_.translate(__s.__current_[__i])) |
| 1968 | goto __not_equal; |
| 1969 | } |
| 1970 | __s.__do_ = __state::__accept_but_not_consume; |
| 1971 | __s.__current_ += __len; |
| 1972 | __s.__node_ = this->first(); |
| 1973 | } |
| 1974 | else |
| 1975 | { |
| 1976 | __s.__do_ = __state::__reject; |
| 1977 | __s.__node_ = nullptr; |
| 1978 | } |
| 1979 | } |
| 1980 | else |
| 1981 | { |
| 1982 | __not_equal: |
| 1983 | __s.__do_ = __state::__reject; |
| 1984 | __s.__node_ = nullptr; |
| 1985 | } |
| 1986 | } |
| 1987 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1988 | // __word_boundary |
| 1989 | |
| 1990 | template <class _CharT, class _Traits> |
| 1991 | class __word_boundary |
| 1992 | : public __owns_one_state<_CharT> |
| 1993 | { |
| 1994 | typedef __owns_one_state<_CharT> base; |
| 1995 | |
| 1996 | _Traits __traits_; |
| 1997 | bool __invert_; |
| 1998 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1999 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2000 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2001 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2002 | explicit __word_boundary(const _Traits& __traits, bool __invert, |
| 2003 | __node<_CharT>* __s) |
| 2004 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 2005 | |
| 2006 | virtual void __exec(__state&) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2007 | }; |
| 2008 | |
| 2009 | template <class _CharT, class _Traits> |
| 2010 | void |
| 2011 | __word_boundary<_CharT, _Traits>::__exec(__state& __s) const |
| 2012 | { |
| 2013 | bool __is_word_b = false; |
| 2014 | if (__s.__first_ != __s.__last_) |
| 2015 | { |
| 2016 | if (__s.__current_ == __s.__last_) |
| 2017 | { |
| 2018 | if (!(__s.__flags_ & regex_constants::match_not_eow)) |
| 2019 | { |
| 2020 | _CharT __c = __s.__current_[-1]; |
| 2021 | __is_word_b = __c == '_' || |
| 2022 | __traits_.isctype(__c, ctype_base::alnum); |
| 2023 | } |
| 2024 | } |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 2025 | else if (__s.__current_ == __s.__first_ && |
| 2026 | !(__s.__flags_ & regex_constants::match_prev_avail)) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2027 | { |
| 2028 | if (!(__s.__flags_ & regex_constants::match_not_bow)) |
| 2029 | { |
| 2030 | _CharT __c = *__s.__current_; |
| 2031 | __is_word_b = __c == '_' || |
| 2032 | __traits_.isctype(__c, ctype_base::alnum); |
| 2033 | } |
| 2034 | } |
| 2035 | else |
| 2036 | { |
| 2037 | _CharT __c1 = __s.__current_[-1]; |
| 2038 | _CharT __c2 = *__s.__current_; |
| 2039 | bool __is_c1_b = __c1 == '_' || |
| 2040 | __traits_.isctype(__c1, ctype_base::alnum); |
| 2041 | bool __is_c2_b = __c2 == '_' || |
| 2042 | __traits_.isctype(__c2, ctype_base::alnum); |
| 2043 | __is_word_b = __is_c1_b != __is_c2_b; |
| 2044 | } |
| 2045 | } |
| 2046 | if (__is_word_b != __invert_) |
| 2047 | { |
| 2048 | __s.__do_ = __state::__accept_but_not_consume; |
| 2049 | __s.__node_ = this->first(); |
| 2050 | } |
| 2051 | else |
| 2052 | { |
| 2053 | __s.__do_ = __state::__reject; |
| 2054 | __s.__node_ = nullptr; |
| 2055 | } |
| 2056 | } |
| 2057 | |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2058 | // __l_anchor |
| 2059 | |
| 2060 | template <class _CharT> |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2061 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 2062 | bool __is_eol(_CharT __c) |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2063 | { |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 2064 | return __c == '\r' || __c == '\n'; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | template <class _CharT> |
| 2068 | class __l_anchor_multiline |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2069 | : public __owns_one_state<_CharT> |
| 2070 | { |
| 2071 | typedef __owns_one_state<_CharT> base; |
| 2072 | |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2073 | bool __multiline_; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2074 | |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2075 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2076 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2077 | |
| 2078 | _LIBCPP_INLINE_VISIBILITY |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2079 | __l_anchor_multiline(bool __multiline, __node<_CharT>* __s) |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2080 | : base(__s), __multiline_(__multiline) {} |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2081 | |
| 2082 | virtual void __exec(__state&) const; |
| 2083 | }; |
| 2084 | |
| 2085 | template <class _CharT> |
| 2086 | void |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2087 | __l_anchor_multiline<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2088 | { |
Marshall Clow | 5440439 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 2089 | if (__s.__at_first_ && __s.__current_ == __s.__first_ && |
| 2090 | !(__s.__flags_ & regex_constants::match_not_bol)) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2091 | { |
| 2092 | __s.__do_ = __state::__accept_but_not_consume; |
| 2093 | __s.__node_ = this->first(); |
| 2094 | } |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2095 | else if (__multiline_ && |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2096 | !__s.__at_first_ && |
| 2097 | __is_eol(*_VSTD::prev(__s.__current_))) |
| 2098 | { |
| 2099 | __s.__do_ = __state::__accept_but_not_consume; |
| 2100 | __s.__node_ = this->first(); |
| 2101 | } |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2102 | else |
| 2103 | { |
| 2104 | __s.__do_ = __state::__reject; |
| 2105 | __s.__node_ = nullptr; |
| 2106 | } |
| 2107 | } |
| 2108 | |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2109 | // __r_anchor |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2110 | |
| 2111 | template <class _CharT> |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2112 | class __r_anchor_multiline |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2113 | : public __owns_one_state<_CharT> |
| 2114 | { |
| 2115 | typedef __owns_one_state<_CharT> base; |
| 2116 | |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2117 | bool __multiline_; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2118 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2119 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2120 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2121 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2122 | _LIBCPP_INLINE_VISIBILITY |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2123 | __r_anchor_multiline(bool __multiline, __node<_CharT>* __s) |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2124 | : base(__s), __multiline_(__multiline) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2125 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2126 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2127 | }; |
| 2128 | |
| 2129 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2130 | void |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2131 | __r_anchor_multiline<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2132 | { |
Marshall Clow | 5440439 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 2133 | if (__s.__current_ == __s.__last_ && |
| 2134 | !(__s.__flags_ & regex_constants::match_not_eol)) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2135 | { |
| 2136 | __s.__do_ = __state::__accept_but_not_consume; |
| 2137 | __s.__node_ = this->first(); |
| 2138 | } |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2139 | else if (__multiline_ && __is_eol(*__s.__current_)) |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2140 | { |
| 2141 | __s.__do_ = __state::__accept_but_not_consume; |
| 2142 | __s.__node_ = this->first(); |
| 2143 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2144 | else |
| 2145 | { |
| 2146 | __s.__do_ = __state::__reject; |
| 2147 | __s.__node_ = nullptr; |
| 2148 | } |
| 2149 | } |
| 2150 | |
| 2151 | // __match_any |
| 2152 | |
| 2153 | template <class _CharT> |
| 2154 | class __match_any |
| 2155 | : public __owns_one_state<_CharT> |
| 2156 | { |
| 2157 | typedef __owns_one_state<_CharT> base; |
| 2158 | |
| 2159 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2160 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2161 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2162 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2163 | __match_any(__node<_CharT>* __s) |
| 2164 | : base(__s) {} |
| 2165 | |
| 2166 | virtual void __exec(__state&) const; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2167 | }; |
| 2168 | |
| 2169 | template <class _CharT> |
| 2170 | void |
| 2171 | __match_any<_CharT>::__exec(__state& __s) const |
| 2172 | { |
| 2173 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 2174 | { |
| 2175 | __s.__do_ = __state::__accept_and_consume; |
| 2176 | ++__s.__current_; |
| 2177 | __s.__node_ = this->first(); |
| 2178 | } |
| 2179 | else |
| 2180 | { |
| 2181 | __s.__do_ = __state::__reject; |
| 2182 | __s.__node_ = nullptr; |
| 2183 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2184 | } |
| 2185 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2186 | // __match_any_but_newline |
| 2187 | |
| 2188 | template <class _CharT> |
| 2189 | class __match_any_but_newline |
| 2190 | : public __owns_one_state<_CharT> |
| 2191 | { |
| 2192 | typedef __owns_one_state<_CharT> base; |
| 2193 | |
| 2194 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2195 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2196 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2197 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2198 | __match_any_but_newline(__node<_CharT>* __s) |
| 2199 | : base(__s) {} |
| 2200 | |
Nikolas Klauser | aa3a6cd | 2022-08-24 02:14:29 +0200 | [diff] [blame] | 2201 | void __exec(__state&) const override; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2202 | }; |
| 2203 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2204 | 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] | 2205 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2206 | 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] | 2207 | #endif |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2208 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2209 | // __match_char |
| 2210 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2211 | template <class _CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2212 | class __match_char |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2213 | : public __owns_one_state<_CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2214 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2215 | typedef __owns_one_state<_CharT> base; |
| 2216 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2217 | _CharT __c_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2218 | |
| 2219 | __match_char(const __match_char&); |
| 2220 | __match_char& operator=(const __match_char&); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2221 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2222 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2223 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2224 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2225 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2226 | : base(__s), __c_(__c) {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2227 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2228 | virtual void __exec(__state&) const; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2229 | }; |
| 2230 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2231 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2232 | void |
| 2233 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2234 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2235 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2236 | { |
| 2237 | __s.__do_ = __state::__accept_and_consume; |
| 2238 | ++__s.__current_; |
| 2239 | __s.__node_ = this->first(); |
| 2240 | } |
| 2241 | else |
| 2242 | { |
| 2243 | __s.__do_ = __state::__reject; |
| 2244 | __s.__node_ = nullptr; |
| 2245 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2246 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2247 | |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2248 | // __match_char_icase |
| 2249 | |
| 2250 | template <class _CharT, class _Traits> |
| 2251 | class __match_char_icase |
| 2252 | : public __owns_one_state<_CharT> |
| 2253 | { |
| 2254 | typedef __owns_one_state<_CharT> base; |
| 2255 | |
| 2256 | _Traits __traits_; |
| 2257 | _CharT __c_; |
| 2258 | |
| 2259 | __match_char_icase(const __match_char_icase&); |
| 2260 | __match_char_icase& operator=(const __match_char_icase&); |
| 2261 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2262 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2263 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2264 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2265 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2266 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2267 | |
| 2268 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2269 | }; |
| 2270 | |
| 2271 | template <class _CharT, class _Traits> |
| 2272 | void |
| 2273 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2274 | { |
| 2275 | if (__s.__current_ != __s.__last_ && |
| 2276 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2277 | { |
| 2278 | __s.__do_ = __state::__accept_and_consume; |
| 2279 | ++__s.__current_; |
| 2280 | __s.__node_ = this->first(); |
| 2281 | } |
| 2282 | else |
| 2283 | { |
| 2284 | __s.__do_ = __state::__reject; |
| 2285 | __s.__node_ = nullptr; |
| 2286 | } |
| 2287 | } |
| 2288 | |
| 2289 | // __match_char_collate |
| 2290 | |
| 2291 | template <class _CharT, class _Traits> |
| 2292 | class __match_char_collate |
| 2293 | : public __owns_one_state<_CharT> |
| 2294 | { |
| 2295 | typedef __owns_one_state<_CharT> base; |
| 2296 | |
| 2297 | _Traits __traits_; |
| 2298 | _CharT __c_; |
| 2299 | |
| 2300 | __match_char_collate(const __match_char_collate&); |
| 2301 | __match_char_collate& operator=(const __match_char_collate&); |
| 2302 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2303 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2304 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2305 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2306 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2307 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2308 | |
| 2309 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2310 | }; |
| 2311 | |
| 2312 | template <class _CharT, class _Traits> |
| 2313 | void |
| 2314 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2315 | { |
| 2316 | if (__s.__current_ != __s.__last_ && |
| 2317 | __traits_.translate(*__s.__current_) == __c_) |
| 2318 | { |
| 2319 | __s.__do_ = __state::__accept_and_consume; |
| 2320 | ++__s.__current_; |
| 2321 | __s.__node_ = this->first(); |
| 2322 | } |
| 2323 | else |
| 2324 | { |
| 2325 | __s.__do_ = __state::__reject; |
| 2326 | __s.__node_ = nullptr; |
| 2327 | } |
| 2328 | } |
| 2329 | |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2330 | // __bracket_expression |
| 2331 | |
| 2332 | template <class _CharT, class _Traits> |
| 2333 | class __bracket_expression |
| 2334 | : public __owns_one_state<_CharT> |
| 2335 | { |
| 2336 | typedef __owns_one_state<_CharT> base; |
| 2337 | typedef typename _Traits::string_type string_type; |
| 2338 | |
| 2339 | _Traits __traits_; |
| 2340 | vector<_CharT> __chars_; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2341 | vector<_CharT> __neg_chars_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2342 | vector<pair<string_type, string_type> > __ranges_; |
| 2343 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2344 | vector<string_type> __equivalences_; |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2345 | typename regex_traits<_CharT>::char_class_type __mask_; |
| 2346 | typename regex_traits<_CharT>::char_class_type __neg_mask_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2347 | bool __negate_; |
| 2348 | bool __icase_; |
| 2349 | bool __collate_; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2350 | bool __might_have_digraph_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2351 | |
| 2352 | __bracket_expression(const __bracket_expression&); |
| 2353 | __bracket_expression& operator=(const __bracket_expression&); |
| 2354 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2355 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2356 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2357 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2358 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2359 | bool __negate, bool __icase, bool __collate) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2360 | : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), |
| 2361 | __negate_(__negate), __icase_(__icase), __collate_(__collate), |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2362 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2363 | |
| 2364 | virtual void __exec(__state&) const; |
| 2365 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2366 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2367 | bool __negated() const {return __negate_;} |
| 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_char(_CharT __c) |
| 2371 | { |
| 2372 | if (__icase_) |
| 2373 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2374 | else if (__collate_) |
| 2375 | __chars_.push_back(__traits_.translate(__c)); |
| 2376 | else |
| 2377 | __chars_.push_back(__c); |
| 2378 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2379 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2380 | void __add_neg_char(_CharT __c) |
| 2381 | { |
| 2382 | if (__icase_) |
| 2383 | __neg_chars_.push_back(__traits_.translate_nocase(__c)); |
| 2384 | else if (__collate_) |
| 2385 | __neg_chars_.push_back(__traits_.translate(__c)); |
| 2386 | else |
| 2387 | __neg_chars_.push_back(__c); |
| 2388 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2389 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2390 | void __add_range(string_type __b, string_type __e) |
| 2391 | { |
| 2392 | if (__collate_) |
| 2393 | { |
| 2394 | if (__icase_) |
| 2395 | { |
| 2396 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2397 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2398 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2399 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2400 | } |
| 2401 | else |
| 2402 | { |
| 2403 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2404 | __b[__i] = __traits_.translate(__b[__i]); |
| 2405 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2406 | __e[__i] = __traits_.translate(__e[__i]); |
| 2407 | } |
| 2408 | __ranges_.push_back(make_pair( |
| 2409 | __traits_.transform(__b.begin(), __b.end()), |
| 2410 | __traits_.transform(__e.begin(), __e.end()))); |
| 2411 | } |
| 2412 | else |
| 2413 | { |
| 2414 | if (__b.size() != 1 || __e.size() != 1) |
Marshall Clow | a521211 | 2019-05-28 22:42:32 +0000 | [diff] [blame] | 2415 | __throw_regex_error<regex_constants::error_range>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2416 | if (__icase_) |
| 2417 | { |
| 2418 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2419 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2420 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2421 | __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e))); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2422 | } |
| 2423 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2424 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2425 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2426 | { |
| 2427 | if (__icase_) |
| 2428 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2429 | __traits_.translate_nocase(__c2))); |
| 2430 | else if (__collate_) |
| 2431 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2432 | __traits_.translate(__c2))); |
| 2433 | else |
| 2434 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2435 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2436 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2437 | void __add_equivalence(const string_type& __s) |
| 2438 | {__equivalences_.push_back(__s);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2439 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2440 | void __add_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2441 | {__mask_ |= __mask;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2442 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2443 | void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2444 | {__neg_mask_ |= __mask;} |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2445 | }; |
| 2446 | |
| 2447 | template <class _CharT, class _Traits> |
| 2448 | void |
| 2449 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2450 | { |
| 2451 | bool __found = false; |
| 2452 | unsigned __consumed = 0; |
| 2453 | if (__s.__current_ != __s.__last_) |
| 2454 | { |
| 2455 | ++__consumed; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2456 | if (__might_have_digraph_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2457 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2458 | const _CharT* __next = _VSTD::next(__s.__current_); |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2459 | if (__next != __s.__last_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2460 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2461 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2462 | if (__icase_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2463 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2464 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2465 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2466 | } |
| 2467 | else if (__collate_) |
| 2468 | { |
| 2469 | __ch2.first = __traits_.translate(__ch2.first); |
| 2470 | __ch2.second = __traits_.translate(__ch2.second); |
| 2471 | } |
| 2472 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2473 | { |
| 2474 | // __ch2 is a digraph in this locale |
| 2475 | ++__consumed; |
| 2476 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2477 | { |
| 2478 | if (__ch2 == __digraphs_[__i]) |
| 2479 | { |
| 2480 | __found = true; |
| 2481 | goto __exit; |
| 2482 | } |
| 2483 | } |
| 2484 | if (__collate_ && !__ranges_.empty()) |
| 2485 | { |
| 2486 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2487 | &__ch2.first + 2); |
| 2488 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2489 | { |
| 2490 | if (__ranges_[__i].first <= __s2 && |
| 2491 | __s2 <= __ranges_[__i].second) |
| 2492 | { |
| 2493 | __found = true; |
| 2494 | goto __exit; |
| 2495 | } |
| 2496 | } |
| 2497 | } |
| 2498 | if (!__equivalences_.empty()) |
| 2499 | { |
| 2500 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2501 | &__ch2.first + 2); |
| 2502 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2503 | { |
| 2504 | if (__s2 == __equivalences_[__i]) |
| 2505 | { |
| 2506 | __found = true; |
| 2507 | goto __exit; |
| 2508 | } |
| 2509 | } |
| 2510 | } |
| 2511 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2512 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2513 | { |
| 2514 | __found = true; |
| 2515 | goto __exit; |
| 2516 | } |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2517 | if (!__traits_.isctype(__ch2.first, __neg_mask_) && |
| 2518 | !__traits_.isctype(__ch2.second, __neg_mask_)) |
| 2519 | { |
| 2520 | __found = true; |
| 2521 | goto __exit; |
| 2522 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2523 | goto __exit; |
| 2524 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2525 | } |
| 2526 | } |
| 2527 | // test *__s.__current_ as not a digraph |
| 2528 | _CharT __ch = *__s.__current_; |
| 2529 | if (__icase_) |
| 2530 | __ch = __traits_.translate_nocase(__ch); |
| 2531 | else if (__collate_) |
| 2532 | __ch = __traits_.translate(__ch); |
| 2533 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2534 | { |
| 2535 | if (__ch == __chars_[__i]) |
| 2536 | { |
| 2537 | __found = true; |
| 2538 | goto __exit; |
| 2539 | } |
| 2540 | } |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2541 | // When there's at least one of __neg_chars_ and __neg_mask_, the set |
| 2542 | // of "__found" chars is |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2543 | // union(complement(union(__neg_chars_, __neg_mask_)), |
| 2544 | // other cases...) |
| 2545 | // |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2546 | // It doesn't make sense to check this when there are no __neg_chars_ |
| 2547 | // and no __neg_mask_. |
| 2548 | if (!(__neg_mask_ == 0 && __neg_chars_.empty())) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2549 | { |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2550 | const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_); |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2551 | const bool __in_neg_chars = |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 2552 | _VSTD::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2553 | __neg_chars_.end(); |
| 2554 | if (!(__in_neg_mask || __in_neg_chars)) |
| 2555 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2556 | __found = true; |
| 2557 | goto __exit; |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2558 | } |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2559 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2560 | if (!__ranges_.empty()) |
| 2561 | { |
| 2562 | string_type __s2 = __collate_ ? |
| 2563 | __traits_.transform(&__ch, &__ch + 1) : |
| 2564 | string_type(1, __ch); |
| 2565 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2566 | { |
| 2567 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2568 | { |
| 2569 | __found = true; |
| 2570 | goto __exit; |
| 2571 | } |
| 2572 | } |
| 2573 | } |
| 2574 | if (!__equivalences_.empty()) |
| 2575 | { |
| 2576 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2577 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2578 | { |
| 2579 | if (__s2 == __equivalences_[__i]) |
| 2580 | { |
| 2581 | __found = true; |
| 2582 | goto __exit; |
| 2583 | } |
| 2584 | } |
| 2585 | } |
| 2586 | if (__traits_.isctype(__ch, __mask_)) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2587 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2588 | __found = true; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2589 | goto __exit; |
| 2590 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2591 | } |
| 2592 | else |
| 2593 | __found = __negate_; // force reject |
| 2594 | __exit: |
| 2595 | if (__found != __negate_) |
| 2596 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2597 | __s.__do_ = __state::__accept_and_consume; |
| 2598 | __s.__current_ += __consumed; |
| 2599 | __s.__node_ = this->first(); |
| 2600 | } |
| 2601 | else |
| 2602 | { |
| 2603 | __s.__do_ = __state::__reject; |
| 2604 | __s.__node_ = nullptr; |
| 2605 | } |
| 2606 | } |
| 2607 | |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 2608 | template <class _CharT, class _Traits> class __lookahead; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2609 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2610 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2611 | class _LIBCPP_TEMPLATE_VIS basic_regex; |
| 2612 | |
| 2613 | typedef basic_regex<char> regex; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2614 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2615 | typedef basic_regex<wchar_t> wregex; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2616 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2617 | |
| 2618 | template <class _CharT, class _Traits> |
| 2619 | class |
| 2620 | _LIBCPP_TEMPLATE_VIS |
| 2621 | _LIBCPP_PREFERRED_NAME(regex) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2622 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2623 | basic_regex |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2624 | { |
| 2625 | public: |
| 2626 | // types: |
| 2627 | typedef _CharT value_type; |
Hubert Tong | 1f1ae9c | 2016-08-02 21:34:48 +0000 | [diff] [blame] | 2628 | typedef _Traits traits_type; |
| 2629 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2630 | typedef regex_constants::syntax_option_type flag_type; |
| 2631 | typedef typename _Traits::locale_type locale_type; |
| 2632 | |
| 2633 | private: |
| 2634 | _Traits __traits_; |
| 2635 | flag_type __flags_; |
| 2636 | unsigned __marked_count_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2637 | unsigned __loop_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2638 | int __open_count_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2639 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2640 | __owns_one_state<_CharT>* __end_; |
| 2641 | |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2642 | typedef _VSTD::__state<_CharT> __state; |
| 2643 | typedef _VSTD::__node<_CharT> __node; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2644 | |
| 2645 | public: |
| 2646 | // constants: |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2647 | static const regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2648 | static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2649 | static const regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2650 | static const regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2651 | static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2652 | static const regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2653 | static const regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2654 | static const regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2655 | static const regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2656 | static const regex_constants::syntax_option_type egrep = regex_constants::egrep; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2657 | static const regex_constants::syntax_option_type multiline = regex_constants::multiline; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2658 | |
| 2659 | // construct/copy/destroy: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2660 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2661 | basic_regex() |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2662 | : __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] | 2663 | __end_(nullptr) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2664 | {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2665 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2666 | 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] | 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, __p + __traits_.length(__p)); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2671 | } |
| 2672 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2673 | _LIBCPP_INLINE_VISIBILITY |
Hubert Tong | 1966286 | 2016-08-07 22:26:04 +0000 | [diff] [blame] | 2674 | 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] | 2675 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2676 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2677 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2678 | __init(__p, __p + __len); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2679 | } |
| 2680 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2681 | // basic_regex(const basic_regex&) = default; |
| 2682 | // basic_regex(basic_regex&&) = default; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2683 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2684 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2685 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2686 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2687 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2688 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2689 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2690 | __init(__p.begin(), __p.end()); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2691 | } |
| 2692 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2693 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2694 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2695 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 2696 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2697 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2698 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2699 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2700 | __init(__first, __last); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2701 | } |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2702 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2703 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2704 | basic_regex(initializer_list<value_type> __il, |
| 2705 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2706 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2707 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2708 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2709 | __init(__il.begin(), __il.end()); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2710 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2711 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2712 | |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2713 | // ~basic_regex() = default; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2714 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2715 | // basic_regex& operator=(const basic_regex&) = default; |
| 2716 | // basic_regex& operator=(basic_regex&&) = default; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2717 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2718 | basic_regex& operator=(const value_type* __p) |
| 2719 | {return assign(__p);} |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2720 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2721 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2722 | basic_regex& operator=(initializer_list<value_type> __il) |
| 2723 | {return assign(__il);} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2724 | #endif // _LIBCPP_CXX03_LANG |
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 | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2727 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) |
| 2728 | {return assign(__p);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2729 | |
| 2730 | // assign: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2731 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2732 | basic_regex& assign(const basic_regex& __that) |
| 2733 | {return *this = __that;} |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2734 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2735 | _LIBCPP_INLINE_VISIBILITY |
| 2736 | basic_regex& assign(basic_regex&& __that) _NOEXCEPT |
| 2737 | {return *this = _VSTD::move(__that);} |
| 2738 | #endif |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2739 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2740 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
| 2741 | {return assign(__p, __p + __traits_.length(__p), __f);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2742 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | d402893 | 2019-09-25 16:40:30 +0000 | [diff] [blame] | 2743 | 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] | 2744 | {return assign(__p, __p + __len, __f);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2745 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2746 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2747 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2748 | flag_type __f = regex_constants::ECMAScript) |
| 2749 | {return assign(__s.begin(), __s.end(), __f);} |
| 2750 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2751 | template <class _InputIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2752 | _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 15a63e9 | 2022-07-04 22:45:49 +0200 | [diff] [blame] | 2753 | typename enable_if<__is_exactly_cpp17_input_iterator<_InputIterator>::value, basic_regex&>::type |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2754 | assign(_InputIterator __first, _InputIterator __last, |
| 2755 | flag_type __f = regex_constants::ECMAScript) |
| 2756 | { |
| 2757 | basic_string<_CharT> __t(__first, __last); |
| 2758 | return assign(__t.begin(), __t.end(), __f); |
| 2759 | } |
| 2760 | |
| 2761 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2762 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2763 | void __member_init(flag_type __f) |
| 2764 | { |
| 2765 | __flags_ = __f; |
| 2766 | __marked_count_ = 0; |
| 2767 | __loop_count_ = 0; |
| 2768 | __open_count_ = 0; |
| 2769 | __end_ = nullptr; |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2770 | } |
| 2771 | public: |
| 2772 | |
| 2773 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2774 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2775 | typename enable_if |
| 2776 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2777 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2778 | basic_regex& |
| 2779 | >::type |
| 2780 | assign(_ForwardIterator __first, _ForwardIterator __last, |
| 2781 | flag_type __f = regex_constants::ECMAScript) |
| 2782 | { |
Marshall Clow | ce03dc1 | 2015-01-13 16:49:52 +0000 | [diff] [blame] | 2783 | return assign(basic_regex(__first, __last, __f)); |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2784 | } |
| 2785 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2786 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2787 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2788 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2789 | basic_regex& assign(initializer_list<value_type> __il, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2790 | flag_type __f = regex_constants::ECMAScript) |
| 2791 | {return assign(__il.begin(), __il.end(), __f);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2792 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2793 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2794 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2795 | // const operations: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2796 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2797 | unsigned mark_count() const {return __marked_count_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2798 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2799 | flag_type flags() const {return __flags_;} |
| 2800 | |
| 2801 | // locale: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2802 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2803 | locale_type imbue(locale_type __loc) |
| 2804 | { |
| 2805 | __member_init(ECMAScript); |
| 2806 | __start_.reset(); |
| 2807 | return __traits_.imbue(__loc); |
| 2808 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2809 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2810 | locale_type getloc() const {return __traits_.getloc();} |
| 2811 | |
| 2812 | // swap: |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2813 | void swap(basic_regex& __r); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2814 | |
| 2815 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2816 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2817 | unsigned __loop_count() const {return __loop_count_;} |
| 2818 | |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2819 | _LIBCPP_INLINE_VISIBILITY |
| 2820 | bool __use_multiline() const |
| 2821 | { |
| 2822 | return __get_grammar(__flags_) == ECMAScript && (__flags_ & multiline); |
| 2823 | } |
| 2824 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2825 | template <class _ForwardIterator> |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2826 | void |
| 2827 | __init(_ForwardIterator __first, _ForwardIterator __last); |
| 2828 | template <class _ForwardIterator> |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2829 | _ForwardIterator |
| 2830 | __parse(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2831 | template <class _ForwardIterator> |
| 2832 | _ForwardIterator |
| 2833 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2834 | template <class _ForwardIterator> |
| 2835 | _ForwardIterator |
| 2836 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2837 | template <class _ForwardIterator> |
| 2838 | _ForwardIterator |
| 2839 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2840 | template <class _ForwardIterator> |
| 2841 | _ForwardIterator |
| 2842 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2843 | template <class _ForwardIterator> |
| 2844 | _ForwardIterator |
| 2845 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2846 | template <class _ForwardIterator> |
| 2847 | _ForwardIterator |
| 2848 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2849 | template <class _ForwardIterator> |
| 2850 | _ForwardIterator |
| 2851 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2852 | template <class _ForwardIterator> |
| 2853 | _ForwardIterator |
| 2854 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2855 | template <class _ForwardIterator> |
| 2856 | _ForwardIterator |
| 2857 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2858 | template <class _ForwardIterator> |
| 2859 | _ForwardIterator |
| 2860 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2861 | template <class _ForwardIterator> |
| 2862 | _ForwardIterator |
| 2863 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2864 | template <class _ForwardIterator> |
| 2865 | _ForwardIterator |
| 2866 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2867 | template <class _ForwardIterator> |
| 2868 | _ForwardIterator |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2869 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2870 | __owns_one_state<_CharT>* __s, |
| 2871 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2872 | template <class _ForwardIterator> |
| 2873 | _ForwardIterator |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2874 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2875 | __owns_one_state<_CharT>* __s, |
| 2876 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2877 | template <class _ForwardIterator> |
| 2878 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2879 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2880 | template <class _ForwardIterator> |
| 2881 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2882 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2883 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2884 | template <class _ForwardIterator> |
| 2885 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2886 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2887 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2888 | template <class _ForwardIterator> |
| 2889 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2890 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2891 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2892 | template <class _ForwardIterator> |
| 2893 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2894 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2895 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2896 | template <class _ForwardIterator> |
| 2897 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2898 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2899 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2900 | template <class _ForwardIterator> |
| 2901 | _ForwardIterator |
| 2902 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2903 | template <class _ForwardIterator> |
| 2904 | _ForwardIterator |
| 2905 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2906 | template <class _ForwardIterator> |
| 2907 | _ForwardIterator |
| 2908 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2909 | template <class _ForwardIterator> |
| 2910 | _ForwardIterator |
| 2911 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2912 | template <class _ForwardIterator> |
| 2913 | _ForwardIterator |
| 2914 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2915 | template <class _ForwardIterator> |
| 2916 | _ForwardIterator |
| 2917 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2918 | template <class _ForwardIterator> |
| 2919 | _ForwardIterator |
| 2920 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2921 | template <class _ForwardIterator> |
| 2922 | _ForwardIterator |
| 2923 | __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2924 | template <class _ForwardIterator> |
| 2925 | _ForwardIterator |
| 2926 | __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); |
| 2927 | template <class _ForwardIterator> |
| 2928 | _ForwardIterator |
| 2929 | __parse_term(_ForwardIterator __first, _ForwardIterator __last); |
| 2930 | template <class _ForwardIterator> |
| 2931 | _ForwardIterator |
| 2932 | __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); |
| 2933 | template <class _ForwardIterator> |
| 2934 | _ForwardIterator |
| 2935 | __parse_atom(_ForwardIterator __first, _ForwardIterator __last); |
| 2936 | template <class _ForwardIterator> |
| 2937 | _ForwardIterator |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2938 | __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2939 | template <class _ForwardIterator> |
| 2940 | _ForwardIterator |
| 2941 | __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2942 | template <class _ForwardIterator> |
| 2943 | _ForwardIterator |
| 2944 | __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2945 | template <class _ForwardIterator> |
| 2946 | _ForwardIterator |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2947 | __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2948 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2949 | template <class _ForwardIterator> |
| 2950 | _ForwardIterator |
| 2951 | __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 2952 | template <class _ForwardIterator> |
| 2953 | _ForwardIterator |
| 2954 | __parse_grep(_ForwardIterator __first, _ForwardIterator __last); |
| 2955 | template <class _ForwardIterator> |
| 2956 | _ForwardIterator |
| 2957 | __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2958 | template <class _ForwardIterator> |
| 2959 | _ForwardIterator |
| 2960 | __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2961 | basic_string<_CharT>& __str, |
| 2962 | __bracket_expression<_CharT, _Traits>* __ml); |
| 2963 | template <class _ForwardIterator> |
| 2964 | _ForwardIterator |
| 2965 | __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2966 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2967 | |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 2968 | bool __test_back_ref(_CharT); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 2969 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2970 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2971 | void __push_l_anchor(); |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2972 | void __push_r_anchor(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2973 | void __push_match_any(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2974 | void __push_match_any_but_newline(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2975 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2976 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2977 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2978 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2979 | __mexp_begin, __mexp_end);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2980 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2981 | void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2982 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2983 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2984 | __mexp_begin, __mexp_end, false);} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2985 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2986 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2987 | bool __greedy = true); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2988 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2989 | void __push_char(value_type __c); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 2990 | void __push_back_ref(int __i); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2991 | void __push_alternation(__owns_one_state<_CharT>* __sa, |
| 2992 | __owns_one_state<_CharT>* __sb); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2993 | void __push_begin_marked_subexpression(); |
| 2994 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2995 | void __push_empty(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2996 | void __push_word_boundary(bool); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2997 | void __push_lookahead(const basic_regex&, bool, unsigned); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2998 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2999 | template <class _Allocator> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3000 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3001 | __search(const _CharT* __first, const _CharT* __last, |
| 3002 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3003 | regex_constants::match_flag_type __flags) const; |
| 3004 | |
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(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 | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3010 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3011 | bool |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3012 | __match_at_start_ecma(const _CharT* __first, const _CharT* __last, |
| 3013 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3014 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3015 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3016 | bool |
| 3017 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3018 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3019 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3020 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3021 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3022 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 3023 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3024 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3025 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3026 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3027 | friend |
| 3028 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3029 | 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] | 3030 | regex_constants::match_flag_type); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3031 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3032 | template <class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3033 | friend |
| 3034 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3035 | regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&, |
| 3036 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3037 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3038 | template <class _Bp, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3039 | friend |
| 3040 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3041 | regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3042 | regex_constants::match_flag_type); |
| 3043 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3044 | template <class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3045 | friend |
| 3046 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3047 | regex_search(const _Cp*, const _Cp*, |
| 3048 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3049 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3050 | template <class _Cp, class _Ap, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3051 | friend |
| 3052 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3053 | 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] | 3054 | regex_constants::match_flag_type); |
| 3055 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3056 | template <class _ST, class _SA, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3057 | friend |
| 3058 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3059 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 3060 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3061 | regex_constants::match_flag_type __flags); |
| 3062 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3063 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3064 | friend |
| 3065 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3066 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 3067 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 3068 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3069 | regex_constants::match_flag_type __flags); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3070 | |
Howard Hinnant | 4018c48 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 3071 | template <class _Iter, class _Ap, class _Cp, class _Tp> |
| 3072 | friend |
| 3073 | bool |
| 3074 | regex_search(__wrap_iter<_Iter> __first, |
| 3075 | __wrap_iter<_Iter> __last, |
| 3076 | match_results<__wrap_iter<_Iter>, _Ap>& __m, |
| 3077 | const basic_regex<_Cp, _Tp>& __e, |
| 3078 | regex_constants::match_flag_type __flags); |
| 3079 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3080 | template <class, class> friend class __lookahead; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3081 | }; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3082 | |
Louis Dionne | d59f8a5 | 2021-08-17 11:59:07 -0400 | [diff] [blame] | 3083 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | 2dce1f4 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 3084 | template <class _ForwardIterator, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3085 | 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] | 3086 | > |
| 3087 | basic_regex(_ForwardIterator, _ForwardIterator, |
| 3088 | regex_constants::syntax_option_type = regex_constants::ECMAScript) |
| 3089 | -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>; |
| 3090 | #endif |
| 3091 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3092 | template <class _CharT, class _Traits> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 3093 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase; |
| 3094 | template <class _CharT, class _Traits> |
| 3095 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs; |
| 3096 | template <class _CharT, class _Traits> |
| 3097 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize; |
| 3098 | template <class _CharT, class _Traits> |
| 3099 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate; |
| 3100 | template <class _CharT, class _Traits> |
| 3101 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript; |
| 3102 | template <class _CharT, class _Traits> |
| 3103 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic; |
| 3104 | template <class _CharT, class _Traits> |
| 3105 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended; |
| 3106 | template <class _CharT, class _Traits> |
| 3107 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk; |
| 3108 | template <class _CharT, class _Traits> |
| 3109 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep; |
| 3110 | template <class _CharT, class _Traits> |
| 3111 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep; |
| 3112 | |
| 3113 | template <class _CharT, class _Traits> |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3114 | void |
| 3115 | basic_regex<_CharT, _Traits>::swap(basic_regex& __r) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3116 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3117 | using _VSTD::swap; |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3118 | swap(__traits_, __r.__traits_); |
| 3119 | swap(__flags_, __r.__flags_); |
| 3120 | swap(__marked_count_, __r.__marked_count_); |
| 3121 | swap(__loop_count_, __r.__loop_count_); |
| 3122 | swap(__open_count_, __r.__open_count_); |
| 3123 | swap(__start_, __r.__start_); |
| 3124 | swap(__end_, __r.__end_); |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | template <class _CharT, class _Traits> |
| 3128 | inline _LIBCPP_INLINE_VISIBILITY |
| 3129 | void |
| 3130 | swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) |
| 3131 | { |
| 3132 | return __x.swap(__y); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3133 | } |
| 3134 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3135 | // __lookahead |
| 3136 | |
| 3137 | template <class _CharT, class _Traits> |
| 3138 | class __lookahead |
| 3139 | : public __owns_one_state<_CharT> |
| 3140 | { |
| 3141 | typedef __owns_one_state<_CharT> base; |
| 3142 | |
| 3143 | basic_regex<_CharT, _Traits> __exp_; |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3144 | unsigned __mexp_; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3145 | bool __invert_; |
| 3146 | |
| 3147 | __lookahead(const __lookahead&); |
| 3148 | __lookahead& operator=(const __lookahead&); |
| 3149 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3150 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3151 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 3152 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3153 | __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] | 3154 | : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {} |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3155 | |
| 3156 | virtual void __exec(__state&) const; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3157 | }; |
| 3158 | |
| 3159 | template <class _CharT, class _Traits> |
| 3160 | void |
| 3161 | __lookahead<_CharT, _Traits>::__exec(__state& __s) const |
| 3162 | { |
| 3163 | match_results<const _CharT*> __m; |
| 3164 | __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 3165 | bool __matched = __exp_.__match_at_start_ecma( |
| 3166 | __s.__current_, __s.__last_, |
| 3167 | __m, |
| 3168 | (__s.__flags_ | regex_constants::match_continuous) & |
| 3169 | ~regex_constants::__full_match, |
| 3170 | __s.__at_first_ && __s.__current_ == __s.__first_); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3171 | if (__matched != __invert_) |
| 3172 | { |
| 3173 | __s.__do_ = __state::__accept_but_not_consume; |
| 3174 | __s.__node_ = this->first(); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3175 | for (unsigned __i = 1; __i < __m.size(); ++__i) { |
| 3176 | __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i]; |
| 3177 | } |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3178 | } |
| 3179 | else |
| 3180 | { |
| 3181 | __s.__do_ = __state::__reject; |
| 3182 | __s.__node_ = nullptr; |
| 3183 | } |
| 3184 | } |
| 3185 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3186 | template <class _CharT, class _Traits> |
| 3187 | template <class _ForwardIterator> |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 3188 | void |
| 3189 | basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last) |
| 3190 | { |
| 3191 | if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; |
| 3192 | _ForwardIterator __temp = __parse(__first, __last); |
| 3193 | if ( __temp != __last) |
| 3194 | __throw_regex_error<regex_constants::__re_err_parse>(); |
| 3195 | } |
| 3196 | |
| 3197 | template <class _CharT, class _Traits> |
| 3198 | template <class _ForwardIterator> |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3199 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3200 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 3201 | _ForwardIterator __last) |
| 3202 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3203 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 3204 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3205 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 3206 | __h.release(); |
| 3207 | __end_ = __start_.get(); |
| 3208 | } |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3209 | switch (__get_grammar(__flags_)) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3210 | { |
| 3211 | case ECMAScript: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3212 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3213 | break; |
| 3214 | case basic: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3215 | __first = __parse_basic_reg_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3216 | break; |
| 3217 | case extended: |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3218 | case awk: |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3219 | __first = __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3220 | break; |
| 3221 | case grep: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3222 | __first = __parse_grep(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3223 | break; |
| 3224 | case egrep: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3225 | __first = __parse_egrep(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3226 | break; |
| 3227 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3228 | __throw_regex_error<regex_constants::__re_err_grammar>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3229 | } |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3230 | return __first; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | template <class _CharT, class _Traits> |
| 3234 | template <class _ForwardIterator> |
| 3235 | _ForwardIterator |
| 3236 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 3237 | _ForwardIterator __last) |
| 3238 | { |
| 3239 | if (__first != __last) |
| 3240 | { |
| 3241 | if (*__first == '^') |
| 3242 | { |
| 3243 | __push_l_anchor(); |
| 3244 | ++__first; |
| 3245 | } |
| 3246 | if (__first != __last) |
| 3247 | { |
| 3248 | __first = __parse_RE_expression(__first, __last); |
| 3249 | if (__first != __last) |
| 3250 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3251 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3252 | if (__temp == __last && *__first == '$') |
| 3253 | { |
| 3254 | __push_r_anchor(); |
| 3255 | ++__first; |
| 3256 | } |
| 3257 | } |
| 3258 | } |
| 3259 | if (__first != __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3260 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3261 | } |
| 3262 | return __first; |
| 3263 | } |
| 3264 | |
| 3265 | template <class _CharT, class _Traits> |
| 3266 | template <class _ForwardIterator> |
| 3267 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3268 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 3269 | _ForwardIterator __last) |
| 3270 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3271 | __owns_one_state<_CharT>* __sa = __end_; |
| 3272 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
| 3273 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3274 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3275 | __first = __temp; |
| 3276 | while (__first != __last && *__first == '|') |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3277 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3278 | __owns_one_state<_CharT>* __sb = __end_; |
| 3279 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 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 | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3282 | __push_alternation(__sa, __sb); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3283 | __first = __temp; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3284 | } |
| 3285 | return __first; |
| 3286 | } |
| 3287 | |
| 3288 | template <class _CharT, class _Traits> |
| 3289 | template <class _ForwardIterator> |
| 3290 | _ForwardIterator |
| 3291 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 3292 | _ForwardIterator __last) |
| 3293 | { |
| 3294 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
| 3295 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3296 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3297 | do |
| 3298 | { |
| 3299 | __first = __temp; |
| 3300 | __temp = __parse_ERE_expression(__first, __last); |
| 3301 | } while (__temp != __first); |
| 3302 | return __first; |
| 3303 | } |
| 3304 | |
| 3305 | template <class _CharT, class _Traits> |
| 3306 | template <class _ForwardIterator> |
| 3307 | _ForwardIterator |
| 3308 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 3309 | _ForwardIterator __last) |
| 3310 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3311 | __owns_one_state<_CharT>* __e = __end_; |
| 3312 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3313 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 3314 | if (__temp == __first && __temp != __last) |
| 3315 | { |
| 3316 | switch (*__temp) |
| 3317 | { |
| 3318 | case '^': |
| 3319 | __push_l_anchor(); |
| 3320 | ++__temp; |
| 3321 | break; |
| 3322 | case '$': |
| 3323 | __push_r_anchor(); |
| 3324 | ++__temp; |
| 3325 | break; |
| 3326 | case '(': |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3327 | __push_begin_marked_subexpression(); |
| 3328 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3329 | ++__open_count_; |
| 3330 | __temp = __parse_extended_reg_exp(++__temp, __last); |
| 3331 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3332 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3333 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3334 | --__open_count_; |
| 3335 | ++__temp; |
| 3336 | break; |
| 3337 | } |
| 3338 | } |
| 3339 | if (__temp != __first) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3340 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 3341 | __marked_count_+1); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3342 | __first = __temp; |
| 3343 | return __first; |
| 3344 | } |
| 3345 | |
| 3346 | template <class _CharT, class _Traits> |
| 3347 | template <class _ForwardIterator> |
| 3348 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3349 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 3350 | _ForwardIterator __last) |
| 3351 | { |
| 3352 | while (true) |
| 3353 | { |
| 3354 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 3355 | if (__temp == __first) |
| 3356 | break; |
| 3357 | __first = __temp; |
| 3358 | } |
| 3359 | return __first; |
| 3360 | } |
| 3361 | |
| 3362 | template <class _CharT, class _Traits> |
| 3363 | template <class _ForwardIterator> |
| 3364 | _ForwardIterator |
| 3365 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 3366 | _ForwardIterator __last) |
| 3367 | { |
| 3368 | if (__first != __last) |
| 3369 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3370 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3371 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3372 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 3373 | if (__temp != __first) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3374 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 3375 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3376 | } |
| 3377 | return __first; |
| 3378 | } |
| 3379 | |
| 3380 | template <class _CharT, class _Traits> |
| 3381 | template <class _ForwardIterator> |
| 3382 | _ForwardIterator |
| 3383 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 3384 | _ForwardIterator __last) |
| 3385 | { |
| 3386 | _ForwardIterator __temp = __first; |
| 3387 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 3388 | if (__temp == __first) |
| 3389 | { |
| 3390 | __temp = __parse_Back_open_paren(__first, __last); |
| 3391 | if (__temp != __first) |
| 3392 | { |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3393 | __push_begin_marked_subexpression(); |
| 3394 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3395 | __first = __parse_RE_expression(__temp, __last); |
| 3396 | __temp = __parse_Back_close_paren(__first, __last); |
| 3397 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3398 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3399 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3400 | __first = __temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3401 | } |
| 3402 | else |
| 3403 | __first = __parse_BACKREF(__first, __last); |
| 3404 | } |
| 3405 | return __first; |
| 3406 | } |
| 3407 | |
| 3408 | template <class _CharT, class _Traits> |
| 3409 | template <class _ForwardIterator> |
| 3410 | _ForwardIterator |
| 3411 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3412 | _ForwardIterator __first, |
| 3413 | _ForwardIterator __last) |
| 3414 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3415 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3416 | if (__temp == __first) |
| 3417 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3418 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3419 | if (__temp == __first) |
| 3420 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3421 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3422 | { |
| 3423 | __push_match_any(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3424 | ++__temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3425 | } |
| 3426 | else |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3427 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3428 | } |
| 3429 | } |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3430 | __first = __temp; |
| 3431 | return __first; |
| 3432 | } |
| 3433 | |
| 3434 | template <class _CharT, class _Traits> |
| 3435 | template <class _ForwardIterator> |
| 3436 | _ForwardIterator |
| 3437 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3438 | _ForwardIterator __first, |
| 3439 | _ForwardIterator __last) |
| 3440 | { |
| 3441 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3442 | if (__temp == __first) |
| 3443 | { |
| 3444 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3445 | if (__temp == __first) |
| 3446 | { |
| 3447 | if (__temp != __last && *__temp == '.') |
| 3448 | { |
| 3449 | __push_match_any(); |
| 3450 | ++__temp; |
| 3451 | } |
| 3452 | else |
| 3453 | __temp = __parse_bracket_expression(__first, __last); |
| 3454 | } |
| 3455 | } |
| 3456 | __first = __temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3457 | return __first; |
| 3458 | } |
| 3459 | |
| 3460 | template <class _CharT, class _Traits> |
| 3461 | template <class _ForwardIterator> |
| 3462 | _ForwardIterator |
| 3463 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3464 | _ForwardIterator __last) |
| 3465 | { |
| 3466 | if (__first != __last) |
| 3467 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3468 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3469 | if (__temp != __last) |
| 3470 | { |
| 3471 | if (*__first == '\\' && *__temp == '(') |
| 3472 | __first = ++__temp; |
| 3473 | } |
| 3474 | } |
| 3475 | return __first; |
| 3476 | } |
| 3477 | |
| 3478 | template <class _CharT, class _Traits> |
| 3479 | template <class _ForwardIterator> |
| 3480 | _ForwardIterator |
| 3481 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3482 | _ForwardIterator __last) |
| 3483 | { |
| 3484 | if (__first != __last) |
| 3485 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3486 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3487 | if (__temp != __last) |
| 3488 | { |
| 3489 | if (*__first == '\\' && *__temp == ')') |
| 3490 | __first = ++__temp; |
| 3491 | } |
| 3492 | } |
| 3493 | return __first; |
| 3494 | } |
| 3495 | |
| 3496 | template <class _CharT, class _Traits> |
| 3497 | template <class _ForwardIterator> |
| 3498 | _ForwardIterator |
| 3499 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3500 | _ForwardIterator __last) |
| 3501 | { |
| 3502 | if (__first != __last) |
| 3503 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3504 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3505 | if (__temp != __last) |
| 3506 | { |
| 3507 | if (*__first == '\\' && *__temp == '{') |
| 3508 | __first = ++__temp; |
| 3509 | } |
| 3510 | } |
| 3511 | return __first; |
| 3512 | } |
| 3513 | |
| 3514 | template <class _CharT, class _Traits> |
| 3515 | template <class _ForwardIterator> |
| 3516 | _ForwardIterator |
| 3517 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3518 | _ForwardIterator __last) |
| 3519 | { |
| 3520 | if (__first != __last) |
| 3521 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3522 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3523 | if (__temp != __last) |
| 3524 | { |
| 3525 | if (*__first == '\\' && *__temp == '}') |
| 3526 | __first = ++__temp; |
| 3527 | } |
| 3528 | } |
| 3529 | return __first; |
| 3530 | } |
| 3531 | |
| 3532 | template <class _CharT, class _Traits> |
| 3533 | template <class _ForwardIterator> |
| 3534 | _ForwardIterator |
| 3535 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_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); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 3541 | if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp)) |
| 3542 | __first = ++__temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3543 | } |
| 3544 | return __first; |
| 3545 | } |
| 3546 | |
| 3547 | template <class _CharT, class _Traits> |
| 3548 | template <class _ForwardIterator> |
| 3549 | _ForwardIterator |
| 3550 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3551 | _ForwardIterator __last) |
| 3552 | { |
| 3553 | if (__first != __last) |
| 3554 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3555 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3556 | if (__temp == __last && *__first == '$') |
| 3557 | return __first; |
| 3558 | // Not called inside a bracket |
| 3559 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3560 | return __first; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3561 | __push_char(*__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3562 | ++__first; |
| 3563 | } |
| 3564 | return __first; |
| 3565 | } |
| 3566 | |
| 3567 | template <class _CharT, class _Traits> |
| 3568 | template <class _ForwardIterator> |
| 3569 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3570 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3571 | _ForwardIterator __last) |
| 3572 | { |
| 3573 | if (__first != __last) |
| 3574 | { |
| 3575 | switch (*__first) |
| 3576 | { |
| 3577 | case '^': |
| 3578 | case '.': |
| 3579 | case '[': |
| 3580 | case '$': |
| 3581 | case '(': |
| 3582 | case '|': |
| 3583 | case '*': |
| 3584 | case '+': |
| 3585 | case '?': |
| 3586 | case '{': |
| 3587 | case '\\': |
| 3588 | break; |
| 3589 | case ')': |
| 3590 | if (__open_count_ == 0) |
| 3591 | { |
| 3592 | __push_char(*__first); |
| 3593 | ++__first; |
| 3594 | } |
| 3595 | break; |
| 3596 | default: |
| 3597 | __push_char(*__first); |
| 3598 | ++__first; |
| 3599 | break; |
| 3600 | } |
| 3601 | } |
| 3602 | return __first; |
| 3603 | } |
| 3604 | |
| 3605 | template <class _CharT, class _Traits> |
| 3606 | template <class _ForwardIterator> |
| 3607 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3608 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3609 | _ForwardIterator __last) |
| 3610 | { |
| 3611 | if (__first != __last) |
| 3612 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3613 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3614 | if (__temp != __last) |
| 3615 | { |
| 3616 | if (*__first == '\\') |
| 3617 | { |
| 3618 | switch (*__temp) |
| 3619 | { |
| 3620 | case '^': |
| 3621 | case '.': |
| 3622 | case '*': |
| 3623 | case '[': |
| 3624 | case '$': |
| 3625 | case '\\': |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3626 | __push_char(*__temp); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3627 | __first = ++__temp; |
| 3628 | break; |
| 3629 | } |
| 3630 | } |
| 3631 | } |
| 3632 | } |
| 3633 | return __first; |
| 3634 | } |
| 3635 | |
| 3636 | template <class _CharT, class _Traits> |
| 3637 | template <class _ForwardIterator> |
| 3638 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3639 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3640 | _ForwardIterator __last) |
| 3641 | { |
| 3642 | if (__first != __last) |
| 3643 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3644 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3645 | if (__temp != __last) |
| 3646 | { |
| 3647 | if (*__first == '\\') |
| 3648 | { |
| 3649 | switch (*__temp) |
| 3650 | { |
| 3651 | case '^': |
| 3652 | case '.': |
| 3653 | case '*': |
| 3654 | case '[': |
| 3655 | case '$': |
| 3656 | case '\\': |
| 3657 | case '(': |
| 3658 | case ')': |
| 3659 | case '|': |
| 3660 | case '+': |
| 3661 | case '?': |
| 3662 | case '{': |
Howard Hinnant | 73072eb | 2013-06-28 20:31:05 +0000 | [diff] [blame] | 3663 | case '}': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3664 | __push_char(*__temp); |
| 3665 | __first = ++__temp; |
| 3666 | break; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3667 | default: |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3668 | if (__get_grammar(__flags_) == awk) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3669 | __first = __parse_awk_escape(++__first, __last); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 3670 | else if(__test_back_ref(*__temp)) |
| 3671 | __first = ++__temp; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3672 | break; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3673 | } |
| 3674 | } |
| 3675 | } |
| 3676 | } |
| 3677 | return __first; |
| 3678 | } |
| 3679 | |
| 3680 | template <class _CharT, class _Traits> |
| 3681 | template <class _ForwardIterator> |
| 3682 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3683 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3684 | _ForwardIterator __last, |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3685 | __owns_one_state<_CharT>* __s, |
| 3686 | unsigned __mexp_begin, |
| 3687 | unsigned __mexp_end) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3688 | { |
| 3689 | if (__first != __last) |
| 3690 | { |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3691 | if (*__first == '*') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3692 | { |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3693 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3694 | ++__first; |
| 3695 | } |
| 3696 | else |
| 3697 | { |
| 3698 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3699 | if (__temp != __first) |
| 3700 | { |
| 3701 | int __min = 0; |
| 3702 | __first = __temp; |
| 3703 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 3704 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3705 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3706 | __first = __temp; |
| 3707 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3708 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3709 | if (*__first != ',') |
| 3710 | { |
| 3711 | __temp = __parse_Back_close_brace(__first, __last); |
| 3712 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3713 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3714 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3715 | true); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3716 | __first = __temp; |
| 3717 | } |
| 3718 | else |
| 3719 | { |
| 3720 | ++__first; // consume ',' |
| 3721 | int __max = -1; |
| 3722 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3723 | __temp = __parse_Back_close_brace(__first, __last); |
| 3724 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3725 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3726 | if (__max == -1) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3727 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3728 | else |
| 3729 | { |
| 3730 | if (__max < __min) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3731 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3732 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3733 | true); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3734 | } |
| 3735 | __first = __temp; |
| 3736 | } |
| 3737 | } |
| 3738 | } |
| 3739 | } |
| 3740 | return __first; |
| 3741 | } |
| 3742 | |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3743 | template <class _CharT, class _Traits> |
| 3744 | template <class _ForwardIterator> |
| 3745 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3746 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3747 | _ForwardIterator __last, |
| 3748 | __owns_one_state<_CharT>* __s, |
| 3749 | unsigned __mexp_begin, |
| 3750 | unsigned __mexp_end) |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3751 | { |
| 3752 | if (__first != __last) |
| 3753 | { |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3754 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3755 | switch (*__first) |
| 3756 | { |
| 3757 | case '*': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3758 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3759 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3760 | { |
| 3761 | ++__first; |
| 3762 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3763 | } |
| 3764 | else |
| 3765 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3766 | break; |
| 3767 | case '+': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3768 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3769 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3770 | { |
| 3771 | ++__first; |
| 3772 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3773 | } |
| 3774 | else |
| 3775 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3776 | break; |
| 3777 | case '?': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3778 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3779 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3780 | { |
| 3781 | ++__first; |
| 3782 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3783 | } |
| 3784 | else |
| 3785 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3786 | break; |
| 3787 | case '{': |
| 3788 | { |
| 3789 | int __min; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3790 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3791 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3792 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3793 | __first = __temp; |
| 3794 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3795 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3796 | switch (*__first) |
| 3797 | { |
| 3798 | case '}': |
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_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3804 | } |
| 3805 | else |
| 3806 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3807 | break; |
| 3808 | case ',': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3809 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3810 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3811 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3812 | if (*__first == '}') |
| 3813 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3814 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3815 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3816 | { |
| 3817 | ++__first; |
| 3818 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3819 | } |
| 3820 | else |
| 3821 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3822 | } |
| 3823 | else |
| 3824 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3825 | int __max = -1; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3826 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 3827 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3828 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3829 | __first = __temp; |
| 3830 | if (__first == __last || *__first != '}') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3831 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3832 | ++__first; |
| 3833 | if (__max < __min) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3834 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3835 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3836 | { |
| 3837 | ++__first; |
| 3838 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3839 | } |
| 3840 | else |
| 3841 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3842 | } |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3843 | break; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3844 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3845 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3846 | } |
| 3847 | } |
| 3848 | break; |
| 3849 | } |
| 3850 | } |
| 3851 | return __first; |
| 3852 | } |
| 3853 | |
| 3854 | template <class _CharT, class _Traits> |
| 3855 | template <class _ForwardIterator> |
| 3856 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3857 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3858 | _ForwardIterator __last) |
| 3859 | { |
| 3860 | if (__first != __last && *__first == '[') |
| 3861 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3862 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3863 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3864 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3865 | bool __negate = false; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3866 | if (*__first == '^') |
| 3867 | { |
| 3868 | ++__first; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3869 | __negate = true; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3870 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3871 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3872 | // __ml owned by *this |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3873 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3874 | __throw_regex_error<regex_constants::error_brack>(); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3875 | if (__get_grammar(__flags_) != ECMAScript && *__first == ']') |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3876 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3877 | __ml->__add_char(']'); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3878 | ++__first; |
| 3879 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3880 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3881 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3882 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3883 | if (*__first == '-') |
| 3884 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3885 | __ml->__add_char('-'); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3886 | ++__first; |
| 3887 | } |
| 3888 | if (__first == __last || *__first != ']') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3889 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3890 | ++__first; |
| 3891 | } |
| 3892 | return __first; |
| 3893 | } |
| 3894 | |
| 3895 | template <class _CharT, class _Traits> |
| 3896 | template <class _ForwardIterator> |
| 3897 | _ForwardIterator |
| 3898 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3899 | _ForwardIterator __last, |
| 3900 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3901 | { |
| 3902 | if (__first != __last) |
| 3903 | { |
| 3904 | while (true) |
| 3905 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3906 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3907 | __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3908 | if (__temp == __first) |
| 3909 | break; |
| 3910 | __first = __temp; |
| 3911 | } |
| 3912 | } |
| 3913 | return __first; |
| 3914 | } |
| 3915 | |
| 3916 | template <class _CharT, class _Traits> |
| 3917 | template <class _ForwardIterator> |
| 3918 | _ForwardIterator |
| 3919 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3920 | _ForwardIterator __last, |
| 3921 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3922 | { |
| 3923 | if (__first != __last && *__first != ']') |
| 3924 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3925 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3926 | basic_string<_CharT> __start_range; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3927 | if (__temp != __last && *__first == '[') |
| 3928 | { |
| 3929 | if (*__temp == '=') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3930 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3931 | else if (*__temp == ':') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3932 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3933 | else if (*__temp == '.') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3934 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3935 | } |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3936 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3937 | if (__start_range.empty()) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3938 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3939 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3940 | { |
| 3941 | if (__grammar == ECMAScript) |
| 3942 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3943 | else |
| 3944 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3945 | } |
| 3946 | else |
| 3947 | { |
| 3948 | __start_range = *__first; |
| 3949 | ++__first; |
| 3950 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3951 | } |
| 3952 | if (__first != __last && *__first != ']') |
| 3953 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3954 | __temp = _VSTD::next(__first); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3955 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3956 | { |
| 3957 | // parse a range |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3958 | basic_string<_CharT> __end_range; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3959 | __first = __temp; |
| 3960 | ++__temp; |
| 3961 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3962 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3963 | else |
| 3964 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3965 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3966 | { |
| 3967 | if (__grammar == ECMAScript) |
| 3968 | __first = __parse_class_escape(++__first, __last, |
| 3969 | __end_range, __ml); |
| 3970 | else |
| 3971 | __first = __parse_awk_escape(++__first, __last, |
| 3972 | &__end_range); |
| 3973 | } |
| 3974 | else |
| 3975 | { |
| 3976 | __end_range = *__first; |
| 3977 | ++__first; |
| 3978 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3979 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3980 | __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3981 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3982 | else if (!__start_range.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3983 | { |
| 3984 | if (__start_range.size() == 1) |
| 3985 | __ml->__add_char(__start_range[0]); |
| 3986 | else |
| 3987 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3988 | } |
| 3989 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3990 | else if (!__start_range.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3991 | { |
| 3992 | if (__start_range.size() == 1) |
| 3993 | __ml->__add_char(__start_range[0]); |
| 3994 | else |
| 3995 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3996 | } |
| 3997 | } |
| 3998 | return __first; |
| 3999 | } |
| 4000 | |
| 4001 | template <class _CharT, class _Traits> |
| 4002 | template <class _ForwardIterator> |
| 4003 | _ForwardIterator |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4004 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 4005 | _ForwardIterator __last, |
| 4006 | basic_string<_CharT>& __str, |
| 4007 | __bracket_expression<_CharT, _Traits>* __ml) |
| 4008 | { |
| 4009 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4010 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4011 | switch (*__first) |
| 4012 | { |
| 4013 | case 0: |
| 4014 | __str = *__first; |
| 4015 | return ++__first; |
| 4016 | case 'b': |
| 4017 | __str = _CharT(8); |
| 4018 | return ++__first; |
| 4019 | case 'd': |
| 4020 | __ml->__add_class(ctype_base::digit); |
| 4021 | return ++__first; |
| 4022 | case 'D': |
| 4023 | __ml->__add_neg_class(ctype_base::digit); |
| 4024 | return ++__first; |
| 4025 | case 's': |
| 4026 | __ml->__add_class(ctype_base::space); |
| 4027 | return ++__first; |
| 4028 | case 'S': |
| 4029 | __ml->__add_neg_class(ctype_base::space); |
| 4030 | return ++__first; |
| 4031 | case 'w': |
| 4032 | __ml->__add_class(ctype_base::alnum); |
| 4033 | __ml->__add_char('_'); |
| 4034 | return ++__first; |
| 4035 | case 'W': |
| 4036 | __ml->__add_neg_class(ctype_base::alnum); |
| 4037 | __ml->__add_neg_char('_'); |
| 4038 | return ++__first; |
| 4039 | } |
| 4040 | __first = __parse_character_escape(__first, __last, &__str); |
| 4041 | return __first; |
| 4042 | } |
| 4043 | |
| 4044 | template <class _CharT, class _Traits> |
| 4045 | template <class _ForwardIterator> |
| 4046 | _ForwardIterator |
| 4047 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 4048 | _ForwardIterator __last, |
| 4049 | basic_string<_CharT>* __str) |
| 4050 | { |
| 4051 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4052 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4053 | switch (*__first) |
| 4054 | { |
| 4055 | case '\\': |
| 4056 | case '"': |
| 4057 | case '/': |
| 4058 | if (__str) |
| 4059 | *__str = *__first; |
| 4060 | else |
| 4061 | __push_char(*__first); |
| 4062 | return ++__first; |
| 4063 | case 'a': |
| 4064 | if (__str) |
| 4065 | *__str = _CharT(7); |
| 4066 | else |
| 4067 | __push_char(_CharT(7)); |
| 4068 | return ++__first; |
| 4069 | case 'b': |
| 4070 | if (__str) |
| 4071 | *__str = _CharT(8); |
| 4072 | else |
| 4073 | __push_char(_CharT(8)); |
| 4074 | return ++__first; |
| 4075 | case 'f': |
| 4076 | if (__str) |
| 4077 | *__str = _CharT(0xC); |
| 4078 | else |
| 4079 | __push_char(_CharT(0xC)); |
| 4080 | return ++__first; |
| 4081 | case 'n': |
| 4082 | if (__str) |
| 4083 | *__str = _CharT(0xA); |
| 4084 | else |
| 4085 | __push_char(_CharT(0xA)); |
| 4086 | return ++__first; |
| 4087 | case 'r': |
| 4088 | if (__str) |
| 4089 | *__str = _CharT(0xD); |
| 4090 | else |
| 4091 | __push_char(_CharT(0xD)); |
| 4092 | return ++__first; |
| 4093 | case 't': |
| 4094 | if (__str) |
| 4095 | *__str = _CharT(0x9); |
| 4096 | else |
| 4097 | __push_char(_CharT(0x9)); |
| 4098 | return ++__first; |
| 4099 | case 'v': |
| 4100 | if (__str) |
| 4101 | *__str = _CharT(0xB); |
| 4102 | else |
| 4103 | __push_char(_CharT(0xB)); |
| 4104 | return ++__first; |
| 4105 | } |
| 4106 | if ('0' <= *__first && *__first <= '7') |
| 4107 | { |
| 4108 | unsigned __val = *__first - '0'; |
| 4109 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 4110 | { |
| 4111 | __val = 8 * __val + *__first - '0'; |
| 4112 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
Howard Hinnant | a309687 | 2013-07-02 17:43:31 +0000 | [diff] [blame] | 4113 | __val = 8 * __val + *__first++ - '0'; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4114 | } |
| 4115 | if (__str) |
| 4116 | *__str = _CharT(__val); |
| 4117 | else |
| 4118 | __push_char(_CharT(__val)); |
| 4119 | } |
| 4120 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4121 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4122 | return __first; |
| 4123 | } |
| 4124 | |
| 4125 | template <class _CharT, class _Traits> |
| 4126 | template <class _ForwardIterator> |
| 4127 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4128 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4129 | _ForwardIterator __last, |
| 4130 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4131 | { |
| 4132 | // Found [= |
| 4133 | // This means =] must exist |
| 4134 | value_type _Equal_close[2] = {'=', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4135 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4136 | _Equal_close+2); |
| 4137 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4138 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4139 | // [__first, __temp) contains all text in [= ... =] |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4140 | string_type __collate_name = |
| 4141 | __traits_.lookup_collatename(__first, __temp); |
| 4142 | if (__collate_name.empty()) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4143 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4144 | string_type __equiv_name = |
| 4145 | __traits_.transform_primary(__collate_name.begin(), |
| 4146 | __collate_name.end()); |
| 4147 | if (!__equiv_name.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4148 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4149 | else |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4150 | { |
| 4151 | switch (__collate_name.size()) |
| 4152 | { |
| 4153 | case 1: |
| 4154 | __ml->__add_char(__collate_name[0]); |
| 4155 | break; |
| 4156 | case 2: |
| 4157 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 4158 | break; |
| 4159 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4160 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4161 | } |
| 4162 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4163 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4164 | return __first; |
| 4165 | } |
| 4166 | |
| 4167 | template <class _CharT, class _Traits> |
| 4168 | template <class _ForwardIterator> |
| 4169 | _ForwardIterator |
| 4170 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4171 | _ForwardIterator __last, |
| 4172 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4173 | { |
| 4174 | // Found [: |
| 4175 | // This means :] must exist |
| 4176 | value_type _Colon_close[2] = {':', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4177 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4178 | _Colon_close+2); |
| 4179 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4180 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4181 | // [__first, __temp) contains all text in [: ... :] |
| 4182 | typedef typename _Traits::char_class_type char_class_type; |
| 4183 | char_class_type __class_type = |
| 4184 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 4185 | if (__class_type == 0) |
Mikhail Maltsev | 6ef945b | 2018-01-24 12:45:18 +0000 | [diff] [blame] | 4186 | __throw_regex_error<regex_constants::error_ctype>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4187 | __ml->__add_class(__class_type); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4188 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4189 | return __first; |
| 4190 | } |
| 4191 | |
| 4192 | template <class _CharT, class _Traits> |
| 4193 | template <class _ForwardIterator> |
| 4194 | _ForwardIterator |
| 4195 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4196 | _ForwardIterator __last, |
| 4197 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4198 | { |
| 4199 | // Found [. |
| 4200 | // This means .] must exist |
| 4201 | value_type _Dot_close[2] = {'.', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4202 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4203 | _Dot_close+2); |
| 4204 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4205 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4206 | // [__first, __temp) contains all text in [. ... .] |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4207 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 4208 | switch (__col_sym.size()) |
| 4209 | { |
| 4210 | case 1: |
| 4211 | case 2: |
| 4212 | break; |
| 4213 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4214 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4215 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4216 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4217 | return __first; |
| 4218 | } |
| 4219 | |
| 4220 | template <class _CharT, class _Traits> |
| 4221 | template <class _ForwardIterator> |
| 4222 | _ForwardIterator |
| 4223 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 4224 | _ForwardIterator __last, |
| 4225 | int& __c) |
| 4226 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4227 | if (__first != __last ) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4228 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4229 | int __val = __traits_.value(*__first, 10); |
| 4230 | if ( __val != -1 ) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4231 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4232 | __c = __val; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4233 | for (++__first; |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4234 | __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; |
| 4235 | ++__first) |
| 4236 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4237 | if (__c >= numeric_limits<int>::max() / 10) |
Marshall Clow | 863ae38 | 2017-10-19 17:39:16 +0000 | [diff] [blame] | 4238 | __throw_regex_error<regex_constants::error_badbrace>(); |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4239 | __c *= 10; |
| 4240 | __c += __val; |
| 4241 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4242 | } |
| 4243 | } |
| 4244 | return __first; |
| 4245 | } |
| 4246 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4247 | template <class _CharT, class _Traits> |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4248 | template <class _ForwardIterator> |
| 4249 | _ForwardIterator |
| 4250 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 4251 | _ForwardIterator __last) |
| 4252 | { |
| 4253 | __owns_one_state<_CharT>* __sa = __end_; |
| 4254 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 4255 | if (__temp == __first) |
| 4256 | __push_empty(); |
| 4257 | __first = __temp; |
| 4258 | while (__first != __last && *__first == '|') |
| 4259 | { |
| 4260 | __owns_one_state<_CharT>* __sb = __end_; |
| 4261 | __temp = __parse_alternative(++__first, __last); |
| 4262 | if (__temp == __first) |
| 4263 | __push_empty(); |
| 4264 | __push_alternation(__sa, __sb); |
| 4265 | __first = __temp; |
| 4266 | } |
| 4267 | return __first; |
| 4268 | } |
| 4269 | |
| 4270 | template <class _CharT, class _Traits> |
| 4271 | template <class _ForwardIterator> |
| 4272 | _ForwardIterator |
| 4273 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 4274 | _ForwardIterator __last) |
| 4275 | { |
| 4276 | while (true) |
| 4277 | { |
| 4278 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 4279 | if (__temp == __first) |
| 4280 | break; |
| 4281 | __first = __temp; |
| 4282 | } |
| 4283 | return __first; |
| 4284 | } |
| 4285 | |
| 4286 | template <class _CharT, class _Traits> |
| 4287 | template <class _ForwardIterator> |
| 4288 | _ForwardIterator |
| 4289 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 4290 | _ForwardIterator __last) |
| 4291 | { |
| 4292 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 4293 | if (__temp == __first) |
| 4294 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4295 | __owns_one_state<_CharT>* __e = __end_; |
| 4296 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4297 | __temp = __parse_atom(__first, __last); |
| 4298 | if (__temp != __first) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4299 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 4300 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4301 | } |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4302 | else |
| 4303 | __first = __temp; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4304 | return __first; |
| 4305 | } |
| 4306 | |
| 4307 | template <class _CharT, class _Traits> |
| 4308 | template <class _ForwardIterator> |
| 4309 | _ForwardIterator |
| 4310 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 4311 | _ForwardIterator __last) |
| 4312 | { |
| 4313 | if (__first != __last) |
| 4314 | { |
| 4315 | switch (*__first) |
| 4316 | { |
| 4317 | case '^': |
| 4318 | __push_l_anchor(); |
| 4319 | ++__first; |
| 4320 | break; |
| 4321 | case '$': |
| 4322 | __push_r_anchor(); |
| 4323 | ++__first; |
| 4324 | break; |
| 4325 | case '\\': |
| 4326 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4327 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4328 | if (__temp != __last) |
| 4329 | { |
| 4330 | if (*__temp == 'b') |
| 4331 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4332 | __push_word_boundary(false); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4333 | __first = ++__temp; |
| 4334 | } |
| 4335 | else if (*__temp == 'B') |
| 4336 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4337 | __push_word_boundary(true); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4338 | __first = ++__temp; |
| 4339 | } |
| 4340 | } |
| 4341 | } |
| 4342 | break; |
| 4343 | case '(': |
| 4344 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4345 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4346 | if (__temp != __last && *__temp == '?') |
| 4347 | { |
| 4348 | if (++__temp != __last) |
| 4349 | { |
| 4350 | switch (*__temp) |
| 4351 | { |
| 4352 | case '=': |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4353 | { |
| 4354 | basic_regex __exp; |
| 4355 | __exp.__flags_ = __flags_; |
| 4356 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4357 | unsigned __mexp = __exp.__marked_count_; |
| 4358 | __push_lookahead(_VSTD::move(__exp), false, __marked_count_); |
| 4359 | __marked_count_ += __mexp; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4360 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4361 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4362 | __first = ++__temp; |
| 4363 | } |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4364 | break; |
| 4365 | case '!': |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4366 | { |
| 4367 | basic_regex __exp; |
| 4368 | __exp.__flags_ = __flags_; |
| 4369 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4370 | unsigned __mexp = __exp.__marked_count_; |
| 4371 | __push_lookahead(_VSTD::move(__exp), true, __marked_count_); |
| 4372 | __marked_count_ += __mexp; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4373 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4374 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4375 | __first = ++__temp; |
| 4376 | } |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4377 | break; |
| 4378 | } |
| 4379 | } |
| 4380 | } |
| 4381 | } |
| 4382 | break; |
| 4383 | } |
| 4384 | } |
| 4385 | return __first; |
| 4386 | } |
| 4387 | |
| 4388 | template <class _CharT, class _Traits> |
| 4389 | template <class _ForwardIterator> |
| 4390 | _ForwardIterator |
| 4391 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4392 | _ForwardIterator __last) |
| 4393 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4394 | if (__first != __last) |
| 4395 | { |
| 4396 | switch (*__first) |
| 4397 | { |
| 4398 | case '.': |
| 4399 | __push_match_any_but_newline(); |
| 4400 | ++__first; |
| 4401 | break; |
| 4402 | case '\\': |
| 4403 | __first = __parse_atom_escape(__first, __last); |
| 4404 | break; |
| 4405 | case '[': |
| 4406 | __first = __parse_bracket_expression(__first, __last); |
| 4407 | break; |
| 4408 | case '(': |
| 4409 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4410 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4411 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4412 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4413 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4414 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4415 | { |
| 4416 | ++__open_count_; |
| 4417 | __first = __parse_ecma_exp(++__temp, __last); |
| 4418 | if (__first == __last || *__first != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4419 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4420 | --__open_count_; |
| 4421 | ++__first; |
| 4422 | } |
| 4423 | else |
| 4424 | { |
| 4425 | __push_begin_marked_subexpression(); |
| 4426 | unsigned __temp_count = __marked_count_; |
| 4427 | ++__open_count_; |
| 4428 | __first = __parse_ecma_exp(__first, __last); |
| 4429 | if (__first == __last || *__first != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4430 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4431 | __push_end_marked_subexpression(__temp_count); |
| 4432 | --__open_count_; |
| 4433 | ++__first; |
| 4434 | } |
| 4435 | } |
| 4436 | break; |
Marshall Clow | 8205821 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4437 | case '*': |
| 4438 | case '+': |
| 4439 | case '?': |
| 4440 | case '{': |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4441 | __throw_regex_error<regex_constants::error_badrepeat>(); |
Marshall Clow | 8205821 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4442 | break; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4443 | default: |
| 4444 | __first = __parse_pattern_character(__first, __last); |
| 4445 | break; |
| 4446 | } |
| 4447 | } |
| 4448 | return __first; |
| 4449 | } |
| 4450 | |
| 4451 | template <class _CharT, class _Traits> |
| 4452 | template <class _ForwardIterator> |
| 4453 | _ForwardIterator |
| 4454 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4455 | _ForwardIterator __last) |
| 4456 | { |
| 4457 | if (__first != __last && *__first == '\\') |
| 4458 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4459 | _ForwardIterator __t1 = _VSTD::next(__first); |
Marshall Clow | db9633c | 2016-01-19 00:50:37 +0000 | [diff] [blame] | 4460 | if (__t1 == __last) |
| 4461 | __throw_regex_error<regex_constants::error_escape>(); |
| 4462 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4463 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4464 | if (__t2 != __t1) |
| 4465 | __first = __t2; |
| 4466 | else |
| 4467 | { |
| 4468 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4469 | if (__t2 != __t1) |
| 4470 | __first = __t2; |
| 4471 | else |
| 4472 | { |
| 4473 | __t2 = __parse_character_escape(__t1, __last); |
| 4474 | if (__t2 != __t1) |
| 4475 | __first = __t2; |
| 4476 | } |
| 4477 | } |
| 4478 | } |
| 4479 | return __first; |
| 4480 | } |
| 4481 | |
| 4482 | template <class _CharT, class _Traits> |
| 4483 | template <class _ForwardIterator> |
| 4484 | _ForwardIterator |
| 4485 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4486 | _ForwardIterator __last) |
| 4487 | { |
| 4488 | if (__first != __last) |
| 4489 | { |
| 4490 | if (*__first == '0') |
| 4491 | { |
| 4492 | __push_char(_CharT()); |
| 4493 | ++__first; |
| 4494 | } |
| 4495 | else if ('1' <= *__first && *__first <= '9') |
| 4496 | { |
| 4497 | unsigned __v = *__first - '0'; |
Marshall Clow | dc03ec7 | 2016-12-24 17:21:03 +0000 | [diff] [blame] | 4498 | for (++__first; |
| 4499 | __first != __last && '0' <= *__first && *__first <= '9'; ++__first) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4500 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4501 | if (__v >= numeric_limits<unsigned>::max() / 10) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4502 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4503 | __v = 10 * __v + *__first - '0'; |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4504 | } |
| 4505 | if (__v == 0 || __v > mark_count()) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4506 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4507 | __push_back_ref(__v); |
| 4508 | } |
| 4509 | } |
| 4510 | return __first; |
| 4511 | } |
| 4512 | |
| 4513 | template <class _CharT, class _Traits> |
| 4514 | template <class _ForwardIterator> |
| 4515 | _ForwardIterator |
| 4516 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4517 | _ForwardIterator __last) |
| 4518 | { |
| 4519 | if (__first != __last) |
| 4520 | { |
| 4521 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4522 | switch (*__first) |
| 4523 | { |
| 4524 | case 'd': |
| 4525 | __ml = __start_matching_list(false); |
| 4526 | __ml->__add_class(ctype_base::digit); |
| 4527 | ++__first; |
| 4528 | break; |
| 4529 | case 'D': |
| 4530 | __ml = __start_matching_list(true); |
| 4531 | __ml->__add_class(ctype_base::digit); |
| 4532 | ++__first; |
| 4533 | break; |
| 4534 | case 's': |
| 4535 | __ml = __start_matching_list(false); |
| 4536 | __ml->__add_class(ctype_base::space); |
| 4537 | ++__first; |
| 4538 | break; |
| 4539 | case 'S': |
| 4540 | __ml = __start_matching_list(true); |
| 4541 | __ml->__add_class(ctype_base::space); |
| 4542 | ++__first; |
| 4543 | break; |
| 4544 | case 'w': |
| 4545 | __ml = __start_matching_list(false); |
| 4546 | __ml->__add_class(ctype_base::alnum); |
| 4547 | __ml->__add_char('_'); |
| 4548 | ++__first; |
| 4549 | break; |
| 4550 | case 'W': |
| 4551 | __ml = __start_matching_list(true); |
| 4552 | __ml->__add_class(ctype_base::alnum); |
| 4553 | __ml->__add_char('_'); |
| 4554 | ++__first; |
| 4555 | break; |
| 4556 | } |
| 4557 | } |
| 4558 | return __first; |
| 4559 | } |
| 4560 | |
| 4561 | template <class _CharT, class _Traits> |
| 4562 | template <class _ForwardIterator> |
| 4563 | _ForwardIterator |
| 4564 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4565 | _ForwardIterator __last, |
| 4566 | basic_string<_CharT>* __str) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4567 | { |
| 4568 | if (__first != __last) |
| 4569 | { |
| 4570 | _ForwardIterator __t; |
| 4571 | unsigned __sum = 0; |
| 4572 | int __hd; |
| 4573 | switch (*__first) |
| 4574 | { |
| 4575 | case 'f': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4576 | if (__str) |
| 4577 | *__str = _CharT(0xC); |
| 4578 | else |
| 4579 | __push_char(_CharT(0xC)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4580 | ++__first; |
| 4581 | break; |
| 4582 | case 'n': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4583 | if (__str) |
| 4584 | *__str = _CharT(0xA); |
| 4585 | else |
| 4586 | __push_char(_CharT(0xA)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4587 | ++__first; |
| 4588 | break; |
| 4589 | case 'r': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4590 | if (__str) |
| 4591 | *__str = _CharT(0xD); |
| 4592 | else |
| 4593 | __push_char(_CharT(0xD)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4594 | ++__first; |
| 4595 | break; |
| 4596 | case 't': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4597 | if (__str) |
| 4598 | *__str = _CharT(0x9); |
| 4599 | else |
| 4600 | __push_char(_CharT(0x9)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4601 | ++__first; |
| 4602 | break; |
| 4603 | case 'v': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4604 | if (__str) |
| 4605 | *__str = _CharT(0xB); |
| 4606 | else |
| 4607 | __push_char(_CharT(0xB)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4608 | ++__first; |
| 4609 | break; |
| 4610 | case 'c': |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4611 | if ((__t = _VSTD::next(__first)) != __last) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4612 | { |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4613 | if (('A' <= *__t && *__t <= 'Z') || |
Howard Hinnant | d04741b | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4614 | ('a' <= *__t && *__t <= 'z')) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4615 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4616 | if (__str) |
| 4617 | *__str = _CharT(*__t % 32); |
| 4618 | else |
| 4619 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4620 | __first = ++__t; |
| 4621 | } |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4622 | else |
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 | } |
Howard Hinnant | d04741b | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4625 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4626 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4627 | break; |
| 4628 | case 'u': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4629 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4630 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4631 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4632 | __hd = __traits_.value(*__first, 16); |
| 4633 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4634 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4635 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4636 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4637 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4638 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4639 | __hd = __traits_.value(*__first, 16); |
| 4640 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4641 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4642 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 4643 | // fallthrough |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4644 | case 'x': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4645 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4646 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4647 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4648 | __hd = __traits_.value(*__first, 16); |
| 4649 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4650 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4651 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4652 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4653 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4654 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4655 | __hd = __traits_.value(*__first, 16); |
| 4656 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4657 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4658 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4659 | if (__str) |
| 4660 | *__str = _CharT(__sum); |
| 4661 | else |
| 4662 | __push_char(_CharT(__sum)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4663 | ++__first; |
| 4664 | break; |
Marshall Clow | f6cef0d | 2014-05-21 16:29:50 +0000 | [diff] [blame] | 4665 | case '0': |
| 4666 | if (__str) |
| 4667 | *__str = _CharT(0); |
| 4668 | else |
| 4669 | __push_char(_CharT(0)); |
| 4670 | ++__first; |
| 4671 | break; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4672 | default: |
| 4673 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4674 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4675 | if (__str) |
| 4676 | *__str = *__first; |
| 4677 | else |
| 4678 | __push_char(*__first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4679 | ++__first; |
| 4680 | } |
Howard Hinnant | 4f7a1f5 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 4681 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4682 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4683 | break; |
| 4684 | } |
| 4685 | } |
| 4686 | return __first; |
| 4687 | } |
| 4688 | |
| 4689 | template <class _CharT, class _Traits> |
| 4690 | template <class _ForwardIterator> |
| 4691 | _ForwardIterator |
| 4692 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4693 | _ForwardIterator __last) |
| 4694 | { |
| 4695 | if (__first != __last) |
| 4696 | { |
| 4697 | switch (*__first) |
| 4698 | { |
| 4699 | case '^': |
| 4700 | case '$': |
| 4701 | case '\\': |
| 4702 | case '.': |
| 4703 | case '*': |
| 4704 | case '+': |
| 4705 | case '?': |
| 4706 | case '(': |
| 4707 | case ')': |
| 4708 | case '[': |
| 4709 | case ']': |
| 4710 | case '{': |
| 4711 | case '}': |
| 4712 | case '|': |
| 4713 | break; |
| 4714 | default: |
| 4715 | __push_char(*__first); |
| 4716 | ++__first; |
| 4717 | break; |
| 4718 | } |
| 4719 | } |
| 4720 | return __first; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4721 | } |
| 4722 | |
| 4723 | template <class _CharT, class _Traits> |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4724 | template <class _ForwardIterator> |
| 4725 | _ForwardIterator |
| 4726 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4727 | _ForwardIterator __last) |
| 4728 | { |
| 4729 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4730 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4731 | if (__t1 != __first) |
| 4732 | __parse_basic_reg_exp(__first, __t1); |
| 4733 | else |
| 4734 | __push_empty(); |
| 4735 | __first = __t1; |
| 4736 | if (__first != __last) |
| 4737 | ++__first; |
| 4738 | while (__first != __last) |
| 4739 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4740 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4741 | __owns_one_state<_CharT>* __sb = __end_; |
| 4742 | if (__t1 != __first) |
| 4743 | __parse_basic_reg_exp(__first, __t1); |
| 4744 | else |
| 4745 | __push_empty(); |
| 4746 | __push_alternation(__sa, __sb); |
| 4747 | __first = __t1; |
| 4748 | if (__first != __last) |
| 4749 | ++__first; |
| 4750 | } |
| 4751 | return __first; |
| 4752 | } |
| 4753 | |
| 4754 | template <class _CharT, class _Traits> |
| 4755 | template <class _ForwardIterator> |
| 4756 | _ForwardIterator |
| 4757 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4758 | _ForwardIterator __last) |
| 4759 | { |
| 4760 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4761 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4762 | if (__t1 != __first) |
| 4763 | __parse_extended_reg_exp(__first, __t1); |
| 4764 | else |
| 4765 | __push_empty(); |
| 4766 | __first = __t1; |
| 4767 | if (__first != __last) |
| 4768 | ++__first; |
| 4769 | while (__first != __last) |
| 4770 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4771 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4772 | __owns_one_state<_CharT>* __sb = __end_; |
| 4773 | if (__t1 != __first) |
| 4774 | __parse_extended_reg_exp(__first, __t1); |
| 4775 | else |
| 4776 | __push_empty(); |
| 4777 | __push_alternation(__sa, __sb); |
| 4778 | __first = __t1; |
| 4779 | if (__first != __last) |
| 4780 | ++__first; |
| 4781 | } |
| 4782 | return __first; |
| 4783 | } |
| 4784 | |
| 4785 | template <class _CharT, class _Traits> |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4786 | bool |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 4787 | basic_regex<_CharT, _Traits>::__test_back_ref(_CharT __c) |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4788 | { |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 4789 | unsigned __val = __traits_.value(__c, 10); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4790 | if (__val >= 1 && __val <= 9) |
| 4791 | { |
Mark de Wever | d324e5f | 2020-02-20 18:13:38 -0500 | [diff] [blame] | 4792 | if (__val > mark_count()) |
| 4793 | __throw_regex_error<regex_constants::error_backref>(); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4794 | __push_back_ref(__val); |
| 4795 | return true; |
| 4796 | } |
| 4797 | |
| 4798 | return false; |
| 4799 | } |
| 4800 | |
| 4801 | template <class _CharT, class _Traits> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4802 | void |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4803 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4804 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4805 | bool __greedy) |
| 4806 | { |
| 4807 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4808 | __end_->first() = nullptr; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4809 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4810 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4811 | __min, __max)); |
| 4812 | __s->first() = nullptr; |
| 4813 | __e1.release(); |
| 4814 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4815 | __end_ = __e2->second(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4816 | __s->first() = __e2.release(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4817 | ++__loop_count_; |
| 4818 | } |
| 4819 | |
| 4820 | template <class _CharT, class _Traits> |
| 4821 | void |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4822 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4823 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4824 | if (flags() & icase) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4825 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4826 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4827 | else if (flags() & collate) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4828 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4829 | (__traits_, __c, __end_->first()); |
| 4830 | else |
| 4831 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4832 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4833 | } |
| 4834 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4835 | template <class _CharT, class _Traits> |
| 4836 | void |
| 4837 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4838 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4839 | if (!(__flags_ & nosubs)) |
| 4840 | { |
| 4841 | __end_->first() = |
| 4842 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4843 | __end_->first()); |
| 4844 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4845 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4846 | } |
| 4847 | |
| 4848 | template <class _CharT, class _Traits> |
| 4849 | void |
| 4850 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4851 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4852 | if (!(__flags_ & nosubs)) |
| 4853 | { |
| 4854 | __end_->first() = |
| 4855 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4856 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4857 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4858 | } |
| 4859 | |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4860 | template <class _CharT, class _Traits> |
| 4861 | void |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4862 | basic_regex<_CharT, _Traits>::__push_l_anchor() |
| 4863 | { |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 4864 | __end_->first() = new __l_anchor_multiline<_CharT>(__use_multiline(), __end_->first()); |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4865 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4866 | } |
| 4867 | |
| 4868 | template <class _CharT, class _Traits> |
| 4869 | void |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4870 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4871 | { |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 4872 | __end_->first() = new __r_anchor_multiline<_CharT>(__use_multiline(), __end_->first()); |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4873 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4874 | } |
| 4875 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4876 | template <class _CharT, class _Traits> |
| 4877 | void |
| 4878 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4879 | { |
| 4880 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4881 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4882 | } |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4883 | |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4884 | template <class _CharT, class _Traits> |
| 4885 | void |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4886 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4887 | { |
| 4888 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4889 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4890 | } |
| 4891 | |
| 4892 | template <class _CharT, class _Traits> |
| 4893 | void |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4894 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4895 | { |
| 4896 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4897 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4898 | } |
| 4899 | |
| 4900 | template <class _CharT, class _Traits> |
| 4901 | void |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4902 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4903 | { |
| 4904 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4905 | __end_->first()); |
| 4906 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4907 | } |
| 4908 | |
| 4909 | template <class _CharT, class _Traits> |
| 4910 | void |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4911 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4912 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4913 | if (flags() & icase) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4914 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4915 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4916 | else if (flags() & collate) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4917 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4918 | (__traits_, __i, __end_->first()); |
| 4919 | else |
| 4920 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4921 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4922 | } |
| 4923 | |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4924 | template <class _CharT, class _Traits> |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4925 | void |
| 4926 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4927 | __owns_one_state<_CharT>* __ea) |
| 4928 | { |
| 4929 | __sa->first() = new __alternate<_CharT>( |
| 4930 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4931 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4932 | __ea->first() = nullptr; |
| 4933 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4934 | __end_->first() = nullptr; |
| 4935 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4936 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4937 | } |
| 4938 | |
| 4939 | template <class _CharT, class _Traits> |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4940 | __bracket_expression<_CharT, _Traits>* |
| 4941 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4942 | { |
| 4943 | __bracket_expression<_CharT, _Traits>* __r = |
| 4944 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4945 | __negate, __flags_ & icase, |
| 4946 | __flags_ & collate); |
| 4947 | __end_->first() = __r; |
| 4948 | __end_ = __r; |
| 4949 | return __r; |
| 4950 | } |
| 4951 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4952 | template <class _CharT, class _Traits> |
| 4953 | void |
| 4954 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4955 | bool __invert, |
| 4956 | unsigned __mexp) |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4957 | { |
| 4958 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4959 | __end_->first(), __mexp); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4960 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4961 | } |
| 4962 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4963 | // sub_match |
| 4964 | |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4965 | typedef sub_match<const char*> csub_match; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4966 | typedef sub_match<string::const_iterator> ssub_match; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4967 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4968 | typedef sub_match<const wchar_t*> wcsub_match; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4969 | typedef sub_match<wstring::const_iterator> wssub_match; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4970 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4971 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4972 | template <class _BidirectionalIterator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4973 | class |
| 4974 | _LIBCPP_TEMPLATE_VIS |
| 4975 | _LIBCPP_PREFERRED_NAME(csub_match) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4976 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4977 | _LIBCPP_PREFERRED_NAME(ssub_match) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4978 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4979 | sub_match |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4980 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4981 | { |
| 4982 | public: |
| 4983 | typedef _BidirectionalIterator iterator; |
| 4984 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4985 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4986 | typedef basic_string<value_type> string_type; |
| 4987 | |
| 4988 | bool matched; |
| 4989 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4990 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 4991 | _LIBCPP_CONSTEXPR sub_match() : matched() {} |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 4992 | |
| 4993 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4994 | difference_type length() const |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4995 | {return matched ? _VSTD::distance(this->first, this->second) : 0;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4996 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4997 | string_type str() const |
| 4998 | {return matched ? string_type(this->first, this->second) : string_type();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4999 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5000 | operator string_type() const |
| 5001 | {return str();} |
| 5002 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5003 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5004 | int compare(const sub_match& __s) const |
| 5005 | {return str().compare(__s.str());} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5006 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5007 | int compare(const string_type& __s) const |
| 5008 | {return str().compare(__s);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5009 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5010 | int compare(const value_type* __s) const |
| 5011 | {return str().compare(__s);} |
| 5012 | }; |
| 5013 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5014 | template <class _BiIter> |
| 5015 | inline _LIBCPP_INLINE_VISIBILITY |
| 5016 | bool |
| 5017 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5018 | { |
| 5019 | return __x.compare(__y) == 0; |
| 5020 | } |
| 5021 | |
| 5022 | template <class _BiIter> |
| 5023 | inline _LIBCPP_INLINE_VISIBILITY |
| 5024 | bool |
| 5025 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5026 | { |
| 5027 | return !(__x == __y); |
| 5028 | } |
| 5029 | |
| 5030 | template <class _BiIter> |
| 5031 | inline _LIBCPP_INLINE_VISIBILITY |
| 5032 | bool |
| 5033 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5034 | { |
| 5035 | return __x.compare(__y) < 0; |
| 5036 | } |
| 5037 | |
| 5038 | template <class _BiIter> |
| 5039 | inline _LIBCPP_INLINE_VISIBILITY |
| 5040 | bool |
| 5041 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5042 | { |
| 5043 | return !(__y < __x); |
| 5044 | } |
| 5045 | |
| 5046 | template <class _BiIter> |
| 5047 | inline _LIBCPP_INLINE_VISIBILITY |
| 5048 | bool |
| 5049 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5050 | { |
| 5051 | return !(__x < __y); |
| 5052 | } |
| 5053 | |
| 5054 | template <class _BiIter> |
| 5055 | inline _LIBCPP_INLINE_VISIBILITY |
| 5056 | bool |
| 5057 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5058 | { |
| 5059 | return __y < __x; |
| 5060 | } |
| 5061 | |
| 5062 | template <class _BiIter, class _ST, class _SA> |
| 5063 | inline _LIBCPP_INLINE_VISIBILITY |
| 5064 | bool |
| 5065 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5066 | const sub_match<_BiIter>& __y) |
| 5067 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5068 | 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] | 5069 | } |
| 5070 | |
| 5071 | template <class _BiIter, class _ST, class _SA> |
| 5072 | inline _LIBCPP_INLINE_VISIBILITY |
| 5073 | bool |
| 5074 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5075 | const sub_match<_BiIter>& __y) |
| 5076 | { |
| 5077 | return !(__x == __y); |
| 5078 | } |
| 5079 | |
| 5080 | template <class _BiIter, class _ST, class _SA> |
| 5081 | inline _LIBCPP_INLINE_VISIBILITY |
| 5082 | bool |
| 5083 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5084 | const sub_match<_BiIter>& __y) |
| 5085 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5086 | 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] | 5087 | } |
| 5088 | |
| 5089 | template <class _BiIter, class _ST, class _SA> |
| 5090 | inline _LIBCPP_INLINE_VISIBILITY |
| 5091 | bool |
| 5092 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5093 | const sub_match<_BiIter>& __y) |
| 5094 | { |
| 5095 | return __y < __x; |
| 5096 | } |
| 5097 | |
| 5098 | template <class _BiIter, class _ST, class _SA> |
| 5099 | inline _LIBCPP_INLINE_VISIBILITY |
| 5100 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5101 | const sub_match<_BiIter>& __y) |
| 5102 | { |
| 5103 | return !(__x < __y); |
| 5104 | } |
| 5105 | |
| 5106 | template <class _BiIter, class _ST, class _SA> |
| 5107 | inline _LIBCPP_INLINE_VISIBILITY |
| 5108 | bool |
| 5109 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5110 | const sub_match<_BiIter>& __y) |
| 5111 | { |
| 5112 | return !(__y < __x); |
| 5113 | } |
| 5114 | |
| 5115 | template <class _BiIter, class _ST, class _SA> |
| 5116 | inline _LIBCPP_INLINE_VISIBILITY |
| 5117 | bool |
| 5118 | operator==(const sub_match<_BiIter>& __x, |
| 5119 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5120 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5121 | 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] | 5122 | } |
| 5123 | |
| 5124 | template <class _BiIter, class _ST, class _SA> |
| 5125 | inline _LIBCPP_INLINE_VISIBILITY |
| 5126 | bool |
| 5127 | operator!=(const sub_match<_BiIter>& __x, |
| 5128 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5129 | { |
| 5130 | return !(__x == __y); |
| 5131 | } |
| 5132 | |
| 5133 | template <class _BiIter, class _ST, class _SA> |
| 5134 | inline _LIBCPP_INLINE_VISIBILITY |
| 5135 | bool |
| 5136 | operator<(const sub_match<_BiIter>& __x, |
| 5137 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5138 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5139 | 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] | 5140 | } |
| 5141 | |
| 5142 | template <class _BiIter, class _ST, class _SA> |
| 5143 | inline _LIBCPP_INLINE_VISIBILITY |
| 5144 | bool operator>(const sub_match<_BiIter>& __x, |
| 5145 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5146 | { |
| 5147 | return __y < __x; |
| 5148 | } |
| 5149 | |
| 5150 | template <class _BiIter, class _ST, class _SA> |
| 5151 | inline _LIBCPP_INLINE_VISIBILITY |
| 5152 | bool |
| 5153 | operator>=(const sub_match<_BiIter>& __x, |
| 5154 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5155 | { |
| 5156 | return !(__x < __y); |
| 5157 | } |
| 5158 | |
| 5159 | template <class _BiIter, class _ST, class _SA> |
| 5160 | inline _LIBCPP_INLINE_VISIBILITY |
| 5161 | bool |
| 5162 | operator<=(const sub_match<_BiIter>& __x, |
| 5163 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5164 | { |
| 5165 | return !(__y < __x); |
| 5166 | } |
| 5167 | |
| 5168 | template <class _BiIter> |
| 5169 | inline _LIBCPP_INLINE_VISIBILITY |
| 5170 | bool |
| 5171 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5172 | const sub_match<_BiIter>& __y) |
| 5173 | { |
| 5174 | return __y.compare(__x) == 0; |
| 5175 | } |
| 5176 | |
| 5177 | template <class _BiIter> |
| 5178 | inline _LIBCPP_INLINE_VISIBILITY |
| 5179 | bool |
| 5180 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5181 | const sub_match<_BiIter>& __y) |
| 5182 | { |
| 5183 | return !(__x == __y); |
| 5184 | } |
| 5185 | |
| 5186 | template <class _BiIter> |
| 5187 | inline _LIBCPP_INLINE_VISIBILITY |
| 5188 | bool |
| 5189 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5190 | const sub_match<_BiIter>& __y) |
| 5191 | { |
| 5192 | return __y.compare(__x) > 0; |
| 5193 | } |
| 5194 | |
| 5195 | template <class _BiIter> |
| 5196 | inline _LIBCPP_INLINE_VISIBILITY |
| 5197 | bool |
| 5198 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5199 | const sub_match<_BiIter>& __y) |
| 5200 | { |
| 5201 | return __y < __x; |
| 5202 | } |
| 5203 | |
| 5204 | template <class _BiIter> |
| 5205 | inline _LIBCPP_INLINE_VISIBILITY |
| 5206 | bool |
| 5207 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5208 | const sub_match<_BiIter>& __y) |
| 5209 | { |
| 5210 | return !(__x < __y); |
| 5211 | } |
| 5212 | |
| 5213 | template <class _BiIter> |
| 5214 | inline _LIBCPP_INLINE_VISIBILITY |
| 5215 | bool |
| 5216 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5217 | const sub_match<_BiIter>& __y) |
| 5218 | { |
| 5219 | return !(__y < __x); |
| 5220 | } |
| 5221 | |
| 5222 | template <class _BiIter> |
| 5223 | inline _LIBCPP_INLINE_VISIBILITY |
| 5224 | bool |
| 5225 | operator==(const sub_match<_BiIter>& __x, |
| 5226 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5227 | { |
| 5228 | return __x.compare(__y) == 0; |
| 5229 | } |
| 5230 | |
| 5231 | template <class _BiIter> |
| 5232 | inline _LIBCPP_INLINE_VISIBILITY |
| 5233 | bool |
| 5234 | operator!=(const sub_match<_BiIter>& __x, |
| 5235 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5236 | { |
| 5237 | return !(__x == __y); |
| 5238 | } |
| 5239 | |
| 5240 | template <class _BiIter> |
| 5241 | inline _LIBCPP_INLINE_VISIBILITY |
| 5242 | bool |
| 5243 | operator<(const sub_match<_BiIter>& __x, |
| 5244 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5245 | { |
| 5246 | return __x.compare(__y) < 0; |
| 5247 | } |
| 5248 | |
| 5249 | template <class _BiIter> |
| 5250 | inline _LIBCPP_INLINE_VISIBILITY |
| 5251 | bool |
| 5252 | operator>(const sub_match<_BiIter>& __x, |
| 5253 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5254 | { |
| 5255 | return __y < __x; |
| 5256 | } |
| 5257 | |
| 5258 | template <class _BiIter> |
| 5259 | inline _LIBCPP_INLINE_VISIBILITY |
| 5260 | bool |
| 5261 | operator>=(const sub_match<_BiIter>& __x, |
| 5262 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5263 | { |
| 5264 | return !(__x < __y); |
| 5265 | } |
| 5266 | |
| 5267 | template <class _BiIter> |
| 5268 | inline _LIBCPP_INLINE_VISIBILITY |
| 5269 | bool |
| 5270 | operator<=(const sub_match<_BiIter>& __x, |
| 5271 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5272 | { |
| 5273 | return !(__y < __x); |
| 5274 | } |
| 5275 | |
| 5276 | template <class _BiIter> |
| 5277 | inline _LIBCPP_INLINE_VISIBILITY |
| 5278 | bool |
| 5279 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5280 | const sub_match<_BiIter>& __y) |
| 5281 | { |
| 5282 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5283 | return __y.compare(string_type(1, __x)) == 0; |
| 5284 | } |
| 5285 | |
| 5286 | template <class _BiIter> |
| 5287 | inline _LIBCPP_INLINE_VISIBILITY |
| 5288 | bool |
| 5289 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5290 | const sub_match<_BiIter>& __y) |
| 5291 | { |
| 5292 | return !(__x == __y); |
| 5293 | } |
| 5294 | |
| 5295 | template <class _BiIter> |
| 5296 | inline _LIBCPP_INLINE_VISIBILITY |
| 5297 | bool |
| 5298 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5299 | const sub_match<_BiIter>& __y) |
| 5300 | { |
| 5301 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5302 | return __y.compare(string_type(1, __x)) > 0; |
| 5303 | } |
| 5304 | |
| 5305 | template <class _BiIter> |
| 5306 | inline _LIBCPP_INLINE_VISIBILITY |
| 5307 | bool |
| 5308 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5309 | const sub_match<_BiIter>& __y) |
| 5310 | { |
| 5311 | return __y < __x; |
| 5312 | } |
| 5313 | |
| 5314 | template <class _BiIter> |
| 5315 | inline _LIBCPP_INLINE_VISIBILITY |
| 5316 | bool |
| 5317 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5318 | const sub_match<_BiIter>& __y) |
| 5319 | { |
| 5320 | return !(__x < __y); |
| 5321 | } |
| 5322 | |
| 5323 | template <class _BiIter> |
| 5324 | inline _LIBCPP_INLINE_VISIBILITY |
| 5325 | bool |
| 5326 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5327 | const sub_match<_BiIter>& __y) |
| 5328 | { |
| 5329 | return !(__y < __x); |
| 5330 | } |
| 5331 | |
| 5332 | template <class _BiIter> |
| 5333 | inline _LIBCPP_INLINE_VISIBILITY |
| 5334 | bool |
| 5335 | operator==(const sub_match<_BiIter>& __x, |
| 5336 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5337 | { |
| 5338 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5339 | return __x.compare(string_type(1, __y)) == 0; |
| 5340 | } |
| 5341 | |
| 5342 | template <class _BiIter> |
| 5343 | inline _LIBCPP_INLINE_VISIBILITY |
| 5344 | bool |
| 5345 | operator!=(const sub_match<_BiIter>& __x, |
| 5346 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5347 | { |
| 5348 | return !(__x == __y); |
| 5349 | } |
| 5350 | |
| 5351 | template <class _BiIter> |
| 5352 | inline _LIBCPP_INLINE_VISIBILITY |
| 5353 | bool |
| 5354 | operator<(const sub_match<_BiIter>& __x, |
| 5355 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5356 | { |
| 5357 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5358 | return __x.compare(string_type(1, __y)) < 0; |
| 5359 | } |
| 5360 | |
| 5361 | template <class _BiIter> |
| 5362 | inline _LIBCPP_INLINE_VISIBILITY |
| 5363 | bool |
| 5364 | operator>(const sub_match<_BiIter>& __x, |
| 5365 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5366 | { |
| 5367 | return __y < __x; |
| 5368 | } |
| 5369 | |
| 5370 | template <class _BiIter> |
| 5371 | inline _LIBCPP_INLINE_VISIBILITY |
| 5372 | bool |
| 5373 | operator>=(const sub_match<_BiIter>& __x, |
| 5374 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5375 | { |
| 5376 | return !(__x < __y); |
| 5377 | } |
| 5378 | |
| 5379 | template <class _BiIter> |
| 5380 | inline _LIBCPP_INLINE_VISIBILITY |
| 5381 | bool |
| 5382 | operator<=(const sub_match<_BiIter>& __x, |
| 5383 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5384 | { |
| 5385 | return !(__y < __x); |
| 5386 | } |
| 5387 | |
| 5388 | template <class _CharT, class _ST, class _BiIter> |
| 5389 | inline _LIBCPP_INLINE_VISIBILITY |
| 5390 | basic_ostream<_CharT, _ST>& |
| 5391 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 5392 | { |
| 5393 | return __os << __m.str(); |
| 5394 | } |
| 5395 | |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5396 | typedef match_results<const char*> cmatch; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5397 | typedef match_results<string::const_iterator> smatch; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5398 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 5399 | typedef match_results<const wchar_t*> wcmatch; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5400 | typedef match_results<wstring::const_iterator> wsmatch; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5401 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5402 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5403 | template <class _BidirectionalIterator, class _Allocator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5404 | class |
| 5405 | _LIBCPP_TEMPLATE_VIS |
| 5406 | _LIBCPP_PREFERRED_NAME(cmatch) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5407 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5408 | _LIBCPP_PREFERRED_NAME(smatch) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5409 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5410 | match_results |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5411 | { |
| 5412 | public: |
| 5413 | typedef _Allocator allocator_type; |
| 5414 | typedef sub_match<_BidirectionalIterator> value_type; |
| 5415 | private: |
| 5416 | typedef vector<value_type, allocator_type> __container_type; |
| 5417 | |
| 5418 | __container_type __matches_; |
| 5419 | value_type __unmatched_; |
| 5420 | value_type __prefix_; |
| 5421 | value_type __suffix_; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5422 | bool __ready_; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5423 | public: |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5424 | _BidirectionalIterator __position_start_; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5425 | typedef const value_type& const_reference; |
Marshall Clow | 96e0614 | 2014-02-26 01:56:31 +0000 | [diff] [blame] | 5426 | typedef value_type& reference; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5427 | typedef typename __container_type::const_iterator const_iterator; |
| 5428 | typedef const_iterator iterator; |
| 5429 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5430 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5431 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5432 | typedef basic_string<char_type> string_type; |
| 5433 | |
| 5434 | // construct/copy/destroy: |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5435 | #ifndef _LIBCPP_CXX03_LANG |
| 5436 | match_results() : match_results(allocator_type()) {} |
| 5437 | explicit match_results(const allocator_type& __a); |
| 5438 | #else |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5439 | explicit match_results(const allocator_type& __a = allocator_type()); |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5440 | #endif |
| 5441 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5442 | // match_results(const match_results&) = default; |
| 5443 | // match_results& operator=(const match_results&) = default; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5444 | // match_results(match_results&& __m) = default; |
| 5445 | // match_results& operator=(match_results&& __m) = default; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5446 | // ~match_results() = default; |
| 5447 | |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5448 | _LIBCPP_INLINE_VISIBILITY |
| 5449 | bool ready() const {return __ready_;} |
| 5450 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5451 | // size: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5452 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 081bcd2 | 2017-11-16 04:48:34 +0000 | [diff] [blame] | 5453 | size_type size() const _NOEXCEPT {return __matches_.size();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5454 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 081bcd2 | 2017-11-16 04:48:34 +0000 | [diff] [blame] | 5455 | size_type max_size() const _NOEXCEPT {return __matches_.max_size();} |
| 5456 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 5457 | bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5458 | |
| 5459 | // element access: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5460 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5461 | difference_type length(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5462 | { |
| 5463 | _LIBCPP_ASSERT(ready(), "match_results::length() called when not ready"); |
| 5464 | return (*this)[__sub].length(); |
| 5465 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5466 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5467 | difference_type position(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5468 | { |
| 5469 | _LIBCPP_ASSERT(ready(), "match_results::position() called when not ready"); |
| 5470 | return _VSTD::distance(__position_start_, (*this)[__sub].first); |
| 5471 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5472 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5473 | string_type str(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5474 | { |
| 5475 | _LIBCPP_ASSERT(ready(), "match_results::str() called when not ready"); |
| 5476 | return (*this)[__sub].str(); |
| 5477 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5478 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5479 | const_reference operator[](size_type __n) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5480 | { |
| 5481 | _LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready"); |
| 5482 | return __n < __matches_.size() ? __matches_[__n] : __unmatched_; |
| 5483 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5484 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5485 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5486 | const_reference prefix() const |
| 5487 | { |
| 5488 | _LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready"); |
| 5489 | return __prefix_; |
| 5490 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5491 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5492 | const_reference suffix() const |
| 5493 | { |
| 5494 | _LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready"); |
| 5495 | return __suffix_; |
| 5496 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5497 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5498 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f4191f | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5499 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5500 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5501 | const_iterator end() const {return __matches_.end();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5502 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f4191f | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5503 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5504 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5505 | const_iterator cend() const {return __matches_.end();} |
| 5506 | |
| 5507 | // format: |
| 5508 | template <class _OutputIter> |
| 5509 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5510 | format(_OutputIter __output_iter, const char_type* __fmt_first, |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5511 | const char_type* __fmt_last, |
| 5512 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5513 | template <class _OutputIter, class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5514 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5515 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5516 | format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5517 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5518 | {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5519 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5520 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5521 | basic_string<char_type, _ST, _SA> |
| 5522 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5523 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5524 | { |
| 5525 | basic_string<char_type, _ST, _SA> __r; |
| 5526 | format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), |
| 5527 | __flags); |
| 5528 | return __r; |
| 5529 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5530 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5531 | string_type |
| 5532 | format(const char_type* __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5533 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5534 | { |
| 5535 | string_type __r; |
| 5536 | format(back_inserter(__r), __fmt, |
| 5537 | __fmt + char_traits<char_type>::length(__fmt), __flags); |
| 5538 | return __r; |
| 5539 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5540 | |
| 5541 | // allocator: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5542 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5543 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5544 | |
| 5545 | // swap: |
| 5546 | void swap(match_results& __m); |
| 5547 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5548 | template <class _Bp, class _Ap> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5549 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5550 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5551 | const match_results<_Bp, _Ap>& __m, bool __no_update_pos) |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5552 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5553 | _Bp __mf = __m.prefix().first; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5554 | __matches_.resize(__m.size()); |
| 5555 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5556 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5557 | __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); |
| 5558 | __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5559 | __matches_[__i].matched = __m[__i].matched; |
| 5560 | } |
| 5561 | __unmatched_.first = __l; |
| 5562 | __unmatched_.second = __l; |
| 5563 | __unmatched_.matched = false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5564 | __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); |
| 5565 | __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5566 | __prefix_.matched = __m.prefix().matched; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5567 | __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); |
| 5568 | __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5569 | __suffix_.matched = __m.suffix().matched; |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5570 | if (!__no_update_pos) |
| 5571 | __position_start_ = __prefix_.first; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5572 | __ready_ = __m.ready(); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5573 | } |
| 5574 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5575 | private: |
| 5576 | void __init(unsigned __s, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5577 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5578 | bool __no_update_pos = false); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5579 | |
| 5580 | template <class, class> friend class basic_regex; |
| 5581 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5582 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5583 | friend |
| 5584 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5585 | 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] | 5586 | regex_constants::match_flag_type); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5587 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5588 | template <class _Bp, class _Ap> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5589 | friend |
| 5590 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5591 | operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5592 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5593 | template <class, class> friend class __lookahead; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5594 | }; |
| 5595 | |
| 5596 | template <class _BidirectionalIterator, class _Allocator> |
| 5597 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5598 | const allocator_type& __a) |
| 5599 | : __matches_(__a), |
| 5600 | __unmatched_(), |
| 5601 | __prefix_(), |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5602 | __suffix_(), |
Eric Fiselier | a75ee26 | 2015-07-22 01:29:41 +0000 | [diff] [blame] | 5603 | __ready_(false), |
| 5604 | __position_start_() |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5605 | { |
| 5606 | } |
| 5607 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5608 | template <class _BidirectionalIterator, class _Allocator> |
| 5609 | void |
| 5610 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5611 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5612 | bool __no_update_pos) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5613 | { |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5614 | __unmatched_.first = __l; |
| 5615 | __unmatched_.second = __l; |
| 5616 | __unmatched_.matched = false; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5617 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5618 | __prefix_.first = __f; |
| 5619 | __prefix_.second = __f; |
| 5620 | __prefix_.matched = false; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5621 | __suffix_ = __unmatched_; |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5622 | if (!__no_update_pos) |
| 5623 | __position_start_ = __prefix_.first; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5624 | __ready_ = true; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5625 | } |
| 5626 | |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5627 | template <class _BidirectionalIterator, class _Allocator> |
| 5628 | template <class _OutputIter> |
| 5629 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5630 | match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5631 | const char_type* __fmt_first, const char_type* __fmt_last, |
| 5632 | regex_constants::match_flag_type __flags) const |
| 5633 | { |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5634 | _LIBCPP_ASSERT(ready(), "match_results::format() called when not ready"); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5635 | if (__flags & regex_constants::format_sed) |
| 5636 | { |
| 5637 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5638 | { |
| 5639 | if (*__fmt_first == '&') |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5640 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 5641 | __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5642 | else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) |
| 5643 | { |
| 5644 | ++__fmt_first; |
| 5645 | if ('0' <= *__fmt_first && *__fmt_first <= '9') |
| 5646 | { |
| 5647 | size_t __i = *__fmt_first - '0'; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5648 | __output_iter = _VSTD::copy((*this)[__i].first, |
| 5649 | (*this)[__i].second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5650 | } |
| 5651 | else |
| 5652 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5653 | *__output_iter = *__fmt_first; |
| 5654 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5655 | } |
| 5656 | } |
| 5657 | else |
| 5658 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5659 | *__output_iter = *__fmt_first; |
| 5660 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5661 | } |
| 5662 | } |
| 5663 | } |
| 5664 | else |
| 5665 | { |
| 5666 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5667 | { |
| 5668 | if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) |
| 5669 | { |
| 5670 | switch (__fmt_first[1]) |
| 5671 | { |
| 5672 | case '$': |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5673 | *__output_iter = *++__fmt_first; |
| 5674 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5675 | break; |
| 5676 | case '&': |
| 5677 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5678 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 5679 | __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5680 | break; |
| 5681 | case '`': |
| 5682 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5683 | __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5684 | break; |
| 5685 | case '\'': |
| 5686 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5687 | __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5688 | break; |
| 5689 | default: |
| 5690 | if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5691 | { |
| 5692 | ++__fmt_first; |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 5693 | size_t __idx = *__fmt_first - '0'; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5694 | if (__fmt_first + 1 != __fmt_last && |
| 5695 | '0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5696 | { |
| 5697 | ++__fmt_first; |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 5698 | if (__idx >= numeric_limits<size_t>::max() / 10) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 5699 | __throw_regex_error<regex_constants::error_escape>(); |
| 5700 | __idx = 10 * __idx + *__fmt_first - '0'; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5701 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5702 | __output_iter = _VSTD::copy((*this)[__idx].first, |
| 5703 | (*this)[__idx].second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5704 | } |
| 5705 | else |
| 5706 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5707 | *__output_iter = *__fmt_first; |
| 5708 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5709 | } |
| 5710 | break; |
| 5711 | } |
| 5712 | } |
| 5713 | else |
| 5714 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5715 | *__output_iter = *__fmt_first; |
| 5716 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5717 | } |
| 5718 | } |
| 5719 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5720 | return __output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5721 | } |
| 5722 | |
| 5723 | template <class _BidirectionalIterator, class _Allocator> |
| 5724 | void |
| 5725 | match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) |
| 5726 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5727 | using _VSTD::swap; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5728 | swap(__matches_, __m.__matches_); |
| 5729 | swap(__unmatched_, __m.__unmatched_); |
| 5730 | swap(__prefix_, __m.__prefix_); |
| 5731 | swap(__suffix_, __m.__suffix_); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5732 | swap(__position_start_, __m.__position_start_); |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5733 | swap(__ready_, __m.__ready_); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5734 | } |
| 5735 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5736 | template <class _BidirectionalIterator, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 5737 | _LIBCPP_HIDE_FROM_ABI bool |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5738 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5739 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5740 | { |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5741 | if (__x.__ready_ != __y.__ready_) |
| 5742 | return false; |
| 5743 | if (!__x.__ready_) |
| 5744 | return true; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5745 | return __x.__matches_ == __y.__matches_ && |
| 5746 | __x.__prefix_ == __y.__prefix_ && |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5747 | __x.__suffix_ == __y.__suffix_; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5748 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5749 | |
| 5750 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5751 | inline _LIBCPP_INLINE_VISIBILITY |
| 5752 | bool |
| 5753 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5754 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5755 | { |
| 5756 | return !(__x == __y); |
| 5757 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5758 | |
| 5759 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5760 | inline _LIBCPP_INLINE_VISIBILITY |
| 5761 | void |
| 5762 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5763 | match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5764 | { |
| 5765 | __x.swap(__y); |
| 5766 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5767 | |
| 5768 | // regex_search |
| 5769 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5770 | template <class _CharT, class _Traits> |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5771 | template <class _Allocator> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5772 | bool |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5773 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5774 | const _CharT* __first, const _CharT* __last, |
| 5775 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5776 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5777 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5778 | vector<__state> __states; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5779 | __node* __st = __start_.get(); |
| 5780 | if (__st) |
| 5781 | { |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5782 | sub_match<const _CharT*> __unmatched; |
| 5783 | __unmatched.first = __last; |
| 5784 | __unmatched.second = __last; |
| 5785 | __unmatched.matched = false; |
| 5786 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5787 | __states.push_back(__state()); |
| 5788 | __states.back().__do_ = 0; |
| 5789 | __states.back().__first_ = __first; |
| 5790 | __states.back().__current_ = __first; |
| 5791 | __states.back().__last_ = __last; |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5792 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5793 | __states.back().__loop_data_.resize(__loop_count()); |
| 5794 | __states.back().__node_ = __st; |
| 5795 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5796 | __states.back().__at_first_ = __at_first; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5797 | int __counter = 0; |
| 5798 | int __length = __last - __first; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5799 | do |
| 5800 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5801 | ++__counter; |
| 5802 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5803 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5804 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5805 | __state& __s = __states.back(); |
| 5806 | if (__s.__node_) |
| 5807 | __s.__node_->__exec(__s); |
| 5808 | switch (__s.__do_) |
| 5809 | { |
| 5810 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5811 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5812 | __s.__current_ == __first) |
| 5813 | { |
| 5814 | __states.pop_back(); |
| 5815 | break; |
| 5816 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5817 | if ((__flags & regex_constants::__full_match) && |
| 5818 | __s.__current_ != __last) |
| 5819 | { |
| 5820 | __states.pop_back(); |
| 5821 | break; |
| 5822 | } |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5823 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5824 | __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5825 | __m.__matches_[0].matched = true; |
| 5826 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5827 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5828 | return true; |
| 5829 | case __state::__accept_and_consume: |
| 5830 | case __state::__repeat: |
| 5831 | case __state::__accept_but_not_consume: |
| 5832 | break; |
| 5833 | case __state::__split: |
| 5834 | { |
| 5835 | __state __snext = __s; |
| 5836 | __s.__node_->__exec_split(true, __s); |
| 5837 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5838 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5839 | } |
| 5840 | break; |
| 5841 | case __state::__reject: |
| 5842 | __states.pop_back(); |
| 5843 | break; |
| 5844 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5845 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5846 | break; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5847 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5848 | } |
| 5849 | } while (!__states.empty()); |
| 5850 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5851 | return false; |
| 5852 | } |
| 5853 | |
| 5854 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5855 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5856 | bool |
| 5857 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5858 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5859 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5860 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5861 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5862 | deque<__state> __states; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5863 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5864 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5865 | __node* __st = __start_.get(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5866 | if (__st) |
| 5867 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5868 | __states.push_back(__state()); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5869 | __states.back().__do_ = 0; |
| 5870 | __states.back().__first_ = __first; |
| 5871 | __states.back().__current_ = __first; |
| 5872 | __states.back().__last_ = __last; |
| 5873 | __states.back().__loop_data_.resize(__loop_count()); |
| 5874 | __states.back().__node_ = __st; |
| 5875 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5876 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5877 | bool __matched = false; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5878 | int __counter = 0; |
| 5879 | int __length = __last - __first; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5880 | do |
| 5881 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5882 | ++__counter; |
| 5883 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5884 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5885 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5886 | __state& __s = __states.back(); |
| 5887 | if (__s.__node_) |
| 5888 | __s.__node_->__exec(__s); |
| 5889 | switch (__s.__do_) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5890 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5891 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5892 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5893 | __s.__current_ == __first) |
| 5894 | { |
| 5895 | __states.pop_back(); |
| 5896 | break; |
| 5897 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5898 | if ((__flags & regex_constants::__full_match) && |
| 5899 | __s.__current_ != __last) |
| 5900 | { |
| 5901 | __states.pop_back(); |
| 5902 | break; |
| 5903 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5904 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5905 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5906 | __matched = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5907 | if (__highest_j == _Np) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5908 | __states.clear(); |
| 5909 | else |
| 5910 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5911 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5912 | case __state::__consume_input: |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5913 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5914 | case __state::__accept_and_consume: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5915 | __states.push_front(_VSTD::move(__s)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5916 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5917 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5918 | case __state::__repeat: |
| 5919 | case __state::__accept_but_not_consume: |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5920 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5921 | case __state::__split: |
| 5922 | { |
| 5923 | __state __snext = __s; |
| 5924 | __s.__node_->__exec_split(true, __s); |
| 5925 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5926 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5927 | } |
| 5928 | break; |
| 5929 | case __state::__reject: |
| 5930 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5931 | break; |
| 5932 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5933 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5934 | break; |
| 5935 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5936 | } while (!__states.empty()); |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5937 | if (__matched) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5938 | { |
| 5939 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5940 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5941 | __m.__matches_[0].matched = true; |
| 5942 | return true; |
| 5943 | } |
| 5944 | } |
| 5945 | return false; |
| 5946 | } |
| 5947 | |
| 5948 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5949 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5950 | bool |
| 5951 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5952 | const _CharT* __first, const _CharT* __last, |
| 5953 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5954 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5955 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5956 | vector<__state> __states; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5957 | __state __best_state; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5958 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5959 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5960 | __node* __st = __start_.get(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5961 | if (__st) |
| 5962 | { |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5963 | sub_match<const _CharT*> __unmatched; |
| 5964 | __unmatched.first = __last; |
| 5965 | __unmatched.second = __last; |
| 5966 | __unmatched.matched = false; |
| 5967 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5968 | __states.push_back(__state()); |
| 5969 | __states.back().__do_ = 0; |
| 5970 | __states.back().__first_ = __first; |
| 5971 | __states.back().__current_ = __first; |
| 5972 | __states.back().__last_ = __last; |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5973 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5974 | __states.back().__loop_data_.resize(__loop_count()); |
| 5975 | __states.back().__node_ = __st; |
| 5976 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5977 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5978 | bool __matched = false; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5979 | int __counter = 0; |
| 5980 | int __length = __last - __first; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5981 | do |
| 5982 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5983 | ++__counter; |
| 5984 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5985 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5986 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5987 | __state& __s = __states.back(); |
| 5988 | if (__s.__node_) |
| 5989 | __s.__node_->__exec(__s); |
| 5990 | switch (__s.__do_) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5991 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5992 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5993 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5994 | __s.__current_ == __first) |
| 5995 | { |
| 5996 | __states.pop_back(); |
| 5997 | break; |
| 5998 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5999 | if ((__flags & regex_constants::__full_match) && |
| 6000 | __s.__current_ != __last) |
| 6001 | { |
| 6002 | __states.pop_back(); |
| 6003 | break; |
| 6004 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 6005 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6006 | { |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 6007 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6008 | __best_state = __s; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6009 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 6010 | __matched = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6011 | if (__highest_j == _Np) |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 6012 | __states.clear(); |
| 6013 | else |
| 6014 | __states.pop_back(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6015 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6016 | case __state::__accept_and_consume: |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6017 | case __state::__repeat: |
| 6018 | case __state::__accept_but_not_consume: |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6019 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6020 | case __state::__split: |
| 6021 | { |
| 6022 | __state __snext = __s; |
| 6023 | __s.__node_->__exec_split(true, __s); |
| 6024 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6025 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6026 | } |
| 6027 | break; |
| 6028 | case __state::__reject: |
| 6029 | __states.pop_back(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6030 | break; |
| 6031 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 6032 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6033 | break; |
| 6034 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6035 | } while (!__states.empty()); |
| 6036 | if (__matched) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6037 | { |
| 6038 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6039 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6040 | __m.__matches_[0].matched = true; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6041 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 6042 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6043 | return true; |
| 6044 | } |
| 6045 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6046 | return false; |
| 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 |
| 6052 | basic_regex<_CharT, _Traits>::__match_at_start( |
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 | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6055 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6056 | { |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 6057 | if (__get_grammar(__flags_) == ECMAScript) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6058 | return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6059 | if (mark_count() == 0) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6060 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |
| 6061 | return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6062 | } |
| 6063 | |
| 6064 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6065 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6066 | bool |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6067 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6068 | const _CharT* __first, const _CharT* __last, |
| 6069 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6070 | regex_constants::match_flag_type __flags) const |
| 6071 | { |
Diogo Sampaio | 300ade7 | 2020-04-30 23:34:01 +0100 | [diff] [blame] | 6072 | if (__flags & regex_constants::match_prev_avail) |
| 6073 | __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow); |
| 6074 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6075 | __m.__init(1 + mark_count(), __first, __last, |
| 6076 | __flags & regex_constants::__no_update_pos); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6077 | if (__match_at_start(__first, __last, __m, __flags, |
Howard Hinnant | 38d14f7 | 2013-07-09 17:29:09 +0000 | [diff] [blame] | 6078 | !(__flags & regex_constants::__no_update_pos))) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6079 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6080 | __m.__prefix_.second = __m[0].first; |
| 6081 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 6082 | __m.__suffix_.first = __m[0].second; |
| 6083 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 6084 | return true; |
| 6085 | } |
Howard Hinnant | 22cf486 | 2010-07-29 01:15:27 +0000 | [diff] [blame] | 6086 | if (__first != __last && !(__flags & regex_constants::match_continuous)) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6087 | { |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 6088 | __flags |= regex_constants::match_prev_avail; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6089 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6090 | { |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 6091 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6092 | if (__match_at_start(__first, __last, __m, __flags, false)) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6093 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6094 | __m.__prefix_.second = __m[0].first; |
| 6095 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 6096 | __m.__suffix_.first = __m[0].second; |
| 6097 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 6098 | return true; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6099 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6100 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6101 | } |
| 6102 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6103 | __m.__matches_.clear(); |
| 6104 | return false; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6105 | } |
| 6106 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6107 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6108 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6109 | bool |
| 6110 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6111 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6112 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6113 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6114 | { |
Howard Hinnant | 1e5de64 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 6115 | int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0; |
| 6116 | basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6117 | match_results<const _CharT*> __mc; |
Howard Hinnant | 1e5de64 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 6118 | 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] | 6119 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6120 | return __r; |
| 6121 | } |
| 6122 | |
Howard Hinnant | 4018c48 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 6123 | template <class _Iter, class _Allocator, class _CharT, class _Traits> |
| 6124 | inline _LIBCPP_INLINE_VISIBILITY |
| 6125 | bool |
| 6126 | regex_search(__wrap_iter<_Iter> __first, |
| 6127 | __wrap_iter<_Iter> __last, |
| 6128 | match_results<__wrap_iter<_Iter>, _Allocator>& __m, |
| 6129 | const basic_regex<_CharT, _Traits>& __e, |
| 6130 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6131 | { |
| 6132 | match_results<const _CharT*> __mc; |
| 6133 | bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags); |
| 6134 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
| 6135 | return __r; |
| 6136 | } |
| 6137 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6138 | template <class _Allocator, class _CharT, class _Traits> |
| 6139 | inline _LIBCPP_INLINE_VISIBILITY |
| 6140 | bool |
| 6141 | regex_search(const _CharT* __first, const _CharT* __last, |
| 6142 | match_results<const _CharT*, _Allocator>& __m, |
| 6143 | const basic_regex<_CharT, _Traits>& __e, |
| 6144 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6145 | { |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6146 | return __e.__search(__first, __last, __m, __flags); |
| 6147 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6148 | |
| 6149 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6150 | inline _LIBCPP_INLINE_VISIBILITY |
| 6151 | bool |
| 6152 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6153 | const basic_regex<_CharT, _Traits>& __e, |
| 6154 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6155 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6156 | basic_string<_CharT> __s(__first, __last); |
| 6157 | match_results<const _CharT*> __mc; |
| 6158 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 6159 | } |
| 6160 | |
| 6161 | template <class _CharT, class _Traits> |
| 6162 | inline _LIBCPP_INLINE_VISIBILITY |
| 6163 | bool |
| 6164 | regex_search(const _CharT* __first, const _CharT* __last, |
| 6165 | const basic_regex<_CharT, _Traits>& __e, |
| 6166 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6167 | { |
| 6168 | match_results<const _CharT*> __mc; |
| 6169 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6170 | } |
| 6171 | |
| 6172 | template <class _CharT, class _Allocator, class _Traits> |
| 6173 | inline _LIBCPP_INLINE_VISIBILITY |
| 6174 | bool |
| 6175 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6176 | const basic_regex<_CharT, _Traits>& __e, |
| 6177 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6178 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6179 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6180 | } |
| 6181 | |
| 6182 | template <class _CharT, class _Traits> |
| 6183 | inline _LIBCPP_INLINE_VISIBILITY |
| 6184 | bool |
| 6185 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6186 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6187 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6188 | match_results<const _CharT*> __m; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6189 | return _VSTD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6190 | } |
| 6191 | |
| 6192 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6193 | inline _LIBCPP_INLINE_VISIBILITY |
| 6194 | bool |
| 6195 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6196 | const basic_regex<_CharT, _Traits>& __e, |
| 6197 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6198 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6199 | match_results<const _CharT*> __mc; |
| 6200 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6204 | inline _LIBCPP_INLINE_VISIBILITY |
| 6205 | bool |
| 6206 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6207 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6208 | const basic_regex<_CharT, _Traits>& __e, |
| 6209 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6210 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6211 | match_results<const _CharT*> __mc; |
| 6212 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6213 | __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] | 6214 | return __r; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6215 | } |
| 6216 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6217 | #if _LIBCPP_STD_VER > 11 |
| 6218 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
| 6219 | bool |
| 6220 | regex_search(const basic_string<_Cp, _ST, _SA>&& __s, |
| 6221 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 6222 | const basic_regex<_Cp, _Tp>& __e, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6223 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6224 | #endif |
| 6225 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6226 | // regex_match |
| 6227 | |
| 6228 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 6229 | _LIBCPP_HIDE_FROM_ABI bool |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6230 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6231 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6232 | const basic_regex<_CharT, _Traits>& __e, |
| 6233 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6234 | { |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 6235 | bool __r = _VSTD::regex_search( |
| 6236 | __first, __last, __m, __e, |
| 6237 | __flags | regex_constants::match_continuous | |
| 6238 | regex_constants::__full_match); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6239 | if (__r) |
| 6240 | { |
| 6241 | __r = !__m.suffix().matched; |
| 6242 | if (!__r) |
| 6243 | __m.__matches_.clear(); |
| 6244 | } |
| 6245 | return __r; |
| 6246 | } |
| 6247 | |
| 6248 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6249 | inline _LIBCPP_INLINE_VISIBILITY |
| 6250 | bool |
| 6251 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6252 | const basic_regex<_CharT, _Traits>& __e, |
| 6253 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6254 | { |
| 6255 | match_results<_BidirectionalIterator> __m; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6256 | return _VSTD::regex_match(__first, __last, __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6257 | } |
| 6258 | |
| 6259 | template <class _CharT, class _Allocator, class _Traits> |
| 6260 | inline _LIBCPP_INLINE_VISIBILITY |
| 6261 | bool |
| 6262 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6263 | const basic_regex<_CharT, _Traits>& __e, |
| 6264 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6265 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6266 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6267 | } |
| 6268 | |
| 6269 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6270 | inline _LIBCPP_INLINE_VISIBILITY |
| 6271 | bool |
| 6272 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6273 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6274 | const basic_regex<_CharT, _Traits>& __e, |
| 6275 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6276 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6277 | return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6278 | } |
| 6279 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6280 | #if _LIBCPP_STD_VER > 11 |
| 6281 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6282 | inline _LIBCPP_INLINE_VISIBILITY |
| 6283 | bool |
| 6284 | regex_match(const basic_string<_CharT, _ST, _SA>&& __s, |
| 6285 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6286 | const basic_regex<_CharT, _Traits>& __e, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6287 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6288 | #endif |
| 6289 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6290 | template <class _CharT, class _Traits> |
| 6291 | inline _LIBCPP_INLINE_VISIBILITY |
| 6292 | bool |
| 6293 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6294 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6295 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6296 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6297 | } |
| 6298 | |
| 6299 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6300 | inline _LIBCPP_INLINE_VISIBILITY |
| 6301 | bool |
| 6302 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6303 | const basic_regex<_CharT, _Traits>& __e, |
| 6304 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6305 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6306 | return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6307 | } |
| 6308 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6309 | // regex_iterator |
| 6310 | |
| 6311 | template <class _BidirectionalIterator, |
| 6312 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6313 | class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6314 | class _LIBCPP_TEMPLATE_VIS regex_iterator; |
| 6315 | |
| 6316 | typedef regex_iterator<const char*> cregex_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6317 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6318 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6319 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6320 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6321 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6322 | |
| 6323 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6324 | class |
| 6325 | _LIBCPP_TEMPLATE_VIS |
| 6326 | _LIBCPP_PREFERRED_NAME(cregex_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6327 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6328 | _LIBCPP_PREFERRED_NAME(sregex_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6329 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6330 | regex_iterator |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6331 | { |
| 6332 | public: |
| 6333 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6334 | typedef match_results<_BidirectionalIterator> value_type; |
| 6335 | typedef ptrdiff_t difference_type; |
| 6336 | typedef const value_type* pointer; |
| 6337 | typedef const value_type& reference; |
| 6338 | typedef forward_iterator_tag iterator_category; |
| 6339 | |
| 6340 | private: |
| 6341 | _BidirectionalIterator __begin_; |
| 6342 | _BidirectionalIterator __end_; |
| 6343 | const regex_type* __pregex_; |
| 6344 | regex_constants::match_flag_type __flags_; |
| 6345 | value_type __match_; |
| 6346 | |
| 6347 | public: |
| 6348 | regex_iterator(); |
| 6349 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6350 | const regex_type& __re, |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6351 | regex_constants::match_flag_type __m |
| 6352 | = regex_constants::match_default); |
| 6353 | #if _LIBCPP_STD_VER > 11 |
| 6354 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6355 | const regex_type&& __re, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6356 | regex_constants::match_flag_type __m |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6357 | = regex_constants::match_default) = delete; |
| 6358 | #endif |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6359 | |
| 6360 | bool operator==(const regex_iterator& __x) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6361 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6362 | bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} |
| 6363 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6364 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6365 | reference operator*() const {return __match_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6366 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6367 | pointer operator->() const {return _VSTD::addressof(__match_);} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6368 | |
| 6369 | regex_iterator& operator++(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6370 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6371 | regex_iterator operator++(int) |
| 6372 | { |
| 6373 | regex_iterator __t(*this); |
| 6374 | ++(*this); |
| 6375 | return __t; |
| 6376 | } |
| 6377 | }; |
| 6378 | |
| 6379 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6380 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() |
| 6381 | : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() |
| 6382 | { |
| 6383 | } |
| 6384 | |
| 6385 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6386 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6387 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6388 | const regex_type& __re, regex_constants::match_flag_type __m) |
| 6389 | : __begin_(__a), |
| 6390 | __end_(__b), |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6391 | __pregex_(_VSTD::addressof(__re)), |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6392 | __flags_(__m) |
| 6393 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6394 | _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6395 | } |
| 6396 | |
| 6397 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6398 | bool |
| 6399 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6400 | operator==(const regex_iterator& __x) const |
| 6401 | { |
| 6402 | if (__match_.empty() && __x.__match_.empty()) |
| 6403 | return true; |
| 6404 | if (__match_.empty() || __x.__match_.empty()) |
| 6405 | return false; |
| 6406 | return __begin_ == __x.__begin_ && |
| 6407 | __end_ == __x.__end_ && |
| 6408 | __pregex_ == __x.__pregex_ && |
| 6409 | __flags_ == __x.__flags_ && |
| 6410 | __match_[0] == __x.__match_[0]; |
| 6411 | } |
| 6412 | |
| 6413 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6414 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6415 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6416 | { |
| 6417 | __flags_ |= regex_constants::__no_update_pos; |
| 6418 | _BidirectionalIterator __start = __match_[0].second; |
Marshall Clow | faa964d | 2017-07-05 16:37:19 +0000 | [diff] [blame] | 6419 | if (__match_[0].first == __match_[0].second) |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6420 | { |
| 6421 | if (__start == __end_) |
| 6422 | { |
| 6423 | __match_ = value_type(); |
| 6424 | return *this; |
| 6425 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6426 | else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6427 | __flags_ | regex_constants::match_not_null | |
| 6428 | regex_constants::match_continuous)) |
| 6429 | return *this; |
| 6430 | else |
| 6431 | ++__start; |
| 6432 | } |
| 6433 | __flags_ |= regex_constants::match_prev_avail; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6434 | if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6435 | __match_ = value_type(); |
| 6436 | return *this; |
| 6437 | } |
| 6438 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6439 | // regex_token_iterator |
| 6440 | |
| 6441 | template <class _BidirectionalIterator, |
| 6442 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6443 | class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6444 | class _LIBCPP_TEMPLATE_VIS regex_token_iterator; |
| 6445 | |
| 6446 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6447 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6448 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6449 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6450 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6451 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6452 | |
| 6453 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6454 | class |
| 6455 | _LIBCPP_TEMPLATE_VIS |
| 6456 | _LIBCPP_PREFERRED_NAME(cregex_token_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6457 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6458 | _LIBCPP_PREFERRED_NAME(sregex_token_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6459 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6460 | regex_token_iterator |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6461 | { |
| 6462 | public: |
| 6463 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6464 | typedef sub_match<_BidirectionalIterator> value_type; |
| 6465 | typedef ptrdiff_t difference_type; |
| 6466 | typedef const value_type* pointer; |
| 6467 | typedef const value_type& reference; |
| 6468 | typedef forward_iterator_tag iterator_category; |
| 6469 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6470 | private: |
| 6471 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; |
| 6472 | |
| 6473 | _Position __position_; |
| 6474 | const value_type* __result_; |
| 6475 | value_type __suffix_; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6476 | ptrdiff_t __n_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6477 | vector<int> __subs_; |
| 6478 | |
| 6479 | public: |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6480 | regex_token_iterator(); |
| 6481 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6482 | const regex_type& __re, int __submatch = 0, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6483 | regex_constants::match_flag_type __m = |
| 6484 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6485 | #if _LIBCPP_STD_VER > 11 |
| 6486 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6487 | const regex_type&& __re, int __submatch = 0, |
| 6488 | regex_constants::match_flag_type __m = |
| 6489 | regex_constants::match_default) = delete; |
| 6490 | #endif |
| 6491 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6492 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6493 | const regex_type& __re, const vector<int>& __submatches, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6494 | regex_constants::match_flag_type __m = |
| 6495 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6496 | #if _LIBCPP_STD_VER > 11 |
| 6497 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6498 | const regex_type&& __re, const vector<int>& __submatches, |
| 6499 | regex_constants::match_flag_type __m = |
| 6500 | regex_constants::match_default) = delete; |
| 6501 | #endif |
| 6502 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 6503 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6504 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6505 | const regex_type& __re, |
| 6506 | initializer_list<int> __submatches, |
| 6507 | regex_constants::match_flag_type __m = |
| 6508 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6509 | |
| 6510 | #if _LIBCPP_STD_VER > 11 |
| 6511 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6512 | const regex_type&& __re, |
| 6513 | initializer_list<int> __submatches, |
| 6514 | regex_constants::match_flag_type __m = |
| 6515 | regex_constants::match_default) = delete; |
| 6516 | #endif |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6517 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6518 | template <size_t _Np> |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6519 | regex_token_iterator(_BidirectionalIterator __a, |
| 6520 | _BidirectionalIterator __b, |
| 6521 | const regex_type& __re, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6522 | const int (&__submatches)[_Np], |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6523 | regex_constants::match_flag_type __m = |
| 6524 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6525 | #if _LIBCPP_STD_VER > 11 |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 6526 | template <size_t _Np> |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6527 | regex_token_iterator(_BidirectionalIterator __a, |
| 6528 | _BidirectionalIterator __b, |
| 6529 | const regex_type&& __re, |
| 6530 | const int (&__submatches)[_Np], |
| 6531 | regex_constants::match_flag_type __m = |
| 6532 | regex_constants::match_default) = delete; |
| 6533 | #endif |
| 6534 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6535 | regex_token_iterator(const regex_token_iterator&); |
| 6536 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 6537 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6538 | bool operator==(const regex_token_iterator& __x) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6539 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6540 | bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6541 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6542 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6543 | const value_type& operator*() const {return *__result_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6544 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6545 | const value_type* operator->() const {return __result_;} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6546 | |
| 6547 | regex_token_iterator& operator++(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6548 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6549 | regex_token_iterator operator++(int) |
| 6550 | { |
| 6551 | regex_token_iterator __t(*this); |
| 6552 | ++(*this); |
| 6553 | return __t; |
| 6554 | } |
| 6555 | |
| 6556 | private: |
| 6557 | void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6558 | void __establish_result () { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6559 | if (__subs_[__n_] == -1) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6560 | __result_ = &__position_->prefix(); |
| 6561 | else |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6562 | __result_ = &(*__position_)[__subs_[__n_]]; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6563 | } |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6564 | }; |
| 6565 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6566 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6567 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6568 | regex_token_iterator() |
| 6569 | : __result_(nullptr), |
| 6570 | __suffix_(), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6571 | __n_(0) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6572 | { |
| 6573 | } |
| 6574 | |
| 6575 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6576 | void |
| 6577 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6578 | __init(_BidirectionalIterator __a, _BidirectionalIterator __b) |
| 6579 | { |
| 6580 | if (__position_ != _Position()) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6581 | __establish_result (); |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6582 | else if (__subs_[__n_] == -1) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6583 | { |
| 6584 | __suffix_.matched = true; |
| 6585 | __suffix_.first = __a; |
| 6586 | __suffix_.second = __b; |
| 6587 | __result_ = &__suffix_; |
| 6588 | } |
| 6589 | else |
| 6590 | __result_ = nullptr; |
| 6591 | } |
| 6592 | |
| 6593 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6594 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6595 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6596 | const regex_type& __re, int __submatch, |
| 6597 | regex_constants::match_flag_type __m) |
| 6598 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6599 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6600 | __subs_(1, __submatch) |
| 6601 | { |
| 6602 | __init(__a, __b); |
| 6603 | } |
| 6604 | |
| 6605 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6606 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6607 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6608 | const regex_type& __re, const vector<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 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 6617 | #ifndef _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> |
| 6620 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6621 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6622 | const regex_type& __re, |
| 6623 | initializer_list<int> __submatches, |
| 6624 | regex_constants::match_flag_type __m) |
| 6625 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6626 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6627 | __subs_(__submatches) |
| 6628 | { |
| 6629 | __init(__a, __b); |
| 6630 | } |
| 6631 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6632 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6633 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6634 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6635 | template <size_t _Np> |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6636 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6637 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6638 | const regex_type& __re, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6639 | const int (&__submatches)[_Np], |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6640 | regex_constants::match_flag_type __m) |
| 6641 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6642 | __n_(0), |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6643 | __subs_(begin(__submatches), end(__submatches)) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6644 | { |
| 6645 | __init(__a, __b); |
| 6646 | } |
| 6647 | |
| 6648 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6649 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6650 | regex_token_iterator(const regex_token_iterator& __x) |
| 6651 | : __position_(__x.__position_), |
| 6652 | __result_(__x.__result_), |
| 6653 | __suffix_(__x.__suffix_), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6654 | __n_(__x.__n_), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6655 | __subs_(__x.__subs_) |
| 6656 | { |
| 6657 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 20756ac | 2014-01-13 17:47:08 +0000 | [diff] [blame] | 6658 | __result_ = &__suffix_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6659 | else if ( __result_ != nullptr ) |
| 6660 | __establish_result (); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6661 | } |
| 6662 | |
| 6663 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6664 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6665 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6666 | operator=(const regex_token_iterator& __x) |
| 6667 | { |
| 6668 | if (this != &__x) |
| 6669 | { |
| 6670 | __position_ = __x.__position_; |
| 6671 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6672 | __result_ = &__suffix_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6673 | else |
| 6674 | __result_ = __x.__result_; |
| 6675 | __suffix_ = __x.__suffix_; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6676 | __n_ = __x.__n_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6677 | __subs_ = __x.__subs_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6678 | |
| 6679 | if ( __result_ != nullptr && __result_ != &__suffix_ ) |
| 6680 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6681 | } |
| 6682 | return *this; |
| 6683 | } |
| 6684 | |
| 6685 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6686 | bool |
| 6687 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6688 | operator==(const regex_token_iterator& __x) const |
| 6689 | { |
| 6690 | if (__result_ == nullptr && __x.__result_ == nullptr) |
| 6691 | return true; |
| 6692 | if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && |
| 6693 | __suffix_ == __x.__suffix_) |
| 6694 | return true; |
| 6695 | if (__result_ == nullptr || __x.__result_ == nullptr) |
| 6696 | return false; |
| 6697 | if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) |
| 6698 | return false; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6699 | return __position_ == __x.__position_ && __n_ == __x.__n_ && |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6700 | __subs_ == __x.__subs_; |
| 6701 | } |
| 6702 | |
| 6703 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6704 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6705 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6706 | { |
| 6707 | _Position __prev = __position_; |
| 6708 | if (__result_ == &__suffix_) |
| 6709 | __result_ = nullptr; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6710 | else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6711 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6712 | ++__n_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6713 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6714 | } |
| 6715 | else |
| 6716 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6717 | __n_ = 0; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6718 | ++__position_; |
| 6719 | if (__position_ != _Position()) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6720 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6721 | else |
| 6722 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6723 | if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6724 | && __prev->suffix().length() != 0) |
| 6725 | { |
| 6726 | __suffix_.matched = true; |
| 6727 | __suffix_.first = __prev->suffix().first; |
| 6728 | __suffix_.second = __prev->suffix().second; |
| 6729 | __result_ = &__suffix_; |
| 6730 | } |
| 6731 | else |
| 6732 | __result_ = nullptr; |
| 6733 | } |
| 6734 | } |
| 6735 | return *this; |
| 6736 | } |
| 6737 | |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6738 | // regex_replace |
| 6739 | |
| 6740 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6741 | class _Traits, class _CharT> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 6742 | _LIBCPP_HIDE_FROM_ABI _OutputIterator |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6743 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6744 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6745 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6746 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6747 | { |
| 6748 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; |
| 6749 | _Iter __i(__first, __last, __e, __flags); |
| 6750 | _Iter __eof; |
| 6751 | if (__i == __eof) |
| 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(__first, __last, __output_iter); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6755 | } |
| 6756 | else |
| 6757 | { |
| 6758 | sub_match<_BidirectionalIterator> __lm; |
| 6759 | for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) |
| 6760 | { |
| 6761 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6762 | __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter); |
| 6763 | __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6764 | __lm = __i->suffix(); |
| 6765 | if (__flags & regex_constants::format_first_only) |
| 6766 | break; |
| 6767 | } |
| 6768 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6769 | __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6770 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6771 | return __output_iter; |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6772 | } |
| 6773 | |
| 6774 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6775 | class _Traits, class _CharT, class _ST, class _SA> |
| 6776 | inline _LIBCPP_INLINE_VISIBILITY |
| 6777 | _OutputIterator |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6778 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6779 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6780 | const basic_regex<_CharT, _Traits>& __e, |
| 6781 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6782 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6783 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6784 | 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] | 6785 | } |
| 6786 | |
| 6787 | template <class _Traits, class _CharT, class _ST, class _SA, class _FST, |
| 6788 | class _FSA> |
| 6789 | inline _LIBCPP_INLINE_VISIBILITY |
| 6790 | basic_string<_CharT, _ST, _SA> |
| 6791 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6792 | const basic_regex<_CharT, _Traits>& __e, |
| 6793 | const basic_string<_CharT, _FST, _FSA>& __fmt, |
| 6794 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6795 | { |
| 6796 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6797 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6798 | __fmt.c_str(), __flags); |
| 6799 | return __r; |
| 6800 | } |
| 6801 | |
| 6802 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6803 | inline _LIBCPP_INLINE_VISIBILITY |
| 6804 | basic_string<_CharT, _ST, _SA> |
| 6805 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6806 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6807 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6808 | { |
| 6809 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6810 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6811 | __fmt, __flags); |
| 6812 | return __r; |
| 6813 | } |
| 6814 | |
| 6815 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6816 | inline _LIBCPP_INLINE_VISIBILITY |
| 6817 | basic_string<_CharT> |
| 6818 | regex_replace(const _CharT* __s, |
| 6819 | const basic_regex<_CharT, _Traits>& __e, |
| 6820 | const basic_string<_CharT, _ST, _SA>& __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.c_str(), __flags); |
| 6827 | return __r; |
| 6828 | } |
| 6829 | |
| 6830 | template <class _Traits, class _CharT> |
| 6831 | inline _LIBCPP_INLINE_VISIBILITY |
| 6832 | basic_string<_CharT> |
| 6833 | regex_replace(const _CharT* __s, |
| 6834 | const basic_regex<_CharT, _Traits>& __e, |
| 6835 | const _CharT* __fmt, |
| 6836 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6837 | { |
| 6838 | basic_string<_CharT> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6839 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6840 | __s + char_traits<_CharT>::length(__s), __e, |
| 6841 | __fmt, __flags); |
| 6842 | return __r; |
| 6843 | } |
| 6844 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 6845 | _LIBCPP_END_NAMESPACE_STD |
| 6846 | |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 6847 | #if _LIBCPP_STD_VER > 14 |
| 6848 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 6849 | namespace pmr { |
| 6850 | template <class _BidirT> |
| 6851 | using match_results = std::match_results<_BidirT, polymorphic_allocator<std::sub_match<_BidirT>>>; |
| 6852 | |
| 6853 | using cmatch = match_results<const char*>; |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 6854 | using smatch = match_results<std::pmr::string::const_iterator>; |
Nikolas Klauser | 713bfda | 2022-10-13 01:03:58 +0200 | [diff] [blame] | 6855 | |
| 6856 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6857 | using wcmatch = match_results<const wchar_t*>; |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 6858 | using wsmatch = match_results<std::pmr::wstring::const_iterator>; |
Nikolas Klauser | 713bfda | 2022-10-13 01:03:58 +0200 | [diff] [blame] | 6859 | #endif |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 6860 | } // namespace pmr |
| 6861 | _LIBCPP_END_NAMESPACE_STD |
| 6862 | #endif |
| 6863 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 6864 | _LIBCPP_POP_MACROS |
| 6865 | |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 6866 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
Nikolas Klauser | d858e75 | 2022-09-22 21:53:13 +0200 | [diff] [blame] | 6867 | # include <atomic> |
Nikolas Klauser | 1e4ae5d | 2022-11-02 20:27:42 +0100 | [diff] [blame] | 6868 | # include <concepts> |
Nikolas Klauser | d858e75 | 2022-09-22 21:53:13 +0200 | [diff] [blame] | 6869 | # include <iosfwd> |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 6870 | # include <iterator> |
Nikolas Klauser | d858e75 | 2022-09-22 21:53:13 +0200 | [diff] [blame] | 6871 | # include <new> |
| 6872 | # include <typeinfo> |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 6873 | # include <utility> |
| 6874 | #endif |
| 6875 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6876 | #endif // _LIBCPP_REGEX |