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> |
Louis Dionne | 9bdbeb3 | 2022-02-14 13:41:09 -0500 | [diff] [blame] | 766 | #include <__assert> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 767 | #include <__config> |
Louis Dionne | 7724952 | 2021-06-11 09:55:11 -0400 | [diff] [blame] | 768 | #include <__iterator/wrap_iter.h> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 769 | #include <__locale> |
Nikolas Klauser | 8fccd62 | 2022-03-05 19:17:07 +0100 | [diff] [blame] | 770 | #include <__utility/move.h> |
| 771 | #include <__utility/swap.h> |
Arthur O'Dwyer | 7deec12 | 2021-03-24 18:19:12 -0400 | [diff] [blame] | 772 | #include <compare> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 773 | #include <deque> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 774 | #include <initializer_list> |
| 775 | #include <iterator> |
| 776 | #include <memory> |
| 777 | #include <stdexcept> |
| 778 | #include <string> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 779 | #include <vector> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 780 | #include <version> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 781 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 782 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Arthur O'Dwyer | 6eeaa00 | 2022-02-01 20:16:40 -0500 | [diff] [blame] | 783 | # pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 784 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 785 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 786 | _LIBCPP_PUSH_MACROS |
| 787 | #include <__undef_macros> |
| 788 | |
| 789 | |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 790 | #define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096 |
| 791 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 792 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 793 | |
| 794 | namespace regex_constants |
| 795 | { |
| 796 | |
| 797 | // syntax_option_type |
| 798 | |
| 799 | enum syntax_option_type |
| 800 | { |
| 801 | icase = 1 << 0, |
| 802 | nosubs = 1 << 1, |
| 803 | optimize = 1 << 2, |
| 804 | collate = 1 << 3, |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 805 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 806 | ECMAScript = 1 << 9, |
| 807 | #else |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 808 | ECMAScript = 0, |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 809 | #endif |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 810 | basic = 1 << 4, |
| 811 | extended = 1 << 5, |
| 812 | awk = 1 << 6, |
| 813 | grep = 1 << 7, |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 814 | egrep = 1 << 8, |
| 815 | // 1 << 9 may be used by ECMAScript |
| 816 | multiline = 1 << 10 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 817 | }; |
| 818 | |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 819 | inline _LIBCPP_CONSTEXPR |
| 820 | syntax_option_type __get_grammar(syntax_option_type __g) |
| 821 | { |
| 822 | #ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO |
| 823 | return static_cast<syntax_option_type>(__g & 0x3F0); |
| 824 | #else |
| 825 | return static_cast<syntax_option_type>(__g & 0x1F0); |
| 826 | #endif |
| 827 | } |
| 828 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 829 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 830 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 831 | syntax_option_type |
| 832 | operator~(syntax_option_type __x) |
| 833 | { |
Marshall Clow | 924cffa | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 834 | return syntax_option_type(~int(__x) & 0x1FF); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 835 | } |
| 836 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 837 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 838 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 839 | syntax_option_type |
| 840 | operator&(syntax_option_type __x, syntax_option_type __y) |
| 841 | { |
| 842 | return syntax_option_type(int(__x) & int(__y)); |
| 843 | } |
| 844 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 845 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 846 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 847 | syntax_option_type |
| 848 | operator|(syntax_option_type __x, syntax_option_type __y) |
| 849 | { |
| 850 | return syntax_option_type(int(__x) | int(__y)); |
| 851 | } |
| 852 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 853 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 854 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 855 | syntax_option_type |
| 856 | operator^(syntax_option_type __x, syntax_option_type __y) |
| 857 | { |
| 858 | return syntax_option_type(int(__x) ^ int(__y)); |
| 859 | } |
| 860 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 861 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 862 | syntax_option_type& |
| 863 | operator&=(syntax_option_type& __x, syntax_option_type __y) |
| 864 | { |
| 865 | __x = __x & __y; |
| 866 | return __x; |
| 867 | } |
| 868 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 869 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 870 | syntax_option_type& |
| 871 | operator|=(syntax_option_type& __x, syntax_option_type __y) |
| 872 | { |
| 873 | __x = __x | __y; |
| 874 | return __x; |
| 875 | } |
| 876 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 877 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 878 | syntax_option_type& |
| 879 | operator^=(syntax_option_type& __x, syntax_option_type __y) |
| 880 | { |
| 881 | __x = __x ^ __y; |
| 882 | return __x; |
| 883 | } |
| 884 | |
| 885 | // match_flag_type |
| 886 | |
| 887 | enum match_flag_type |
| 888 | { |
| 889 | match_default = 0, |
| 890 | match_not_bol = 1 << 0, |
| 891 | match_not_eol = 1 << 1, |
| 892 | match_not_bow = 1 << 2, |
| 893 | match_not_eow = 1 << 3, |
| 894 | match_any = 1 << 4, |
| 895 | match_not_null = 1 << 5, |
| 896 | match_continuous = 1 << 6, |
| 897 | match_prev_avail = 1 << 7, |
| 898 | format_default = 0, |
| 899 | format_sed = 1 << 8, |
| 900 | format_no_copy = 1 << 9, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 901 | format_first_only = 1 << 10, |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 902 | __no_update_pos = 1 << 11, |
| 903 | __full_match = 1 << 12 |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 904 | }; |
| 905 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 906 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 907 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 908 | match_flag_type |
| 909 | operator~(match_flag_type __x) |
| 910 | { |
Marshall Clow | 924cffa | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 911 | return match_flag_type(~int(__x) & 0x0FFF); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 914 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 915 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 916 | match_flag_type |
| 917 | operator&(match_flag_type __x, match_flag_type __y) |
| 918 | { |
| 919 | return match_flag_type(int(__x) & int(__y)); |
| 920 | } |
| 921 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 922 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 923 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 924 | match_flag_type |
| 925 | operator|(match_flag_type __x, match_flag_type __y) |
| 926 | { |
| 927 | return match_flag_type(int(__x) | int(__y)); |
| 928 | } |
| 929 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 930 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 931 | _LIBCPP_CONSTEXPR |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 932 | match_flag_type |
| 933 | operator^(match_flag_type __x, match_flag_type __y) |
| 934 | { |
| 935 | return match_flag_type(int(__x) ^ int(__y)); |
| 936 | } |
| 937 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 938 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 939 | match_flag_type& |
| 940 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 941 | { |
| 942 | __x = __x & __y; |
| 943 | return __x; |
| 944 | } |
| 945 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 946 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 947 | match_flag_type& |
| 948 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 949 | { |
| 950 | __x = __x | __y; |
| 951 | return __x; |
| 952 | } |
| 953 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 954 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 955 | match_flag_type& |
| 956 | operator^=(match_flag_type& __x, match_flag_type __y) |
| 957 | { |
| 958 | __x = __x ^ __y; |
| 959 | return __x; |
| 960 | } |
| 961 | |
| 962 | enum error_type |
| 963 | { |
| 964 | error_collate = 1, |
| 965 | error_ctype, |
| 966 | error_escape, |
| 967 | error_backref, |
| 968 | error_brack, |
| 969 | error_paren, |
| 970 | error_brace, |
| 971 | error_badbrace, |
| 972 | error_range, |
| 973 | error_space, |
| 974 | error_badrepeat, |
| 975 | error_complexity, |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 976 | error_stack, |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 977 | __re_err_grammar, |
| 978 | __re_err_empty, |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 979 | __re_err_unknown, |
| 980 | __re_err_parse |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 981 | }; |
| 982 | |
Nikolas Klauser | d26407a | 2021-12-02 14:12:51 +0100 | [diff] [blame] | 983 | } // namespace regex_constants |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 984 | |
| 985 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 986 | : public runtime_error |
| 987 | { |
| 988 | regex_constants::error_type __code_; |
| 989 | public: |
| 990 | explicit regex_error(regex_constants::error_type __ecode); |
Dimitry Andric | 47269ce | 2020-03-13 19:36:26 +0100 | [diff] [blame] | 991 | regex_error(const regex_error&) _NOEXCEPT = default; |
| 992 | virtual ~regex_error() _NOEXCEPT; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 993 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 994 | regex_constants::error_type code() const {return __code_;} |
| 995 | }; |
| 996 | |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 997 | template <regex_constants::error_type _Ev> |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 998 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 999 | void __throw_regex_error() |
| 1000 | { |
| 1001 | #ifndef _LIBCPP_NO_EXCEPTIONS |
Marshall Clow | 8bf61bb | 2015-08-17 21:14:16 +0000 | [diff] [blame] | 1002 | throw regex_error(_Ev); |
| 1003 | #else |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 1004 | _VSTD::abort(); |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 1005 | #endif |
| 1006 | } |
| 1007 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1008 | template <class _CharT> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1009 | struct _LIBCPP_TEMPLATE_VIS regex_traits |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1010 | { |
| 1011 | public: |
| 1012 | typedef _CharT char_type; |
| 1013 | typedef basic_string<char_type> string_type; |
| 1014 | typedef locale locale_type; |
Dan Albert | 70ee07e | 2020-04-06 13:34:27 -0700 | [diff] [blame] | 1015 | #ifdef __BIONIC__ |
| 1016 | // Originally bionic's ctype_base used its own ctype masks because the |
| 1017 | // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask |
| 1018 | // was only 8 bits wide and already saturated, so it used a wider type here |
| 1019 | // to make room for __regex_word (then a part of this class rather than |
| 1020 | // ctype_base). Bionic has since moved to the builtin ctype_base |
| 1021 | // implementation, but this was not updated to match. Since then Android has |
| 1022 | // needed to maintain a stable libc++ ABI, and this can't be changed without |
| 1023 | // an ABI break. |
| 1024 | typedef uint16_t char_class_type; |
| 1025 | #else |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1026 | typedef ctype_base::mask char_class_type; |
Dan Albert | 70ee07e | 2020-04-06 13:34:27 -0700 | [diff] [blame] | 1027 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1028 | |
Mikhail Maltsev | 014ed06 | 2019-06-14 09:04:16 +0000 | [diff] [blame] | 1029 | static const char_class_type __regex_word = ctype_base::__regex_word; |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1030 | private: |
| 1031 | locale __loc_; |
| 1032 | const ctype<char_type>* __ct_; |
| 1033 | const collate<char_type>* __col_; |
| 1034 | |
| 1035 | public: |
| 1036 | regex_traits(); |
| 1037 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1038 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1039 | static size_t length(const char_type* __p) |
| 1040 | {return char_traits<char_type>::length(__p);} |
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 | char_type translate(char_type __c) const {return __c;} |
| 1043 | char_type translate_nocase(char_type __c) const; |
| 1044 | template <class _ForwardIterator> |
| 1045 | string_type |
| 1046 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 1047 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1048 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1049 | string_type |
| 1050 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 1051 | {return __transform_primary(__f, __l, char_type());} |
| 1052 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1053 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1054 | string_type |
| 1055 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 1056 | {return __lookup_collatename(__f, __l, char_type());} |
| 1057 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1058 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1059 | char_class_type |
| 1060 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1061 | bool __icase = false) const |
| 1062 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 1063 | bool isctype(char_type __c, char_class_type __m) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1064 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1065 | int value(char_type __ch, int __radix) const |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1066 | {return __regex_traits_value(__ch, __radix);} |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1067 | locale_type imbue(locale_type __l); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1068 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1069 | locale_type getloc()const {return __loc_;} |
| 1070 | |
| 1071 | private: |
| 1072 | void __init(); |
| 1073 | |
| 1074 | template <class _ForwardIterator> |
| 1075 | string_type |
| 1076 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1077 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1078 | template <class _ForwardIterator> |
| 1079 | string_type |
| 1080 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1081 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1082 | template <class _ForwardIterator> |
| 1083 | string_type |
| 1084 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1085 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1086 | template <class _ForwardIterator> |
| 1087 | string_type |
| 1088 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1089 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1090 | template <class _ForwardIterator> |
| 1091 | char_class_type |
| 1092 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1093 | bool __icase, char) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1094 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1095 | template <class _ForwardIterator> |
| 1096 | char_class_type |
| 1097 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1098 | bool __icase, wchar_t) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1099 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1100 | |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1101 | static int __regex_traits_value(unsigned char __ch, int __radix); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1102 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1103 | int __regex_traits_value(char __ch, int __radix) const |
| 1104 | {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);} |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1105 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1106 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1107 | int __regex_traits_value(wchar_t __ch, int __radix) const; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1108 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1109 | }; |
| 1110 | |
| 1111 | template <class _CharT> |
Howard Hinnant | 592cb61 | 2013-03-07 19:38:08 +0000 | [diff] [blame] | 1112 | const typename regex_traits<_CharT>::char_class_type |
| 1113 | regex_traits<_CharT>::__regex_word; |
| 1114 | |
| 1115 | template <class _CharT> |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1116 | regex_traits<_CharT>::regex_traits() |
| 1117 | { |
| 1118 | __init(); |
| 1119 | } |
| 1120 | |
| 1121 | template <class _CharT> |
| 1122 | typename regex_traits<_CharT>::char_type |
| 1123 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1124 | { |
| 1125 | return __ct_->tolower(__c); |
| 1126 | } |
| 1127 | |
| 1128 | template <class _CharT> |
| 1129 | template <class _ForwardIterator> |
| 1130 | typename regex_traits<_CharT>::string_type |
| 1131 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1132 | { |
| 1133 | string_type __s(__f, __l); |
| 1134 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1135 | } |
| 1136 | |
| 1137 | template <class _CharT> |
| 1138 | void |
| 1139 | regex_traits<_CharT>::__init() |
| 1140 | { |
| 1141 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1142 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1143 | } |
| 1144 | |
| 1145 | template <class _CharT> |
| 1146 | typename regex_traits<_CharT>::locale_type |
| 1147 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1148 | { |
| 1149 | locale __r = __loc_; |
| 1150 | __loc_ = __l; |
| 1151 | __init(); |
| 1152 | return __r; |
| 1153 | } |
| 1154 | |
| 1155 | // transform_primary is very FreeBSD-specific |
| 1156 | |
| 1157 | template <class _CharT> |
| 1158 | template <class _ForwardIterator> |
| 1159 | typename regex_traits<_CharT>::string_type |
| 1160 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1161 | _ForwardIterator __l, char) const |
| 1162 | { |
| 1163 | const string_type __s(__f, __l); |
| 1164 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1165 | switch (__d.size()) |
| 1166 | { |
| 1167 | case 1: |
| 1168 | break; |
| 1169 | case 12: |
| 1170 | __d[11] = __d[3]; |
| 1171 | break; |
| 1172 | default: |
| 1173 | __d.clear(); |
| 1174 | break; |
| 1175 | } |
| 1176 | return __d; |
| 1177 | } |
| 1178 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1179 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1180 | template <class _CharT> |
| 1181 | template <class _ForwardIterator> |
| 1182 | typename regex_traits<_CharT>::string_type |
| 1183 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1184 | _ForwardIterator __l, wchar_t) const |
| 1185 | { |
| 1186 | const string_type __s(__f, __l); |
| 1187 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1188 | switch (__d.size()) |
| 1189 | { |
| 1190 | case 1: |
| 1191 | break; |
| 1192 | case 3: |
| 1193 | __d[2] = __d[0]; |
| 1194 | break; |
| 1195 | default: |
| 1196 | __d.clear(); |
| 1197 | break; |
| 1198 | } |
| 1199 | return __d; |
| 1200 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1201 | #endif |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1202 | |
| 1203 | // lookup_collatename is very FreeBSD-specific |
| 1204 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1205 | _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s); |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1206 | |
| 1207 | template <class _CharT> |
| 1208 | template <class _ForwardIterator> |
| 1209 | typename regex_traits<_CharT>::string_type |
| 1210 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1211 | _ForwardIterator __l, char) const |
| 1212 | { |
| 1213 | string_type __s(__f, __l); |
| 1214 | string_type __r; |
| 1215 | if (!__s.empty()) |
| 1216 | { |
| 1217 | __r = __get_collation_name(__s.c_str()); |
| 1218 | if (__r.empty() && __s.size() <= 2) |
| 1219 | { |
| 1220 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1221 | if (__r.size() == 1 || __r.size() == 12) |
| 1222 | __r = __s; |
| 1223 | else |
| 1224 | __r.clear(); |
| 1225 | } |
| 1226 | } |
| 1227 | return __r; |
| 1228 | } |
| 1229 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1230 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1231 | template <class _CharT> |
| 1232 | template <class _ForwardIterator> |
| 1233 | typename regex_traits<_CharT>::string_type |
| 1234 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1235 | _ForwardIterator __l, wchar_t) const |
| 1236 | { |
| 1237 | string_type __s(__f, __l); |
| 1238 | string __n; |
| 1239 | __n.reserve(__s.size()); |
| 1240 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1241 | __i != __e; ++__i) |
| 1242 | { |
| 1243 | if (static_cast<unsigned>(*__i) >= 127) |
| 1244 | return string_type(); |
| 1245 | __n.push_back(char(*__i)); |
| 1246 | } |
| 1247 | string_type __r; |
| 1248 | if (!__s.empty()) |
| 1249 | { |
| 1250 | __n = __get_collation_name(__n.c_str()); |
| 1251 | if (!__n.empty()) |
| 1252 | __r.assign(__n.begin(), __n.end()); |
| 1253 | else if (__s.size() <= 2) |
| 1254 | { |
| 1255 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1256 | if (__r.size() == 1 || __r.size() == 3) |
| 1257 | __r = __s; |
| 1258 | else |
| 1259 | __r.clear(); |
| 1260 | } |
| 1261 | } |
| 1262 | return __r; |
| 1263 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1264 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1265 | |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1266 | // lookup_classname |
| 1267 | |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 1268 | regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS |
| 1269 | __get_classname(const char* __s, bool __icase); |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1270 | |
| 1271 | template <class _CharT> |
| 1272 | template <class _ForwardIterator> |
| 1273 | typename regex_traits<_CharT>::char_class_type |
| 1274 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1275 | _ForwardIterator __l, |
| 1276 | bool __icase, char) const |
| 1277 | { |
| 1278 | string_type __s(__f, __l); |
| 1279 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1280 | return __get_classname(__s.c_str(), __icase); |
| 1281 | } |
| 1282 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1283 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1284 | template <class _CharT> |
| 1285 | template <class _ForwardIterator> |
| 1286 | typename regex_traits<_CharT>::char_class_type |
| 1287 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1288 | _ForwardIterator __l, |
| 1289 | bool __icase, wchar_t) const |
| 1290 | { |
| 1291 | string_type __s(__f, __l); |
| 1292 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1293 | string __n; |
| 1294 | __n.reserve(__s.size()); |
| 1295 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1296 | __i != __e; ++__i) |
| 1297 | { |
| 1298 | if (static_cast<unsigned>(*__i) >= 127) |
| 1299 | return char_class_type(); |
| 1300 | __n.push_back(char(*__i)); |
| 1301 | } |
| 1302 | return __get_classname(__n.c_str(), __icase); |
| 1303 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1304 | #endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1305 | |
| 1306 | template <class _CharT> |
| 1307 | bool |
| 1308 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1309 | { |
| 1310 | if (__ct_->is(__m, __c)) |
| 1311 | return true; |
| 1312 | return (__c == '_' && (__m & __regex_word)); |
| 1313 | } |
| 1314 | |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1315 | inline _LIBCPP_INLINE_VISIBILITY |
| 1316 | bool __is_07(unsigned char c) |
| 1317 | { |
| 1318 | return (c & 0xF8u) == |
| 1319 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1320 | 0xF0; |
| 1321 | #else |
| 1322 | 0x30; |
| 1323 | #endif |
| 1324 | } |
| 1325 | |
| 1326 | inline _LIBCPP_INLINE_VISIBILITY |
| 1327 | bool __is_89(unsigned char c) |
| 1328 | { |
| 1329 | return (c & 0xFEu) == |
| 1330 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1331 | 0xF8; |
| 1332 | #else |
| 1333 | 0x38; |
| 1334 | #endif |
| 1335 | } |
| 1336 | |
| 1337 | inline _LIBCPP_INLINE_VISIBILITY |
| 1338 | unsigned char __to_lower(unsigned char c) |
| 1339 | { |
| 1340 | #if defined(__MVS__) && !defined(__NATIVE_ASCII_F) |
| 1341 | return c & 0xBF; |
| 1342 | #else |
| 1343 | return c | 0x20; |
| 1344 | #endif |
| 1345 | } |
| 1346 | |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1347 | template <class _CharT> |
| 1348 | int |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1349 | regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1350 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1351 | if (__is_07(__ch)) // '0' <= __ch && __ch <= '7' |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1352 | return __ch - '0'; |
| 1353 | if (__radix != 8) |
| 1354 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1355 | if (__is_89(__ch)) // '8' <= __ch && __ch <= '9' |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1356 | return __ch - '0'; |
| 1357 | if (__radix == 16) |
| 1358 | { |
Muiez Ahmed | 38aa787 | 2022-01-14 11:35:53 -0500 | [diff] [blame] | 1359 | __ch = __to_lower(__ch); // tolower |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1360 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1361 | return __ch - ('a' - 10); |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1362 | } |
| 1363 | } |
| 1364 | return -1; |
| 1365 | } |
| 1366 | |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1367 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1368 | template <class _CharT> |
Evgeniy Stepanov | 2fb1cb6 | 2015-11-07 01:22:13 +0000 | [diff] [blame] | 1369 | inline |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1370 | int |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1371 | regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1372 | { |
Marshall Clow | ef42019 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1373 | 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] | 1374 | } |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 1375 | #endif |
Howard Hinnant | 40b45e1 | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1376 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1377 | template <class _CharT> class __node; |
| 1378 | |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1379 | template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1380 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1381 | template <class _BidirectionalIterator, |
| 1382 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1383 | class _LIBCPP_TEMPLATE_VIS match_results; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1384 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1385 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1386 | struct __state |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1387 | { |
| 1388 | enum |
| 1389 | { |
| 1390 | __end_state = -1000, |
| 1391 | __consume_input, // -999 |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1392 | __begin_marked_expr, // -998 |
| 1393 | __end_marked_expr, // -997 |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1394 | __pop_state, // -996 |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1395 | __accept_and_consume, // -995 |
| 1396 | __accept_but_not_consume, // -994 |
| 1397 | __reject, // -993 |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1398 | __split, |
| 1399 | __repeat |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1400 | }; |
| 1401 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1402 | int __do_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1403 | const _CharT* __first_; |
| 1404 | const _CharT* __current_; |
| 1405 | const _CharT* __last_; |
| 1406 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1407 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1408 | const __node<_CharT>* __node_; |
| 1409 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1410 | bool __at_first_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1411 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1412 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1413 | __state() |
| 1414 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1415 | __node_(nullptr), __flags_() {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1416 | }; |
| 1417 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1418 | // __node |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1419 | |
| 1420 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1421 | class __node |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1422 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1423 | __node(const __node&); |
| 1424 | __node& operator=(const __node&); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1425 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1426 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1427 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1428 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1429 | __node() {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1430 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1431 | virtual ~__node() {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1432 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1433 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 1434 | virtual void __exec(__state&) const {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1435 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b41db9a | 2018-10-01 01:59:37 +0000 | [diff] [blame] | 1436 | virtual void __exec_split(bool, __state&) const {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1437 | }; |
| 1438 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1439 | // __end_state |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1440 | |
| 1441 | template <class _CharT> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1442 | class __end_state |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1443 | : public __node<_CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1444 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1445 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1446 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1447 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1448 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1449 | __end_state() {} |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1450 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1451 | virtual void __exec(__state&) const; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1452 | }; |
| 1453 | |
| 1454 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1455 | void |
| 1456 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1457 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1458 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1459 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1460 | |
| 1461 | // __has_one_state |
| 1462 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1463 | template <class _CharT> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1464 | class __has_one_state |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1465 | : public __node<_CharT> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1466 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1467 | __node<_CharT>* __first_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1468 | |
| 1469 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1470 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1471 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1472 | : __first_(__s) {} |
| 1473 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1474 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1475 | __node<_CharT>* first() const {return __first_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1476 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1477 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1478 | }; |
| 1479 | |
| 1480 | // __owns_one_state |
| 1481 | |
| 1482 | template <class _CharT> |
| 1483 | class __owns_one_state |
| 1484 | : public __has_one_state<_CharT> |
| 1485 | { |
| 1486 | typedef __has_one_state<_CharT> base; |
| 1487 | |
| 1488 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1489 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1490 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1491 | : base(__s) {} |
| 1492 | |
| 1493 | virtual ~__owns_one_state(); |
| 1494 | }; |
| 1495 | |
| 1496 | template <class _CharT> |
| 1497 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1498 | { |
| 1499 | delete this->first(); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1500 | } |
| 1501 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1502 | // __empty_state |
| 1503 | |
| 1504 | template <class _CharT> |
| 1505 | class __empty_state |
| 1506 | : public __owns_one_state<_CharT> |
| 1507 | { |
| 1508 | typedef __owns_one_state<_CharT> base; |
| 1509 | |
| 1510 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1511 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1512 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1513 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1514 | explicit __empty_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1515 | : base(__s) {} |
| 1516 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1517 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1518 | }; |
| 1519 | |
| 1520 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1521 | void |
| 1522 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1523 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1524 | __s.__do_ = __state::__accept_but_not_consume; |
| 1525 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | // __empty_non_own_state |
| 1529 | |
| 1530 | template <class _CharT> |
| 1531 | class __empty_non_own_state |
| 1532 | : public __has_one_state<_CharT> |
| 1533 | { |
| 1534 | typedef __has_one_state<_CharT> base; |
| 1535 | |
| 1536 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1537 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1538 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1539 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1540 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1541 | : base(__s) {} |
| 1542 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1543 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1544 | }; |
| 1545 | |
| 1546 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1547 | void |
| 1548 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1549 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1550 | __s.__do_ = __state::__accept_but_not_consume; |
| 1551 | __s.__node_ = this->first(); |
| 1552 | } |
| 1553 | |
| 1554 | // __repeat_one_loop |
| 1555 | |
| 1556 | template <class _CharT> |
| 1557 | class __repeat_one_loop |
| 1558 | : public __has_one_state<_CharT> |
| 1559 | { |
| 1560 | typedef __has_one_state<_CharT> base; |
| 1561 | |
| 1562 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1563 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1564 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1565 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1566 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1567 | : base(__s) {} |
| 1568 | |
| 1569 | virtual void __exec(__state&) const; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1570 | }; |
| 1571 | |
| 1572 | template <class _CharT> |
| 1573 | void |
| 1574 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1575 | { |
| 1576 | __s.__do_ = __state::__repeat; |
| 1577 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | // __owns_two_states |
| 1581 | |
| 1582 | template <class _CharT> |
| 1583 | class __owns_two_states |
| 1584 | : public __owns_one_state<_CharT> |
| 1585 | { |
| 1586 | typedef __owns_one_state<_CharT> base; |
| 1587 | |
| 1588 | base* __second_; |
| 1589 | |
| 1590 | public: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1591 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1592 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1593 | : base(__s1), __second_(__s2) {} |
| 1594 | |
| 1595 | virtual ~__owns_two_states(); |
| 1596 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1597 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1598 | base* second() const {return __second_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1599 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1600 | base*& second() {return __second_;} |
| 1601 | }; |
| 1602 | |
| 1603 | template <class _CharT> |
| 1604 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1605 | { |
| 1606 | delete __second_; |
| 1607 | } |
| 1608 | |
| 1609 | // __loop |
| 1610 | |
| 1611 | template <class _CharT> |
| 1612 | class __loop |
| 1613 | : public __owns_two_states<_CharT> |
| 1614 | { |
| 1615 | typedef __owns_two_states<_CharT> base; |
| 1616 | |
| 1617 | size_t __min_; |
| 1618 | size_t __max_; |
| 1619 | unsigned __loop_id_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1620 | unsigned __mexp_begin_; |
| 1621 | unsigned __mexp_end_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1622 | bool __greedy_; |
| 1623 | |
| 1624 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1625 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1626 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1627 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1628 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1629 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1630 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1631 | bool __greedy = true, |
| 1632 | size_t __min = 0, |
| 1633 | size_t __max = numeric_limits<size_t>::max()) |
| 1634 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1635 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1636 | __greedy_(__greedy) {} |
| 1637 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1638 | virtual void __exec(__state& __s) const; |
| 1639 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1640 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1641 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1642 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1643 | void __init_repeat(__state& __s) const |
| 1644 | { |
| 1645 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1646 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1647 | { |
| 1648 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1649 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1650 | __s.__sub_matches_[__i].matched = false; |
| 1651 | } |
| 1652 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1653 | }; |
| 1654 | |
| 1655 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1656 | void |
| 1657 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1658 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1659 | if (__s.__do_ == __state::__repeat) |
| 1660 | { |
| 1661 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1662 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1663 | if (__do_repeat && __do_alt && |
| 1664 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1665 | __do_repeat = false; |
| 1666 | if (__do_repeat && __do_alt) |
| 1667 | __s.__do_ = __state::__split; |
| 1668 | else if (__do_repeat) |
| 1669 | { |
| 1670 | __s.__do_ = __state::__accept_but_not_consume; |
| 1671 | __s.__node_ = this->first(); |
| 1672 | __init_repeat(__s); |
| 1673 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1674 | else |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1675 | { |
| 1676 | __s.__do_ = __state::__accept_but_not_consume; |
| 1677 | __s.__node_ = this->second(); |
| 1678 | } |
| 1679 | } |
| 1680 | else |
| 1681 | { |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1682 | __s.__loop_data_[__loop_id_].first = 0; |
| 1683 | bool __do_repeat = 0 < __max_; |
| 1684 | bool __do_alt = 0 >= __min_; |
| 1685 | if (__do_repeat && __do_alt) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1686 | __s.__do_ = __state::__split; |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1687 | else if (__do_repeat) |
| 1688 | { |
| 1689 | __s.__do_ = __state::__accept_but_not_consume; |
| 1690 | __s.__node_ = this->first(); |
| 1691 | __init_repeat(__s); |
| 1692 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1693 | else |
| 1694 | { |
| 1695 | __s.__do_ = __state::__accept_but_not_consume; |
| 1696 | __s.__node_ = this->second(); |
| 1697 | } |
| 1698 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1701 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1702 | void |
| 1703 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1704 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1705 | __s.__do_ = __state::__accept_but_not_consume; |
| 1706 | if (__greedy_ != __second) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1707 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1708 | __s.__node_ = this->first(); |
| 1709 | __init_repeat(__s); |
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 | else |
| 1712 | __s.__node_ = this->second(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1715 | // __alternate |
| 1716 | |
| 1717 | template <class _CharT> |
| 1718 | class __alternate |
| 1719 | : public __owns_two_states<_CharT> |
| 1720 | { |
| 1721 | typedef __owns_two_states<_CharT> base; |
| 1722 | |
| 1723 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1724 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1725 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1726 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1727 | explicit __alternate(__owns_one_state<_CharT>* __s1, |
| 1728 | __owns_one_state<_CharT>* __s2) |
| 1729 | : base(__s1, __s2) {} |
| 1730 | |
| 1731 | virtual void __exec(__state& __s) const; |
| 1732 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1733 | }; |
| 1734 | |
| 1735 | template <class _CharT> |
| 1736 | void |
| 1737 | __alternate<_CharT>::__exec(__state& __s) const |
| 1738 | { |
| 1739 | __s.__do_ = __state::__split; |
| 1740 | } |
| 1741 | |
| 1742 | template <class _CharT> |
| 1743 | void |
| 1744 | __alternate<_CharT>::__exec_split(bool __second, __state& __s) const |
| 1745 | { |
| 1746 | __s.__do_ = __state::__accept_but_not_consume; |
Howard Hinnant | cbf2f3f | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1747 | if (__second) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1748 | __s.__node_ = this->second(); |
Howard Hinnant | cbf2f3f | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1749 | else |
| 1750 | __s.__node_ = this->first(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1753 | // __begin_marked_subexpression |
| 1754 | |
| 1755 | template <class _CharT> |
| 1756 | class __begin_marked_subexpression |
| 1757 | : public __owns_one_state<_CharT> |
| 1758 | { |
| 1759 | typedef __owns_one_state<_CharT> base; |
| 1760 | |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1761 | unsigned __mexp_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1762 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1763 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1764 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1765 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1766 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1767 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1768 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1769 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1770 | }; |
| 1771 | |
| 1772 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1773 | void |
| 1774 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1775 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1776 | __s.__do_ = __state::__accept_but_not_consume; |
| 1777 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1778 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | // __end_marked_subexpression |
| 1782 | |
| 1783 | template <class _CharT> |
| 1784 | class __end_marked_subexpression |
| 1785 | : public __owns_one_state<_CharT> |
| 1786 | { |
| 1787 | typedef __owns_one_state<_CharT> base; |
| 1788 | |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1789 | unsigned __mexp_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1790 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1791 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1792 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1793 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1794 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1795 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1796 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1797 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1798 | }; |
| 1799 | |
| 1800 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1801 | void |
| 1802 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1803 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1804 | __s.__do_ = __state::__accept_but_not_consume; |
| 1805 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1806 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1807 | __s.__node_ = this->first(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1810 | // __back_ref |
| 1811 | |
| 1812 | template <class _CharT> |
| 1813 | class __back_ref |
| 1814 | : public __owns_one_state<_CharT> |
| 1815 | { |
| 1816 | typedef __owns_one_state<_CharT> base; |
| 1817 | |
| 1818 | unsigned __mexp_; |
| 1819 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1820 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1821 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1822 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1823 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1824 | : base(__s), __mexp_(__mexp) {} |
| 1825 | |
| 1826 | virtual void __exec(__state&) const; |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1827 | }; |
| 1828 | |
| 1829 | template <class _CharT> |
| 1830 | void |
| 1831 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1832 | { |
Marshall Clow | 360e839 | 2015-08-24 15:57:09 +0000 | [diff] [blame] | 1833 | if (__mexp_ > __s.__sub_matches_.size()) |
| 1834 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1835 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1836 | if (__sm.matched) |
| 1837 | { |
| 1838 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1839 | if (__s.__last_ - __s.__current_ >= __len && |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1840 | _VSTD::equal(__sm.first, __sm.second, __s.__current_)) |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1841 | { |
| 1842 | __s.__do_ = __state::__accept_but_not_consume; |
| 1843 | __s.__current_ += __len; |
| 1844 | __s.__node_ = this->first(); |
| 1845 | } |
| 1846 | else |
| 1847 | { |
| 1848 | __s.__do_ = __state::__reject; |
| 1849 | __s.__node_ = nullptr; |
| 1850 | } |
| 1851 | } |
| 1852 | else |
| 1853 | { |
| 1854 | __s.__do_ = __state::__reject; |
| 1855 | __s.__node_ = nullptr; |
| 1856 | } |
| 1857 | } |
| 1858 | |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1859 | // __back_ref_icase |
| 1860 | |
| 1861 | template <class _CharT, class _Traits> |
| 1862 | class __back_ref_icase |
| 1863 | : public __owns_one_state<_CharT> |
| 1864 | { |
| 1865 | typedef __owns_one_state<_CharT> base; |
| 1866 | |
| 1867 | _Traits __traits_; |
| 1868 | unsigned __mexp_; |
| 1869 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1870 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1871 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1872 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1873 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1874 | __node<_CharT>* __s) |
| 1875 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1876 | |
| 1877 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1878 | }; |
| 1879 | |
| 1880 | template <class _CharT, class _Traits> |
| 1881 | void |
| 1882 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1883 | { |
| 1884 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1885 | if (__sm.matched) |
| 1886 | { |
| 1887 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1888 | if (__s.__last_ - __s.__current_ >= __len) |
| 1889 | { |
| 1890 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1891 | { |
| 1892 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1893 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1894 | goto __not_equal; |
| 1895 | } |
| 1896 | __s.__do_ = __state::__accept_but_not_consume; |
| 1897 | __s.__current_ += __len; |
| 1898 | __s.__node_ = this->first(); |
| 1899 | } |
| 1900 | else |
| 1901 | { |
| 1902 | __s.__do_ = __state::__reject; |
| 1903 | __s.__node_ = nullptr; |
| 1904 | } |
| 1905 | } |
| 1906 | else |
| 1907 | { |
| 1908 | __not_equal: |
| 1909 | __s.__do_ = __state::__reject; |
| 1910 | __s.__node_ = nullptr; |
| 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | // __back_ref_collate |
| 1915 | |
| 1916 | template <class _CharT, class _Traits> |
| 1917 | class __back_ref_collate |
| 1918 | : public __owns_one_state<_CharT> |
| 1919 | { |
| 1920 | typedef __owns_one_state<_CharT> base; |
| 1921 | |
| 1922 | _Traits __traits_; |
| 1923 | unsigned __mexp_; |
| 1924 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1925 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1926 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1927 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1928 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1929 | __node<_CharT>* __s) |
| 1930 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1931 | |
| 1932 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1933 | }; |
| 1934 | |
| 1935 | template <class _CharT, class _Traits> |
| 1936 | void |
| 1937 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1938 | { |
| 1939 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1940 | if (__sm.matched) |
| 1941 | { |
| 1942 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1943 | if (__s.__last_ - __s.__current_ >= __len) |
| 1944 | { |
| 1945 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1946 | { |
| 1947 | if (__traits_.translate(__sm.first[__i]) != |
| 1948 | __traits_.translate(__s.__current_[__i])) |
| 1949 | goto __not_equal; |
| 1950 | } |
| 1951 | __s.__do_ = __state::__accept_but_not_consume; |
| 1952 | __s.__current_ += __len; |
| 1953 | __s.__node_ = this->first(); |
| 1954 | } |
| 1955 | else |
| 1956 | { |
| 1957 | __s.__do_ = __state::__reject; |
| 1958 | __s.__node_ = nullptr; |
| 1959 | } |
| 1960 | } |
| 1961 | else |
| 1962 | { |
| 1963 | __not_equal: |
| 1964 | __s.__do_ = __state::__reject; |
| 1965 | __s.__node_ = nullptr; |
| 1966 | } |
| 1967 | } |
| 1968 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1969 | // __word_boundary |
| 1970 | |
| 1971 | template <class _CharT, class _Traits> |
| 1972 | class __word_boundary |
| 1973 | : public __owns_one_state<_CharT> |
| 1974 | { |
| 1975 | typedef __owns_one_state<_CharT> base; |
| 1976 | |
| 1977 | _Traits __traits_; |
| 1978 | bool __invert_; |
| 1979 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1980 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1981 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1982 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1983 | explicit __word_boundary(const _Traits& __traits, bool __invert, |
| 1984 | __node<_CharT>* __s) |
| 1985 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 1986 | |
| 1987 | virtual void __exec(__state&) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1988 | }; |
| 1989 | |
| 1990 | template <class _CharT, class _Traits> |
| 1991 | void |
| 1992 | __word_boundary<_CharT, _Traits>::__exec(__state& __s) const |
| 1993 | { |
| 1994 | bool __is_word_b = false; |
| 1995 | if (__s.__first_ != __s.__last_) |
| 1996 | { |
| 1997 | if (__s.__current_ == __s.__last_) |
| 1998 | { |
| 1999 | if (!(__s.__flags_ & regex_constants::match_not_eow)) |
| 2000 | { |
| 2001 | _CharT __c = __s.__current_[-1]; |
| 2002 | __is_word_b = __c == '_' || |
| 2003 | __traits_.isctype(__c, ctype_base::alnum); |
| 2004 | } |
| 2005 | } |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 2006 | else if (__s.__current_ == __s.__first_ && |
| 2007 | !(__s.__flags_ & regex_constants::match_prev_avail)) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2008 | { |
| 2009 | if (!(__s.__flags_ & regex_constants::match_not_bow)) |
| 2010 | { |
| 2011 | _CharT __c = *__s.__current_; |
| 2012 | __is_word_b = __c == '_' || |
| 2013 | __traits_.isctype(__c, ctype_base::alnum); |
| 2014 | } |
| 2015 | } |
| 2016 | else |
| 2017 | { |
| 2018 | _CharT __c1 = __s.__current_[-1]; |
| 2019 | _CharT __c2 = *__s.__current_; |
| 2020 | bool __is_c1_b = __c1 == '_' || |
| 2021 | __traits_.isctype(__c1, ctype_base::alnum); |
| 2022 | bool __is_c2_b = __c2 == '_' || |
| 2023 | __traits_.isctype(__c2, ctype_base::alnum); |
| 2024 | __is_word_b = __is_c1_b != __is_c2_b; |
| 2025 | } |
| 2026 | } |
| 2027 | if (__is_word_b != __invert_) |
| 2028 | { |
| 2029 | __s.__do_ = __state::__accept_but_not_consume; |
| 2030 | __s.__node_ = this->first(); |
| 2031 | } |
| 2032 | else |
| 2033 | { |
| 2034 | __s.__do_ = __state::__reject; |
| 2035 | __s.__node_ = nullptr; |
| 2036 | } |
| 2037 | } |
| 2038 | |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2039 | // __l_anchor |
| 2040 | |
| 2041 | template <class _CharT> |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2042 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR |
| 2043 | bool __is_eol(_CharT c) |
| 2044 | { |
| 2045 | return c == '\r' || c == '\n'; |
| 2046 | } |
| 2047 | |
| 2048 | template <class _CharT> |
| 2049 | class __l_anchor_multiline |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2050 | : public __owns_one_state<_CharT> |
| 2051 | { |
| 2052 | typedef __owns_one_state<_CharT> base; |
| 2053 | |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2054 | bool __multiline_; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2055 | |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2056 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2057 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2058 | |
| 2059 | _LIBCPP_INLINE_VISIBILITY |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2060 | __l_anchor_multiline(bool __multiline, __node<_CharT>* __s) |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2061 | : base(__s), __multiline_(__multiline) {} |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2062 | |
| 2063 | virtual void __exec(__state&) const; |
| 2064 | }; |
| 2065 | |
| 2066 | template <class _CharT> |
| 2067 | void |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2068 | __l_anchor_multiline<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2069 | { |
Marshall Clow | 5440439 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 2070 | if (__s.__at_first_ && __s.__current_ == __s.__first_ && |
| 2071 | !(__s.__flags_ & regex_constants::match_not_bol)) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2072 | { |
| 2073 | __s.__do_ = __state::__accept_but_not_consume; |
| 2074 | __s.__node_ = this->first(); |
| 2075 | } |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 2076 | else if (__multiline_ && |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2077 | !__s.__at_first_ && |
| 2078 | __is_eol(*_VSTD::prev(__s.__current_))) |
| 2079 | { |
| 2080 | __s.__do_ = __state::__accept_but_not_consume; |
| 2081 | __s.__node_ = this->first(); |
| 2082 | } |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2083 | else |
| 2084 | { |
| 2085 | __s.__do_ = __state::__reject; |
| 2086 | __s.__node_ = nullptr; |
| 2087 | } |
| 2088 | } |
| 2089 | |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2090 | // __r_anchor |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2091 | |
| 2092 | template <class _CharT> |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2093 | class __r_anchor_multiline |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2094 | : public __owns_one_state<_CharT> |
| 2095 | { |
| 2096 | typedef __owns_one_state<_CharT> base; |
| 2097 | |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2098 | bool __multiline_; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2099 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2100 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2101 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2102 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2103 | _LIBCPP_INLINE_VISIBILITY |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2104 | __r_anchor_multiline(bool __multiline, __node<_CharT>* __s) |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2105 | : base(__s), __multiline_(__multiline) {} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2106 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2107 | virtual void __exec(__state&) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2108 | }; |
| 2109 | |
| 2110 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2111 | void |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2112 | __r_anchor_multiline<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2113 | { |
Marshall Clow | 5440439 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 2114 | if (__s.__current_ == __s.__last_ && |
| 2115 | !(__s.__flags_ & regex_constants::match_not_eol)) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2116 | { |
| 2117 | __s.__do_ = __state::__accept_but_not_consume; |
| 2118 | __s.__node_ = this->first(); |
| 2119 | } |
Louis Dionne | 6209e9f | 2022-03-03 13:39:12 -0500 | [diff] [blame] | 2120 | else if (__multiline_ && __is_eol(*__s.__current_)) |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2121 | { |
| 2122 | __s.__do_ = __state::__accept_but_not_consume; |
| 2123 | __s.__node_ = this->first(); |
| 2124 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2125 | else |
| 2126 | { |
| 2127 | __s.__do_ = __state::__reject; |
| 2128 | __s.__node_ = nullptr; |
| 2129 | } |
| 2130 | } |
| 2131 | |
| 2132 | // __match_any |
| 2133 | |
| 2134 | template <class _CharT> |
| 2135 | class __match_any |
| 2136 | : public __owns_one_state<_CharT> |
| 2137 | { |
| 2138 | typedef __owns_one_state<_CharT> base; |
| 2139 | |
| 2140 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2141 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2142 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2143 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2144 | __match_any(__node<_CharT>* __s) |
| 2145 | : base(__s) {} |
| 2146 | |
| 2147 | virtual void __exec(__state&) const; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2148 | }; |
| 2149 | |
| 2150 | template <class _CharT> |
| 2151 | void |
| 2152 | __match_any<_CharT>::__exec(__state& __s) const |
| 2153 | { |
| 2154 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 2155 | { |
| 2156 | __s.__do_ = __state::__accept_and_consume; |
| 2157 | ++__s.__current_; |
| 2158 | __s.__node_ = this->first(); |
| 2159 | } |
| 2160 | else |
| 2161 | { |
| 2162 | __s.__do_ = __state::__reject; |
| 2163 | __s.__node_ = nullptr; |
| 2164 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2167 | // __match_any_but_newline |
| 2168 | |
| 2169 | template <class _CharT> |
| 2170 | class __match_any_but_newline |
| 2171 | : public __owns_one_state<_CharT> |
| 2172 | { |
| 2173 | typedef __owns_one_state<_CharT> base; |
| 2174 | |
| 2175 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2176 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2177 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2178 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2179 | __match_any_but_newline(__node<_CharT>* __s) |
| 2180 | : base(__s) {} |
| 2181 | |
| 2182 | virtual void __exec(__state&) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2183 | }; |
| 2184 | |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2185 | 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] | 2186 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2187 | 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] | 2188 | #endif |
Howard Hinnant | a37d3cf | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2189 | |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2190 | // __match_char |
| 2191 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2192 | template <class _CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2193 | class __match_char |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2194 | : public __owns_one_state<_CharT> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2195 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2196 | typedef __owns_one_state<_CharT> base; |
| 2197 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2198 | _CharT __c_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2199 | |
| 2200 | __match_char(const __match_char&); |
| 2201 | __match_char& operator=(const __match_char&); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2202 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2203 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2204 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2205 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2206 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2207 | : base(__s), __c_(__c) {} |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2208 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2209 | virtual void __exec(__state&) const; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2210 | }; |
| 2211 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2212 | template <class _CharT> |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2213 | void |
| 2214 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2215 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2216 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2217 | { |
| 2218 | __s.__do_ = __state::__accept_and_consume; |
| 2219 | ++__s.__current_; |
| 2220 | __s.__node_ = this->first(); |
| 2221 | } |
| 2222 | else |
| 2223 | { |
| 2224 | __s.__do_ = __state::__reject; |
| 2225 | __s.__node_ = nullptr; |
| 2226 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2227 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2228 | |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2229 | // __match_char_icase |
| 2230 | |
| 2231 | template <class _CharT, class _Traits> |
| 2232 | class __match_char_icase |
| 2233 | : public __owns_one_state<_CharT> |
| 2234 | { |
| 2235 | typedef __owns_one_state<_CharT> base; |
| 2236 | |
| 2237 | _Traits __traits_; |
| 2238 | _CharT __c_; |
| 2239 | |
| 2240 | __match_char_icase(const __match_char_icase&); |
| 2241 | __match_char_icase& operator=(const __match_char_icase&); |
| 2242 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2243 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2244 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2245 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2246 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2247 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2248 | |
| 2249 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2250 | }; |
| 2251 | |
| 2252 | template <class _CharT, class _Traits> |
| 2253 | void |
| 2254 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2255 | { |
| 2256 | if (__s.__current_ != __s.__last_ && |
| 2257 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2258 | { |
| 2259 | __s.__do_ = __state::__accept_and_consume; |
| 2260 | ++__s.__current_; |
| 2261 | __s.__node_ = this->first(); |
| 2262 | } |
| 2263 | else |
| 2264 | { |
| 2265 | __s.__do_ = __state::__reject; |
| 2266 | __s.__node_ = nullptr; |
| 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | // __match_char_collate |
| 2271 | |
| 2272 | template <class _CharT, class _Traits> |
| 2273 | class __match_char_collate |
| 2274 | : public __owns_one_state<_CharT> |
| 2275 | { |
| 2276 | typedef __owns_one_state<_CharT> base; |
| 2277 | |
| 2278 | _Traits __traits_; |
| 2279 | _CharT __c_; |
| 2280 | |
| 2281 | __match_char_collate(const __match_char_collate&); |
| 2282 | __match_char_collate& operator=(const __match_char_collate&); |
| 2283 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2284 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2285 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2286 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2287 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2288 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2289 | |
| 2290 | virtual void __exec(__state&) const; |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2291 | }; |
| 2292 | |
| 2293 | template <class _CharT, class _Traits> |
| 2294 | void |
| 2295 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2296 | { |
| 2297 | if (__s.__current_ != __s.__last_ && |
| 2298 | __traits_.translate(*__s.__current_) == __c_) |
| 2299 | { |
| 2300 | __s.__do_ = __state::__accept_and_consume; |
| 2301 | ++__s.__current_; |
| 2302 | __s.__node_ = this->first(); |
| 2303 | } |
| 2304 | else |
| 2305 | { |
| 2306 | __s.__do_ = __state::__reject; |
| 2307 | __s.__node_ = nullptr; |
| 2308 | } |
| 2309 | } |
| 2310 | |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2311 | // __bracket_expression |
| 2312 | |
| 2313 | template <class _CharT, class _Traits> |
| 2314 | class __bracket_expression |
| 2315 | : public __owns_one_state<_CharT> |
| 2316 | { |
| 2317 | typedef __owns_one_state<_CharT> base; |
| 2318 | typedef typename _Traits::string_type string_type; |
| 2319 | |
| 2320 | _Traits __traits_; |
| 2321 | vector<_CharT> __chars_; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2322 | vector<_CharT> __neg_chars_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2323 | vector<pair<string_type, string_type> > __ranges_; |
| 2324 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2325 | vector<string_type> __equivalences_; |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2326 | typename regex_traits<_CharT>::char_class_type __mask_; |
| 2327 | typename regex_traits<_CharT>::char_class_type __neg_mask_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2328 | bool __negate_; |
| 2329 | bool __icase_; |
| 2330 | bool __collate_; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2331 | bool __might_have_digraph_; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2332 | |
| 2333 | __bracket_expression(const __bracket_expression&); |
| 2334 | __bracket_expression& operator=(const __bracket_expression&); |
| 2335 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2336 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2337 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2338 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2339 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2340 | bool __negate, bool __icase, bool __collate) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2341 | : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), |
| 2342 | __negate_(__negate), __icase_(__icase), __collate_(__collate), |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2343 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2344 | |
| 2345 | virtual void __exec(__state&) const; |
| 2346 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2347 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2348 | bool __negated() const {return __negate_;} |
| 2349 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2350 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2351 | void __add_char(_CharT __c) |
| 2352 | { |
| 2353 | if (__icase_) |
| 2354 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2355 | else if (__collate_) |
| 2356 | __chars_.push_back(__traits_.translate(__c)); |
| 2357 | else |
| 2358 | __chars_.push_back(__c); |
| 2359 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2360 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2361 | void __add_neg_char(_CharT __c) |
| 2362 | { |
| 2363 | if (__icase_) |
| 2364 | __neg_chars_.push_back(__traits_.translate_nocase(__c)); |
| 2365 | else if (__collate_) |
| 2366 | __neg_chars_.push_back(__traits_.translate(__c)); |
| 2367 | else |
| 2368 | __neg_chars_.push_back(__c); |
| 2369 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2370 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2371 | void __add_range(string_type __b, string_type __e) |
| 2372 | { |
| 2373 | if (__collate_) |
| 2374 | { |
| 2375 | if (__icase_) |
| 2376 | { |
| 2377 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2378 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2379 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2380 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2381 | } |
| 2382 | else |
| 2383 | { |
| 2384 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2385 | __b[__i] = __traits_.translate(__b[__i]); |
| 2386 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2387 | __e[__i] = __traits_.translate(__e[__i]); |
| 2388 | } |
| 2389 | __ranges_.push_back(make_pair( |
| 2390 | __traits_.transform(__b.begin(), __b.end()), |
| 2391 | __traits_.transform(__e.begin(), __e.end()))); |
| 2392 | } |
| 2393 | else |
| 2394 | { |
| 2395 | if (__b.size() != 1 || __e.size() != 1) |
Marshall Clow | a521211 | 2019-05-28 22:42:32 +0000 | [diff] [blame] | 2396 | __throw_regex_error<regex_constants::error_range>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2397 | if (__icase_) |
| 2398 | { |
| 2399 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2400 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2401 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2402 | __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e))); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2403 | } |
| 2404 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2405 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2406 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2407 | { |
| 2408 | if (__icase_) |
| 2409 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2410 | __traits_.translate_nocase(__c2))); |
| 2411 | else if (__collate_) |
| 2412 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2413 | __traits_.translate(__c2))); |
| 2414 | else |
| 2415 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2416 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2417 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2418 | void __add_equivalence(const string_type& __s) |
| 2419 | {__equivalences_.push_back(__s);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2420 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 49f384c | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2421 | void __add_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2422 | {__mask_ |= __mask;} |
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_neg_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2425 | {__neg_mask_ |= __mask;} |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2426 | }; |
| 2427 | |
| 2428 | template <class _CharT, class _Traits> |
| 2429 | void |
| 2430 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2431 | { |
| 2432 | bool __found = false; |
| 2433 | unsigned __consumed = 0; |
| 2434 | if (__s.__current_ != __s.__last_) |
| 2435 | { |
| 2436 | ++__consumed; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2437 | if (__might_have_digraph_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2438 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2439 | const _CharT* __next = _VSTD::next(__s.__current_); |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2440 | if (__next != __s.__last_) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2441 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2442 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2443 | if (__icase_) |
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 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2446 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2447 | } |
| 2448 | else if (__collate_) |
| 2449 | { |
| 2450 | __ch2.first = __traits_.translate(__ch2.first); |
| 2451 | __ch2.second = __traits_.translate(__ch2.second); |
| 2452 | } |
| 2453 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2454 | { |
| 2455 | // __ch2 is a digraph in this locale |
| 2456 | ++__consumed; |
| 2457 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2458 | { |
| 2459 | if (__ch2 == __digraphs_[__i]) |
| 2460 | { |
| 2461 | __found = true; |
| 2462 | goto __exit; |
| 2463 | } |
| 2464 | } |
| 2465 | if (__collate_ && !__ranges_.empty()) |
| 2466 | { |
| 2467 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2468 | &__ch2.first + 2); |
| 2469 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2470 | { |
| 2471 | if (__ranges_[__i].first <= __s2 && |
| 2472 | __s2 <= __ranges_[__i].second) |
| 2473 | { |
| 2474 | __found = true; |
| 2475 | goto __exit; |
| 2476 | } |
| 2477 | } |
| 2478 | } |
| 2479 | if (!__equivalences_.empty()) |
| 2480 | { |
| 2481 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2482 | &__ch2.first + 2); |
| 2483 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2484 | { |
| 2485 | if (__s2 == __equivalences_[__i]) |
| 2486 | { |
| 2487 | __found = true; |
| 2488 | goto __exit; |
| 2489 | } |
| 2490 | } |
| 2491 | } |
| 2492 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2493 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2494 | { |
| 2495 | __found = true; |
| 2496 | goto __exit; |
| 2497 | } |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2498 | if (!__traits_.isctype(__ch2.first, __neg_mask_) && |
| 2499 | !__traits_.isctype(__ch2.second, __neg_mask_)) |
| 2500 | { |
| 2501 | __found = true; |
| 2502 | goto __exit; |
| 2503 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2504 | goto __exit; |
| 2505 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2506 | } |
| 2507 | } |
| 2508 | // test *__s.__current_ as not a digraph |
| 2509 | _CharT __ch = *__s.__current_; |
| 2510 | if (__icase_) |
| 2511 | __ch = __traits_.translate_nocase(__ch); |
| 2512 | else if (__collate_) |
| 2513 | __ch = __traits_.translate(__ch); |
| 2514 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2515 | { |
| 2516 | if (__ch == __chars_[__i]) |
| 2517 | { |
| 2518 | __found = true; |
| 2519 | goto __exit; |
| 2520 | } |
| 2521 | } |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2522 | // When there's at least one of __neg_chars_ and __neg_mask_, the set |
| 2523 | // of "__found" chars is |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2524 | // union(complement(union(__neg_chars_, __neg_mask_)), |
| 2525 | // other cases...) |
| 2526 | // |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2527 | // It doesn't make sense to check this when there are no __neg_chars_ |
| 2528 | // and no __neg_mask_. |
| 2529 | if (!(__neg_mask_ == 0 && __neg_chars_.empty())) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2530 | { |
Louis Dionne | 9023f02 | 2018-08-24 14:10:28 +0000 | [diff] [blame] | 2531 | const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_); |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2532 | const bool __in_neg_chars = |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 2533 | _VSTD::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2534 | __neg_chars_.end(); |
| 2535 | if (!(__in_neg_mask || __in_neg_chars)) |
| 2536 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2537 | __found = true; |
| 2538 | goto __exit; |
Marshall Clow | 42af8d9 | 2017-10-18 16:49:22 +0000 | [diff] [blame] | 2539 | } |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2540 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2541 | if (!__ranges_.empty()) |
| 2542 | { |
| 2543 | string_type __s2 = __collate_ ? |
| 2544 | __traits_.transform(&__ch, &__ch + 1) : |
| 2545 | string_type(1, __ch); |
| 2546 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2547 | { |
| 2548 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2549 | { |
| 2550 | __found = true; |
| 2551 | goto __exit; |
| 2552 | } |
| 2553 | } |
| 2554 | } |
| 2555 | if (!__equivalences_.empty()) |
| 2556 | { |
| 2557 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2558 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2559 | { |
| 2560 | if (__s2 == __equivalences_[__i]) |
| 2561 | { |
| 2562 | __found = true; |
| 2563 | goto __exit; |
| 2564 | } |
| 2565 | } |
| 2566 | } |
| 2567 | if (__traits_.isctype(__ch, __mask_)) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2568 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2569 | __found = true; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2570 | goto __exit; |
| 2571 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2572 | } |
| 2573 | else |
| 2574 | __found = __negate_; // force reject |
| 2575 | __exit: |
| 2576 | if (__found != __negate_) |
| 2577 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2578 | __s.__do_ = __state::__accept_and_consume; |
| 2579 | __s.__current_ += __consumed; |
| 2580 | __s.__node_ = this->first(); |
| 2581 | } |
| 2582 | else |
| 2583 | { |
| 2584 | __s.__do_ = __state::__reject; |
| 2585 | __s.__node_ = nullptr; |
| 2586 | } |
| 2587 | } |
| 2588 | |
Howard Hinnant | 944510a | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 2589 | template <class _CharT, class _Traits> class __lookahead; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2590 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2591 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2592 | class _LIBCPP_TEMPLATE_VIS basic_regex; |
| 2593 | |
| 2594 | typedef basic_regex<char> regex; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2595 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2596 | typedef basic_regex<wchar_t> wregex; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2597 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2598 | |
| 2599 | template <class _CharT, class _Traits> |
| 2600 | class |
| 2601 | _LIBCPP_TEMPLATE_VIS |
| 2602 | _LIBCPP_PREFERRED_NAME(regex) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 2603 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 2604 | basic_regex |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2605 | { |
| 2606 | public: |
| 2607 | // types: |
| 2608 | typedef _CharT value_type; |
Hubert Tong | 1f1ae9c | 2016-08-02 21:34:48 +0000 | [diff] [blame] | 2609 | typedef _Traits traits_type; |
| 2610 | typedef typename _Traits::string_type string_type; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2611 | typedef regex_constants::syntax_option_type flag_type; |
| 2612 | typedef typename _Traits::locale_type locale_type; |
| 2613 | |
| 2614 | private: |
| 2615 | _Traits __traits_; |
| 2616 | flag_type __flags_; |
| 2617 | unsigned __marked_count_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2618 | unsigned __loop_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2619 | int __open_count_; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2620 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2621 | __owns_one_state<_CharT>* __end_; |
| 2622 | |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2623 | typedef _VSTD::__state<_CharT> __state; |
| 2624 | typedef _VSTD::__node<_CharT> __node; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2625 | |
| 2626 | public: |
| 2627 | // constants: |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2628 | static const regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2629 | static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2630 | static const regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2631 | static const regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2632 | static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2633 | static const regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2634 | static const regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2635 | static const regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2636 | static const regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2637 | static const regex_constants::syntax_option_type egrep = regex_constants::egrep; |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2638 | static const regex_constants::syntax_option_type multiline = regex_constants::multiline; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2639 | |
| 2640 | // construct/copy/destroy: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2641 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2642 | basic_regex() |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2643 | : __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] | 2644 | __end_(nullptr) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2645 | {} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2646 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2647 | 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] | 2648 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2649 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2650 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2651 | __init(__p, __p + __traits_.length(__p)); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2652 | } |
| 2653 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2654 | _LIBCPP_INLINE_VISIBILITY |
Hubert Tong | 1966286 | 2016-08-07 22:26:04 +0000 | [diff] [blame] | 2655 | 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] | 2656 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2657 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2658 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2659 | __init(__p, __p + __len); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2660 | } |
| 2661 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2662 | // basic_regex(const basic_regex&) = default; |
| 2663 | // basic_regex(basic_regex&&) = default; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2664 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2665 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2666 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2667 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2668 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2669 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2670 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2671 | __init(__p.begin(), __p.end()); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2672 | } |
| 2673 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2674 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2675 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2676 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 2677 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2678 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2679 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2680 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2681 | __init(__first, __last); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2682 | } |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2683 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2684 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2685 | basic_regex(initializer_list<value_type> __il, |
| 2686 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2687 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2688 | __end_(nullptr) |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2689 | { |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2690 | __init(__il.begin(), __il.end()); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 2691 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2692 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2693 | |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2694 | // ~basic_regex() = default; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2695 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2696 | // basic_regex& operator=(const basic_regex&) = default; |
| 2697 | // basic_regex& operator=(basic_regex&&) = default; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2698 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2699 | basic_regex& operator=(const value_type* __p) |
| 2700 | {return assign(__p);} |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2701 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2702 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2703 | basic_regex& operator=(initializer_list<value_type> __il) |
| 2704 | {return assign(__il);} |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2705 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2706 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2707 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2708 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) |
| 2709 | {return assign(__p);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2710 | |
| 2711 | // assign: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2712 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2713 | basic_regex& assign(const basic_regex& __that) |
| 2714 | {return *this = __that;} |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2715 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2716 | _LIBCPP_INLINE_VISIBILITY |
| 2717 | basic_regex& assign(basic_regex&& __that) _NOEXCEPT |
| 2718 | {return *this = _VSTD::move(__that);} |
| 2719 | #endif |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2720 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2721 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
| 2722 | {return assign(__p, __p + __traits_.length(__p), __f);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2723 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | d402893 | 2019-09-25 16:40:30 +0000 | [diff] [blame] | 2724 | 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] | 2725 | {return assign(__p, __p + __len, __f);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2726 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2727 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2728 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2729 | flag_type __f = regex_constants::ECMAScript) |
| 2730 | {return assign(__s.begin(), __s.end(), __f);} |
| 2731 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2732 | template <class _InputIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2733 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2734 | typename enable_if |
| 2735 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2736 | __is_cpp17_input_iterator <_InputIterator>::value && |
| 2737 | !__is_cpp17_forward_iterator<_InputIterator>::value, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2738 | basic_regex& |
| 2739 | >::type |
| 2740 | assign(_InputIterator __first, _InputIterator __last, |
| 2741 | flag_type __f = regex_constants::ECMAScript) |
| 2742 | { |
| 2743 | basic_string<_CharT> __t(__first, __last); |
| 2744 | return assign(__t.begin(), __t.end(), __f); |
| 2745 | } |
| 2746 | |
| 2747 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2748 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2749 | void __member_init(flag_type __f) |
| 2750 | { |
| 2751 | __flags_ = __f; |
| 2752 | __marked_count_ = 0; |
| 2753 | __loop_count_ = 0; |
| 2754 | __open_count_ = 0; |
| 2755 | __end_ = nullptr; |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2756 | } |
| 2757 | public: |
| 2758 | |
| 2759 | template <class _ForwardIterator> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2760 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2761 | typename enable_if |
| 2762 | < |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 2763 | __is_cpp17_forward_iterator<_ForwardIterator>::value, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2764 | basic_regex& |
| 2765 | >::type |
| 2766 | assign(_ForwardIterator __first, _ForwardIterator __last, |
| 2767 | flag_type __f = regex_constants::ECMAScript) |
| 2768 | { |
Marshall Clow | ce03dc1 | 2015-01-13 16:49:52 +0000 | [diff] [blame] | 2769 | return assign(basic_regex(__first, __last, __f)); |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2770 | } |
| 2771 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 2772 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2773 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2774 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2775 | basic_regex& assign(initializer_list<value_type> __il, |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2776 | flag_type __f = regex_constants::ECMAScript) |
| 2777 | {return assign(__il.begin(), __il.end(), __f);} |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2778 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2779 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2780 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2781 | // const operations: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2782 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2783 | unsigned mark_count() const {return __marked_count_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2784 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2785 | flag_type flags() const {return __flags_;} |
| 2786 | |
| 2787 | // locale: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2788 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2789 | locale_type imbue(locale_type __loc) |
| 2790 | { |
| 2791 | __member_init(ECMAScript); |
| 2792 | __start_.reset(); |
| 2793 | return __traits_.imbue(__loc); |
| 2794 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2795 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2796 | locale_type getloc() const {return __traits_.getloc();} |
| 2797 | |
| 2798 | // swap: |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2799 | void swap(basic_regex& __r); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2800 | |
| 2801 | private: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2802 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2803 | unsigned __loop_count() const {return __loop_count_;} |
| 2804 | |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 2805 | _LIBCPP_INLINE_VISIBILITY |
| 2806 | bool __use_multiline() const |
| 2807 | { |
| 2808 | return __get_grammar(__flags_) == ECMAScript && (__flags_ & multiline); |
| 2809 | } |
| 2810 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2811 | template <class _ForwardIterator> |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 2812 | void |
| 2813 | __init(_ForwardIterator __first, _ForwardIterator __last); |
| 2814 | template <class _ForwardIterator> |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2815 | _ForwardIterator |
| 2816 | __parse(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2817 | template <class _ForwardIterator> |
| 2818 | _ForwardIterator |
| 2819 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2820 | template <class _ForwardIterator> |
| 2821 | _ForwardIterator |
| 2822 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2823 | template <class _ForwardIterator> |
| 2824 | _ForwardIterator |
| 2825 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2826 | template <class _ForwardIterator> |
| 2827 | _ForwardIterator |
| 2828 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2829 | template <class _ForwardIterator> |
| 2830 | _ForwardIterator |
| 2831 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2832 | template <class _ForwardIterator> |
| 2833 | _ForwardIterator |
| 2834 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2835 | template <class _ForwardIterator> |
| 2836 | _ForwardIterator |
| 2837 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2838 | template <class _ForwardIterator> |
| 2839 | _ForwardIterator |
| 2840 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2841 | template <class _ForwardIterator> |
| 2842 | _ForwardIterator |
| 2843 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2844 | template <class _ForwardIterator> |
| 2845 | _ForwardIterator |
| 2846 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2847 | template <class _ForwardIterator> |
| 2848 | _ForwardIterator |
| 2849 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2850 | template <class _ForwardIterator> |
| 2851 | _ForwardIterator |
| 2852 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2853 | template <class _ForwardIterator> |
| 2854 | _ForwardIterator |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2855 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2856 | __owns_one_state<_CharT>* __s, |
| 2857 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2858 | template <class _ForwardIterator> |
| 2859 | _ForwardIterator |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2860 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2861 | __owns_one_state<_CharT>* __s, |
| 2862 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2863 | template <class _ForwardIterator> |
| 2864 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2865 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2866 | template <class _ForwardIterator> |
| 2867 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2868 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2869 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2870 | template <class _ForwardIterator> |
| 2871 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2872 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2873 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2874 | template <class _ForwardIterator> |
| 2875 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2876 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2877 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2878 | template <class _ForwardIterator> |
| 2879 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2880 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2881 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2882 | template <class _ForwardIterator> |
| 2883 | _ForwardIterator |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2884 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2885 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2886 | template <class _ForwardIterator> |
| 2887 | _ForwardIterator |
| 2888 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2889 | template <class _ForwardIterator> |
| 2890 | _ForwardIterator |
| 2891 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2892 | template <class _ForwardIterator> |
| 2893 | _ForwardIterator |
| 2894 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2895 | template <class _ForwardIterator> |
| 2896 | _ForwardIterator |
| 2897 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2898 | template <class _ForwardIterator> |
| 2899 | _ForwardIterator |
| 2900 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2901 | template <class _ForwardIterator> |
| 2902 | _ForwardIterator |
| 2903 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2904 | template <class _ForwardIterator> |
| 2905 | _ForwardIterator |
| 2906 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2907 | template <class _ForwardIterator> |
| 2908 | _ForwardIterator |
| 2909 | __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2910 | template <class _ForwardIterator> |
| 2911 | _ForwardIterator |
| 2912 | __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); |
| 2913 | template <class _ForwardIterator> |
| 2914 | _ForwardIterator |
| 2915 | __parse_term(_ForwardIterator __first, _ForwardIterator __last); |
| 2916 | template <class _ForwardIterator> |
| 2917 | _ForwardIterator |
| 2918 | __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); |
| 2919 | template <class _ForwardIterator> |
| 2920 | _ForwardIterator |
| 2921 | __parse_atom(_ForwardIterator __first, _ForwardIterator __last); |
| 2922 | template <class _ForwardIterator> |
| 2923 | _ForwardIterator |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2924 | __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2925 | template <class _ForwardIterator> |
| 2926 | _ForwardIterator |
| 2927 | __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2928 | template <class _ForwardIterator> |
| 2929 | _ForwardIterator |
| 2930 | __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2931 | template <class _ForwardIterator> |
| 2932 | _ForwardIterator |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2933 | __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2934 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2935 | template <class _ForwardIterator> |
| 2936 | _ForwardIterator |
| 2937 | __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 2938 | template <class _ForwardIterator> |
| 2939 | _ForwardIterator |
| 2940 | __parse_grep(_ForwardIterator __first, _ForwardIterator __last); |
| 2941 | template <class _ForwardIterator> |
| 2942 | _ForwardIterator |
| 2943 | __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2944 | template <class _ForwardIterator> |
| 2945 | _ForwardIterator |
| 2946 | __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2947 | basic_string<_CharT>& __str, |
| 2948 | __bracket_expression<_CharT, _Traits>* __ml); |
| 2949 | template <class _ForwardIterator> |
| 2950 | _ForwardIterator |
| 2951 | __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2952 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2953 | |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 2954 | bool __test_back_ref(_CharT c); |
| 2955 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2956 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2957 | void __push_l_anchor(); |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2958 | void __push_r_anchor(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2959 | void __push_match_any(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2960 | void __push_match_any_but_newline(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2961 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2962 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2963 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2964 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2965 | __mexp_begin, __mexp_end);} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2966 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2967 | void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2968 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2969 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2970 | __mexp_begin, __mexp_end, false);} |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2971 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2972 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2973 | bool __greedy = true); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2974 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2975 | void __push_char(value_type __c); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 2976 | void __push_back_ref(int __i); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2977 | void __push_alternation(__owns_one_state<_CharT>* __sa, |
| 2978 | __owns_one_state<_CharT>* __sb); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2979 | void __push_begin_marked_subexpression(); |
| 2980 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2981 | void __push_empty(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2982 | void __push_word_boundary(bool); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2983 | void __push_lookahead(const basic_regex&, bool, unsigned); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2984 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2985 | template <class _Allocator> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2986 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2987 | __search(const _CharT* __first, const _CharT* __last, |
| 2988 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2989 | regex_constants::match_flag_type __flags) const; |
| 2990 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2991 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2992 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2993 | __match_at_start(const _CharT* __first, const _CharT* __last, |
| 2994 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2995 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2996 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2997 | bool |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2998 | __match_at_start_ecma(const _CharT* __first, const _CharT* __last, |
| 2999 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3000 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3001 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3002 | bool |
| 3003 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3004 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3005 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3006 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3007 | bool |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3008 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 3009 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 3010 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3011 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3012 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 3013 | friend |
| 3014 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3015 | 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] | 3016 | regex_constants::match_flag_type); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3017 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3018 | template <class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3019 | friend |
| 3020 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3021 | regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&, |
| 3022 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3023 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3024 | template <class _Bp, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3025 | friend |
| 3026 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3027 | regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3028 | regex_constants::match_flag_type); |
| 3029 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3030 | template <class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3031 | friend |
| 3032 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3033 | regex_search(const _Cp*, const _Cp*, |
| 3034 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3035 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3036 | template <class _Cp, class _Ap, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3037 | friend |
| 3038 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3039 | 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] | 3040 | regex_constants::match_flag_type); |
| 3041 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3042 | template <class _ST, class _SA, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3043 | friend |
| 3044 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3045 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 3046 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3047 | regex_constants::match_flag_type __flags); |
| 3048 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3049 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3050 | friend |
| 3051 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3052 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 3053 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 3054 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 3055 | regex_constants::match_flag_type __flags); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3056 | |
Howard Hinnant | 4018c48 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 3057 | template <class _Iter, class _Ap, class _Cp, class _Tp> |
| 3058 | friend |
| 3059 | bool |
| 3060 | regex_search(__wrap_iter<_Iter> __first, |
| 3061 | __wrap_iter<_Iter> __last, |
| 3062 | match_results<__wrap_iter<_Iter>, _Ap>& __m, |
| 3063 | const basic_regex<_Cp, _Tp>& __e, |
| 3064 | regex_constants::match_flag_type __flags); |
| 3065 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3066 | template <class, class> friend class __lookahead; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3067 | }; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3068 | |
Louis Dionne | d59f8a5 | 2021-08-17 11:59:07 -0400 | [diff] [blame] | 3069 | #if _LIBCPP_STD_VER >= 17 |
Marshall Clow | 2dce1f4 | 2018-05-23 01:57:02 +0000 | [diff] [blame] | 3070 | template <class _ForwardIterator, |
Eric Fiselier | cd5a677 | 2019-11-18 01:46:58 -0500 | [diff] [blame] | 3071 | 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] | 3072 | > |
| 3073 | basic_regex(_ForwardIterator, _ForwardIterator, |
| 3074 | regex_constants::syntax_option_type = regex_constants::ECMAScript) |
| 3075 | -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>; |
| 3076 | #endif |
| 3077 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3078 | template <class _CharT, class _Traits> |
Howard Hinnant | 2c45cb4 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 3079 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase; |
| 3080 | template <class _CharT, class _Traits> |
| 3081 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs; |
| 3082 | template <class _CharT, class _Traits> |
| 3083 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize; |
| 3084 | template <class _CharT, class _Traits> |
| 3085 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate; |
| 3086 | template <class _CharT, class _Traits> |
| 3087 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript; |
| 3088 | template <class _CharT, class _Traits> |
| 3089 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic; |
| 3090 | template <class _CharT, class _Traits> |
| 3091 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended; |
| 3092 | template <class _CharT, class _Traits> |
| 3093 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk; |
| 3094 | template <class _CharT, class _Traits> |
| 3095 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep; |
| 3096 | template <class _CharT, class _Traits> |
| 3097 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep; |
| 3098 | |
| 3099 | template <class _CharT, class _Traits> |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3100 | void |
| 3101 | basic_regex<_CharT, _Traits>::swap(basic_regex& __r) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3102 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3103 | using _VSTD::swap; |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3104 | swap(__traits_, __r.__traits_); |
| 3105 | swap(__flags_, __r.__flags_); |
| 3106 | swap(__marked_count_, __r.__marked_count_); |
| 3107 | swap(__loop_count_, __r.__loop_count_); |
| 3108 | swap(__open_count_, __r.__open_count_); |
| 3109 | swap(__start_, __r.__start_); |
| 3110 | swap(__end_, __r.__end_); |
Howard Hinnant | 997621e | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | template <class _CharT, class _Traits> |
| 3114 | inline _LIBCPP_INLINE_VISIBILITY |
| 3115 | void |
| 3116 | swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) |
| 3117 | { |
| 3118 | return __x.swap(__y); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3119 | } |
| 3120 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3121 | // __lookahead |
| 3122 | |
| 3123 | template <class _CharT, class _Traits> |
| 3124 | class __lookahead |
| 3125 | : public __owns_one_state<_CharT> |
| 3126 | { |
| 3127 | typedef __owns_one_state<_CharT> base; |
| 3128 | |
| 3129 | basic_regex<_CharT, _Traits> __exp_; |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3130 | unsigned __mexp_; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3131 | bool __invert_; |
| 3132 | |
| 3133 | __lookahead(const __lookahead&); |
| 3134 | __lookahead& operator=(const __lookahead&); |
| 3135 | public: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3136 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3137 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 3138 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3139 | __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] | 3140 | : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {} |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3141 | |
| 3142 | virtual void __exec(__state&) const; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3143 | }; |
| 3144 | |
| 3145 | template <class _CharT, class _Traits> |
| 3146 | void |
| 3147 | __lookahead<_CharT, _Traits>::__exec(__state& __s) const |
| 3148 | { |
| 3149 | match_results<const _CharT*> __m; |
| 3150 | __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 3151 | bool __matched = __exp_.__match_at_start_ecma( |
| 3152 | __s.__current_, __s.__last_, |
| 3153 | __m, |
| 3154 | (__s.__flags_ | regex_constants::match_continuous) & |
| 3155 | ~regex_constants::__full_match, |
| 3156 | __s.__at_first_ && __s.__current_ == __s.__first_); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3157 | if (__matched != __invert_) |
| 3158 | { |
| 3159 | __s.__do_ = __state::__accept_but_not_consume; |
| 3160 | __s.__node_ = this->first(); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 3161 | for (unsigned __i = 1; __i < __m.size(); ++__i) { |
| 3162 | __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i]; |
| 3163 | } |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3164 | } |
| 3165 | else |
| 3166 | { |
| 3167 | __s.__do_ = __state::__reject; |
| 3168 | __s.__node_ = nullptr; |
| 3169 | } |
| 3170 | } |
| 3171 | |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3172 | template <class _CharT, class _Traits> |
| 3173 | template <class _ForwardIterator> |
Mark de Wever | a0ad976 | 2019-11-09 17:01:37 +0100 | [diff] [blame] | 3174 | void |
| 3175 | basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last) |
| 3176 | { |
| 3177 | if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; |
| 3178 | _ForwardIterator __temp = __parse(__first, __last); |
| 3179 | if ( __temp != __last) |
| 3180 | __throw_regex_error<regex_constants::__re_err_parse>(); |
| 3181 | } |
| 3182 | |
| 3183 | template <class _CharT, class _Traits> |
| 3184 | template <class _ForwardIterator> |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3185 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3186 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 3187 | _ForwardIterator __last) |
| 3188 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3189 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 3190 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3191 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 3192 | __h.release(); |
| 3193 | __end_ = __start_.get(); |
| 3194 | } |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3195 | switch (__get_grammar(__flags_)) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3196 | { |
| 3197 | case ECMAScript: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3198 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3199 | break; |
| 3200 | case basic: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3201 | __first = __parse_basic_reg_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3202 | break; |
| 3203 | case extended: |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3204 | case awk: |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3205 | __first = __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3206 | break; |
| 3207 | case grep: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3208 | __first = __parse_grep(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3209 | break; |
| 3210 | case egrep: |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3211 | __first = __parse_egrep(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3212 | break; |
| 3213 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3214 | __throw_regex_error<regex_constants::__re_err_grammar>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3215 | } |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3216 | return __first; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | template <class _CharT, class _Traits> |
| 3220 | template <class _ForwardIterator> |
| 3221 | _ForwardIterator |
| 3222 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 3223 | _ForwardIterator __last) |
| 3224 | { |
| 3225 | if (__first != __last) |
| 3226 | { |
| 3227 | if (*__first == '^') |
| 3228 | { |
| 3229 | __push_l_anchor(); |
| 3230 | ++__first; |
| 3231 | } |
| 3232 | if (__first != __last) |
| 3233 | { |
| 3234 | __first = __parse_RE_expression(__first, __last); |
| 3235 | if (__first != __last) |
| 3236 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3237 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3238 | if (__temp == __last && *__first == '$') |
| 3239 | { |
| 3240 | __push_r_anchor(); |
| 3241 | ++__first; |
| 3242 | } |
| 3243 | } |
| 3244 | } |
| 3245 | if (__first != __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3246 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3247 | } |
| 3248 | return __first; |
| 3249 | } |
| 3250 | |
| 3251 | template <class _CharT, class _Traits> |
| 3252 | template <class _ForwardIterator> |
| 3253 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3254 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 3255 | _ForwardIterator __last) |
| 3256 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3257 | __owns_one_state<_CharT>* __sa = __end_; |
| 3258 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
| 3259 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3260 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3261 | __first = __temp; |
| 3262 | while (__first != __last && *__first == '|') |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3263 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3264 | __owns_one_state<_CharT>* __sb = __end_; |
| 3265 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3266 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3267 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3268 | __push_alternation(__sa, __sb); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3269 | __first = __temp; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3270 | } |
| 3271 | return __first; |
| 3272 | } |
| 3273 | |
| 3274 | template <class _CharT, class _Traits> |
| 3275 | template <class _ForwardIterator> |
| 3276 | _ForwardIterator |
| 3277 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 3278 | _ForwardIterator __last) |
| 3279 | { |
| 3280 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
| 3281 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3282 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3283 | do |
| 3284 | { |
| 3285 | __first = __temp; |
| 3286 | __temp = __parse_ERE_expression(__first, __last); |
| 3287 | } while (__temp != __first); |
| 3288 | return __first; |
| 3289 | } |
| 3290 | |
| 3291 | template <class _CharT, class _Traits> |
| 3292 | template <class _ForwardIterator> |
| 3293 | _ForwardIterator |
| 3294 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 3295 | _ForwardIterator __last) |
| 3296 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3297 | __owns_one_state<_CharT>* __e = __end_; |
| 3298 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3299 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 3300 | if (__temp == __first && __temp != __last) |
| 3301 | { |
| 3302 | switch (*__temp) |
| 3303 | { |
| 3304 | case '^': |
| 3305 | __push_l_anchor(); |
| 3306 | ++__temp; |
| 3307 | break; |
| 3308 | case '$': |
| 3309 | __push_r_anchor(); |
| 3310 | ++__temp; |
| 3311 | break; |
| 3312 | case '(': |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3313 | __push_begin_marked_subexpression(); |
| 3314 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3315 | ++__open_count_; |
| 3316 | __temp = __parse_extended_reg_exp(++__temp, __last); |
| 3317 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3318 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3319 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3320 | --__open_count_; |
| 3321 | ++__temp; |
| 3322 | break; |
| 3323 | } |
| 3324 | } |
| 3325 | if (__temp != __first) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3326 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 3327 | __marked_count_+1); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3328 | __first = __temp; |
| 3329 | return __first; |
| 3330 | } |
| 3331 | |
| 3332 | template <class _CharT, class _Traits> |
| 3333 | template <class _ForwardIterator> |
| 3334 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3335 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 3336 | _ForwardIterator __last) |
| 3337 | { |
| 3338 | while (true) |
| 3339 | { |
| 3340 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 3341 | if (__temp == __first) |
| 3342 | break; |
| 3343 | __first = __temp; |
| 3344 | } |
| 3345 | return __first; |
| 3346 | } |
| 3347 | |
| 3348 | template <class _CharT, class _Traits> |
| 3349 | template <class _ForwardIterator> |
| 3350 | _ForwardIterator |
| 3351 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 3352 | _ForwardIterator __last) |
| 3353 | { |
| 3354 | if (__first != __last) |
| 3355 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3356 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3357 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3358 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 3359 | if (__temp != __first) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3360 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 3361 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3362 | } |
| 3363 | return __first; |
| 3364 | } |
| 3365 | |
| 3366 | template <class _CharT, class _Traits> |
| 3367 | template <class _ForwardIterator> |
| 3368 | _ForwardIterator |
| 3369 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 3370 | _ForwardIterator __last) |
| 3371 | { |
| 3372 | _ForwardIterator __temp = __first; |
| 3373 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 3374 | if (__temp == __first) |
| 3375 | { |
| 3376 | __temp = __parse_Back_open_paren(__first, __last); |
| 3377 | if (__temp != __first) |
| 3378 | { |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3379 | __push_begin_marked_subexpression(); |
| 3380 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3381 | __first = __parse_RE_expression(__temp, __last); |
| 3382 | __temp = __parse_Back_close_paren(__first, __last); |
| 3383 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3384 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3385 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3386 | __first = __temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3387 | } |
| 3388 | else |
| 3389 | __first = __parse_BACKREF(__first, __last); |
| 3390 | } |
| 3391 | return __first; |
| 3392 | } |
| 3393 | |
| 3394 | template <class _CharT, class _Traits> |
| 3395 | template <class _ForwardIterator> |
| 3396 | _ForwardIterator |
| 3397 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3398 | _ForwardIterator __first, |
| 3399 | _ForwardIterator __last) |
| 3400 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3401 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3402 | if (__temp == __first) |
| 3403 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3404 | __temp = __parse_QUOTED_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 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3408 | { |
| 3409 | __push_match_any(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3410 | ++__temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3411 | } |
| 3412 | else |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3413 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3414 | } |
| 3415 | } |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3416 | __first = __temp; |
| 3417 | return __first; |
| 3418 | } |
| 3419 | |
| 3420 | template <class _CharT, class _Traits> |
| 3421 | template <class _ForwardIterator> |
| 3422 | _ForwardIterator |
| 3423 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3424 | _ForwardIterator __first, |
| 3425 | _ForwardIterator __last) |
| 3426 | { |
| 3427 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3428 | if (__temp == __first) |
| 3429 | { |
| 3430 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3431 | if (__temp == __first) |
| 3432 | { |
| 3433 | if (__temp != __last && *__temp == '.') |
| 3434 | { |
| 3435 | __push_match_any(); |
| 3436 | ++__temp; |
| 3437 | } |
| 3438 | else |
| 3439 | __temp = __parse_bracket_expression(__first, __last); |
| 3440 | } |
| 3441 | } |
| 3442 | __first = __temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3443 | return __first; |
| 3444 | } |
| 3445 | |
| 3446 | template <class _CharT, class _Traits> |
| 3447 | template <class _ForwardIterator> |
| 3448 | _ForwardIterator |
| 3449 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3450 | _ForwardIterator __last) |
| 3451 | { |
| 3452 | if (__first != __last) |
| 3453 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3454 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3455 | if (__temp != __last) |
| 3456 | { |
| 3457 | if (*__first == '\\' && *__temp == '(') |
| 3458 | __first = ++__temp; |
| 3459 | } |
| 3460 | } |
| 3461 | return __first; |
| 3462 | } |
| 3463 | |
| 3464 | template <class _CharT, class _Traits> |
| 3465 | template <class _ForwardIterator> |
| 3466 | _ForwardIterator |
| 3467 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3468 | _ForwardIterator __last) |
| 3469 | { |
| 3470 | if (__first != __last) |
| 3471 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3472 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3473 | if (__temp != __last) |
| 3474 | { |
| 3475 | if (*__first == '\\' && *__temp == ')') |
| 3476 | __first = ++__temp; |
| 3477 | } |
| 3478 | } |
| 3479 | return __first; |
| 3480 | } |
| 3481 | |
| 3482 | template <class _CharT, class _Traits> |
| 3483 | template <class _ForwardIterator> |
| 3484 | _ForwardIterator |
| 3485 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3486 | _ForwardIterator __last) |
| 3487 | { |
| 3488 | if (__first != __last) |
| 3489 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3490 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3491 | if (__temp != __last) |
| 3492 | { |
| 3493 | if (*__first == '\\' && *__temp == '{') |
| 3494 | __first = ++__temp; |
| 3495 | } |
| 3496 | } |
| 3497 | return __first; |
| 3498 | } |
| 3499 | |
| 3500 | template <class _CharT, class _Traits> |
| 3501 | template <class _ForwardIterator> |
| 3502 | _ForwardIterator |
| 3503 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3504 | _ForwardIterator __last) |
| 3505 | { |
| 3506 | if (__first != __last) |
| 3507 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3508 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3509 | if (__temp != __last) |
| 3510 | { |
| 3511 | if (*__first == '\\' && *__temp == '}') |
| 3512 | __first = ++__temp; |
| 3513 | } |
| 3514 | } |
| 3515 | return __first; |
| 3516 | } |
| 3517 | |
| 3518 | template <class _CharT, class _Traits> |
| 3519 | template <class _ForwardIterator> |
| 3520 | _ForwardIterator |
| 3521 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 3522 | _ForwardIterator __last) |
| 3523 | { |
| 3524 | if (__first != __last) |
| 3525 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3526 | _ForwardIterator __temp = _VSTD::next(__first); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 3527 | if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp)) |
| 3528 | __first = ++__temp; |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3529 | } |
| 3530 | return __first; |
| 3531 | } |
| 3532 | |
| 3533 | template <class _CharT, class _Traits> |
| 3534 | template <class _ForwardIterator> |
| 3535 | _ForwardIterator |
| 3536 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3537 | _ForwardIterator __last) |
| 3538 | { |
| 3539 | if (__first != __last) |
| 3540 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3541 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3542 | if (__temp == __last && *__first == '$') |
| 3543 | return __first; |
| 3544 | // Not called inside a bracket |
| 3545 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3546 | return __first; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3547 | __push_char(*__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3548 | ++__first; |
| 3549 | } |
| 3550 | return __first; |
| 3551 | } |
| 3552 | |
| 3553 | template <class _CharT, class _Traits> |
| 3554 | template <class _ForwardIterator> |
| 3555 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3556 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3557 | _ForwardIterator __last) |
| 3558 | { |
| 3559 | if (__first != __last) |
| 3560 | { |
| 3561 | switch (*__first) |
| 3562 | { |
| 3563 | case '^': |
| 3564 | case '.': |
| 3565 | case '[': |
| 3566 | case '$': |
| 3567 | case '(': |
| 3568 | case '|': |
| 3569 | case '*': |
| 3570 | case '+': |
| 3571 | case '?': |
| 3572 | case '{': |
| 3573 | case '\\': |
| 3574 | break; |
| 3575 | case ')': |
| 3576 | if (__open_count_ == 0) |
| 3577 | { |
| 3578 | __push_char(*__first); |
| 3579 | ++__first; |
| 3580 | } |
| 3581 | break; |
| 3582 | default: |
| 3583 | __push_char(*__first); |
| 3584 | ++__first; |
| 3585 | break; |
| 3586 | } |
| 3587 | } |
| 3588 | return __first; |
| 3589 | } |
| 3590 | |
| 3591 | template <class _CharT, class _Traits> |
| 3592 | template <class _ForwardIterator> |
| 3593 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3594 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3595 | _ForwardIterator __last) |
| 3596 | { |
| 3597 | if (__first != __last) |
| 3598 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3599 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3600 | if (__temp != __last) |
| 3601 | { |
| 3602 | if (*__first == '\\') |
| 3603 | { |
| 3604 | switch (*__temp) |
| 3605 | { |
| 3606 | case '^': |
| 3607 | case '.': |
| 3608 | case '*': |
| 3609 | case '[': |
| 3610 | case '$': |
| 3611 | case '\\': |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3612 | __push_char(*__temp); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3613 | __first = ++__temp; |
| 3614 | break; |
| 3615 | } |
| 3616 | } |
| 3617 | } |
| 3618 | } |
| 3619 | return __first; |
| 3620 | } |
| 3621 | |
| 3622 | template <class _CharT, class _Traits> |
| 3623 | template <class _ForwardIterator> |
| 3624 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3625 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3626 | _ForwardIterator __last) |
| 3627 | { |
| 3628 | if (__first != __last) |
| 3629 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3630 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3631 | if (__temp != __last) |
| 3632 | { |
| 3633 | if (*__first == '\\') |
| 3634 | { |
| 3635 | switch (*__temp) |
| 3636 | { |
| 3637 | case '^': |
| 3638 | case '.': |
| 3639 | case '*': |
| 3640 | case '[': |
| 3641 | case '$': |
| 3642 | case '\\': |
| 3643 | case '(': |
| 3644 | case ')': |
| 3645 | case '|': |
| 3646 | case '+': |
| 3647 | case '?': |
| 3648 | case '{': |
Howard Hinnant | 73072eb | 2013-06-28 20:31:05 +0000 | [diff] [blame] | 3649 | case '}': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3650 | __push_char(*__temp); |
| 3651 | __first = ++__temp; |
| 3652 | break; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3653 | default: |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3654 | if (__get_grammar(__flags_) == awk) |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3655 | __first = __parse_awk_escape(++__first, __last); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 3656 | else if(__test_back_ref(*__temp)) |
| 3657 | __first = ++__temp; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3658 | break; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3659 | } |
| 3660 | } |
| 3661 | } |
| 3662 | } |
| 3663 | return __first; |
| 3664 | } |
| 3665 | |
| 3666 | template <class _CharT, class _Traits> |
| 3667 | template <class _ForwardIterator> |
| 3668 | _ForwardIterator |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3669 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3670 | _ForwardIterator __last, |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3671 | __owns_one_state<_CharT>* __s, |
| 3672 | unsigned __mexp_begin, |
| 3673 | unsigned __mexp_end) |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3674 | { |
| 3675 | if (__first != __last) |
| 3676 | { |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3677 | if (*__first == '*') |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3678 | { |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3679 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3680 | ++__first; |
| 3681 | } |
| 3682 | else |
| 3683 | { |
| 3684 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3685 | if (__temp != __first) |
| 3686 | { |
| 3687 | int __min = 0; |
| 3688 | __first = __temp; |
| 3689 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 3690 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3691 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3692 | __first = __temp; |
| 3693 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3694 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3695 | if (*__first != ',') |
| 3696 | { |
| 3697 | __temp = __parse_Back_close_brace(__first, __last); |
| 3698 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3699 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3700 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3701 | true); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3702 | __first = __temp; |
| 3703 | } |
| 3704 | else |
| 3705 | { |
| 3706 | ++__first; // consume ',' |
| 3707 | int __max = -1; |
| 3708 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3709 | __temp = __parse_Back_close_brace(__first, __last); |
| 3710 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3711 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3712 | if (__max == -1) |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3713 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3714 | else |
| 3715 | { |
| 3716 | if (__max < __min) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3717 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3718 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3719 | true); |
Howard Hinnant | 6c89168 | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3720 | } |
| 3721 | __first = __temp; |
| 3722 | } |
| 3723 | } |
| 3724 | } |
| 3725 | } |
| 3726 | return __first; |
| 3727 | } |
| 3728 | |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3729 | template <class _CharT, class _Traits> |
| 3730 | template <class _ForwardIterator> |
| 3731 | _ForwardIterator |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3732 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3733 | _ForwardIterator __last, |
| 3734 | __owns_one_state<_CharT>* __s, |
| 3735 | unsigned __mexp_begin, |
| 3736 | unsigned __mexp_end) |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3737 | { |
| 3738 | if (__first != __last) |
| 3739 | { |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3740 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3741 | switch (*__first) |
| 3742 | { |
| 3743 | case '*': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3744 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3745 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3746 | { |
| 3747 | ++__first; |
| 3748 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3749 | } |
| 3750 | else |
| 3751 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3752 | break; |
| 3753 | case '+': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3754 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3755 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3756 | { |
| 3757 | ++__first; |
| 3758 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3759 | } |
| 3760 | else |
| 3761 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3762 | break; |
| 3763 | case '?': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3764 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3765 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3766 | { |
| 3767 | ++__first; |
| 3768 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3769 | } |
| 3770 | else |
| 3771 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3772 | break; |
| 3773 | case '{': |
| 3774 | { |
| 3775 | int __min; |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3776 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3777 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3778 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3779 | __first = __temp; |
| 3780 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3781 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3782 | switch (*__first) |
| 3783 | { |
| 3784 | case '}': |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3785 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3786 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3787 | { |
| 3788 | ++__first; |
| 3789 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3790 | } |
| 3791 | else |
| 3792 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3793 | break; |
| 3794 | case ',': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3795 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3796 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3797 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3798 | if (*__first == '}') |
| 3799 | { |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3800 | ++__first; |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3801 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3802 | { |
| 3803 | ++__first; |
| 3804 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3805 | } |
| 3806 | else |
| 3807 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3808 | } |
| 3809 | else |
| 3810 | { |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3811 | int __max = -1; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3812 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 3813 | if (__temp == __first) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3814 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3815 | __first = __temp; |
| 3816 | if (__first == __last || *__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; |
| 3819 | if (__max < __min) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3820 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 446e9c6 | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3821 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3822 | { |
| 3823 | ++__first; |
| 3824 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3825 | } |
| 3826 | else |
| 3827 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3828 | } |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3829 | break; |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3830 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3831 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3832 | } |
| 3833 | } |
| 3834 | break; |
| 3835 | } |
| 3836 | } |
| 3837 | return __first; |
| 3838 | } |
| 3839 | |
| 3840 | template <class _CharT, class _Traits> |
| 3841 | template <class _ForwardIterator> |
| 3842 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3843 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3844 | _ForwardIterator __last) |
| 3845 | { |
| 3846 | if (__first != __last && *__first == '[') |
| 3847 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3848 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3849 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3850 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3851 | bool __negate = false; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3852 | if (*__first == '^') |
| 3853 | { |
| 3854 | ++__first; |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3855 | __negate = true; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3856 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3857 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3858 | // __ml owned by *this |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3859 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3860 | __throw_regex_error<regex_constants::error_brack>(); |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3861 | if (__get_grammar(__flags_) != ECMAScript && *__first == ']') |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3862 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3863 | __ml->__add_char(']'); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3864 | ++__first; |
| 3865 | } |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3866 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3867 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3868 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3869 | if (*__first == '-') |
| 3870 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3871 | __ml->__add_char('-'); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3872 | ++__first; |
| 3873 | } |
| 3874 | if (__first == __last || *__first != ']') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3875 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3876 | ++__first; |
| 3877 | } |
| 3878 | return __first; |
| 3879 | } |
| 3880 | |
| 3881 | template <class _CharT, class _Traits> |
| 3882 | template <class _ForwardIterator> |
| 3883 | _ForwardIterator |
| 3884 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3885 | _ForwardIterator __last, |
| 3886 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3887 | { |
| 3888 | if (__first != __last) |
| 3889 | { |
| 3890 | while (true) |
| 3891 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3892 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3893 | __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3894 | if (__temp == __first) |
| 3895 | break; |
| 3896 | __first = __temp; |
| 3897 | } |
| 3898 | } |
| 3899 | return __first; |
| 3900 | } |
| 3901 | |
| 3902 | template <class _CharT, class _Traits> |
| 3903 | template <class _ForwardIterator> |
| 3904 | _ForwardIterator |
| 3905 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3906 | _ForwardIterator __last, |
| 3907 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3908 | { |
| 3909 | if (__first != __last && *__first != ']') |
| 3910 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3911 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3912 | basic_string<_CharT> __start_range; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3913 | if (__temp != __last && *__first == '[') |
| 3914 | { |
| 3915 | if (*__temp == '=') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3916 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3917 | else if (*__temp == ':') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3918 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3919 | else if (*__temp == '.') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3920 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3921 | } |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 3922 | unsigned __grammar = __get_grammar(__flags_); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3923 | if (__start_range.empty()) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3924 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3925 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3926 | { |
| 3927 | if (__grammar == ECMAScript) |
| 3928 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3929 | else |
| 3930 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3931 | } |
| 3932 | else |
| 3933 | { |
| 3934 | __start_range = *__first; |
| 3935 | ++__first; |
| 3936 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3937 | } |
| 3938 | if (__first != __last && *__first != ']') |
| 3939 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3940 | __temp = _VSTD::next(__first); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3941 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3942 | { |
| 3943 | // parse a range |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3944 | basic_string<_CharT> __end_range; |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3945 | __first = __temp; |
| 3946 | ++__temp; |
| 3947 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3948 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3949 | else |
| 3950 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3951 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3952 | { |
| 3953 | if (__grammar == ECMAScript) |
| 3954 | __first = __parse_class_escape(++__first, __last, |
| 3955 | __end_range, __ml); |
| 3956 | else |
| 3957 | __first = __parse_awk_escape(++__first, __last, |
| 3958 | &__end_range); |
| 3959 | } |
| 3960 | else |
| 3961 | { |
| 3962 | __end_range = *__first; |
| 3963 | ++__first; |
| 3964 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3965 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3966 | __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3967 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3968 | else if (!__start_range.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3969 | { |
| 3970 | if (__start_range.size() == 1) |
| 3971 | __ml->__add_char(__start_range[0]); |
| 3972 | else |
| 3973 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3974 | } |
| 3975 | } |
Howard Hinnant | 8ea9824 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3976 | else if (!__start_range.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3977 | { |
| 3978 | if (__start_range.size() == 1) |
| 3979 | __ml->__add_char(__start_range[0]); |
| 3980 | else |
| 3981 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3982 | } |
| 3983 | } |
| 3984 | return __first; |
| 3985 | } |
| 3986 | |
| 3987 | template <class _CharT, class _Traits> |
| 3988 | template <class _ForwardIterator> |
| 3989 | _ForwardIterator |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3990 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 3991 | _ForwardIterator __last, |
| 3992 | basic_string<_CharT>& __str, |
| 3993 | __bracket_expression<_CharT, _Traits>* __ml) |
| 3994 | { |
| 3995 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 3996 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3997 | switch (*__first) |
| 3998 | { |
| 3999 | case 0: |
| 4000 | __str = *__first; |
| 4001 | return ++__first; |
| 4002 | case 'b': |
| 4003 | __str = _CharT(8); |
| 4004 | return ++__first; |
| 4005 | case 'd': |
| 4006 | __ml->__add_class(ctype_base::digit); |
| 4007 | return ++__first; |
| 4008 | case 'D': |
| 4009 | __ml->__add_neg_class(ctype_base::digit); |
| 4010 | return ++__first; |
| 4011 | case 's': |
| 4012 | __ml->__add_class(ctype_base::space); |
| 4013 | return ++__first; |
| 4014 | case 'S': |
| 4015 | __ml->__add_neg_class(ctype_base::space); |
| 4016 | return ++__first; |
| 4017 | case 'w': |
| 4018 | __ml->__add_class(ctype_base::alnum); |
| 4019 | __ml->__add_char('_'); |
| 4020 | return ++__first; |
| 4021 | case 'W': |
| 4022 | __ml->__add_neg_class(ctype_base::alnum); |
| 4023 | __ml->__add_neg_char('_'); |
| 4024 | return ++__first; |
| 4025 | } |
| 4026 | __first = __parse_character_escape(__first, __last, &__str); |
| 4027 | return __first; |
| 4028 | } |
| 4029 | |
| 4030 | template <class _CharT, class _Traits> |
| 4031 | template <class _ForwardIterator> |
| 4032 | _ForwardIterator |
| 4033 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 4034 | _ForwardIterator __last, |
| 4035 | basic_string<_CharT>* __str) |
| 4036 | { |
| 4037 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4038 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4039 | switch (*__first) |
| 4040 | { |
| 4041 | case '\\': |
| 4042 | case '"': |
| 4043 | case '/': |
| 4044 | if (__str) |
| 4045 | *__str = *__first; |
| 4046 | else |
| 4047 | __push_char(*__first); |
| 4048 | return ++__first; |
| 4049 | case 'a': |
| 4050 | if (__str) |
| 4051 | *__str = _CharT(7); |
| 4052 | else |
| 4053 | __push_char(_CharT(7)); |
| 4054 | return ++__first; |
| 4055 | case 'b': |
| 4056 | if (__str) |
| 4057 | *__str = _CharT(8); |
| 4058 | else |
| 4059 | __push_char(_CharT(8)); |
| 4060 | return ++__first; |
| 4061 | case 'f': |
| 4062 | if (__str) |
| 4063 | *__str = _CharT(0xC); |
| 4064 | else |
| 4065 | __push_char(_CharT(0xC)); |
| 4066 | return ++__first; |
| 4067 | case 'n': |
| 4068 | if (__str) |
| 4069 | *__str = _CharT(0xA); |
| 4070 | else |
| 4071 | __push_char(_CharT(0xA)); |
| 4072 | return ++__first; |
| 4073 | case 'r': |
| 4074 | if (__str) |
| 4075 | *__str = _CharT(0xD); |
| 4076 | else |
| 4077 | __push_char(_CharT(0xD)); |
| 4078 | return ++__first; |
| 4079 | case 't': |
| 4080 | if (__str) |
| 4081 | *__str = _CharT(0x9); |
| 4082 | else |
| 4083 | __push_char(_CharT(0x9)); |
| 4084 | return ++__first; |
| 4085 | case 'v': |
| 4086 | if (__str) |
| 4087 | *__str = _CharT(0xB); |
| 4088 | else |
| 4089 | __push_char(_CharT(0xB)); |
| 4090 | return ++__first; |
| 4091 | } |
| 4092 | if ('0' <= *__first && *__first <= '7') |
| 4093 | { |
| 4094 | unsigned __val = *__first - '0'; |
| 4095 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 4096 | { |
| 4097 | __val = 8 * __val + *__first - '0'; |
| 4098 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
Howard Hinnant | a309687 | 2013-07-02 17:43:31 +0000 | [diff] [blame] | 4099 | __val = 8 * __val + *__first++ - '0'; |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4100 | } |
| 4101 | if (__str) |
| 4102 | *__str = _CharT(__val); |
| 4103 | else |
| 4104 | __push_char(_CharT(__val)); |
| 4105 | } |
| 4106 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4107 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4108 | return __first; |
| 4109 | } |
| 4110 | |
| 4111 | template <class _CharT, class _Traits> |
| 4112 | template <class _ForwardIterator> |
| 4113 | _ForwardIterator |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4114 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4115 | _ForwardIterator __last, |
| 4116 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4117 | { |
| 4118 | // Found [= |
| 4119 | // This means =] must exist |
| 4120 | value_type _Equal_close[2] = {'=', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4121 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4122 | _Equal_close+2); |
| 4123 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4124 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4125 | // [__first, __temp) contains all text in [= ... =] |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4126 | string_type __collate_name = |
| 4127 | __traits_.lookup_collatename(__first, __temp); |
| 4128 | if (__collate_name.empty()) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4129 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4130 | string_type __equiv_name = |
| 4131 | __traits_.transform_primary(__collate_name.begin(), |
| 4132 | __collate_name.end()); |
| 4133 | if (!__equiv_name.empty()) |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4134 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4135 | else |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4136 | { |
| 4137 | switch (__collate_name.size()) |
| 4138 | { |
| 4139 | case 1: |
| 4140 | __ml->__add_char(__collate_name[0]); |
| 4141 | break; |
| 4142 | case 2: |
| 4143 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 4144 | break; |
| 4145 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4146 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4147 | } |
| 4148 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4149 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4150 | return __first; |
| 4151 | } |
| 4152 | |
| 4153 | template <class _CharT, class _Traits> |
| 4154 | template <class _ForwardIterator> |
| 4155 | _ForwardIterator |
| 4156 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4157 | _ForwardIterator __last, |
| 4158 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4159 | { |
| 4160 | // Found [: |
| 4161 | // This means :] must exist |
| 4162 | value_type _Colon_close[2] = {':', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4163 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4164 | _Colon_close+2); |
| 4165 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4166 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4167 | // [__first, __temp) contains all text in [: ... :] |
| 4168 | typedef typename _Traits::char_class_type char_class_type; |
| 4169 | char_class_type __class_type = |
| 4170 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 4171 | if (__class_type == 0) |
Mikhail Maltsev | 6ef945b | 2018-01-24 12:45:18 +0000 | [diff] [blame] | 4172 | __throw_regex_error<regex_constants::error_ctype>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4173 | __ml->__add_class(__class_type); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4174 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4175 | return __first; |
| 4176 | } |
| 4177 | |
| 4178 | template <class _CharT, class _Traits> |
| 4179 | template <class _ForwardIterator> |
| 4180 | _ForwardIterator |
| 4181 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4182 | _ForwardIterator __last, |
| 4183 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4184 | { |
| 4185 | // Found [. |
| 4186 | // This means .] must exist |
| 4187 | value_type _Dot_close[2] = {'.', ']'}; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4188 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4189 | _Dot_close+2); |
| 4190 | if (__temp == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4191 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4192 | // [__first, __temp) contains all text in [. ... .] |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4193 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 4194 | switch (__col_sym.size()) |
| 4195 | { |
| 4196 | case 1: |
| 4197 | case 2: |
| 4198 | break; |
| 4199 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4200 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4201 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4202 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4203 | return __first; |
| 4204 | } |
| 4205 | |
| 4206 | template <class _CharT, class _Traits> |
| 4207 | template <class _ForwardIterator> |
| 4208 | _ForwardIterator |
| 4209 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 4210 | _ForwardIterator __last, |
| 4211 | int& __c) |
| 4212 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4213 | if (__first != __last ) |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4214 | { |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4215 | int __val = __traits_.value(*__first, 10); |
| 4216 | if ( __val != -1 ) |
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 | __c = __val; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4219 | for (++__first; |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4220 | __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; |
| 4221 | ++__first) |
| 4222 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4223 | if (__c >= numeric_limits<int>::max() / 10) |
Marshall Clow | 863ae38 | 2017-10-19 17:39:16 +0000 | [diff] [blame] | 4224 | __throw_regex_error<regex_constants::error_badbrace>(); |
Marshall Clow | aa38d97 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4225 | __c *= 10; |
| 4226 | __c += __val; |
| 4227 | } |
Howard Hinnant | 89a4057 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4228 | } |
| 4229 | } |
| 4230 | return __first; |
| 4231 | } |
| 4232 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4233 | template <class _CharT, class _Traits> |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4234 | template <class _ForwardIterator> |
| 4235 | _ForwardIterator |
| 4236 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 4237 | _ForwardIterator __last) |
| 4238 | { |
| 4239 | __owns_one_state<_CharT>* __sa = __end_; |
| 4240 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 4241 | if (__temp == __first) |
| 4242 | __push_empty(); |
| 4243 | __first = __temp; |
| 4244 | while (__first != __last && *__first == '|') |
| 4245 | { |
| 4246 | __owns_one_state<_CharT>* __sb = __end_; |
| 4247 | __temp = __parse_alternative(++__first, __last); |
| 4248 | if (__temp == __first) |
| 4249 | __push_empty(); |
| 4250 | __push_alternation(__sa, __sb); |
| 4251 | __first = __temp; |
| 4252 | } |
| 4253 | return __first; |
| 4254 | } |
| 4255 | |
| 4256 | template <class _CharT, class _Traits> |
| 4257 | template <class _ForwardIterator> |
| 4258 | _ForwardIterator |
| 4259 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 4260 | _ForwardIterator __last) |
| 4261 | { |
| 4262 | while (true) |
| 4263 | { |
| 4264 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 4265 | if (__temp == __first) |
| 4266 | break; |
| 4267 | __first = __temp; |
| 4268 | } |
| 4269 | return __first; |
| 4270 | } |
| 4271 | |
| 4272 | template <class _CharT, class _Traits> |
| 4273 | template <class _ForwardIterator> |
| 4274 | _ForwardIterator |
| 4275 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 4276 | _ForwardIterator __last) |
| 4277 | { |
| 4278 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 4279 | if (__temp == __first) |
| 4280 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4281 | __owns_one_state<_CharT>* __e = __end_; |
| 4282 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4283 | __temp = __parse_atom(__first, __last); |
| 4284 | if (__temp != __first) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4285 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 4286 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4287 | } |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4288 | else |
| 4289 | __first = __temp; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4290 | return __first; |
| 4291 | } |
| 4292 | |
| 4293 | template <class _CharT, class _Traits> |
| 4294 | template <class _ForwardIterator> |
| 4295 | _ForwardIterator |
| 4296 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 4297 | _ForwardIterator __last) |
| 4298 | { |
| 4299 | if (__first != __last) |
| 4300 | { |
| 4301 | switch (*__first) |
| 4302 | { |
| 4303 | case '^': |
| 4304 | __push_l_anchor(); |
| 4305 | ++__first; |
| 4306 | break; |
| 4307 | case '$': |
| 4308 | __push_r_anchor(); |
| 4309 | ++__first; |
| 4310 | break; |
| 4311 | case '\\': |
| 4312 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4313 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4314 | if (__temp != __last) |
| 4315 | { |
| 4316 | if (*__temp == 'b') |
| 4317 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4318 | __push_word_boundary(false); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4319 | __first = ++__temp; |
| 4320 | } |
| 4321 | else if (*__temp == 'B') |
| 4322 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4323 | __push_word_boundary(true); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4324 | __first = ++__temp; |
| 4325 | } |
| 4326 | } |
| 4327 | } |
| 4328 | break; |
| 4329 | case '(': |
| 4330 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4331 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4332 | if (__temp != __last && *__temp == '?') |
| 4333 | { |
| 4334 | if (++__temp != __last) |
| 4335 | { |
| 4336 | switch (*__temp) |
| 4337 | { |
| 4338 | case '=': |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4339 | { |
| 4340 | basic_regex __exp; |
| 4341 | __exp.__flags_ = __flags_; |
| 4342 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4343 | unsigned __mexp = __exp.__marked_count_; |
| 4344 | __push_lookahead(_VSTD::move(__exp), false, __marked_count_); |
| 4345 | __marked_count_ += __mexp; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4346 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4347 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4348 | __first = ++__temp; |
| 4349 | } |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4350 | break; |
| 4351 | case '!': |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4352 | { |
| 4353 | basic_regex __exp; |
| 4354 | __exp.__flags_ = __flags_; |
| 4355 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4356 | unsigned __mexp = __exp.__marked_count_; |
| 4357 | __push_lookahead(_VSTD::move(__exp), true, __marked_count_); |
| 4358 | __marked_count_ += __mexp; |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4359 | if (__temp == __last || *__temp != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4360 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4361 | __first = ++__temp; |
| 4362 | } |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4363 | break; |
| 4364 | } |
| 4365 | } |
| 4366 | } |
| 4367 | } |
| 4368 | break; |
| 4369 | } |
| 4370 | } |
| 4371 | return __first; |
| 4372 | } |
| 4373 | |
| 4374 | template <class _CharT, class _Traits> |
| 4375 | template <class _ForwardIterator> |
| 4376 | _ForwardIterator |
| 4377 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4378 | _ForwardIterator __last) |
| 4379 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4380 | if (__first != __last) |
| 4381 | { |
| 4382 | switch (*__first) |
| 4383 | { |
| 4384 | case '.': |
| 4385 | __push_match_any_but_newline(); |
| 4386 | ++__first; |
| 4387 | break; |
| 4388 | case '\\': |
| 4389 | __first = __parse_atom_escape(__first, __last); |
| 4390 | break; |
| 4391 | case '[': |
| 4392 | __first = __parse_bracket_expression(__first, __last); |
| 4393 | break; |
| 4394 | case '(': |
| 4395 | { |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4396 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4397 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4398 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4399 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4400 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4401 | { |
| 4402 | ++__open_count_; |
| 4403 | __first = __parse_ecma_exp(++__temp, __last); |
| 4404 | if (__first == __last || *__first != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4405 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4406 | --__open_count_; |
| 4407 | ++__first; |
| 4408 | } |
| 4409 | else |
| 4410 | { |
| 4411 | __push_begin_marked_subexpression(); |
| 4412 | unsigned __temp_count = __marked_count_; |
| 4413 | ++__open_count_; |
| 4414 | __first = __parse_ecma_exp(__first, __last); |
| 4415 | if (__first == __last || *__first != ')') |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4416 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4417 | __push_end_marked_subexpression(__temp_count); |
| 4418 | --__open_count_; |
| 4419 | ++__first; |
| 4420 | } |
| 4421 | } |
| 4422 | break; |
Marshall Clow | 8205821 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4423 | case '*': |
| 4424 | case '+': |
| 4425 | case '?': |
| 4426 | case '{': |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4427 | __throw_regex_error<regex_constants::error_badrepeat>(); |
Marshall Clow | 8205821 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4428 | break; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4429 | default: |
| 4430 | __first = __parse_pattern_character(__first, __last); |
| 4431 | break; |
| 4432 | } |
| 4433 | } |
| 4434 | return __first; |
| 4435 | } |
| 4436 | |
| 4437 | template <class _CharT, class _Traits> |
| 4438 | template <class _ForwardIterator> |
| 4439 | _ForwardIterator |
| 4440 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4441 | _ForwardIterator __last) |
| 4442 | { |
| 4443 | if (__first != __last && *__first == '\\') |
| 4444 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4445 | _ForwardIterator __t1 = _VSTD::next(__first); |
Marshall Clow | db9633c | 2016-01-19 00:50:37 +0000 | [diff] [blame] | 4446 | if (__t1 == __last) |
| 4447 | __throw_regex_error<regex_constants::error_escape>(); |
| 4448 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4449 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4450 | if (__t2 != __t1) |
| 4451 | __first = __t2; |
| 4452 | else |
| 4453 | { |
| 4454 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4455 | if (__t2 != __t1) |
| 4456 | __first = __t2; |
| 4457 | else |
| 4458 | { |
| 4459 | __t2 = __parse_character_escape(__t1, __last); |
| 4460 | if (__t2 != __t1) |
| 4461 | __first = __t2; |
| 4462 | } |
| 4463 | } |
| 4464 | } |
| 4465 | return __first; |
| 4466 | } |
| 4467 | |
| 4468 | template <class _CharT, class _Traits> |
| 4469 | template <class _ForwardIterator> |
| 4470 | _ForwardIterator |
| 4471 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4472 | _ForwardIterator __last) |
| 4473 | { |
| 4474 | if (__first != __last) |
| 4475 | { |
| 4476 | if (*__first == '0') |
| 4477 | { |
| 4478 | __push_char(_CharT()); |
| 4479 | ++__first; |
| 4480 | } |
| 4481 | else if ('1' <= *__first && *__first <= '9') |
| 4482 | { |
| 4483 | unsigned __v = *__first - '0'; |
Marshall Clow | dc03ec7 | 2016-12-24 17:21:03 +0000 | [diff] [blame] | 4484 | for (++__first; |
| 4485 | __first != __last && '0' <= *__first && *__first <= '9'; ++__first) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4486 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 4487 | if (__v >= numeric_limits<unsigned>::max() / 10) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4488 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4489 | __v = 10 * __v + *__first - '0'; |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 4490 | } |
| 4491 | if (__v == 0 || __v > mark_count()) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4492 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4493 | __push_back_ref(__v); |
| 4494 | } |
| 4495 | } |
| 4496 | return __first; |
| 4497 | } |
| 4498 | |
| 4499 | template <class _CharT, class _Traits> |
| 4500 | template <class _ForwardIterator> |
| 4501 | _ForwardIterator |
| 4502 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4503 | _ForwardIterator __last) |
| 4504 | { |
| 4505 | if (__first != __last) |
| 4506 | { |
| 4507 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4508 | switch (*__first) |
| 4509 | { |
| 4510 | case 'd': |
| 4511 | __ml = __start_matching_list(false); |
| 4512 | __ml->__add_class(ctype_base::digit); |
| 4513 | ++__first; |
| 4514 | break; |
| 4515 | case 'D': |
| 4516 | __ml = __start_matching_list(true); |
| 4517 | __ml->__add_class(ctype_base::digit); |
| 4518 | ++__first; |
| 4519 | break; |
| 4520 | case 's': |
| 4521 | __ml = __start_matching_list(false); |
| 4522 | __ml->__add_class(ctype_base::space); |
| 4523 | ++__first; |
| 4524 | break; |
| 4525 | case 'S': |
| 4526 | __ml = __start_matching_list(true); |
| 4527 | __ml->__add_class(ctype_base::space); |
| 4528 | ++__first; |
| 4529 | break; |
| 4530 | case 'w': |
| 4531 | __ml = __start_matching_list(false); |
| 4532 | __ml->__add_class(ctype_base::alnum); |
| 4533 | __ml->__add_char('_'); |
| 4534 | ++__first; |
| 4535 | break; |
| 4536 | case 'W': |
| 4537 | __ml = __start_matching_list(true); |
| 4538 | __ml->__add_class(ctype_base::alnum); |
| 4539 | __ml->__add_char('_'); |
| 4540 | ++__first; |
| 4541 | break; |
| 4542 | } |
| 4543 | } |
| 4544 | return __first; |
| 4545 | } |
| 4546 | |
| 4547 | template <class _CharT, class _Traits> |
| 4548 | template <class _ForwardIterator> |
| 4549 | _ForwardIterator |
| 4550 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4551 | _ForwardIterator __last, |
| 4552 | basic_string<_CharT>* __str) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4553 | { |
| 4554 | if (__first != __last) |
| 4555 | { |
| 4556 | _ForwardIterator __t; |
| 4557 | unsigned __sum = 0; |
| 4558 | int __hd; |
| 4559 | switch (*__first) |
| 4560 | { |
| 4561 | case 'f': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4562 | if (__str) |
| 4563 | *__str = _CharT(0xC); |
| 4564 | else |
| 4565 | __push_char(_CharT(0xC)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4566 | ++__first; |
| 4567 | break; |
| 4568 | case 'n': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4569 | if (__str) |
| 4570 | *__str = _CharT(0xA); |
| 4571 | else |
| 4572 | __push_char(_CharT(0xA)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4573 | ++__first; |
| 4574 | break; |
| 4575 | case 'r': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4576 | if (__str) |
| 4577 | *__str = _CharT(0xD); |
| 4578 | else |
| 4579 | __push_char(_CharT(0xD)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4580 | ++__first; |
| 4581 | break; |
| 4582 | case 't': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4583 | if (__str) |
| 4584 | *__str = _CharT(0x9); |
| 4585 | else |
| 4586 | __push_char(_CharT(0x9)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4587 | ++__first; |
| 4588 | break; |
| 4589 | case 'v': |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4590 | if (__str) |
| 4591 | *__str = _CharT(0xB); |
| 4592 | else |
| 4593 | __push_char(_CharT(0xB)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4594 | ++__first; |
| 4595 | break; |
| 4596 | case 'c': |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4597 | if ((__t = _VSTD::next(__first)) != __last) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4598 | { |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4599 | if (('A' <= *__t && *__t <= 'Z') || |
Howard Hinnant | d04741b | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4600 | ('a' <= *__t && *__t <= 'z')) |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4601 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4602 | if (__str) |
| 4603 | *__str = _CharT(*__t % 32); |
| 4604 | else |
| 4605 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4606 | __first = ++__t; |
| 4607 | } |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 4608 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4609 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4610 | } |
Howard Hinnant | d04741b | 2013-07-15 18:21:11 +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 | break; |
| 4614 | case 'u': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4615 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4616 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4617 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4618 | __hd = __traits_.value(*__first, 16); |
| 4619 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4620 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4621 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4622 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4623 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4624 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4625 | __hd = __traits_.value(*__first, 16); |
| 4626 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4627 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4628 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Louis Dionne | af6be62 | 2021-07-27 17:30:47 -0400 | [diff] [blame] | 4629 | // fallthrough |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4630 | case 'x': |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4631 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4632 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4633 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4634 | __hd = __traits_.value(*__first, 16); |
| 4635 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4636 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4637 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4638 | ++__first; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4639 | if (__first == __last) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4640 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4641 | __hd = __traits_.value(*__first, 16); |
| 4642 | if (__hd == -1) |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4643 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4644 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4645 | if (__str) |
| 4646 | *__str = _CharT(__sum); |
| 4647 | else |
| 4648 | __push_char(_CharT(__sum)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4649 | ++__first; |
| 4650 | break; |
Marshall Clow | f6cef0d | 2014-05-21 16:29:50 +0000 | [diff] [blame] | 4651 | case '0': |
| 4652 | if (__str) |
| 4653 | *__str = _CharT(0); |
| 4654 | else |
| 4655 | __push_char(_CharT(0)); |
| 4656 | ++__first; |
| 4657 | break; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4658 | default: |
| 4659 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4660 | { |
Howard Hinnant | 70b3e19 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4661 | if (__str) |
| 4662 | *__str = *__first; |
| 4663 | else |
| 4664 | __push_char(*__first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4665 | ++__first; |
| 4666 | } |
Howard Hinnant | 4f7a1f5 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 4667 | else |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 4668 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4669 | break; |
| 4670 | } |
| 4671 | } |
| 4672 | return __first; |
| 4673 | } |
| 4674 | |
| 4675 | template <class _CharT, class _Traits> |
| 4676 | template <class _ForwardIterator> |
| 4677 | _ForwardIterator |
| 4678 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4679 | _ForwardIterator __last) |
| 4680 | { |
| 4681 | if (__first != __last) |
| 4682 | { |
| 4683 | switch (*__first) |
| 4684 | { |
| 4685 | case '^': |
| 4686 | case '$': |
| 4687 | case '\\': |
| 4688 | case '.': |
| 4689 | case '*': |
| 4690 | case '+': |
| 4691 | case '?': |
| 4692 | case '(': |
| 4693 | case ')': |
| 4694 | case '[': |
| 4695 | case ']': |
| 4696 | case '{': |
| 4697 | case '}': |
| 4698 | case '|': |
| 4699 | break; |
| 4700 | default: |
| 4701 | __push_char(*__first); |
| 4702 | ++__first; |
| 4703 | break; |
| 4704 | } |
| 4705 | } |
| 4706 | return __first; |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | template <class _CharT, class _Traits> |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4710 | template <class _ForwardIterator> |
| 4711 | _ForwardIterator |
| 4712 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4713 | _ForwardIterator __last) |
| 4714 | { |
| 4715 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4716 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4717 | if (__t1 != __first) |
| 4718 | __parse_basic_reg_exp(__first, __t1); |
| 4719 | else |
| 4720 | __push_empty(); |
| 4721 | __first = __t1; |
| 4722 | if (__first != __last) |
| 4723 | ++__first; |
| 4724 | while (__first != __last) |
| 4725 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4726 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4727 | __owns_one_state<_CharT>* __sb = __end_; |
| 4728 | if (__t1 != __first) |
| 4729 | __parse_basic_reg_exp(__first, __t1); |
| 4730 | else |
| 4731 | __push_empty(); |
| 4732 | __push_alternation(__sa, __sb); |
| 4733 | __first = __t1; |
| 4734 | if (__first != __last) |
| 4735 | ++__first; |
| 4736 | } |
| 4737 | return __first; |
| 4738 | } |
| 4739 | |
| 4740 | template <class _CharT, class _Traits> |
| 4741 | template <class _ForwardIterator> |
| 4742 | _ForwardIterator |
| 4743 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4744 | _ForwardIterator __last) |
| 4745 | { |
| 4746 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4747 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4748 | if (__t1 != __first) |
| 4749 | __parse_extended_reg_exp(__first, __t1); |
| 4750 | else |
| 4751 | __push_empty(); |
| 4752 | __first = __t1; |
| 4753 | if (__first != __last) |
| 4754 | ++__first; |
| 4755 | while (__first != __last) |
| 4756 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4757 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | eaf649e | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4758 | __owns_one_state<_CharT>* __sb = __end_; |
| 4759 | if (__t1 != __first) |
| 4760 | __parse_extended_reg_exp(__first, __t1); |
| 4761 | else |
| 4762 | __push_empty(); |
| 4763 | __push_alternation(__sa, __sb); |
| 4764 | __first = __t1; |
| 4765 | if (__first != __last) |
| 4766 | ++__first; |
| 4767 | } |
| 4768 | return __first; |
| 4769 | } |
| 4770 | |
| 4771 | template <class _CharT, class _Traits> |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4772 | bool |
| 4773 | basic_regex<_CharT, _Traits>::__test_back_ref(_CharT c) |
| 4774 | { |
| 4775 | unsigned __val = __traits_.value(c, 10); |
| 4776 | if (__val >= 1 && __val <= 9) |
| 4777 | { |
Mark de Wever | d324e5f | 2020-02-20 18:13:38 -0500 | [diff] [blame] | 4778 | if (__val > mark_count()) |
| 4779 | __throw_regex_error<regex_constants::error_backref>(); |
Louis Dionne | f16eb59 | 2020-02-19 15:56:15 -0500 | [diff] [blame] | 4780 | __push_back_ref(__val); |
| 4781 | return true; |
| 4782 | } |
| 4783 | |
| 4784 | return false; |
| 4785 | } |
| 4786 | |
| 4787 | template <class _CharT, class _Traits> |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4788 | void |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4789 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4790 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4791 | bool __greedy) |
| 4792 | { |
| 4793 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4794 | __end_->first() = nullptr; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4795 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4796 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4797 | __min, __max)); |
| 4798 | __s->first() = nullptr; |
| 4799 | __e1.release(); |
| 4800 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4801 | __end_ = __e2->second(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4802 | __s->first() = __e2.release(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4803 | ++__loop_count_; |
| 4804 | } |
| 4805 | |
| 4806 | template <class _CharT, class _Traits> |
| 4807 | void |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4808 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4809 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4810 | if (flags() & icase) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4811 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4812 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4813 | else if (flags() & collate) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4814 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4815 | (__traits_, __c, __end_->first()); |
| 4816 | else |
| 4817 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4818 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4819 | } |
| 4820 | |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4821 | template <class _CharT, class _Traits> |
| 4822 | void |
| 4823 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4824 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4825 | if (!(__flags_ & nosubs)) |
| 4826 | { |
| 4827 | __end_->first() = |
| 4828 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4829 | __end_->first()); |
| 4830 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4831 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | template <class _CharT, class _Traits> |
| 4835 | void |
| 4836 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4837 | { |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4838 | if (!(__flags_ & nosubs)) |
| 4839 | { |
| 4840 | __end_->first() = |
| 4841 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4842 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4843 | } |
Howard Hinnant | 93ef655 | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4844 | } |
| 4845 | |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4846 | template <class _CharT, class _Traits> |
| 4847 | void |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4848 | basic_regex<_CharT, _Traits>::__push_l_anchor() |
| 4849 | { |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 4850 | __end_->first() = new __l_anchor_multiline<_CharT>(__use_multiline(), __end_->first()); |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4851 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4852 | } |
| 4853 | |
| 4854 | template <class _CharT, class _Traits> |
| 4855 | void |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4856 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4857 | { |
Mark de Wever | a989cce | 2020-11-18 18:09:13 +0100 | [diff] [blame] | 4858 | __end_->first() = new __r_anchor_multiline<_CharT>(__use_multiline(), __end_->first()); |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4859 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4860 | } |
| 4861 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4862 | template <class _CharT, class _Traits> |
| 4863 | void |
| 4864 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4865 | { |
| 4866 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4867 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4868 | } |
Howard Hinnant | aad0aa6 | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4869 | |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4870 | template <class _CharT, class _Traits> |
| 4871 | void |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4872 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4873 | { |
| 4874 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4875 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4876 | } |
| 4877 | |
| 4878 | template <class _CharT, class _Traits> |
| 4879 | void |
Howard Hinnant | e105382 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4880 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4881 | { |
| 4882 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4883 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4884 | } |
| 4885 | |
| 4886 | template <class _CharT, class _Traits> |
| 4887 | void |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4888 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4889 | { |
| 4890 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4891 | __end_->first()); |
| 4892 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4893 | } |
| 4894 | |
| 4895 | template <class _CharT, class _Traits> |
| 4896 | void |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4897 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4898 | { |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4899 | if (flags() & icase) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4900 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4901 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4902 | else if (flags() & collate) |
Howard Hinnant | cfe8d27 | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4903 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4904 | (__traits_, __i, __end_->first()); |
| 4905 | else |
| 4906 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | 2a315e3 | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4907 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4908 | } |
| 4909 | |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4910 | template <class _CharT, class _Traits> |
Howard Hinnant | 16d6542 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4911 | void |
| 4912 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4913 | __owns_one_state<_CharT>* __ea) |
| 4914 | { |
| 4915 | __sa->first() = new __alternate<_CharT>( |
| 4916 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4917 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4918 | __ea->first() = nullptr; |
| 4919 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4920 | __end_->first() = nullptr; |
| 4921 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4922 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4923 | } |
| 4924 | |
| 4925 | template <class _CharT, class _Traits> |
Howard Hinnant | 3034c90 | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4926 | __bracket_expression<_CharT, _Traits>* |
| 4927 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4928 | { |
| 4929 | __bracket_expression<_CharT, _Traits>* __r = |
| 4930 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4931 | __negate, __flags_ & icase, |
| 4932 | __flags_ & collate); |
| 4933 | __end_->first() = __r; |
| 4934 | __end_ = __r; |
| 4935 | return __r; |
| 4936 | } |
| 4937 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4938 | template <class _CharT, class _Traits> |
| 4939 | void |
| 4940 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4941 | bool __invert, |
| 4942 | unsigned __mexp) |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4943 | { |
| 4944 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
Howard Hinnant | 3efac71 | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4945 | __end_->first(), __mexp); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4946 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4947 | } |
| 4948 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4949 | // sub_match |
| 4950 | |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4951 | typedef sub_match<const char*> csub_match; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4952 | typedef sub_match<string::const_iterator> ssub_match; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4953 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 4954 | typedef sub_match<const wchar_t*> wcsub_match; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4955 | typedef sub_match<wstring::const_iterator> wssub_match; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4956 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4957 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4958 | template <class _BidirectionalIterator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4959 | class |
| 4960 | _LIBCPP_TEMPLATE_VIS |
| 4961 | _LIBCPP_PREFERRED_NAME(csub_match) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4962 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4963 | _LIBCPP_PREFERRED_NAME(ssub_match) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 4964 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 4965 | sub_match |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4966 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4967 | { |
| 4968 | public: |
| 4969 | typedef _BidirectionalIterator iterator; |
| 4970 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4971 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4972 | typedef basic_string<value_type> string_type; |
| 4973 | |
| 4974 | bool matched; |
| 4975 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4976 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 5ddd33c | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 4977 | _LIBCPP_CONSTEXPR sub_match() : matched() {} |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 4978 | |
| 4979 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4980 | difference_type length() const |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4981 | {return matched ? _VSTD::distance(this->first, this->second) : 0;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4982 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4983 | string_type str() const |
| 4984 | {return matched ? string_type(this->first, this->second) : string_type();} |
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 | operator string_type() const |
| 4987 | {return str();} |
| 4988 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4989 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4990 | int compare(const sub_match& __s) const |
| 4991 | {return str().compare(__s.str());} |
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 string_type& __s) const |
| 4994 | {return str().compare(__s);} |
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 value_type* __s) const |
| 4997 | {return str().compare(__s);} |
| 4998 | }; |
| 4999 | |
Howard Hinnant | 67ad213 | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 5000 | template <class _BiIter> |
| 5001 | inline _LIBCPP_INLINE_VISIBILITY |
| 5002 | bool |
| 5003 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5004 | { |
| 5005 | return __x.compare(__y) == 0; |
| 5006 | } |
| 5007 | |
| 5008 | template <class _BiIter> |
| 5009 | inline _LIBCPP_INLINE_VISIBILITY |
| 5010 | bool |
| 5011 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5012 | { |
| 5013 | return !(__x == __y); |
| 5014 | } |
| 5015 | |
| 5016 | template <class _BiIter> |
| 5017 | inline _LIBCPP_INLINE_VISIBILITY |
| 5018 | bool |
| 5019 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5020 | { |
| 5021 | return __x.compare(__y) < 0; |
| 5022 | } |
| 5023 | |
| 5024 | template <class _BiIter> |
| 5025 | inline _LIBCPP_INLINE_VISIBILITY |
| 5026 | bool |
| 5027 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5028 | { |
| 5029 | return !(__y < __x); |
| 5030 | } |
| 5031 | |
| 5032 | template <class _BiIter> |
| 5033 | inline _LIBCPP_INLINE_VISIBILITY |
| 5034 | bool |
| 5035 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5036 | { |
| 5037 | return !(__x < __y); |
| 5038 | } |
| 5039 | |
| 5040 | template <class _BiIter> |
| 5041 | inline _LIBCPP_INLINE_VISIBILITY |
| 5042 | bool |
| 5043 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 5044 | { |
| 5045 | return __y < __x; |
| 5046 | } |
| 5047 | |
| 5048 | template <class _BiIter, class _ST, class _SA> |
| 5049 | inline _LIBCPP_INLINE_VISIBILITY |
| 5050 | bool |
| 5051 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5052 | const sub_match<_BiIter>& __y) |
| 5053 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5054 | 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] | 5055 | } |
| 5056 | |
| 5057 | template <class _BiIter, class _ST, class _SA> |
| 5058 | inline _LIBCPP_INLINE_VISIBILITY |
| 5059 | bool |
| 5060 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5061 | const sub_match<_BiIter>& __y) |
| 5062 | { |
| 5063 | return !(__x == __y); |
| 5064 | } |
| 5065 | |
| 5066 | template <class _BiIter, class _ST, class _SA> |
| 5067 | inline _LIBCPP_INLINE_VISIBILITY |
| 5068 | bool |
| 5069 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5070 | const sub_match<_BiIter>& __y) |
| 5071 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5072 | 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] | 5073 | } |
| 5074 | |
| 5075 | template <class _BiIter, class _ST, class _SA> |
| 5076 | inline _LIBCPP_INLINE_VISIBILITY |
| 5077 | bool |
| 5078 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5079 | const sub_match<_BiIter>& __y) |
| 5080 | { |
| 5081 | return __y < __x; |
| 5082 | } |
| 5083 | |
| 5084 | template <class _BiIter, class _ST, class _SA> |
| 5085 | inline _LIBCPP_INLINE_VISIBILITY |
| 5086 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5087 | const sub_match<_BiIter>& __y) |
| 5088 | { |
| 5089 | return !(__x < __y); |
| 5090 | } |
| 5091 | |
| 5092 | template <class _BiIter, class _ST, class _SA> |
| 5093 | inline _LIBCPP_INLINE_VISIBILITY |
| 5094 | bool |
| 5095 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 5096 | const sub_match<_BiIter>& __y) |
| 5097 | { |
| 5098 | return !(__y < __x); |
| 5099 | } |
| 5100 | |
| 5101 | template <class _BiIter, class _ST, class _SA> |
| 5102 | inline _LIBCPP_INLINE_VISIBILITY |
| 5103 | bool |
| 5104 | operator==(const sub_match<_BiIter>& __x, |
| 5105 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5106 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5107 | 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] | 5108 | } |
| 5109 | |
| 5110 | template <class _BiIter, class _ST, class _SA> |
| 5111 | inline _LIBCPP_INLINE_VISIBILITY |
| 5112 | bool |
| 5113 | operator!=(const sub_match<_BiIter>& __x, |
| 5114 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5115 | { |
| 5116 | return !(__x == __y); |
| 5117 | } |
| 5118 | |
| 5119 | template <class _BiIter, class _ST, class _SA> |
| 5120 | inline _LIBCPP_INLINE_VISIBILITY |
| 5121 | bool |
| 5122 | operator<(const sub_match<_BiIter>& __x, |
| 5123 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5124 | { |
Marshall Clow | 54a4634 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 5125 | 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] | 5126 | } |
| 5127 | |
| 5128 | template <class _BiIter, class _ST, class _SA> |
| 5129 | inline _LIBCPP_INLINE_VISIBILITY |
| 5130 | bool operator>(const sub_match<_BiIter>& __x, |
| 5131 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5132 | { |
| 5133 | return __y < __x; |
| 5134 | } |
| 5135 | |
| 5136 | template <class _BiIter, class _ST, class _SA> |
| 5137 | inline _LIBCPP_INLINE_VISIBILITY |
| 5138 | bool |
| 5139 | operator>=(const sub_match<_BiIter>& __x, |
| 5140 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5141 | { |
| 5142 | return !(__x < __y); |
| 5143 | } |
| 5144 | |
| 5145 | template <class _BiIter, class _ST, class _SA> |
| 5146 | inline _LIBCPP_INLINE_VISIBILITY |
| 5147 | bool |
| 5148 | operator<=(const sub_match<_BiIter>& __x, |
| 5149 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 5150 | { |
| 5151 | return !(__y < __x); |
| 5152 | } |
| 5153 | |
| 5154 | template <class _BiIter> |
| 5155 | inline _LIBCPP_INLINE_VISIBILITY |
| 5156 | bool |
| 5157 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5158 | const sub_match<_BiIter>& __y) |
| 5159 | { |
| 5160 | return __y.compare(__x) == 0; |
| 5161 | } |
| 5162 | |
| 5163 | template <class _BiIter> |
| 5164 | inline _LIBCPP_INLINE_VISIBILITY |
| 5165 | bool |
| 5166 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5167 | const sub_match<_BiIter>& __y) |
| 5168 | { |
| 5169 | return !(__x == __y); |
| 5170 | } |
| 5171 | |
| 5172 | template <class _BiIter> |
| 5173 | inline _LIBCPP_INLINE_VISIBILITY |
| 5174 | bool |
| 5175 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5176 | const sub_match<_BiIter>& __y) |
| 5177 | { |
| 5178 | return __y.compare(__x) > 0; |
| 5179 | } |
| 5180 | |
| 5181 | template <class _BiIter> |
| 5182 | inline _LIBCPP_INLINE_VISIBILITY |
| 5183 | bool |
| 5184 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5185 | const sub_match<_BiIter>& __y) |
| 5186 | { |
| 5187 | return __y < __x; |
| 5188 | } |
| 5189 | |
| 5190 | template <class _BiIter> |
| 5191 | inline _LIBCPP_INLINE_VISIBILITY |
| 5192 | bool |
| 5193 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5194 | const sub_match<_BiIter>& __y) |
| 5195 | { |
| 5196 | return !(__x < __y); |
| 5197 | } |
| 5198 | |
| 5199 | template <class _BiIter> |
| 5200 | inline _LIBCPP_INLINE_VISIBILITY |
| 5201 | bool |
| 5202 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 5203 | const sub_match<_BiIter>& __y) |
| 5204 | { |
| 5205 | return !(__y < __x); |
| 5206 | } |
| 5207 | |
| 5208 | template <class _BiIter> |
| 5209 | inline _LIBCPP_INLINE_VISIBILITY |
| 5210 | bool |
| 5211 | operator==(const sub_match<_BiIter>& __x, |
| 5212 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5213 | { |
| 5214 | return __x.compare(__y) == 0; |
| 5215 | } |
| 5216 | |
| 5217 | template <class _BiIter> |
| 5218 | inline _LIBCPP_INLINE_VISIBILITY |
| 5219 | bool |
| 5220 | operator!=(const sub_match<_BiIter>& __x, |
| 5221 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5222 | { |
| 5223 | return !(__x == __y); |
| 5224 | } |
| 5225 | |
| 5226 | template <class _BiIter> |
| 5227 | inline _LIBCPP_INLINE_VISIBILITY |
| 5228 | bool |
| 5229 | operator<(const sub_match<_BiIter>& __x, |
| 5230 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5231 | { |
| 5232 | return __x.compare(__y) < 0; |
| 5233 | } |
| 5234 | |
| 5235 | template <class _BiIter> |
| 5236 | inline _LIBCPP_INLINE_VISIBILITY |
| 5237 | bool |
| 5238 | operator>(const sub_match<_BiIter>& __x, |
| 5239 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5240 | { |
| 5241 | return __y < __x; |
| 5242 | } |
| 5243 | |
| 5244 | template <class _BiIter> |
| 5245 | inline _LIBCPP_INLINE_VISIBILITY |
| 5246 | bool |
| 5247 | operator>=(const sub_match<_BiIter>& __x, |
| 5248 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5249 | { |
| 5250 | return !(__x < __y); |
| 5251 | } |
| 5252 | |
| 5253 | template <class _BiIter> |
| 5254 | inline _LIBCPP_INLINE_VISIBILITY |
| 5255 | bool |
| 5256 | operator<=(const sub_match<_BiIter>& __x, |
| 5257 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5258 | { |
| 5259 | return !(__y < __x); |
| 5260 | } |
| 5261 | |
| 5262 | template <class _BiIter> |
| 5263 | inline _LIBCPP_INLINE_VISIBILITY |
| 5264 | bool |
| 5265 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5266 | const sub_match<_BiIter>& __y) |
| 5267 | { |
| 5268 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5269 | return __y.compare(string_type(1, __x)) == 0; |
| 5270 | } |
| 5271 | |
| 5272 | template <class _BiIter> |
| 5273 | inline _LIBCPP_INLINE_VISIBILITY |
| 5274 | bool |
| 5275 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5276 | const sub_match<_BiIter>& __y) |
| 5277 | { |
| 5278 | return !(__x == __y); |
| 5279 | } |
| 5280 | |
| 5281 | template <class _BiIter> |
| 5282 | inline _LIBCPP_INLINE_VISIBILITY |
| 5283 | bool |
| 5284 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5285 | const sub_match<_BiIter>& __y) |
| 5286 | { |
| 5287 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5288 | return __y.compare(string_type(1, __x)) > 0; |
| 5289 | } |
| 5290 | |
| 5291 | template <class _BiIter> |
| 5292 | inline _LIBCPP_INLINE_VISIBILITY |
| 5293 | bool |
| 5294 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5295 | const sub_match<_BiIter>& __y) |
| 5296 | { |
| 5297 | return __y < __x; |
| 5298 | } |
| 5299 | |
| 5300 | template <class _BiIter> |
| 5301 | inline _LIBCPP_INLINE_VISIBILITY |
| 5302 | bool |
| 5303 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5304 | const sub_match<_BiIter>& __y) |
| 5305 | { |
| 5306 | return !(__x < __y); |
| 5307 | } |
| 5308 | |
| 5309 | template <class _BiIter> |
| 5310 | inline _LIBCPP_INLINE_VISIBILITY |
| 5311 | bool |
| 5312 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5313 | const sub_match<_BiIter>& __y) |
| 5314 | { |
| 5315 | return !(__y < __x); |
| 5316 | } |
| 5317 | |
| 5318 | template <class _BiIter> |
| 5319 | inline _LIBCPP_INLINE_VISIBILITY |
| 5320 | bool |
| 5321 | operator==(const sub_match<_BiIter>& __x, |
| 5322 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5323 | { |
| 5324 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5325 | return __x.compare(string_type(1, __y)) == 0; |
| 5326 | } |
| 5327 | |
| 5328 | template <class _BiIter> |
| 5329 | inline _LIBCPP_INLINE_VISIBILITY |
| 5330 | bool |
| 5331 | operator!=(const sub_match<_BiIter>& __x, |
| 5332 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5333 | { |
| 5334 | return !(__x == __y); |
| 5335 | } |
| 5336 | |
| 5337 | template <class _BiIter> |
| 5338 | inline _LIBCPP_INLINE_VISIBILITY |
| 5339 | bool |
| 5340 | operator<(const sub_match<_BiIter>& __x, |
| 5341 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5342 | { |
| 5343 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5344 | return __x.compare(string_type(1, __y)) < 0; |
| 5345 | } |
| 5346 | |
| 5347 | template <class _BiIter> |
| 5348 | inline _LIBCPP_INLINE_VISIBILITY |
| 5349 | bool |
| 5350 | operator>(const sub_match<_BiIter>& __x, |
| 5351 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5352 | { |
| 5353 | return __y < __x; |
| 5354 | } |
| 5355 | |
| 5356 | template <class _BiIter> |
| 5357 | inline _LIBCPP_INLINE_VISIBILITY |
| 5358 | bool |
| 5359 | operator>=(const sub_match<_BiIter>& __x, |
| 5360 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5361 | { |
| 5362 | return !(__x < __y); |
| 5363 | } |
| 5364 | |
| 5365 | template <class _BiIter> |
| 5366 | inline _LIBCPP_INLINE_VISIBILITY |
| 5367 | bool |
| 5368 | operator<=(const sub_match<_BiIter>& __x, |
| 5369 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5370 | { |
| 5371 | return !(__y < __x); |
| 5372 | } |
| 5373 | |
| 5374 | template <class _CharT, class _ST, class _BiIter> |
| 5375 | inline _LIBCPP_INLINE_VISIBILITY |
| 5376 | basic_ostream<_CharT, _ST>& |
| 5377 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 5378 | { |
| 5379 | return __os << __m.str(); |
| 5380 | } |
| 5381 | |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5382 | typedef match_results<const char*> cmatch; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5383 | typedef match_results<string::const_iterator> smatch; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5384 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 5385 | typedef match_results<const wchar_t*> wcmatch; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5386 | typedef match_results<wstring::const_iterator> wsmatch; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5387 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5388 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5389 | template <class _BidirectionalIterator, class _Allocator> |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5390 | class |
| 5391 | _LIBCPP_TEMPLATE_VIS |
| 5392 | _LIBCPP_PREFERRED_NAME(cmatch) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5393 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5394 | _LIBCPP_PREFERRED_NAME(smatch) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 5395 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 5396 | match_results |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5397 | { |
| 5398 | public: |
| 5399 | typedef _Allocator allocator_type; |
| 5400 | typedef sub_match<_BidirectionalIterator> value_type; |
| 5401 | private: |
| 5402 | typedef vector<value_type, allocator_type> __container_type; |
| 5403 | |
| 5404 | __container_type __matches_; |
| 5405 | value_type __unmatched_; |
| 5406 | value_type __prefix_; |
| 5407 | value_type __suffix_; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5408 | bool __ready_; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5409 | public: |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5410 | _BidirectionalIterator __position_start_; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5411 | typedef const value_type& const_reference; |
Marshall Clow | 96e0614 | 2014-02-26 01:56:31 +0000 | [diff] [blame] | 5412 | typedef value_type& reference; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5413 | typedef typename __container_type::const_iterator const_iterator; |
| 5414 | typedef const_iterator iterator; |
| 5415 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5416 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5417 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5418 | typedef basic_string<char_type> string_type; |
| 5419 | |
| 5420 | // construct/copy/destroy: |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5421 | #ifndef _LIBCPP_CXX03_LANG |
| 5422 | match_results() : match_results(allocator_type()) {} |
| 5423 | explicit match_results(const allocator_type& __a); |
| 5424 | #else |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5425 | explicit match_results(const allocator_type& __a = allocator_type()); |
Marek Kurdej | cd0bd6a | 2021-01-19 08:21:09 +0100 | [diff] [blame] | 5426 | #endif |
| 5427 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5428 | // match_results(const match_results&) = default; |
| 5429 | // match_results& operator=(const match_results&) = default; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5430 | // match_results(match_results&& __m) = default; |
| 5431 | // match_results& operator=(match_results&& __m) = default; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5432 | // ~match_results() = default; |
| 5433 | |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5434 | _LIBCPP_INLINE_VISIBILITY |
| 5435 | bool ready() const {return __ready_;} |
| 5436 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5437 | // size: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5438 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 081bcd2 | 2017-11-16 04:48:34 +0000 | [diff] [blame] | 5439 | size_type size() const _NOEXCEPT {return __matches_.size();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5440 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 081bcd2 | 2017-11-16 04:48:34 +0000 | [diff] [blame] | 5441 | size_type max_size() const _NOEXCEPT {return __matches_.max_size();} |
| 5442 | _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY |
| 5443 | bool empty() const _NOEXCEPT {return size() == 0;} |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5444 | |
| 5445 | // element access: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5446 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5447 | difference_type length(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5448 | { |
| 5449 | _LIBCPP_ASSERT(ready(), "match_results::length() called when not ready"); |
| 5450 | return (*this)[__sub].length(); |
| 5451 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5452 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5453 | difference_type position(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5454 | { |
| 5455 | _LIBCPP_ASSERT(ready(), "match_results::position() called when not ready"); |
| 5456 | return _VSTD::distance(__position_start_, (*this)[__sub].first); |
| 5457 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5458 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5459 | string_type str(size_type __sub = 0) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5460 | { |
| 5461 | _LIBCPP_ASSERT(ready(), "match_results::str() called when not ready"); |
| 5462 | return (*this)[__sub].str(); |
| 5463 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5464 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5465 | const_reference operator[](size_type __n) const |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5466 | { |
| 5467 | _LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready"); |
| 5468 | return __n < __matches_.size() ? __matches_[__n] : __unmatched_; |
| 5469 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5470 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5471 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5472 | const_reference prefix() const |
| 5473 | { |
| 5474 | _LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready"); |
| 5475 | return __prefix_; |
| 5476 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5477 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5478 | const_reference suffix() const |
| 5479 | { |
| 5480 | _LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready"); |
| 5481 | return __suffix_; |
| 5482 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5483 | |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5484 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f4191f | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5485 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5486 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5487 | const_iterator end() const {return __matches_.end();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5488 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 2f4191f | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5489 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5490 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5491 | const_iterator cend() const {return __matches_.end();} |
| 5492 | |
| 5493 | // format: |
| 5494 | template <class _OutputIter> |
| 5495 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5496 | format(_OutputIter __output_iter, const char_type* __fmt_first, |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5497 | const char_type* __fmt_last, |
| 5498 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5499 | template <class _OutputIter, class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5500 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5501 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5502 | format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5503 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5504 | {return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5505 | template <class _ST, class _SA> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5506 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5507 | basic_string<char_type, _ST, _SA> |
| 5508 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5509 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5510 | { |
| 5511 | basic_string<char_type, _ST, _SA> __r; |
| 5512 | format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), |
| 5513 | __flags); |
| 5514 | return __r; |
| 5515 | } |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5516 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5517 | string_type |
| 5518 | format(const char_type* __fmt, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5519 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5520 | { |
| 5521 | string_type __r; |
| 5522 | format(back_inserter(__r), __fmt, |
| 5523 | __fmt + char_traits<char_type>::length(__fmt), __flags); |
| 5524 | return __r; |
| 5525 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5526 | |
| 5527 | // allocator: |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5528 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5529 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5530 | |
| 5531 | // swap: |
| 5532 | void swap(match_results& __m); |
| 5533 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5534 | template <class _Bp, class _Ap> |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5535 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5536 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5537 | const match_results<_Bp, _Ap>& __m, bool __no_update_pos) |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5538 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5539 | _Bp __mf = __m.prefix().first; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5540 | __matches_.resize(__m.size()); |
| 5541 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5542 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5543 | __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); |
| 5544 | __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5545 | __matches_[__i].matched = __m[__i].matched; |
| 5546 | } |
| 5547 | __unmatched_.first = __l; |
| 5548 | __unmatched_.second = __l; |
| 5549 | __unmatched_.matched = false; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5550 | __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); |
| 5551 | __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5552 | __prefix_.matched = __m.prefix().matched; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5553 | __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); |
| 5554 | __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5555 | __suffix_.matched = __m.suffix().matched; |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5556 | if (!__no_update_pos) |
| 5557 | __position_start_ = __prefix_.first; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5558 | __ready_ = __m.ready(); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5559 | } |
| 5560 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5561 | private: |
| 5562 | void __init(unsigned __s, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5563 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5564 | bool __no_update_pos = false); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5565 | |
| 5566 | template <class, class> friend class basic_regex; |
| 5567 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5568 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5569 | friend |
| 5570 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5571 | 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] | 5572 | regex_constants::match_flag_type); |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5573 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5574 | template <class _Bp, class _Ap> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5575 | friend |
| 5576 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5577 | operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5578 | |
Howard Hinnant | 126da6a | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5579 | template <class, class> friend class __lookahead; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5580 | }; |
| 5581 | |
| 5582 | template <class _BidirectionalIterator, class _Allocator> |
| 5583 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5584 | const allocator_type& __a) |
| 5585 | : __matches_(__a), |
| 5586 | __unmatched_(), |
| 5587 | __prefix_(), |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5588 | __suffix_(), |
Eric Fiselier | a75ee26 | 2015-07-22 01:29:41 +0000 | [diff] [blame] | 5589 | __ready_(false), |
| 5590 | __position_start_() |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5591 | { |
| 5592 | } |
| 5593 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5594 | template <class _BidirectionalIterator, class _Allocator> |
| 5595 | void |
| 5596 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5597 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5598 | bool __no_update_pos) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5599 | { |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5600 | __unmatched_.first = __l; |
| 5601 | __unmatched_.second = __l; |
| 5602 | __unmatched_.matched = false; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5603 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5604 | __prefix_.first = __f; |
| 5605 | __prefix_.second = __f; |
| 5606 | __prefix_.matched = false; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5607 | __suffix_ = __unmatched_; |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5608 | if (!__no_update_pos) |
| 5609 | __position_start_ = __prefix_.first; |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5610 | __ready_ = true; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5611 | } |
| 5612 | |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5613 | template <class _BidirectionalIterator, class _Allocator> |
| 5614 | template <class _OutputIter> |
| 5615 | _OutputIter |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5616 | match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter, |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5617 | const char_type* __fmt_first, const char_type* __fmt_last, |
| 5618 | regex_constants::match_flag_type __flags) const |
| 5619 | { |
Marshall Clow | 14d319a | 2019-04-26 17:10:03 +0000 | [diff] [blame] | 5620 | _LIBCPP_ASSERT(ready(), "match_results::format() called when not ready"); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5621 | if (__flags & regex_constants::format_sed) |
| 5622 | { |
| 5623 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5624 | { |
| 5625 | if (*__fmt_first == '&') |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5626 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 5627 | __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5628 | else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) |
| 5629 | { |
| 5630 | ++__fmt_first; |
| 5631 | if ('0' <= *__fmt_first && *__fmt_first <= '9') |
| 5632 | { |
| 5633 | size_t __i = *__fmt_first - '0'; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5634 | __output_iter = _VSTD::copy((*this)[__i].first, |
| 5635 | (*this)[__i].second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5636 | } |
| 5637 | else |
| 5638 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5639 | *__output_iter = *__fmt_first; |
| 5640 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5641 | } |
| 5642 | } |
| 5643 | else |
| 5644 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5645 | *__output_iter = *__fmt_first; |
| 5646 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5647 | } |
| 5648 | } |
| 5649 | } |
| 5650 | else |
| 5651 | { |
| 5652 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5653 | { |
| 5654 | if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) |
| 5655 | { |
| 5656 | switch (__fmt_first[1]) |
| 5657 | { |
| 5658 | case '$': |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5659 | *__output_iter = *++__fmt_first; |
| 5660 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5661 | break; |
| 5662 | case '&': |
| 5663 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5664 | __output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
| 5665 | __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5666 | break; |
| 5667 | case '`': |
| 5668 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5669 | __output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5670 | break; |
| 5671 | case '\'': |
| 5672 | ++__fmt_first; |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5673 | __output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5674 | break; |
| 5675 | default: |
| 5676 | if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5677 | { |
| 5678 | ++__fmt_first; |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 5679 | size_t __idx = *__fmt_first - '0'; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5680 | if (__fmt_first + 1 != __fmt_last && |
| 5681 | '0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5682 | { |
| 5683 | ++__fmt_first; |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 5684 | if (__idx >= numeric_limits<size_t>::max() / 10) |
Marshall Clow | 266b5ec | 2017-10-19 22:10:41 +0000 | [diff] [blame] | 5685 | __throw_regex_error<regex_constants::error_escape>(); |
| 5686 | __idx = 10 * __idx + *__fmt_first - '0'; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5687 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5688 | __output_iter = _VSTD::copy((*this)[__idx].first, |
| 5689 | (*this)[__idx].second, __output_iter); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5690 | } |
| 5691 | else |
| 5692 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5693 | *__output_iter = *__fmt_first; |
| 5694 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5695 | } |
| 5696 | break; |
| 5697 | } |
| 5698 | } |
| 5699 | else |
| 5700 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5701 | *__output_iter = *__fmt_first; |
| 5702 | ++__output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5703 | } |
| 5704 | } |
| 5705 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 5706 | return __output_iter; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5707 | } |
| 5708 | |
| 5709 | template <class _BidirectionalIterator, class _Allocator> |
| 5710 | void |
| 5711 | match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) |
| 5712 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5713 | using _VSTD::swap; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5714 | swap(__matches_, __m.__matches_); |
| 5715 | swap(__unmatched_, __m.__unmatched_); |
| 5716 | swap(__prefix_, __m.__prefix_); |
| 5717 | swap(__suffix_, __m.__suffix_); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5718 | swap(__position_start_, __m.__position_start_); |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5719 | swap(__ready_, __m.__ready_); |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5720 | } |
| 5721 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5722 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5723 | bool |
| 5724 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5725 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5726 | { |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5727 | if (__x.__ready_ != __y.__ready_) |
| 5728 | return false; |
| 5729 | if (!__x.__ready_) |
| 5730 | return true; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5731 | return __x.__matches_ == __y.__matches_ && |
| 5732 | __x.__prefix_ == __y.__prefix_ && |
Howard Hinnant | b5c53a8 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5733 | __x.__suffix_ == __y.__suffix_; |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5734 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5735 | |
| 5736 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5737 | inline _LIBCPP_INLINE_VISIBILITY |
| 5738 | bool |
| 5739 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5740 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5741 | { |
| 5742 | return !(__x == __y); |
| 5743 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5744 | |
| 5745 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | cbc4525 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5746 | inline _LIBCPP_INLINE_VISIBILITY |
| 5747 | void |
| 5748 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5749 | match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5750 | { |
| 5751 | __x.swap(__y); |
| 5752 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5753 | |
| 5754 | // regex_search |
| 5755 | |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5756 | template <class _CharT, class _Traits> |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5757 | template <class _Allocator> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5758 | bool |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5759 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5760 | const _CharT* __first, const _CharT* __last, |
| 5761 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5762 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5763 | { |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5764 | vector<__state> __states; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5765 | __node* __st = __start_.get(); |
| 5766 | if (__st) |
| 5767 | { |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5768 | sub_match<const _CharT*> __unmatched; |
| 5769 | __unmatched.first = __last; |
| 5770 | __unmatched.second = __last; |
| 5771 | __unmatched.matched = false; |
| 5772 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5773 | __states.push_back(__state()); |
| 5774 | __states.back().__do_ = 0; |
| 5775 | __states.back().__first_ = __first; |
| 5776 | __states.back().__current_ = __first; |
| 5777 | __states.back().__last_ = __last; |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5778 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5779 | __states.back().__loop_data_.resize(__loop_count()); |
| 5780 | __states.back().__node_ = __st; |
| 5781 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5782 | __states.back().__at_first_ = __at_first; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5783 | int __counter = 0; |
| 5784 | int __length = __last - __first; |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5785 | do |
| 5786 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5787 | ++__counter; |
| 5788 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5789 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5790 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5791 | __state& __s = __states.back(); |
| 5792 | if (__s.__node_) |
| 5793 | __s.__node_->__exec(__s); |
| 5794 | switch (__s.__do_) |
| 5795 | { |
| 5796 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5797 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5798 | __s.__current_ == __first) |
| 5799 | { |
| 5800 | __states.pop_back(); |
| 5801 | break; |
| 5802 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5803 | if ((__flags & regex_constants::__full_match) && |
| 5804 | __s.__current_ != __last) |
| 5805 | { |
| 5806 | __states.pop_back(); |
| 5807 | break; |
| 5808 | } |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5809 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5810 | __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5811 | __m.__matches_[0].matched = true; |
| 5812 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5813 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5814 | return true; |
| 5815 | case __state::__accept_and_consume: |
| 5816 | case __state::__repeat: |
| 5817 | case __state::__accept_but_not_consume: |
| 5818 | break; |
| 5819 | case __state::__split: |
| 5820 | { |
| 5821 | __state __snext = __s; |
| 5822 | __s.__node_->__exec_split(true, __s); |
| 5823 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5824 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5825 | } |
| 5826 | break; |
| 5827 | case __state::__reject: |
| 5828 | __states.pop_back(); |
| 5829 | break; |
| 5830 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5831 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5832 | break; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5833 | |
Howard Hinnant | 70d2785 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5834 | } |
| 5835 | } while (!__states.empty()); |
| 5836 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5837 | return false; |
| 5838 | } |
| 5839 | |
| 5840 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5841 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5842 | bool |
| 5843 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5844 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5845 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5846 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5847 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5848 | deque<__state> __states; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5849 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5850 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5851 | __node* __st = __start_.get(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5852 | if (__st) |
| 5853 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5854 | __states.push_back(__state()); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5855 | __states.back().__do_ = 0; |
| 5856 | __states.back().__first_ = __first; |
| 5857 | __states.back().__current_ = __first; |
| 5858 | __states.back().__last_ = __last; |
| 5859 | __states.back().__loop_data_.resize(__loop_count()); |
| 5860 | __states.back().__node_ = __st; |
| 5861 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5862 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5863 | bool __matched = false; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5864 | int __counter = 0; |
| 5865 | int __length = __last - __first; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5866 | do |
| 5867 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5868 | ++__counter; |
| 5869 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5870 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5871 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5872 | __state& __s = __states.back(); |
| 5873 | if (__s.__node_) |
| 5874 | __s.__node_->__exec(__s); |
| 5875 | switch (__s.__do_) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5876 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5877 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5878 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5879 | __s.__current_ == __first) |
| 5880 | { |
| 5881 | __states.pop_back(); |
| 5882 | break; |
| 5883 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5884 | if ((__flags & regex_constants::__full_match) && |
| 5885 | __s.__current_ != __last) |
| 5886 | { |
| 5887 | __states.pop_back(); |
| 5888 | break; |
| 5889 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5890 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5891 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5892 | __matched = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5893 | if (__highest_j == _Np) |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5894 | __states.clear(); |
| 5895 | else |
| 5896 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5897 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5898 | case __state::__consume_input: |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5899 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5900 | case __state::__accept_and_consume: |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5901 | __states.push_front(_VSTD::move(__s)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5902 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5903 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5904 | case __state::__repeat: |
| 5905 | case __state::__accept_but_not_consume: |
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::__split: |
| 5908 | { |
| 5909 | __state __snext = __s; |
| 5910 | __s.__node_->__exec_split(true, __s); |
| 5911 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5912 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5913 | } |
| 5914 | break; |
| 5915 | case __state::__reject: |
| 5916 | __states.pop_back(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5917 | break; |
| 5918 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 5919 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5920 | break; |
| 5921 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5922 | } while (!__states.empty()); |
Howard Hinnant | 5d4aaa4 | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5923 | if (__matched) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5924 | { |
| 5925 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5926 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5927 | __m.__matches_[0].matched = true; |
| 5928 | return true; |
| 5929 | } |
| 5930 | } |
| 5931 | return false; |
| 5932 | } |
| 5933 | |
| 5934 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5935 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5936 | bool |
| 5937 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5938 | const _CharT* __first, const _CharT* __last, |
| 5939 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5940 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5941 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5942 | vector<__state> __states; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5943 | __state __best_state; |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5944 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5945 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5946 | __node* __st = __start_.get(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5947 | if (__st) |
| 5948 | { |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5949 | sub_match<const _CharT*> __unmatched; |
| 5950 | __unmatched.first = __last; |
| 5951 | __unmatched.second = __last; |
| 5952 | __unmatched.matched = false; |
| 5953 | |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5954 | __states.push_back(__state()); |
| 5955 | __states.back().__do_ = 0; |
| 5956 | __states.back().__first_ = __first; |
| 5957 | __states.back().__current_ = __first; |
| 5958 | __states.back().__last_ = __last; |
Marshall Clow | 8db143c | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5959 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5960 | __states.back().__loop_data_.resize(__loop_count()); |
| 5961 | __states.back().__node_ = __st; |
| 5962 | __states.back().__flags_ = __flags; |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5963 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5964 | bool __matched = false; |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5965 | int __counter = 0; |
| 5966 | int __length = __last - __first; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5967 | do |
| 5968 | { |
Marshall Clow | d39d21d | 2017-09-12 17:56:59 +0000 | [diff] [blame] | 5969 | ++__counter; |
| 5970 | if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && |
| 5971 | __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length) |
| 5972 | __throw_regex_error<regex_constants::error_complexity>(); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5973 | __state& __s = __states.back(); |
| 5974 | if (__s.__node_) |
| 5975 | __s.__node_->__exec(__s); |
| 5976 | switch (__s.__do_) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5977 | { |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5978 | case __state::__end_state: |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5979 | if ((__flags & regex_constants::match_not_null) && |
Tim Shen | d5f175a | 2016-10-21 20:41:47 +0000 | [diff] [blame] | 5980 | __s.__current_ == __first) |
| 5981 | { |
| 5982 | __states.pop_back(); |
| 5983 | break; |
| 5984 | } |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 5985 | if ((__flags & regex_constants::__full_match) && |
| 5986 | __s.__current_ != __last) |
| 5987 | { |
| 5988 | __states.pop_back(); |
| 5989 | break; |
| 5990 | } |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5991 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5992 | { |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5993 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5994 | __best_state = __s; |
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 | __matched = true; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5997 | if (__highest_j == _Np) |
Howard Hinnant | ebbc2b6 | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5998 | __states.clear(); |
| 5999 | else |
| 6000 | __states.pop_back(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6001 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6002 | case __state::__accept_and_consume: |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6003 | case __state::__repeat: |
| 6004 | case __state::__accept_but_not_consume: |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6005 | break; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6006 | case __state::__split: |
| 6007 | { |
| 6008 | __state __snext = __s; |
| 6009 | __s.__node_->__exec_split(true, __s); |
| 6010 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6011 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6012 | } |
| 6013 | break; |
| 6014 | case __state::__reject: |
| 6015 | __states.pop_back(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6016 | break; |
| 6017 | default: |
Marshall Clow | c8ccc29 | 2015-07-28 13:30:47 +0000 | [diff] [blame] | 6018 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6019 | break; |
| 6020 | } |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6021 | } while (!__states.empty()); |
| 6022 | if (__matched) |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6023 | { |
| 6024 | __m.__matches_[0].first = __first; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6025 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6026 | __m.__matches_[0].matched = true; |
Howard Hinnant | aa0874c | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 6027 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 6028 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | 5bf9613 | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 6029 | return true; |
| 6030 | } |
| 6031 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6032 | return false; |
| 6033 | } |
| 6034 | |
| 6035 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6036 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6037 | bool |
| 6038 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6039 | const _CharT* __first, const _CharT* __last, |
| 6040 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6041 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6042 | { |
Marshall Clow | 88a3087 | 2019-03-28 17:30:23 +0000 | [diff] [blame] | 6043 | if (__get_grammar(__flags_) == ECMAScript) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6044 | return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6045 | if (mark_count() == 0) |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6046 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |
| 6047 | return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6048 | } |
| 6049 | |
| 6050 | template <class _CharT, class _Traits> |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6051 | template <class _Allocator> |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6052 | bool |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6053 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6054 | const _CharT* __first, const _CharT* __last, |
| 6055 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6056 | regex_constants::match_flag_type __flags) const |
| 6057 | { |
Diogo Sampaio | 300ade7 | 2020-04-30 23:34:01 +0100 | [diff] [blame] | 6058 | if (__flags & regex_constants::match_prev_avail) |
| 6059 | __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow); |
| 6060 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6061 | __m.__init(1 + mark_count(), __first, __last, |
| 6062 | __flags & regex_constants::__no_update_pos); |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6063 | if (__match_at_start(__first, __last, __m, __flags, |
Howard Hinnant | 38d14f7 | 2013-07-09 17:29:09 +0000 | [diff] [blame] | 6064 | !(__flags & regex_constants::__no_update_pos))) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6065 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6066 | __m.__prefix_.second = __m[0].first; |
| 6067 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 6068 | __m.__suffix_.first = __m[0].second; |
| 6069 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 6070 | return true; |
| 6071 | } |
Howard Hinnant | 22cf486 | 2010-07-29 01:15:27 +0000 | [diff] [blame] | 6072 | if (__first != __last && !(__flags & regex_constants::match_continuous)) |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6073 | { |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 6074 | __flags |= regex_constants::match_prev_avail; |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6075 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6076 | { |
Howard Hinnant | 6b2602a | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 6077 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 066ba51 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 6078 | if (__match_at_start(__first, __last, __m, __flags, false)) |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6079 | { |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6080 | __m.__prefix_.second = __m[0].first; |
| 6081 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 6082 | __m.__suffix_.first = __m[0].second; |
| 6083 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 6084 | return true; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6085 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6086 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6087 | } |
| 6088 | } |
Howard Hinnant | 66bcf7e | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 6089 | __m.__matches_.clear(); |
| 6090 | return false; |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6091 | } |
| 6092 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6093 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6094 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6095 | bool |
| 6096 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6097 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6098 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6099 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6100 | { |
Howard Hinnant | 1e5de64 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 6101 | int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0; |
| 6102 | basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6103 | match_results<const _CharT*> __mc; |
Howard Hinnant | 1e5de64 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 6104 | 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] | 6105 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6106 | return __r; |
| 6107 | } |
| 6108 | |
Howard Hinnant | 4018c48 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 6109 | template <class _Iter, class _Allocator, class _CharT, class _Traits> |
| 6110 | inline _LIBCPP_INLINE_VISIBILITY |
| 6111 | bool |
| 6112 | regex_search(__wrap_iter<_Iter> __first, |
| 6113 | __wrap_iter<_Iter> __last, |
| 6114 | match_results<__wrap_iter<_Iter>, _Allocator>& __m, |
| 6115 | const basic_regex<_CharT, _Traits>& __e, |
| 6116 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6117 | { |
| 6118 | match_results<const _CharT*> __mc; |
| 6119 | bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags); |
| 6120 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
| 6121 | return __r; |
| 6122 | } |
| 6123 | |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6124 | template <class _Allocator, class _CharT, class _Traits> |
| 6125 | inline _LIBCPP_INLINE_VISIBILITY |
| 6126 | bool |
| 6127 | regex_search(const _CharT* __first, const _CharT* __last, |
| 6128 | match_results<const _CharT*, _Allocator>& __m, |
| 6129 | const basic_regex<_CharT, _Traits>& __e, |
| 6130 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6131 | { |
Howard Hinnant | f5cb6eb | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 6132 | return __e.__search(__first, __last, __m, __flags); |
| 6133 | } |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6134 | |
| 6135 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6136 | inline _LIBCPP_INLINE_VISIBILITY |
| 6137 | bool |
| 6138 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6139 | const basic_regex<_CharT, _Traits>& __e, |
| 6140 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6141 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6142 | basic_string<_CharT> __s(__first, __last); |
| 6143 | match_results<const _CharT*> __mc; |
| 6144 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 6145 | } |
| 6146 | |
| 6147 | template <class _CharT, class _Traits> |
| 6148 | inline _LIBCPP_INLINE_VISIBILITY |
| 6149 | bool |
| 6150 | regex_search(const _CharT* __first, const _CharT* __last, |
| 6151 | const basic_regex<_CharT, _Traits>& __e, |
| 6152 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6153 | { |
| 6154 | match_results<const _CharT*> __mc; |
| 6155 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6156 | } |
| 6157 | |
| 6158 | template <class _CharT, class _Allocator, class _Traits> |
| 6159 | inline _LIBCPP_INLINE_VISIBILITY |
| 6160 | bool |
| 6161 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6162 | const basic_regex<_CharT, _Traits>& __e, |
| 6163 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6164 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6165 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6166 | } |
| 6167 | |
| 6168 | template <class _CharT, class _Traits> |
| 6169 | inline _LIBCPP_INLINE_VISIBILITY |
| 6170 | bool |
| 6171 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6172 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6173 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6174 | match_results<const _CharT*> __m; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6175 | return _VSTD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6176 | } |
| 6177 | |
| 6178 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6179 | inline _LIBCPP_INLINE_VISIBILITY |
| 6180 | bool |
| 6181 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6182 | const basic_regex<_CharT, _Traits>& __e, |
| 6183 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6184 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6185 | match_results<const _CharT*> __mc; |
| 6186 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6187 | } |
| 6188 | |
| 6189 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6190 | inline _LIBCPP_INLINE_VISIBILITY |
| 6191 | bool |
| 6192 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 6193 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6194 | const basic_regex<_CharT, _Traits>& __e, |
| 6195 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6196 | { |
Howard Hinnant | 6642321 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 6197 | match_results<const _CharT*> __mc; |
| 6198 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6199 | __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] | 6200 | return __r; |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6201 | } |
| 6202 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6203 | #if _LIBCPP_STD_VER > 11 |
| 6204 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
| 6205 | bool |
| 6206 | regex_search(const basic_string<_Cp, _ST, _SA>&& __s, |
| 6207 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 6208 | const basic_regex<_Cp, _Tp>& __e, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6209 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6210 | #endif |
| 6211 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6212 | // regex_match |
| 6213 | |
| 6214 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 6215 | bool |
| 6216 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6217 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 6218 | const basic_regex<_CharT, _Traits>& __e, |
| 6219 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6220 | { |
Tim Shen | 11113f5 | 2016-10-27 21:40:34 +0000 | [diff] [blame] | 6221 | bool __r = _VSTD::regex_search( |
| 6222 | __first, __last, __m, __e, |
| 6223 | __flags | regex_constants::match_continuous | |
| 6224 | regex_constants::__full_match); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6225 | if (__r) |
| 6226 | { |
| 6227 | __r = !__m.suffix().matched; |
| 6228 | if (!__r) |
| 6229 | __m.__matches_.clear(); |
| 6230 | } |
| 6231 | return __r; |
| 6232 | } |
| 6233 | |
| 6234 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6235 | inline _LIBCPP_INLINE_VISIBILITY |
| 6236 | bool |
| 6237 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6238 | const basic_regex<_CharT, _Traits>& __e, |
| 6239 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6240 | { |
| 6241 | match_results<_BidirectionalIterator> __m; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6242 | return _VSTD::regex_match(__first, __last, __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6243 | } |
| 6244 | |
| 6245 | template <class _CharT, class _Allocator, class _Traits> |
| 6246 | inline _LIBCPP_INLINE_VISIBILITY |
| 6247 | bool |
| 6248 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 6249 | const basic_regex<_CharT, _Traits>& __e, |
| 6250 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6251 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6252 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6253 | } |
| 6254 | |
| 6255 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6256 | inline _LIBCPP_INLINE_VISIBILITY |
| 6257 | bool |
| 6258 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6259 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6260 | const basic_regex<_CharT, _Traits>& __e, |
| 6261 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6262 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6263 | return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6264 | } |
| 6265 | |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6266 | #if _LIBCPP_STD_VER > 11 |
| 6267 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 6268 | inline _LIBCPP_INLINE_VISIBILITY |
| 6269 | bool |
| 6270 | regex_match(const basic_string<_CharT, _ST, _SA>&& __s, |
| 6271 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 6272 | const basic_regex<_CharT, _Traits>& __e, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6273 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6274 | #endif |
| 6275 | |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6276 | template <class _CharT, class _Traits> |
| 6277 | inline _LIBCPP_INLINE_VISIBILITY |
| 6278 | bool |
| 6279 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 6280 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6281 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6282 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6283 | } |
| 6284 | |
| 6285 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 6286 | inline _LIBCPP_INLINE_VISIBILITY |
| 6287 | bool |
| 6288 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 6289 | const basic_regex<_CharT, _Traits>& __e, |
| 6290 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6291 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6292 | return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); |
Howard Hinnant | 65a3f3d | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 6293 | } |
| 6294 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6295 | // regex_iterator |
| 6296 | |
| 6297 | template <class _BidirectionalIterator, |
| 6298 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6299 | class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6300 | class _LIBCPP_TEMPLATE_VIS regex_iterator; |
| 6301 | |
| 6302 | typedef regex_iterator<const char*> cregex_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6303 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6304 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6305 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6306 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6307 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6308 | |
| 6309 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6310 | class |
| 6311 | _LIBCPP_TEMPLATE_VIS |
| 6312 | _LIBCPP_PREFERRED_NAME(cregex_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6313 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6314 | _LIBCPP_PREFERRED_NAME(sregex_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6315 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6316 | regex_iterator |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6317 | { |
| 6318 | public: |
| 6319 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6320 | typedef match_results<_BidirectionalIterator> value_type; |
| 6321 | typedef ptrdiff_t difference_type; |
| 6322 | typedef const value_type* pointer; |
| 6323 | typedef const value_type& reference; |
| 6324 | typedef forward_iterator_tag iterator_category; |
| 6325 | |
| 6326 | private: |
| 6327 | _BidirectionalIterator __begin_; |
| 6328 | _BidirectionalIterator __end_; |
| 6329 | const regex_type* __pregex_; |
| 6330 | regex_constants::match_flag_type __flags_; |
| 6331 | value_type __match_; |
| 6332 | |
| 6333 | public: |
| 6334 | regex_iterator(); |
| 6335 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6336 | const regex_type& __re, |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6337 | regex_constants::match_flag_type __m |
| 6338 | = regex_constants::match_default); |
| 6339 | #if _LIBCPP_STD_VER > 11 |
| 6340 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6341 | const regex_type&& __re, |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6342 | regex_constants::match_flag_type __m |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6343 | = regex_constants::match_default) = delete; |
| 6344 | #endif |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6345 | |
| 6346 | bool operator==(const regex_iterator& __x) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6347 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6348 | bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} |
| 6349 | |
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 | reference operator*() const {return __match_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6352 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6353 | pointer operator->() const {return _VSTD::addressof(__match_);} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6354 | |
| 6355 | regex_iterator& operator++(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6356 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6357 | regex_iterator operator++(int) |
| 6358 | { |
| 6359 | regex_iterator __t(*this); |
| 6360 | ++(*this); |
| 6361 | return __t; |
| 6362 | } |
| 6363 | }; |
| 6364 | |
| 6365 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6366 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() |
| 6367 | : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() |
| 6368 | { |
| 6369 | } |
| 6370 | |
| 6371 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6372 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6373 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6374 | const regex_type& __re, regex_constants::match_flag_type __m) |
| 6375 | : __begin_(__a), |
| 6376 | __end_(__b), |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6377 | __pregex_(_VSTD::addressof(__re)), |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6378 | __flags_(__m) |
| 6379 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6380 | _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6381 | } |
| 6382 | |
| 6383 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6384 | bool |
| 6385 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6386 | operator==(const regex_iterator& __x) const |
| 6387 | { |
| 6388 | if (__match_.empty() && __x.__match_.empty()) |
| 6389 | return true; |
| 6390 | if (__match_.empty() || __x.__match_.empty()) |
| 6391 | return false; |
| 6392 | return __begin_ == __x.__begin_ && |
| 6393 | __end_ == __x.__end_ && |
| 6394 | __pregex_ == __x.__pregex_ && |
| 6395 | __flags_ == __x.__flags_ && |
| 6396 | __match_[0] == __x.__match_[0]; |
| 6397 | } |
| 6398 | |
| 6399 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6400 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6401 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6402 | { |
| 6403 | __flags_ |= regex_constants::__no_update_pos; |
| 6404 | _BidirectionalIterator __start = __match_[0].second; |
Marshall Clow | faa964d | 2017-07-05 16:37:19 +0000 | [diff] [blame] | 6405 | if (__match_[0].first == __match_[0].second) |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6406 | { |
| 6407 | if (__start == __end_) |
| 6408 | { |
| 6409 | __match_ = value_type(); |
| 6410 | return *this; |
| 6411 | } |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6412 | else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6413 | __flags_ | regex_constants::match_not_null | |
| 6414 | regex_constants::match_continuous)) |
| 6415 | return *this; |
| 6416 | else |
| 6417 | ++__start; |
| 6418 | } |
| 6419 | __flags_ |= regex_constants::match_prev_avail; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6420 | if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6421 | __match_ = value_type(); |
| 6422 | return *this; |
| 6423 | } |
| 6424 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6425 | // regex_token_iterator |
| 6426 | |
| 6427 | template <class _BidirectionalIterator, |
| 6428 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6429 | class _Traits = regex_traits<_CharT> > |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6430 | class _LIBCPP_TEMPLATE_VIS regex_token_iterator; |
| 6431 | |
| 6432 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6433 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6434 | #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS |
| 6435 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6436 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6437 | #endif |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6438 | |
| 6439 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6440 | class |
| 6441 | _LIBCPP_TEMPLATE_VIS |
| 6442 | _LIBCPP_PREFERRED_NAME(cregex_token_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6443 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6444 | _LIBCPP_PREFERRED_NAME(sregex_token_iterator) |
Louis Dionne | 8925814 | 2021-08-23 15:32:36 -0400 | [diff] [blame] | 6445 | _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator)) |
Richard Smith | 256954d | 2020-11-11 17:12:18 -0800 | [diff] [blame] | 6446 | regex_token_iterator |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6447 | { |
| 6448 | public: |
| 6449 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6450 | typedef sub_match<_BidirectionalIterator> value_type; |
| 6451 | typedef ptrdiff_t difference_type; |
| 6452 | typedef const value_type* pointer; |
| 6453 | typedef const value_type& reference; |
| 6454 | typedef forward_iterator_tag iterator_category; |
| 6455 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6456 | private: |
| 6457 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; |
| 6458 | |
| 6459 | _Position __position_; |
| 6460 | const value_type* __result_; |
| 6461 | value_type __suffix_; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6462 | ptrdiff_t __n_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6463 | vector<int> __subs_; |
| 6464 | |
| 6465 | public: |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6466 | regex_token_iterator(); |
| 6467 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6468 | const regex_type& __re, int __submatch = 0, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6469 | regex_constants::match_flag_type __m = |
| 6470 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6471 | #if _LIBCPP_STD_VER > 11 |
| 6472 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6473 | const regex_type&& __re, int __submatch = 0, |
| 6474 | regex_constants::match_flag_type __m = |
| 6475 | regex_constants::match_default) = delete; |
| 6476 | #endif |
| 6477 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6478 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6479 | const regex_type& __re, const vector<int>& __submatches, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6480 | regex_constants::match_flag_type __m = |
| 6481 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6482 | #if _LIBCPP_STD_VER > 11 |
| 6483 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6484 | const regex_type&& __re, const vector<int>& __submatches, |
| 6485 | regex_constants::match_flag_type __m = |
| 6486 | regex_constants::match_default) = delete; |
| 6487 | #endif |
| 6488 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 6489 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6490 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6491 | const regex_type& __re, |
| 6492 | initializer_list<int> __submatches, |
| 6493 | regex_constants::match_flag_type __m = |
| 6494 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6495 | |
| 6496 | #if _LIBCPP_STD_VER > 11 |
| 6497 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6498 | const regex_type&& __re, |
| 6499 | initializer_list<int> __submatches, |
| 6500 | regex_constants::match_flag_type __m = |
| 6501 | regex_constants::match_default) = delete; |
| 6502 | #endif |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6503 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6504 | template <size_t _Np> |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6505 | regex_token_iterator(_BidirectionalIterator __a, |
| 6506 | _BidirectionalIterator __b, |
| 6507 | const regex_type& __re, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6508 | const int (&__submatches)[_Np], |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6509 | regex_constants::match_flag_type __m = |
| 6510 | regex_constants::match_default); |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6511 | #if _LIBCPP_STD_VER > 11 |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 6512 | template <size_t _Np> |
Marshall Clow | 8c95007 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6513 | regex_token_iterator(_BidirectionalIterator __a, |
| 6514 | _BidirectionalIterator __b, |
| 6515 | const regex_type&& __re, |
| 6516 | const int (&__submatches)[_Np], |
| 6517 | regex_constants::match_flag_type __m = |
| 6518 | regex_constants::match_default) = delete; |
| 6519 | #endif |
| 6520 | |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6521 | regex_token_iterator(const regex_token_iterator&); |
| 6522 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 6523 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6524 | bool operator==(const regex_token_iterator& __x) const; |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6525 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6526 | bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6527 | |
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 | const value_type& operator*() const {return *__result_;} |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6530 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6531 | const value_type* operator->() const {return __result_;} |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6532 | |
| 6533 | regex_token_iterator& operator++(); |
Howard Hinnant | 7ca9d94 | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6534 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6535 | regex_token_iterator operator++(int) |
| 6536 | { |
| 6537 | regex_token_iterator __t(*this); |
| 6538 | ++(*this); |
| 6539 | return __t; |
| 6540 | } |
| 6541 | |
| 6542 | private: |
| 6543 | void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6544 | void __establish_result () { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6545 | if (__subs_[__n_] == -1) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6546 | __result_ = &__position_->prefix(); |
| 6547 | else |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6548 | __result_ = &(*__position_)[__subs_[__n_]]; |
Louis Dionne | 173f29e | 2019-05-29 16:01:36 +0000 | [diff] [blame] | 6549 | } |
Howard Hinnant | d392534 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6550 | }; |
| 6551 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6552 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6553 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6554 | regex_token_iterator() |
| 6555 | : __result_(nullptr), |
| 6556 | __suffix_(), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6557 | __n_(0) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6558 | { |
| 6559 | } |
| 6560 | |
| 6561 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6562 | void |
| 6563 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6564 | __init(_BidirectionalIterator __a, _BidirectionalIterator __b) |
| 6565 | { |
| 6566 | if (__position_ != _Position()) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6567 | __establish_result (); |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6568 | else if (__subs_[__n_] == -1) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6569 | { |
| 6570 | __suffix_.matched = true; |
| 6571 | __suffix_.first = __a; |
| 6572 | __suffix_.second = __b; |
| 6573 | __result_ = &__suffix_; |
| 6574 | } |
| 6575 | else |
| 6576 | __result_ = nullptr; |
| 6577 | } |
| 6578 | |
| 6579 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6580 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6581 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6582 | const regex_type& __re, int __submatch, |
| 6583 | regex_constants::match_flag_type __m) |
| 6584 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6585 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6586 | __subs_(1, __submatch) |
| 6587 | { |
| 6588 | __init(__a, __b); |
| 6589 | } |
| 6590 | |
| 6591 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6592 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6593 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6594 | const regex_type& __re, const vector<int>& __submatches, |
| 6595 | regex_constants::match_flag_type __m) |
| 6596 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6597 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6598 | __subs_(__submatches) |
| 6599 | { |
| 6600 | __init(__a, __b); |
| 6601 | } |
| 6602 | |
Eric Fiselier | 6f8516f | 2017-04-18 23:42:15 +0000 | [diff] [blame] | 6603 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6604 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6605 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6606 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6607 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6608 | const regex_type& __re, |
| 6609 | initializer_list<int> __submatches, |
| 6610 | regex_constants::match_flag_type __m) |
| 6611 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6612 | __n_(0), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6613 | __subs_(__submatches) |
| 6614 | { |
| 6615 | __init(__a, __b); |
| 6616 | } |
| 6617 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6618 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | 3371179 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6619 | |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6620 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6621 | template <size_t _Np> |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6622 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6623 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6624 | const regex_type& __re, |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6625 | const int (&__submatches)[_Np], |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6626 | regex_constants::match_flag_type __m) |
| 6627 | : __position_(__a, __b, __re, __m), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6628 | __n_(0), |
Marshall Clow | f01062c | 2019-01-24 02:02:50 +0000 | [diff] [blame] | 6629 | __subs_(begin(__submatches), end(__submatches)) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6630 | { |
| 6631 | __init(__a, __b); |
| 6632 | } |
| 6633 | |
| 6634 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6635 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6636 | regex_token_iterator(const regex_token_iterator& __x) |
| 6637 | : __position_(__x.__position_), |
| 6638 | __result_(__x.__result_), |
| 6639 | __suffix_(__x.__suffix_), |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6640 | __n_(__x.__n_), |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6641 | __subs_(__x.__subs_) |
| 6642 | { |
| 6643 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 20756ac | 2014-01-13 17:47:08 +0000 | [diff] [blame] | 6644 | __result_ = &__suffix_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6645 | else if ( __result_ != nullptr ) |
| 6646 | __establish_result (); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6647 | } |
| 6648 | |
| 6649 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6650 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6651 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6652 | operator=(const regex_token_iterator& __x) |
| 6653 | { |
| 6654 | if (this != &__x) |
| 6655 | { |
| 6656 | __position_ = __x.__position_; |
| 6657 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6658 | __result_ = &__suffix_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6659 | else |
| 6660 | __result_ = __x.__result_; |
| 6661 | __suffix_ = __x.__suffix_; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6662 | __n_ = __x.__n_; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6663 | __subs_ = __x.__subs_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6664 | |
| 6665 | if ( __result_ != nullptr && __result_ != &__suffix_ ) |
| 6666 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6667 | } |
| 6668 | return *this; |
| 6669 | } |
| 6670 | |
| 6671 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6672 | bool |
| 6673 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6674 | operator==(const regex_token_iterator& __x) const |
| 6675 | { |
| 6676 | if (__result_ == nullptr && __x.__result_ == nullptr) |
| 6677 | return true; |
| 6678 | if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && |
| 6679 | __suffix_ == __x.__suffix_) |
| 6680 | return true; |
| 6681 | if (__result_ == nullptr || __x.__result_ == nullptr) |
| 6682 | return false; |
| 6683 | if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) |
| 6684 | return false; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6685 | return __position_ == __x.__position_ && __n_ == __x.__n_ && |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6686 | __subs_ == __x.__subs_; |
| 6687 | } |
| 6688 | |
| 6689 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6690 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6691 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6692 | { |
| 6693 | _Position __prev = __position_; |
| 6694 | if (__result_ == &__suffix_) |
| 6695 | __result_ = nullptr; |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6696 | else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6697 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6698 | ++__n_; |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6699 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6700 | } |
| 6701 | else |
| 6702 | { |
Eric Fiselier | 37c2215 | 2016-12-24 00:24:44 +0000 | [diff] [blame] | 6703 | __n_ = 0; |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6704 | ++__position_; |
| 6705 | if (__position_ != _Position()) |
Marshall Clow | 6808302 | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6706 | __establish_result(); |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6707 | else |
| 6708 | { |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6709 | if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() |
Howard Hinnant | 63c9ce6 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6710 | && __prev->suffix().length() != 0) |
| 6711 | { |
| 6712 | __suffix_.matched = true; |
| 6713 | __suffix_.first = __prev->suffix().first; |
| 6714 | __suffix_.second = __prev->suffix().second; |
| 6715 | __result_ = &__suffix_; |
| 6716 | } |
| 6717 | else |
| 6718 | __result_ = nullptr; |
| 6719 | } |
| 6720 | } |
| 6721 | return *this; |
| 6722 | } |
| 6723 | |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6724 | // regex_replace |
| 6725 | |
| 6726 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6727 | class _Traits, class _CharT> |
| 6728 | _OutputIterator |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6729 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6730 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6731 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6732 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6733 | { |
| 6734 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; |
| 6735 | _Iter __i(__first, __last, __e, __flags); |
| 6736 | _Iter __eof; |
| 6737 | if (__i == __eof) |
| 6738 | { |
| 6739 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6740 | __output_iter = _VSTD::copy(__first, __last, __output_iter); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6741 | } |
| 6742 | else |
| 6743 | { |
| 6744 | sub_match<_BidirectionalIterator> __lm; |
| 6745 | for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) |
| 6746 | { |
| 6747 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6748 | __output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter); |
| 6749 | __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6750 | __lm = __i->suffix(); |
| 6751 | if (__flags & regex_constants::format_first_only) |
| 6752 | break; |
| 6753 | } |
| 6754 | if (!(__flags & regex_constants::format_no_copy)) |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6755 | __output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter); |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6756 | } |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6757 | return __output_iter; |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6758 | } |
| 6759 | |
| 6760 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6761 | class _Traits, class _CharT, class _ST, class _SA> |
| 6762 | inline _LIBCPP_INLINE_VISIBILITY |
| 6763 | _OutputIterator |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6764 | regex_replace(_OutputIterator __output_iter, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6765 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6766 | const basic_regex<_CharT, _Traits>& __e, |
| 6767 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6768 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6769 | { |
Alexander Richardson | c963764 | 2017-11-14 11:14:25 +0000 | [diff] [blame] | 6770 | 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] | 6771 | } |
| 6772 | |
| 6773 | template <class _Traits, class _CharT, class _ST, class _SA, class _FST, |
| 6774 | class _FSA> |
| 6775 | inline _LIBCPP_INLINE_VISIBILITY |
| 6776 | basic_string<_CharT, _ST, _SA> |
| 6777 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6778 | const basic_regex<_CharT, _Traits>& __e, |
| 6779 | const basic_string<_CharT, _FST, _FSA>& __fmt, |
| 6780 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6781 | { |
| 6782 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6783 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6784 | __fmt.c_str(), __flags); |
| 6785 | return __r; |
| 6786 | } |
| 6787 | |
| 6788 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6789 | inline _LIBCPP_INLINE_VISIBILITY |
| 6790 | basic_string<_CharT, _ST, _SA> |
| 6791 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6792 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6793 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6794 | { |
| 6795 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6796 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6797 | __fmt, __flags); |
| 6798 | return __r; |
| 6799 | } |
| 6800 | |
| 6801 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6802 | inline _LIBCPP_INLINE_VISIBILITY |
| 6803 | basic_string<_CharT> |
| 6804 | regex_replace(const _CharT* __s, |
| 6805 | const basic_regex<_CharT, _Traits>& __e, |
| 6806 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6807 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6808 | { |
| 6809 | basic_string<_CharT> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6810 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6811 | __s + char_traits<_CharT>::length(__s), __e, |
| 6812 | __fmt.c_str(), __flags); |
| 6813 | return __r; |
| 6814 | } |
| 6815 | |
| 6816 | template <class _Traits, class _CharT> |
| 6817 | inline _LIBCPP_INLINE_VISIBILITY |
| 6818 | basic_string<_CharT> |
| 6819 | regex_replace(const _CharT* __s, |
| 6820 | const basic_regex<_CharT, _Traits>& __e, |
| 6821 | const _CharT* __fmt, |
| 6822 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6823 | { |
| 6824 | basic_string<_CharT> __r; |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6825 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | e90434c | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6826 | __s + char_traits<_CharT>::length(__s), __e, |
| 6827 | __fmt, __flags); |
| 6828 | return __r; |
| 6829 | } |
| 6830 | |
Howard Hinnant | a3af5a3 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 6831 | _LIBCPP_END_NAMESPACE_STD |
| 6832 | |
Eric Fiselier | f4433a3 | 2017-05-31 22:07:49 +0000 | [diff] [blame] | 6833 | _LIBCPP_POP_MACROS |
| 6834 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 6835 | #endif // _LIBCPP_REGEX |