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> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 776 | #include <deque> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 777 | #include <stdexcept> |
| 778 | #include <string> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 779 | #include <vector> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 780 | #include <version> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 781 | |
Nikolas Klauser | a0e0edb | 2022-06-16 22:43:46 +0200 | [diff] [blame] | 782 | // standard-mandated includes |
| 783 | |
| 784 | // [iterator.range] |
| 785 | #include <__iterator/access.h> |
| 786 | #include <__iterator/data.h> |
| 787 | #include <__iterator/empty.h> |
| 788 | #include <__iterator/reverse_access.h> |
| 789 | #include <__iterator/size.h> |
| 790 | |
| 791 | // [re.syn] |
| 792 | #include <compare> |
| 793 | #include <initializer_list> |
| 794 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 795 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 796 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 797 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 798 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 799 | _LIBCPP_PUSH_MACROS |
| 800 | #include <__undef_macros> |
| 801 | |
| 802 | |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 803 | #define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096 |
| 804 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 805 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 806 | |
| 807 | namespace regex_constants |
| 808 | { |
| 809 | |
| 810 | // syntax_option_type |
| 811 | |
| 812 | enum syntax_option_type |
| 813 | { |
| 814 | icase = 1 << 0, |
| 815 | nosubs = 1 << 1, |
| 816 | optimize = 1 << 2, |
| 817 | collate = 1 << 3, |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 818 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 819 | ECMAScript = 1 << 9, |
| 820 | #else |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 821 | ECMAScript = 0, |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 822 | #endif |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 823 | basic = 1 << 4, |
| 824 | extended = 1 << 5, |
| 825 | awk = 1 << 6, |
| 826 | grep = 1 << 7, |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 827 | egrep = 1 << 8, |
| 828 | // 1 << 9 may be used by ECMAScript |
| 829 | multiline = 1 << 10 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 830 | }; |
| 831 | |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 832 | _LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 833 | syntax_option_type __get_grammar(syntax_option_type __g) |
| 834 | { |
| 835 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 836 | return static_cast<syntax_option_type>(__g & 0x3F0); |
| 837 | #else |
| 838 | return static_cast<syntax_option_type>(__g & 0x1F0); |
| 839 | #endif |
| 840 | } |
| 841 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 842 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 843 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 844 | syntax_option_type |
| 845 | operator~(syntax_option_type __x) |
| 846 | { |
Marshall Clow | 924cffa | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 847 | return syntax_option_type(~int(__x) & 0x1FF); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 848 | } |
| 849 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 850 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 851 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 852 | syntax_option_type |
| 853 | operator&(syntax_option_type __x, syntax_option_type __y) |
| 854 | { |
| 855 | return syntax_option_type(int(__x) & int(__y)); |
| 856 | } |
| 857 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 858 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 859 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 860 | syntax_option_type |
| 861 | operator|(syntax_option_type __x, syntax_option_type __y) |
| 862 | { |
| 863 | return syntax_option_type(int(__x) | int(__y)); |
| 864 | } |
| 865 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 866 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 867 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 868 | syntax_option_type |
| 869 | operator^(syntax_option_type __x, syntax_option_type __y) |
| 870 | { |
| 871 | return syntax_option_type(int(__x) ^ int(__y)); |
| 872 | } |
| 873 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 874 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 875 | syntax_option_type& |
| 876 | operator&=(syntax_option_type& __x, syntax_option_type __y) |
| 877 | { |
| 878 | __x = __x & __y; |
| 879 | return __x; |
| 880 | } |
| 881 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 882 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 883 | syntax_option_type& |
| 884 | operator|=(syntax_option_type& __x, syntax_option_type __y) |
| 885 | { |
| 886 | __x = __x | __y; |
| 887 | return __x; |
| 888 | } |
| 889 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 890 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 891 | syntax_option_type& |
| 892 | operator^=(syntax_option_type& __x, syntax_option_type __y) |
| 893 | { |
| 894 | __x = __x ^ __y; |
| 895 | return __x; |
| 896 | } |
| 897 | |
| 898 | // match_flag_type |
| 899 | |
| 900 | enum match_flag_type |
| 901 | { |
| 902 | match_default = 0, |
| 903 | match_not_bol = 1 << 0, |
| 904 | match_not_eol = 1 << 1, |
| 905 | match_not_bow = 1 << 2, |
| 906 | match_not_eow = 1 << 3, |
| 907 | match_any = 1 << 4, |
| 908 | match_not_null = 1 << 5, |
| 909 | match_continuous = 1 << 6, |
| 910 | match_prev_avail = 1 << 7, |
| 911 | format_default = 0, |
| 912 | format_sed = 1 << 8, |
| 913 | format_no_copy = 1 << 9, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 914 | format_first_only = 1 << 10, |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 915 | __no_update_pos = 1 << 11, |
| 916 | __full_match = 1 << 12 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 917 | }; |
| 918 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 919 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 920 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 921 | match_flag_type |
| 922 | operator~(match_flag_type __x) |
| 923 | { |
Marshall Clow | 924cffa | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 924 | return match_flag_type(~int(__x) & 0x0FFF); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 925 | } |
| 926 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 927 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 928 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 929 | match_flag_type |
| 930 | operator&(match_flag_type __x, match_flag_type __y) |
| 931 | { |
| 932 | return match_flag_type(int(__x) & int(__y)); |
| 933 | } |
| 934 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 935 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 936 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 937 | match_flag_type |
| 938 | operator|(match_flag_type __x, match_flag_type __y) |
| 939 | { |
| 940 | return match_flag_type(int(__x) | int(__y)); |
| 941 | } |
| 942 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 943 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 944 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 945 | match_flag_type |
| 946 | operator^(match_flag_type __x, match_flag_type __y) |
| 947 | { |
| 948 | return match_flag_type(int(__x) ^ int(__y)); |
| 949 | } |
| 950 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 951 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 952 | match_flag_type& |
| 953 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 954 | { |
| 955 | __x = __x & __y; |
| 956 | return __x; |
| 957 | } |
| 958 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 959 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 960 | match_flag_type& |
| 961 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 962 | { |
| 963 | __x = __x | __y; |
| 964 | return __x; |
| 965 | } |
| 966 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 967 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 968 | match_flag_type& |
| 969 | operator^=(match_flag_type& __x, match_flag_type __y) |
| 970 | { |
| 971 | __x = __x ^ __y; |
| 972 | return __x; |
| 973 | } |
| 974 | |
| 975 | enum error_type |
| 976 | { |
| 977 | error_collate = 1, |
| 978 | error_ctype, |
| 979 | error_escape, |
| 980 | error_backref, |
| 981 | error_brack, |
| 982 | error_paren, |
| 983 | error_brace, |
| 984 | error_badbrace, |
| 985 | error_range, |
| 986 | error_space, |
| 987 | error_badrepeat, |
| 988 | error_complexity, |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 989 | error_stack, |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 990 | __re_err_grammar, |
| 991 | __re_err_empty, |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 992 | __re_err_unknown, |
| 993 | __re_err_parse |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 994 | }; |
| 995 | |
Nikolas Klauser | d26407a | 2021-12-02 14:12:51 +0100 | [diff] [blame] | 996 | } // namespace regex_constants |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 997 | |
| 998 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 999 | : public runtime_error |
| 1000 | { |
| 1001 | regex_constants::error_type __code_; |
| 1002 | public: |
| 1003 | explicit regex_error(regex_constants::error_type __ecode); |
Dimitry Andric | 47269ce | 2020-03-13 19:36:26 +0100 | [diff] [blame] | 1004 | regex_error(const regex_error&) _NOEXCEPT = default; |
Nikolas Klauser | aa3a6cd | 2022-08-24 02:14:29 +0200 | [diff] [blame] | 1005 | ~regex_error() _NOEXCEPT override; |
| 1006 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1007 | regex_constants::error_type code() const {return __code_;} |
| 1008 | }; |
| 1009 | |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 1010 | template <regex_constants::error_type _Ev> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1011 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 1012 | void __throw_regex_error() |
| 1013 | { |
| 1014 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Marshall Clow | 8bf61bb | 2015-08-17 21:14:16 +0000 | [diff] [blame] | 1015 | throw regex_error(_Ev); |
| 1016 | #else |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 1017 | _VSTD::abort(); |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 1018 | #endif |
| 1019 | } |
| 1020 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1021 | template <class _CharT> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1022 | struct _LIBCPP_TEMPLATE_VIS regex_traits |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1023 | { |
| 1024 | public: |
| 1025 | typedef _CharT char_type; |
| 1026 | typedef basic_string<char_type> string_type; |
| 1027 | typedef locale locale_type; |
Dan Albert | 70ee07e | 2020-04-06 13:34:27 -0700 | [diff] [blame] | 1028 | #ifdef __BIONIC__ |
| 1029 | // Originally bionic's ctype_base used its own ctype masks because the |
| 1030 | // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask |
| 1031 | // was only 8 bits wide and already saturated, so it used a wider type here |
| 1032 | // to make room for __regex_word (then a part of this class rather than |
| 1033 | // ctype_base). Bionic has since moved to the builtin ctype_base |
| 1034 | // implementation, but this was not updated to match. Since then Android has |
| 1035 | // needed to maintain a stable libc++ ABI, and this can't be changed without |
| 1036 | // an ABI break. |
| 1037 | typedef uint16_t char_class_type; |
| 1038 | #else |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1039 | typedef ctype_base::mask char_class_type; |
Dan Albert | 70ee07e | 2020-04-06 13:34:27 -0700 | [diff] [blame] | 1040 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1041 | |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 1042 | static const char_class_type __regex_word = ctype_base::__regex_word; |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1043 | private: |
| 1044 | locale __loc_; |
| 1045 | const ctype<char_type>* __ct_; |
| 1046 | const collate<char_type>* __col_; |
| 1047 | |
| 1048 | public: |
| 1049 | regex_traits(); |
| 1050 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1051 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1052 | static size_t length(const char_type* __p) |
| 1053 | {return char_traits<char_type>::length(__p);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1054 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1055 | char_type translate(char_type __c) const {return __c;} |
| 1056 | char_type translate_nocase(char_type __c) const; |
| 1057 | template <class _ForwardIterator> |
| 1058 | string_type |
| 1059 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 1060 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1061 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1062 | string_type |
| 1063 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 1064 | {return __transform_primary(__f, __l, char_type());} |
| 1065 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1066 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1067 | string_type |
| 1068 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 1069 | {return __lookup_collatename(__f, __l, char_type());} |
| 1070 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1071 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1072 | char_class_type |
| 1073 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1074 | bool __icase = false) const |
| 1075 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 1076 | bool isctype(char_type __c, char_class_type __m) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1077 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1078 | int value(char_type __ch, int __radix) const |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1079 | {return __regex_traits_value(__ch, __radix);} |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1080 | locale_type imbue(locale_type __l); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1081 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1082 | locale_type getloc()const {return __loc_;} |
| 1083 | |
| 1084 | private: |
| 1085 | void __init(); |
| 1086 | |
| 1087 | template <class _ForwardIterator> |
| 1088 | string_type |
| 1089 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1090 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1091 | template <class _ForwardIterator> |
| 1092 | string_type |
| 1093 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1094 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1095 | template <class _ForwardIterator> |
| 1096 | string_type |
| 1097 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1098 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1099 | template <class _ForwardIterator> |
| 1100 | string_type |
| 1101 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1102 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1103 | template <class _ForwardIterator> |
| 1104 | char_class_type |
| 1105 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1106 | bool __icase, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1107 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1108 | template <class _ForwardIterator> |
| 1109 | char_class_type |
| 1110 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1111 | bool __icase, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1112 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1113 | |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1114 | static int __regex_traits_value(unsigned char __ch, int __radix); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1115 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1116 | int __regex_traits_value(char __ch, int __radix) const |
| 1117 | {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);} |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1118 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1119 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1120 | int __regex_traits_value(wchar_t __ch, int __radix) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1121 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1122 | }; |
| 1123 | |
| 1124 | template <class _CharT> |
Howard Hinnant | 592cb61 | 2013-03-07 19:38:08 +0000 | [diff] [blame] | 1125 | const typename regex_traits<_CharT>::char_class_type |
| 1126 | regex_traits<_CharT>::__regex_word; |
| 1127 | |
| 1128 | template <class _CharT> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1129 | regex_traits<_CharT>::regex_traits() |
| 1130 | { |
| 1131 | __init(); |
| 1132 | } |
| 1133 | |
| 1134 | template <class _CharT> |
| 1135 | typename regex_traits<_CharT>::char_type |
| 1136 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1137 | { |
| 1138 | return __ct_->tolower(__c); |
| 1139 | } |
| 1140 | |
| 1141 | template <class _CharT> |
| 1142 | template <class _ForwardIterator> |
| 1143 | typename regex_traits<_CharT>::string_type |
| 1144 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1145 | { |
| 1146 | string_type __s(__f, __l); |
| 1147 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1148 | } |
| 1149 | |
| 1150 | template <class _CharT> |
| 1151 | void |
| 1152 | regex_traits<_CharT>::__init() |
| 1153 | { |
| 1154 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1155 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1156 | } |
| 1157 | |
| 1158 | template <class _CharT> |
| 1159 | typename regex_traits<_CharT>::locale_type |
| 1160 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1161 | { |
| 1162 | locale __r = __loc_; |
| 1163 | __loc_ = __l; |
| 1164 | __init(); |
| 1165 | return __r; |
| 1166 | } |
| 1167 | |
| 1168 | // transform_primary is very FreeBSD-specific |
| 1169 | |
| 1170 | template <class _CharT> |
| 1171 | template <class _ForwardIterator> |
| 1172 | typename regex_traits<_CharT>::string_type |
| 1173 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1174 | _ForwardIterator __l, char) const |
| 1175 | { |
| 1176 | const string_type __s(__f, __l); |
| 1177 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1178 | switch (__d.size()) |
| 1179 | { |
| 1180 | case 1: |
| 1181 | break; |
| 1182 | case 12: |
| 1183 | __d[11] = __d[3]; |
| 1184 | break; |
| 1185 | default: |
| 1186 | __d.clear(); |
| 1187 | break; |
| 1188 | } |
| 1189 | return __d; |
| 1190 | } |
| 1191 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1192 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1193 | template <class _CharT> |
| 1194 | template <class _ForwardIterator> |
| 1195 | typename regex_traits<_CharT>::string_type |
| 1196 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1197 | _ForwardIterator __l, wchar_t) const |
| 1198 | { |
| 1199 | const string_type __s(__f, __l); |
| 1200 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1201 | switch (__d.size()) |
| 1202 | { |
| 1203 | case 1: |
| 1204 | break; |
| 1205 | case 3: |
| 1206 | __d[2] = __d[0]; |
| 1207 | break; |
| 1208 | default: |
| 1209 | __d.clear(); |
| 1210 | break; |
| 1211 | } |
| 1212 | return __d; |
| 1213 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1214 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1215 | |
| 1216 | // lookup_collatename is very FreeBSD-specific |
| 1217 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1218 | _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1219 | |
| 1220 | template <class _CharT> |
| 1221 | template <class _ForwardIterator> |
| 1222 | typename regex_traits<_CharT>::string_type |
| 1223 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1224 | _ForwardIterator __l, char) const |
| 1225 | { |
| 1226 | string_type __s(__f, __l); |
| 1227 | string_type __r; |
| 1228 | if (!__s.empty()) |
| 1229 | { |
| 1230 | __r = __get_collation_name(__s.c_str()); |
| 1231 | if (__r.empty() && __s.size() <= 2) |
| 1232 | { |
| 1233 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1234 | if (__r.size() == 1 || __r.size() == 12) |
| 1235 | __r = __s; |
| 1236 | else |
| 1237 | __r.clear(); |
| 1238 | } |
| 1239 | } |
| 1240 | return __r; |
| 1241 | } |
| 1242 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1243 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1244 | template <class _CharT> |
| 1245 | template <class _ForwardIterator> |
| 1246 | typename regex_traits<_CharT>::string_type |
| 1247 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1248 | _ForwardIterator __l, wchar_t) const |
| 1249 | { |
| 1250 | string_type __s(__f, __l); |
| 1251 | string __n; |
| 1252 | __n.reserve(__s.size()); |
| 1253 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1254 | __i != __e; ++__i) |
| 1255 | { |
| 1256 | if (static_cast<unsigned>(*__i) >= 127) |
| 1257 | return string_type(); |
| 1258 | __n.push_back(char(*__i)); |
| 1259 | } |
| 1260 | string_type __r; |
| 1261 | if (!__s.empty()) |
| 1262 | { |
| 1263 | __n = __get_collation_name(__n.c_str()); |
| 1264 | if (!__n.empty()) |
| 1265 | __r.assign(__n.begin(), __n.end()); |
| 1266 | else if (__s.size() <= 2) |
| 1267 | { |
| 1268 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1269 | if (__r.size() == 1 || __r.size() == 3) |
| 1270 | __r = __s; |
| 1271 | else |
| 1272 | __r.clear(); |
| 1273 | } |
| 1274 | } |
| 1275 | return __r; |
| 1276 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1277 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1278 | |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1279 | // lookup_classname |
| 1280 | |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 1281 | regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS |
| 1282 | __get_classname(const char* __s, bool __icase); |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1283 | |
| 1284 | template <class _CharT> |
| 1285 | template <class _ForwardIterator> |
| 1286 | typename regex_traits<_CharT>::char_class_type |
| 1287 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1288 | _ForwardIterator __l, |
| 1289 | bool __icase, char) const |
| 1290 | { |
| 1291 | string_type __s(__f, __l); |
| 1292 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1293 | return __get_classname(__s.c_str(), __icase); |
| 1294 | } |
| 1295 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1296 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1297 | template <class _CharT> |
| 1298 | template <class _ForwardIterator> |
| 1299 | typename regex_traits<_CharT>::char_class_type |
| 1300 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1301 | _ForwardIterator __l, |
| 1302 | bool __icase, wchar_t) const |
| 1303 | { |
| 1304 | string_type __s(__f, __l); |
| 1305 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1306 | string __n; |
| 1307 | __n.reserve(__s.size()); |
| 1308 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1309 | __i != __e; ++__i) |
| 1310 | { |
| 1311 | if (static_cast<unsigned>(*__i) >= 127) |
| 1312 | return char_class_type(); |
| 1313 | __n.push_back(char(*__i)); |
| 1314 | } |
| 1315 | return __get_classname(__n.c_str(), __icase); |
| 1316 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1317 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1318 | |
| 1319 | template <class _CharT> |
| 1320 | bool |
| 1321 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1322 | { |
| 1323 | if (__ct_->is(__m, __c)) |
| 1324 | return true; |
| 1325 | return (__c == '_' && (__m & __regex_word)); |
| 1326 | } |
| 1327 | |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1328 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1329 | bool __is_07(unsigned char __c) |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1330 | { |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1331 | return (__c & 0xF8u) == |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1332 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1333 | 0xF0; |
| 1334 | #else |
| 1335 | 0x30; |
| 1336 | #endif |
| 1337 | } |
| 1338 | |
| 1339 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1340 | bool __is_89(unsigned char __c) |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1341 | { |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1342 | return (__c & 0xFEu) == |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1343 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1344 | 0xF8; |
| 1345 | #else |
| 1346 | 0x38; |
| 1347 | #endif |
| 1348 | } |
| 1349 | |
| 1350 | inline _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1351 | unsigned char __to_lower(unsigned char __c) |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1352 | { |
| 1353 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
Muiez Ahmed | 42e738f | 2022-08-30 14:18:44 -0400 | [diff] [blame] | 1354 | return __c & 0xBF; |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1355 | #else |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 1356 | return __c | 0x20; |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1357 | #endif |
| 1358 | } |
| 1359 | |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1360 | template <class _CharT> |
| 1361 | int |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1362 | regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1363 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1364 | if (__is_07(__ch)) // '0' <= __ch && __ch <= '7' |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1365 | return __ch - '0'; |
| 1366 | if (__radix != 8) |
| 1367 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1368 | if (__is_89(__ch)) // '8' <= __ch && __ch <= '9' |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1369 | return __ch - '0'; |
| 1370 | if (__radix == 16) |
| 1371 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1372 | __ch = __to_lower(__ch); // tolower |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1373 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1374 | return __ch - ('a' - 10); |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1375 | } |
| 1376 | } |
| 1377 | return -1; |
| 1378 | } |
| 1379 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1380 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1381 | template <class _CharT> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1382 | inline |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1383 | int |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1384 | regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1385 | { |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1386 | 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] | 1387 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1388 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1389 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1390 | template <class _CharT> class __node; |
| 1391 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1392 | template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1393 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1394 | template <class _BidirectionalIterator, |
| 1395 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1396 | class _LIBCPP_TEMPLATE_VIS match_results; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1397 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1398 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1399 | struct __state |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1400 | { |
| 1401 | enum |
| 1402 | { |
| 1403 | __end_state = -1000, |
| 1404 | __consume_input, // -999 |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1405 | __begin_marked_expr, // -998 |
| 1406 | __end_marked_expr, // -997 |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1407 | __pop_state, // -996 |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1408 | __accept_and_consume, // -995 |
| 1409 | __accept_but_not_consume, // -994 |
| 1410 | __reject, // -993 |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1411 | __split, |
| 1412 | __repeat |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1413 | }; |
| 1414 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1415 | int __do_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1416 | const _CharT* __first_; |
| 1417 | const _CharT* __current_; |
| 1418 | const _CharT* __last_; |
| 1419 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1420 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1421 | const __node<_CharT>* __node_; |
| 1422 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1423 | bool __at_first_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1424 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1425 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1426 | __state() |
| 1427 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1428 | __node_(nullptr), __flags_() {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1429 | }; |
| 1430 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1431 | // __node |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1432 | |
| 1433 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1434 | class __node |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1435 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1436 | __node(const __node&); |
| 1437 | __node& operator=(const __node&); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1438 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1439 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1440 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1441 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1442 | __node() {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1443 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1444 | virtual ~__node() {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1445 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1446 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 1447 | virtual void __exec(__state&) const {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1448 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 1449 | virtual void __exec_split(bool, __state&) const {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1450 | }; |
| 1451 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1452 | // __end_state |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1453 | |
| 1454 | template <class _CharT> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1455 | class __end_state |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1456 | : public __node<_CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1457 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1458 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1459 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1460 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1461 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1462 | __end_state() {} |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1463 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1464 | virtual void __exec(__state&) const; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1465 | }; |
| 1466 | |
| 1467 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1468 | void |
| 1469 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1470 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1471 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1472 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1473 | |
| 1474 | // __has_one_state |
| 1475 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1476 | template <class _CharT> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1477 | class __has_one_state |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1478 | : public __node<_CharT> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1479 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1480 | __node<_CharT>* __first_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1481 | |
| 1482 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1483 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1484 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1485 | : __first_(__s) {} |
| 1486 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1487 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1488 | __node<_CharT>* first() const {return __first_;} |
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 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1491 | }; |
| 1492 | |
| 1493 | // __owns_one_state |
| 1494 | |
| 1495 | template <class _CharT> |
| 1496 | class __owns_one_state |
| 1497 | : public __has_one_state<_CharT> |
| 1498 | { |
| 1499 | typedef __has_one_state<_CharT> base; |
| 1500 | |
| 1501 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1502 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1503 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1504 | : base(__s) {} |
| 1505 | |
Nikolas Klauser | aa3a6cd | 2022-08-24 02:14:29 +0200 | [diff] [blame] | 1506 | ~__owns_one_state() override; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1507 | }; |
| 1508 | |
| 1509 | template <class _CharT> |
| 1510 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1511 | { |
| 1512 | delete this->first(); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1515 | // __empty_state |
| 1516 | |
| 1517 | template <class _CharT> |
| 1518 | class __empty_state |
| 1519 | : public __owns_one_state<_CharT> |
| 1520 | { |
| 1521 | typedef __owns_one_state<_CharT> base; |
| 1522 | |
| 1523 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1524 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1525 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1526 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1527 | explicit __empty_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1528 | : base(__s) {} |
| 1529 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1530 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1531 | }; |
| 1532 | |
| 1533 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1534 | void |
| 1535 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1536 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1537 | __s.__do_ = __state::__accept_but_not_consume; |
| 1538 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | // __empty_non_own_state |
| 1542 | |
| 1543 | template <class _CharT> |
| 1544 | class __empty_non_own_state |
| 1545 | : public __has_one_state<_CharT> |
| 1546 | { |
| 1547 | typedef __has_one_state<_CharT> base; |
| 1548 | |
| 1549 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1550 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1551 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1552 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1553 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1554 | : base(__s) {} |
| 1555 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1556 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1557 | }; |
| 1558 | |
| 1559 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1560 | void |
| 1561 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1562 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1563 | __s.__do_ = __state::__accept_but_not_consume; |
| 1564 | __s.__node_ = this->first(); |
| 1565 | } |
| 1566 | |
| 1567 | // __repeat_one_loop |
| 1568 | |
| 1569 | template <class _CharT> |
| 1570 | class __repeat_one_loop |
| 1571 | : public __has_one_state<_CharT> |
| 1572 | { |
| 1573 | typedef __has_one_state<_CharT> base; |
| 1574 | |
| 1575 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1576 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1577 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1578 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1579 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1580 | : base(__s) {} |
| 1581 | |
| 1582 | virtual void __exec(__state&) const; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1583 | }; |
| 1584 | |
| 1585 | template <class _CharT> |
| 1586 | void |
| 1587 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1588 | { |
| 1589 | __s.__do_ = __state::__repeat; |
| 1590 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | // __owns_two_states |
| 1594 | |
| 1595 | template <class _CharT> |
| 1596 | class __owns_two_states |
| 1597 | : public __owns_one_state<_CharT> |
| 1598 | { |
| 1599 | typedef __owns_one_state<_CharT> base; |
| 1600 | |
| 1601 | base* __second_; |
| 1602 | |
| 1603 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1604 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1605 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1606 | : base(__s1), __second_(__s2) {} |
| 1607 | |
| 1608 | virtual ~__owns_two_states(); |
| 1609 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1610 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1611 | base* second() const {return __second_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1612 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1613 | base*& second() {return __second_;} |
| 1614 | }; |
| 1615 | |
| 1616 | template <class _CharT> |
| 1617 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1618 | { |
| 1619 | delete __second_; |
| 1620 | } |
| 1621 | |
| 1622 | // __loop |
| 1623 | |
| 1624 | template <class _CharT> |
| 1625 | class __loop |
| 1626 | : public __owns_two_states<_CharT> |
| 1627 | { |
| 1628 | typedef __owns_two_states<_CharT> base; |
| 1629 | |
| 1630 | size_t __min_; |
| 1631 | size_t __max_; |
| 1632 | unsigned __loop_id_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1633 | unsigned __mexp_begin_; |
| 1634 | unsigned __mexp_end_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1635 | bool __greedy_; |
| 1636 | |
| 1637 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1638 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1639 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1640 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1641 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1642 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1643 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1644 | bool __greedy = true, |
| 1645 | size_t __min = 0, |
| 1646 | size_t __max = numeric_limits<size_t>::max()) |
| 1647 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1648 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1649 | __greedy_(__greedy) {} |
| 1650 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1651 | virtual void __exec(__state& __s) const; |
| 1652 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1653 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1654 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1655 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1656 | void __init_repeat(__state& __s) const |
| 1657 | { |
| 1658 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1659 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1660 | { |
| 1661 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1662 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1663 | __s.__sub_matches_[__i].matched = false; |
| 1664 | } |
| 1665 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1666 | }; |
| 1667 | |
| 1668 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1669 | void |
| 1670 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1671 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1672 | if (__s.__do_ == __state::__repeat) |
| 1673 | { |
| 1674 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1675 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1676 | if (__do_repeat && __do_alt && |
| 1677 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1678 | __do_repeat = false; |
| 1679 | if (__do_repeat && __do_alt) |
| 1680 | __s.__do_ = __state::__split; |
| 1681 | else if (__do_repeat) |
| 1682 | { |
| 1683 | __s.__do_ = __state::__accept_but_not_consume; |
| 1684 | __s.__node_ = this->first(); |
| 1685 | __init_repeat(__s); |
| 1686 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1687 | else |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1688 | { |
| 1689 | __s.__do_ = __state::__accept_but_not_consume; |
| 1690 | __s.__node_ = this->second(); |
| 1691 | } |
| 1692 | } |
| 1693 | else |
| 1694 | { |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1695 | __s.__loop_data_[__loop_id_].first = 0; |
| 1696 | bool __do_repeat = 0 < __max_; |
| 1697 | bool __do_alt = 0 >= __min_; |
| 1698 | if (__do_repeat && __do_alt) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1699 | __s.__do_ = __state::__split; |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1700 | else if (__do_repeat) |
| 1701 | { |
| 1702 | __s.__do_ = __state::__accept_but_not_consume; |
| 1703 | __s.__node_ = this->first(); |
| 1704 | __init_repeat(__s); |
| 1705 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1706 | else |
| 1707 | { |
| 1708 | __s.__do_ = __state::__accept_but_not_consume; |
| 1709 | __s.__node_ = this->second(); |
| 1710 | } |
| 1711 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1714 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1715 | void |
| 1716 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1717 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1718 | __s.__do_ = __state::__accept_but_not_consume; |
| 1719 | if (__greedy_ != __second) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1720 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1721 | __s.__node_ = this->first(); |
| 1722 | __init_repeat(__s); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1723 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1724 | else |
| 1725 | __s.__node_ = this->second(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1728 | // __alternate |
| 1729 | |
| 1730 | template <class _CharT> |
| 1731 | class __alternate |
| 1732 | : public __owns_two_states<_CharT> |
| 1733 | { |
| 1734 | typedef __owns_two_states<_CharT> base; |
| 1735 | |
| 1736 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1737 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1738 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1739 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1740 | explicit __alternate(__owns_one_state<_CharT>* __s1, |
| 1741 | __owns_one_state<_CharT>* __s2) |
| 1742 | : base(__s1, __s2) {} |
| 1743 | |
| 1744 | virtual void __exec(__state& __s) const; |
| 1745 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1746 | }; |
| 1747 | |
| 1748 | template <class _CharT> |
| 1749 | void |
| 1750 | __alternate<_CharT>::__exec(__state& __s) const |
| 1751 | { |
| 1752 | __s.__do_ = __state::__split; |
| 1753 | } |
| 1754 | |
| 1755 | template <class _CharT> |
| 1756 | void |
| 1757 | __alternate<_CharT>::__exec_split(bool __second, __state& __s) const |
| 1758 | { |
| 1759 | __s.__do_ = __state::__accept_but_not_consume; |
Howard Hinnant | cbf2f3f | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1760 | if (__second) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1761 | __s.__node_ = this->second(); |
Howard Hinnant | cbf2f3f | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1762 | else |
| 1763 | __s.__node_ = this->first(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1764 | } |
| 1765 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1766 | // __begin_marked_subexpression |
| 1767 | |
| 1768 | template <class _CharT> |
| 1769 | class __begin_marked_subexpression |
| 1770 | : public __owns_one_state<_CharT> |
| 1771 | { |
| 1772 | typedef __owns_one_state<_CharT> base; |
| 1773 | |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1774 | unsigned __mexp_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1775 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1776 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1777 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1778 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1779 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1780 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1781 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1782 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1783 | }; |
| 1784 | |
| 1785 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1786 | void |
| 1787 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1788 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1789 | __s.__do_ = __state::__accept_but_not_consume; |
| 1790 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1791 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
| 1794 | // __end_marked_subexpression |
| 1795 | |
| 1796 | template <class _CharT> |
| 1797 | class __end_marked_subexpression |
| 1798 | : public __owns_one_state<_CharT> |
| 1799 | { |
| 1800 | typedef __owns_one_state<_CharT> base; |
| 1801 | |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1802 | unsigned __mexp_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1803 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1804 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1805 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1806 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1807 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1808 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1809 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1810 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1811 | }; |
| 1812 | |
| 1813 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1814 | void |
| 1815 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1816 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1817 | __s.__do_ = __state::__accept_but_not_consume; |
| 1818 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1819 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1820 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1821 | } |
| 1822 | |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1823 | // __back_ref |
| 1824 | |
| 1825 | template <class _CharT> |
| 1826 | class __back_ref |
| 1827 | : public __owns_one_state<_CharT> |
| 1828 | { |
| 1829 | typedef __owns_one_state<_CharT> base; |
| 1830 | |
| 1831 | unsigned __mexp_; |
| 1832 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1833 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1834 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1835 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1836 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1837 | : base(__s), __mexp_(__mexp) {} |
| 1838 | |
| 1839 | virtual void __exec(__state&) const; |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1840 | }; |
| 1841 | |
| 1842 | template <class _CharT> |
| 1843 | void |
| 1844 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1845 | { |
Marshall Clow | 360e839 | 2015-08-24 15:57:09 +0000 | [diff] [blame] | 1846 | if (__mexp_ > __s.__sub_matches_.size()) |
| 1847 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1848 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1849 | if (__sm.matched) |
| 1850 | { |
| 1851 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1852 | if (__s.__last_ - __s.__current_ >= __len && |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1853 | _VSTD::equal(__sm.first, __sm.second, __s.__current_)) |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1854 | { |
| 1855 | __s.__do_ = __state::__accept_but_not_consume; |
| 1856 | __s.__current_ += __len; |
| 1857 | __s.__node_ = this->first(); |
| 1858 | } |
| 1859 | else |
| 1860 | { |
| 1861 | __s.__do_ = __state::__reject; |
| 1862 | __s.__node_ = nullptr; |
| 1863 | } |
| 1864 | } |
| 1865 | else |
| 1866 | { |
| 1867 | __s.__do_ = __state::__reject; |
| 1868 | __s.__node_ = nullptr; |
| 1869 | } |
| 1870 | } |
| 1871 | |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1872 | // __back_ref_icase |
| 1873 | |
| 1874 | template <class _CharT, class _Traits> |
| 1875 | class __back_ref_icase |
| 1876 | : public __owns_one_state<_CharT> |
| 1877 | { |
| 1878 | typedef __owns_one_state<_CharT> base; |
| 1879 | |
| 1880 | _Traits __traits_; |
| 1881 | unsigned __mexp_; |
| 1882 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1883 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1884 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1885 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1886 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1887 | __node<_CharT>* __s) |
| 1888 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1889 | |
| 1890 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1891 | }; |
| 1892 | |
| 1893 | template <class _CharT, class _Traits> |
| 1894 | void |
| 1895 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1896 | { |
| 1897 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1898 | if (__sm.matched) |
| 1899 | { |
| 1900 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1901 | if (__s.__last_ - __s.__current_ >= __len) |
| 1902 | { |
| 1903 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1904 | { |
| 1905 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1906 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1907 | goto __not_equal; |
| 1908 | } |
| 1909 | __s.__do_ = __state::__accept_but_not_consume; |
| 1910 | __s.__current_ += __len; |
| 1911 | __s.__node_ = this->first(); |
| 1912 | } |
| 1913 | else |
| 1914 | { |
| 1915 | __s.__do_ = __state::__reject; |
| 1916 | __s.__node_ = nullptr; |
| 1917 | } |
| 1918 | } |
| 1919 | else |
| 1920 | { |
| 1921 | __not_equal: |
| 1922 | __s.__do_ = __state::__reject; |
| 1923 | __s.__node_ = nullptr; |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | // __back_ref_collate |
| 1928 | |
| 1929 | template <class _CharT, class _Traits> |
| 1930 | class __back_ref_collate |
| 1931 | : public __owns_one_state<_CharT> |
| 1932 | { |
| 1933 | typedef __owns_one_state<_CharT> base; |
| 1934 | |
| 1935 | _Traits __traits_; |
| 1936 | unsigned __mexp_; |
| 1937 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1938 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1939 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1940 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1941 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1942 | __node<_CharT>* __s) |
| 1943 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1944 | |
| 1945 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1946 | }; |
| 1947 | |
| 1948 | template <class _CharT, class _Traits> |
| 1949 | void |
| 1950 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1951 | { |
| 1952 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1953 | if (__sm.matched) |
| 1954 | { |
| 1955 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1956 | if (__s.__last_ - __s.__current_ >= __len) |
| 1957 | { |
| 1958 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1959 | { |
| 1960 | if (__traits_.translate(__sm.first[__i]) != |
| 1961 | __traits_.translate(__s.__current_[__i])) |
| 1962 | goto __not_equal; |
| 1963 | } |
| 1964 | __s.__do_ = __state::__accept_but_not_consume; |
| 1965 | __s.__current_ += __len; |
| 1966 | __s.__node_ = this->first(); |
| 1967 | } |
| 1968 | else |
| 1969 | { |
| 1970 | __s.__do_ = __state::__reject; |
| 1971 | __s.__node_ = nullptr; |
| 1972 | } |
| 1973 | } |
| 1974 | else |
| 1975 | { |
| 1976 | __not_equal: |
| 1977 | __s.__do_ = __state::__reject; |
| 1978 | __s.__node_ = nullptr; |
| 1979 | } |
| 1980 | } |
| 1981 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1982 | // __word_boundary |
| 1983 | |
| 1984 | template <class _CharT, class _Traits> |
| 1985 | class __word_boundary |
| 1986 | : public __owns_one_state<_CharT> |
| 1987 | { |
| 1988 | typedef __owns_one_state<_CharT> base; |
| 1989 | |
| 1990 | _Traits __traits_; |
| 1991 | bool __invert_; |
| 1992 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1993 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1994 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1995 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1996 | explicit __word_boundary(const _Traits& __traits, bool __invert, |
| 1997 | __node<_CharT>* __s) |
| 1998 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 1999 | |
| 2000 | virtual void __exec(__state&) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2001 | }; |
| 2002 | |
| 2003 | template <class _CharT, class _Traits> |
| 2004 | void |
| 2005 | __word_boundary<_CharT, _Traits>::__exec(__state& __s) const |
| 2006 | { |
| 2007 | bool __is_word_b = false; |
| 2008 | if (__s.__first_ != __s.__last_) |
| 2009 | { |
| 2010 | if (__s.__current_ == __s.__last_) |
| 2011 | { |
| 2012 | if (!(__s.__flags_ & regex_constants::match_not_eow)) |
| 2013 | { |
| 2014 | _CharT __c = __s.__current_[-1]; |
| 2015 | __is_word_b = __c == '_' || |
| 2016 | __traits_.isctype(__c, ctype_base::alnum); |
| 2017 | } |
| 2018 | } |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 2019 | else if (__s.__current_ == __s.__first_ && |
| 2020 | !(__s.__flags_ & regex_constants::match_prev_avail)) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2021 | { |
| 2022 | if (!(__s.__flags_ & regex_constants::match_not_bow)) |
| 2023 | { |
| 2024 | _CharT __c = *__s.__current_; |
| 2025 | __is_word_b = __c == '_' || |
| 2026 | __traits_.isctype(__c, ctype_base::alnum); |
| 2027 | } |
| 2028 | } |
| 2029 | else |
| 2030 | { |
| 2031 | _CharT __c1 = __s.__current_[-1]; |
| 2032 | _CharT __c2 = *__s.__current_; |
| 2033 | bool __is_c1_b = __c1 == '_' || |
| 2034 | __traits_.isctype(__c1, ctype_base::alnum); |
| 2035 | bool __is_c2_b = __c2 == '_' || |
| 2036 | __traits_.isctype(__c2, ctype_base::alnum); |
| 2037 | __is_word_b = __is_c1_b != __is_c2_b; |
| 2038 | } |
| 2039 | } |
| 2040 | if (__is_word_b != __invert_) |
| 2041 | { |
| 2042 | __s.__do_ = __state::__accept_but_not_consume; |
| 2043 | __s.__node_ = this->first(); |
| 2044 | } |
| 2045 | else |
| 2046 | { |
| 2047 | __s.__do_ = __state::__reject; |
| 2048 | __s.__node_ = nullptr; |
| 2049 | } |
| 2050 | } |
| 2051 | |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2052 | // __l_anchor |
| 2053 | |
| 2054 | template <class _CharT> |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2055 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 2056 | bool __is_eol(_CharT __c) |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2057 | { |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 2058 | return __c == '\r' || __c == '\n'; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | template <class _CharT> |
| 2062 | class __l_anchor_multiline |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2063 | : public __owns_one_state<_CharT> |
| 2064 | { |
| 2065 | typedef __owns_one_state<_CharT> base; |
| 2066 | |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2067 | bool __multiline_; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2068 | |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2069 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2070 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2071 | |
| 2072 | _LIBCPP_INLINE_VISIBILITY |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2073 | __l_anchor_multiline(bool __multiline, __node<_CharT>* __s) |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2074 | : base(__s), __multiline_(__multiline) {} |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2075 | |
| 2076 | virtual void __exec(__state&) const; |
| 2077 | }; |
| 2078 | |
| 2079 | template <class _CharT> |
| 2080 | void |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2081 | __l_anchor_multiline<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2082 | { |
Marshall Clow | 5440439 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 2083 | if (__s.__at_first_ && __s.__current_ == __s.__first_ && |
| 2084 | !(__s.__flags_ & regex_constants::match_not_bol)) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2085 | { |
| 2086 | __s.__do_ = __state::__accept_but_not_consume; |
| 2087 | __s.__node_ = this->first(); |
| 2088 | } |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2089 | else if (__multiline_ && |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2090 | !__s.__at_first_ && |
| 2091 | __is_eol(*_VSTD::prev(__s.__current_))) |
| 2092 | { |
| 2093 | __s.__do_ = __state::__accept_but_not_consume; |
| 2094 | __s.__node_ = this->first(); |
| 2095 | } |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2096 | else |
| 2097 | { |
| 2098 | __s.__do_ = __state::__reject; |
| 2099 | __s.__node_ = nullptr; |
| 2100 | } |
| 2101 | } |
| 2102 | |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2103 | // __r_anchor |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2104 | |
| 2105 | template <class _CharT> |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2106 | class __r_anchor_multiline |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2107 | : public __owns_one_state<_CharT> |
| 2108 | { |
| 2109 | typedef __owns_one_state<_CharT> base; |
| 2110 | |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2111 | bool __multiline_; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2112 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2113 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2114 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2115 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2116 | _LIBCPP_INLINE_VISIBILITY |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2117 | __r_anchor_multiline(bool __multiline, __node<_CharT>* __s) |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2118 | : base(__s), __multiline_(__multiline) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2119 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2120 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2121 | }; |
| 2122 | |
| 2123 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2124 | void |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2125 | __r_anchor_multiline<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2126 | { |
Marshall Clow | 5440439 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 2127 | if (__s.__current_ == __s.__last_ && |
| 2128 | !(__s.__flags_ & regex_constants::match_not_eol)) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2129 | { |
| 2130 | __s.__do_ = __state::__accept_but_not_consume; |
| 2131 | __s.__node_ = this->first(); |
| 2132 | } |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2133 | else if (__multiline_ && __is_eol(*__s.__current_)) |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2134 | { |
| 2135 | __s.__do_ = __state::__accept_but_not_consume; |
| 2136 | __s.__node_ = this->first(); |
| 2137 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2138 | else |
| 2139 | { |
| 2140 | __s.__do_ = __state::__reject; |
| 2141 | __s.__node_ = nullptr; |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | // __match_any |
| 2146 | |
| 2147 | template <class _CharT> |
| 2148 | class __match_any |
| 2149 | : public __owns_one_state<_CharT> |
| 2150 | { |
| 2151 | typedef __owns_one_state<_CharT> base; |
| 2152 | |
| 2153 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2154 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2155 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2156 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2157 | __match_any(__node<_CharT>* __s) |
| 2158 | : base(__s) {} |
| 2159 | |
| 2160 | virtual void __exec(__state&) const; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2161 | }; |
| 2162 | |
| 2163 | template <class _CharT> |
| 2164 | void |
| 2165 | __match_any<_CharT>::__exec(__state& __s) const |
| 2166 | { |
| 2167 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 2168 | { |
| 2169 | __s.__do_ = __state::__accept_and_consume; |
| 2170 | ++__s.__current_; |
| 2171 | __s.__node_ = this->first(); |
| 2172 | } |
| 2173 | else |
| 2174 | { |
| 2175 | __s.__do_ = __state::__reject; |
| 2176 | __s.__node_ = nullptr; |
| 2177 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2180 | // __match_any_but_newline |
| 2181 | |
| 2182 | template <class _CharT> |
| 2183 | class __match_any_but_newline |
| 2184 | : public __owns_one_state<_CharT> |
| 2185 | { |
| 2186 | typedef __owns_one_state<_CharT> base; |
| 2187 | |
| 2188 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2189 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2190 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2191 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2192 | __match_any_but_newline(__node<_CharT>* __s) |
| 2193 | : base(__s) {} |
| 2194 | |
Nikolas Klauser | aa3a6cd | 2022-08-24 02:14:29 +0200 | [diff] [blame] | 2195 | void __exec(__state&) const override; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2196 | }; |
| 2197 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2198 | 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] | 2199 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2200 | 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] | 2201 | #endif |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2202 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2203 | // __match_char |
| 2204 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2205 | template <class _CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2206 | class __match_char |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2207 | : public __owns_one_state<_CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2208 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2209 | typedef __owns_one_state<_CharT> base; |
| 2210 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2211 | _CharT __c_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2212 | |
| 2213 | __match_char(const __match_char&); |
| 2214 | __match_char& operator=(const __match_char&); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2215 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2216 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2217 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2218 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2219 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2220 | : base(__s), __c_(__c) {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2221 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2222 | virtual void __exec(__state&) const; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2223 | }; |
| 2224 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2225 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2226 | void |
| 2227 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2228 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2229 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2230 | { |
| 2231 | __s.__do_ = __state::__accept_and_consume; |
| 2232 | ++__s.__current_; |
| 2233 | __s.__node_ = this->first(); |
| 2234 | } |
| 2235 | else |
| 2236 | { |
| 2237 | __s.__do_ = __state::__reject; |
| 2238 | __s.__node_ = nullptr; |
| 2239 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2240 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2241 | |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2242 | // __match_char_icase |
| 2243 | |
| 2244 | template <class _CharT, class _Traits> |
| 2245 | class __match_char_icase |
| 2246 | : public __owns_one_state<_CharT> |
| 2247 | { |
| 2248 | typedef __owns_one_state<_CharT> base; |
| 2249 | |
| 2250 | _Traits __traits_; |
| 2251 | _CharT __c_; |
| 2252 | |
| 2253 | __match_char_icase(const __match_char_icase&); |
| 2254 | __match_char_icase& operator=(const __match_char_icase&); |
| 2255 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2256 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2257 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2258 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2259 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2260 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2261 | |
| 2262 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2263 | }; |
| 2264 | |
| 2265 | template <class _CharT, class _Traits> |
| 2266 | void |
| 2267 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2268 | { |
| 2269 | if (__s.__current_ != __s.__last_ && |
| 2270 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2271 | { |
| 2272 | __s.__do_ = __state::__accept_and_consume; |
| 2273 | ++__s.__current_; |
| 2274 | __s.__node_ = this->first(); |
| 2275 | } |
| 2276 | else |
| 2277 | { |
| 2278 | __s.__do_ = __state::__reject; |
| 2279 | __s.__node_ = nullptr; |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | // __match_char_collate |
| 2284 | |
| 2285 | template <class _CharT, class _Traits> |
| 2286 | class __match_char_collate |
| 2287 | : public __owns_one_state<_CharT> |
| 2288 | { |
| 2289 | typedef __owns_one_state<_CharT> base; |
| 2290 | |
| 2291 | _Traits __traits_; |
| 2292 | _CharT __c_; |
| 2293 | |
| 2294 | __match_char_collate(const __match_char_collate&); |
| 2295 | __match_char_collate& operator=(const __match_char_collate&); |
| 2296 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2297 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2298 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2299 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2300 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2301 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2302 | |
| 2303 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2304 | }; |
| 2305 | |
| 2306 | template <class _CharT, class _Traits> |
| 2307 | void |
| 2308 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2309 | { |
| 2310 | if (__s.__current_ != __s.__last_ && |
| 2311 | __traits_.translate(*__s.__current_) == __c_) |
| 2312 | { |
| 2313 | __s.__do_ = __state::__accept_and_consume; |
| 2314 | ++__s.__current_; |
| 2315 | __s.__node_ = this->first(); |
| 2316 | } |
| 2317 | else |
| 2318 | { |
| 2319 | __s.__do_ = __state::__reject; |
| 2320 | __s.__node_ = nullptr; |
| 2321 | } |
| 2322 | } |
| 2323 | |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2324 | // __bracket_expression |
| 2325 | |
| 2326 | template <class _CharT, class _Traits> |
| 2327 | class __bracket_expression |
| 2328 | : public __owns_one_state<_CharT> |
| 2329 | { |
| 2330 | typedef __owns_one_state<_CharT> base; |
| 2331 | typedef typename _Traits::string_type string_type; |
| 2332 | |
| 2333 | _Traits __traits_; |
| 2334 | vector<_CharT> __chars_; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2335 | vector<_CharT> __neg_chars_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2336 | vector<pair<string_type, string_type> > __ranges_; |
| 2337 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2338 | vector<string_type> __equivalences_; |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2339 | typename regex_traits<_CharT>::char_class_type __mask_; |
| 2340 | typename regex_traits<_CharT>::char_class_type __neg_mask_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2341 | bool __negate_; |
| 2342 | bool __icase_; |
| 2343 | bool __collate_; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2344 | bool __might_have_digraph_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2345 | |
| 2346 | __bracket_expression(const __bracket_expression&); |
| 2347 | __bracket_expression& operator=(const __bracket_expression&); |
| 2348 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2349 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2350 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2351 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2352 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2353 | bool __negate, bool __icase, bool __collate) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2354 | : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), |
| 2355 | __negate_(__negate), __icase_(__icase), __collate_(__collate), |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2356 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2357 | |
| 2358 | virtual void __exec(__state&) const; |
| 2359 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2360 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2361 | bool __negated() const {return __negate_;} |
| 2362 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2363 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2364 | void __add_char(_CharT __c) |
| 2365 | { |
| 2366 | if (__icase_) |
| 2367 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2368 | else if (__collate_) |
| 2369 | __chars_.push_back(__traits_.translate(__c)); |
| 2370 | else |
| 2371 | __chars_.push_back(__c); |
| 2372 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2373 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2374 | void __add_neg_char(_CharT __c) |
| 2375 | { |
| 2376 | if (__icase_) |
| 2377 | __neg_chars_.push_back(__traits_.translate_nocase(__c)); |
| 2378 | else if (__collate_) |
| 2379 | __neg_chars_.push_back(__traits_.translate(__c)); |
| 2380 | else |
| 2381 | __neg_chars_.push_back(__c); |
| 2382 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2383 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2384 | void __add_range(string_type __b, string_type __e) |
| 2385 | { |
| 2386 | if (__collate_) |
| 2387 | { |
| 2388 | if (__icase_) |
| 2389 | { |
| 2390 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2391 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2392 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2393 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2394 | } |
| 2395 | else |
| 2396 | { |
| 2397 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2398 | __b[__i] = __traits_.translate(__b[__i]); |
| 2399 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2400 | __e[__i] = __traits_.translate(__e[__i]); |
| 2401 | } |
| 2402 | __ranges_.push_back(make_pair( |
| 2403 | __traits_.transform(__b.begin(), __b.end()), |
| 2404 | __traits_.transform(__e.begin(), __e.end()))); |
| 2405 | } |
| 2406 | else |
| 2407 | { |
| 2408 | if (__b.size() != 1 || __e.size() != 1) |
Marshall Clow | a521211 | 2019-05-28 22:42:32 +0000 | [diff] [blame] | 2409 | __throw_regex_error<regex_constants::error_range>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2410 | if (__icase_) |
| 2411 | { |
| 2412 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2413 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2414 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2415 | __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e))); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2416 | } |
| 2417 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2418 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2419 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2420 | { |
| 2421 | if (__icase_) |
| 2422 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2423 | __traits_.translate_nocase(__c2))); |
| 2424 | else if (__collate_) |
| 2425 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2426 | __traits_.translate(__c2))); |
| 2427 | else |
| 2428 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2429 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2430 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2431 | void __add_equivalence(const string_type& __s) |
| 2432 | {__equivalences_.push_back(__s);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2433 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2434 | void __add_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2435 | {__mask_ |= __mask;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2436 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2437 | void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2438 | {__neg_mask_ |= __mask;} |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2439 | }; |
| 2440 | |
| 2441 | template <class _CharT, class _Traits> |
| 2442 | void |
| 2443 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2444 | { |
| 2445 | bool __found = false; |
| 2446 | unsigned __consumed = 0; |
| 2447 | if (__s.__current_ != __s.__last_) |
| 2448 | { |
| 2449 | ++__consumed; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2450 | if (__might_have_digraph_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2451 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2452 | const _CharT* __next = _VSTD::next(__s.__current_); |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2453 | if (__next != __s.__last_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2454 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2455 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2456 | if (__icase_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2457 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2458 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2459 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2460 | } |
| 2461 | else if (__collate_) |
| 2462 | { |
| 2463 | __ch2.first = __traits_.translate(__ch2.first); |
| 2464 | __ch2.second = __traits_.translate(__ch2.second); |
| 2465 | } |
| 2466 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2467 | { |
| 2468 | // __ch2 is a digraph in this locale |
| 2469 | ++__consumed; |
| 2470 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2471 | { |
| 2472 | if (__ch2 == __digraphs_[__i]) |
| 2473 | { |
| 2474 | __found = true; |
| 2475 | goto __exit; |
| 2476 | } |
| 2477 | } |
| 2478 | if (__collate_ && !__ranges_.empty()) |
| 2479 | { |
| 2480 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2481 | &__ch2.first + 2); |
| 2482 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2483 | { |
| 2484 | if (__ranges_[__i].first <= __s2 && |
| 2485 | __s2 <= __ranges_[__i].second) |
| 2486 | { |
| 2487 | __found = true; |
| 2488 | goto __exit; |
| 2489 | } |
| 2490 | } |
| 2491 | } |
| 2492 | if (!__equivalences_.empty()) |
| 2493 | { |
| 2494 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2495 | &__ch2.first + 2); |
| 2496 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2497 | { |
| 2498 | if (__s2 == __equivalences_[__i]) |
| 2499 | { |
| 2500 | __found = true; |
| 2501 | goto __exit; |
| 2502 | } |
| 2503 | } |
| 2504 | } |
| 2505 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2506 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2507 | { |
| 2508 | __found = true; |
| 2509 | goto __exit; |
| 2510 | } |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2511 | if (!__traits_.isctype(__ch2.first, __neg_mask_) && |
| 2512 | !__traits_.isctype(__ch2.second, __neg_mask_)) |
| 2513 | { |
| 2514 | __found = true; |
| 2515 | goto __exit; |
| 2516 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2517 | goto __exit; |
| 2518 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2519 | } |
| 2520 | } |
| 2521 | // test *__s.__current_ as not a digraph |
| 2522 | _CharT __ch = *__s.__current_; |
| 2523 | if (__icase_) |
| 2524 | __ch = __traits_.translate_nocase(__ch); |
| 2525 | else if (__collate_) |
| 2526 | __ch = __traits_.translate(__ch); |
| 2527 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2528 | { |
| 2529 | if (__ch == __chars_[__i]) |
| 2530 | { |
| 2531 | __found = true; |
| 2532 | goto __exit; |
| 2533 | } |
| 2534 | } |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2535 | // When there's at least one of __neg_chars_ and __neg_mask_, the set |
| 2536 | // of "__found" chars is |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2537 | // union(complement(union(__neg_chars_, __neg_mask_)), |
| 2538 | // other cases...) |
| 2539 | // |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2540 | // It doesn't make sense to check this when there are no __neg_chars_ |
| 2541 | // and no __neg_mask_. |
| 2542 | if (!(__neg_mask_ == 0 && __neg_chars_.empty())) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2543 | { |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2544 | const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_); |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2545 | const bool __in_neg_chars = |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 2546 | _VSTD::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2547 | __neg_chars_.end(); |
| 2548 | if (!(__in_neg_mask || __in_neg_chars)) |
| 2549 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2550 | __found = true; |
| 2551 | goto __exit; |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2552 | } |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2553 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2554 | if (!__ranges_.empty()) |
| 2555 | { |
| 2556 | string_type __s2 = __collate_ ? |
| 2557 | __traits_.transform(&__ch, &__ch + 1) : |
| 2558 | string_type(1, __ch); |
| 2559 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2560 | { |
| 2561 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2562 | { |
| 2563 | __found = true; |
| 2564 | goto __exit; |
| 2565 | } |
| 2566 | } |
| 2567 | } |
| 2568 | if (!__equivalences_.empty()) |
| 2569 | { |
| 2570 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2571 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2572 | { |
| 2573 | if (__s2 == __equivalences_[__i]) |
| 2574 | { |
| 2575 | __found = true; |
| 2576 | goto __exit; |
| 2577 | } |
| 2578 | } |
| 2579 | } |
| 2580 | if (__traits_.isctype(__ch, __mask_)) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2581 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2582 | __found = true; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2583 | goto __exit; |
| 2584 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2585 | } |
| 2586 | else |
| 2587 | __found = __negate_; // force reject |
| 2588 | __exit: |
| 2589 | if (__found != __negate_) |
| 2590 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2591 | __s.__do_ = __state::__accept_and_consume; |
| 2592 | __s.__current_ += __consumed; |
| 2593 | __s.__node_ = this->first(); |
| 2594 | } |
| 2595 | else |
| 2596 | { |
| 2597 | __s.__do_ = __state::__reject; |
| 2598 | __s.__node_ = nullptr; |
| 2599 | } |
| 2600 | } |
| 2601 | |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 2602 | template <class _CharT, class _Traits> class __lookahead; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2603 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2604 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2605 | class _LIBCPP_TEMPLATE_VIS basic_regex; |
| 2606 | |
| 2607 | typedef basic_regex<char> regex; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2608 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2609 | typedef basic_regex<wchar_t> wregex; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2610 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2611 | |
| 2612 | template <class _CharT, class _Traits> |
| 2613 | class |
| 2614 | _LIBCPP_TEMPLATE_VIS |
| 2615 | _LIBCPP_PREFERRED_NAME(regex) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2616 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2617 | basic_regex |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2618 | { |
| 2619 | public: |
| 2620 | // types: |
| 2621 | typedef _CharT value_type; |
Hubert Tong | 1f1ae9c | 2016-08-02 21:34:48 +0000 | [diff] [blame] | 2622 | typedef _Traits traits_type; |
| 2623 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2624 | typedef regex_constants::syntax_option_type flag_type; |
| 2625 | typedef typename _Traits::locale_type locale_type; |
| 2626 | |
| 2627 | private: |
| 2628 | _Traits __traits_; |
| 2629 | flag_type __flags_; |
| 2630 | unsigned __marked_count_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2631 | unsigned __loop_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2632 | int __open_count_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2633 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2634 | __owns_one_state<_CharT>* __end_; |
| 2635 | |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2636 | typedef _VSTD::__state<_CharT> __state; |
| 2637 | typedef _VSTD::__node<_CharT> __node; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2638 | |
| 2639 | public: |
| 2640 | // constants: |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2641 | static const regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2642 | static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2643 | static const regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2644 | static const regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2645 | static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2646 | static const regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2647 | static const regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2648 | static const regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2649 | static const regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2650 | static const regex_constants::syntax_option_type egrep = regex_constants::egrep; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2651 | static const regex_constants::syntax_option_type multiline = regex_constants::multiline; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2652 | |
| 2653 | // construct/copy/destroy: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2654 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2655 | basic_regex() |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2656 | : __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] | 2657 | __end_(nullptr) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2658 | {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2659 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2660 | 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] | 2661 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2662 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2663 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2664 | __init(__p, __p + __traits_.length(__p)); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2665 | } |
| 2666 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2667 | _LIBCPP_INLINE_VISIBILITY |
Hubert Tong | 1966286 | 2016-08-07 22:26:04 +0000 | [diff] [blame] | 2668 | 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] | 2669 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2670 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2671 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2672 | __init(__p, __p + __len); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2673 | } |
| 2674 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2675 | // basic_regex(const basic_regex&) = default; |
| 2676 | // basic_regex(basic_regex&&) = default; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2677 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2678 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2679 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2680 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2681 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2682 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2683 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2684 | __init(__p.begin(), __p.end()); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2687 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2688 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2689 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 2690 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2691 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2692 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2693 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2694 | __init(__first, __last); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2695 | } |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2696 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2697 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2698 | basic_regex(initializer_list<value_type> __il, |
| 2699 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2700 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2701 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2702 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2703 | __init(__il.begin(), __il.end()); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2704 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2705 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2706 | |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2707 | // ~basic_regex() = default; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2708 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2709 | // basic_regex& operator=(const basic_regex&) = default; |
| 2710 | // basic_regex& operator=(basic_regex&&) = default; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2711 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2712 | basic_regex& operator=(const value_type* __p) |
| 2713 | {return assign(__p);} |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2714 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2715 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2716 | basic_regex& operator=(initializer_list<value_type> __il) |
| 2717 | {return assign(__il);} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2718 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2719 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2720 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2721 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) |
| 2722 | {return assign(__p);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2723 | |
| 2724 | // assign: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2725 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2726 | basic_regex& assign(const basic_regex& __that) |
| 2727 | {return *this = __that;} |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2728 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2729 | _LIBCPP_INLINE_VISIBILITY |
| 2730 | basic_regex& assign(basic_regex&& __that) _NOEXCEPT |
| 2731 | {return *this = _VSTD::move(__that);} |
| 2732 | #endif |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2733 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2734 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
| 2735 | {return assign(__p, __p + __traits_.length(__p), __f);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2736 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | d402893 | 2019-09-25 16:40:30 +0000 | [diff] [blame] | 2737 | 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] | 2738 | {return assign(__p, __p + __len, __f);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2739 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2740 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2741 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2742 | flag_type __f = regex_constants::ECMAScript) |
| 2743 | {return assign(__s.begin(), __s.end(), __f);} |
| 2744 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2745 | template <class _InputIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2746 | _LIBCPP_INLINE_VISIBILITY |
Nikolas Klauser | 15a63e9 | 2022-07-04 22:45:49 +0200 | [diff] [blame] | 2747 | 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] | 2748 | assign(_InputIterator __first, _InputIterator __last, |
| 2749 | flag_type __f = regex_constants::ECMAScript) |
| 2750 | { |
| 2751 | basic_string<_CharT> __t(__first, __last); |
| 2752 | return assign(__t.begin(), __t.end(), __f); |
| 2753 | } |
| 2754 | |
| 2755 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2756 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2757 | void __member_init(flag_type __f) |
| 2758 | { |
| 2759 | __flags_ = __f; |
| 2760 | __marked_count_ = 0; |
| 2761 | __loop_count_ = 0; |
| 2762 | __open_count_ = 0; |
| 2763 | __end_ = nullptr; |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2764 | } |
| 2765 | public: |
| 2766 | |
| 2767 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2768 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2769 | typename enable_if |
| 2770 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2771 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2772 | basic_regex& |
| 2773 | >::type |
| 2774 | assign(_ForwardIterator __first, _ForwardIterator __last, |
| 2775 | flag_type __f = regex_constants::ECMAScript) |
| 2776 | { |
Marshall Clow | ce03dc1 | 2015-01-13 16:49:52 +0000 | [diff] [blame] | 2777 | return assign(basic_regex(__first, __last, __f)); |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2778 | } |
| 2779 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2780 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2781 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2782 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2783 | basic_regex& assign(initializer_list<value_type> __il, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2784 | flag_type __f = regex_constants::ECMAScript) |
| 2785 | {return assign(__il.begin(), __il.end(), __f);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2786 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2787 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2788 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2789 | // const operations: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2790 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2791 | unsigned mark_count() const {return __marked_count_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2792 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2793 | flag_type flags() const {return __flags_;} |
| 2794 | |
| 2795 | // locale: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2796 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2797 | locale_type imbue(locale_type __loc) |
| 2798 | { |
| 2799 | __member_init(ECMAScript); |
| 2800 | __start_.reset(); |
| 2801 | return __traits_.imbue(__loc); |
| 2802 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2803 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2804 | locale_type getloc() const {return __traits_.getloc();} |
| 2805 | |
| 2806 | // swap: |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2807 | void swap(basic_regex& __r); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2808 | |
| 2809 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2810 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2811 | unsigned __loop_count() const {return __loop_count_;} |
| 2812 | |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2813 | _LIBCPP_INLINE_VISIBILITY |
| 2814 | bool __use_multiline() const |
| 2815 | { |
| 2816 | return __get_grammar(__flags_) == ECMAScript && (__flags_ & multiline); |
| 2817 | } |
| 2818 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2819 | template <class _ForwardIterator> |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2820 | void |
| 2821 | __init(_ForwardIterator __first, _ForwardIterator __last); |
| 2822 | template <class _ForwardIterator> |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2823 | _ForwardIterator |
| 2824 | __parse(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2825 | template <class _ForwardIterator> |
| 2826 | _ForwardIterator |
| 2827 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2828 | template <class _ForwardIterator> |
| 2829 | _ForwardIterator |
| 2830 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2831 | template <class _ForwardIterator> |
| 2832 | _ForwardIterator |
| 2833 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2834 | template <class _ForwardIterator> |
| 2835 | _ForwardIterator |
| 2836 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2837 | template <class _ForwardIterator> |
| 2838 | _ForwardIterator |
| 2839 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2840 | template <class _ForwardIterator> |
| 2841 | _ForwardIterator |
| 2842 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2843 | template <class _ForwardIterator> |
| 2844 | _ForwardIterator |
| 2845 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2846 | template <class _ForwardIterator> |
| 2847 | _ForwardIterator |
| 2848 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2849 | template <class _ForwardIterator> |
| 2850 | _ForwardIterator |
| 2851 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2852 | template <class _ForwardIterator> |
| 2853 | _ForwardIterator |
| 2854 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2855 | template <class _ForwardIterator> |
| 2856 | _ForwardIterator |
| 2857 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2858 | template <class _ForwardIterator> |
| 2859 | _ForwardIterator |
| 2860 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2861 | template <class _ForwardIterator> |
| 2862 | _ForwardIterator |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2863 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2864 | __owns_one_state<_CharT>* __s, |
| 2865 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2866 | template <class _ForwardIterator> |
| 2867 | _ForwardIterator |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2868 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2869 | __owns_one_state<_CharT>* __s, |
| 2870 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2871 | template <class _ForwardIterator> |
| 2872 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2873 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2874 | template <class _ForwardIterator> |
| 2875 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2876 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2877 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2878 | template <class _ForwardIterator> |
| 2879 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2880 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2881 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2882 | template <class _ForwardIterator> |
| 2883 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2884 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2885 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2886 | template <class _ForwardIterator> |
| 2887 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2888 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2889 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2890 | template <class _ForwardIterator> |
| 2891 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2892 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2893 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2894 | template <class _ForwardIterator> |
| 2895 | _ForwardIterator |
| 2896 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2897 | template <class _ForwardIterator> |
| 2898 | _ForwardIterator |
| 2899 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2900 | template <class _ForwardIterator> |
| 2901 | _ForwardIterator |
| 2902 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2903 | template <class _ForwardIterator> |
| 2904 | _ForwardIterator |
| 2905 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2906 | template <class _ForwardIterator> |
| 2907 | _ForwardIterator |
| 2908 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2909 | template <class _ForwardIterator> |
| 2910 | _ForwardIterator |
| 2911 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2912 | template <class _ForwardIterator> |
| 2913 | _ForwardIterator |
| 2914 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2915 | template <class _ForwardIterator> |
| 2916 | _ForwardIterator |
| 2917 | __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2918 | template <class _ForwardIterator> |
| 2919 | _ForwardIterator |
| 2920 | __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); |
| 2921 | template <class _ForwardIterator> |
| 2922 | _ForwardIterator |
| 2923 | __parse_term(_ForwardIterator __first, _ForwardIterator __last); |
| 2924 | template <class _ForwardIterator> |
| 2925 | _ForwardIterator |
| 2926 | __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); |
| 2927 | template <class _ForwardIterator> |
| 2928 | _ForwardIterator |
| 2929 | __parse_atom(_ForwardIterator __first, _ForwardIterator __last); |
| 2930 | template <class _ForwardIterator> |
| 2931 | _ForwardIterator |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2932 | __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2933 | template <class _ForwardIterator> |
| 2934 | _ForwardIterator |
| 2935 | __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2936 | template <class _ForwardIterator> |
| 2937 | _ForwardIterator |
| 2938 | __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2939 | template <class _ForwardIterator> |
| 2940 | _ForwardIterator |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2941 | __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2942 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2943 | template <class _ForwardIterator> |
| 2944 | _ForwardIterator |
| 2945 | __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 2946 | template <class _ForwardIterator> |
| 2947 | _ForwardIterator |
| 2948 | __parse_grep(_ForwardIterator __first, _ForwardIterator __last); |
| 2949 | template <class _ForwardIterator> |
| 2950 | _ForwardIterator |
| 2951 | __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2952 | template <class _ForwardIterator> |
| 2953 | _ForwardIterator |
| 2954 | __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2955 | basic_string<_CharT>& __str, |
| 2956 | __bracket_expression<_CharT, _Traits>* __ml); |
| 2957 | template <class _ForwardIterator> |
| 2958 | _ForwardIterator |
| 2959 | __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2960 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2961 | |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 2962 | bool __test_back_ref(_CharT); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 2963 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2964 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2965 | void __push_l_anchor(); |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2966 | void __push_r_anchor(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2967 | void __push_match_any(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2968 | void __push_match_any_but_newline(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2969 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2970 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2971 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2972 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2973 | __mexp_begin, __mexp_end);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2974 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2975 | void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2976 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2977 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2978 | __mexp_begin, __mexp_end, false);} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2979 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2980 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2981 | bool __greedy = true); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2982 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2983 | void __push_char(value_type __c); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 2984 | void __push_back_ref(int __i); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2985 | void __push_alternation(__owns_one_state<_CharT>* __sa, |
| 2986 | __owns_one_state<_CharT>* __sb); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2987 | void __push_begin_marked_subexpression(); |
| 2988 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2989 | void __push_empty(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2990 | void __push_word_boundary(bool); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2991 | void __push_lookahead(const basic_regex&, bool, unsigned); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2992 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2993 | template <class _Allocator> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2994 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2995 | __search(const _CharT* __first, const _CharT* __last, |
| 2996 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2997 | regex_constants::match_flag_type __flags) const; |
| 2998 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2999 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3000 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3001 | __match_at_start(const _CharT* __first, const _CharT* __last, |
| 3002 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3003 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3004 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3005 | bool |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3006 | __match_at_start_ecma(const _CharT* __first, const _CharT* __last, |
| 3007 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3008 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3009 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3010 | bool |
| 3011 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3012 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3013 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3014 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3015 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3016 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 3017 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3018 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3019 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3020 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3021 | friend |
| 3022 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3023 | 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] | 3024 | regex_constants::match_flag_type); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3025 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3026 | template <class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3027 | friend |
| 3028 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3029 | regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&, |
| 3030 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3031 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3032 | template <class _Bp, 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(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3036 | regex_constants::match_flag_type); |
| 3037 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3038 | template <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(const _Cp*, const _Cp*, |
| 3042 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3043 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3044 | template <class _Cp, class _Ap, 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*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3048 | regex_constants::match_flag_type); |
| 3049 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3050 | template <class _ST, class _SA, class _Cp, 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 basic_string<_Cp, _ST, _SA>& __s, |
| 3054 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3055 | regex_constants::match_flag_type __flags); |
| 3056 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3057 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3058 | friend |
| 3059 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3060 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 3061 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 3062 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3063 | regex_constants::match_flag_type __flags); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3064 | |
Howard Hinnant | 4018c48 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 3065 | template <class _Iter, class _Ap, class _Cp, class _Tp> |
| 3066 | friend |
| 3067 | bool |
| 3068 | regex_search(__wrap_iter<_Iter> __first, |
| 3069 | __wrap_iter<_Iter> __last, |
| 3070 | match_results<__wrap_iter<_Iter>, _Ap>& __m, |
| 3071 | const basic_regex<_Cp, _Tp>& __e, |
| 3072 | regex_constants::match_flag_type __flags); |
| 3073 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3074 | template <class, class> friend class __lookahead; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3075 | }; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3076 | |
Louis Dionne | d59f8a5 | 2021-08-17 11:59:07 -0400 | [diff] [blame] | 3077 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | 2dce1f4 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 3078 | template <class _ForwardIterator, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3079 | 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] | 3080 | > |
| 3081 | basic_regex(_ForwardIterator, _ForwardIterator, |
| 3082 | regex_constants::syntax_option_type = regex_constants::ECMAScript) |
| 3083 | -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>; |
| 3084 | #endif |
| 3085 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3086 | template <class _CharT, class _Traits> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 3087 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase; |
| 3088 | template <class _CharT, class _Traits> |
| 3089 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs; |
| 3090 | template <class _CharT, class _Traits> |
| 3091 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize; |
| 3092 | template <class _CharT, class _Traits> |
| 3093 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate; |
| 3094 | template <class _CharT, class _Traits> |
| 3095 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript; |
| 3096 | template <class _CharT, class _Traits> |
| 3097 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic; |
| 3098 | template <class _CharT, class _Traits> |
| 3099 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended; |
| 3100 | template <class _CharT, class _Traits> |
| 3101 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk; |
| 3102 | template <class _CharT, class _Traits> |
| 3103 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep; |
| 3104 | template <class _CharT, class _Traits> |
| 3105 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep; |
| 3106 | |
| 3107 | template <class _CharT, class _Traits> |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3108 | void |
| 3109 | basic_regex<_CharT, _Traits>::swap(basic_regex& __r) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3110 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3111 | using _VSTD::swap; |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3112 | swap(__traits_, __r.__traits_); |
| 3113 | swap(__flags_, __r.__flags_); |
| 3114 | swap(__marked_count_, __r.__marked_count_); |
| 3115 | swap(__loop_count_, __r.__loop_count_); |
| 3116 | swap(__open_count_, __r.__open_count_); |
| 3117 | swap(__start_, __r.__start_); |
| 3118 | swap(__end_, __r.__end_); |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3119 | } |
| 3120 | |
| 3121 | template <class _CharT, class _Traits> |
| 3122 | inline _LIBCPP_INLINE_VISIBILITY |
| 3123 | void |
| 3124 | swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) |
| 3125 | { |
| 3126 | return __x.swap(__y); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3127 | } |
| 3128 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3129 | // __lookahead |
| 3130 | |
| 3131 | template <class _CharT, class _Traits> |
| 3132 | class __lookahead |
| 3133 | : public __owns_one_state<_CharT> |
| 3134 | { |
| 3135 | typedef __owns_one_state<_CharT> base; |
| 3136 | |
| 3137 | basic_regex<_CharT, _Traits> __exp_; |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3138 | unsigned __mexp_; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3139 | bool __invert_; |
| 3140 | |
| 3141 | __lookahead(const __lookahead&); |
| 3142 | __lookahead& operator=(const __lookahead&); |
| 3143 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3144 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3145 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 3146 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3147 | __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] | 3148 | : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {} |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3149 | |
| 3150 | virtual void __exec(__state&) const; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3151 | }; |
| 3152 | |
| 3153 | template <class _CharT, class _Traits> |
| 3154 | void |
| 3155 | __lookahead<_CharT, _Traits>::__exec(__state& __s) const |
| 3156 | { |
| 3157 | match_results<const _CharT*> __m; |
| 3158 | __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 3159 | bool __matched = __exp_.__match_at_start_ecma( |
| 3160 | __s.__current_, __s.__last_, |
| 3161 | __m, |
| 3162 | (__s.__flags_ | regex_constants::match_continuous) & |
| 3163 | ~regex_constants::__full_match, |
| 3164 | __s.__at_first_ && __s.__current_ == __s.__first_); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3165 | if (__matched != __invert_) |
| 3166 | { |
| 3167 | __s.__do_ = __state::__accept_but_not_consume; |
| 3168 | __s.__node_ = this->first(); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3169 | for (unsigned __i = 1; __i < __m.size(); ++__i) { |
| 3170 | __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i]; |
| 3171 | } |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3172 | } |
| 3173 | else |
| 3174 | { |
| 3175 | __s.__do_ = __state::__reject; |
| 3176 | __s.__node_ = nullptr; |
| 3177 | } |
| 3178 | } |
| 3179 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3180 | template <class _CharT, class _Traits> |
| 3181 | template <class _ForwardIterator> |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 3182 | void |
| 3183 | basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last) |
| 3184 | { |
| 3185 | if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; |
| 3186 | _ForwardIterator __temp = __parse(__first, __last); |
| 3187 | if ( __temp != __last) |
| 3188 | __throw_regex_error<regex_constants::__re_err_parse>(); |
| 3189 | } |
| 3190 | |
| 3191 | template <class _CharT, class _Traits> |
| 3192 | template <class _ForwardIterator> |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3193 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3194 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 3195 | _ForwardIterator __last) |
| 3196 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3197 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 3198 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3199 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 3200 | __h.release(); |
| 3201 | __end_ = __start_.get(); |
| 3202 | } |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3203 | switch (__get_grammar(__flags_)) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3204 | { |
| 3205 | case ECMAScript: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3206 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3207 | break; |
| 3208 | case basic: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3209 | __first = __parse_basic_reg_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3210 | break; |
| 3211 | case extended: |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3212 | case awk: |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3213 | __first = __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3214 | break; |
| 3215 | case grep: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3216 | __first = __parse_grep(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3217 | break; |
| 3218 | case egrep: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3219 | __first = __parse_egrep(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3220 | break; |
| 3221 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3222 | __throw_regex_error<regex_constants::__re_err_grammar>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3223 | } |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3224 | return __first; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | template <class _CharT, class _Traits> |
| 3228 | template <class _ForwardIterator> |
| 3229 | _ForwardIterator |
| 3230 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 3231 | _ForwardIterator __last) |
| 3232 | { |
| 3233 | if (__first != __last) |
| 3234 | { |
| 3235 | if (*__first == '^') |
| 3236 | { |
| 3237 | __push_l_anchor(); |
| 3238 | ++__first; |
| 3239 | } |
| 3240 | if (__first != __last) |
| 3241 | { |
| 3242 | __first = __parse_RE_expression(__first, __last); |
| 3243 | if (__first != __last) |
| 3244 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3245 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3246 | if (__temp == __last && *__first == '$') |
| 3247 | { |
| 3248 | __push_r_anchor(); |
| 3249 | ++__first; |
| 3250 | } |
| 3251 | } |
| 3252 | } |
| 3253 | if (__first != __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3254 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3255 | } |
| 3256 | return __first; |
| 3257 | } |
| 3258 | |
| 3259 | template <class _CharT, class _Traits> |
| 3260 | template <class _ForwardIterator> |
| 3261 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3262 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 3263 | _ForwardIterator __last) |
| 3264 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3265 | __owns_one_state<_CharT>* __sa = __end_; |
| 3266 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
| 3267 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3268 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3269 | __first = __temp; |
| 3270 | while (__first != __last && *__first == '|') |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3271 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3272 | __owns_one_state<_CharT>* __sb = __end_; |
| 3273 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3274 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3275 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3276 | __push_alternation(__sa, __sb); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3277 | __first = __temp; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3278 | } |
| 3279 | return __first; |
| 3280 | } |
| 3281 | |
| 3282 | template <class _CharT, class _Traits> |
| 3283 | template <class _ForwardIterator> |
| 3284 | _ForwardIterator |
| 3285 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 3286 | _ForwardIterator __last) |
| 3287 | { |
| 3288 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
| 3289 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3290 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3291 | do |
| 3292 | { |
| 3293 | __first = __temp; |
| 3294 | __temp = __parse_ERE_expression(__first, __last); |
| 3295 | } while (__temp != __first); |
| 3296 | return __first; |
| 3297 | } |
| 3298 | |
| 3299 | template <class _CharT, class _Traits> |
| 3300 | template <class _ForwardIterator> |
| 3301 | _ForwardIterator |
| 3302 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 3303 | _ForwardIterator __last) |
| 3304 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3305 | __owns_one_state<_CharT>* __e = __end_; |
| 3306 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3307 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 3308 | if (__temp == __first && __temp != __last) |
| 3309 | { |
| 3310 | switch (*__temp) |
| 3311 | { |
| 3312 | case '^': |
| 3313 | __push_l_anchor(); |
| 3314 | ++__temp; |
| 3315 | break; |
| 3316 | case '$': |
| 3317 | __push_r_anchor(); |
| 3318 | ++__temp; |
| 3319 | break; |
| 3320 | case '(': |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3321 | __push_begin_marked_subexpression(); |
| 3322 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3323 | ++__open_count_; |
| 3324 | __temp = __parse_extended_reg_exp(++__temp, __last); |
| 3325 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3326 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3327 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3328 | --__open_count_; |
| 3329 | ++__temp; |
| 3330 | break; |
| 3331 | } |
| 3332 | } |
| 3333 | if (__temp != __first) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3334 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 3335 | __marked_count_+1); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3336 | __first = __temp; |
| 3337 | return __first; |
| 3338 | } |
| 3339 | |
| 3340 | template <class _CharT, class _Traits> |
| 3341 | template <class _ForwardIterator> |
| 3342 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3343 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 3344 | _ForwardIterator __last) |
| 3345 | { |
| 3346 | while (true) |
| 3347 | { |
| 3348 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 3349 | if (__temp == __first) |
| 3350 | break; |
| 3351 | __first = __temp; |
| 3352 | } |
| 3353 | return __first; |
| 3354 | } |
| 3355 | |
| 3356 | template <class _CharT, class _Traits> |
| 3357 | template <class _ForwardIterator> |
| 3358 | _ForwardIterator |
| 3359 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 3360 | _ForwardIterator __last) |
| 3361 | { |
| 3362 | if (__first != __last) |
| 3363 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3364 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3365 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3366 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 3367 | if (__temp != __first) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3368 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 3369 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3370 | } |
| 3371 | return __first; |
| 3372 | } |
| 3373 | |
| 3374 | template <class _CharT, class _Traits> |
| 3375 | template <class _ForwardIterator> |
| 3376 | _ForwardIterator |
| 3377 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 3378 | _ForwardIterator __last) |
| 3379 | { |
| 3380 | _ForwardIterator __temp = __first; |
| 3381 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 3382 | if (__temp == __first) |
| 3383 | { |
| 3384 | __temp = __parse_Back_open_paren(__first, __last); |
| 3385 | if (__temp != __first) |
| 3386 | { |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3387 | __push_begin_marked_subexpression(); |
| 3388 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3389 | __first = __parse_RE_expression(__temp, __last); |
| 3390 | __temp = __parse_Back_close_paren(__first, __last); |
| 3391 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3392 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3393 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3394 | __first = __temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3395 | } |
| 3396 | else |
| 3397 | __first = __parse_BACKREF(__first, __last); |
| 3398 | } |
| 3399 | return __first; |
| 3400 | } |
| 3401 | |
| 3402 | template <class _CharT, class _Traits> |
| 3403 | template <class _ForwardIterator> |
| 3404 | _ForwardIterator |
| 3405 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3406 | _ForwardIterator __first, |
| 3407 | _ForwardIterator __last) |
| 3408 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3409 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3410 | if (__temp == __first) |
| 3411 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3412 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3413 | if (__temp == __first) |
| 3414 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3415 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3416 | { |
| 3417 | __push_match_any(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3418 | ++__temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3419 | } |
| 3420 | else |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3421 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3422 | } |
| 3423 | } |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3424 | __first = __temp; |
| 3425 | return __first; |
| 3426 | } |
| 3427 | |
| 3428 | template <class _CharT, class _Traits> |
| 3429 | template <class _ForwardIterator> |
| 3430 | _ForwardIterator |
| 3431 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3432 | _ForwardIterator __first, |
| 3433 | _ForwardIterator __last) |
| 3434 | { |
| 3435 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3436 | if (__temp == __first) |
| 3437 | { |
| 3438 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3439 | if (__temp == __first) |
| 3440 | { |
| 3441 | if (__temp != __last && *__temp == '.') |
| 3442 | { |
| 3443 | __push_match_any(); |
| 3444 | ++__temp; |
| 3445 | } |
| 3446 | else |
| 3447 | __temp = __parse_bracket_expression(__first, __last); |
| 3448 | } |
| 3449 | } |
| 3450 | __first = __temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3451 | return __first; |
| 3452 | } |
| 3453 | |
| 3454 | template <class _CharT, class _Traits> |
| 3455 | template <class _ForwardIterator> |
| 3456 | _ForwardIterator |
| 3457 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3458 | _ForwardIterator __last) |
| 3459 | { |
| 3460 | if (__first != __last) |
| 3461 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3462 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3463 | if (__temp != __last) |
| 3464 | { |
| 3465 | if (*__first == '\\' && *__temp == '(') |
| 3466 | __first = ++__temp; |
| 3467 | } |
| 3468 | } |
| 3469 | return __first; |
| 3470 | } |
| 3471 | |
| 3472 | template <class _CharT, class _Traits> |
| 3473 | template <class _ForwardIterator> |
| 3474 | _ForwardIterator |
| 3475 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3476 | _ForwardIterator __last) |
| 3477 | { |
| 3478 | if (__first != __last) |
| 3479 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3480 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3481 | if (__temp != __last) |
| 3482 | { |
| 3483 | if (*__first == '\\' && *__temp == ')') |
| 3484 | __first = ++__temp; |
| 3485 | } |
| 3486 | } |
| 3487 | return __first; |
| 3488 | } |
| 3489 | |
| 3490 | template <class _CharT, class _Traits> |
| 3491 | template <class _ForwardIterator> |
| 3492 | _ForwardIterator |
| 3493 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3494 | _ForwardIterator __last) |
| 3495 | { |
| 3496 | if (__first != __last) |
| 3497 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3498 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3499 | if (__temp != __last) |
| 3500 | { |
| 3501 | if (*__first == '\\' && *__temp == '{') |
| 3502 | __first = ++__temp; |
| 3503 | } |
| 3504 | } |
| 3505 | return __first; |
| 3506 | } |
| 3507 | |
| 3508 | template <class _CharT, class _Traits> |
| 3509 | template <class _ForwardIterator> |
| 3510 | _ForwardIterator |
| 3511 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3512 | _ForwardIterator __last) |
| 3513 | { |
| 3514 | if (__first != __last) |
| 3515 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3516 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3517 | if (__temp != __last) |
| 3518 | { |
| 3519 | if (*__first == '\\' && *__temp == '}') |
| 3520 | __first = ++__temp; |
| 3521 | } |
| 3522 | } |
| 3523 | return __first; |
| 3524 | } |
| 3525 | |
| 3526 | template <class _CharT, class _Traits> |
| 3527 | template <class _ForwardIterator> |
| 3528 | _ForwardIterator |
| 3529 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 3530 | _ForwardIterator __last) |
| 3531 | { |
| 3532 | if (__first != __last) |
| 3533 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3534 | _ForwardIterator __temp = _VSTD::next(__first); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 3535 | if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp)) |
| 3536 | __first = ++__temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3537 | } |
| 3538 | return __first; |
| 3539 | } |
| 3540 | |
| 3541 | template <class _CharT, class _Traits> |
| 3542 | template <class _ForwardIterator> |
| 3543 | _ForwardIterator |
| 3544 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3545 | _ForwardIterator __last) |
| 3546 | { |
| 3547 | if (__first != __last) |
| 3548 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3549 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3550 | if (__temp == __last && *__first == '$') |
| 3551 | return __first; |
| 3552 | // Not called inside a bracket |
| 3553 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3554 | return __first; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3555 | __push_char(*__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3556 | ++__first; |
| 3557 | } |
| 3558 | return __first; |
| 3559 | } |
| 3560 | |
| 3561 | template <class _CharT, class _Traits> |
| 3562 | template <class _ForwardIterator> |
| 3563 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3564 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3565 | _ForwardIterator __last) |
| 3566 | { |
| 3567 | if (__first != __last) |
| 3568 | { |
| 3569 | switch (*__first) |
| 3570 | { |
| 3571 | case '^': |
| 3572 | case '.': |
| 3573 | case '[': |
| 3574 | case '$': |
| 3575 | case '(': |
| 3576 | case '|': |
| 3577 | case '*': |
| 3578 | case '+': |
| 3579 | case '?': |
| 3580 | case '{': |
| 3581 | case '\\': |
| 3582 | break; |
| 3583 | case ')': |
| 3584 | if (__open_count_ == 0) |
| 3585 | { |
| 3586 | __push_char(*__first); |
| 3587 | ++__first; |
| 3588 | } |
| 3589 | break; |
| 3590 | default: |
| 3591 | __push_char(*__first); |
| 3592 | ++__first; |
| 3593 | break; |
| 3594 | } |
| 3595 | } |
| 3596 | return __first; |
| 3597 | } |
| 3598 | |
| 3599 | template <class _CharT, class _Traits> |
| 3600 | template <class _ForwardIterator> |
| 3601 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3602 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3603 | _ForwardIterator __last) |
| 3604 | { |
| 3605 | if (__first != __last) |
| 3606 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3607 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3608 | if (__temp != __last) |
| 3609 | { |
| 3610 | if (*__first == '\\') |
| 3611 | { |
| 3612 | switch (*__temp) |
| 3613 | { |
| 3614 | case '^': |
| 3615 | case '.': |
| 3616 | case '*': |
| 3617 | case '[': |
| 3618 | case '$': |
| 3619 | case '\\': |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3620 | __push_char(*__temp); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3621 | __first = ++__temp; |
| 3622 | break; |
| 3623 | } |
| 3624 | } |
| 3625 | } |
| 3626 | } |
| 3627 | return __first; |
| 3628 | } |
| 3629 | |
| 3630 | template <class _CharT, class _Traits> |
| 3631 | template <class _ForwardIterator> |
| 3632 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3633 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3634 | _ForwardIterator __last) |
| 3635 | { |
| 3636 | if (__first != __last) |
| 3637 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3638 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3639 | if (__temp != __last) |
| 3640 | { |
| 3641 | if (*__first == '\\') |
| 3642 | { |
| 3643 | switch (*__temp) |
| 3644 | { |
| 3645 | case '^': |
| 3646 | case '.': |
| 3647 | case '*': |
| 3648 | case '[': |
| 3649 | case '$': |
| 3650 | case '\\': |
| 3651 | case '(': |
| 3652 | case ')': |
| 3653 | case '|': |
| 3654 | case '+': |
| 3655 | case '?': |
| 3656 | case '{': |
Howard Hinnant | 73072eb | 2013-06-28 20:31:05 +0000 | [diff] [blame] | 3657 | case '}': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3658 | __push_char(*__temp); |
| 3659 | __first = ++__temp; |
| 3660 | break; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3661 | default: |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3662 | if (__get_grammar(__flags_) == awk) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3663 | __first = __parse_awk_escape(++__first, __last); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 3664 | else if(__test_back_ref(*__temp)) |
| 3665 | __first = ++__temp; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3666 | break; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3667 | } |
| 3668 | } |
| 3669 | } |
| 3670 | } |
| 3671 | return __first; |
| 3672 | } |
| 3673 | |
| 3674 | template <class _CharT, class _Traits> |
| 3675 | template <class _ForwardIterator> |
| 3676 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3677 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3678 | _ForwardIterator __last, |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3679 | __owns_one_state<_CharT>* __s, |
| 3680 | unsigned __mexp_begin, |
| 3681 | unsigned __mexp_end) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3682 | { |
| 3683 | if (__first != __last) |
| 3684 | { |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3685 | if (*__first == '*') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3686 | { |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3687 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3688 | ++__first; |
| 3689 | } |
| 3690 | else |
| 3691 | { |
| 3692 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3693 | if (__temp != __first) |
| 3694 | { |
| 3695 | int __min = 0; |
| 3696 | __first = __temp; |
| 3697 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 3698 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3699 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3700 | __first = __temp; |
| 3701 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3702 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3703 | if (*__first != ',') |
| 3704 | { |
| 3705 | __temp = __parse_Back_close_brace(__first, __last); |
| 3706 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3707 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3708 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3709 | true); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3710 | __first = __temp; |
| 3711 | } |
| 3712 | else |
| 3713 | { |
| 3714 | ++__first; // consume ',' |
| 3715 | int __max = -1; |
| 3716 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3717 | __temp = __parse_Back_close_brace(__first, __last); |
| 3718 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3719 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3720 | if (__max == -1) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3721 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3722 | else |
| 3723 | { |
| 3724 | if (__max < __min) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3725 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3726 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3727 | true); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3728 | } |
| 3729 | __first = __temp; |
| 3730 | } |
| 3731 | } |
| 3732 | } |
| 3733 | } |
| 3734 | return __first; |
| 3735 | } |
| 3736 | |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3737 | template <class _CharT, class _Traits> |
| 3738 | template <class _ForwardIterator> |
| 3739 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3740 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3741 | _ForwardIterator __last, |
| 3742 | __owns_one_state<_CharT>* __s, |
| 3743 | unsigned __mexp_begin, |
| 3744 | unsigned __mexp_end) |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3745 | { |
| 3746 | if (__first != __last) |
| 3747 | { |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3748 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3749 | switch (*__first) |
| 3750 | { |
| 3751 | case '*': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3752 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3753 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3754 | { |
| 3755 | ++__first; |
| 3756 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3757 | } |
| 3758 | else |
| 3759 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3760 | break; |
| 3761 | case '+': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3762 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3763 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3764 | { |
| 3765 | ++__first; |
| 3766 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3767 | } |
| 3768 | else |
| 3769 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3770 | break; |
| 3771 | case '?': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3772 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3773 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3774 | { |
| 3775 | ++__first; |
| 3776 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3777 | } |
| 3778 | else |
| 3779 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3780 | break; |
| 3781 | case '{': |
| 3782 | { |
| 3783 | int __min; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3784 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3785 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3786 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3787 | __first = __temp; |
| 3788 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3789 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3790 | switch (*__first) |
| 3791 | { |
| 3792 | case '}': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3793 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3794 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3795 | { |
| 3796 | ++__first; |
| 3797 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3798 | } |
| 3799 | else |
| 3800 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3801 | break; |
| 3802 | case ',': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3803 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3804 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3805 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3806 | if (*__first == '}') |
| 3807 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3808 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3809 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3810 | { |
| 3811 | ++__first; |
| 3812 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3813 | } |
| 3814 | else |
| 3815 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3816 | } |
| 3817 | else |
| 3818 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3819 | int __max = -1; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3820 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 3821 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3822 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3823 | __first = __temp; |
| 3824 | if (__first == __last || *__first != '}') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3825 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3826 | ++__first; |
| 3827 | if (__max < __min) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3828 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3829 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3830 | { |
| 3831 | ++__first; |
| 3832 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3833 | } |
| 3834 | else |
| 3835 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3836 | } |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3837 | break; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3838 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3839 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3840 | } |
| 3841 | } |
| 3842 | break; |
| 3843 | } |
| 3844 | } |
| 3845 | return __first; |
| 3846 | } |
| 3847 | |
| 3848 | template <class _CharT, class _Traits> |
| 3849 | template <class _ForwardIterator> |
| 3850 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3851 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3852 | _ForwardIterator __last) |
| 3853 | { |
| 3854 | if (__first != __last && *__first == '[') |
| 3855 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3856 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3857 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3858 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3859 | bool __negate = false; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3860 | if (*__first == '^') |
| 3861 | { |
| 3862 | ++__first; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3863 | __negate = true; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3864 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3865 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3866 | // __ml owned by *this |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3867 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3868 | __throw_regex_error<regex_constants::error_brack>(); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3869 | if (__get_grammar(__flags_) != ECMAScript && *__first == ']') |
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 | __ml->__add_char(']'); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3872 | ++__first; |
| 3873 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3874 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3875 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3876 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3877 | if (*__first == '-') |
| 3878 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3879 | __ml->__add_char('-'); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3880 | ++__first; |
| 3881 | } |
| 3882 | if (__first == __last || *__first != ']') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3883 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3884 | ++__first; |
| 3885 | } |
| 3886 | return __first; |
| 3887 | } |
| 3888 | |
| 3889 | template <class _CharT, class _Traits> |
| 3890 | template <class _ForwardIterator> |
| 3891 | _ForwardIterator |
| 3892 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3893 | _ForwardIterator __last, |
| 3894 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3895 | { |
| 3896 | if (__first != __last) |
| 3897 | { |
| 3898 | while (true) |
| 3899 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3900 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3901 | __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3902 | if (__temp == __first) |
| 3903 | break; |
| 3904 | __first = __temp; |
| 3905 | } |
| 3906 | } |
| 3907 | return __first; |
| 3908 | } |
| 3909 | |
| 3910 | template <class _CharT, class _Traits> |
| 3911 | template <class _ForwardIterator> |
| 3912 | _ForwardIterator |
| 3913 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3914 | _ForwardIterator __last, |
| 3915 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3916 | { |
| 3917 | if (__first != __last && *__first != ']') |
| 3918 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3919 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3920 | basic_string<_CharT> __start_range; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3921 | if (__temp != __last && *__first == '[') |
| 3922 | { |
| 3923 | if (*__temp == '=') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3924 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3925 | else if (*__temp == ':') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3926 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3927 | else if (*__temp == '.') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3928 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3929 | } |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3930 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3931 | if (__start_range.empty()) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3932 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3933 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3934 | { |
| 3935 | if (__grammar == ECMAScript) |
| 3936 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3937 | else |
| 3938 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3939 | } |
| 3940 | else |
| 3941 | { |
| 3942 | __start_range = *__first; |
| 3943 | ++__first; |
| 3944 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3945 | } |
| 3946 | if (__first != __last && *__first != ']') |
| 3947 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3948 | __temp = _VSTD::next(__first); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3949 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3950 | { |
| 3951 | // parse a range |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3952 | basic_string<_CharT> __end_range; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3953 | __first = __temp; |
| 3954 | ++__temp; |
| 3955 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3956 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3957 | else |
| 3958 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3959 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3960 | { |
| 3961 | if (__grammar == ECMAScript) |
| 3962 | __first = __parse_class_escape(++__first, __last, |
| 3963 | __end_range, __ml); |
| 3964 | else |
| 3965 | __first = __parse_awk_escape(++__first, __last, |
| 3966 | &__end_range); |
| 3967 | } |
| 3968 | else |
| 3969 | { |
| 3970 | __end_range = *__first; |
| 3971 | ++__first; |
| 3972 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3973 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3974 | __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3975 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3976 | else if (!__start_range.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3977 | { |
| 3978 | if (__start_range.size() == 1) |
| 3979 | __ml->__add_char(__start_range[0]); |
| 3980 | else |
| 3981 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3982 | } |
| 3983 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3984 | else if (!__start_range.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3985 | { |
| 3986 | if (__start_range.size() == 1) |
| 3987 | __ml->__add_char(__start_range[0]); |
| 3988 | else |
| 3989 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3990 | } |
| 3991 | } |
| 3992 | return __first; |
| 3993 | } |
| 3994 | |
| 3995 | template <class _CharT, class _Traits> |
| 3996 | template <class _ForwardIterator> |
| 3997 | _ForwardIterator |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3998 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 3999 | _ForwardIterator __last, |
| 4000 | basic_string<_CharT>& __str, |
| 4001 | __bracket_expression<_CharT, _Traits>* __ml) |
| 4002 | { |
| 4003 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4004 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4005 | switch (*__first) |
| 4006 | { |
| 4007 | case 0: |
| 4008 | __str = *__first; |
| 4009 | return ++__first; |
| 4010 | case 'b': |
| 4011 | __str = _CharT(8); |
| 4012 | return ++__first; |
| 4013 | case 'd': |
| 4014 | __ml->__add_class(ctype_base::digit); |
| 4015 | return ++__first; |
| 4016 | case 'D': |
| 4017 | __ml->__add_neg_class(ctype_base::digit); |
| 4018 | return ++__first; |
| 4019 | case 's': |
| 4020 | __ml->__add_class(ctype_base::space); |
| 4021 | return ++__first; |
| 4022 | case 'S': |
| 4023 | __ml->__add_neg_class(ctype_base::space); |
| 4024 | return ++__first; |
| 4025 | case 'w': |
| 4026 | __ml->__add_class(ctype_base::alnum); |
| 4027 | __ml->__add_char('_'); |
| 4028 | return ++__first; |
| 4029 | case 'W': |
| 4030 | __ml->__add_neg_class(ctype_base::alnum); |
| 4031 | __ml->__add_neg_char('_'); |
| 4032 | return ++__first; |
| 4033 | } |
| 4034 | __first = __parse_character_escape(__first, __last, &__str); |
| 4035 | return __first; |
| 4036 | } |
| 4037 | |
| 4038 | template <class _CharT, class _Traits> |
| 4039 | template <class _ForwardIterator> |
| 4040 | _ForwardIterator |
| 4041 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 4042 | _ForwardIterator __last, |
| 4043 | basic_string<_CharT>* __str) |
| 4044 | { |
| 4045 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4046 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4047 | switch (*__first) |
| 4048 | { |
| 4049 | case '\\': |
| 4050 | case '"': |
| 4051 | case '/': |
| 4052 | if (__str) |
| 4053 | *__str = *__first; |
| 4054 | else |
| 4055 | __push_char(*__first); |
| 4056 | return ++__first; |
| 4057 | case 'a': |
| 4058 | if (__str) |
| 4059 | *__str = _CharT(7); |
| 4060 | else |
| 4061 | __push_char(_CharT(7)); |
| 4062 | return ++__first; |
| 4063 | case 'b': |
| 4064 | if (__str) |
| 4065 | *__str = _CharT(8); |
| 4066 | else |
| 4067 | __push_char(_CharT(8)); |
| 4068 | return ++__first; |
| 4069 | case 'f': |
| 4070 | if (__str) |
| 4071 | *__str = _CharT(0xC); |
| 4072 | else |
| 4073 | __push_char(_CharT(0xC)); |
| 4074 | return ++__first; |
| 4075 | case 'n': |
| 4076 | if (__str) |
| 4077 | *__str = _CharT(0xA); |
| 4078 | else |
| 4079 | __push_char(_CharT(0xA)); |
| 4080 | return ++__first; |
| 4081 | case 'r': |
| 4082 | if (__str) |
| 4083 | *__str = _CharT(0xD); |
| 4084 | else |
| 4085 | __push_char(_CharT(0xD)); |
| 4086 | return ++__first; |
| 4087 | case 't': |
| 4088 | if (__str) |
| 4089 | *__str = _CharT(0x9); |
| 4090 | else |
| 4091 | __push_char(_CharT(0x9)); |
| 4092 | return ++__first; |
| 4093 | case 'v': |
| 4094 | if (__str) |
| 4095 | *__str = _CharT(0xB); |
| 4096 | else |
| 4097 | __push_char(_CharT(0xB)); |
| 4098 | return ++__first; |
| 4099 | } |
| 4100 | if ('0' <= *__first && *__first <= '7') |
| 4101 | { |
| 4102 | unsigned __val = *__first - '0'; |
| 4103 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 4104 | { |
| 4105 | __val = 8 * __val + *__first - '0'; |
| 4106 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
Howard Hinnant | a309687 | 2013-07-02 17:43:31 +0000 | [diff] [blame] | 4107 | __val = 8 * __val + *__first++ - '0'; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4108 | } |
| 4109 | if (__str) |
| 4110 | *__str = _CharT(__val); |
| 4111 | else |
| 4112 | __push_char(_CharT(__val)); |
| 4113 | } |
| 4114 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4115 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4116 | return __first; |
| 4117 | } |
| 4118 | |
| 4119 | template <class _CharT, class _Traits> |
| 4120 | template <class _ForwardIterator> |
| 4121 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4122 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4123 | _ForwardIterator __last, |
| 4124 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4125 | { |
| 4126 | // Found [= |
| 4127 | // This means =] must exist |
| 4128 | value_type _Equal_close[2] = {'=', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4129 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4130 | _Equal_close+2); |
| 4131 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4132 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4133 | // [__first, __temp) contains all text in [= ... =] |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4134 | string_type __collate_name = |
| 4135 | __traits_.lookup_collatename(__first, __temp); |
| 4136 | if (__collate_name.empty()) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4137 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4138 | string_type __equiv_name = |
| 4139 | __traits_.transform_primary(__collate_name.begin(), |
| 4140 | __collate_name.end()); |
| 4141 | if (!__equiv_name.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4142 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4143 | else |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4144 | { |
| 4145 | switch (__collate_name.size()) |
| 4146 | { |
| 4147 | case 1: |
| 4148 | __ml->__add_char(__collate_name[0]); |
| 4149 | break; |
| 4150 | case 2: |
| 4151 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 4152 | break; |
| 4153 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4154 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4155 | } |
| 4156 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4157 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4158 | return __first; |
| 4159 | } |
| 4160 | |
| 4161 | template <class _CharT, class _Traits> |
| 4162 | template <class _ForwardIterator> |
| 4163 | _ForwardIterator |
| 4164 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4165 | _ForwardIterator __last, |
| 4166 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4167 | { |
| 4168 | // Found [: |
| 4169 | // This means :] must exist |
| 4170 | value_type _Colon_close[2] = {':', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4171 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4172 | _Colon_close+2); |
| 4173 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4174 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4175 | // [__first, __temp) contains all text in [: ... :] |
| 4176 | typedef typename _Traits::char_class_type char_class_type; |
| 4177 | char_class_type __class_type = |
| 4178 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 4179 | if (__class_type == 0) |
Mikhail Maltsev | 6ef945b | 2018-01-24 12:45:18 +0000 | [diff] [blame] | 4180 | __throw_regex_error<regex_constants::error_ctype>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4181 | __ml->__add_class(__class_type); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4182 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4183 | return __first; |
| 4184 | } |
| 4185 | |
| 4186 | template <class _CharT, class _Traits> |
| 4187 | template <class _ForwardIterator> |
| 4188 | _ForwardIterator |
| 4189 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4190 | _ForwardIterator __last, |
| 4191 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4192 | { |
| 4193 | // Found [. |
| 4194 | // This means .] must exist |
| 4195 | value_type _Dot_close[2] = {'.', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4196 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4197 | _Dot_close+2); |
| 4198 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4199 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4200 | // [__first, __temp) contains all text in [. ... .] |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4201 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 4202 | switch (__col_sym.size()) |
| 4203 | { |
| 4204 | case 1: |
| 4205 | case 2: |
| 4206 | break; |
| 4207 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4208 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4209 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4210 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4211 | return __first; |
| 4212 | } |
| 4213 | |
| 4214 | template <class _CharT, class _Traits> |
| 4215 | template <class _ForwardIterator> |
| 4216 | _ForwardIterator |
| 4217 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 4218 | _ForwardIterator __last, |
| 4219 | int& __c) |
| 4220 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4221 | if (__first != __last ) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4222 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4223 | int __val = __traits_.value(*__first, 10); |
| 4224 | if ( __val != -1 ) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4225 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4226 | __c = __val; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4227 | for (++__first; |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4228 | __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; |
| 4229 | ++__first) |
| 4230 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4231 | if (__c >= numeric_limits<int>::max() / 10) |
Marshall Clow | 863ae38 | 2017-10-19 17:39:16 +0000 | [diff] [blame] | 4232 | __throw_regex_error<regex_constants::error_badbrace>(); |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4233 | __c *= 10; |
| 4234 | __c += __val; |
| 4235 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4236 | } |
| 4237 | } |
| 4238 | return __first; |
| 4239 | } |
| 4240 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4241 | template <class _CharT, class _Traits> |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4242 | template <class _ForwardIterator> |
| 4243 | _ForwardIterator |
| 4244 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 4245 | _ForwardIterator __last) |
| 4246 | { |
| 4247 | __owns_one_state<_CharT>* __sa = __end_; |
| 4248 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 4249 | if (__temp == __first) |
| 4250 | __push_empty(); |
| 4251 | __first = __temp; |
| 4252 | while (__first != __last && *__first == '|') |
| 4253 | { |
| 4254 | __owns_one_state<_CharT>* __sb = __end_; |
| 4255 | __temp = __parse_alternative(++__first, __last); |
| 4256 | if (__temp == __first) |
| 4257 | __push_empty(); |
| 4258 | __push_alternation(__sa, __sb); |
| 4259 | __first = __temp; |
| 4260 | } |
| 4261 | return __first; |
| 4262 | } |
| 4263 | |
| 4264 | template <class _CharT, class _Traits> |
| 4265 | template <class _ForwardIterator> |
| 4266 | _ForwardIterator |
| 4267 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 4268 | _ForwardIterator __last) |
| 4269 | { |
| 4270 | while (true) |
| 4271 | { |
| 4272 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 4273 | if (__temp == __first) |
| 4274 | break; |
| 4275 | __first = __temp; |
| 4276 | } |
| 4277 | return __first; |
| 4278 | } |
| 4279 | |
| 4280 | template <class _CharT, class _Traits> |
| 4281 | template <class _ForwardIterator> |
| 4282 | _ForwardIterator |
| 4283 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 4284 | _ForwardIterator __last) |
| 4285 | { |
| 4286 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 4287 | if (__temp == __first) |
| 4288 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4289 | __owns_one_state<_CharT>* __e = __end_; |
| 4290 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4291 | __temp = __parse_atom(__first, __last); |
| 4292 | if (__temp != __first) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4293 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 4294 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4295 | } |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4296 | else |
| 4297 | __first = __temp; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4298 | return __first; |
| 4299 | } |
| 4300 | |
| 4301 | template <class _CharT, class _Traits> |
| 4302 | template <class _ForwardIterator> |
| 4303 | _ForwardIterator |
| 4304 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 4305 | _ForwardIterator __last) |
| 4306 | { |
| 4307 | if (__first != __last) |
| 4308 | { |
| 4309 | switch (*__first) |
| 4310 | { |
| 4311 | case '^': |
| 4312 | __push_l_anchor(); |
| 4313 | ++__first; |
| 4314 | break; |
| 4315 | case '$': |
| 4316 | __push_r_anchor(); |
| 4317 | ++__first; |
| 4318 | break; |
| 4319 | case '\\': |
| 4320 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4321 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4322 | if (__temp != __last) |
| 4323 | { |
| 4324 | if (*__temp == 'b') |
| 4325 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4326 | __push_word_boundary(false); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4327 | __first = ++__temp; |
| 4328 | } |
| 4329 | else if (*__temp == 'B') |
| 4330 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4331 | __push_word_boundary(true); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4332 | __first = ++__temp; |
| 4333 | } |
| 4334 | } |
| 4335 | } |
| 4336 | break; |
| 4337 | case '(': |
| 4338 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4339 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4340 | if (__temp != __last && *__temp == '?') |
| 4341 | { |
| 4342 | if (++__temp != __last) |
| 4343 | { |
| 4344 | switch (*__temp) |
| 4345 | { |
| 4346 | case '=': |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4347 | { |
| 4348 | basic_regex __exp; |
| 4349 | __exp.__flags_ = __flags_; |
| 4350 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4351 | unsigned __mexp = __exp.__marked_count_; |
| 4352 | __push_lookahead(_VSTD::move(__exp), false, __marked_count_); |
| 4353 | __marked_count_ += __mexp; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4354 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4355 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4356 | __first = ++__temp; |
| 4357 | } |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4358 | break; |
| 4359 | case '!': |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4360 | { |
| 4361 | basic_regex __exp; |
| 4362 | __exp.__flags_ = __flags_; |
| 4363 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4364 | unsigned __mexp = __exp.__marked_count_; |
| 4365 | __push_lookahead(_VSTD::move(__exp), true, __marked_count_); |
| 4366 | __marked_count_ += __mexp; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4367 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4368 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4369 | __first = ++__temp; |
| 4370 | } |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4371 | break; |
| 4372 | } |
| 4373 | } |
| 4374 | } |
| 4375 | } |
| 4376 | break; |
| 4377 | } |
| 4378 | } |
| 4379 | return __first; |
| 4380 | } |
| 4381 | |
| 4382 | template <class _CharT, class _Traits> |
| 4383 | template <class _ForwardIterator> |
| 4384 | _ForwardIterator |
| 4385 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4386 | _ForwardIterator __last) |
| 4387 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4388 | if (__first != __last) |
| 4389 | { |
| 4390 | switch (*__first) |
| 4391 | { |
| 4392 | case '.': |
| 4393 | __push_match_any_but_newline(); |
| 4394 | ++__first; |
| 4395 | break; |
| 4396 | case '\\': |
| 4397 | __first = __parse_atom_escape(__first, __last); |
| 4398 | break; |
| 4399 | case '[': |
| 4400 | __first = __parse_bracket_expression(__first, __last); |
| 4401 | break; |
| 4402 | case '(': |
| 4403 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4404 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4405 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4406 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4407 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4408 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4409 | { |
| 4410 | ++__open_count_; |
| 4411 | __first = __parse_ecma_exp(++__temp, __last); |
| 4412 | if (__first == __last || *__first != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4413 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4414 | --__open_count_; |
| 4415 | ++__first; |
| 4416 | } |
| 4417 | else |
| 4418 | { |
| 4419 | __push_begin_marked_subexpression(); |
| 4420 | unsigned __temp_count = __marked_count_; |
| 4421 | ++__open_count_; |
| 4422 | __first = __parse_ecma_exp(__first, __last); |
| 4423 | if (__first == __last || *__first != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4424 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4425 | __push_end_marked_subexpression(__temp_count); |
| 4426 | --__open_count_; |
| 4427 | ++__first; |
| 4428 | } |
| 4429 | } |
| 4430 | break; |
Marshall Clow | 8205821 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4431 | case '*': |
| 4432 | case '+': |
| 4433 | case '?': |
| 4434 | case '{': |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4435 | __throw_regex_error<regex_constants::error_badrepeat>(); |
Marshall Clow | 8205821 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4436 | break; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4437 | default: |
| 4438 | __first = __parse_pattern_character(__first, __last); |
| 4439 | break; |
| 4440 | } |
| 4441 | } |
| 4442 | return __first; |
| 4443 | } |
| 4444 | |
| 4445 | template <class _CharT, class _Traits> |
| 4446 | template <class _ForwardIterator> |
| 4447 | _ForwardIterator |
| 4448 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4449 | _ForwardIterator __last) |
| 4450 | { |
| 4451 | if (__first != __last && *__first == '\\') |
| 4452 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4453 | _ForwardIterator __t1 = _VSTD::next(__first); |
Marshall Clow | db9633c | 2016-01-19 00:50:37 +0000 | [diff] [blame] | 4454 | if (__t1 == __last) |
| 4455 | __throw_regex_error<regex_constants::error_escape>(); |
| 4456 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4457 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4458 | if (__t2 != __t1) |
| 4459 | __first = __t2; |
| 4460 | else |
| 4461 | { |
| 4462 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4463 | if (__t2 != __t1) |
| 4464 | __first = __t2; |
| 4465 | else |
| 4466 | { |
| 4467 | __t2 = __parse_character_escape(__t1, __last); |
| 4468 | if (__t2 != __t1) |
| 4469 | __first = __t2; |
| 4470 | } |
| 4471 | } |
| 4472 | } |
| 4473 | return __first; |
| 4474 | } |
| 4475 | |
| 4476 | template <class _CharT, class _Traits> |
| 4477 | template <class _ForwardIterator> |
| 4478 | _ForwardIterator |
| 4479 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4480 | _ForwardIterator __last) |
| 4481 | { |
| 4482 | if (__first != __last) |
| 4483 | { |
| 4484 | if (*__first == '0') |
| 4485 | { |
| 4486 | __push_char(_CharT()); |
| 4487 | ++__first; |
| 4488 | } |
| 4489 | else if ('1' <= *__first && *__first <= '9') |
| 4490 | { |
| 4491 | unsigned __v = *__first - '0'; |
Marshall Clow | dc03ec7 | 2016-12-24 17:21:03 +0000 | [diff] [blame] | 4492 | for (++__first; |
| 4493 | __first != __last && '0' <= *__first && *__first <= '9'; ++__first) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4494 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4495 | if (__v >= numeric_limits<unsigned>::max() / 10) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4496 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4497 | __v = 10 * __v + *__first - '0'; |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4498 | } |
| 4499 | if (__v == 0 || __v > mark_count()) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4500 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4501 | __push_back_ref(__v); |
| 4502 | } |
| 4503 | } |
| 4504 | return __first; |
| 4505 | } |
| 4506 | |
| 4507 | template <class _CharT, class _Traits> |
| 4508 | template <class _ForwardIterator> |
| 4509 | _ForwardIterator |
| 4510 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4511 | _ForwardIterator __last) |
| 4512 | { |
| 4513 | if (__first != __last) |
| 4514 | { |
| 4515 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4516 | switch (*__first) |
| 4517 | { |
| 4518 | case 'd': |
| 4519 | __ml = __start_matching_list(false); |
| 4520 | __ml->__add_class(ctype_base::digit); |
| 4521 | ++__first; |
| 4522 | break; |
| 4523 | case 'D': |
| 4524 | __ml = __start_matching_list(true); |
| 4525 | __ml->__add_class(ctype_base::digit); |
| 4526 | ++__first; |
| 4527 | break; |
| 4528 | case 's': |
| 4529 | __ml = __start_matching_list(false); |
| 4530 | __ml->__add_class(ctype_base::space); |
| 4531 | ++__first; |
| 4532 | break; |
| 4533 | case 'S': |
| 4534 | __ml = __start_matching_list(true); |
| 4535 | __ml->__add_class(ctype_base::space); |
| 4536 | ++__first; |
| 4537 | break; |
| 4538 | case 'w': |
| 4539 | __ml = __start_matching_list(false); |
| 4540 | __ml->__add_class(ctype_base::alnum); |
| 4541 | __ml->__add_char('_'); |
| 4542 | ++__first; |
| 4543 | break; |
| 4544 | case 'W': |
| 4545 | __ml = __start_matching_list(true); |
| 4546 | __ml->__add_class(ctype_base::alnum); |
| 4547 | __ml->__add_char('_'); |
| 4548 | ++__first; |
| 4549 | break; |
| 4550 | } |
| 4551 | } |
| 4552 | return __first; |
| 4553 | } |
| 4554 | |
| 4555 | template <class _CharT, class _Traits> |
| 4556 | template <class _ForwardIterator> |
| 4557 | _ForwardIterator |
| 4558 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4559 | _ForwardIterator __last, |
| 4560 | basic_string<_CharT>* __str) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4561 | { |
| 4562 | if (__first != __last) |
| 4563 | { |
| 4564 | _ForwardIterator __t; |
| 4565 | unsigned __sum = 0; |
| 4566 | int __hd; |
| 4567 | switch (*__first) |
| 4568 | { |
| 4569 | case 'f': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4570 | if (__str) |
| 4571 | *__str = _CharT(0xC); |
| 4572 | else |
| 4573 | __push_char(_CharT(0xC)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4574 | ++__first; |
| 4575 | break; |
| 4576 | case 'n': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4577 | if (__str) |
| 4578 | *__str = _CharT(0xA); |
| 4579 | else |
| 4580 | __push_char(_CharT(0xA)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4581 | ++__first; |
| 4582 | break; |
| 4583 | case 'r': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4584 | if (__str) |
| 4585 | *__str = _CharT(0xD); |
| 4586 | else |
| 4587 | __push_char(_CharT(0xD)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4588 | ++__first; |
| 4589 | break; |
| 4590 | case 't': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4591 | if (__str) |
| 4592 | *__str = _CharT(0x9); |
| 4593 | else |
| 4594 | __push_char(_CharT(0x9)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4595 | ++__first; |
| 4596 | break; |
| 4597 | case 'v': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4598 | if (__str) |
| 4599 | *__str = _CharT(0xB); |
| 4600 | else |
| 4601 | __push_char(_CharT(0xB)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4602 | ++__first; |
| 4603 | break; |
| 4604 | case 'c': |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4605 | if ((__t = _VSTD::next(__first)) != __last) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4606 | { |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4607 | if (('A' <= *__t && *__t <= 'Z') || |
Howard Hinnant | d04741b | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4608 | ('a' <= *__t && *__t <= 'z')) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4609 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4610 | if (__str) |
| 4611 | *__str = _CharT(*__t % 32); |
| 4612 | else |
| 4613 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4614 | __first = ++__t; |
| 4615 | } |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4616 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4617 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4618 | } |
Howard Hinnant | d04741b | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4619 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4620 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4621 | break; |
| 4622 | case 'u': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4623 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4624 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4625 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4626 | __hd = __traits_.value(*__first, 16); |
| 4627 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4628 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4629 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4630 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4631 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4632 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4633 | __hd = __traits_.value(*__first, 16); |
| 4634 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4635 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4636 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 4637 | // fallthrough |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4638 | case 'x': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4639 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4640 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4641 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4642 | __hd = __traits_.value(*__first, 16); |
| 4643 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4644 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4645 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4646 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4647 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4648 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4649 | __hd = __traits_.value(*__first, 16); |
| 4650 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4651 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4652 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4653 | if (__str) |
| 4654 | *__str = _CharT(__sum); |
| 4655 | else |
| 4656 | __push_char(_CharT(__sum)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4657 | ++__first; |
| 4658 | break; |
Marshall Clow | f6cef0d | 2014-05-21 16:29:50 +0000 | [diff] [blame] | 4659 | case '0': |
| 4660 | if (__str) |
| 4661 | *__str = _CharT(0); |
| 4662 | else |
| 4663 | __push_char(_CharT(0)); |
| 4664 | ++__first; |
| 4665 | break; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4666 | default: |
| 4667 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4668 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4669 | if (__str) |
| 4670 | *__str = *__first; |
| 4671 | else |
| 4672 | __push_char(*__first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4673 | ++__first; |
| 4674 | } |
Howard Hinnant | 4f7a1f5 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 4675 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4676 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4677 | break; |
| 4678 | } |
| 4679 | } |
| 4680 | return __first; |
| 4681 | } |
| 4682 | |
| 4683 | template <class _CharT, class _Traits> |
| 4684 | template <class _ForwardIterator> |
| 4685 | _ForwardIterator |
| 4686 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4687 | _ForwardIterator __last) |
| 4688 | { |
| 4689 | if (__first != __last) |
| 4690 | { |
| 4691 | switch (*__first) |
| 4692 | { |
| 4693 | case '^': |
| 4694 | case '$': |
| 4695 | case '\\': |
| 4696 | case '.': |
| 4697 | case '*': |
| 4698 | case '+': |
| 4699 | case '?': |
| 4700 | case '(': |
| 4701 | case ')': |
| 4702 | case '[': |
| 4703 | case ']': |
| 4704 | case '{': |
| 4705 | case '}': |
| 4706 | case '|': |
| 4707 | break; |
| 4708 | default: |
| 4709 | __push_char(*__first); |
| 4710 | ++__first; |
| 4711 | break; |
| 4712 | } |
| 4713 | } |
| 4714 | return __first; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | template <class _CharT, class _Traits> |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4718 | template <class _ForwardIterator> |
| 4719 | _ForwardIterator |
| 4720 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4721 | _ForwardIterator __last) |
| 4722 | { |
| 4723 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4724 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4725 | if (__t1 != __first) |
| 4726 | __parse_basic_reg_exp(__first, __t1); |
| 4727 | else |
| 4728 | __push_empty(); |
| 4729 | __first = __t1; |
| 4730 | if (__first != __last) |
| 4731 | ++__first; |
| 4732 | while (__first != __last) |
| 4733 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4734 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4735 | __owns_one_state<_CharT>* __sb = __end_; |
| 4736 | if (__t1 != __first) |
| 4737 | __parse_basic_reg_exp(__first, __t1); |
| 4738 | else |
| 4739 | __push_empty(); |
| 4740 | __push_alternation(__sa, __sb); |
| 4741 | __first = __t1; |
| 4742 | if (__first != __last) |
| 4743 | ++__first; |
| 4744 | } |
| 4745 | return __first; |
| 4746 | } |
| 4747 | |
| 4748 | template <class _CharT, class _Traits> |
| 4749 | template <class _ForwardIterator> |
| 4750 | _ForwardIterator |
| 4751 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4752 | _ForwardIterator __last) |
| 4753 | { |
| 4754 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4755 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4756 | if (__t1 != __first) |
| 4757 | __parse_extended_reg_exp(__first, __t1); |
| 4758 | else |
| 4759 | __push_empty(); |
| 4760 | __first = __t1; |
| 4761 | if (__first != __last) |
| 4762 | ++__first; |
| 4763 | while (__first != __last) |
| 4764 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4765 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4766 | __owns_one_state<_CharT>* __sb = __end_; |
| 4767 | if (__t1 != __first) |
| 4768 | __parse_extended_reg_exp(__first, __t1); |
| 4769 | else |
| 4770 | __push_empty(); |
| 4771 | __push_alternation(__sa, __sb); |
| 4772 | __first = __t1; |
| 4773 | if (__first != __last) |
| 4774 | ++__first; |
| 4775 | } |
| 4776 | return __first; |
| 4777 | } |
| 4778 | |
| 4779 | template <class _CharT, class _Traits> |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4780 | bool |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 4781 | basic_regex<_CharT, _Traits>::__test_back_ref(_CharT __c) |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4782 | { |
Nikolas Klauser | 7b8c050 | 2022-07-08 18:17:26 +0200 | [diff] [blame] | 4783 | unsigned __val = __traits_.value(__c, 10); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4784 | if (__val >= 1 && __val <= 9) |
| 4785 | { |
Mark de Wever | d324e5f | 2020-02-20 18:13:38 -0500 | [diff] [blame] | 4786 | if (__val > mark_count()) |
| 4787 | __throw_regex_error<regex_constants::error_backref>(); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4788 | __push_back_ref(__val); |
| 4789 | return true; |
| 4790 | } |
| 4791 | |
| 4792 | return false; |
| 4793 | } |
| 4794 | |
| 4795 | template <class _CharT, class _Traits> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4796 | void |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4797 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4798 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4799 | bool __greedy) |
| 4800 | { |
| 4801 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4802 | __end_->first() = nullptr; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4803 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4804 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4805 | __min, __max)); |
| 4806 | __s->first() = nullptr; |
| 4807 | __e1.release(); |
| 4808 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4809 | __end_ = __e2->second(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4810 | __s->first() = __e2.release(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4811 | ++__loop_count_; |
| 4812 | } |
| 4813 | |
| 4814 | template <class _CharT, class _Traits> |
| 4815 | void |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4816 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4817 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4818 | if (flags() & icase) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4819 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4820 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4821 | else if (flags() & collate) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4822 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4823 | (__traits_, __c, __end_->first()); |
| 4824 | else |
| 4825 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4826 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4827 | } |
| 4828 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4829 | template <class _CharT, class _Traits> |
| 4830 | void |
| 4831 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4832 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4833 | if (!(__flags_ & nosubs)) |
| 4834 | { |
| 4835 | __end_->first() = |
| 4836 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4837 | __end_->first()); |
| 4838 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4839 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4840 | } |
| 4841 | |
| 4842 | template <class _CharT, class _Traits> |
| 4843 | void |
| 4844 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4845 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4846 | if (!(__flags_ & nosubs)) |
| 4847 | { |
| 4848 | __end_->first() = |
| 4849 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4850 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4851 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4852 | } |
| 4853 | |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4854 | template <class _CharT, class _Traits> |
| 4855 | void |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4856 | basic_regex<_CharT, _Traits>::__push_l_anchor() |
| 4857 | { |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 4858 | __end_->first() = new __l_anchor_multiline<_CharT>(__use_multiline(), __end_->first()); |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4859 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4860 | } |
| 4861 | |
| 4862 | template <class _CharT, class _Traits> |
| 4863 | void |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4864 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4865 | { |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 4866 | __end_->first() = new __r_anchor_multiline<_CharT>(__use_multiline(), __end_->first()); |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4867 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4868 | } |
| 4869 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4870 | template <class _CharT, class _Traits> |
| 4871 | void |
| 4872 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4873 | { |
| 4874 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4875 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4876 | } |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4877 | |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4878 | template <class _CharT, class _Traits> |
| 4879 | void |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4880 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4881 | { |
| 4882 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4883 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4884 | } |
| 4885 | |
| 4886 | template <class _CharT, class _Traits> |
| 4887 | void |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4888 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4889 | { |
| 4890 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4891 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4892 | } |
| 4893 | |
| 4894 | template <class _CharT, class _Traits> |
| 4895 | void |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4896 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4897 | { |
| 4898 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4899 | __end_->first()); |
| 4900 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4901 | } |
| 4902 | |
| 4903 | template <class _CharT, class _Traits> |
| 4904 | void |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4905 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4906 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4907 | if (flags() & icase) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4908 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4909 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4910 | else if (flags() & collate) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4911 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4912 | (__traits_, __i, __end_->first()); |
| 4913 | else |
| 4914 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4915 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4916 | } |
| 4917 | |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4918 | template <class _CharT, class _Traits> |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4919 | void |
| 4920 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4921 | __owns_one_state<_CharT>* __ea) |
| 4922 | { |
| 4923 | __sa->first() = new __alternate<_CharT>( |
| 4924 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4925 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4926 | __ea->first() = nullptr; |
| 4927 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4928 | __end_->first() = nullptr; |
| 4929 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4930 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4931 | } |
| 4932 | |
| 4933 | template <class _CharT, class _Traits> |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4934 | __bracket_expression<_CharT, _Traits>* |
| 4935 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4936 | { |
| 4937 | __bracket_expression<_CharT, _Traits>* __r = |
| 4938 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4939 | __negate, __flags_ & icase, |
| 4940 | __flags_ & collate); |
| 4941 | __end_->first() = __r; |
| 4942 | __end_ = __r; |
| 4943 | return __r; |
| 4944 | } |
| 4945 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4946 | template <class _CharT, class _Traits> |
| 4947 | void |
| 4948 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4949 | bool __invert, |
| 4950 | unsigned __mexp) |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4951 | { |
| 4952 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4953 | __end_->first(), __mexp); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4954 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4955 | } |
| 4956 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4957 | // sub_match |
| 4958 | |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4959 | typedef sub_match<const char*> csub_match; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4960 | typedef sub_match<string::const_iterator> ssub_match; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4961 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4962 | typedef sub_match<const wchar_t*> wcsub_match; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4963 | typedef sub_match<wstring::const_iterator> wssub_match; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4964 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4965 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4966 | template <class _BidirectionalIterator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4967 | class |
| 4968 | _LIBCPP_TEMPLATE_VIS |
| 4969 | _LIBCPP_PREFERRED_NAME(csub_match) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4970 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4971 | _LIBCPP_PREFERRED_NAME(ssub_match) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4972 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4973 | sub_match |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4974 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4975 | { |
| 4976 | public: |
| 4977 | typedef _BidirectionalIterator iterator; |
| 4978 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4979 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4980 | typedef basic_string<value_type> string_type; |
| 4981 | |
| 4982 | bool matched; |
| 4983 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4984 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 4985 | _LIBCPP_CONSTEXPR sub_match() : matched() {} |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 4986 | |
| 4987 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4988 | difference_type length() const |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4989 | {return matched ? _VSTD::distance(this->first, this->second) : 0;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4990 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4991 | string_type str() const |
| 4992 | {return matched ? string_type(this->first, this->second) : string_type();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4993 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4994 | operator string_type() const |
| 4995 | {return str();} |
| 4996 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4997 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4998 | int compare(const sub_match& __s) const |
| 4999 | {return str().compare(__s.str());} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5000 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5001 | int compare(const string_type& __s) const |
| 5002 | {return str().compare(__s);} |
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 value_type* __s) const |
| 5005 | {return str().compare(__s);} |
| 5006 | }; |
| 5007 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5008 | template <class _BiIter> |
| 5009 | inline _LIBCPP_INLINE_VISIBILITY |
| 5010 | bool |
| 5011 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5012 | { |
| 5013 | return __x.compare(__y) == 0; |
| 5014 | } |
| 5015 | |
| 5016 | template <class _BiIter> |
| 5017 | inline _LIBCPP_INLINE_VISIBILITY |
| 5018 | bool |
| 5019 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5020 | { |
| 5021 | return !(__x == __y); |
| 5022 | } |
| 5023 | |
| 5024 | template <class _BiIter> |
| 5025 | inline _LIBCPP_INLINE_VISIBILITY |
| 5026 | bool |
| 5027 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5028 | { |
| 5029 | return __x.compare(__y) < 0; |
| 5030 | } |
| 5031 | |
| 5032 | template <class _BiIter> |
| 5033 | inline _LIBCPP_INLINE_VISIBILITY |
| 5034 | bool |
| 5035 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5036 | { |
| 5037 | return !(__y < __x); |
| 5038 | } |
| 5039 | |
| 5040 | template <class _BiIter> |
| 5041 | inline _LIBCPP_INLINE_VISIBILITY |
| 5042 | bool |
| 5043 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5044 | { |
| 5045 | return !(__x < __y); |
| 5046 | } |
| 5047 | |
| 5048 | template <class _BiIter> |
| 5049 | inline _LIBCPP_INLINE_VISIBILITY |
| 5050 | bool |
| 5051 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5052 | { |
| 5053 | return __y < __x; |
| 5054 | } |
| 5055 | |
| 5056 | template <class _BiIter, class _ST, class _SA> |
| 5057 | inline _LIBCPP_INLINE_VISIBILITY |
| 5058 | bool |
| 5059 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5060 | const sub_match<_BiIter>& __y) |
| 5061 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5062 | 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] | 5063 | } |
| 5064 | |
| 5065 | template <class _BiIter, class _ST, class _SA> |
| 5066 | inline _LIBCPP_INLINE_VISIBILITY |
| 5067 | bool |
| 5068 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5069 | const sub_match<_BiIter>& __y) |
| 5070 | { |
| 5071 | return !(__x == __y); |
| 5072 | } |
| 5073 | |
| 5074 | template <class _BiIter, class _ST, class _SA> |
| 5075 | inline _LIBCPP_INLINE_VISIBILITY |
| 5076 | bool |
| 5077 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5078 | const sub_match<_BiIter>& __y) |
| 5079 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5080 | 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] | 5081 | } |
| 5082 | |
| 5083 | template <class _BiIter, class _ST, class _SA> |
| 5084 | inline _LIBCPP_INLINE_VISIBILITY |
| 5085 | bool |
| 5086 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5087 | const sub_match<_BiIter>& __y) |
| 5088 | { |
| 5089 | return __y < __x; |
| 5090 | } |
| 5091 | |
| 5092 | template <class _BiIter, class _ST, class _SA> |
| 5093 | inline _LIBCPP_INLINE_VISIBILITY |
| 5094 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5095 | const sub_match<_BiIter>& __y) |
| 5096 | { |
| 5097 | return !(__x < __y); |
| 5098 | } |
| 5099 | |
| 5100 | template <class _BiIter, class _ST, class _SA> |
| 5101 | inline _LIBCPP_INLINE_VISIBILITY |
| 5102 | bool |
| 5103 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5104 | const sub_match<_BiIter>& __y) |
| 5105 | { |
| 5106 | return !(__y < __x); |
| 5107 | } |
| 5108 | |
| 5109 | template <class _BiIter, class _ST, class _SA> |
| 5110 | inline _LIBCPP_INLINE_VISIBILITY |
| 5111 | bool |
| 5112 | operator==(const sub_match<_BiIter>& __x, |
| 5113 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5114 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5115 | 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] | 5116 | } |
| 5117 | |
| 5118 | template <class _BiIter, class _ST, class _SA> |
| 5119 | inline _LIBCPP_INLINE_VISIBILITY |
| 5120 | bool |
| 5121 | operator!=(const sub_match<_BiIter>& __x, |
| 5122 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5123 | { |
| 5124 | return !(__x == __y); |
| 5125 | } |
| 5126 | |
| 5127 | template <class _BiIter, class _ST, class _SA> |
| 5128 | inline _LIBCPP_INLINE_VISIBILITY |
| 5129 | bool |
| 5130 | operator<(const sub_match<_BiIter>& __x, |
| 5131 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5132 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5133 | 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] | 5134 | } |
| 5135 | |
| 5136 | template <class _BiIter, class _ST, class _SA> |
| 5137 | inline _LIBCPP_INLINE_VISIBILITY |
| 5138 | bool operator>(const sub_match<_BiIter>& __x, |
| 5139 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5140 | { |
| 5141 | return __y < __x; |
| 5142 | } |
| 5143 | |
| 5144 | template <class _BiIter, class _ST, class _SA> |
| 5145 | inline _LIBCPP_INLINE_VISIBILITY |
| 5146 | bool |
| 5147 | operator>=(const sub_match<_BiIter>& __x, |
| 5148 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5149 | { |
| 5150 | return !(__x < __y); |
| 5151 | } |
| 5152 | |
| 5153 | template <class _BiIter, class _ST, class _SA> |
| 5154 | inline _LIBCPP_INLINE_VISIBILITY |
| 5155 | bool |
| 5156 | operator<=(const sub_match<_BiIter>& __x, |
| 5157 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5158 | { |
| 5159 | return !(__y < __x); |
| 5160 | } |
| 5161 | |
| 5162 | template <class _BiIter> |
| 5163 | inline _LIBCPP_INLINE_VISIBILITY |
| 5164 | bool |
| 5165 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5166 | const sub_match<_BiIter>& __y) |
| 5167 | { |
| 5168 | return __y.compare(__x) == 0; |
| 5169 | } |
| 5170 | |
| 5171 | template <class _BiIter> |
| 5172 | inline _LIBCPP_INLINE_VISIBILITY |
| 5173 | bool |
| 5174 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5175 | const sub_match<_BiIter>& __y) |
| 5176 | { |
| 5177 | return !(__x == __y); |
| 5178 | } |
| 5179 | |
| 5180 | template <class _BiIter> |
| 5181 | inline _LIBCPP_INLINE_VISIBILITY |
| 5182 | bool |
| 5183 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5184 | const sub_match<_BiIter>& __y) |
| 5185 | { |
| 5186 | return __y.compare(__x) > 0; |
| 5187 | } |
| 5188 | |
| 5189 | template <class _BiIter> |
| 5190 | inline _LIBCPP_INLINE_VISIBILITY |
| 5191 | bool |
| 5192 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5193 | const sub_match<_BiIter>& __y) |
| 5194 | { |
| 5195 | return __y < __x; |
| 5196 | } |
| 5197 | |
| 5198 | template <class _BiIter> |
| 5199 | inline _LIBCPP_INLINE_VISIBILITY |
| 5200 | bool |
| 5201 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5202 | const sub_match<_BiIter>& __y) |
| 5203 | { |
| 5204 | return !(__x < __y); |
| 5205 | } |
| 5206 | |
| 5207 | template <class _BiIter> |
| 5208 | inline _LIBCPP_INLINE_VISIBILITY |
| 5209 | bool |
| 5210 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5211 | const sub_match<_BiIter>& __y) |
| 5212 | { |
| 5213 | return !(__y < __x); |
| 5214 | } |
| 5215 | |
| 5216 | template <class _BiIter> |
| 5217 | inline _LIBCPP_INLINE_VISIBILITY |
| 5218 | bool |
| 5219 | operator==(const sub_match<_BiIter>& __x, |
| 5220 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5221 | { |
| 5222 | return __x.compare(__y) == 0; |
| 5223 | } |
| 5224 | |
| 5225 | template <class _BiIter> |
| 5226 | inline _LIBCPP_INLINE_VISIBILITY |
| 5227 | bool |
| 5228 | operator!=(const sub_match<_BiIter>& __x, |
| 5229 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5230 | { |
| 5231 | return !(__x == __y); |
| 5232 | } |
| 5233 | |
| 5234 | template <class _BiIter> |
| 5235 | inline _LIBCPP_INLINE_VISIBILITY |
| 5236 | bool |
| 5237 | operator<(const sub_match<_BiIter>& __x, |
| 5238 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5239 | { |
| 5240 | return __x.compare(__y) < 0; |
| 5241 | } |
| 5242 | |
| 5243 | template <class _BiIter> |
| 5244 | inline _LIBCPP_INLINE_VISIBILITY |
| 5245 | bool |
| 5246 | operator>(const sub_match<_BiIter>& __x, |
| 5247 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5248 | { |
| 5249 | return __y < __x; |
| 5250 | } |
| 5251 | |
| 5252 | template <class _BiIter> |
| 5253 | inline _LIBCPP_INLINE_VISIBILITY |
| 5254 | bool |
| 5255 | operator>=(const sub_match<_BiIter>& __x, |
| 5256 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5257 | { |
| 5258 | return !(__x < __y); |
| 5259 | } |
| 5260 | |
| 5261 | template <class _BiIter> |
| 5262 | inline _LIBCPP_INLINE_VISIBILITY |
| 5263 | bool |
| 5264 | operator<=(const sub_match<_BiIter>& __x, |
| 5265 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5266 | { |
| 5267 | return !(__y < __x); |
| 5268 | } |
| 5269 | |
| 5270 | template <class _BiIter> |
| 5271 | inline _LIBCPP_INLINE_VISIBILITY |
| 5272 | bool |
| 5273 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5274 | const sub_match<_BiIter>& __y) |
| 5275 | { |
| 5276 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5277 | return __y.compare(string_type(1, __x)) == 0; |
| 5278 | } |
| 5279 | |
| 5280 | template <class _BiIter> |
| 5281 | inline _LIBCPP_INLINE_VISIBILITY |
| 5282 | bool |
| 5283 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5284 | const sub_match<_BiIter>& __y) |
| 5285 | { |
| 5286 | return !(__x == __y); |
| 5287 | } |
| 5288 | |
| 5289 | template <class _BiIter> |
| 5290 | inline _LIBCPP_INLINE_VISIBILITY |
| 5291 | bool |
| 5292 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5293 | const sub_match<_BiIter>& __y) |
| 5294 | { |
| 5295 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5296 | return __y.compare(string_type(1, __x)) > 0; |
| 5297 | } |
| 5298 | |
| 5299 | template <class _BiIter> |
| 5300 | inline _LIBCPP_INLINE_VISIBILITY |
| 5301 | bool |
| 5302 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5303 | const sub_match<_BiIter>& __y) |
| 5304 | { |
| 5305 | return __y < __x; |
| 5306 | } |
| 5307 | |
| 5308 | template <class _BiIter> |
| 5309 | inline _LIBCPP_INLINE_VISIBILITY |
| 5310 | bool |
| 5311 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5312 | const sub_match<_BiIter>& __y) |
| 5313 | { |
| 5314 | return !(__x < __y); |
| 5315 | } |
| 5316 | |
| 5317 | template <class _BiIter> |
| 5318 | inline _LIBCPP_INLINE_VISIBILITY |
| 5319 | bool |
| 5320 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5321 | const sub_match<_BiIter>& __y) |
| 5322 | { |
| 5323 | return !(__y < __x); |
| 5324 | } |
| 5325 | |
| 5326 | template <class _BiIter> |
| 5327 | inline _LIBCPP_INLINE_VISIBILITY |
| 5328 | bool |
| 5329 | operator==(const sub_match<_BiIter>& __x, |
| 5330 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5331 | { |
| 5332 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5333 | return __x.compare(string_type(1, __y)) == 0; |
| 5334 | } |
| 5335 | |
| 5336 | template <class _BiIter> |
| 5337 | inline _LIBCPP_INLINE_VISIBILITY |
| 5338 | bool |
| 5339 | operator!=(const sub_match<_BiIter>& __x, |
| 5340 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5341 | { |
| 5342 | return !(__x == __y); |
| 5343 | } |
| 5344 | |
| 5345 | template <class _BiIter> |
| 5346 | inline _LIBCPP_INLINE_VISIBILITY |
| 5347 | bool |
| 5348 | operator<(const sub_match<_BiIter>& __x, |
| 5349 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5350 | { |
| 5351 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5352 | return __x.compare(string_type(1, __y)) < 0; |
| 5353 | } |
| 5354 | |
| 5355 | template <class _BiIter> |
| 5356 | inline _LIBCPP_INLINE_VISIBILITY |
| 5357 | bool |
| 5358 | operator>(const sub_match<_BiIter>& __x, |
| 5359 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5360 | { |
| 5361 | return __y < __x; |
| 5362 | } |
| 5363 | |
| 5364 | template <class _BiIter> |
| 5365 | inline _LIBCPP_INLINE_VISIBILITY |
| 5366 | bool |
| 5367 | operator>=(const sub_match<_BiIter>& __x, |
| 5368 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5369 | { |
| 5370 | return !(__x < __y); |
| 5371 | } |
| 5372 | |
| 5373 | template <class _BiIter> |
| 5374 | inline _LIBCPP_INLINE_VISIBILITY |
| 5375 | bool |
| 5376 | operator<=(const sub_match<_BiIter>& __x, |
| 5377 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5378 | { |
| 5379 | return !(__y < __x); |
| 5380 | } |
| 5381 | |
| 5382 | template <class _CharT, class _ST, class _BiIter> |
| 5383 | inline _LIBCPP_INLINE_VISIBILITY |
| 5384 | basic_ostream<_CharT, _ST>& |
| 5385 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 5386 | { |
| 5387 | return __os << __m.str(); |
| 5388 | } |
| 5389 | |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5390 | typedef match_results<const char*> cmatch; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5391 | typedef match_results<string::const_iterator> smatch; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5392 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 5393 | typedef match_results<const wchar_t*> wcmatch; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5394 | typedef match_results<wstring::const_iterator> wsmatch; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5395 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5396 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5397 | template <class _BidirectionalIterator, class _Allocator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5398 | class |
| 5399 | _LIBCPP_TEMPLATE_VIS |
| 5400 | _LIBCPP_PREFERRED_NAME(cmatch) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5401 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5402 | _LIBCPP_PREFERRED_NAME(smatch) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5403 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5404 | match_results |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5405 | { |
| 5406 | public: |
| 5407 | typedef _Allocator allocator_type; |
| 5408 | typedef sub_match<_BidirectionalIterator> value_type; |
| 5409 | private: |
| 5410 | typedef vector<value_type, allocator_type> __container_type; |
| 5411 | |
| 5412 | __container_type __matches_; |
| 5413 | value_type __unmatched_; |
| 5414 | value_type __prefix_; |
| 5415 | value_type __suffix_; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5416 | bool __ready_; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5417 | public: |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5418 | _BidirectionalIterator __position_start_; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5419 | typedef const value_type& const_reference; |
Marshall Clow | 96e0614 | 2014-02-26 01:56:31 +0000 | [diff] [blame] | 5420 | typedef value_type& reference; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5421 | typedef typename __container_type::const_iterator const_iterator; |
| 5422 | typedef const_iterator iterator; |
| 5423 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5424 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5425 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5426 | typedef basic_string<char_type> string_type; |
| 5427 | |
| 5428 | // construct/copy/destroy: |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5429 | #ifndef _LIBCPP_CXX03_LANG |
| 5430 | match_results() : match_results(allocator_type()) {} |
| 5431 | explicit match_results(const allocator_type& __a); |
| 5432 | #else |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5433 | explicit match_results(const allocator_type& __a = allocator_type()); |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5434 | #endif |
| 5435 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5436 | // match_results(const match_results&) = default; |
| 5437 | // match_results& operator=(const match_results&) = default; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5438 | // match_results(match_results&& __m) = default; |
| 5439 | // match_results& operator=(match_results&& __m) = default; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5440 | // ~match_results() = default; |
| 5441 | |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5442 | _LIBCPP_INLINE_VISIBILITY |
| 5443 | bool ready() const {return __ready_;} |
| 5444 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5445 | // size: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5446 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 081bcd2 | 2017-11-16 04:48:34 +0000 | [diff] [blame] | 5447 | size_type size() const _NOEXCEPT {return __matches_.size();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5448 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 081bcd2 | 2017-11-16 04:48:34 +0000 | [diff] [blame] | 5449 | size_type max_size() const _NOEXCEPT {return __matches_.max_size();} |
| 5450 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 5451 | bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5452 | |
| 5453 | // element access: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5454 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5455 | difference_type length(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5456 | { |
| 5457 | _LIBCPP_ASSERT(ready(), "match_results::length() called when not ready"); |
| 5458 | return (*this)[__sub].length(); |
| 5459 | } |
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 position(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5462 | { |
| 5463 | _LIBCPP_ASSERT(ready(), "match_results::position() called when not ready"); |
| 5464 | return _VSTD::distance(__position_start_, (*this)[__sub].first); |
| 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 | string_type str(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5468 | { |
| 5469 | _LIBCPP_ASSERT(ready(), "match_results::str() called when not ready"); |
| 5470 | return (*this)[__sub].str(); |
| 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 | const_reference operator[](size_type __n) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5474 | { |
| 5475 | _LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready"); |
| 5476 | return __n < __matches_.size() ? __matches_[__n] : __unmatched_; |
| 5477 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5478 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5479 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5480 | const_reference prefix() const |
| 5481 | { |
| 5482 | _LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready"); |
| 5483 | return __prefix_; |
| 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 suffix() const |
| 5487 | { |
| 5488 | _LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready"); |
| 5489 | return __suffix_; |
| 5490 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5491 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5492 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f4191f | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5493 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5494 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5495 | const_iterator end() const {return __matches_.end();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5496 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f4191f | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5497 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5498 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5499 | const_iterator cend() const {return __matches_.end();} |
| 5500 | |
| 5501 | // format: |
| 5502 | template <class _OutputIter> |
| 5503 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5504 | format(_OutputIter __output_iter, const char_type* __fmt_first, |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5505 | const char_type* __fmt_last, |
| 5506 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5507 | template <class _OutputIter, class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5508 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5509 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5510 | format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5511 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5512 | {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5513 | template <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 | basic_string<char_type, _ST, _SA> |
| 5516 | format(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 |
| 5518 | { |
| 5519 | basic_string<char_type, _ST, _SA> __r; |
| 5520 | format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), |
| 5521 | __flags); |
| 5522 | return __r; |
| 5523 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5524 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5525 | string_type |
| 5526 | format(const char_type* __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5527 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5528 | { |
| 5529 | string_type __r; |
| 5530 | format(back_inserter(__r), __fmt, |
| 5531 | __fmt + char_traits<char_type>::length(__fmt), __flags); |
| 5532 | return __r; |
| 5533 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5534 | |
| 5535 | // allocator: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5536 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5537 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5538 | |
| 5539 | // swap: |
| 5540 | void swap(match_results& __m); |
| 5541 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5542 | template <class _Bp, class _Ap> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5543 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5544 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5545 | const match_results<_Bp, _Ap>& __m, bool __no_update_pos) |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5546 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5547 | _Bp __mf = __m.prefix().first; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5548 | __matches_.resize(__m.size()); |
| 5549 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5550 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5551 | __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); |
| 5552 | __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5553 | __matches_[__i].matched = __m[__i].matched; |
| 5554 | } |
| 5555 | __unmatched_.first = __l; |
| 5556 | __unmatched_.second = __l; |
| 5557 | __unmatched_.matched = false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5558 | __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); |
| 5559 | __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5560 | __prefix_.matched = __m.prefix().matched; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5561 | __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); |
| 5562 | __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5563 | __suffix_.matched = __m.suffix().matched; |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5564 | if (!__no_update_pos) |
| 5565 | __position_start_ = __prefix_.first; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5566 | __ready_ = __m.ready(); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5567 | } |
| 5568 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5569 | private: |
| 5570 | void __init(unsigned __s, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5571 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5572 | bool __no_update_pos = false); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5573 | |
| 5574 | template <class, class> friend class basic_regex; |
| 5575 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5576 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5577 | friend |
| 5578 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5579 | 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] | 5580 | regex_constants::match_flag_type); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5581 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5582 | template <class _Bp, class _Ap> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5583 | friend |
| 5584 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5585 | operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5586 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5587 | template <class, class> friend class __lookahead; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5588 | }; |
| 5589 | |
| 5590 | template <class _BidirectionalIterator, class _Allocator> |
| 5591 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5592 | const allocator_type& __a) |
| 5593 | : __matches_(__a), |
| 5594 | __unmatched_(), |
| 5595 | __prefix_(), |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5596 | __suffix_(), |
Eric Fiselier | a75ee26 | 2015-07-22 01:29:41 +0000 | [diff] [blame] | 5597 | __ready_(false), |
| 5598 | __position_start_() |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5599 | { |
| 5600 | } |
| 5601 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5602 | template <class _BidirectionalIterator, class _Allocator> |
| 5603 | void |
| 5604 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5605 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5606 | bool __no_update_pos) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5607 | { |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5608 | __unmatched_.first = __l; |
| 5609 | __unmatched_.second = __l; |
| 5610 | __unmatched_.matched = false; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5611 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5612 | __prefix_.first = __f; |
| 5613 | __prefix_.second = __f; |
| 5614 | __prefix_.matched = false; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5615 | __suffix_ = __unmatched_; |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5616 | if (!__no_update_pos) |
| 5617 | __position_start_ = __prefix_.first; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5618 | __ready_ = true; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5619 | } |
| 5620 | |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5621 | template <class _BidirectionalIterator, class _Allocator> |
| 5622 | template <class _OutputIter> |
| 5623 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5624 | match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5625 | const char_type* __fmt_first, const char_type* __fmt_last, |
| 5626 | regex_constants::match_flag_type __flags) const |
| 5627 | { |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5628 | _LIBCPP_ASSERT(ready(), "match_results::format() called when not ready"); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5629 | if (__flags & regex_constants::format_sed) |
| 5630 | { |
| 5631 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5632 | { |
| 5633 | if (*__fmt_first == '&') |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5634 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 5635 | __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5636 | else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) |
| 5637 | { |
| 5638 | ++__fmt_first; |
| 5639 | if ('0' <= *__fmt_first && *__fmt_first <= '9') |
| 5640 | { |
| 5641 | size_t __i = *__fmt_first - '0'; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5642 | __output_iter = _VSTD::copy((*this)[__i].first, |
| 5643 | (*this)[__i].second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5644 | } |
| 5645 | else |
| 5646 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5647 | *__output_iter = *__fmt_first; |
| 5648 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5649 | } |
| 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 | } |
| 5658 | else |
| 5659 | { |
| 5660 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5661 | { |
| 5662 | if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) |
| 5663 | { |
| 5664 | switch (__fmt_first[1]) |
| 5665 | { |
| 5666 | case '$': |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5667 | *__output_iter = *++__fmt_first; |
| 5668 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5669 | break; |
| 5670 | case '&': |
| 5671 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5672 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 5673 | __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5674 | break; |
| 5675 | case '`': |
| 5676 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5677 | __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5678 | break; |
| 5679 | case '\'': |
| 5680 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5681 | __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5682 | break; |
| 5683 | default: |
| 5684 | if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5685 | { |
| 5686 | ++__fmt_first; |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 5687 | size_t __idx = *__fmt_first - '0'; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5688 | if (__fmt_first + 1 != __fmt_last && |
| 5689 | '0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5690 | { |
| 5691 | ++__fmt_first; |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 5692 | if (__idx >= numeric_limits<size_t>::max() / 10) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 5693 | __throw_regex_error<regex_constants::error_escape>(); |
| 5694 | __idx = 10 * __idx + *__fmt_first - '0'; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5695 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5696 | __output_iter = _VSTD::copy((*this)[__idx].first, |
| 5697 | (*this)[__idx].second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5698 | } |
| 5699 | else |
| 5700 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5701 | *__output_iter = *__fmt_first; |
| 5702 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5703 | } |
| 5704 | break; |
| 5705 | } |
| 5706 | } |
| 5707 | else |
| 5708 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5709 | *__output_iter = *__fmt_first; |
| 5710 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5711 | } |
| 5712 | } |
| 5713 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5714 | return __output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | template <class _BidirectionalIterator, class _Allocator> |
| 5718 | void |
| 5719 | match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) |
| 5720 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5721 | using _VSTD::swap; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5722 | swap(__matches_, __m.__matches_); |
| 5723 | swap(__unmatched_, __m.__unmatched_); |
| 5724 | swap(__prefix_, __m.__prefix_); |
| 5725 | swap(__suffix_, __m.__suffix_); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5726 | swap(__position_start_, __m.__position_start_); |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5727 | swap(__ready_, __m.__ready_); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5730 | template <class _BidirectionalIterator, class _Allocator> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 5731 | _LIBCPP_HIDE_FROM_ABI bool |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5732 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5733 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5734 | { |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5735 | if (__x.__ready_ != __y.__ready_) |
| 5736 | return false; |
| 5737 | if (!__x.__ready_) |
| 5738 | return true; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5739 | return __x.__matches_ == __y.__matches_ && |
| 5740 | __x.__prefix_ == __y.__prefix_ && |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5741 | __x.__suffix_ == __y.__suffix_; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5742 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5743 | |
| 5744 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5745 | inline _LIBCPP_INLINE_VISIBILITY |
| 5746 | bool |
| 5747 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5748 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5749 | { |
| 5750 | return !(__x == __y); |
| 5751 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5752 | |
| 5753 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5754 | inline _LIBCPP_INLINE_VISIBILITY |
| 5755 | void |
| 5756 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5757 | match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5758 | { |
| 5759 | __x.swap(__y); |
| 5760 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5761 | |
| 5762 | // regex_search |
| 5763 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5764 | template <class _CharT, class _Traits> |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5765 | template <class _Allocator> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5766 | bool |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5767 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5768 | const _CharT* __first, const _CharT* __last, |
| 5769 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5770 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5771 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5772 | vector<__state> __states; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5773 | __node* __st = __start_.get(); |
| 5774 | if (__st) |
| 5775 | { |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5776 | sub_match<const _CharT*> __unmatched; |
| 5777 | __unmatched.first = __last; |
| 5778 | __unmatched.second = __last; |
| 5779 | __unmatched.matched = false; |
| 5780 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5781 | __states.push_back(__state()); |
| 5782 | __states.back().__do_ = 0; |
| 5783 | __states.back().__first_ = __first; |
| 5784 | __states.back().__current_ = __first; |
| 5785 | __states.back().__last_ = __last; |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5786 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5787 | __states.back().__loop_data_.resize(__loop_count()); |
| 5788 | __states.back().__node_ = __st; |
| 5789 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5790 | __states.back().__at_first_ = __at_first; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5791 | int __counter = 0; |
| 5792 | int __length = __last - __first; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5793 | do |
| 5794 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5795 | ++__counter; |
| 5796 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5797 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5798 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5799 | __state& __s = __states.back(); |
| 5800 | if (__s.__node_) |
| 5801 | __s.__node_->__exec(__s); |
| 5802 | switch (__s.__do_) |
| 5803 | { |
| 5804 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5805 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5806 | __s.__current_ == __first) |
| 5807 | { |
| 5808 | __states.pop_back(); |
| 5809 | break; |
| 5810 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5811 | if ((__flags & regex_constants::__full_match) && |
| 5812 | __s.__current_ != __last) |
| 5813 | { |
| 5814 | __states.pop_back(); |
| 5815 | break; |
| 5816 | } |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5817 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5818 | __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5819 | __m.__matches_[0].matched = true; |
| 5820 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5821 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5822 | return true; |
| 5823 | case __state::__accept_and_consume: |
| 5824 | case __state::__repeat: |
| 5825 | case __state::__accept_but_not_consume: |
| 5826 | break; |
| 5827 | case __state::__split: |
| 5828 | { |
| 5829 | __state __snext = __s; |
| 5830 | __s.__node_->__exec_split(true, __s); |
| 5831 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5832 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5833 | } |
| 5834 | break; |
| 5835 | case __state::__reject: |
| 5836 | __states.pop_back(); |
| 5837 | break; |
| 5838 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5839 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5840 | break; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5841 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5842 | } |
| 5843 | } while (!__states.empty()); |
| 5844 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5845 | return false; |
| 5846 | } |
| 5847 | |
| 5848 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5849 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5850 | bool |
| 5851 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5852 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5853 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5854 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5855 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5856 | deque<__state> __states; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5857 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5858 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5859 | __node* __st = __start_.get(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5860 | if (__st) |
| 5861 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5862 | __states.push_back(__state()); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5863 | __states.back().__do_ = 0; |
| 5864 | __states.back().__first_ = __first; |
| 5865 | __states.back().__current_ = __first; |
| 5866 | __states.back().__last_ = __last; |
| 5867 | __states.back().__loop_data_.resize(__loop_count()); |
| 5868 | __states.back().__node_ = __st; |
| 5869 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5870 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5871 | bool __matched = false; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5872 | int __counter = 0; |
| 5873 | int __length = __last - __first; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5874 | do |
| 5875 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5876 | ++__counter; |
| 5877 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5878 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5879 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5880 | __state& __s = __states.back(); |
| 5881 | if (__s.__node_) |
| 5882 | __s.__node_->__exec(__s); |
| 5883 | switch (__s.__do_) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5884 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5885 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5886 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5887 | __s.__current_ == __first) |
| 5888 | { |
| 5889 | __states.pop_back(); |
| 5890 | break; |
| 5891 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5892 | if ((__flags & regex_constants::__full_match) && |
| 5893 | __s.__current_ != __last) |
| 5894 | { |
| 5895 | __states.pop_back(); |
| 5896 | break; |
| 5897 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5898 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5899 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5900 | __matched = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5901 | if (__highest_j == _Np) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5902 | __states.clear(); |
| 5903 | else |
| 5904 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5905 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5906 | case __state::__consume_input: |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5907 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5908 | case __state::__accept_and_consume: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5909 | __states.push_front(_VSTD::move(__s)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 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::__repeat: |
| 5913 | case __state::__accept_but_not_consume: |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5914 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5915 | case __state::__split: |
| 5916 | { |
| 5917 | __state __snext = __s; |
| 5918 | __s.__node_->__exec_split(true, __s); |
| 5919 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5920 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5921 | } |
| 5922 | break; |
| 5923 | case __state::__reject: |
| 5924 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5925 | break; |
| 5926 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5927 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5928 | break; |
| 5929 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5930 | } while (!__states.empty()); |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5931 | if (__matched) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5932 | { |
| 5933 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5934 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5935 | __m.__matches_[0].matched = true; |
| 5936 | return true; |
| 5937 | } |
| 5938 | } |
| 5939 | return false; |
| 5940 | } |
| 5941 | |
| 5942 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5943 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5944 | bool |
| 5945 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5946 | const _CharT* __first, const _CharT* __last, |
| 5947 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5948 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5949 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5950 | vector<__state> __states; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5951 | __state __best_state; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5952 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5953 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5954 | __node* __st = __start_.get(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5955 | if (__st) |
| 5956 | { |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5957 | sub_match<const _CharT*> __unmatched; |
| 5958 | __unmatched.first = __last; |
| 5959 | __unmatched.second = __last; |
| 5960 | __unmatched.matched = false; |
| 5961 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5962 | __states.push_back(__state()); |
| 5963 | __states.back().__do_ = 0; |
| 5964 | __states.back().__first_ = __first; |
| 5965 | __states.back().__current_ = __first; |
| 5966 | __states.back().__last_ = __last; |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5967 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5968 | __states.back().__loop_data_.resize(__loop_count()); |
| 5969 | __states.back().__node_ = __st; |
| 5970 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5971 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5972 | bool __matched = false; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5973 | int __counter = 0; |
| 5974 | int __length = __last - __first; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5975 | do |
| 5976 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5977 | ++__counter; |
| 5978 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5979 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5980 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5981 | __state& __s = __states.back(); |
| 5982 | if (__s.__node_) |
| 5983 | __s.__node_->__exec(__s); |
| 5984 | switch (__s.__do_) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5985 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5986 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5987 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5988 | __s.__current_ == __first) |
| 5989 | { |
| 5990 | __states.pop_back(); |
| 5991 | break; |
| 5992 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5993 | if ((__flags & regex_constants::__full_match) && |
| 5994 | __s.__current_ != __last) |
| 5995 | { |
| 5996 | __states.pop_back(); |
| 5997 | break; |
| 5998 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5999 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6000 | { |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 6001 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6002 | __best_state = __s; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6003 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 6004 | __matched = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6005 | if (__highest_j == _Np) |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 6006 | __states.clear(); |
| 6007 | else |
| 6008 | __states.pop_back(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6009 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6010 | case __state::__accept_and_consume: |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6011 | case __state::__repeat: |
| 6012 | case __state::__accept_but_not_consume: |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6013 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6014 | case __state::__split: |
| 6015 | { |
| 6016 | __state __snext = __s; |
| 6017 | __s.__node_->__exec_split(true, __s); |
| 6018 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6019 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6020 | } |
| 6021 | break; |
| 6022 | case __state::__reject: |
| 6023 | __states.pop_back(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6024 | break; |
| 6025 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 6026 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6027 | break; |
| 6028 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6029 | } while (!__states.empty()); |
| 6030 | if (__matched) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6031 | { |
| 6032 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6033 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6034 | __m.__matches_[0].matched = true; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6035 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 6036 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6037 | return true; |
| 6038 | } |
| 6039 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6040 | return false; |
| 6041 | } |
| 6042 | |
| 6043 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6044 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6045 | bool |
| 6046 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6047 | const _CharT* __first, const _CharT* __last, |
| 6048 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6049 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6050 | { |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 6051 | if (__get_grammar(__flags_) == ECMAScript) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6052 | return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6053 | if (mark_count() == 0) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6054 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |
| 6055 | return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6056 | } |
| 6057 | |
| 6058 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6059 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6060 | bool |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6061 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6062 | const _CharT* __first, const _CharT* __last, |
| 6063 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6064 | regex_constants::match_flag_type __flags) const |
| 6065 | { |
Diogo Sampaio | 300ade7 | 2020-04-30 23:34:01 +0100 | [diff] [blame] | 6066 | if (__flags & regex_constants::match_prev_avail) |
| 6067 | __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow); |
| 6068 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6069 | __m.__init(1 + mark_count(), __first, __last, |
| 6070 | __flags & regex_constants::__no_update_pos); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6071 | if (__match_at_start(__first, __last, __m, __flags, |
Howard Hinnant | 38d14f7 | 2013-07-09 17:29:09 +0000 | [diff] [blame] | 6072 | !(__flags & regex_constants::__no_update_pos))) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6073 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6074 | __m.__prefix_.second = __m[0].first; |
| 6075 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 6076 | __m.__suffix_.first = __m[0].second; |
| 6077 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 6078 | return true; |
| 6079 | } |
Howard Hinnant | 22cf486 | 2010-07-29 01:15:27 +0000 | [diff] [blame] | 6080 | if (__first != __last && !(__flags & regex_constants::match_continuous)) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6081 | { |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 6082 | __flags |= regex_constants::match_prev_avail; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6083 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6084 | { |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 6085 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6086 | if (__match_at_start(__first, __last, __m, __flags, false)) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6087 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6088 | __m.__prefix_.second = __m[0].first; |
| 6089 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 6090 | __m.__suffix_.first = __m[0].second; |
| 6091 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 6092 | return true; |
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.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6095 | } |
| 6096 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6097 | __m.__matches_.clear(); |
| 6098 | return false; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6099 | } |
| 6100 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6101 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6102 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6103 | bool |
| 6104 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6105 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6106 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6107 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6108 | { |
Howard Hinnant | 1e5de64 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 6109 | int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0; |
| 6110 | basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6111 | match_results<const _CharT*> __mc; |
Howard Hinnant | 1e5de64 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 6112 | 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] | 6113 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6114 | return __r; |
| 6115 | } |
| 6116 | |
Howard Hinnant | 4018c48 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 6117 | template <class _Iter, class _Allocator, class _CharT, class _Traits> |
| 6118 | inline _LIBCPP_INLINE_VISIBILITY |
| 6119 | bool |
| 6120 | regex_search(__wrap_iter<_Iter> __first, |
| 6121 | __wrap_iter<_Iter> __last, |
| 6122 | match_results<__wrap_iter<_Iter>, _Allocator>& __m, |
| 6123 | const basic_regex<_CharT, _Traits>& __e, |
| 6124 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6125 | { |
| 6126 | match_results<const _CharT*> __mc; |
| 6127 | bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags); |
| 6128 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
| 6129 | return __r; |
| 6130 | } |
| 6131 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6132 | template <class _Allocator, class _CharT, class _Traits> |
| 6133 | inline _LIBCPP_INLINE_VISIBILITY |
| 6134 | bool |
| 6135 | regex_search(const _CharT* __first, const _CharT* __last, |
| 6136 | match_results<const _CharT*, _Allocator>& __m, |
| 6137 | const basic_regex<_CharT, _Traits>& __e, |
| 6138 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6139 | { |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6140 | return __e.__search(__first, __last, __m, __flags); |
| 6141 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6142 | |
| 6143 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6144 | inline _LIBCPP_INLINE_VISIBILITY |
| 6145 | bool |
| 6146 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6147 | const basic_regex<_CharT, _Traits>& __e, |
| 6148 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6149 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6150 | basic_string<_CharT> __s(__first, __last); |
| 6151 | match_results<const _CharT*> __mc; |
| 6152 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 6153 | } |
| 6154 | |
| 6155 | template <class _CharT, class _Traits> |
| 6156 | inline _LIBCPP_INLINE_VISIBILITY |
| 6157 | bool |
| 6158 | regex_search(const _CharT* __first, const _CharT* __last, |
| 6159 | const basic_regex<_CharT, _Traits>& __e, |
| 6160 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6161 | { |
| 6162 | match_results<const _CharT*> __mc; |
| 6163 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6164 | } |
| 6165 | |
| 6166 | template <class _CharT, class _Allocator, class _Traits> |
| 6167 | inline _LIBCPP_INLINE_VISIBILITY |
| 6168 | bool |
| 6169 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6170 | const basic_regex<_CharT, _Traits>& __e, |
| 6171 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6172 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6173 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6174 | } |
| 6175 | |
| 6176 | template <class _CharT, class _Traits> |
| 6177 | inline _LIBCPP_INLINE_VISIBILITY |
| 6178 | bool |
| 6179 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6180 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6181 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6182 | match_results<const _CharT*> __m; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6183 | return _VSTD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6184 | } |
| 6185 | |
| 6186 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6187 | inline _LIBCPP_INLINE_VISIBILITY |
| 6188 | bool |
| 6189 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6190 | const basic_regex<_CharT, _Traits>& __e, |
| 6191 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6192 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6193 | match_results<const _CharT*> __mc; |
| 6194 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6195 | } |
| 6196 | |
| 6197 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6198 | inline _LIBCPP_INLINE_VISIBILITY |
| 6199 | bool |
| 6200 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6201 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6202 | const basic_regex<_CharT, _Traits>& __e, |
| 6203 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6204 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6205 | match_results<const _CharT*> __mc; |
| 6206 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6207 | __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] | 6208 | return __r; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6209 | } |
| 6210 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6211 | #if _LIBCPP_STD_VER > 11 |
| 6212 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
| 6213 | bool |
| 6214 | regex_search(const basic_string<_Cp, _ST, _SA>&& __s, |
| 6215 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 6216 | const basic_regex<_Cp, _Tp>& __e, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6217 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6218 | #endif |
| 6219 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6220 | // regex_match |
| 6221 | |
| 6222 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 6223 | _LIBCPP_HIDE_FROM_ABI bool |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6224 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6225 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6226 | const basic_regex<_CharT, _Traits>& __e, |
| 6227 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6228 | { |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 6229 | bool __r = _VSTD::regex_search( |
| 6230 | __first, __last, __m, __e, |
| 6231 | __flags | regex_constants::match_continuous | |
| 6232 | regex_constants::__full_match); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6233 | if (__r) |
| 6234 | { |
| 6235 | __r = !__m.suffix().matched; |
| 6236 | if (!__r) |
| 6237 | __m.__matches_.clear(); |
| 6238 | } |
| 6239 | return __r; |
| 6240 | } |
| 6241 | |
| 6242 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6243 | inline _LIBCPP_INLINE_VISIBILITY |
| 6244 | bool |
| 6245 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6246 | const basic_regex<_CharT, _Traits>& __e, |
| 6247 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6248 | { |
| 6249 | match_results<_BidirectionalIterator> __m; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6250 | return _VSTD::regex_match(__first, __last, __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6251 | } |
| 6252 | |
| 6253 | template <class _CharT, class _Allocator, class _Traits> |
| 6254 | inline _LIBCPP_INLINE_VISIBILITY |
| 6255 | bool |
| 6256 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6257 | const basic_regex<_CharT, _Traits>& __e, |
| 6258 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6259 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6260 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6261 | } |
| 6262 | |
| 6263 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6264 | inline _LIBCPP_INLINE_VISIBILITY |
| 6265 | bool |
| 6266 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6267 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6268 | const basic_regex<_CharT, _Traits>& __e, |
| 6269 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6270 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6271 | return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6272 | } |
| 6273 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6274 | #if _LIBCPP_STD_VER > 11 |
| 6275 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6276 | inline _LIBCPP_INLINE_VISIBILITY |
| 6277 | bool |
| 6278 | regex_match(const basic_string<_CharT, _ST, _SA>&& __s, |
| 6279 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6280 | const basic_regex<_CharT, _Traits>& __e, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6281 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6282 | #endif |
| 6283 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6284 | template <class _CharT, class _Traits> |
| 6285 | inline _LIBCPP_INLINE_VISIBILITY |
| 6286 | bool |
| 6287 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6288 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6289 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6290 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6291 | } |
| 6292 | |
| 6293 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6294 | inline _LIBCPP_INLINE_VISIBILITY |
| 6295 | bool |
| 6296 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6297 | const basic_regex<_CharT, _Traits>& __e, |
| 6298 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6299 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6300 | return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6301 | } |
| 6302 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6303 | // regex_iterator |
| 6304 | |
| 6305 | template <class _BidirectionalIterator, |
| 6306 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6307 | class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6308 | class _LIBCPP_TEMPLATE_VIS regex_iterator; |
| 6309 | |
| 6310 | typedef regex_iterator<const char*> cregex_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6311 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6312 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6313 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6314 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6315 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6316 | |
| 6317 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6318 | class |
| 6319 | _LIBCPP_TEMPLATE_VIS |
| 6320 | _LIBCPP_PREFERRED_NAME(cregex_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6321 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6322 | _LIBCPP_PREFERRED_NAME(sregex_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6323 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6324 | regex_iterator |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6325 | { |
| 6326 | public: |
| 6327 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6328 | typedef match_results<_BidirectionalIterator> value_type; |
| 6329 | typedef ptrdiff_t difference_type; |
| 6330 | typedef const value_type* pointer; |
| 6331 | typedef const value_type& reference; |
| 6332 | typedef forward_iterator_tag iterator_category; |
| 6333 | |
| 6334 | private: |
| 6335 | _BidirectionalIterator __begin_; |
| 6336 | _BidirectionalIterator __end_; |
| 6337 | const regex_type* __pregex_; |
| 6338 | regex_constants::match_flag_type __flags_; |
| 6339 | value_type __match_; |
| 6340 | |
| 6341 | public: |
| 6342 | regex_iterator(); |
| 6343 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6344 | const regex_type& __re, |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6345 | regex_constants::match_flag_type __m |
| 6346 | = regex_constants::match_default); |
| 6347 | #if _LIBCPP_STD_VER > 11 |
| 6348 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6349 | const regex_type&& __re, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6350 | regex_constants::match_flag_type __m |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6351 | = regex_constants::match_default) = delete; |
| 6352 | #endif |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6353 | |
| 6354 | bool operator==(const regex_iterator& __x) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6355 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6356 | bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} |
| 6357 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6358 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6359 | reference operator*() const {return __match_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6360 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6361 | pointer operator->() const {return _VSTD::addressof(__match_);} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6362 | |
| 6363 | regex_iterator& operator++(); |
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 | regex_iterator operator++(int) |
| 6366 | { |
| 6367 | regex_iterator __t(*this); |
| 6368 | ++(*this); |
| 6369 | return __t; |
| 6370 | } |
| 6371 | }; |
| 6372 | |
| 6373 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6374 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() |
| 6375 | : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() |
| 6376 | { |
| 6377 | } |
| 6378 | |
| 6379 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6380 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6381 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6382 | const regex_type& __re, regex_constants::match_flag_type __m) |
| 6383 | : __begin_(__a), |
| 6384 | __end_(__b), |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6385 | __pregex_(_VSTD::addressof(__re)), |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6386 | __flags_(__m) |
| 6387 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6388 | _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6389 | } |
| 6390 | |
| 6391 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6392 | bool |
| 6393 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6394 | operator==(const regex_iterator& __x) const |
| 6395 | { |
| 6396 | if (__match_.empty() && __x.__match_.empty()) |
| 6397 | return true; |
| 6398 | if (__match_.empty() || __x.__match_.empty()) |
| 6399 | return false; |
| 6400 | return __begin_ == __x.__begin_ && |
| 6401 | __end_ == __x.__end_ && |
| 6402 | __pregex_ == __x.__pregex_ && |
| 6403 | __flags_ == __x.__flags_ && |
| 6404 | __match_[0] == __x.__match_[0]; |
| 6405 | } |
| 6406 | |
| 6407 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6408 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6409 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6410 | { |
| 6411 | __flags_ |= regex_constants::__no_update_pos; |
| 6412 | _BidirectionalIterator __start = __match_[0].second; |
Marshall Clow | faa964d | 2017-07-05 16:37:19 +0000 | [diff] [blame] | 6413 | if (__match_[0].first == __match_[0].second) |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6414 | { |
| 6415 | if (__start == __end_) |
| 6416 | { |
| 6417 | __match_ = value_type(); |
| 6418 | return *this; |
| 6419 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6420 | else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6421 | __flags_ | regex_constants::match_not_null | |
| 6422 | regex_constants::match_continuous)) |
| 6423 | return *this; |
| 6424 | else |
| 6425 | ++__start; |
| 6426 | } |
| 6427 | __flags_ |= regex_constants::match_prev_avail; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6428 | if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6429 | __match_ = value_type(); |
| 6430 | return *this; |
| 6431 | } |
| 6432 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6433 | // regex_token_iterator |
| 6434 | |
| 6435 | template <class _BidirectionalIterator, |
| 6436 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6437 | class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6438 | class _LIBCPP_TEMPLATE_VIS regex_token_iterator; |
| 6439 | |
| 6440 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6441 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6442 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6443 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6444 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6445 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6446 | |
| 6447 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6448 | class |
| 6449 | _LIBCPP_TEMPLATE_VIS |
| 6450 | _LIBCPP_PREFERRED_NAME(cregex_token_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6451 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6452 | _LIBCPP_PREFERRED_NAME(sregex_token_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6453 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6454 | regex_token_iterator |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6455 | { |
| 6456 | public: |
| 6457 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6458 | typedef sub_match<_BidirectionalIterator> value_type; |
| 6459 | typedef ptrdiff_t difference_type; |
| 6460 | typedef const value_type* pointer; |
| 6461 | typedef const value_type& reference; |
| 6462 | typedef forward_iterator_tag iterator_category; |
| 6463 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6464 | private: |
| 6465 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; |
| 6466 | |
| 6467 | _Position __position_; |
| 6468 | const value_type* __result_; |
| 6469 | value_type __suffix_; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6470 | ptrdiff_t __n_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6471 | vector<int> __subs_; |
| 6472 | |
| 6473 | public: |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6474 | regex_token_iterator(); |
| 6475 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6476 | const regex_type& __re, int __submatch = 0, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6477 | regex_constants::match_flag_type __m = |
| 6478 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6479 | #if _LIBCPP_STD_VER > 11 |
| 6480 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6481 | const regex_type&& __re, int __submatch = 0, |
| 6482 | regex_constants::match_flag_type __m = |
| 6483 | regex_constants::match_default) = delete; |
| 6484 | #endif |
| 6485 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6486 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6487 | const regex_type& __re, const vector<int>& __submatches, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6488 | regex_constants::match_flag_type __m = |
| 6489 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6490 | #if _LIBCPP_STD_VER > 11 |
| 6491 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6492 | const regex_type&& __re, const vector<int>& __submatches, |
| 6493 | regex_constants::match_flag_type __m = |
| 6494 | regex_constants::match_default) = delete; |
| 6495 | #endif |
| 6496 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 6497 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6498 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6499 | const regex_type& __re, |
| 6500 | initializer_list<int> __submatches, |
| 6501 | regex_constants::match_flag_type __m = |
| 6502 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6503 | |
| 6504 | #if _LIBCPP_STD_VER > 11 |
| 6505 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6506 | const regex_type&& __re, |
| 6507 | initializer_list<int> __submatches, |
| 6508 | regex_constants::match_flag_type __m = |
| 6509 | regex_constants::match_default) = delete; |
| 6510 | #endif |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6511 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6512 | template <size_t _Np> |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6513 | regex_token_iterator(_BidirectionalIterator __a, |
| 6514 | _BidirectionalIterator __b, |
| 6515 | const regex_type& __re, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6516 | const int (&__submatches)[_Np], |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6517 | regex_constants::match_flag_type __m = |
| 6518 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6519 | #if _LIBCPP_STD_VER > 11 |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 6520 | template <size_t _Np> |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6521 | regex_token_iterator(_BidirectionalIterator __a, |
| 6522 | _BidirectionalIterator __b, |
| 6523 | const regex_type&& __re, |
| 6524 | const int (&__submatches)[_Np], |
| 6525 | regex_constants::match_flag_type __m = |
| 6526 | regex_constants::match_default) = delete; |
| 6527 | #endif |
| 6528 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6529 | regex_token_iterator(const regex_token_iterator&); |
| 6530 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 6531 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6532 | bool operator==(const regex_token_iterator& __x) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6533 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6534 | bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6535 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6536 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6537 | const value_type& operator*() const {return *__result_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6538 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6539 | const value_type* operator->() const {return __result_;} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6540 | |
| 6541 | regex_token_iterator& operator++(); |
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 | regex_token_iterator operator++(int) |
| 6544 | { |
| 6545 | regex_token_iterator __t(*this); |
| 6546 | ++(*this); |
| 6547 | return __t; |
| 6548 | } |
| 6549 | |
| 6550 | private: |
| 6551 | void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6552 | void __establish_result () { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6553 | if (__subs_[__n_] == -1) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6554 | __result_ = &__position_->prefix(); |
| 6555 | else |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6556 | __result_ = &(*__position_)[__subs_[__n_]]; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6557 | } |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6558 | }; |
| 6559 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6560 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6561 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6562 | regex_token_iterator() |
| 6563 | : __result_(nullptr), |
| 6564 | __suffix_(), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6565 | __n_(0) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6566 | { |
| 6567 | } |
| 6568 | |
| 6569 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6570 | void |
| 6571 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6572 | __init(_BidirectionalIterator __a, _BidirectionalIterator __b) |
| 6573 | { |
| 6574 | if (__position_ != _Position()) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6575 | __establish_result (); |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6576 | else if (__subs_[__n_] == -1) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6577 | { |
| 6578 | __suffix_.matched = true; |
| 6579 | __suffix_.first = __a; |
| 6580 | __suffix_.second = __b; |
| 6581 | __result_ = &__suffix_; |
| 6582 | } |
| 6583 | else |
| 6584 | __result_ = nullptr; |
| 6585 | } |
| 6586 | |
| 6587 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6588 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6589 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6590 | const regex_type& __re, int __submatch, |
| 6591 | regex_constants::match_flag_type __m) |
| 6592 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6593 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6594 | __subs_(1, __submatch) |
| 6595 | { |
| 6596 | __init(__a, __b); |
| 6597 | } |
| 6598 | |
| 6599 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6600 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6601 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6602 | const regex_type& __re, const vector<int>& __submatches, |
| 6603 | regex_constants::match_flag_type __m) |
| 6604 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6605 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6606 | __subs_(__submatches) |
| 6607 | { |
| 6608 | __init(__a, __b); |
| 6609 | } |
| 6610 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 6611 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6612 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6613 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6614 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6615 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6616 | const regex_type& __re, |
| 6617 | initializer_list<int> __submatches, |
| 6618 | regex_constants::match_flag_type __m) |
| 6619 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6620 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6621 | __subs_(__submatches) |
| 6622 | { |
| 6623 | __init(__a, __b); |
| 6624 | } |
| 6625 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6626 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6627 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6628 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6629 | template <size_t _Np> |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6630 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6631 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6632 | const regex_type& __re, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6633 | const int (&__submatches)[_Np], |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6634 | regex_constants::match_flag_type __m) |
| 6635 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6636 | __n_(0), |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6637 | __subs_(begin(__submatches), end(__submatches)) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6638 | { |
| 6639 | __init(__a, __b); |
| 6640 | } |
| 6641 | |
| 6642 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6643 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6644 | regex_token_iterator(const regex_token_iterator& __x) |
| 6645 | : __position_(__x.__position_), |
| 6646 | __result_(__x.__result_), |
| 6647 | __suffix_(__x.__suffix_), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6648 | __n_(__x.__n_), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6649 | __subs_(__x.__subs_) |
| 6650 | { |
| 6651 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 20756ac | 2014-01-13 17:47:08 +0000 | [diff] [blame] | 6652 | __result_ = &__suffix_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6653 | else if ( __result_ != nullptr ) |
| 6654 | __establish_result (); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6655 | } |
| 6656 | |
| 6657 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6658 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6659 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6660 | operator=(const regex_token_iterator& __x) |
| 6661 | { |
| 6662 | if (this != &__x) |
| 6663 | { |
| 6664 | __position_ = __x.__position_; |
| 6665 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6666 | __result_ = &__suffix_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6667 | else |
| 6668 | __result_ = __x.__result_; |
| 6669 | __suffix_ = __x.__suffix_; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6670 | __n_ = __x.__n_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6671 | __subs_ = __x.__subs_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6672 | |
| 6673 | if ( __result_ != nullptr && __result_ != &__suffix_ ) |
| 6674 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6675 | } |
| 6676 | return *this; |
| 6677 | } |
| 6678 | |
| 6679 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6680 | bool |
| 6681 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6682 | operator==(const regex_token_iterator& __x) const |
| 6683 | { |
| 6684 | if (__result_ == nullptr && __x.__result_ == nullptr) |
| 6685 | return true; |
| 6686 | if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && |
| 6687 | __suffix_ == __x.__suffix_) |
| 6688 | return true; |
| 6689 | if (__result_ == nullptr || __x.__result_ == nullptr) |
| 6690 | return false; |
| 6691 | if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) |
| 6692 | return false; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6693 | return __position_ == __x.__position_ && __n_ == __x.__n_ && |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6694 | __subs_ == __x.__subs_; |
| 6695 | } |
| 6696 | |
| 6697 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6698 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6699 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6700 | { |
| 6701 | _Position __prev = __position_; |
| 6702 | if (__result_ == &__suffix_) |
| 6703 | __result_ = nullptr; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6704 | else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6705 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6706 | ++__n_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6707 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6708 | } |
| 6709 | else |
| 6710 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6711 | __n_ = 0; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6712 | ++__position_; |
| 6713 | if (__position_ != _Position()) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6714 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6715 | else |
| 6716 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6717 | if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6718 | && __prev->suffix().length() != 0) |
| 6719 | { |
| 6720 | __suffix_.matched = true; |
| 6721 | __suffix_.first = __prev->suffix().first; |
| 6722 | __suffix_.second = __prev->suffix().second; |
| 6723 | __result_ = &__suffix_; |
| 6724 | } |
| 6725 | else |
| 6726 | __result_ = nullptr; |
| 6727 | } |
| 6728 | } |
| 6729 | return *this; |
| 6730 | } |
| 6731 | |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6732 | // regex_replace |
| 6733 | |
| 6734 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6735 | class _Traits, class _CharT> |
Nikolas Klauser | a9ad670 | 2022-08-13 13:23:16 +0200 | [diff] [blame] | 6736 | _LIBCPP_HIDE_FROM_ABI _OutputIterator |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6737 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6738 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6739 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6740 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6741 | { |
| 6742 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; |
| 6743 | _Iter __i(__first, __last, __e, __flags); |
| 6744 | _Iter __eof; |
| 6745 | if (__i == __eof) |
| 6746 | { |
| 6747 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6748 | __output_iter = _VSTD::copy(__first, __last, __output_iter); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6749 | } |
| 6750 | else |
| 6751 | { |
| 6752 | sub_match<_BidirectionalIterator> __lm; |
| 6753 | for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) |
| 6754 | { |
| 6755 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6756 | __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter); |
| 6757 | __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6758 | __lm = __i->suffix(); |
| 6759 | if (__flags & regex_constants::format_first_only) |
| 6760 | break; |
| 6761 | } |
| 6762 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6763 | __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6764 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6765 | return __output_iter; |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6766 | } |
| 6767 | |
| 6768 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6769 | class _Traits, class _CharT, class _ST, class _SA> |
| 6770 | inline _LIBCPP_INLINE_VISIBILITY |
| 6771 | _OutputIterator |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6772 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6773 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6774 | const basic_regex<_CharT, _Traits>& __e, |
| 6775 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6776 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6777 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6778 | 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] | 6779 | } |
| 6780 | |
| 6781 | template <class _Traits, class _CharT, class _ST, class _SA, class _FST, |
| 6782 | class _FSA> |
| 6783 | inline _LIBCPP_INLINE_VISIBILITY |
| 6784 | basic_string<_CharT, _ST, _SA> |
| 6785 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6786 | const basic_regex<_CharT, _Traits>& __e, |
| 6787 | const basic_string<_CharT, _FST, _FSA>& __fmt, |
| 6788 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6789 | { |
| 6790 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6791 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6792 | __fmt.c_str(), __flags); |
| 6793 | return __r; |
| 6794 | } |
| 6795 | |
| 6796 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6797 | inline _LIBCPP_INLINE_VISIBILITY |
| 6798 | basic_string<_CharT, _ST, _SA> |
| 6799 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6800 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6801 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6802 | { |
| 6803 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6804 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6805 | __fmt, __flags); |
| 6806 | return __r; |
| 6807 | } |
| 6808 | |
| 6809 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6810 | inline _LIBCPP_INLINE_VISIBILITY |
| 6811 | basic_string<_CharT> |
| 6812 | regex_replace(const _CharT* __s, |
| 6813 | const basic_regex<_CharT, _Traits>& __e, |
| 6814 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6815 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6816 | { |
| 6817 | basic_string<_CharT> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6818 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6819 | __s + char_traits<_CharT>::length(__s), __e, |
| 6820 | __fmt.c_str(), __flags); |
| 6821 | return __r; |
| 6822 | } |
| 6823 | |
| 6824 | template <class _Traits, class _CharT> |
| 6825 | inline _LIBCPP_INLINE_VISIBILITY |
| 6826 | basic_string<_CharT> |
| 6827 | regex_replace(const _CharT* __s, |
| 6828 | const basic_regex<_CharT, _Traits>& __e, |
| 6829 | const _CharT* __fmt, |
| 6830 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6831 | { |
| 6832 | basic_string<_CharT> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6833 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6834 | __s + char_traits<_CharT>::length(__s), __e, |
| 6835 | __fmt, __flags); |
| 6836 | return __r; |
| 6837 | } |
| 6838 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 6839 | _LIBCPP_END_NAMESPACE_STD |
| 6840 | |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 6841 | #if _LIBCPP_STD_VER > 14 |
| 6842 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 6843 | namespace pmr { |
| 6844 | template <class _BidirT> |
| 6845 | using match_results = std::match_results<_BidirT, polymorphic_allocator<std::sub_match<_BidirT>>>; |
| 6846 | |
| 6847 | using cmatch = match_results<const char*>; |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 6848 | using smatch = match_results<std::pmr::string::const_iterator>; |
Nikolas Klauser | 713bfda | 2022-10-13 01:03:58 +0200 | [diff] [blame] | 6849 | |
| 6850 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6851 | using wcmatch = match_results<const wchar_t*>; |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 6852 | using wsmatch = match_results<std::pmr::wstring::const_iterator>; |
Nikolas Klauser | 713bfda | 2022-10-13 01:03:58 +0200 | [diff] [blame] | 6853 | #endif |
Arthur O'Dwyer | ebf2d34 | 2022-10-06 16:53:30 -0400 | [diff] [blame] | 6854 | } // namespace pmr |
| 6855 | _LIBCPP_END_NAMESPACE_STD |
| 6856 | #endif |
| 6857 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 6858 | _LIBCPP_POP_MACROS |
| 6859 | |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 6860 | #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
Nikolas Klauser | 1e4ae5d | 2022-11-02 20:27:42 +0100 | [diff] [blame^] | 6861 | # include <concepts> |
Mark de Wever | ee5fe27 | 2022-09-02 17:53:28 +0200 | [diff] [blame] | 6862 | # include <iterator> |
| 6863 | # include <utility> |
| 6864 | #endif |
| 6865 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6866 | #endif // _LIBCPP_REGEX |