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/access.h> |
| 770 | #include <__iterator/back_insert_iterator.h> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 771 | #include <__iterator/wrap_iter.h> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 772 | #include <__locale> |
Nikolas Klauser | 8fccd62 | 2022-03-05 19:17:07 +0100 | [diff] [blame] | 773 | #include <__utility/move.h> |
| 774 | #include <__utility/swap.h> |
Arthur O'Dwyer | 7deec12 | 2021-03-24 18:19:12 -0400 | [diff] [blame] | 775 | #include <compare> |
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 <initializer_list> |
Nikolas Klauser | fb1b067 | 2022-06-10 19:53:10 +0200 | [diff] [blame^] | 778 | #include <iterator> // TODO: Remove this include |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 779 | #include <memory> |
| 780 | #include <stdexcept> |
| 781 | #include <string> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 782 | #include <vector> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 783 | #include <version> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 784 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 785 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 786 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 787 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 788 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 789 | _LIBCPP_PUSH_MACROS |
| 790 | #include <__undef_macros> |
| 791 | |
| 792 | |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 793 | #define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096 |
| 794 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 795 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 796 | |
| 797 | namespace regex_constants |
| 798 | { |
| 799 | |
| 800 | // syntax_option_type |
| 801 | |
| 802 | enum syntax_option_type |
| 803 | { |
| 804 | icase = 1 << 0, |
| 805 | nosubs = 1 << 1, |
| 806 | optimize = 1 << 2, |
| 807 | collate = 1 << 3, |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 808 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 809 | ECMAScript = 1 << 9, |
| 810 | #else |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 811 | ECMAScript = 0, |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 812 | #endif |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 813 | basic = 1 << 4, |
| 814 | extended = 1 << 5, |
| 815 | awk = 1 << 6, |
| 816 | grep = 1 << 7, |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 817 | egrep = 1 << 8, |
| 818 | // 1 << 9 may be used by ECMAScript |
| 819 | multiline = 1 << 10 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 820 | }; |
| 821 | |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 822 | inline _LIBCPP_CONSTEXPR |
| 823 | syntax_option_type __get_grammar(syntax_option_type __g) |
| 824 | { |
| 825 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 826 | return static_cast<syntax_option_type>(__g & 0x3F0); |
| 827 | #else |
| 828 | return static_cast<syntax_option_type>(__g & 0x1F0); |
| 829 | #endif |
| 830 | } |
| 831 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 832 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 833 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 834 | syntax_option_type |
| 835 | operator~(syntax_option_type __x) |
| 836 | { |
Marshall Clow | 924cffa | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 837 | return syntax_option_type(~int(__x) & 0x1FF); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 840 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 841 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 842 | syntax_option_type |
| 843 | operator&(syntax_option_type __x, syntax_option_type __y) |
| 844 | { |
| 845 | return syntax_option_type(int(__x) & int(__y)); |
| 846 | } |
| 847 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 848 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 849 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 850 | syntax_option_type |
| 851 | operator|(syntax_option_type __x, syntax_option_type __y) |
| 852 | { |
| 853 | return syntax_option_type(int(__x) | int(__y)); |
| 854 | } |
| 855 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 856 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 857 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 858 | syntax_option_type |
| 859 | operator^(syntax_option_type __x, syntax_option_type __y) |
| 860 | { |
| 861 | return syntax_option_type(int(__x) ^ int(__y)); |
| 862 | } |
| 863 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 864 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 865 | syntax_option_type& |
| 866 | operator&=(syntax_option_type& __x, syntax_option_type __y) |
| 867 | { |
| 868 | __x = __x & __y; |
| 869 | return __x; |
| 870 | } |
| 871 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 872 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 873 | syntax_option_type& |
| 874 | operator|=(syntax_option_type& __x, syntax_option_type __y) |
| 875 | { |
| 876 | __x = __x | __y; |
| 877 | return __x; |
| 878 | } |
| 879 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 880 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 881 | syntax_option_type& |
| 882 | operator^=(syntax_option_type& __x, syntax_option_type __y) |
| 883 | { |
| 884 | __x = __x ^ __y; |
| 885 | return __x; |
| 886 | } |
| 887 | |
| 888 | // match_flag_type |
| 889 | |
| 890 | enum match_flag_type |
| 891 | { |
| 892 | match_default = 0, |
| 893 | match_not_bol = 1 << 0, |
| 894 | match_not_eol = 1 << 1, |
| 895 | match_not_bow = 1 << 2, |
| 896 | match_not_eow = 1 << 3, |
| 897 | match_any = 1 << 4, |
| 898 | match_not_null = 1 << 5, |
| 899 | match_continuous = 1 << 6, |
| 900 | match_prev_avail = 1 << 7, |
| 901 | format_default = 0, |
| 902 | format_sed = 1 << 8, |
| 903 | format_no_copy = 1 << 9, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 904 | format_first_only = 1 << 10, |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 905 | __no_update_pos = 1 << 11, |
| 906 | __full_match = 1 << 12 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 907 | }; |
| 908 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 909 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 910 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 911 | match_flag_type |
| 912 | operator~(match_flag_type __x) |
| 913 | { |
Marshall Clow | 924cffa | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 914 | return match_flag_type(~int(__x) & 0x0FFF); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 915 | } |
| 916 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 917 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 918 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 919 | match_flag_type |
| 920 | operator&(match_flag_type __x, match_flag_type __y) |
| 921 | { |
| 922 | return match_flag_type(int(__x) & int(__y)); |
| 923 | } |
| 924 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 925 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 926 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 927 | match_flag_type |
| 928 | operator|(match_flag_type __x, match_flag_type __y) |
| 929 | { |
| 930 | return match_flag_type(int(__x) | int(__y)); |
| 931 | } |
| 932 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 933 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 934 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 935 | match_flag_type |
| 936 | operator^(match_flag_type __x, match_flag_type __y) |
| 937 | { |
| 938 | return match_flag_type(int(__x) ^ int(__y)); |
| 939 | } |
| 940 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 941 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 942 | match_flag_type& |
| 943 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 944 | { |
| 945 | __x = __x & __y; |
| 946 | return __x; |
| 947 | } |
| 948 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 949 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 950 | match_flag_type& |
| 951 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 952 | { |
| 953 | __x = __x | __y; |
| 954 | return __x; |
| 955 | } |
| 956 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 957 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 958 | match_flag_type& |
| 959 | operator^=(match_flag_type& __x, match_flag_type __y) |
| 960 | { |
| 961 | __x = __x ^ __y; |
| 962 | return __x; |
| 963 | } |
| 964 | |
| 965 | enum error_type |
| 966 | { |
| 967 | error_collate = 1, |
| 968 | error_ctype, |
| 969 | error_escape, |
| 970 | error_backref, |
| 971 | error_brack, |
| 972 | error_paren, |
| 973 | error_brace, |
| 974 | error_badbrace, |
| 975 | error_range, |
| 976 | error_space, |
| 977 | error_badrepeat, |
| 978 | error_complexity, |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 979 | error_stack, |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 980 | __re_err_grammar, |
| 981 | __re_err_empty, |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 982 | __re_err_unknown, |
| 983 | __re_err_parse |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 984 | }; |
| 985 | |
Nikolas Klauser | d26407a | 2021-12-02 14:12:51 +0100 | [diff] [blame] | 986 | } // namespace regex_constants |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 987 | |
| 988 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 989 | : public runtime_error |
| 990 | { |
| 991 | regex_constants::error_type __code_; |
| 992 | public: |
| 993 | explicit regex_error(regex_constants::error_type __ecode); |
Dimitry Andric | 47269ce | 2020-03-13 19:36:26 +0100 | [diff] [blame] | 994 | regex_error(const regex_error&) _NOEXCEPT = default; |
| 995 | virtual ~regex_error() _NOEXCEPT; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 996 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 997 | regex_constants::error_type code() const {return __code_;} |
| 998 | }; |
| 999 | |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 1000 | template <regex_constants::error_type _Ev> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1001 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 1002 | void __throw_regex_error() |
| 1003 | { |
| 1004 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Marshall Clow | 8bf61bb | 2015-08-17 21:14:16 +0000 | [diff] [blame] | 1005 | throw regex_error(_Ev); |
| 1006 | #else |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 1007 | _VSTD::abort(); |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 1008 | #endif |
| 1009 | } |
| 1010 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1011 | template <class _CharT> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1012 | struct _LIBCPP_TEMPLATE_VIS regex_traits |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1013 | { |
| 1014 | public: |
| 1015 | typedef _CharT char_type; |
| 1016 | typedef basic_string<char_type> string_type; |
| 1017 | typedef locale locale_type; |
Dan Albert | 70ee07e | 2020-04-06 13:34:27 -0700 | [diff] [blame] | 1018 | #ifdef __BIONIC__ |
| 1019 | // Originally bionic's ctype_base used its own ctype masks because the |
| 1020 | // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask |
| 1021 | // was only 8 bits wide and already saturated, so it used a wider type here |
| 1022 | // to make room for __regex_word (then a part of this class rather than |
| 1023 | // ctype_base). Bionic has since moved to the builtin ctype_base |
| 1024 | // implementation, but this was not updated to match. Since then Android has |
| 1025 | // needed to maintain a stable libc++ ABI, and this can't be changed without |
| 1026 | // an ABI break. |
| 1027 | typedef uint16_t char_class_type; |
| 1028 | #else |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1029 | typedef ctype_base::mask char_class_type; |
Dan Albert | 70ee07e | 2020-04-06 13:34:27 -0700 | [diff] [blame] | 1030 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1031 | |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 1032 | static const char_class_type __regex_word = ctype_base::__regex_word; |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1033 | private: |
| 1034 | locale __loc_; |
| 1035 | const ctype<char_type>* __ct_; |
| 1036 | const collate<char_type>* __col_; |
| 1037 | |
| 1038 | public: |
| 1039 | regex_traits(); |
| 1040 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1041 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1042 | static size_t length(const char_type* __p) |
| 1043 | {return char_traits<char_type>::length(__p);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1044 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1045 | char_type translate(char_type __c) const {return __c;} |
| 1046 | char_type translate_nocase(char_type __c) const; |
| 1047 | template <class _ForwardIterator> |
| 1048 | string_type |
| 1049 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 1050 | template <class _ForwardIterator> |
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 | string_type |
| 1053 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 1054 | {return __transform_primary(__f, __l, char_type());} |
| 1055 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1056 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1057 | string_type |
| 1058 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 1059 | {return __lookup_collatename(__f, __l, char_type());} |
| 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 | char_class_type |
| 1063 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1064 | bool __icase = false) const |
| 1065 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 1066 | bool isctype(char_type __c, char_class_type __m) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1067 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1068 | int value(char_type __ch, int __radix) const |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1069 | {return __regex_traits_value(__ch, __radix);} |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1070 | locale_type imbue(locale_type __l); |
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 | locale_type getloc()const {return __loc_;} |
| 1073 | |
| 1074 | private: |
| 1075 | void __init(); |
| 1076 | |
| 1077 | template <class _ForwardIterator> |
| 1078 | string_type |
| 1079 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1080 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1081 | template <class _ForwardIterator> |
| 1082 | string_type |
| 1083 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1084 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1085 | template <class _ForwardIterator> |
| 1086 | string_type |
| 1087 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1088 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1089 | template <class _ForwardIterator> |
| 1090 | string_type |
| 1091 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1092 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1093 | template <class _ForwardIterator> |
| 1094 | char_class_type |
| 1095 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1096 | bool __icase, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1097 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1098 | template <class _ForwardIterator> |
| 1099 | char_class_type |
| 1100 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1101 | bool __icase, 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 | |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1104 | static int __regex_traits_value(unsigned char __ch, int __radix); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1105 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1106 | int __regex_traits_value(char __ch, int __radix) const |
| 1107 | {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);} |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1108 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1109 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1110 | int __regex_traits_value(wchar_t __ch, int __radix) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1111 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1112 | }; |
| 1113 | |
| 1114 | template <class _CharT> |
Howard Hinnant | 592cb61 | 2013-03-07 19:38:08 +0000 | [diff] [blame] | 1115 | const typename regex_traits<_CharT>::char_class_type |
| 1116 | regex_traits<_CharT>::__regex_word; |
| 1117 | |
| 1118 | template <class _CharT> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1119 | regex_traits<_CharT>::regex_traits() |
| 1120 | { |
| 1121 | __init(); |
| 1122 | } |
| 1123 | |
| 1124 | template <class _CharT> |
| 1125 | typename regex_traits<_CharT>::char_type |
| 1126 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1127 | { |
| 1128 | return __ct_->tolower(__c); |
| 1129 | } |
| 1130 | |
| 1131 | template <class _CharT> |
| 1132 | template <class _ForwardIterator> |
| 1133 | typename regex_traits<_CharT>::string_type |
| 1134 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1135 | { |
| 1136 | string_type __s(__f, __l); |
| 1137 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1138 | } |
| 1139 | |
| 1140 | template <class _CharT> |
| 1141 | void |
| 1142 | regex_traits<_CharT>::__init() |
| 1143 | { |
| 1144 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1145 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1146 | } |
| 1147 | |
| 1148 | template <class _CharT> |
| 1149 | typename regex_traits<_CharT>::locale_type |
| 1150 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1151 | { |
| 1152 | locale __r = __loc_; |
| 1153 | __loc_ = __l; |
| 1154 | __init(); |
| 1155 | return __r; |
| 1156 | } |
| 1157 | |
| 1158 | // transform_primary is very FreeBSD-specific |
| 1159 | |
| 1160 | template <class _CharT> |
| 1161 | template <class _ForwardIterator> |
| 1162 | typename regex_traits<_CharT>::string_type |
| 1163 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1164 | _ForwardIterator __l, char) const |
| 1165 | { |
| 1166 | const string_type __s(__f, __l); |
| 1167 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1168 | switch (__d.size()) |
| 1169 | { |
| 1170 | case 1: |
| 1171 | break; |
| 1172 | case 12: |
| 1173 | __d[11] = __d[3]; |
| 1174 | break; |
| 1175 | default: |
| 1176 | __d.clear(); |
| 1177 | break; |
| 1178 | } |
| 1179 | return __d; |
| 1180 | } |
| 1181 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1182 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1183 | template <class _CharT> |
| 1184 | template <class _ForwardIterator> |
| 1185 | typename regex_traits<_CharT>::string_type |
| 1186 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1187 | _ForwardIterator __l, wchar_t) const |
| 1188 | { |
| 1189 | const string_type __s(__f, __l); |
| 1190 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1191 | switch (__d.size()) |
| 1192 | { |
| 1193 | case 1: |
| 1194 | break; |
| 1195 | case 3: |
| 1196 | __d[2] = __d[0]; |
| 1197 | break; |
| 1198 | default: |
| 1199 | __d.clear(); |
| 1200 | break; |
| 1201 | } |
| 1202 | return __d; |
| 1203 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1204 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1205 | |
| 1206 | // lookup_collatename is very FreeBSD-specific |
| 1207 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1208 | _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1209 | |
| 1210 | template <class _CharT> |
| 1211 | template <class _ForwardIterator> |
| 1212 | typename regex_traits<_CharT>::string_type |
| 1213 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1214 | _ForwardIterator __l, char) const |
| 1215 | { |
| 1216 | string_type __s(__f, __l); |
| 1217 | string_type __r; |
| 1218 | if (!__s.empty()) |
| 1219 | { |
| 1220 | __r = __get_collation_name(__s.c_str()); |
| 1221 | if (__r.empty() && __s.size() <= 2) |
| 1222 | { |
| 1223 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1224 | if (__r.size() == 1 || __r.size() == 12) |
| 1225 | __r = __s; |
| 1226 | else |
| 1227 | __r.clear(); |
| 1228 | } |
| 1229 | } |
| 1230 | return __r; |
| 1231 | } |
| 1232 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1233 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1234 | template <class _CharT> |
| 1235 | template <class _ForwardIterator> |
| 1236 | typename regex_traits<_CharT>::string_type |
| 1237 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1238 | _ForwardIterator __l, wchar_t) const |
| 1239 | { |
| 1240 | string_type __s(__f, __l); |
| 1241 | string __n; |
| 1242 | __n.reserve(__s.size()); |
| 1243 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1244 | __i != __e; ++__i) |
| 1245 | { |
| 1246 | if (static_cast<unsigned>(*__i) >= 127) |
| 1247 | return string_type(); |
| 1248 | __n.push_back(char(*__i)); |
| 1249 | } |
| 1250 | string_type __r; |
| 1251 | if (!__s.empty()) |
| 1252 | { |
| 1253 | __n = __get_collation_name(__n.c_str()); |
| 1254 | if (!__n.empty()) |
| 1255 | __r.assign(__n.begin(), __n.end()); |
| 1256 | else if (__s.size() <= 2) |
| 1257 | { |
| 1258 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1259 | if (__r.size() == 1 || __r.size() == 3) |
| 1260 | __r = __s; |
| 1261 | else |
| 1262 | __r.clear(); |
| 1263 | } |
| 1264 | } |
| 1265 | return __r; |
| 1266 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1267 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1268 | |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1269 | // lookup_classname |
| 1270 | |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 1271 | regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS |
| 1272 | __get_classname(const char* __s, bool __icase); |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1273 | |
| 1274 | template <class _CharT> |
| 1275 | template <class _ForwardIterator> |
| 1276 | typename regex_traits<_CharT>::char_class_type |
| 1277 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1278 | _ForwardIterator __l, |
| 1279 | bool __icase, char) const |
| 1280 | { |
| 1281 | string_type __s(__f, __l); |
| 1282 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1283 | return __get_classname(__s.c_str(), __icase); |
| 1284 | } |
| 1285 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1286 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1287 | template <class _CharT> |
| 1288 | template <class _ForwardIterator> |
| 1289 | typename regex_traits<_CharT>::char_class_type |
| 1290 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1291 | _ForwardIterator __l, |
| 1292 | bool __icase, wchar_t) const |
| 1293 | { |
| 1294 | string_type __s(__f, __l); |
| 1295 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1296 | string __n; |
| 1297 | __n.reserve(__s.size()); |
| 1298 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1299 | __i != __e; ++__i) |
| 1300 | { |
| 1301 | if (static_cast<unsigned>(*__i) >= 127) |
| 1302 | return char_class_type(); |
| 1303 | __n.push_back(char(*__i)); |
| 1304 | } |
| 1305 | return __get_classname(__n.c_str(), __icase); |
| 1306 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1307 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1308 | |
| 1309 | template <class _CharT> |
| 1310 | bool |
| 1311 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1312 | { |
| 1313 | if (__ct_->is(__m, __c)) |
| 1314 | return true; |
| 1315 | return (__c == '_' && (__m & __regex_word)); |
| 1316 | } |
| 1317 | |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1318 | inline _LIBCPP_INLINE_VISIBILITY |
| 1319 | bool __is_07(unsigned char c) |
| 1320 | { |
| 1321 | return (c & 0xF8u) == |
| 1322 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1323 | 0xF0; |
| 1324 | #else |
| 1325 | 0x30; |
| 1326 | #endif |
| 1327 | } |
| 1328 | |
| 1329 | inline _LIBCPP_INLINE_VISIBILITY |
| 1330 | bool __is_89(unsigned char c) |
| 1331 | { |
| 1332 | return (c & 0xFEu) == |
| 1333 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1334 | 0xF8; |
| 1335 | #else |
| 1336 | 0x38; |
| 1337 | #endif |
| 1338 | } |
| 1339 | |
| 1340 | inline _LIBCPP_INLINE_VISIBILITY |
| 1341 | unsigned char __to_lower(unsigned char c) |
| 1342 | { |
| 1343 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1344 | return c & 0xBF; |
| 1345 | #else |
| 1346 | return c | 0x20; |
| 1347 | #endif |
| 1348 | } |
| 1349 | |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1350 | template <class _CharT> |
| 1351 | int |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1352 | regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1353 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1354 | if (__is_07(__ch)) // '0' <= __ch && __ch <= '7' |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1355 | return __ch - '0'; |
| 1356 | if (__radix != 8) |
| 1357 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1358 | if (__is_89(__ch)) // '8' <= __ch && __ch <= '9' |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1359 | return __ch - '0'; |
| 1360 | if (__radix == 16) |
| 1361 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1362 | __ch = __to_lower(__ch); // tolower |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1363 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1364 | return __ch - ('a' - 10); |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | return -1; |
| 1368 | } |
| 1369 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1370 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1371 | template <class _CharT> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1372 | inline |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1373 | int |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1374 | regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1375 | { |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1376 | 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] | 1377 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1378 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1379 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1380 | template <class _CharT> class __node; |
| 1381 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1382 | template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1383 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1384 | template <class _BidirectionalIterator, |
| 1385 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1386 | class _LIBCPP_TEMPLATE_VIS match_results; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1387 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1388 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1389 | struct __state |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1390 | { |
| 1391 | enum |
| 1392 | { |
| 1393 | __end_state = -1000, |
| 1394 | __consume_input, // -999 |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1395 | __begin_marked_expr, // -998 |
| 1396 | __end_marked_expr, // -997 |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1397 | __pop_state, // -996 |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1398 | __accept_and_consume, // -995 |
| 1399 | __accept_but_not_consume, // -994 |
| 1400 | __reject, // -993 |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1401 | __split, |
| 1402 | __repeat |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1403 | }; |
| 1404 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1405 | int __do_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1406 | const _CharT* __first_; |
| 1407 | const _CharT* __current_; |
| 1408 | const _CharT* __last_; |
| 1409 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1410 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1411 | const __node<_CharT>* __node_; |
| 1412 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1413 | bool __at_first_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1414 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1415 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1416 | __state() |
| 1417 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1418 | __node_(nullptr), __flags_() {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1419 | }; |
| 1420 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1421 | // __node |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1422 | |
| 1423 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1424 | class __node |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1425 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1426 | __node(const __node&); |
| 1427 | __node& operator=(const __node&); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1428 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1429 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1430 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1431 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1432 | __node() {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1433 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1434 | virtual ~__node() {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1435 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1436 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 1437 | virtual void __exec(__state&) const {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1438 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 1439 | virtual void __exec_split(bool, __state&) const {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1440 | }; |
| 1441 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1442 | // __end_state |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1443 | |
| 1444 | template <class _CharT> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1445 | class __end_state |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1446 | : public __node<_CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1447 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1448 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1449 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1450 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1451 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1452 | __end_state() {} |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1453 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1454 | virtual void __exec(__state&) const; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1455 | }; |
| 1456 | |
| 1457 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1458 | void |
| 1459 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1460 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1461 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1462 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1463 | |
| 1464 | // __has_one_state |
| 1465 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1466 | template <class _CharT> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1467 | class __has_one_state |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1468 | : public __node<_CharT> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1469 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1470 | __node<_CharT>* __first_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1471 | |
| 1472 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1473 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1474 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1475 | : __first_(__s) {} |
| 1476 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1477 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1478 | __node<_CharT>* first() const {return __first_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1479 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1480 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1481 | }; |
| 1482 | |
| 1483 | // __owns_one_state |
| 1484 | |
| 1485 | template <class _CharT> |
| 1486 | class __owns_one_state |
| 1487 | : public __has_one_state<_CharT> |
| 1488 | { |
| 1489 | typedef __has_one_state<_CharT> base; |
| 1490 | |
| 1491 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1492 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1493 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1494 | : base(__s) {} |
| 1495 | |
| 1496 | virtual ~__owns_one_state(); |
| 1497 | }; |
| 1498 | |
| 1499 | template <class _CharT> |
| 1500 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1501 | { |
| 1502 | delete this->first(); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1505 | // __empty_state |
| 1506 | |
| 1507 | template <class _CharT> |
| 1508 | class __empty_state |
| 1509 | : public __owns_one_state<_CharT> |
| 1510 | { |
| 1511 | typedef __owns_one_state<_CharT> base; |
| 1512 | |
| 1513 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1514 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1515 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1516 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1517 | explicit __empty_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1518 | : base(__s) {} |
| 1519 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1520 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1521 | }; |
| 1522 | |
| 1523 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1524 | void |
| 1525 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1526 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1527 | __s.__do_ = __state::__accept_but_not_consume; |
| 1528 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | // __empty_non_own_state |
| 1532 | |
| 1533 | template <class _CharT> |
| 1534 | class __empty_non_own_state |
| 1535 | : public __has_one_state<_CharT> |
| 1536 | { |
| 1537 | typedef __has_one_state<_CharT> base; |
| 1538 | |
| 1539 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1540 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1541 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1542 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1543 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1544 | : base(__s) {} |
| 1545 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1546 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1547 | }; |
| 1548 | |
| 1549 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1550 | void |
| 1551 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1552 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1553 | __s.__do_ = __state::__accept_but_not_consume; |
| 1554 | __s.__node_ = this->first(); |
| 1555 | } |
| 1556 | |
| 1557 | // __repeat_one_loop |
| 1558 | |
| 1559 | template <class _CharT> |
| 1560 | class __repeat_one_loop |
| 1561 | : public __has_one_state<_CharT> |
| 1562 | { |
| 1563 | typedef __has_one_state<_CharT> base; |
| 1564 | |
| 1565 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1566 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1567 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1568 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1569 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1570 | : base(__s) {} |
| 1571 | |
| 1572 | virtual void __exec(__state&) const; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1573 | }; |
| 1574 | |
| 1575 | template <class _CharT> |
| 1576 | void |
| 1577 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1578 | { |
| 1579 | __s.__do_ = __state::__repeat; |
| 1580 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | // __owns_two_states |
| 1584 | |
| 1585 | template <class _CharT> |
| 1586 | class __owns_two_states |
| 1587 | : public __owns_one_state<_CharT> |
| 1588 | { |
| 1589 | typedef __owns_one_state<_CharT> base; |
| 1590 | |
| 1591 | base* __second_; |
| 1592 | |
| 1593 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1594 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1595 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1596 | : base(__s1), __second_(__s2) {} |
| 1597 | |
| 1598 | virtual ~__owns_two_states(); |
| 1599 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1600 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1601 | base* second() const {return __second_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1602 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1603 | base*& second() {return __second_;} |
| 1604 | }; |
| 1605 | |
| 1606 | template <class _CharT> |
| 1607 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1608 | { |
| 1609 | delete __second_; |
| 1610 | } |
| 1611 | |
| 1612 | // __loop |
| 1613 | |
| 1614 | template <class _CharT> |
| 1615 | class __loop |
| 1616 | : public __owns_two_states<_CharT> |
| 1617 | { |
| 1618 | typedef __owns_two_states<_CharT> base; |
| 1619 | |
| 1620 | size_t __min_; |
| 1621 | size_t __max_; |
| 1622 | unsigned __loop_id_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1623 | unsigned __mexp_begin_; |
| 1624 | unsigned __mexp_end_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1625 | bool __greedy_; |
| 1626 | |
| 1627 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1628 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1629 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1630 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1631 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1632 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1633 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1634 | bool __greedy = true, |
| 1635 | size_t __min = 0, |
| 1636 | size_t __max = numeric_limits<size_t>::max()) |
| 1637 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1638 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1639 | __greedy_(__greedy) {} |
| 1640 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1641 | virtual void __exec(__state& __s) const; |
| 1642 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1643 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1644 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1645 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1646 | void __init_repeat(__state& __s) const |
| 1647 | { |
| 1648 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1649 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1650 | { |
| 1651 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1652 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1653 | __s.__sub_matches_[__i].matched = false; |
| 1654 | } |
| 1655 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1656 | }; |
| 1657 | |
| 1658 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1659 | void |
| 1660 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1661 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1662 | if (__s.__do_ == __state::__repeat) |
| 1663 | { |
| 1664 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1665 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1666 | if (__do_repeat && __do_alt && |
| 1667 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1668 | __do_repeat = false; |
| 1669 | if (__do_repeat && __do_alt) |
| 1670 | __s.__do_ = __state::__split; |
| 1671 | else if (__do_repeat) |
| 1672 | { |
| 1673 | __s.__do_ = __state::__accept_but_not_consume; |
| 1674 | __s.__node_ = this->first(); |
| 1675 | __init_repeat(__s); |
| 1676 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1677 | else |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1678 | { |
| 1679 | __s.__do_ = __state::__accept_but_not_consume; |
| 1680 | __s.__node_ = this->second(); |
| 1681 | } |
| 1682 | } |
| 1683 | else |
| 1684 | { |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1685 | __s.__loop_data_[__loop_id_].first = 0; |
| 1686 | bool __do_repeat = 0 < __max_; |
| 1687 | bool __do_alt = 0 >= __min_; |
| 1688 | if (__do_repeat && __do_alt) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1689 | __s.__do_ = __state::__split; |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1690 | else if (__do_repeat) |
| 1691 | { |
| 1692 | __s.__do_ = __state::__accept_but_not_consume; |
| 1693 | __s.__node_ = this->first(); |
| 1694 | __init_repeat(__s); |
| 1695 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1696 | else |
| 1697 | { |
| 1698 | __s.__do_ = __state::__accept_but_not_consume; |
| 1699 | __s.__node_ = this->second(); |
| 1700 | } |
| 1701 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1702 | } |
| 1703 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1704 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1705 | void |
| 1706 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1707 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1708 | __s.__do_ = __state::__accept_but_not_consume; |
| 1709 | if (__greedy_ != __second) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1710 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1711 | __s.__node_ = this->first(); |
| 1712 | __init_repeat(__s); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1713 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1714 | else |
| 1715 | __s.__node_ = this->second(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1718 | // __alternate |
| 1719 | |
| 1720 | template <class _CharT> |
| 1721 | class __alternate |
| 1722 | : public __owns_two_states<_CharT> |
| 1723 | { |
| 1724 | typedef __owns_two_states<_CharT> base; |
| 1725 | |
| 1726 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1727 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1728 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1729 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1730 | explicit __alternate(__owns_one_state<_CharT>* __s1, |
| 1731 | __owns_one_state<_CharT>* __s2) |
| 1732 | : base(__s1, __s2) {} |
| 1733 | |
| 1734 | virtual void __exec(__state& __s) const; |
| 1735 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1736 | }; |
| 1737 | |
| 1738 | template <class _CharT> |
| 1739 | void |
| 1740 | __alternate<_CharT>::__exec(__state& __s) const |
| 1741 | { |
| 1742 | __s.__do_ = __state::__split; |
| 1743 | } |
| 1744 | |
| 1745 | template <class _CharT> |
| 1746 | void |
| 1747 | __alternate<_CharT>::__exec_split(bool __second, __state& __s) const |
| 1748 | { |
| 1749 | __s.__do_ = __state::__accept_but_not_consume; |
Howard Hinnant | cbf2f3f | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1750 | if (__second) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1751 | __s.__node_ = this->second(); |
Howard Hinnant | cbf2f3f | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1752 | else |
| 1753 | __s.__node_ = this->first(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1754 | } |
| 1755 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1756 | // __begin_marked_subexpression |
| 1757 | |
| 1758 | template <class _CharT> |
| 1759 | class __begin_marked_subexpression |
| 1760 | : public __owns_one_state<_CharT> |
| 1761 | { |
| 1762 | typedef __owns_one_state<_CharT> base; |
| 1763 | |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1764 | unsigned __mexp_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1765 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1766 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1767 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1768 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1769 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1770 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1771 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1772 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1773 | }; |
| 1774 | |
| 1775 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1776 | void |
| 1777 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1778 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1779 | __s.__do_ = __state::__accept_but_not_consume; |
| 1780 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1781 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | // __end_marked_subexpression |
| 1785 | |
| 1786 | template <class _CharT> |
| 1787 | class __end_marked_subexpression |
| 1788 | : public __owns_one_state<_CharT> |
| 1789 | { |
| 1790 | typedef __owns_one_state<_CharT> base; |
| 1791 | |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1792 | unsigned __mexp_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1793 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1794 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1795 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1796 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1797 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1798 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1799 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1800 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1801 | }; |
| 1802 | |
| 1803 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1804 | void |
| 1805 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1806 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1807 | __s.__do_ = __state::__accept_but_not_consume; |
| 1808 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1809 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1810 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1811 | } |
| 1812 | |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1813 | // __back_ref |
| 1814 | |
| 1815 | template <class _CharT> |
| 1816 | class __back_ref |
| 1817 | : public __owns_one_state<_CharT> |
| 1818 | { |
| 1819 | typedef __owns_one_state<_CharT> base; |
| 1820 | |
| 1821 | unsigned __mexp_; |
| 1822 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1823 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1824 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1825 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1826 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1827 | : base(__s), __mexp_(__mexp) {} |
| 1828 | |
| 1829 | virtual void __exec(__state&) const; |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1830 | }; |
| 1831 | |
| 1832 | template <class _CharT> |
| 1833 | void |
| 1834 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1835 | { |
Marshall Clow | 360e839 | 2015-08-24 15:57:09 +0000 | [diff] [blame] | 1836 | if (__mexp_ > __s.__sub_matches_.size()) |
| 1837 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1838 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1839 | if (__sm.matched) |
| 1840 | { |
| 1841 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1842 | if (__s.__last_ - __s.__current_ >= __len && |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1843 | _VSTD::equal(__sm.first, __sm.second, __s.__current_)) |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1844 | { |
| 1845 | __s.__do_ = __state::__accept_but_not_consume; |
| 1846 | __s.__current_ += __len; |
| 1847 | __s.__node_ = this->first(); |
| 1848 | } |
| 1849 | else |
| 1850 | { |
| 1851 | __s.__do_ = __state::__reject; |
| 1852 | __s.__node_ = nullptr; |
| 1853 | } |
| 1854 | } |
| 1855 | else |
| 1856 | { |
| 1857 | __s.__do_ = __state::__reject; |
| 1858 | __s.__node_ = nullptr; |
| 1859 | } |
| 1860 | } |
| 1861 | |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1862 | // __back_ref_icase |
| 1863 | |
| 1864 | template <class _CharT, class _Traits> |
| 1865 | class __back_ref_icase |
| 1866 | : public __owns_one_state<_CharT> |
| 1867 | { |
| 1868 | typedef __owns_one_state<_CharT> base; |
| 1869 | |
| 1870 | _Traits __traits_; |
| 1871 | unsigned __mexp_; |
| 1872 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1873 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1874 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1875 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1876 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1877 | __node<_CharT>* __s) |
| 1878 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1879 | |
| 1880 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1881 | }; |
| 1882 | |
| 1883 | template <class _CharT, class _Traits> |
| 1884 | void |
| 1885 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1886 | { |
| 1887 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1888 | if (__sm.matched) |
| 1889 | { |
| 1890 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1891 | if (__s.__last_ - __s.__current_ >= __len) |
| 1892 | { |
| 1893 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1894 | { |
| 1895 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1896 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1897 | goto __not_equal; |
| 1898 | } |
| 1899 | __s.__do_ = __state::__accept_but_not_consume; |
| 1900 | __s.__current_ += __len; |
| 1901 | __s.__node_ = this->first(); |
| 1902 | } |
| 1903 | else |
| 1904 | { |
| 1905 | __s.__do_ = __state::__reject; |
| 1906 | __s.__node_ = nullptr; |
| 1907 | } |
| 1908 | } |
| 1909 | else |
| 1910 | { |
| 1911 | __not_equal: |
| 1912 | __s.__do_ = __state::__reject; |
| 1913 | __s.__node_ = nullptr; |
| 1914 | } |
| 1915 | } |
| 1916 | |
| 1917 | // __back_ref_collate |
| 1918 | |
| 1919 | template <class _CharT, class _Traits> |
| 1920 | class __back_ref_collate |
| 1921 | : public __owns_one_state<_CharT> |
| 1922 | { |
| 1923 | typedef __owns_one_state<_CharT> base; |
| 1924 | |
| 1925 | _Traits __traits_; |
| 1926 | unsigned __mexp_; |
| 1927 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1928 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1929 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1930 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1931 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1932 | __node<_CharT>* __s) |
| 1933 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1934 | |
| 1935 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1936 | }; |
| 1937 | |
| 1938 | template <class _CharT, class _Traits> |
| 1939 | void |
| 1940 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1941 | { |
| 1942 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1943 | if (__sm.matched) |
| 1944 | { |
| 1945 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1946 | if (__s.__last_ - __s.__current_ >= __len) |
| 1947 | { |
| 1948 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1949 | { |
| 1950 | if (__traits_.translate(__sm.first[__i]) != |
| 1951 | __traits_.translate(__s.__current_[__i])) |
| 1952 | goto __not_equal; |
| 1953 | } |
| 1954 | __s.__do_ = __state::__accept_but_not_consume; |
| 1955 | __s.__current_ += __len; |
| 1956 | __s.__node_ = this->first(); |
| 1957 | } |
| 1958 | else |
| 1959 | { |
| 1960 | __s.__do_ = __state::__reject; |
| 1961 | __s.__node_ = nullptr; |
| 1962 | } |
| 1963 | } |
| 1964 | else |
| 1965 | { |
| 1966 | __not_equal: |
| 1967 | __s.__do_ = __state::__reject; |
| 1968 | __s.__node_ = nullptr; |
| 1969 | } |
| 1970 | } |
| 1971 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1972 | // __word_boundary |
| 1973 | |
| 1974 | template <class _CharT, class _Traits> |
| 1975 | class __word_boundary |
| 1976 | : public __owns_one_state<_CharT> |
| 1977 | { |
| 1978 | typedef __owns_one_state<_CharT> base; |
| 1979 | |
| 1980 | _Traits __traits_; |
| 1981 | bool __invert_; |
| 1982 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1983 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1984 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1985 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1986 | explicit __word_boundary(const _Traits& __traits, bool __invert, |
| 1987 | __node<_CharT>* __s) |
| 1988 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 1989 | |
| 1990 | virtual void __exec(__state&) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1991 | }; |
| 1992 | |
| 1993 | template <class _CharT, class _Traits> |
| 1994 | void |
| 1995 | __word_boundary<_CharT, _Traits>::__exec(__state& __s) const |
| 1996 | { |
| 1997 | bool __is_word_b = false; |
| 1998 | if (__s.__first_ != __s.__last_) |
| 1999 | { |
| 2000 | if (__s.__current_ == __s.__last_) |
| 2001 | { |
| 2002 | if (!(__s.__flags_ & regex_constants::match_not_eow)) |
| 2003 | { |
| 2004 | _CharT __c = __s.__current_[-1]; |
| 2005 | __is_word_b = __c == '_' || |
| 2006 | __traits_.isctype(__c, ctype_base::alnum); |
| 2007 | } |
| 2008 | } |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 2009 | else if (__s.__current_ == __s.__first_ && |
| 2010 | !(__s.__flags_ & regex_constants::match_prev_avail)) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2011 | { |
| 2012 | if (!(__s.__flags_ & regex_constants::match_not_bow)) |
| 2013 | { |
| 2014 | _CharT __c = *__s.__current_; |
| 2015 | __is_word_b = __c == '_' || |
| 2016 | __traits_.isctype(__c, ctype_base::alnum); |
| 2017 | } |
| 2018 | } |
| 2019 | else |
| 2020 | { |
| 2021 | _CharT __c1 = __s.__current_[-1]; |
| 2022 | _CharT __c2 = *__s.__current_; |
| 2023 | bool __is_c1_b = __c1 == '_' || |
| 2024 | __traits_.isctype(__c1, ctype_base::alnum); |
| 2025 | bool __is_c2_b = __c2 == '_' || |
| 2026 | __traits_.isctype(__c2, ctype_base::alnum); |
| 2027 | __is_word_b = __is_c1_b != __is_c2_b; |
| 2028 | } |
| 2029 | } |
| 2030 | if (__is_word_b != __invert_) |
| 2031 | { |
| 2032 | __s.__do_ = __state::__accept_but_not_consume; |
| 2033 | __s.__node_ = this->first(); |
| 2034 | } |
| 2035 | else |
| 2036 | { |
| 2037 | __s.__do_ = __state::__reject; |
| 2038 | __s.__node_ = nullptr; |
| 2039 | } |
| 2040 | } |
| 2041 | |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2042 | // __l_anchor |
| 2043 | |
| 2044 | template <class _CharT> |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2045 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 2046 | bool __is_eol(_CharT c) |
| 2047 | { |
| 2048 | return c == '\r' || c == '\n'; |
| 2049 | } |
| 2050 | |
| 2051 | template <class _CharT> |
| 2052 | class __l_anchor_multiline |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2053 | : public __owns_one_state<_CharT> |
| 2054 | { |
| 2055 | typedef __owns_one_state<_CharT> base; |
| 2056 | |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2057 | bool __multiline_; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2058 | |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2059 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2060 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2061 | |
| 2062 | _LIBCPP_INLINE_VISIBILITY |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2063 | __l_anchor_multiline(bool __multiline, __node<_CharT>* __s) |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2064 | : base(__s), __multiline_(__multiline) {} |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2065 | |
| 2066 | virtual void __exec(__state&) const; |
| 2067 | }; |
| 2068 | |
| 2069 | template <class _CharT> |
| 2070 | void |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2071 | __l_anchor_multiline<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2072 | { |
Marshall Clow | 5440439 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 2073 | if (__s.__at_first_ && __s.__current_ == __s.__first_ && |
| 2074 | !(__s.__flags_ & regex_constants::match_not_bol)) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2075 | { |
| 2076 | __s.__do_ = __state::__accept_but_not_consume; |
| 2077 | __s.__node_ = this->first(); |
| 2078 | } |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2079 | else if (__multiline_ && |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2080 | !__s.__at_first_ && |
| 2081 | __is_eol(*_VSTD::prev(__s.__current_))) |
| 2082 | { |
| 2083 | __s.__do_ = __state::__accept_but_not_consume; |
| 2084 | __s.__node_ = this->first(); |
| 2085 | } |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2086 | else |
| 2087 | { |
| 2088 | __s.__do_ = __state::__reject; |
| 2089 | __s.__node_ = nullptr; |
| 2090 | } |
| 2091 | } |
| 2092 | |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2093 | // __r_anchor |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2094 | |
| 2095 | template <class _CharT> |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2096 | class __r_anchor_multiline |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2097 | : public __owns_one_state<_CharT> |
| 2098 | { |
| 2099 | typedef __owns_one_state<_CharT> base; |
| 2100 | |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2101 | bool __multiline_; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2102 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2103 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2104 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2105 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2106 | _LIBCPP_INLINE_VISIBILITY |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2107 | __r_anchor_multiline(bool __multiline, __node<_CharT>* __s) |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2108 | : base(__s), __multiline_(__multiline) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2109 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2110 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2111 | }; |
| 2112 | |
| 2113 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2114 | void |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2115 | __r_anchor_multiline<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2116 | { |
Marshall Clow | 5440439 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 2117 | if (__s.__current_ == __s.__last_ && |
| 2118 | !(__s.__flags_ & regex_constants::match_not_eol)) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2119 | { |
| 2120 | __s.__do_ = __state::__accept_but_not_consume; |
| 2121 | __s.__node_ = this->first(); |
| 2122 | } |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2123 | else if (__multiline_ && __is_eol(*__s.__current_)) |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2124 | { |
| 2125 | __s.__do_ = __state::__accept_but_not_consume; |
| 2126 | __s.__node_ = this->first(); |
| 2127 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2128 | else |
| 2129 | { |
| 2130 | __s.__do_ = __state::__reject; |
| 2131 | __s.__node_ = nullptr; |
| 2132 | } |
| 2133 | } |
| 2134 | |
| 2135 | // __match_any |
| 2136 | |
| 2137 | template <class _CharT> |
| 2138 | class __match_any |
| 2139 | : public __owns_one_state<_CharT> |
| 2140 | { |
| 2141 | typedef __owns_one_state<_CharT> base; |
| 2142 | |
| 2143 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2144 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2145 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2146 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2147 | __match_any(__node<_CharT>* __s) |
| 2148 | : base(__s) {} |
| 2149 | |
| 2150 | virtual void __exec(__state&) const; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2151 | }; |
| 2152 | |
| 2153 | template <class _CharT> |
| 2154 | void |
| 2155 | __match_any<_CharT>::__exec(__state& __s) const |
| 2156 | { |
| 2157 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 2158 | { |
| 2159 | __s.__do_ = __state::__accept_and_consume; |
| 2160 | ++__s.__current_; |
| 2161 | __s.__node_ = this->first(); |
| 2162 | } |
| 2163 | else |
| 2164 | { |
| 2165 | __s.__do_ = __state::__reject; |
| 2166 | __s.__node_ = nullptr; |
| 2167 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2168 | } |
| 2169 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2170 | // __match_any_but_newline |
| 2171 | |
| 2172 | template <class _CharT> |
| 2173 | class __match_any_but_newline |
| 2174 | : public __owns_one_state<_CharT> |
| 2175 | { |
| 2176 | typedef __owns_one_state<_CharT> base; |
| 2177 | |
| 2178 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2179 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2180 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2181 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2182 | __match_any_but_newline(__node<_CharT>* __s) |
| 2183 | : base(__s) {} |
| 2184 | |
| 2185 | virtual void __exec(__state&) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2186 | }; |
| 2187 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2188 | 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] | 2189 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2190 | 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] | 2191 | #endif |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2192 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2193 | // __match_char |
| 2194 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2195 | template <class _CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2196 | class __match_char |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2197 | : public __owns_one_state<_CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2198 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2199 | typedef __owns_one_state<_CharT> base; |
| 2200 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2201 | _CharT __c_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2202 | |
| 2203 | __match_char(const __match_char&); |
| 2204 | __match_char& operator=(const __match_char&); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2205 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2206 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2207 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2208 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2209 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2210 | : base(__s), __c_(__c) {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2211 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2212 | virtual void __exec(__state&) const; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2213 | }; |
| 2214 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2215 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2216 | void |
| 2217 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2218 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2219 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2220 | { |
| 2221 | __s.__do_ = __state::__accept_and_consume; |
| 2222 | ++__s.__current_; |
| 2223 | __s.__node_ = this->first(); |
| 2224 | } |
| 2225 | else |
| 2226 | { |
| 2227 | __s.__do_ = __state::__reject; |
| 2228 | __s.__node_ = nullptr; |
| 2229 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2230 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2231 | |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2232 | // __match_char_icase |
| 2233 | |
| 2234 | template <class _CharT, class _Traits> |
| 2235 | class __match_char_icase |
| 2236 | : public __owns_one_state<_CharT> |
| 2237 | { |
| 2238 | typedef __owns_one_state<_CharT> base; |
| 2239 | |
| 2240 | _Traits __traits_; |
| 2241 | _CharT __c_; |
| 2242 | |
| 2243 | __match_char_icase(const __match_char_icase&); |
| 2244 | __match_char_icase& operator=(const __match_char_icase&); |
| 2245 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2246 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2247 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2248 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2249 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2250 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2251 | |
| 2252 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2253 | }; |
| 2254 | |
| 2255 | template <class _CharT, class _Traits> |
| 2256 | void |
| 2257 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2258 | { |
| 2259 | if (__s.__current_ != __s.__last_ && |
| 2260 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2261 | { |
| 2262 | __s.__do_ = __state::__accept_and_consume; |
| 2263 | ++__s.__current_; |
| 2264 | __s.__node_ = this->first(); |
| 2265 | } |
| 2266 | else |
| 2267 | { |
| 2268 | __s.__do_ = __state::__reject; |
| 2269 | __s.__node_ = nullptr; |
| 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | // __match_char_collate |
| 2274 | |
| 2275 | template <class _CharT, class _Traits> |
| 2276 | class __match_char_collate |
| 2277 | : public __owns_one_state<_CharT> |
| 2278 | { |
| 2279 | typedef __owns_one_state<_CharT> base; |
| 2280 | |
| 2281 | _Traits __traits_; |
| 2282 | _CharT __c_; |
| 2283 | |
| 2284 | __match_char_collate(const __match_char_collate&); |
| 2285 | __match_char_collate& operator=(const __match_char_collate&); |
| 2286 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2287 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2288 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2289 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2290 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2291 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2292 | |
| 2293 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2294 | }; |
| 2295 | |
| 2296 | template <class _CharT, class _Traits> |
| 2297 | void |
| 2298 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2299 | { |
| 2300 | if (__s.__current_ != __s.__last_ && |
| 2301 | __traits_.translate(*__s.__current_) == __c_) |
| 2302 | { |
| 2303 | __s.__do_ = __state::__accept_and_consume; |
| 2304 | ++__s.__current_; |
| 2305 | __s.__node_ = this->first(); |
| 2306 | } |
| 2307 | else |
| 2308 | { |
| 2309 | __s.__do_ = __state::__reject; |
| 2310 | __s.__node_ = nullptr; |
| 2311 | } |
| 2312 | } |
| 2313 | |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2314 | // __bracket_expression |
| 2315 | |
| 2316 | template <class _CharT, class _Traits> |
| 2317 | class __bracket_expression |
| 2318 | : public __owns_one_state<_CharT> |
| 2319 | { |
| 2320 | typedef __owns_one_state<_CharT> base; |
| 2321 | typedef typename _Traits::string_type string_type; |
| 2322 | |
| 2323 | _Traits __traits_; |
| 2324 | vector<_CharT> __chars_; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2325 | vector<_CharT> __neg_chars_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2326 | vector<pair<string_type, string_type> > __ranges_; |
| 2327 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2328 | vector<string_type> __equivalences_; |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2329 | typename regex_traits<_CharT>::char_class_type __mask_; |
| 2330 | typename regex_traits<_CharT>::char_class_type __neg_mask_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2331 | bool __negate_; |
| 2332 | bool __icase_; |
| 2333 | bool __collate_; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2334 | bool __might_have_digraph_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2335 | |
| 2336 | __bracket_expression(const __bracket_expression&); |
| 2337 | __bracket_expression& operator=(const __bracket_expression&); |
| 2338 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2339 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2340 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2341 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2342 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2343 | bool __negate, bool __icase, bool __collate) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2344 | : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), |
| 2345 | __negate_(__negate), __icase_(__icase), __collate_(__collate), |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2346 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2347 | |
| 2348 | virtual void __exec(__state&) const; |
| 2349 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2350 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2351 | bool __negated() const {return __negate_;} |
| 2352 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2353 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2354 | void __add_char(_CharT __c) |
| 2355 | { |
| 2356 | if (__icase_) |
| 2357 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2358 | else if (__collate_) |
| 2359 | __chars_.push_back(__traits_.translate(__c)); |
| 2360 | else |
| 2361 | __chars_.push_back(__c); |
| 2362 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2363 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2364 | void __add_neg_char(_CharT __c) |
| 2365 | { |
| 2366 | if (__icase_) |
| 2367 | __neg_chars_.push_back(__traits_.translate_nocase(__c)); |
| 2368 | else if (__collate_) |
| 2369 | __neg_chars_.push_back(__traits_.translate(__c)); |
| 2370 | else |
| 2371 | __neg_chars_.push_back(__c); |
| 2372 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2373 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2374 | void __add_range(string_type __b, string_type __e) |
| 2375 | { |
| 2376 | if (__collate_) |
| 2377 | { |
| 2378 | if (__icase_) |
| 2379 | { |
| 2380 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2381 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2382 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2383 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2384 | } |
| 2385 | else |
| 2386 | { |
| 2387 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2388 | __b[__i] = __traits_.translate(__b[__i]); |
| 2389 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2390 | __e[__i] = __traits_.translate(__e[__i]); |
| 2391 | } |
| 2392 | __ranges_.push_back(make_pair( |
| 2393 | __traits_.transform(__b.begin(), __b.end()), |
| 2394 | __traits_.transform(__e.begin(), __e.end()))); |
| 2395 | } |
| 2396 | else |
| 2397 | { |
| 2398 | if (__b.size() != 1 || __e.size() != 1) |
Marshall Clow | a521211 | 2019-05-28 22:42:32 +0000 | [diff] [blame] | 2399 | __throw_regex_error<regex_constants::error_range>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2400 | if (__icase_) |
| 2401 | { |
| 2402 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2403 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2404 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2405 | __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e))); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2406 | } |
| 2407 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2408 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2409 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2410 | { |
| 2411 | if (__icase_) |
| 2412 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2413 | __traits_.translate_nocase(__c2))); |
| 2414 | else if (__collate_) |
| 2415 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2416 | __traits_.translate(__c2))); |
| 2417 | else |
| 2418 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2419 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2420 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2421 | void __add_equivalence(const string_type& __s) |
| 2422 | {__equivalences_.push_back(__s);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2423 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2424 | void __add_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2425 | {__mask_ |= __mask;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2426 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2427 | void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2428 | {__neg_mask_ |= __mask;} |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2429 | }; |
| 2430 | |
| 2431 | template <class _CharT, class _Traits> |
| 2432 | void |
| 2433 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2434 | { |
| 2435 | bool __found = false; |
| 2436 | unsigned __consumed = 0; |
| 2437 | if (__s.__current_ != __s.__last_) |
| 2438 | { |
| 2439 | ++__consumed; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2440 | if (__might_have_digraph_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2441 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2442 | const _CharT* __next = _VSTD::next(__s.__current_); |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2443 | if (__next != __s.__last_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2444 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2445 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2446 | if (__icase_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2447 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2448 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2449 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2450 | } |
| 2451 | else if (__collate_) |
| 2452 | { |
| 2453 | __ch2.first = __traits_.translate(__ch2.first); |
| 2454 | __ch2.second = __traits_.translate(__ch2.second); |
| 2455 | } |
| 2456 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2457 | { |
| 2458 | // __ch2 is a digraph in this locale |
| 2459 | ++__consumed; |
| 2460 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2461 | { |
| 2462 | if (__ch2 == __digraphs_[__i]) |
| 2463 | { |
| 2464 | __found = true; |
| 2465 | goto __exit; |
| 2466 | } |
| 2467 | } |
| 2468 | if (__collate_ && !__ranges_.empty()) |
| 2469 | { |
| 2470 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2471 | &__ch2.first + 2); |
| 2472 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2473 | { |
| 2474 | if (__ranges_[__i].first <= __s2 && |
| 2475 | __s2 <= __ranges_[__i].second) |
| 2476 | { |
| 2477 | __found = true; |
| 2478 | goto __exit; |
| 2479 | } |
| 2480 | } |
| 2481 | } |
| 2482 | if (!__equivalences_.empty()) |
| 2483 | { |
| 2484 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2485 | &__ch2.first + 2); |
| 2486 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2487 | { |
| 2488 | if (__s2 == __equivalences_[__i]) |
| 2489 | { |
| 2490 | __found = true; |
| 2491 | goto __exit; |
| 2492 | } |
| 2493 | } |
| 2494 | } |
| 2495 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2496 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2497 | { |
| 2498 | __found = true; |
| 2499 | goto __exit; |
| 2500 | } |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2501 | if (!__traits_.isctype(__ch2.first, __neg_mask_) && |
| 2502 | !__traits_.isctype(__ch2.second, __neg_mask_)) |
| 2503 | { |
| 2504 | __found = true; |
| 2505 | goto __exit; |
| 2506 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2507 | goto __exit; |
| 2508 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2509 | } |
| 2510 | } |
| 2511 | // test *__s.__current_ as not a digraph |
| 2512 | _CharT __ch = *__s.__current_; |
| 2513 | if (__icase_) |
| 2514 | __ch = __traits_.translate_nocase(__ch); |
| 2515 | else if (__collate_) |
| 2516 | __ch = __traits_.translate(__ch); |
| 2517 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2518 | { |
| 2519 | if (__ch == __chars_[__i]) |
| 2520 | { |
| 2521 | __found = true; |
| 2522 | goto __exit; |
| 2523 | } |
| 2524 | } |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2525 | // When there's at least one of __neg_chars_ and __neg_mask_, the set |
| 2526 | // of "__found" chars is |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2527 | // union(complement(union(__neg_chars_, __neg_mask_)), |
| 2528 | // other cases...) |
| 2529 | // |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2530 | // It doesn't make sense to check this when there are no __neg_chars_ |
| 2531 | // and no __neg_mask_. |
| 2532 | if (!(__neg_mask_ == 0 && __neg_chars_.empty())) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2533 | { |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2534 | const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_); |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2535 | const bool __in_neg_chars = |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 2536 | _VSTD::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2537 | __neg_chars_.end(); |
| 2538 | if (!(__in_neg_mask || __in_neg_chars)) |
| 2539 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2540 | __found = true; |
| 2541 | goto __exit; |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2542 | } |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2543 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2544 | if (!__ranges_.empty()) |
| 2545 | { |
| 2546 | string_type __s2 = __collate_ ? |
| 2547 | __traits_.transform(&__ch, &__ch + 1) : |
| 2548 | string_type(1, __ch); |
| 2549 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2550 | { |
| 2551 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2552 | { |
| 2553 | __found = true; |
| 2554 | goto __exit; |
| 2555 | } |
| 2556 | } |
| 2557 | } |
| 2558 | if (!__equivalences_.empty()) |
| 2559 | { |
| 2560 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2561 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2562 | { |
| 2563 | if (__s2 == __equivalences_[__i]) |
| 2564 | { |
| 2565 | __found = true; |
| 2566 | goto __exit; |
| 2567 | } |
| 2568 | } |
| 2569 | } |
| 2570 | if (__traits_.isctype(__ch, __mask_)) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2571 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2572 | __found = true; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2573 | goto __exit; |
| 2574 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2575 | } |
| 2576 | else |
| 2577 | __found = __negate_; // force reject |
| 2578 | __exit: |
| 2579 | if (__found != __negate_) |
| 2580 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2581 | __s.__do_ = __state::__accept_and_consume; |
| 2582 | __s.__current_ += __consumed; |
| 2583 | __s.__node_ = this->first(); |
| 2584 | } |
| 2585 | else |
| 2586 | { |
| 2587 | __s.__do_ = __state::__reject; |
| 2588 | __s.__node_ = nullptr; |
| 2589 | } |
| 2590 | } |
| 2591 | |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 2592 | template <class _CharT, class _Traits> class __lookahead; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2593 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2594 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2595 | class _LIBCPP_TEMPLATE_VIS basic_regex; |
| 2596 | |
| 2597 | typedef basic_regex<char> regex; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2598 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2599 | typedef basic_regex<wchar_t> wregex; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2600 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2601 | |
| 2602 | template <class _CharT, class _Traits> |
| 2603 | class |
| 2604 | _LIBCPP_TEMPLATE_VIS |
| 2605 | _LIBCPP_PREFERRED_NAME(regex) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2606 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2607 | basic_regex |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2608 | { |
| 2609 | public: |
| 2610 | // types: |
| 2611 | typedef _CharT value_type; |
Hubert Tong | 1f1ae9c | 2016-08-02 21:34:48 +0000 | [diff] [blame] | 2612 | typedef _Traits traits_type; |
| 2613 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2614 | typedef regex_constants::syntax_option_type flag_type; |
| 2615 | typedef typename _Traits::locale_type locale_type; |
| 2616 | |
| 2617 | private: |
| 2618 | _Traits __traits_; |
| 2619 | flag_type __flags_; |
| 2620 | unsigned __marked_count_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2621 | unsigned __loop_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2622 | int __open_count_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2623 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2624 | __owns_one_state<_CharT>* __end_; |
| 2625 | |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2626 | typedef _VSTD::__state<_CharT> __state; |
| 2627 | typedef _VSTD::__node<_CharT> __node; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2628 | |
| 2629 | public: |
| 2630 | // constants: |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2631 | static const regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2632 | static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2633 | static const regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2634 | static const regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2635 | static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2636 | static const regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2637 | static const regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2638 | static const regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2639 | static const regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2640 | static const regex_constants::syntax_option_type egrep = regex_constants::egrep; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2641 | static const regex_constants::syntax_option_type multiline = regex_constants::multiline; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2642 | |
| 2643 | // construct/copy/destroy: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2644 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2645 | basic_regex() |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2646 | : __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] | 2647 | __end_(nullptr) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2648 | {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2649 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2650 | 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] | 2651 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2652 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2653 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2654 | __init(__p, __p + __traits_.length(__p)); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2655 | } |
| 2656 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2657 | _LIBCPP_INLINE_VISIBILITY |
Hubert Tong | 1966286 | 2016-08-07 22:26:04 +0000 | [diff] [blame] | 2658 | 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] | 2659 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2660 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2661 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2662 | __init(__p, __p + __len); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2663 | } |
| 2664 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2665 | // basic_regex(const basic_regex&) = default; |
| 2666 | // basic_regex(basic_regex&&) = default; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2667 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2668 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2669 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2670 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2671 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2672 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2673 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2674 | __init(__p.begin(), __p.end()); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2675 | } |
| 2676 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2677 | template <class _ForwardIterator> |
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 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 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(__first, __last); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2685 | } |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2686 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2687 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2688 | basic_regex(initializer_list<value_type> __il, |
| 2689 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2690 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2691 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2692 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2693 | __init(__il.begin(), __il.end()); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2694 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2695 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2696 | |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2697 | // ~basic_regex() = default; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2698 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2699 | // basic_regex& operator=(const basic_regex&) = default; |
| 2700 | // basic_regex& operator=(basic_regex&&) = default; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2701 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2702 | basic_regex& operator=(const value_type* __p) |
| 2703 | {return assign(__p);} |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2704 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2705 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2706 | basic_regex& operator=(initializer_list<value_type> __il) |
| 2707 | {return assign(__il);} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2708 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2709 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2710 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2711 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) |
| 2712 | {return assign(__p);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2713 | |
| 2714 | // assign: |
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& assign(const basic_regex& __that) |
| 2717 | {return *this = __that;} |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2718 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2719 | _LIBCPP_INLINE_VISIBILITY |
| 2720 | basic_regex& assign(basic_regex&& __that) _NOEXCEPT |
| 2721 | {return *this = _VSTD::move(__that);} |
| 2722 | #endif |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2723 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2724 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
| 2725 | {return assign(__p, __p + __traits_.length(__p), __f);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2726 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | d402893 | 2019-09-25 16:40:30 +0000 | [diff] [blame] | 2727 | 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] | 2728 | {return assign(__p, __p + __len, __f);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2729 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2730 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2731 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2732 | flag_type __f = regex_constants::ECMAScript) |
| 2733 | {return assign(__s.begin(), __s.end(), __f);} |
| 2734 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2735 | template <class _InputIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2736 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2737 | typename enable_if |
| 2738 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2739 | __is_cpp17_input_iterator <_InputIterator>::value && |
| 2740 | !__is_cpp17_forward_iterator<_InputIterator>::value, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2741 | basic_regex& |
| 2742 | >::type |
| 2743 | assign(_InputIterator __first, _InputIterator __last, |
| 2744 | flag_type __f = regex_constants::ECMAScript) |
| 2745 | { |
| 2746 | basic_string<_CharT> __t(__first, __last); |
| 2747 | return assign(__t.begin(), __t.end(), __f); |
| 2748 | } |
| 2749 | |
| 2750 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2751 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2752 | void __member_init(flag_type __f) |
| 2753 | { |
| 2754 | __flags_ = __f; |
| 2755 | __marked_count_ = 0; |
| 2756 | __loop_count_ = 0; |
| 2757 | __open_count_ = 0; |
| 2758 | __end_ = nullptr; |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2759 | } |
| 2760 | public: |
| 2761 | |
| 2762 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2763 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2764 | typename enable_if |
| 2765 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2766 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2767 | basic_regex& |
| 2768 | >::type |
| 2769 | assign(_ForwardIterator __first, _ForwardIterator __last, |
| 2770 | flag_type __f = regex_constants::ECMAScript) |
| 2771 | { |
Marshall Clow | ce03dc1 | 2015-01-13 16:49:52 +0000 | [diff] [blame] | 2772 | return assign(basic_regex(__first, __last, __f)); |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2775 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2776 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2777 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2778 | basic_regex& assign(initializer_list<value_type> __il, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2779 | flag_type __f = regex_constants::ECMAScript) |
| 2780 | {return assign(__il.begin(), __il.end(), __f);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2781 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2782 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2783 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2784 | // const operations: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2785 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2786 | unsigned mark_count() const {return __marked_count_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2787 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2788 | flag_type flags() const {return __flags_;} |
| 2789 | |
| 2790 | // locale: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2791 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2792 | locale_type imbue(locale_type __loc) |
| 2793 | { |
| 2794 | __member_init(ECMAScript); |
| 2795 | __start_.reset(); |
| 2796 | return __traits_.imbue(__loc); |
| 2797 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2798 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2799 | locale_type getloc() const {return __traits_.getloc();} |
| 2800 | |
| 2801 | // swap: |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2802 | void swap(basic_regex& __r); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2803 | |
| 2804 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2805 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2806 | unsigned __loop_count() const {return __loop_count_;} |
| 2807 | |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2808 | _LIBCPP_INLINE_VISIBILITY |
| 2809 | bool __use_multiline() const |
| 2810 | { |
| 2811 | return __get_grammar(__flags_) == ECMAScript && (__flags_ & multiline); |
| 2812 | } |
| 2813 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2814 | template <class _ForwardIterator> |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2815 | void |
| 2816 | __init(_ForwardIterator __first, _ForwardIterator __last); |
| 2817 | template <class _ForwardIterator> |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2818 | _ForwardIterator |
| 2819 | __parse(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2820 | template <class _ForwardIterator> |
| 2821 | _ForwardIterator |
| 2822 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2823 | template <class _ForwardIterator> |
| 2824 | _ForwardIterator |
| 2825 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2826 | template <class _ForwardIterator> |
| 2827 | _ForwardIterator |
| 2828 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2829 | template <class _ForwardIterator> |
| 2830 | _ForwardIterator |
| 2831 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2832 | template <class _ForwardIterator> |
| 2833 | _ForwardIterator |
| 2834 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2835 | template <class _ForwardIterator> |
| 2836 | _ForwardIterator |
| 2837 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2838 | template <class _ForwardIterator> |
| 2839 | _ForwardIterator |
| 2840 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2841 | template <class _ForwardIterator> |
| 2842 | _ForwardIterator |
| 2843 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2844 | template <class _ForwardIterator> |
| 2845 | _ForwardIterator |
| 2846 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2847 | template <class _ForwardIterator> |
| 2848 | _ForwardIterator |
| 2849 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2850 | template <class _ForwardIterator> |
| 2851 | _ForwardIterator |
| 2852 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2853 | template <class _ForwardIterator> |
| 2854 | _ForwardIterator |
| 2855 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2856 | template <class _ForwardIterator> |
| 2857 | _ForwardIterator |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2858 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2859 | __owns_one_state<_CharT>* __s, |
| 2860 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2861 | template <class _ForwardIterator> |
| 2862 | _ForwardIterator |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2863 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2864 | __owns_one_state<_CharT>* __s, |
| 2865 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2866 | template <class _ForwardIterator> |
| 2867 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2868 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2869 | template <class _ForwardIterator> |
| 2870 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2871 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2872 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2873 | template <class _ForwardIterator> |
| 2874 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2875 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2876 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2877 | template <class _ForwardIterator> |
| 2878 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2879 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2880 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2881 | template <class _ForwardIterator> |
| 2882 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2883 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2884 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2885 | template <class _ForwardIterator> |
| 2886 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2887 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2888 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2889 | template <class _ForwardIterator> |
| 2890 | _ForwardIterator |
| 2891 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2892 | template <class _ForwardIterator> |
| 2893 | _ForwardIterator |
| 2894 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2895 | template <class _ForwardIterator> |
| 2896 | _ForwardIterator |
| 2897 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2898 | template <class _ForwardIterator> |
| 2899 | _ForwardIterator |
| 2900 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2901 | template <class _ForwardIterator> |
| 2902 | _ForwardIterator |
| 2903 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2904 | template <class _ForwardIterator> |
| 2905 | _ForwardIterator |
| 2906 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2907 | template <class _ForwardIterator> |
| 2908 | _ForwardIterator |
| 2909 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2910 | template <class _ForwardIterator> |
| 2911 | _ForwardIterator |
| 2912 | __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2913 | template <class _ForwardIterator> |
| 2914 | _ForwardIterator |
| 2915 | __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); |
| 2916 | template <class _ForwardIterator> |
| 2917 | _ForwardIterator |
| 2918 | __parse_term(_ForwardIterator __first, _ForwardIterator __last); |
| 2919 | template <class _ForwardIterator> |
| 2920 | _ForwardIterator |
| 2921 | __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); |
| 2922 | template <class _ForwardIterator> |
| 2923 | _ForwardIterator |
| 2924 | __parse_atom(_ForwardIterator __first, _ForwardIterator __last); |
| 2925 | template <class _ForwardIterator> |
| 2926 | _ForwardIterator |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2927 | __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2928 | template <class _ForwardIterator> |
| 2929 | _ForwardIterator |
| 2930 | __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2931 | template <class _ForwardIterator> |
| 2932 | _ForwardIterator |
| 2933 | __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2934 | template <class _ForwardIterator> |
| 2935 | _ForwardIterator |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2936 | __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2937 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2938 | template <class _ForwardIterator> |
| 2939 | _ForwardIterator |
| 2940 | __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 2941 | template <class _ForwardIterator> |
| 2942 | _ForwardIterator |
| 2943 | __parse_grep(_ForwardIterator __first, _ForwardIterator __last); |
| 2944 | template <class _ForwardIterator> |
| 2945 | _ForwardIterator |
| 2946 | __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2947 | template <class _ForwardIterator> |
| 2948 | _ForwardIterator |
| 2949 | __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2950 | basic_string<_CharT>& __str, |
| 2951 | __bracket_expression<_CharT, _Traits>* __ml); |
| 2952 | template <class _ForwardIterator> |
| 2953 | _ForwardIterator |
| 2954 | __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2955 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2956 | |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 2957 | bool __test_back_ref(_CharT c); |
| 2958 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2959 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2960 | void __push_l_anchor(); |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2961 | void __push_r_anchor(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2962 | void __push_match_any(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2963 | void __push_match_any_but_newline(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2964 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2965 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2966 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2967 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2968 | __mexp_begin, __mexp_end);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2969 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2970 | void __push_nongreedy_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, false);} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2974 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2975 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2976 | bool __greedy = true); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2977 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2978 | void __push_char(value_type __c); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 2979 | void __push_back_ref(int __i); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2980 | void __push_alternation(__owns_one_state<_CharT>* __sa, |
| 2981 | __owns_one_state<_CharT>* __sb); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2982 | void __push_begin_marked_subexpression(); |
| 2983 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2984 | void __push_empty(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2985 | void __push_word_boundary(bool); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2986 | void __push_lookahead(const basic_regex&, bool, unsigned); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2987 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2988 | template <class _Allocator> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2989 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2990 | __search(const _CharT* __first, const _CharT* __last, |
| 2991 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2992 | regex_constants::match_flag_type __flags) const; |
| 2993 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2994 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2995 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2996 | __match_at_start(const _CharT* __first, const _CharT* __last, |
| 2997 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2998 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2999 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3000 | bool |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3001 | __match_at_start_ecma(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 | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3004 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3005 | bool |
| 3006 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 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 |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3011 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 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 | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3014 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3015 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3016 | friend |
| 3017 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3018 | 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] | 3019 | regex_constants::match_flag_type); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3020 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3021 | template <class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3022 | friend |
| 3023 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3024 | regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&, |
| 3025 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3026 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3027 | template <class _Bp, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3028 | friend |
| 3029 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3030 | regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3031 | regex_constants::match_flag_type); |
| 3032 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3033 | template <class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3034 | friend |
| 3035 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3036 | regex_search(const _Cp*, const _Cp*, |
| 3037 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3038 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3039 | template <class _Cp, class _Ap, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3040 | friend |
| 3041 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3042 | 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] | 3043 | regex_constants::match_flag_type); |
| 3044 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3045 | template <class _ST, class _SA, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3046 | friend |
| 3047 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3048 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 3049 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3050 | regex_constants::match_flag_type __flags); |
| 3051 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3052 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3053 | friend |
| 3054 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3055 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 3056 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 3057 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3058 | regex_constants::match_flag_type __flags); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3059 | |
Howard Hinnant | 4018c48 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 3060 | template <class _Iter, class _Ap, class _Cp, class _Tp> |
| 3061 | friend |
| 3062 | bool |
| 3063 | regex_search(__wrap_iter<_Iter> __first, |
| 3064 | __wrap_iter<_Iter> __last, |
| 3065 | match_results<__wrap_iter<_Iter>, _Ap>& __m, |
| 3066 | const basic_regex<_Cp, _Tp>& __e, |
| 3067 | regex_constants::match_flag_type __flags); |
| 3068 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3069 | template <class, class> friend class __lookahead; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3070 | }; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3071 | |
Louis Dionne | d59f8a5 | 2021-08-17 11:59:07 -0400 | [diff] [blame] | 3072 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | 2dce1f4 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 3073 | template <class _ForwardIterator, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3074 | 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] | 3075 | > |
| 3076 | basic_regex(_ForwardIterator, _ForwardIterator, |
| 3077 | regex_constants::syntax_option_type = regex_constants::ECMAScript) |
| 3078 | -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>; |
| 3079 | #endif |
| 3080 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3081 | template <class _CharT, class _Traits> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 3082 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase; |
| 3083 | template <class _CharT, class _Traits> |
| 3084 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs; |
| 3085 | template <class _CharT, class _Traits> |
| 3086 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize; |
| 3087 | template <class _CharT, class _Traits> |
| 3088 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate; |
| 3089 | template <class _CharT, class _Traits> |
| 3090 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript; |
| 3091 | template <class _CharT, class _Traits> |
| 3092 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic; |
| 3093 | template <class _CharT, class _Traits> |
| 3094 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended; |
| 3095 | template <class _CharT, class _Traits> |
| 3096 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk; |
| 3097 | template <class _CharT, class _Traits> |
| 3098 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep; |
| 3099 | template <class _CharT, class _Traits> |
| 3100 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep; |
| 3101 | |
| 3102 | template <class _CharT, class _Traits> |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3103 | void |
| 3104 | basic_regex<_CharT, _Traits>::swap(basic_regex& __r) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3105 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3106 | using _VSTD::swap; |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3107 | swap(__traits_, __r.__traits_); |
| 3108 | swap(__flags_, __r.__flags_); |
| 3109 | swap(__marked_count_, __r.__marked_count_); |
| 3110 | swap(__loop_count_, __r.__loop_count_); |
| 3111 | swap(__open_count_, __r.__open_count_); |
| 3112 | swap(__start_, __r.__start_); |
| 3113 | swap(__end_, __r.__end_); |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
| 3116 | template <class _CharT, class _Traits> |
| 3117 | inline _LIBCPP_INLINE_VISIBILITY |
| 3118 | void |
| 3119 | swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) |
| 3120 | { |
| 3121 | return __x.swap(__y); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3122 | } |
| 3123 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3124 | // __lookahead |
| 3125 | |
| 3126 | template <class _CharT, class _Traits> |
| 3127 | class __lookahead |
| 3128 | : public __owns_one_state<_CharT> |
| 3129 | { |
| 3130 | typedef __owns_one_state<_CharT> base; |
| 3131 | |
| 3132 | basic_regex<_CharT, _Traits> __exp_; |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3133 | unsigned __mexp_; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3134 | bool __invert_; |
| 3135 | |
| 3136 | __lookahead(const __lookahead&); |
| 3137 | __lookahead& operator=(const __lookahead&); |
| 3138 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3139 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3140 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 3141 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3142 | __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] | 3143 | : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {} |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3144 | |
| 3145 | virtual void __exec(__state&) const; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3146 | }; |
| 3147 | |
| 3148 | template <class _CharT, class _Traits> |
| 3149 | void |
| 3150 | __lookahead<_CharT, _Traits>::__exec(__state& __s) const |
| 3151 | { |
| 3152 | match_results<const _CharT*> __m; |
| 3153 | __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 3154 | bool __matched = __exp_.__match_at_start_ecma( |
| 3155 | __s.__current_, __s.__last_, |
| 3156 | __m, |
| 3157 | (__s.__flags_ | regex_constants::match_continuous) & |
| 3158 | ~regex_constants::__full_match, |
| 3159 | __s.__at_first_ && __s.__current_ == __s.__first_); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3160 | if (__matched != __invert_) |
| 3161 | { |
| 3162 | __s.__do_ = __state::__accept_but_not_consume; |
| 3163 | __s.__node_ = this->first(); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3164 | for (unsigned __i = 1; __i < __m.size(); ++__i) { |
| 3165 | __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i]; |
| 3166 | } |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3167 | } |
| 3168 | else |
| 3169 | { |
| 3170 | __s.__do_ = __state::__reject; |
| 3171 | __s.__node_ = nullptr; |
| 3172 | } |
| 3173 | } |
| 3174 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3175 | template <class _CharT, class _Traits> |
| 3176 | template <class _ForwardIterator> |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 3177 | void |
| 3178 | basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last) |
| 3179 | { |
| 3180 | if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; |
| 3181 | _ForwardIterator __temp = __parse(__first, __last); |
| 3182 | if ( __temp != __last) |
| 3183 | __throw_regex_error<regex_constants::__re_err_parse>(); |
| 3184 | } |
| 3185 | |
| 3186 | template <class _CharT, class _Traits> |
| 3187 | template <class _ForwardIterator> |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3188 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3189 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 3190 | _ForwardIterator __last) |
| 3191 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3192 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 3193 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3194 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 3195 | __h.release(); |
| 3196 | __end_ = __start_.get(); |
| 3197 | } |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3198 | switch (__get_grammar(__flags_)) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3199 | { |
| 3200 | case ECMAScript: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3201 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3202 | break; |
| 3203 | case basic: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3204 | __first = __parse_basic_reg_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3205 | break; |
| 3206 | case extended: |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3207 | case awk: |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3208 | __first = __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3209 | break; |
| 3210 | case grep: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3211 | __first = __parse_grep(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3212 | break; |
| 3213 | case egrep: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3214 | __first = __parse_egrep(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3215 | break; |
| 3216 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3217 | __throw_regex_error<regex_constants::__re_err_grammar>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3218 | } |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3219 | return __first; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | template <class _CharT, class _Traits> |
| 3223 | template <class _ForwardIterator> |
| 3224 | _ForwardIterator |
| 3225 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 3226 | _ForwardIterator __last) |
| 3227 | { |
| 3228 | if (__first != __last) |
| 3229 | { |
| 3230 | if (*__first == '^') |
| 3231 | { |
| 3232 | __push_l_anchor(); |
| 3233 | ++__first; |
| 3234 | } |
| 3235 | if (__first != __last) |
| 3236 | { |
| 3237 | __first = __parse_RE_expression(__first, __last); |
| 3238 | if (__first != __last) |
| 3239 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3240 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3241 | if (__temp == __last && *__first == '$') |
| 3242 | { |
| 3243 | __push_r_anchor(); |
| 3244 | ++__first; |
| 3245 | } |
| 3246 | } |
| 3247 | } |
| 3248 | if (__first != __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3249 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3250 | } |
| 3251 | return __first; |
| 3252 | } |
| 3253 | |
| 3254 | template <class _CharT, class _Traits> |
| 3255 | template <class _ForwardIterator> |
| 3256 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3257 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 3258 | _ForwardIterator __last) |
| 3259 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3260 | __owns_one_state<_CharT>* __sa = __end_; |
| 3261 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
| 3262 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3263 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3264 | __first = __temp; |
| 3265 | while (__first != __last && *__first == '|') |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3266 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3267 | __owns_one_state<_CharT>* __sb = __end_; |
| 3268 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3269 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3270 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3271 | __push_alternation(__sa, __sb); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3272 | __first = __temp; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3273 | } |
| 3274 | return __first; |
| 3275 | } |
| 3276 | |
| 3277 | template <class _CharT, class _Traits> |
| 3278 | template <class _ForwardIterator> |
| 3279 | _ForwardIterator |
| 3280 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 3281 | _ForwardIterator __last) |
| 3282 | { |
| 3283 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
| 3284 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3285 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3286 | do |
| 3287 | { |
| 3288 | __first = __temp; |
| 3289 | __temp = __parse_ERE_expression(__first, __last); |
| 3290 | } while (__temp != __first); |
| 3291 | return __first; |
| 3292 | } |
| 3293 | |
| 3294 | template <class _CharT, class _Traits> |
| 3295 | template <class _ForwardIterator> |
| 3296 | _ForwardIterator |
| 3297 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 3298 | _ForwardIterator __last) |
| 3299 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3300 | __owns_one_state<_CharT>* __e = __end_; |
| 3301 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3302 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 3303 | if (__temp == __first && __temp != __last) |
| 3304 | { |
| 3305 | switch (*__temp) |
| 3306 | { |
| 3307 | case '^': |
| 3308 | __push_l_anchor(); |
| 3309 | ++__temp; |
| 3310 | break; |
| 3311 | case '$': |
| 3312 | __push_r_anchor(); |
| 3313 | ++__temp; |
| 3314 | break; |
| 3315 | case '(': |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3316 | __push_begin_marked_subexpression(); |
| 3317 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3318 | ++__open_count_; |
| 3319 | __temp = __parse_extended_reg_exp(++__temp, __last); |
| 3320 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3321 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3322 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3323 | --__open_count_; |
| 3324 | ++__temp; |
| 3325 | break; |
| 3326 | } |
| 3327 | } |
| 3328 | if (__temp != __first) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3329 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 3330 | __marked_count_+1); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3331 | __first = __temp; |
| 3332 | return __first; |
| 3333 | } |
| 3334 | |
| 3335 | template <class _CharT, class _Traits> |
| 3336 | template <class _ForwardIterator> |
| 3337 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3338 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 3339 | _ForwardIterator __last) |
| 3340 | { |
| 3341 | while (true) |
| 3342 | { |
| 3343 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 3344 | if (__temp == __first) |
| 3345 | break; |
| 3346 | __first = __temp; |
| 3347 | } |
| 3348 | return __first; |
| 3349 | } |
| 3350 | |
| 3351 | template <class _CharT, class _Traits> |
| 3352 | template <class _ForwardIterator> |
| 3353 | _ForwardIterator |
| 3354 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 3355 | _ForwardIterator __last) |
| 3356 | { |
| 3357 | if (__first != __last) |
| 3358 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3359 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3360 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3361 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 3362 | if (__temp != __first) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3363 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 3364 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3365 | } |
| 3366 | return __first; |
| 3367 | } |
| 3368 | |
| 3369 | template <class _CharT, class _Traits> |
| 3370 | template <class _ForwardIterator> |
| 3371 | _ForwardIterator |
| 3372 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 3373 | _ForwardIterator __last) |
| 3374 | { |
| 3375 | _ForwardIterator __temp = __first; |
| 3376 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 3377 | if (__temp == __first) |
| 3378 | { |
| 3379 | __temp = __parse_Back_open_paren(__first, __last); |
| 3380 | if (__temp != __first) |
| 3381 | { |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3382 | __push_begin_marked_subexpression(); |
| 3383 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3384 | __first = __parse_RE_expression(__temp, __last); |
| 3385 | __temp = __parse_Back_close_paren(__first, __last); |
| 3386 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3387 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3388 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3389 | __first = __temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3390 | } |
| 3391 | else |
| 3392 | __first = __parse_BACKREF(__first, __last); |
| 3393 | } |
| 3394 | return __first; |
| 3395 | } |
| 3396 | |
| 3397 | template <class _CharT, class _Traits> |
| 3398 | template <class _ForwardIterator> |
| 3399 | _ForwardIterator |
| 3400 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3401 | _ForwardIterator __first, |
| 3402 | _ForwardIterator __last) |
| 3403 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3404 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3405 | if (__temp == __first) |
| 3406 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3407 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3408 | if (__temp == __first) |
| 3409 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3410 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3411 | { |
| 3412 | __push_match_any(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3413 | ++__temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3414 | } |
| 3415 | else |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3416 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3417 | } |
| 3418 | } |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3419 | __first = __temp; |
| 3420 | return __first; |
| 3421 | } |
| 3422 | |
| 3423 | template <class _CharT, class _Traits> |
| 3424 | template <class _ForwardIterator> |
| 3425 | _ForwardIterator |
| 3426 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3427 | _ForwardIterator __first, |
| 3428 | _ForwardIterator __last) |
| 3429 | { |
| 3430 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3431 | if (__temp == __first) |
| 3432 | { |
| 3433 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3434 | if (__temp == __first) |
| 3435 | { |
| 3436 | if (__temp != __last && *__temp == '.') |
| 3437 | { |
| 3438 | __push_match_any(); |
| 3439 | ++__temp; |
| 3440 | } |
| 3441 | else |
| 3442 | __temp = __parse_bracket_expression(__first, __last); |
| 3443 | } |
| 3444 | } |
| 3445 | __first = __temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3446 | return __first; |
| 3447 | } |
| 3448 | |
| 3449 | template <class _CharT, class _Traits> |
| 3450 | template <class _ForwardIterator> |
| 3451 | _ForwardIterator |
| 3452 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3453 | _ForwardIterator __last) |
| 3454 | { |
| 3455 | if (__first != __last) |
| 3456 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3457 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3458 | if (__temp != __last) |
| 3459 | { |
| 3460 | if (*__first == '\\' && *__temp == '(') |
| 3461 | __first = ++__temp; |
| 3462 | } |
| 3463 | } |
| 3464 | return __first; |
| 3465 | } |
| 3466 | |
| 3467 | template <class _CharT, class _Traits> |
| 3468 | template <class _ForwardIterator> |
| 3469 | _ForwardIterator |
| 3470 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3471 | _ForwardIterator __last) |
| 3472 | { |
| 3473 | if (__first != __last) |
| 3474 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3475 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3476 | if (__temp != __last) |
| 3477 | { |
| 3478 | if (*__first == '\\' && *__temp == ')') |
| 3479 | __first = ++__temp; |
| 3480 | } |
| 3481 | } |
| 3482 | return __first; |
| 3483 | } |
| 3484 | |
| 3485 | template <class _CharT, class _Traits> |
| 3486 | template <class _ForwardIterator> |
| 3487 | _ForwardIterator |
| 3488 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3489 | _ForwardIterator __last) |
| 3490 | { |
| 3491 | if (__first != __last) |
| 3492 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3493 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3494 | if (__temp != __last) |
| 3495 | { |
| 3496 | if (*__first == '\\' && *__temp == '{') |
| 3497 | __first = ++__temp; |
| 3498 | } |
| 3499 | } |
| 3500 | return __first; |
| 3501 | } |
| 3502 | |
| 3503 | template <class _CharT, class _Traits> |
| 3504 | template <class _ForwardIterator> |
| 3505 | _ForwardIterator |
| 3506 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3507 | _ForwardIterator __last) |
| 3508 | { |
| 3509 | if (__first != __last) |
| 3510 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3511 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3512 | if (__temp != __last) |
| 3513 | { |
| 3514 | if (*__first == '\\' && *__temp == '}') |
| 3515 | __first = ++__temp; |
| 3516 | } |
| 3517 | } |
| 3518 | return __first; |
| 3519 | } |
| 3520 | |
| 3521 | template <class _CharT, class _Traits> |
| 3522 | template <class _ForwardIterator> |
| 3523 | _ForwardIterator |
| 3524 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 3525 | _ForwardIterator __last) |
| 3526 | { |
| 3527 | if (__first != __last) |
| 3528 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3529 | _ForwardIterator __temp = _VSTD::next(__first); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 3530 | if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp)) |
| 3531 | __first = ++__temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3532 | } |
| 3533 | return __first; |
| 3534 | } |
| 3535 | |
| 3536 | template <class _CharT, class _Traits> |
| 3537 | template <class _ForwardIterator> |
| 3538 | _ForwardIterator |
| 3539 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3540 | _ForwardIterator __last) |
| 3541 | { |
| 3542 | if (__first != __last) |
| 3543 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3544 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3545 | if (__temp == __last && *__first == '$') |
| 3546 | return __first; |
| 3547 | // Not called inside a bracket |
| 3548 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3549 | return __first; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3550 | __push_char(*__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3551 | ++__first; |
| 3552 | } |
| 3553 | return __first; |
| 3554 | } |
| 3555 | |
| 3556 | template <class _CharT, class _Traits> |
| 3557 | template <class _ForwardIterator> |
| 3558 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3559 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3560 | _ForwardIterator __last) |
| 3561 | { |
| 3562 | if (__first != __last) |
| 3563 | { |
| 3564 | switch (*__first) |
| 3565 | { |
| 3566 | case '^': |
| 3567 | case '.': |
| 3568 | case '[': |
| 3569 | case '$': |
| 3570 | case '(': |
| 3571 | case '|': |
| 3572 | case '*': |
| 3573 | case '+': |
| 3574 | case '?': |
| 3575 | case '{': |
| 3576 | case '\\': |
| 3577 | break; |
| 3578 | case ')': |
| 3579 | if (__open_count_ == 0) |
| 3580 | { |
| 3581 | __push_char(*__first); |
| 3582 | ++__first; |
| 3583 | } |
| 3584 | break; |
| 3585 | default: |
| 3586 | __push_char(*__first); |
| 3587 | ++__first; |
| 3588 | break; |
| 3589 | } |
| 3590 | } |
| 3591 | return __first; |
| 3592 | } |
| 3593 | |
| 3594 | template <class _CharT, class _Traits> |
| 3595 | template <class _ForwardIterator> |
| 3596 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3597 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3598 | _ForwardIterator __last) |
| 3599 | { |
| 3600 | if (__first != __last) |
| 3601 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3602 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3603 | if (__temp != __last) |
| 3604 | { |
| 3605 | if (*__first == '\\') |
| 3606 | { |
| 3607 | switch (*__temp) |
| 3608 | { |
| 3609 | case '^': |
| 3610 | case '.': |
| 3611 | case '*': |
| 3612 | case '[': |
| 3613 | case '$': |
| 3614 | case '\\': |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3615 | __push_char(*__temp); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3616 | __first = ++__temp; |
| 3617 | break; |
| 3618 | } |
| 3619 | } |
| 3620 | } |
| 3621 | } |
| 3622 | return __first; |
| 3623 | } |
| 3624 | |
| 3625 | template <class _CharT, class _Traits> |
| 3626 | template <class _ForwardIterator> |
| 3627 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3628 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3629 | _ForwardIterator __last) |
| 3630 | { |
| 3631 | if (__first != __last) |
| 3632 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3633 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3634 | if (__temp != __last) |
| 3635 | { |
| 3636 | if (*__first == '\\') |
| 3637 | { |
| 3638 | switch (*__temp) |
| 3639 | { |
| 3640 | case '^': |
| 3641 | case '.': |
| 3642 | case '*': |
| 3643 | case '[': |
| 3644 | case '$': |
| 3645 | case '\\': |
| 3646 | case '(': |
| 3647 | case ')': |
| 3648 | case '|': |
| 3649 | case '+': |
| 3650 | case '?': |
| 3651 | case '{': |
Howard Hinnant | 73072eb | 2013-06-28 20:31:05 +0000 | [diff] [blame] | 3652 | case '}': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3653 | __push_char(*__temp); |
| 3654 | __first = ++__temp; |
| 3655 | break; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3656 | default: |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3657 | if (__get_grammar(__flags_) == awk) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3658 | __first = __parse_awk_escape(++__first, __last); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 3659 | else if(__test_back_ref(*__temp)) |
| 3660 | __first = ++__temp; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3661 | break; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3662 | } |
| 3663 | } |
| 3664 | } |
| 3665 | } |
| 3666 | return __first; |
| 3667 | } |
| 3668 | |
| 3669 | template <class _CharT, class _Traits> |
| 3670 | template <class _ForwardIterator> |
| 3671 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3672 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3673 | _ForwardIterator __last, |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3674 | __owns_one_state<_CharT>* __s, |
| 3675 | unsigned __mexp_begin, |
| 3676 | unsigned __mexp_end) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3677 | { |
| 3678 | if (__first != __last) |
| 3679 | { |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3680 | if (*__first == '*') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3681 | { |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3682 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3683 | ++__first; |
| 3684 | } |
| 3685 | else |
| 3686 | { |
| 3687 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3688 | if (__temp != __first) |
| 3689 | { |
| 3690 | int __min = 0; |
| 3691 | __first = __temp; |
| 3692 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 3693 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3694 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3695 | __first = __temp; |
| 3696 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3697 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3698 | if (*__first != ',') |
| 3699 | { |
| 3700 | __temp = __parse_Back_close_brace(__first, __last); |
| 3701 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3702 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3703 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3704 | true); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3705 | __first = __temp; |
| 3706 | } |
| 3707 | else |
| 3708 | { |
| 3709 | ++__first; // consume ',' |
| 3710 | int __max = -1; |
| 3711 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3712 | __temp = __parse_Back_close_brace(__first, __last); |
| 3713 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3714 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3715 | if (__max == -1) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3716 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3717 | else |
| 3718 | { |
| 3719 | if (__max < __min) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3720 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3721 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3722 | true); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3723 | } |
| 3724 | __first = __temp; |
| 3725 | } |
| 3726 | } |
| 3727 | } |
| 3728 | } |
| 3729 | return __first; |
| 3730 | } |
| 3731 | |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3732 | template <class _CharT, class _Traits> |
| 3733 | template <class _ForwardIterator> |
| 3734 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3735 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3736 | _ForwardIterator __last, |
| 3737 | __owns_one_state<_CharT>* __s, |
| 3738 | unsigned __mexp_begin, |
| 3739 | unsigned __mexp_end) |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3740 | { |
| 3741 | if (__first != __last) |
| 3742 | { |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3743 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3744 | switch (*__first) |
| 3745 | { |
| 3746 | case '*': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3747 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3748 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3749 | { |
| 3750 | ++__first; |
| 3751 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3752 | } |
| 3753 | else |
| 3754 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3755 | break; |
| 3756 | case '+': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3757 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3758 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3759 | { |
| 3760 | ++__first; |
| 3761 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3762 | } |
| 3763 | else |
| 3764 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3765 | break; |
| 3766 | case '?': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3767 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3768 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3769 | { |
| 3770 | ++__first; |
| 3771 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3772 | } |
| 3773 | else |
| 3774 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3775 | break; |
| 3776 | case '{': |
| 3777 | { |
| 3778 | int __min; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3779 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3780 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3781 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3782 | __first = __temp; |
| 3783 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3784 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3785 | switch (*__first) |
| 3786 | { |
| 3787 | case '}': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3788 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3789 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3790 | { |
| 3791 | ++__first; |
| 3792 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3793 | } |
| 3794 | else |
| 3795 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3796 | break; |
| 3797 | case ',': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3798 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3799 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3800 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3801 | if (*__first == '}') |
| 3802 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3803 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3804 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3805 | { |
| 3806 | ++__first; |
| 3807 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3808 | } |
| 3809 | else |
| 3810 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3811 | } |
| 3812 | else |
| 3813 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3814 | int __max = -1; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3815 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 3816 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3817 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3818 | __first = __temp; |
| 3819 | if (__first == __last || *__first != '}') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3820 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3821 | ++__first; |
| 3822 | if (__max < __min) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3823 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3824 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3825 | { |
| 3826 | ++__first; |
| 3827 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3828 | } |
| 3829 | else |
| 3830 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3831 | } |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3832 | break; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3833 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3834 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3835 | } |
| 3836 | } |
| 3837 | break; |
| 3838 | } |
| 3839 | } |
| 3840 | return __first; |
| 3841 | } |
| 3842 | |
| 3843 | template <class _CharT, class _Traits> |
| 3844 | template <class _ForwardIterator> |
| 3845 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3846 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3847 | _ForwardIterator __last) |
| 3848 | { |
| 3849 | if (__first != __last && *__first == '[') |
| 3850 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3851 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3852 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3853 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3854 | bool __negate = false; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3855 | if (*__first == '^') |
| 3856 | { |
| 3857 | ++__first; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3858 | __negate = true; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3859 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3860 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3861 | // __ml owned by *this |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3862 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3863 | __throw_regex_error<regex_constants::error_brack>(); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3864 | if (__get_grammar(__flags_) != ECMAScript && *__first == ']') |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3865 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3866 | __ml->__add_char(']'); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3867 | ++__first; |
| 3868 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3869 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3870 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3871 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3872 | if (*__first == '-') |
| 3873 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3874 | __ml->__add_char('-'); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3875 | ++__first; |
| 3876 | } |
| 3877 | if (__first == __last || *__first != ']') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3878 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3879 | ++__first; |
| 3880 | } |
| 3881 | return __first; |
| 3882 | } |
| 3883 | |
| 3884 | template <class _CharT, class _Traits> |
| 3885 | template <class _ForwardIterator> |
| 3886 | _ForwardIterator |
| 3887 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3888 | _ForwardIterator __last, |
| 3889 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3890 | { |
| 3891 | if (__first != __last) |
| 3892 | { |
| 3893 | while (true) |
| 3894 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3895 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3896 | __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3897 | if (__temp == __first) |
| 3898 | break; |
| 3899 | __first = __temp; |
| 3900 | } |
| 3901 | } |
| 3902 | return __first; |
| 3903 | } |
| 3904 | |
| 3905 | template <class _CharT, class _Traits> |
| 3906 | template <class _ForwardIterator> |
| 3907 | _ForwardIterator |
| 3908 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3909 | _ForwardIterator __last, |
| 3910 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3911 | { |
| 3912 | if (__first != __last && *__first != ']') |
| 3913 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3914 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3915 | basic_string<_CharT> __start_range; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3916 | if (__temp != __last && *__first == '[') |
| 3917 | { |
| 3918 | if (*__temp == '=') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3919 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3920 | else if (*__temp == ':') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3921 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3922 | else if (*__temp == '.') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3923 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3924 | } |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3925 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3926 | if (__start_range.empty()) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3927 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3928 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3929 | { |
| 3930 | if (__grammar == ECMAScript) |
| 3931 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3932 | else |
| 3933 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3934 | } |
| 3935 | else |
| 3936 | { |
| 3937 | __start_range = *__first; |
| 3938 | ++__first; |
| 3939 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3940 | } |
| 3941 | if (__first != __last && *__first != ']') |
| 3942 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3943 | __temp = _VSTD::next(__first); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3944 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3945 | { |
| 3946 | // parse a range |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3947 | basic_string<_CharT> __end_range; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3948 | __first = __temp; |
| 3949 | ++__temp; |
| 3950 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3951 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3952 | else |
| 3953 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3954 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3955 | { |
| 3956 | if (__grammar == ECMAScript) |
| 3957 | __first = __parse_class_escape(++__first, __last, |
| 3958 | __end_range, __ml); |
| 3959 | else |
| 3960 | __first = __parse_awk_escape(++__first, __last, |
| 3961 | &__end_range); |
| 3962 | } |
| 3963 | else |
| 3964 | { |
| 3965 | __end_range = *__first; |
| 3966 | ++__first; |
| 3967 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3968 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3969 | __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3970 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3971 | else if (!__start_range.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3972 | { |
| 3973 | if (__start_range.size() == 1) |
| 3974 | __ml->__add_char(__start_range[0]); |
| 3975 | else |
| 3976 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3977 | } |
| 3978 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3979 | else if (!__start_range.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3980 | { |
| 3981 | if (__start_range.size() == 1) |
| 3982 | __ml->__add_char(__start_range[0]); |
| 3983 | else |
| 3984 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3985 | } |
| 3986 | } |
| 3987 | return __first; |
| 3988 | } |
| 3989 | |
| 3990 | template <class _CharT, class _Traits> |
| 3991 | template <class _ForwardIterator> |
| 3992 | _ForwardIterator |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3993 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 3994 | _ForwardIterator __last, |
| 3995 | basic_string<_CharT>& __str, |
| 3996 | __bracket_expression<_CharT, _Traits>* __ml) |
| 3997 | { |
| 3998 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3999 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4000 | switch (*__first) |
| 4001 | { |
| 4002 | case 0: |
| 4003 | __str = *__first; |
| 4004 | return ++__first; |
| 4005 | case 'b': |
| 4006 | __str = _CharT(8); |
| 4007 | return ++__first; |
| 4008 | case 'd': |
| 4009 | __ml->__add_class(ctype_base::digit); |
| 4010 | return ++__first; |
| 4011 | case 'D': |
| 4012 | __ml->__add_neg_class(ctype_base::digit); |
| 4013 | return ++__first; |
| 4014 | case 's': |
| 4015 | __ml->__add_class(ctype_base::space); |
| 4016 | return ++__first; |
| 4017 | case 'S': |
| 4018 | __ml->__add_neg_class(ctype_base::space); |
| 4019 | return ++__first; |
| 4020 | case 'w': |
| 4021 | __ml->__add_class(ctype_base::alnum); |
| 4022 | __ml->__add_char('_'); |
| 4023 | return ++__first; |
| 4024 | case 'W': |
| 4025 | __ml->__add_neg_class(ctype_base::alnum); |
| 4026 | __ml->__add_neg_char('_'); |
| 4027 | return ++__first; |
| 4028 | } |
| 4029 | __first = __parse_character_escape(__first, __last, &__str); |
| 4030 | return __first; |
| 4031 | } |
| 4032 | |
| 4033 | template <class _CharT, class _Traits> |
| 4034 | template <class _ForwardIterator> |
| 4035 | _ForwardIterator |
| 4036 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 4037 | _ForwardIterator __last, |
| 4038 | basic_string<_CharT>* __str) |
| 4039 | { |
| 4040 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4041 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4042 | switch (*__first) |
| 4043 | { |
| 4044 | case '\\': |
| 4045 | case '"': |
| 4046 | case '/': |
| 4047 | if (__str) |
| 4048 | *__str = *__first; |
| 4049 | else |
| 4050 | __push_char(*__first); |
| 4051 | return ++__first; |
| 4052 | case 'a': |
| 4053 | if (__str) |
| 4054 | *__str = _CharT(7); |
| 4055 | else |
| 4056 | __push_char(_CharT(7)); |
| 4057 | return ++__first; |
| 4058 | case 'b': |
| 4059 | if (__str) |
| 4060 | *__str = _CharT(8); |
| 4061 | else |
| 4062 | __push_char(_CharT(8)); |
| 4063 | return ++__first; |
| 4064 | case 'f': |
| 4065 | if (__str) |
| 4066 | *__str = _CharT(0xC); |
| 4067 | else |
| 4068 | __push_char(_CharT(0xC)); |
| 4069 | return ++__first; |
| 4070 | case 'n': |
| 4071 | if (__str) |
| 4072 | *__str = _CharT(0xA); |
| 4073 | else |
| 4074 | __push_char(_CharT(0xA)); |
| 4075 | return ++__first; |
| 4076 | case 'r': |
| 4077 | if (__str) |
| 4078 | *__str = _CharT(0xD); |
| 4079 | else |
| 4080 | __push_char(_CharT(0xD)); |
| 4081 | return ++__first; |
| 4082 | case 't': |
| 4083 | if (__str) |
| 4084 | *__str = _CharT(0x9); |
| 4085 | else |
| 4086 | __push_char(_CharT(0x9)); |
| 4087 | return ++__first; |
| 4088 | case 'v': |
| 4089 | if (__str) |
| 4090 | *__str = _CharT(0xB); |
| 4091 | else |
| 4092 | __push_char(_CharT(0xB)); |
| 4093 | return ++__first; |
| 4094 | } |
| 4095 | if ('0' <= *__first && *__first <= '7') |
| 4096 | { |
| 4097 | unsigned __val = *__first - '0'; |
| 4098 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 4099 | { |
| 4100 | __val = 8 * __val + *__first - '0'; |
| 4101 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
Howard Hinnant | a309687 | 2013-07-02 17:43:31 +0000 | [diff] [blame] | 4102 | __val = 8 * __val + *__first++ - '0'; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4103 | } |
| 4104 | if (__str) |
| 4105 | *__str = _CharT(__val); |
| 4106 | else |
| 4107 | __push_char(_CharT(__val)); |
| 4108 | } |
| 4109 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4110 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4111 | return __first; |
| 4112 | } |
| 4113 | |
| 4114 | template <class _CharT, class _Traits> |
| 4115 | template <class _ForwardIterator> |
| 4116 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4117 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4118 | _ForwardIterator __last, |
| 4119 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4120 | { |
| 4121 | // Found [= |
| 4122 | // This means =] must exist |
| 4123 | value_type _Equal_close[2] = {'=', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4124 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4125 | _Equal_close+2); |
| 4126 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4127 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4128 | // [__first, __temp) contains all text in [= ... =] |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4129 | string_type __collate_name = |
| 4130 | __traits_.lookup_collatename(__first, __temp); |
| 4131 | if (__collate_name.empty()) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4132 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4133 | string_type __equiv_name = |
| 4134 | __traits_.transform_primary(__collate_name.begin(), |
| 4135 | __collate_name.end()); |
| 4136 | if (!__equiv_name.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4137 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4138 | else |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4139 | { |
| 4140 | switch (__collate_name.size()) |
| 4141 | { |
| 4142 | case 1: |
| 4143 | __ml->__add_char(__collate_name[0]); |
| 4144 | break; |
| 4145 | case 2: |
| 4146 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 4147 | break; |
| 4148 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4149 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4150 | } |
| 4151 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4152 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4153 | return __first; |
| 4154 | } |
| 4155 | |
| 4156 | template <class _CharT, class _Traits> |
| 4157 | template <class _ForwardIterator> |
| 4158 | _ForwardIterator |
| 4159 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4160 | _ForwardIterator __last, |
| 4161 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4162 | { |
| 4163 | // Found [: |
| 4164 | // This means :] must exist |
| 4165 | value_type _Colon_close[2] = {':', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4166 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4167 | _Colon_close+2); |
| 4168 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4169 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4170 | // [__first, __temp) contains all text in [: ... :] |
| 4171 | typedef typename _Traits::char_class_type char_class_type; |
| 4172 | char_class_type __class_type = |
| 4173 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 4174 | if (__class_type == 0) |
Mikhail Maltsev | 6ef945b | 2018-01-24 12:45:18 +0000 | [diff] [blame] | 4175 | __throw_regex_error<regex_constants::error_ctype>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4176 | __ml->__add_class(__class_type); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4177 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4178 | return __first; |
| 4179 | } |
| 4180 | |
| 4181 | template <class _CharT, class _Traits> |
| 4182 | template <class _ForwardIterator> |
| 4183 | _ForwardIterator |
| 4184 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4185 | _ForwardIterator __last, |
| 4186 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4187 | { |
| 4188 | // Found [. |
| 4189 | // This means .] must exist |
| 4190 | value_type _Dot_close[2] = {'.', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4191 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4192 | _Dot_close+2); |
| 4193 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4194 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4195 | // [__first, __temp) contains all text in [. ... .] |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4196 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 4197 | switch (__col_sym.size()) |
| 4198 | { |
| 4199 | case 1: |
| 4200 | case 2: |
| 4201 | break; |
| 4202 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4203 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4204 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4205 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4206 | return __first; |
| 4207 | } |
| 4208 | |
| 4209 | template <class _CharT, class _Traits> |
| 4210 | template <class _ForwardIterator> |
| 4211 | _ForwardIterator |
| 4212 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 4213 | _ForwardIterator __last, |
| 4214 | int& __c) |
| 4215 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4216 | if (__first != __last ) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4217 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4218 | int __val = __traits_.value(*__first, 10); |
| 4219 | if ( __val != -1 ) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4220 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4221 | __c = __val; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4222 | for (++__first; |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4223 | __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; |
| 4224 | ++__first) |
| 4225 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4226 | if (__c >= numeric_limits<int>::max() / 10) |
Marshall Clow | 863ae38 | 2017-10-19 17:39:16 +0000 | [diff] [blame] | 4227 | __throw_regex_error<regex_constants::error_badbrace>(); |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4228 | __c *= 10; |
| 4229 | __c += __val; |
| 4230 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4231 | } |
| 4232 | } |
| 4233 | return __first; |
| 4234 | } |
| 4235 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4236 | template <class _CharT, class _Traits> |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4237 | template <class _ForwardIterator> |
| 4238 | _ForwardIterator |
| 4239 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 4240 | _ForwardIterator __last) |
| 4241 | { |
| 4242 | __owns_one_state<_CharT>* __sa = __end_; |
| 4243 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 4244 | if (__temp == __first) |
| 4245 | __push_empty(); |
| 4246 | __first = __temp; |
| 4247 | while (__first != __last && *__first == '|') |
| 4248 | { |
| 4249 | __owns_one_state<_CharT>* __sb = __end_; |
| 4250 | __temp = __parse_alternative(++__first, __last); |
| 4251 | if (__temp == __first) |
| 4252 | __push_empty(); |
| 4253 | __push_alternation(__sa, __sb); |
| 4254 | __first = __temp; |
| 4255 | } |
| 4256 | return __first; |
| 4257 | } |
| 4258 | |
| 4259 | template <class _CharT, class _Traits> |
| 4260 | template <class _ForwardIterator> |
| 4261 | _ForwardIterator |
| 4262 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 4263 | _ForwardIterator __last) |
| 4264 | { |
| 4265 | while (true) |
| 4266 | { |
| 4267 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 4268 | if (__temp == __first) |
| 4269 | break; |
| 4270 | __first = __temp; |
| 4271 | } |
| 4272 | return __first; |
| 4273 | } |
| 4274 | |
| 4275 | template <class _CharT, class _Traits> |
| 4276 | template <class _ForwardIterator> |
| 4277 | _ForwardIterator |
| 4278 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 4279 | _ForwardIterator __last) |
| 4280 | { |
| 4281 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 4282 | if (__temp == __first) |
| 4283 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4284 | __owns_one_state<_CharT>* __e = __end_; |
| 4285 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4286 | __temp = __parse_atom(__first, __last); |
| 4287 | if (__temp != __first) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4288 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 4289 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4290 | } |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4291 | else |
| 4292 | __first = __temp; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4293 | return __first; |
| 4294 | } |
| 4295 | |
| 4296 | template <class _CharT, class _Traits> |
| 4297 | template <class _ForwardIterator> |
| 4298 | _ForwardIterator |
| 4299 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 4300 | _ForwardIterator __last) |
| 4301 | { |
| 4302 | if (__first != __last) |
| 4303 | { |
| 4304 | switch (*__first) |
| 4305 | { |
| 4306 | case '^': |
| 4307 | __push_l_anchor(); |
| 4308 | ++__first; |
| 4309 | break; |
| 4310 | case '$': |
| 4311 | __push_r_anchor(); |
| 4312 | ++__first; |
| 4313 | break; |
| 4314 | case '\\': |
| 4315 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4316 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4317 | if (__temp != __last) |
| 4318 | { |
| 4319 | if (*__temp == 'b') |
| 4320 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4321 | __push_word_boundary(false); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4322 | __first = ++__temp; |
| 4323 | } |
| 4324 | else if (*__temp == 'B') |
| 4325 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4326 | __push_word_boundary(true); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4327 | __first = ++__temp; |
| 4328 | } |
| 4329 | } |
| 4330 | } |
| 4331 | break; |
| 4332 | case '(': |
| 4333 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4334 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4335 | if (__temp != __last && *__temp == '?') |
| 4336 | { |
| 4337 | if (++__temp != __last) |
| 4338 | { |
| 4339 | switch (*__temp) |
| 4340 | { |
| 4341 | case '=': |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4342 | { |
| 4343 | basic_regex __exp; |
| 4344 | __exp.__flags_ = __flags_; |
| 4345 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4346 | unsigned __mexp = __exp.__marked_count_; |
| 4347 | __push_lookahead(_VSTD::move(__exp), false, __marked_count_); |
| 4348 | __marked_count_ += __mexp; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4349 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4350 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4351 | __first = ++__temp; |
| 4352 | } |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4353 | break; |
| 4354 | case '!': |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4355 | { |
| 4356 | basic_regex __exp; |
| 4357 | __exp.__flags_ = __flags_; |
| 4358 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4359 | unsigned __mexp = __exp.__marked_count_; |
| 4360 | __push_lookahead(_VSTD::move(__exp), true, __marked_count_); |
| 4361 | __marked_count_ += __mexp; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4362 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4363 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4364 | __first = ++__temp; |
| 4365 | } |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4366 | break; |
| 4367 | } |
| 4368 | } |
| 4369 | } |
| 4370 | } |
| 4371 | break; |
| 4372 | } |
| 4373 | } |
| 4374 | return __first; |
| 4375 | } |
| 4376 | |
| 4377 | template <class _CharT, class _Traits> |
| 4378 | template <class _ForwardIterator> |
| 4379 | _ForwardIterator |
| 4380 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4381 | _ForwardIterator __last) |
| 4382 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4383 | if (__first != __last) |
| 4384 | { |
| 4385 | switch (*__first) |
| 4386 | { |
| 4387 | case '.': |
| 4388 | __push_match_any_but_newline(); |
| 4389 | ++__first; |
| 4390 | break; |
| 4391 | case '\\': |
| 4392 | __first = __parse_atom_escape(__first, __last); |
| 4393 | break; |
| 4394 | case '[': |
| 4395 | __first = __parse_bracket_expression(__first, __last); |
| 4396 | break; |
| 4397 | case '(': |
| 4398 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4399 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4400 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4401 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4402 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4403 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4404 | { |
| 4405 | ++__open_count_; |
| 4406 | __first = __parse_ecma_exp(++__temp, __last); |
| 4407 | if (__first == __last || *__first != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4408 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4409 | --__open_count_; |
| 4410 | ++__first; |
| 4411 | } |
| 4412 | else |
| 4413 | { |
| 4414 | __push_begin_marked_subexpression(); |
| 4415 | unsigned __temp_count = __marked_count_; |
| 4416 | ++__open_count_; |
| 4417 | __first = __parse_ecma_exp(__first, __last); |
| 4418 | if (__first == __last || *__first != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4419 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4420 | __push_end_marked_subexpression(__temp_count); |
| 4421 | --__open_count_; |
| 4422 | ++__first; |
| 4423 | } |
| 4424 | } |
| 4425 | break; |
Marshall Clow | 8205821 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4426 | case '*': |
| 4427 | case '+': |
| 4428 | case '?': |
| 4429 | case '{': |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4430 | __throw_regex_error<regex_constants::error_badrepeat>(); |
Marshall Clow | 8205821 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4431 | break; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4432 | default: |
| 4433 | __first = __parse_pattern_character(__first, __last); |
| 4434 | break; |
| 4435 | } |
| 4436 | } |
| 4437 | return __first; |
| 4438 | } |
| 4439 | |
| 4440 | template <class _CharT, class _Traits> |
| 4441 | template <class _ForwardIterator> |
| 4442 | _ForwardIterator |
| 4443 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4444 | _ForwardIterator __last) |
| 4445 | { |
| 4446 | if (__first != __last && *__first == '\\') |
| 4447 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4448 | _ForwardIterator __t1 = _VSTD::next(__first); |
Marshall Clow | db9633c | 2016-01-19 00:50:37 +0000 | [diff] [blame] | 4449 | if (__t1 == __last) |
| 4450 | __throw_regex_error<regex_constants::error_escape>(); |
| 4451 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4452 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4453 | if (__t2 != __t1) |
| 4454 | __first = __t2; |
| 4455 | else |
| 4456 | { |
| 4457 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4458 | if (__t2 != __t1) |
| 4459 | __first = __t2; |
| 4460 | else |
| 4461 | { |
| 4462 | __t2 = __parse_character_escape(__t1, __last); |
| 4463 | if (__t2 != __t1) |
| 4464 | __first = __t2; |
| 4465 | } |
| 4466 | } |
| 4467 | } |
| 4468 | return __first; |
| 4469 | } |
| 4470 | |
| 4471 | template <class _CharT, class _Traits> |
| 4472 | template <class _ForwardIterator> |
| 4473 | _ForwardIterator |
| 4474 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4475 | _ForwardIterator __last) |
| 4476 | { |
| 4477 | if (__first != __last) |
| 4478 | { |
| 4479 | if (*__first == '0') |
| 4480 | { |
| 4481 | __push_char(_CharT()); |
| 4482 | ++__first; |
| 4483 | } |
| 4484 | else if ('1' <= *__first && *__first <= '9') |
| 4485 | { |
| 4486 | unsigned __v = *__first - '0'; |
Marshall Clow | dc03ec7 | 2016-12-24 17:21:03 +0000 | [diff] [blame] | 4487 | for (++__first; |
| 4488 | __first != __last && '0' <= *__first && *__first <= '9'; ++__first) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4489 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4490 | if (__v >= numeric_limits<unsigned>::max() / 10) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4491 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4492 | __v = 10 * __v + *__first - '0'; |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4493 | } |
| 4494 | if (__v == 0 || __v > mark_count()) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4495 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4496 | __push_back_ref(__v); |
| 4497 | } |
| 4498 | } |
| 4499 | return __first; |
| 4500 | } |
| 4501 | |
| 4502 | template <class _CharT, class _Traits> |
| 4503 | template <class _ForwardIterator> |
| 4504 | _ForwardIterator |
| 4505 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4506 | _ForwardIterator __last) |
| 4507 | { |
| 4508 | if (__first != __last) |
| 4509 | { |
| 4510 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4511 | switch (*__first) |
| 4512 | { |
| 4513 | case 'd': |
| 4514 | __ml = __start_matching_list(false); |
| 4515 | __ml->__add_class(ctype_base::digit); |
| 4516 | ++__first; |
| 4517 | break; |
| 4518 | case 'D': |
| 4519 | __ml = __start_matching_list(true); |
| 4520 | __ml->__add_class(ctype_base::digit); |
| 4521 | ++__first; |
| 4522 | break; |
| 4523 | case 's': |
| 4524 | __ml = __start_matching_list(false); |
| 4525 | __ml->__add_class(ctype_base::space); |
| 4526 | ++__first; |
| 4527 | break; |
| 4528 | case 'S': |
| 4529 | __ml = __start_matching_list(true); |
| 4530 | __ml->__add_class(ctype_base::space); |
| 4531 | ++__first; |
| 4532 | break; |
| 4533 | case 'w': |
| 4534 | __ml = __start_matching_list(false); |
| 4535 | __ml->__add_class(ctype_base::alnum); |
| 4536 | __ml->__add_char('_'); |
| 4537 | ++__first; |
| 4538 | break; |
| 4539 | case 'W': |
| 4540 | __ml = __start_matching_list(true); |
| 4541 | __ml->__add_class(ctype_base::alnum); |
| 4542 | __ml->__add_char('_'); |
| 4543 | ++__first; |
| 4544 | break; |
| 4545 | } |
| 4546 | } |
| 4547 | return __first; |
| 4548 | } |
| 4549 | |
| 4550 | template <class _CharT, class _Traits> |
| 4551 | template <class _ForwardIterator> |
| 4552 | _ForwardIterator |
| 4553 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4554 | _ForwardIterator __last, |
| 4555 | basic_string<_CharT>* __str) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4556 | { |
| 4557 | if (__first != __last) |
| 4558 | { |
| 4559 | _ForwardIterator __t; |
| 4560 | unsigned __sum = 0; |
| 4561 | int __hd; |
| 4562 | switch (*__first) |
| 4563 | { |
| 4564 | case 'f': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4565 | if (__str) |
| 4566 | *__str = _CharT(0xC); |
| 4567 | else |
| 4568 | __push_char(_CharT(0xC)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4569 | ++__first; |
| 4570 | break; |
| 4571 | case 'n': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4572 | if (__str) |
| 4573 | *__str = _CharT(0xA); |
| 4574 | else |
| 4575 | __push_char(_CharT(0xA)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4576 | ++__first; |
| 4577 | break; |
| 4578 | case 'r': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4579 | if (__str) |
| 4580 | *__str = _CharT(0xD); |
| 4581 | else |
| 4582 | __push_char(_CharT(0xD)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4583 | ++__first; |
| 4584 | break; |
| 4585 | case 't': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4586 | if (__str) |
| 4587 | *__str = _CharT(0x9); |
| 4588 | else |
| 4589 | __push_char(_CharT(0x9)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4590 | ++__first; |
| 4591 | break; |
| 4592 | case 'v': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4593 | if (__str) |
| 4594 | *__str = _CharT(0xB); |
| 4595 | else |
| 4596 | __push_char(_CharT(0xB)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4597 | ++__first; |
| 4598 | break; |
| 4599 | case 'c': |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4600 | if ((__t = _VSTD::next(__first)) != __last) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4601 | { |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4602 | if (('A' <= *__t && *__t <= 'Z') || |
Howard Hinnant | d04741b | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4603 | ('a' <= *__t && *__t <= 'z')) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4604 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4605 | if (__str) |
| 4606 | *__str = _CharT(*__t % 32); |
| 4607 | else |
| 4608 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4609 | __first = ++__t; |
| 4610 | } |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4611 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4612 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4613 | } |
Howard Hinnant | d04741b | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4614 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4615 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4616 | break; |
| 4617 | case 'u': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4618 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4619 | if (__first == __last) |
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 | __hd = __traits_.value(*__first, 16); |
| 4622 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4623 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4624 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4625 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4626 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4627 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4628 | __hd = __traits_.value(*__first, 16); |
| 4629 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4630 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4631 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 4632 | // fallthrough |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4633 | case 'x': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4634 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4635 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4636 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4637 | __hd = __traits_.value(*__first, 16); |
| 4638 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4639 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4640 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4641 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4642 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4643 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4644 | __hd = __traits_.value(*__first, 16); |
| 4645 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4646 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4647 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4648 | if (__str) |
| 4649 | *__str = _CharT(__sum); |
| 4650 | else |
| 4651 | __push_char(_CharT(__sum)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4652 | ++__first; |
| 4653 | break; |
Marshall Clow | f6cef0d | 2014-05-21 16:29:50 +0000 | [diff] [blame] | 4654 | case '0': |
| 4655 | if (__str) |
| 4656 | *__str = _CharT(0); |
| 4657 | else |
| 4658 | __push_char(_CharT(0)); |
| 4659 | ++__first; |
| 4660 | break; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4661 | default: |
| 4662 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4663 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4664 | if (__str) |
| 4665 | *__str = *__first; |
| 4666 | else |
| 4667 | __push_char(*__first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4668 | ++__first; |
| 4669 | } |
Howard Hinnant | 4f7a1f5 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 4670 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4671 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4672 | break; |
| 4673 | } |
| 4674 | } |
| 4675 | return __first; |
| 4676 | } |
| 4677 | |
| 4678 | template <class _CharT, class _Traits> |
| 4679 | template <class _ForwardIterator> |
| 4680 | _ForwardIterator |
| 4681 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4682 | _ForwardIterator __last) |
| 4683 | { |
| 4684 | if (__first != __last) |
| 4685 | { |
| 4686 | switch (*__first) |
| 4687 | { |
| 4688 | case '^': |
| 4689 | case '$': |
| 4690 | case '\\': |
| 4691 | case '.': |
| 4692 | case '*': |
| 4693 | case '+': |
| 4694 | case '?': |
| 4695 | case '(': |
| 4696 | case ')': |
| 4697 | case '[': |
| 4698 | case ']': |
| 4699 | case '{': |
| 4700 | case '}': |
| 4701 | case '|': |
| 4702 | break; |
| 4703 | default: |
| 4704 | __push_char(*__first); |
| 4705 | ++__first; |
| 4706 | break; |
| 4707 | } |
| 4708 | } |
| 4709 | return __first; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | template <class _CharT, class _Traits> |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4713 | template <class _ForwardIterator> |
| 4714 | _ForwardIterator |
| 4715 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4716 | _ForwardIterator __last) |
| 4717 | { |
| 4718 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4719 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4720 | if (__t1 != __first) |
| 4721 | __parse_basic_reg_exp(__first, __t1); |
| 4722 | else |
| 4723 | __push_empty(); |
| 4724 | __first = __t1; |
| 4725 | if (__first != __last) |
| 4726 | ++__first; |
| 4727 | while (__first != __last) |
| 4728 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4729 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4730 | __owns_one_state<_CharT>* __sb = __end_; |
| 4731 | if (__t1 != __first) |
| 4732 | __parse_basic_reg_exp(__first, __t1); |
| 4733 | else |
| 4734 | __push_empty(); |
| 4735 | __push_alternation(__sa, __sb); |
| 4736 | __first = __t1; |
| 4737 | if (__first != __last) |
| 4738 | ++__first; |
| 4739 | } |
| 4740 | return __first; |
| 4741 | } |
| 4742 | |
| 4743 | template <class _CharT, class _Traits> |
| 4744 | template <class _ForwardIterator> |
| 4745 | _ForwardIterator |
| 4746 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4747 | _ForwardIterator __last) |
| 4748 | { |
| 4749 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4750 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4751 | if (__t1 != __first) |
| 4752 | __parse_extended_reg_exp(__first, __t1); |
| 4753 | else |
| 4754 | __push_empty(); |
| 4755 | __first = __t1; |
| 4756 | if (__first != __last) |
| 4757 | ++__first; |
| 4758 | while (__first != __last) |
| 4759 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4760 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4761 | __owns_one_state<_CharT>* __sb = __end_; |
| 4762 | if (__t1 != __first) |
| 4763 | __parse_extended_reg_exp(__first, __t1); |
| 4764 | else |
| 4765 | __push_empty(); |
| 4766 | __push_alternation(__sa, __sb); |
| 4767 | __first = __t1; |
| 4768 | if (__first != __last) |
| 4769 | ++__first; |
| 4770 | } |
| 4771 | return __first; |
| 4772 | } |
| 4773 | |
| 4774 | template <class _CharT, class _Traits> |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4775 | bool |
| 4776 | basic_regex<_CharT, _Traits>::__test_back_ref(_CharT c) |
| 4777 | { |
| 4778 | unsigned __val = __traits_.value(c, 10); |
| 4779 | if (__val >= 1 && __val <= 9) |
| 4780 | { |
Mark de Wever | d324e5f | 2020-02-20 18:13:38 -0500 | [diff] [blame] | 4781 | if (__val > mark_count()) |
| 4782 | __throw_regex_error<regex_constants::error_backref>(); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4783 | __push_back_ref(__val); |
| 4784 | return true; |
| 4785 | } |
| 4786 | |
| 4787 | return false; |
| 4788 | } |
| 4789 | |
| 4790 | template <class _CharT, class _Traits> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4791 | void |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4792 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4793 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4794 | bool __greedy) |
| 4795 | { |
| 4796 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4797 | __end_->first() = nullptr; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4798 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4799 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4800 | __min, __max)); |
| 4801 | __s->first() = nullptr; |
| 4802 | __e1.release(); |
| 4803 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4804 | __end_ = __e2->second(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4805 | __s->first() = __e2.release(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4806 | ++__loop_count_; |
| 4807 | } |
| 4808 | |
| 4809 | template <class _CharT, class _Traits> |
| 4810 | void |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4811 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4812 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4813 | if (flags() & icase) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4814 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4815 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4816 | else if (flags() & collate) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4817 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4818 | (__traits_, __c, __end_->first()); |
| 4819 | else |
| 4820 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4821 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4822 | } |
| 4823 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4824 | template <class _CharT, class _Traits> |
| 4825 | void |
| 4826 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4827 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4828 | if (!(__flags_ & nosubs)) |
| 4829 | { |
| 4830 | __end_->first() = |
| 4831 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4832 | __end_->first()); |
| 4833 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4834 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | template <class _CharT, class _Traits> |
| 4838 | void |
| 4839 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4840 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4841 | if (!(__flags_ & nosubs)) |
| 4842 | { |
| 4843 | __end_->first() = |
| 4844 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4845 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4846 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4849 | template <class _CharT, class _Traits> |
| 4850 | void |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4851 | basic_regex<_CharT, _Traits>::__push_l_anchor() |
| 4852 | { |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 4853 | __end_->first() = new __l_anchor_multiline<_CharT>(__use_multiline(), __end_->first()); |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4854 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4855 | } |
| 4856 | |
| 4857 | template <class _CharT, class _Traits> |
| 4858 | void |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4859 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4860 | { |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 4861 | __end_->first() = new __r_anchor_multiline<_CharT>(__use_multiline(), __end_->first()); |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4862 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4863 | } |
| 4864 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4865 | template <class _CharT, class _Traits> |
| 4866 | void |
| 4867 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4868 | { |
| 4869 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4870 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4871 | } |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4872 | |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4873 | template <class _CharT, class _Traits> |
| 4874 | void |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4875 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4876 | { |
| 4877 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4878 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4879 | } |
| 4880 | |
| 4881 | template <class _CharT, class _Traits> |
| 4882 | void |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4883 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4884 | { |
| 4885 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4886 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4887 | } |
| 4888 | |
| 4889 | template <class _CharT, class _Traits> |
| 4890 | void |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4891 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4892 | { |
| 4893 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4894 | __end_->first()); |
| 4895 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4896 | } |
| 4897 | |
| 4898 | template <class _CharT, class _Traits> |
| 4899 | void |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4900 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4901 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4902 | if (flags() & icase) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4903 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4904 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4905 | else if (flags() & collate) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4906 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4907 | (__traits_, __i, __end_->first()); |
| 4908 | else |
| 4909 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4910 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4911 | } |
| 4912 | |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4913 | template <class _CharT, class _Traits> |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4914 | void |
| 4915 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4916 | __owns_one_state<_CharT>* __ea) |
| 4917 | { |
| 4918 | __sa->first() = new __alternate<_CharT>( |
| 4919 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4920 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4921 | __ea->first() = nullptr; |
| 4922 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4923 | __end_->first() = nullptr; |
| 4924 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4925 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4926 | } |
| 4927 | |
| 4928 | template <class _CharT, class _Traits> |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4929 | __bracket_expression<_CharT, _Traits>* |
| 4930 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4931 | { |
| 4932 | __bracket_expression<_CharT, _Traits>* __r = |
| 4933 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4934 | __negate, __flags_ & icase, |
| 4935 | __flags_ & collate); |
| 4936 | __end_->first() = __r; |
| 4937 | __end_ = __r; |
| 4938 | return __r; |
| 4939 | } |
| 4940 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4941 | template <class _CharT, class _Traits> |
| 4942 | void |
| 4943 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4944 | bool __invert, |
| 4945 | unsigned __mexp) |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4946 | { |
| 4947 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4948 | __end_->first(), __mexp); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4949 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4950 | } |
| 4951 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4952 | // sub_match |
| 4953 | |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4954 | typedef sub_match<const char*> csub_match; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4955 | typedef sub_match<string::const_iterator> ssub_match; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4956 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4957 | typedef sub_match<const wchar_t*> wcsub_match; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4958 | typedef sub_match<wstring::const_iterator> wssub_match; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4959 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4960 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4961 | template <class _BidirectionalIterator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4962 | class |
| 4963 | _LIBCPP_TEMPLATE_VIS |
| 4964 | _LIBCPP_PREFERRED_NAME(csub_match) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4965 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4966 | _LIBCPP_PREFERRED_NAME(ssub_match) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4967 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4968 | sub_match |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4969 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4970 | { |
| 4971 | public: |
| 4972 | typedef _BidirectionalIterator iterator; |
| 4973 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4974 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4975 | typedef basic_string<value_type> string_type; |
| 4976 | |
| 4977 | bool matched; |
| 4978 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4979 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 4980 | _LIBCPP_CONSTEXPR sub_match() : matched() {} |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 4981 | |
| 4982 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4983 | difference_type length() const |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4984 | {return matched ? _VSTD::distance(this->first, this->second) : 0;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4985 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4986 | string_type str() const |
| 4987 | {return matched ? string_type(this->first, this->second) : string_type();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4988 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4989 | operator string_type() const |
| 4990 | {return str();} |
| 4991 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4992 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4993 | int compare(const sub_match& __s) const |
| 4994 | {return str().compare(__s.str());} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4995 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4996 | int compare(const string_type& __s) const |
| 4997 | {return str().compare(__s);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4998 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4999 | int compare(const value_type* __s) const |
| 5000 | {return str().compare(__s);} |
| 5001 | }; |
| 5002 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5003 | template <class _BiIter> |
| 5004 | inline _LIBCPP_INLINE_VISIBILITY |
| 5005 | bool |
| 5006 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5007 | { |
| 5008 | return __x.compare(__y) == 0; |
| 5009 | } |
| 5010 | |
| 5011 | template <class _BiIter> |
| 5012 | inline _LIBCPP_INLINE_VISIBILITY |
| 5013 | bool |
| 5014 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5015 | { |
| 5016 | return !(__x == __y); |
| 5017 | } |
| 5018 | |
| 5019 | template <class _BiIter> |
| 5020 | inline _LIBCPP_INLINE_VISIBILITY |
| 5021 | bool |
| 5022 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5023 | { |
| 5024 | return __x.compare(__y) < 0; |
| 5025 | } |
| 5026 | |
| 5027 | template <class _BiIter> |
| 5028 | inline _LIBCPP_INLINE_VISIBILITY |
| 5029 | bool |
| 5030 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5031 | { |
| 5032 | return !(__y < __x); |
| 5033 | } |
| 5034 | |
| 5035 | template <class _BiIter> |
| 5036 | inline _LIBCPP_INLINE_VISIBILITY |
| 5037 | bool |
| 5038 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5039 | { |
| 5040 | return !(__x < __y); |
| 5041 | } |
| 5042 | |
| 5043 | template <class _BiIter> |
| 5044 | inline _LIBCPP_INLINE_VISIBILITY |
| 5045 | bool |
| 5046 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5047 | { |
| 5048 | return __y < __x; |
| 5049 | } |
| 5050 | |
| 5051 | template <class _BiIter, class _ST, class _SA> |
| 5052 | inline _LIBCPP_INLINE_VISIBILITY |
| 5053 | bool |
| 5054 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5055 | const sub_match<_BiIter>& __y) |
| 5056 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5057 | 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] | 5058 | } |
| 5059 | |
| 5060 | template <class _BiIter, class _ST, class _SA> |
| 5061 | inline _LIBCPP_INLINE_VISIBILITY |
| 5062 | bool |
| 5063 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5064 | const sub_match<_BiIter>& __y) |
| 5065 | { |
| 5066 | return !(__x == __y); |
| 5067 | } |
| 5068 | |
| 5069 | template <class _BiIter, class _ST, class _SA> |
| 5070 | inline _LIBCPP_INLINE_VISIBILITY |
| 5071 | bool |
| 5072 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5073 | const sub_match<_BiIter>& __y) |
| 5074 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5075 | 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] | 5076 | } |
| 5077 | |
| 5078 | template <class _BiIter, class _ST, class _SA> |
| 5079 | inline _LIBCPP_INLINE_VISIBILITY |
| 5080 | bool |
| 5081 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5082 | const sub_match<_BiIter>& __y) |
| 5083 | { |
| 5084 | return __y < __x; |
| 5085 | } |
| 5086 | |
| 5087 | template <class _BiIter, class _ST, class _SA> |
| 5088 | inline _LIBCPP_INLINE_VISIBILITY |
| 5089 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5090 | const sub_match<_BiIter>& __y) |
| 5091 | { |
| 5092 | return !(__x < __y); |
| 5093 | } |
| 5094 | |
| 5095 | template <class _BiIter, class _ST, class _SA> |
| 5096 | inline _LIBCPP_INLINE_VISIBILITY |
| 5097 | bool |
| 5098 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5099 | const sub_match<_BiIter>& __y) |
| 5100 | { |
| 5101 | return !(__y < __x); |
| 5102 | } |
| 5103 | |
| 5104 | template <class _BiIter, class _ST, class _SA> |
| 5105 | inline _LIBCPP_INLINE_VISIBILITY |
| 5106 | bool |
| 5107 | operator==(const sub_match<_BiIter>& __x, |
| 5108 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5109 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5110 | 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] | 5111 | } |
| 5112 | |
| 5113 | template <class _BiIter, class _ST, class _SA> |
| 5114 | inline _LIBCPP_INLINE_VISIBILITY |
| 5115 | bool |
| 5116 | operator!=(const sub_match<_BiIter>& __x, |
| 5117 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5118 | { |
| 5119 | return !(__x == __y); |
| 5120 | } |
| 5121 | |
| 5122 | template <class _BiIter, class _ST, class _SA> |
| 5123 | inline _LIBCPP_INLINE_VISIBILITY |
| 5124 | bool |
| 5125 | operator<(const sub_match<_BiIter>& __x, |
| 5126 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5127 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5128 | 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] | 5129 | } |
| 5130 | |
| 5131 | template <class _BiIter, class _ST, class _SA> |
| 5132 | inline _LIBCPP_INLINE_VISIBILITY |
| 5133 | bool operator>(const sub_match<_BiIter>& __x, |
| 5134 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5135 | { |
| 5136 | return __y < __x; |
| 5137 | } |
| 5138 | |
| 5139 | template <class _BiIter, class _ST, class _SA> |
| 5140 | inline _LIBCPP_INLINE_VISIBILITY |
| 5141 | bool |
| 5142 | operator>=(const sub_match<_BiIter>& __x, |
| 5143 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5144 | { |
| 5145 | return !(__x < __y); |
| 5146 | } |
| 5147 | |
| 5148 | template <class _BiIter, class _ST, class _SA> |
| 5149 | inline _LIBCPP_INLINE_VISIBILITY |
| 5150 | bool |
| 5151 | operator<=(const sub_match<_BiIter>& __x, |
| 5152 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5153 | { |
| 5154 | return !(__y < __x); |
| 5155 | } |
| 5156 | |
| 5157 | template <class _BiIter> |
| 5158 | inline _LIBCPP_INLINE_VISIBILITY |
| 5159 | bool |
| 5160 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5161 | const sub_match<_BiIter>& __y) |
| 5162 | { |
| 5163 | return __y.compare(__x) == 0; |
| 5164 | } |
| 5165 | |
| 5166 | template <class _BiIter> |
| 5167 | inline _LIBCPP_INLINE_VISIBILITY |
| 5168 | bool |
| 5169 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5170 | const sub_match<_BiIter>& __y) |
| 5171 | { |
| 5172 | return !(__x == __y); |
| 5173 | } |
| 5174 | |
| 5175 | template <class _BiIter> |
| 5176 | inline _LIBCPP_INLINE_VISIBILITY |
| 5177 | bool |
| 5178 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5179 | const sub_match<_BiIter>& __y) |
| 5180 | { |
| 5181 | return __y.compare(__x) > 0; |
| 5182 | } |
| 5183 | |
| 5184 | template <class _BiIter> |
| 5185 | inline _LIBCPP_INLINE_VISIBILITY |
| 5186 | bool |
| 5187 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5188 | const sub_match<_BiIter>& __y) |
| 5189 | { |
| 5190 | return __y < __x; |
| 5191 | } |
| 5192 | |
| 5193 | template <class _BiIter> |
| 5194 | inline _LIBCPP_INLINE_VISIBILITY |
| 5195 | bool |
| 5196 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5197 | const sub_match<_BiIter>& __y) |
| 5198 | { |
| 5199 | return !(__x < __y); |
| 5200 | } |
| 5201 | |
| 5202 | template <class _BiIter> |
| 5203 | inline _LIBCPP_INLINE_VISIBILITY |
| 5204 | bool |
| 5205 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5206 | const sub_match<_BiIter>& __y) |
| 5207 | { |
| 5208 | return !(__y < __x); |
| 5209 | } |
| 5210 | |
| 5211 | template <class _BiIter> |
| 5212 | inline _LIBCPP_INLINE_VISIBILITY |
| 5213 | bool |
| 5214 | operator==(const sub_match<_BiIter>& __x, |
| 5215 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5216 | { |
| 5217 | return __x.compare(__y) == 0; |
| 5218 | } |
| 5219 | |
| 5220 | template <class _BiIter> |
| 5221 | inline _LIBCPP_INLINE_VISIBILITY |
| 5222 | bool |
| 5223 | operator!=(const sub_match<_BiIter>& __x, |
| 5224 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5225 | { |
| 5226 | return !(__x == __y); |
| 5227 | } |
| 5228 | |
| 5229 | template <class _BiIter> |
| 5230 | inline _LIBCPP_INLINE_VISIBILITY |
| 5231 | bool |
| 5232 | operator<(const sub_match<_BiIter>& __x, |
| 5233 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5234 | { |
| 5235 | return __x.compare(__y) < 0; |
| 5236 | } |
| 5237 | |
| 5238 | template <class _BiIter> |
| 5239 | inline _LIBCPP_INLINE_VISIBILITY |
| 5240 | bool |
| 5241 | operator>(const sub_match<_BiIter>& __x, |
| 5242 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5243 | { |
| 5244 | return __y < __x; |
| 5245 | } |
| 5246 | |
| 5247 | template <class _BiIter> |
| 5248 | inline _LIBCPP_INLINE_VISIBILITY |
| 5249 | bool |
| 5250 | operator>=(const sub_match<_BiIter>& __x, |
| 5251 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5252 | { |
| 5253 | return !(__x < __y); |
| 5254 | } |
| 5255 | |
| 5256 | template <class _BiIter> |
| 5257 | inline _LIBCPP_INLINE_VISIBILITY |
| 5258 | bool |
| 5259 | operator<=(const sub_match<_BiIter>& __x, |
| 5260 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5261 | { |
| 5262 | return !(__y < __x); |
| 5263 | } |
| 5264 | |
| 5265 | template <class _BiIter> |
| 5266 | inline _LIBCPP_INLINE_VISIBILITY |
| 5267 | bool |
| 5268 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5269 | const sub_match<_BiIter>& __y) |
| 5270 | { |
| 5271 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5272 | return __y.compare(string_type(1, __x)) == 0; |
| 5273 | } |
| 5274 | |
| 5275 | template <class _BiIter> |
| 5276 | inline _LIBCPP_INLINE_VISIBILITY |
| 5277 | bool |
| 5278 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5279 | const sub_match<_BiIter>& __y) |
| 5280 | { |
| 5281 | return !(__x == __y); |
| 5282 | } |
| 5283 | |
| 5284 | template <class _BiIter> |
| 5285 | inline _LIBCPP_INLINE_VISIBILITY |
| 5286 | bool |
| 5287 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5288 | const sub_match<_BiIter>& __y) |
| 5289 | { |
| 5290 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5291 | return __y.compare(string_type(1, __x)) > 0; |
| 5292 | } |
| 5293 | |
| 5294 | template <class _BiIter> |
| 5295 | inline _LIBCPP_INLINE_VISIBILITY |
| 5296 | bool |
| 5297 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5298 | const sub_match<_BiIter>& __y) |
| 5299 | { |
| 5300 | return __y < __x; |
| 5301 | } |
| 5302 | |
| 5303 | template <class _BiIter> |
| 5304 | inline _LIBCPP_INLINE_VISIBILITY |
| 5305 | bool |
| 5306 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5307 | const sub_match<_BiIter>& __y) |
| 5308 | { |
| 5309 | return !(__x < __y); |
| 5310 | } |
| 5311 | |
| 5312 | template <class _BiIter> |
| 5313 | inline _LIBCPP_INLINE_VISIBILITY |
| 5314 | bool |
| 5315 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5316 | const sub_match<_BiIter>& __y) |
| 5317 | { |
| 5318 | return !(__y < __x); |
| 5319 | } |
| 5320 | |
| 5321 | template <class _BiIter> |
| 5322 | inline _LIBCPP_INLINE_VISIBILITY |
| 5323 | bool |
| 5324 | operator==(const sub_match<_BiIter>& __x, |
| 5325 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5326 | { |
| 5327 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5328 | return __x.compare(string_type(1, __y)) == 0; |
| 5329 | } |
| 5330 | |
| 5331 | template <class _BiIter> |
| 5332 | inline _LIBCPP_INLINE_VISIBILITY |
| 5333 | bool |
| 5334 | operator!=(const sub_match<_BiIter>& __x, |
| 5335 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5336 | { |
| 5337 | return !(__x == __y); |
| 5338 | } |
| 5339 | |
| 5340 | template <class _BiIter> |
| 5341 | inline _LIBCPP_INLINE_VISIBILITY |
| 5342 | bool |
| 5343 | operator<(const sub_match<_BiIter>& __x, |
| 5344 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5345 | { |
| 5346 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5347 | return __x.compare(string_type(1, __y)) < 0; |
| 5348 | } |
| 5349 | |
| 5350 | template <class _BiIter> |
| 5351 | inline _LIBCPP_INLINE_VISIBILITY |
| 5352 | bool |
| 5353 | operator>(const sub_match<_BiIter>& __x, |
| 5354 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5355 | { |
| 5356 | return __y < __x; |
| 5357 | } |
| 5358 | |
| 5359 | template <class _BiIter> |
| 5360 | inline _LIBCPP_INLINE_VISIBILITY |
| 5361 | bool |
| 5362 | operator>=(const sub_match<_BiIter>& __x, |
| 5363 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5364 | { |
| 5365 | return !(__x < __y); |
| 5366 | } |
| 5367 | |
| 5368 | template <class _BiIter> |
| 5369 | inline _LIBCPP_INLINE_VISIBILITY |
| 5370 | bool |
| 5371 | operator<=(const sub_match<_BiIter>& __x, |
| 5372 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5373 | { |
| 5374 | return !(__y < __x); |
| 5375 | } |
| 5376 | |
| 5377 | template <class _CharT, class _ST, class _BiIter> |
| 5378 | inline _LIBCPP_INLINE_VISIBILITY |
| 5379 | basic_ostream<_CharT, _ST>& |
| 5380 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 5381 | { |
| 5382 | return __os << __m.str(); |
| 5383 | } |
| 5384 | |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5385 | typedef match_results<const char*> cmatch; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5386 | typedef match_results<string::const_iterator> smatch; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5387 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 5388 | typedef match_results<const wchar_t*> wcmatch; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5389 | typedef match_results<wstring::const_iterator> wsmatch; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5390 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5391 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5392 | template <class _BidirectionalIterator, class _Allocator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5393 | class |
| 5394 | _LIBCPP_TEMPLATE_VIS |
| 5395 | _LIBCPP_PREFERRED_NAME(cmatch) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5396 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5397 | _LIBCPP_PREFERRED_NAME(smatch) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5398 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5399 | match_results |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5400 | { |
| 5401 | public: |
| 5402 | typedef _Allocator allocator_type; |
| 5403 | typedef sub_match<_BidirectionalIterator> value_type; |
| 5404 | private: |
| 5405 | typedef vector<value_type, allocator_type> __container_type; |
| 5406 | |
| 5407 | __container_type __matches_; |
| 5408 | value_type __unmatched_; |
| 5409 | value_type __prefix_; |
| 5410 | value_type __suffix_; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5411 | bool __ready_; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5412 | public: |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5413 | _BidirectionalIterator __position_start_; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5414 | typedef const value_type& const_reference; |
Marshall Clow | 96e0614 | 2014-02-26 01:56:31 +0000 | [diff] [blame] | 5415 | typedef value_type& reference; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5416 | typedef typename __container_type::const_iterator const_iterator; |
| 5417 | typedef const_iterator iterator; |
| 5418 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5419 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5420 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5421 | typedef basic_string<char_type> string_type; |
| 5422 | |
| 5423 | // construct/copy/destroy: |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5424 | #ifndef _LIBCPP_CXX03_LANG |
| 5425 | match_results() : match_results(allocator_type()) {} |
| 5426 | explicit match_results(const allocator_type& __a); |
| 5427 | #else |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5428 | explicit match_results(const allocator_type& __a = allocator_type()); |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5429 | #endif |
| 5430 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5431 | // match_results(const match_results&) = default; |
| 5432 | // match_results& operator=(const match_results&) = default; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5433 | // match_results(match_results&& __m) = default; |
| 5434 | // match_results& operator=(match_results&& __m) = default; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5435 | // ~match_results() = default; |
| 5436 | |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5437 | _LIBCPP_INLINE_VISIBILITY |
| 5438 | bool ready() const {return __ready_;} |
| 5439 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5440 | // size: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5441 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 081bcd2 | 2017-11-16 04:48:34 +0000 | [diff] [blame] | 5442 | size_type size() const _NOEXCEPT {return __matches_.size();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5443 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 081bcd2 | 2017-11-16 04:48:34 +0000 | [diff] [blame] | 5444 | size_type max_size() const _NOEXCEPT {return __matches_.max_size();} |
| 5445 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 5446 | bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5447 | |
| 5448 | // element access: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5449 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5450 | difference_type length(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5451 | { |
| 5452 | _LIBCPP_ASSERT(ready(), "match_results::length() called when not ready"); |
| 5453 | return (*this)[__sub].length(); |
| 5454 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5455 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5456 | difference_type position(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5457 | { |
| 5458 | _LIBCPP_ASSERT(ready(), "match_results::position() called when not ready"); |
| 5459 | return _VSTD::distance(__position_start_, (*this)[__sub].first); |
| 5460 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5461 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5462 | string_type str(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5463 | { |
| 5464 | _LIBCPP_ASSERT(ready(), "match_results::str() called when not ready"); |
| 5465 | return (*this)[__sub].str(); |
| 5466 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5467 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5468 | const_reference operator[](size_type __n) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5469 | { |
| 5470 | _LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready"); |
| 5471 | return __n < __matches_.size() ? __matches_[__n] : __unmatched_; |
| 5472 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5473 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5474 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5475 | const_reference prefix() const |
| 5476 | { |
| 5477 | _LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready"); |
| 5478 | return __prefix_; |
| 5479 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5480 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5481 | const_reference suffix() const |
| 5482 | { |
| 5483 | _LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready"); |
| 5484 | return __suffix_; |
| 5485 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5486 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5487 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f4191f | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5488 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5489 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5490 | const_iterator end() const {return __matches_.end();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5491 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f4191f | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5492 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5493 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5494 | const_iterator cend() const {return __matches_.end();} |
| 5495 | |
| 5496 | // format: |
| 5497 | template <class _OutputIter> |
| 5498 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5499 | format(_OutputIter __output_iter, const char_type* __fmt_first, |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5500 | const char_type* __fmt_last, |
| 5501 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5502 | template <class _OutputIter, class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5503 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5504 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5505 | format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5506 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5507 | {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5508 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5509 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5510 | basic_string<char_type, _ST, _SA> |
| 5511 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5512 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5513 | { |
| 5514 | basic_string<char_type, _ST, _SA> __r; |
| 5515 | format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), |
| 5516 | __flags); |
| 5517 | return __r; |
| 5518 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5519 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5520 | string_type |
| 5521 | format(const char_type* __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5522 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5523 | { |
| 5524 | string_type __r; |
| 5525 | format(back_inserter(__r), __fmt, |
| 5526 | __fmt + char_traits<char_type>::length(__fmt), __flags); |
| 5527 | return __r; |
| 5528 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5529 | |
| 5530 | // allocator: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5531 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5532 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5533 | |
| 5534 | // swap: |
| 5535 | void swap(match_results& __m); |
| 5536 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5537 | template <class _Bp, class _Ap> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5538 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5539 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5540 | const match_results<_Bp, _Ap>& __m, bool __no_update_pos) |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5541 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5542 | _Bp __mf = __m.prefix().first; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5543 | __matches_.resize(__m.size()); |
| 5544 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5545 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5546 | __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); |
| 5547 | __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5548 | __matches_[__i].matched = __m[__i].matched; |
| 5549 | } |
| 5550 | __unmatched_.first = __l; |
| 5551 | __unmatched_.second = __l; |
| 5552 | __unmatched_.matched = false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5553 | __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); |
| 5554 | __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5555 | __prefix_.matched = __m.prefix().matched; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5556 | __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); |
| 5557 | __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5558 | __suffix_.matched = __m.suffix().matched; |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5559 | if (!__no_update_pos) |
| 5560 | __position_start_ = __prefix_.first; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5561 | __ready_ = __m.ready(); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5562 | } |
| 5563 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5564 | private: |
| 5565 | void __init(unsigned __s, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5566 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5567 | bool __no_update_pos = false); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5568 | |
| 5569 | template <class, class> friend class basic_regex; |
| 5570 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5571 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5572 | friend |
| 5573 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5574 | 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] | 5575 | regex_constants::match_flag_type); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5576 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5577 | template <class _Bp, class _Ap> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5578 | friend |
| 5579 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5580 | operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5581 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5582 | template <class, class> friend class __lookahead; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5583 | }; |
| 5584 | |
| 5585 | template <class _BidirectionalIterator, class _Allocator> |
| 5586 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5587 | const allocator_type& __a) |
| 5588 | : __matches_(__a), |
| 5589 | __unmatched_(), |
| 5590 | __prefix_(), |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5591 | __suffix_(), |
Eric Fiselier | a75ee26 | 2015-07-22 01:29:41 +0000 | [diff] [blame] | 5592 | __ready_(false), |
| 5593 | __position_start_() |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5594 | { |
| 5595 | } |
| 5596 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5597 | template <class _BidirectionalIterator, class _Allocator> |
| 5598 | void |
| 5599 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5600 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5601 | bool __no_update_pos) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5602 | { |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5603 | __unmatched_.first = __l; |
| 5604 | __unmatched_.second = __l; |
| 5605 | __unmatched_.matched = false; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5606 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5607 | __prefix_.first = __f; |
| 5608 | __prefix_.second = __f; |
| 5609 | __prefix_.matched = false; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5610 | __suffix_ = __unmatched_; |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5611 | if (!__no_update_pos) |
| 5612 | __position_start_ = __prefix_.first; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5613 | __ready_ = true; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5614 | } |
| 5615 | |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5616 | template <class _BidirectionalIterator, class _Allocator> |
| 5617 | template <class _OutputIter> |
| 5618 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5619 | match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5620 | const char_type* __fmt_first, const char_type* __fmt_last, |
| 5621 | regex_constants::match_flag_type __flags) const |
| 5622 | { |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5623 | _LIBCPP_ASSERT(ready(), "match_results::format() called when not ready"); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5624 | if (__flags & regex_constants::format_sed) |
| 5625 | { |
| 5626 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5627 | { |
| 5628 | if (*__fmt_first == '&') |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5629 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 5630 | __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5631 | else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) |
| 5632 | { |
| 5633 | ++__fmt_first; |
| 5634 | if ('0' <= *__fmt_first && *__fmt_first <= '9') |
| 5635 | { |
| 5636 | size_t __i = *__fmt_first - '0'; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5637 | __output_iter = _VSTD::copy((*this)[__i].first, |
| 5638 | (*this)[__i].second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5639 | } |
| 5640 | else |
| 5641 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5642 | *__output_iter = *__fmt_first; |
| 5643 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5644 | } |
| 5645 | } |
| 5646 | else |
| 5647 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5648 | *__output_iter = *__fmt_first; |
| 5649 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5650 | } |
| 5651 | } |
| 5652 | } |
| 5653 | else |
| 5654 | { |
| 5655 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5656 | { |
| 5657 | if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) |
| 5658 | { |
| 5659 | switch (__fmt_first[1]) |
| 5660 | { |
| 5661 | case '$': |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5662 | *__output_iter = *++__fmt_first; |
| 5663 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5664 | break; |
| 5665 | case '&': |
| 5666 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5667 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 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(__prefix_.first, __prefix_.second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5673 | break; |
| 5674 | case '\'': |
| 5675 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5676 | __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5677 | break; |
| 5678 | default: |
| 5679 | if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5680 | { |
| 5681 | ++__fmt_first; |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 5682 | size_t __idx = *__fmt_first - '0'; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5683 | if (__fmt_first + 1 != __fmt_last && |
| 5684 | '0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5685 | { |
| 5686 | ++__fmt_first; |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 5687 | if (__idx >= numeric_limits<size_t>::max() / 10) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 5688 | __throw_regex_error<regex_constants::error_escape>(); |
| 5689 | __idx = 10 * __idx + *__fmt_first - '0'; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5690 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5691 | __output_iter = _VSTD::copy((*this)[__idx].first, |
| 5692 | (*this)[__idx].second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5693 | } |
| 5694 | else |
| 5695 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5696 | *__output_iter = *__fmt_first; |
| 5697 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5698 | } |
| 5699 | break; |
| 5700 | } |
| 5701 | } |
| 5702 | else |
| 5703 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5704 | *__output_iter = *__fmt_first; |
| 5705 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5706 | } |
| 5707 | } |
| 5708 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5709 | return __output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5710 | } |
| 5711 | |
| 5712 | template <class _BidirectionalIterator, class _Allocator> |
| 5713 | void |
| 5714 | match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) |
| 5715 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5716 | using _VSTD::swap; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5717 | swap(__matches_, __m.__matches_); |
| 5718 | swap(__unmatched_, __m.__unmatched_); |
| 5719 | swap(__prefix_, __m.__prefix_); |
| 5720 | swap(__suffix_, __m.__suffix_); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5721 | swap(__position_start_, __m.__position_start_); |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5722 | swap(__ready_, __m.__ready_); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5723 | } |
| 5724 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5725 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5726 | bool |
| 5727 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5728 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5729 | { |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5730 | if (__x.__ready_ != __y.__ready_) |
| 5731 | return false; |
| 5732 | if (!__x.__ready_) |
| 5733 | return true; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5734 | return __x.__matches_ == __y.__matches_ && |
| 5735 | __x.__prefix_ == __y.__prefix_ && |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5736 | __x.__suffix_ == __y.__suffix_; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5737 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5738 | |
| 5739 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5740 | inline _LIBCPP_INLINE_VISIBILITY |
| 5741 | bool |
| 5742 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5743 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5744 | { |
| 5745 | return !(__x == __y); |
| 5746 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5747 | |
| 5748 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5749 | inline _LIBCPP_INLINE_VISIBILITY |
| 5750 | void |
| 5751 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5752 | match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5753 | { |
| 5754 | __x.swap(__y); |
| 5755 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5756 | |
| 5757 | // regex_search |
| 5758 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5759 | template <class _CharT, class _Traits> |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5760 | template <class _Allocator> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5761 | bool |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5762 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5763 | const _CharT* __first, const _CharT* __last, |
| 5764 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5765 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5766 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5767 | vector<__state> __states; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5768 | __node* __st = __start_.get(); |
| 5769 | if (__st) |
| 5770 | { |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5771 | sub_match<const _CharT*> __unmatched; |
| 5772 | __unmatched.first = __last; |
| 5773 | __unmatched.second = __last; |
| 5774 | __unmatched.matched = false; |
| 5775 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5776 | __states.push_back(__state()); |
| 5777 | __states.back().__do_ = 0; |
| 5778 | __states.back().__first_ = __first; |
| 5779 | __states.back().__current_ = __first; |
| 5780 | __states.back().__last_ = __last; |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5781 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5782 | __states.back().__loop_data_.resize(__loop_count()); |
| 5783 | __states.back().__node_ = __st; |
| 5784 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5785 | __states.back().__at_first_ = __at_first; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5786 | int __counter = 0; |
| 5787 | int __length = __last - __first; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5788 | do |
| 5789 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5790 | ++__counter; |
| 5791 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5792 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5793 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5794 | __state& __s = __states.back(); |
| 5795 | if (__s.__node_) |
| 5796 | __s.__node_->__exec(__s); |
| 5797 | switch (__s.__do_) |
| 5798 | { |
| 5799 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5800 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5801 | __s.__current_ == __first) |
| 5802 | { |
| 5803 | __states.pop_back(); |
| 5804 | break; |
| 5805 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5806 | if ((__flags & regex_constants::__full_match) && |
| 5807 | __s.__current_ != __last) |
| 5808 | { |
| 5809 | __states.pop_back(); |
| 5810 | break; |
| 5811 | } |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5812 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5813 | __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5814 | __m.__matches_[0].matched = true; |
| 5815 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5816 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5817 | return true; |
| 5818 | case __state::__accept_and_consume: |
| 5819 | case __state::__repeat: |
| 5820 | case __state::__accept_but_not_consume: |
| 5821 | break; |
| 5822 | case __state::__split: |
| 5823 | { |
| 5824 | __state __snext = __s; |
| 5825 | __s.__node_->__exec_split(true, __s); |
| 5826 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5827 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5828 | } |
| 5829 | break; |
| 5830 | case __state::__reject: |
| 5831 | __states.pop_back(); |
| 5832 | break; |
| 5833 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5834 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5835 | break; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5836 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5837 | } |
| 5838 | } while (!__states.empty()); |
| 5839 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5840 | return false; |
| 5841 | } |
| 5842 | |
| 5843 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5844 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5845 | bool |
| 5846 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5847 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5848 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5849 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5850 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5851 | deque<__state> __states; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5852 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5853 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5854 | __node* __st = __start_.get(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5855 | if (__st) |
| 5856 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5857 | __states.push_back(__state()); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5858 | __states.back().__do_ = 0; |
| 5859 | __states.back().__first_ = __first; |
| 5860 | __states.back().__current_ = __first; |
| 5861 | __states.back().__last_ = __last; |
| 5862 | __states.back().__loop_data_.resize(__loop_count()); |
| 5863 | __states.back().__node_ = __st; |
| 5864 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5865 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5866 | bool __matched = false; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5867 | int __counter = 0; |
| 5868 | int __length = __last - __first; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5869 | do |
| 5870 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5871 | ++__counter; |
| 5872 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5873 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5874 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5875 | __state& __s = __states.back(); |
| 5876 | if (__s.__node_) |
| 5877 | __s.__node_->__exec(__s); |
| 5878 | switch (__s.__do_) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5879 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5880 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5881 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5882 | __s.__current_ == __first) |
| 5883 | { |
| 5884 | __states.pop_back(); |
| 5885 | break; |
| 5886 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5887 | if ((__flags & regex_constants::__full_match) && |
| 5888 | __s.__current_ != __last) |
| 5889 | { |
| 5890 | __states.pop_back(); |
| 5891 | break; |
| 5892 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5893 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5894 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5895 | __matched = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5896 | if (__highest_j == _Np) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5897 | __states.clear(); |
| 5898 | else |
| 5899 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5900 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5901 | case __state::__consume_input: |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5902 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5903 | case __state::__accept_and_consume: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5904 | __states.push_front(_VSTD::move(__s)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5905 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5906 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5907 | case __state::__repeat: |
| 5908 | case __state::__accept_but_not_consume: |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5909 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5910 | case __state::__split: |
| 5911 | { |
| 5912 | __state __snext = __s; |
| 5913 | __s.__node_->__exec_split(true, __s); |
| 5914 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5915 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5916 | } |
| 5917 | break; |
| 5918 | case __state::__reject: |
| 5919 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5920 | break; |
| 5921 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5922 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5923 | break; |
| 5924 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5925 | } while (!__states.empty()); |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5926 | if (__matched) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5927 | { |
| 5928 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5929 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5930 | __m.__matches_[0].matched = true; |
| 5931 | return true; |
| 5932 | } |
| 5933 | } |
| 5934 | return false; |
| 5935 | } |
| 5936 | |
| 5937 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5938 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5939 | bool |
| 5940 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5941 | const _CharT* __first, const _CharT* __last, |
| 5942 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5943 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5944 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5945 | vector<__state> __states; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5946 | __state __best_state; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5947 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5948 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5949 | __node* __st = __start_.get(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5950 | if (__st) |
| 5951 | { |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5952 | sub_match<const _CharT*> __unmatched; |
| 5953 | __unmatched.first = __last; |
| 5954 | __unmatched.second = __last; |
| 5955 | __unmatched.matched = false; |
| 5956 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5957 | __states.push_back(__state()); |
| 5958 | __states.back().__do_ = 0; |
| 5959 | __states.back().__first_ = __first; |
| 5960 | __states.back().__current_ = __first; |
| 5961 | __states.back().__last_ = __last; |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5962 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5963 | __states.back().__loop_data_.resize(__loop_count()); |
| 5964 | __states.back().__node_ = __st; |
| 5965 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5966 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5967 | bool __matched = false; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5968 | int __counter = 0; |
| 5969 | int __length = __last - __first; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5970 | do |
| 5971 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5972 | ++__counter; |
| 5973 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5974 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5975 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5976 | __state& __s = __states.back(); |
| 5977 | if (__s.__node_) |
| 5978 | __s.__node_->__exec(__s); |
| 5979 | switch (__s.__do_) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5980 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5981 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5982 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5983 | __s.__current_ == __first) |
| 5984 | { |
| 5985 | __states.pop_back(); |
| 5986 | break; |
| 5987 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5988 | if ((__flags & regex_constants::__full_match) && |
| 5989 | __s.__current_ != __last) |
| 5990 | { |
| 5991 | __states.pop_back(); |
| 5992 | break; |
| 5993 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5994 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5995 | { |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5996 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5997 | __best_state = __s; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5998 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5999 | __matched = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6000 | if (__highest_j == _Np) |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 6001 | __states.clear(); |
| 6002 | else |
| 6003 | __states.pop_back(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6004 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6005 | case __state::__accept_and_consume: |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6006 | case __state::__repeat: |
| 6007 | case __state::__accept_but_not_consume: |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6008 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6009 | case __state::__split: |
| 6010 | { |
| 6011 | __state __snext = __s; |
| 6012 | __s.__node_->__exec_split(true, __s); |
| 6013 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6014 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6015 | } |
| 6016 | break; |
| 6017 | case __state::__reject: |
| 6018 | __states.pop_back(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6019 | break; |
| 6020 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 6021 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6022 | break; |
| 6023 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6024 | } while (!__states.empty()); |
| 6025 | if (__matched) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6026 | { |
| 6027 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6028 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6029 | __m.__matches_[0].matched = true; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6030 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 6031 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6032 | return true; |
| 6033 | } |
| 6034 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6035 | return false; |
| 6036 | } |
| 6037 | |
| 6038 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6039 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6040 | bool |
| 6041 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6042 | const _CharT* __first, const _CharT* __last, |
| 6043 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6044 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6045 | { |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 6046 | if (__get_grammar(__flags_) == ECMAScript) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6047 | return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6048 | if (mark_count() == 0) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6049 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |
| 6050 | return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6054 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6055 | bool |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6056 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6057 | const _CharT* __first, const _CharT* __last, |
| 6058 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6059 | regex_constants::match_flag_type __flags) const |
| 6060 | { |
Diogo Sampaio | 300ade7 | 2020-04-30 23:34:01 +0100 | [diff] [blame] | 6061 | if (__flags & regex_constants::match_prev_avail) |
| 6062 | __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow); |
| 6063 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6064 | __m.__init(1 + mark_count(), __first, __last, |
| 6065 | __flags & regex_constants::__no_update_pos); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6066 | if (__match_at_start(__first, __last, __m, __flags, |
Howard Hinnant | 38d14f7 | 2013-07-09 17:29:09 +0000 | [diff] [blame] | 6067 | !(__flags & regex_constants::__no_update_pos))) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6068 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6069 | __m.__prefix_.second = __m[0].first; |
| 6070 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 6071 | __m.__suffix_.first = __m[0].second; |
| 6072 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 6073 | return true; |
| 6074 | } |
Howard Hinnant | 22cf486 | 2010-07-29 01:15:27 +0000 | [diff] [blame] | 6075 | if (__first != __last && !(__flags & regex_constants::match_continuous)) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6076 | { |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 6077 | __flags |= regex_constants::match_prev_avail; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6078 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6079 | { |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 6080 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6081 | if (__match_at_start(__first, __last, __m, __flags, false)) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6082 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6083 | __m.__prefix_.second = __m[0].first; |
| 6084 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 6085 | __m.__suffix_.first = __m[0].second; |
| 6086 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 6087 | return true; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6088 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6089 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6090 | } |
| 6091 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6092 | __m.__matches_.clear(); |
| 6093 | return false; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6094 | } |
| 6095 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6096 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6097 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6098 | bool |
| 6099 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6100 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6101 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6102 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6103 | { |
Howard Hinnant | 1e5de64 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 6104 | int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0; |
| 6105 | basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6106 | match_results<const _CharT*> __mc; |
Howard Hinnant | 1e5de64 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 6107 | 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] | 6108 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6109 | return __r; |
| 6110 | } |
| 6111 | |
Howard Hinnant | 4018c48 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 6112 | template <class _Iter, class _Allocator, class _CharT, class _Traits> |
| 6113 | inline _LIBCPP_INLINE_VISIBILITY |
| 6114 | bool |
| 6115 | regex_search(__wrap_iter<_Iter> __first, |
| 6116 | __wrap_iter<_Iter> __last, |
| 6117 | match_results<__wrap_iter<_Iter>, _Allocator>& __m, |
| 6118 | const basic_regex<_CharT, _Traits>& __e, |
| 6119 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6120 | { |
| 6121 | match_results<const _CharT*> __mc; |
| 6122 | bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags); |
| 6123 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
| 6124 | return __r; |
| 6125 | } |
| 6126 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6127 | template <class _Allocator, class _CharT, class _Traits> |
| 6128 | inline _LIBCPP_INLINE_VISIBILITY |
| 6129 | bool |
| 6130 | regex_search(const _CharT* __first, const _CharT* __last, |
| 6131 | match_results<const _CharT*, _Allocator>& __m, |
| 6132 | const basic_regex<_CharT, _Traits>& __e, |
| 6133 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6134 | { |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6135 | return __e.__search(__first, __last, __m, __flags); |
| 6136 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6137 | |
| 6138 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6139 | inline _LIBCPP_INLINE_VISIBILITY |
| 6140 | bool |
| 6141 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6142 | const basic_regex<_CharT, _Traits>& __e, |
| 6143 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6144 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6145 | basic_string<_CharT> __s(__first, __last); |
| 6146 | match_results<const _CharT*> __mc; |
| 6147 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 6148 | } |
| 6149 | |
| 6150 | template <class _CharT, class _Traits> |
| 6151 | inline _LIBCPP_INLINE_VISIBILITY |
| 6152 | bool |
| 6153 | regex_search(const _CharT* __first, const _CharT* __last, |
| 6154 | const basic_regex<_CharT, _Traits>& __e, |
| 6155 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6156 | { |
| 6157 | match_results<const _CharT*> __mc; |
| 6158 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6159 | } |
| 6160 | |
| 6161 | template <class _CharT, class _Allocator, class _Traits> |
| 6162 | inline _LIBCPP_INLINE_VISIBILITY |
| 6163 | bool |
| 6164 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6165 | const basic_regex<_CharT, _Traits>& __e, |
| 6166 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6167 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6168 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | template <class _CharT, class _Traits> |
| 6172 | inline _LIBCPP_INLINE_VISIBILITY |
| 6173 | bool |
| 6174 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6175 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6176 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6177 | match_results<const _CharT*> __m; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6178 | return _VSTD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6182 | inline _LIBCPP_INLINE_VISIBILITY |
| 6183 | bool |
| 6184 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6185 | const basic_regex<_CharT, _Traits>& __e, |
| 6186 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6187 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6188 | match_results<const _CharT*> __mc; |
| 6189 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6190 | } |
| 6191 | |
| 6192 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6193 | inline _LIBCPP_INLINE_VISIBILITY |
| 6194 | bool |
| 6195 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6196 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6197 | const basic_regex<_CharT, _Traits>& __e, |
| 6198 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6199 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6200 | match_results<const _CharT*> __mc; |
| 6201 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6202 | __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] | 6203 | return __r; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6204 | } |
| 6205 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6206 | #if _LIBCPP_STD_VER > 11 |
| 6207 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
| 6208 | bool |
| 6209 | regex_search(const basic_string<_Cp, _ST, _SA>&& __s, |
| 6210 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 6211 | const basic_regex<_Cp, _Tp>& __e, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6212 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6213 | #endif |
| 6214 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6215 | // regex_match |
| 6216 | |
| 6217 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 6218 | bool |
| 6219 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6220 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6221 | const basic_regex<_CharT, _Traits>& __e, |
| 6222 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6223 | { |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 6224 | bool __r = _VSTD::regex_search( |
| 6225 | __first, __last, __m, __e, |
| 6226 | __flags | regex_constants::match_continuous | |
| 6227 | regex_constants::__full_match); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6228 | if (__r) |
| 6229 | { |
| 6230 | __r = !__m.suffix().matched; |
| 6231 | if (!__r) |
| 6232 | __m.__matches_.clear(); |
| 6233 | } |
| 6234 | return __r; |
| 6235 | } |
| 6236 | |
| 6237 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6238 | inline _LIBCPP_INLINE_VISIBILITY |
| 6239 | bool |
| 6240 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6241 | const basic_regex<_CharT, _Traits>& __e, |
| 6242 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6243 | { |
| 6244 | match_results<_BidirectionalIterator> __m; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6245 | return _VSTD::regex_match(__first, __last, __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6246 | } |
| 6247 | |
| 6248 | template <class _CharT, class _Allocator, class _Traits> |
| 6249 | inline _LIBCPP_INLINE_VISIBILITY |
| 6250 | bool |
| 6251 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6252 | const basic_regex<_CharT, _Traits>& __e, |
| 6253 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6254 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6255 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6256 | } |
| 6257 | |
| 6258 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6259 | inline _LIBCPP_INLINE_VISIBILITY |
| 6260 | bool |
| 6261 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6262 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6263 | const basic_regex<_CharT, _Traits>& __e, |
| 6264 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6265 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6266 | return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6267 | } |
| 6268 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6269 | #if _LIBCPP_STD_VER > 11 |
| 6270 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6271 | inline _LIBCPP_INLINE_VISIBILITY |
| 6272 | bool |
| 6273 | regex_match(const basic_string<_CharT, _ST, _SA>&& __s, |
| 6274 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6275 | const basic_regex<_CharT, _Traits>& __e, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6276 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6277 | #endif |
| 6278 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6279 | template <class _CharT, class _Traits> |
| 6280 | inline _LIBCPP_INLINE_VISIBILITY |
| 6281 | bool |
| 6282 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6283 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6284 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6285 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6286 | } |
| 6287 | |
| 6288 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6289 | inline _LIBCPP_INLINE_VISIBILITY |
| 6290 | bool |
| 6291 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6292 | const basic_regex<_CharT, _Traits>& __e, |
| 6293 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6294 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6295 | return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6296 | } |
| 6297 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6298 | // regex_iterator |
| 6299 | |
| 6300 | template <class _BidirectionalIterator, |
| 6301 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6302 | class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6303 | class _LIBCPP_TEMPLATE_VIS regex_iterator; |
| 6304 | |
| 6305 | typedef regex_iterator<const char*> cregex_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6306 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6307 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6308 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6309 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6310 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6311 | |
| 6312 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6313 | class |
| 6314 | _LIBCPP_TEMPLATE_VIS |
| 6315 | _LIBCPP_PREFERRED_NAME(cregex_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6316 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6317 | _LIBCPP_PREFERRED_NAME(sregex_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6318 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6319 | regex_iterator |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6320 | { |
| 6321 | public: |
| 6322 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6323 | typedef match_results<_BidirectionalIterator> value_type; |
| 6324 | typedef ptrdiff_t difference_type; |
| 6325 | typedef const value_type* pointer; |
| 6326 | typedef const value_type& reference; |
| 6327 | typedef forward_iterator_tag iterator_category; |
| 6328 | |
| 6329 | private: |
| 6330 | _BidirectionalIterator __begin_; |
| 6331 | _BidirectionalIterator __end_; |
| 6332 | const regex_type* __pregex_; |
| 6333 | regex_constants::match_flag_type __flags_; |
| 6334 | value_type __match_; |
| 6335 | |
| 6336 | public: |
| 6337 | regex_iterator(); |
| 6338 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6339 | const regex_type& __re, |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6340 | regex_constants::match_flag_type __m |
| 6341 | = regex_constants::match_default); |
| 6342 | #if _LIBCPP_STD_VER > 11 |
| 6343 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6344 | const regex_type&& __re, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6345 | regex_constants::match_flag_type __m |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6346 | = regex_constants::match_default) = delete; |
| 6347 | #endif |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6348 | |
| 6349 | bool operator==(const regex_iterator& __x) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6350 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6351 | bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} |
| 6352 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6353 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6354 | reference operator*() const {return __match_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6355 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6356 | pointer operator->() const {return _VSTD::addressof(__match_);} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6357 | |
| 6358 | regex_iterator& operator++(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6359 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6360 | regex_iterator operator++(int) |
| 6361 | { |
| 6362 | regex_iterator __t(*this); |
| 6363 | ++(*this); |
| 6364 | return __t; |
| 6365 | } |
| 6366 | }; |
| 6367 | |
| 6368 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6369 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() |
| 6370 | : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() |
| 6371 | { |
| 6372 | } |
| 6373 | |
| 6374 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6375 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6376 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6377 | const regex_type& __re, regex_constants::match_flag_type __m) |
| 6378 | : __begin_(__a), |
| 6379 | __end_(__b), |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6380 | __pregex_(_VSTD::addressof(__re)), |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6381 | __flags_(__m) |
| 6382 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6383 | _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6384 | } |
| 6385 | |
| 6386 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6387 | bool |
| 6388 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6389 | operator==(const regex_iterator& __x) const |
| 6390 | { |
| 6391 | if (__match_.empty() && __x.__match_.empty()) |
| 6392 | return true; |
| 6393 | if (__match_.empty() || __x.__match_.empty()) |
| 6394 | return false; |
| 6395 | return __begin_ == __x.__begin_ && |
| 6396 | __end_ == __x.__end_ && |
| 6397 | __pregex_ == __x.__pregex_ && |
| 6398 | __flags_ == __x.__flags_ && |
| 6399 | __match_[0] == __x.__match_[0]; |
| 6400 | } |
| 6401 | |
| 6402 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6403 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6404 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6405 | { |
| 6406 | __flags_ |= regex_constants::__no_update_pos; |
| 6407 | _BidirectionalIterator __start = __match_[0].second; |
Marshall Clow | faa964d | 2017-07-05 16:37:19 +0000 | [diff] [blame] | 6408 | if (__match_[0].first == __match_[0].second) |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6409 | { |
| 6410 | if (__start == __end_) |
| 6411 | { |
| 6412 | __match_ = value_type(); |
| 6413 | return *this; |
| 6414 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6415 | else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6416 | __flags_ | regex_constants::match_not_null | |
| 6417 | regex_constants::match_continuous)) |
| 6418 | return *this; |
| 6419 | else |
| 6420 | ++__start; |
| 6421 | } |
| 6422 | __flags_ |= regex_constants::match_prev_avail; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6423 | if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6424 | __match_ = value_type(); |
| 6425 | return *this; |
| 6426 | } |
| 6427 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6428 | // regex_token_iterator |
| 6429 | |
| 6430 | template <class _BidirectionalIterator, |
| 6431 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6432 | class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6433 | class _LIBCPP_TEMPLATE_VIS regex_token_iterator; |
| 6434 | |
| 6435 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6436 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6437 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6438 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6439 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6440 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6441 | |
| 6442 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6443 | class |
| 6444 | _LIBCPP_TEMPLATE_VIS |
| 6445 | _LIBCPP_PREFERRED_NAME(cregex_token_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6446 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6447 | _LIBCPP_PREFERRED_NAME(sregex_token_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6448 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6449 | regex_token_iterator |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6450 | { |
| 6451 | public: |
| 6452 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6453 | typedef sub_match<_BidirectionalIterator> value_type; |
| 6454 | typedef ptrdiff_t difference_type; |
| 6455 | typedef const value_type* pointer; |
| 6456 | typedef const value_type& reference; |
| 6457 | typedef forward_iterator_tag iterator_category; |
| 6458 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6459 | private: |
| 6460 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; |
| 6461 | |
| 6462 | _Position __position_; |
| 6463 | const value_type* __result_; |
| 6464 | value_type __suffix_; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6465 | ptrdiff_t __n_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6466 | vector<int> __subs_; |
| 6467 | |
| 6468 | public: |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6469 | regex_token_iterator(); |
| 6470 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6471 | const regex_type& __re, int __submatch = 0, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6472 | regex_constants::match_flag_type __m = |
| 6473 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6474 | #if _LIBCPP_STD_VER > 11 |
| 6475 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6476 | const regex_type&& __re, int __submatch = 0, |
| 6477 | regex_constants::match_flag_type __m = |
| 6478 | regex_constants::match_default) = delete; |
| 6479 | #endif |
| 6480 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6481 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6482 | const regex_type& __re, const vector<int>& __submatches, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6483 | regex_constants::match_flag_type __m = |
| 6484 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6485 | #if _LIBCPP_STD_VER > 11 |
| 6486 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6487 | const regex_type&& __re, const vector<int>& __submatches, |
| 6488 | regex_constants::match_flag_type __m = |
| 6489 | regex_constants::match_default) = delete; |
| 6490 | #endif |
| 6491 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 6492 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6493 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6494 | const regex_type& __re, |
| 6495 | initializer_list<int> __submatches, |
| 6496 | regex_constants::match_flag_type __m = |
| 6497 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6498 | |
| 6499 | #if _LIBCPP_STD_VER > 11 |
| 6500 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6501 | const regex_type&& __re, |
| 6502 | initializer_list<int> __submatches, |
| 6503 | regex_constants::match_flag_type __m = |
| 6504 | regex_constants::match_default) = delete; |
| 6505 | #endif |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6506 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6507 | template <size_t _Np> |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6508 | regex_token_iterator(_BidirectionalIterator __a, |
| 6509 | _BidirectionalIterator __b, |
| 6510 | const regex_type& __re, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6511 | const int (&__submatches)[_Np], |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6512 | regex_constants::match_flag_type __m = |
| 6513 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6514 | #if _LIBCPP_STD_VER > 11 |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 6515 | template <size_t _Np> |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6516 | regex_token_iterator(_BidirectionalIterator __a, |
| 6517 | _BidirectionalIterator __b, |
| 6518 | const regex_type&& __re, |
| 6519 | const int (&__submatches)[_Np], |
| 6520 | regex_constants::match_flag_type __m = |
| 6521 | regex_constants::match_default) = delete; |
| 6522 | #endif |
| 6523 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6524 | regex_token_iterator(const regex_token_iterator&); |
| 6525 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 6526 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6527 | bool operator==(const regex_token_iterator& __x) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6528 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6529 | bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6530 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6531 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6532 | const value_type& operator*() const {return *__result_;} |
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 | const value_type* operator->() const {return __result_;} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6535 | |
| 6536 | regex_token_iterator& operator++(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6537 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6538 | regex_token_iterator operator++(int) |
| 6539 | { |
| 6540 | regex_token_iterator __t(*this); |
| 6541 | ++(*this); |
| 6542 | return __t; |
| 6543 | } |
| 6544 | |
| 6545 | private: |
| 6546 | void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6547 | void __establish_result () { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6548 | if (__subs_[__n_] == -1) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6549 | __result_ = &__position_->prefix(); |
| 6550 | else |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6551 | __result_ = &(*__position_)[__subs_[__n_]]; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6552 | } |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6553 | }; |
| 6554 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6555 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6556 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6557 | regex_token_iterator() |
| 6558 | : __result_(nullptr), |
| 6559 | __suffix_(), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6560 | __n_(0) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6561 | { |
| 6562 | } |
| 6563 | |
| 6564 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6565 | void |
| 6566 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6567 | __init(_BidirectionalIterator __a, _BidirectionalIterator __b) |
| 6568 | { |
| 6569 | if (__position_ != _Position()) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6570 | __establish_result (); |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6571 | else if (__subs_[__n_] == -1) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6572 | { |
| 6573 | __suffix_.matched = true; |
| 6574 | __suffix_.first = __a; |
| 6575 | __suffix_.second = __b; |
| 6576 | __result_ = &__suffix_; |
| 6577 | } |
| 6578 | else |
| 6579 | __result_ = nullptr; |
| 6580 | } |
| 6581 | |
| 6582 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6583 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6584 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6585 | const regex_type& __re, int __submatch, |
| 6586 | regex_constants::match_flag_type __m) |
| 6587 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6588 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6589 | __subs_(1, __submatch) |
| 6590 | { |
| 6591 | __init(__a, __b); |
| 6592 | } |
| 6593 | |
| 6594 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6595 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6596 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6597 | const regex_type& __re, const vector<int>& __submatches, |
| 6598 | regex_constants::match_flag_type __m) |
| 6599 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6600 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6601 | __subs_(__submatches) |
| 6602 | { |
| 6603 | __init(__a, __b); |
| 6604 | } |
| 6605 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 6606 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6607 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6608 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6609 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6610 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6611 | const regex_type& __re, |
| 6612 | initializer_list<int> __submatches, |
| 6613 | regex_constants::match_flag_type __m) |
| 6614 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6615 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6616 | __subs_(__submatches) |
| 6617 | { |
| 6618 | __init(__a, __b); |
| 6619 | } |
| 6620 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6621 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6622 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6623 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6624 | template <size_t _Np> |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6625 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6626 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6627 | const regex_type& __re, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6628 | const int (&__submatches)[_Np], |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6629 | regex_constants::match_flag_type __m) |
| 6630 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6631 | __n_(0), |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6632 | __subs_(begin(__submatches), end(__submatches)) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6633 | { |
| 6634 | __init(__a, __b); |
| 6635 | } |
| 6636 | |
| 6637 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6638 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6639 | regex_token_iterator(const regex_token_iterator& __x) |
| 6640 | : __position_(__x.__position_), |
| 6641 | __result_(__x.__result_), |
| 6642 | __suffix_(__x.__suffix_), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6643 | __n_(__x.__n_), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6644 | __subs_(__x.__subs_) |
| 6645 | { |
| 6646 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 20756ac | 2014-01-13 17:47:08 +0000 | [diff] [blame] | 6647 | __result_ = &__suffix_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6648 | else if ( __result_ != nullptr ) |
| 6649 | __establish_result (); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6650 | } |
| 6651 | |
| 6652 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6653 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6654 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6655 | operator=(const regex_token_iterator& __x) |
| 6656 | { |
| 6657 | if (this != &__x) |
| 6658 | { |
| 6659 | __position_ = __x.__position_; |
| 6660 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6661 | __result_ = &__suffix_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6662 | else |
| 6663 | __result_ = __x.__result_; |
| 6664 | __suffix_ = __x.__suffix_; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6665 | __n_ = __x.__n_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6666 | __subs_ = __x.__subs_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6667 | |
| 6668 | if ( __result_ != nullptr && __result_ != &__suffix_ ) |
| 6669 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6670 | } |
| 6671 | return *this; |
| 6672 | } |
| 6673 | |
| 6674 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6675 | bool |
| 6676 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6677 | operator==(const regex_token_iterator& __x) const |
| 6678 | { |
| 6679 | if (__result_ == nullptr && __x.__result_ == nullptr) |
| 6680 | return true; |
| 6681 | if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && |
| 6682 | __suffix_ == __x.__suffix_) |
| 6683 | return true; |
| 6684 | if (__result_ == nullptr || __x.__result_ == nullptr) |
| 6685 | return false; |
| 6686 | if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) |
| 6687 | return false; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6688 | return __position_ == __x.__position_ && __n_ == __x.__n_ && |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6689 | __subs_ == __x.__subs_; |
| 6690 | } |
| 6691 | |
| 6692 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6693 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6694 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6695 | { |
| 6696 | _Position __prev = __position_; |
| 6697 | if (__result_ == &__suffix_) |
| 6698 | __result_ = nullptr; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6699 | else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6700 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6701 | ++__n_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6702 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6703 | } |
| 6704 | else |
| 6705 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6706 | __n_ = 0; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6707 | ++__position_; |
| 6708 | if (__position_ != _Position()) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6709 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6710 | else |
| 6711 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6712 | if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6713 | && __prev->suffix().length() != 0) |
| 6714 | { |
| 6715 | __suffix_.matched = true; |
| 6716 | __suffix_.first = __prev->suffix().first; |
| 6717 | __suffix_.second = __prev->suffix().second; |
| 6718 | __result_ = &__suffix_; |
| 6719 | } |
| 6720 | else |
| 6721 | __result_ = nullptr; |
| 6722 | } |
| 6723 | } |
| 6724 | return *this; |
| 6725 | } |
| 6726 | |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6727 | // regex_replace |
| 6728 | |
| 6729 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6730 | class _Traits, class _CharT> |
| 6731 | _OutputIterator |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6732 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6733 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6734 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6735 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6736 | { |
| 6737 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; |
| 6738 | _Iter __i(__first, __last, __e, __flags); |
| 6739 | _Iter __eof; |
| 6740 | if (__i == __eof) |
| 6741 | { |
| 6742 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6743 | __output_iter = _VSTD::copy(__first, __last, __output_iter); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6744 | } |
| 6745 | else |
| 6746 | { |
| 6747 | sub_match<_BidirectionalIterator> __lm; |
| 6748 | for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) |
| 6749 | { |
| 6750 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6751 | __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter); |
| 6752 | __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6753 | __lm = __i->suffix(); |
| 6754 | if (__flags & regex_constants::format_first_only) |
| 6755 | break; |
| 6756 | } |
| 6757 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6758 | __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6759 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6760 | return __output_iter; |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6764 | class _Traits, class _CharT, class _ST, class _SA> |
| 6765 | inline _LIBCPP_INLINE_VISIBILITY |
| 6766 | _OutputIterator |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6767 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6768 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6769 | const basic_regex<_CharT, _Traits>& __e, |
| 6770 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6771 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6772 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6773 | 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] | 6774 | } |
| 6775 | |
| 6776 | template <class _Traits, class _CharT, class _ST, class _SA, class _FST, |
| 6777 | class _FSA> |
| 6778 | inline _LIBCPP_INLINE_VISIBILITY |
| 6779 | basic_string<_CharT, _ST, _SA> |
| 6780 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6781 | const basic_regex<_CharT, _Traits>& __e, |
| 6782 | const basic_string<_CharT, _FST, _FSA>& __fmt, |
| 6783 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6784 | { |
| 6785 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6786 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6787 | __fmt.c_str(), __flags); |
| 6788 | return __r; |
| 6789 | } |
| 6790 | |
| 6791 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6792 | inline _LIBCPP_INLINE_VISIBILITY |
| 6793 | basic_string<_CharT, _ST, _SA> |
| 6794 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6795 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6796 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6797 | { |
| 6798 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6799 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6800 | __fmt, __flags); |
| 6801 | return __r; |
| 6802 | } |
| 6803 | |
| 6804 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6805 | inline _LIBCPP_INLINE_VISIBILITY |
| 6806 | basic_string<_CharT> |
| 6807 | regex_replace(const _CharT* __s, |
| 6808 | const basic_regex<_CharT, _Traits>& __e, |
| 6809 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6810 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6811 | { |
| 6812 | basic_string<_CharT> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6813 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6814 | __s + char_traits<_CharT>::length(__s), __e, |
| 6815 | __fmt.c_str(), __flags); |
| 6816 | return __r; |
| 6817 | } |
| 6818 | |
| 6819 | template <class _Traits, class _CharT> |
| 6820 | inline _LIBCPP_INLINE_VISIBILITY |
| 6821 | basic_string<_CharT> |
| 6822 | regex_replace(const _CharT* __s, |
| 6823 | const basic_regex<_CharT, _Traits>& __e, |
| 6824 | const _CharT* __fmt, |
| 6825 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6826 | { |
| 6827 | basic_string<_CharT> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6828 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6829 | __s + char_traits<_CharT>::length(__s), __e, |
| 6830 | __fmt, __flags); |
| 6831 | return __r; |
| 6832 | } |
| 6833 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 6834 | _LIBCPP_END_NAMESPACE_STD |
| 6835 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 6836 | _LIBCPP_POP_MACROS |
| 6837 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6838 | #endif // _LIBCPP_REGEX |