Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===--------------------------- regex ------------------------------------===// |
| 3 | // |
| 4 | // The LLVM Compiler Infrastructure |
| 5 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_REGEX |
| 12 | #define _LIBCPP_REGEX |
| 13 | |
| 14 | /* |
| 15 | regex synopsis |
| 16 | |
| 17 | #include <initializer_list> |
| 18 | |
| 19 | namespace std |
| 20 | { |
| 21 | |
| 22 | namespace regex_constants |
| 23 | { |
| 24 | |
| 25 | emum syntax_option_type |
| 26 | { |
| 27 | icase = unspecified, |
| 28 | nosubs = unspecified, |
| 29 | optimize = unspecified, |
| 30 | collate = unspecified, |
| 31 | ECMAScript = unspecified, |
| 32 | basic = unspecified, |
| 33 | extended = unspecified, |
| 34 | awk = unspecified, |
| 35 | grep = unspecified, |
| 36 | egrep = unspecified |
| 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; |
| 130 | typedef regex_constants::syntax_option_type flag_type; |
| 131 | typedef typename traits::locale_type locale_type; |
| 132 | |
| 133 | // constants: |
| 134 | static constexpr regex_constants::syntax_option_type icase = regex_constants::icase; |
| 135 | static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 136 | static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 137 | static constexpr regex_constants::syntax_option_type collate = regex_constants::collate; |
| 138 | static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 139 | static constexpr regex_constants::syntax_option_type basic = regex_constants::basic; |
| 140 | static constexpr regex_constants::syntax_option_type extended = regex_constants::extended; |
| 141 | static constexpr regex_constants::syntax_option_type awk = regex_constants::awk; |
| 142 | static constexpr regex_constants::syntax_option_type grep = regex_constants::grep; |
| 143 | static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep; |
| 144 | |
| 145 | // construct/copy/destroy: |
| 146 | basic_regex(); |
| 147 | explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript); |
| 148 | basic_regex(const charT* p, size_t len, flag_type f); |
| 149 | basic_regex(const basic_regex&); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 150 | basic_regex(basic_regex&&) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 151 | template <class ST, class SA> |
| 152 | explicit basic_regex(const basic_string<charT, ST, SA>& p, |
| 153 | flag_type f = regex_constants::ECMAScript); |
| 154 | template <class ForwardIterator> |
| 155 | basic_regex(ForwardIterator first, ForwardIterator last, |
| 156 | flag_type f = regex_constants::ECMAScript); |
| 157 | basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript); |
| 158 | |
| 159 | ~basic_regex(); |
| 160 | |
| 161 | basic_regex& operator=(const basic_regex&); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 162 | basic_regex& operator=(basic_regex&&) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 163 | basic_regex& operator=(const charT* ptr); |
| 164 | basic_regex& operator=(initializer_list<charT> il); |
| 165 | template <class ST, class SA> |
| 166 | basic_regex& operator=(const basic_string<charT, ST, SA>& p); |
| 167 | |
| 168 | // assign: |
| 169 | basic_regex& assign(const basic_regex& that); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 170 | basic_regex& assign(basic_regex&& that) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 171 | basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript); |
| 172 | basic_regex& assign(const charT* p, size_t len, flag_type f); |
| 173 | template <class string_traits, class A> |
| 174 | basic_regex& assign(const basic_string<charT, string_traits, A>& s, |
| 175 | flag_type f = regex_constants::ECMAScript); |
| 176 | template <class InputIterator> |
| 177 | basic_regex& assign(InputIterator first, InputIterator last, |
| 178 | flag_type f = regex_constants::ECMAScript); |
| 179 | basic_regex& assign(initializer_list<charT>, flag_type = regex_constants::ECMAScript); |
| 180 | |
| 181 | // const operations: |
| 182 | unsigned mark_count() const; |
| 183 | flag_type flags() const; |
| 184 | |
| 185 | // locale: |
| 186 | locale_type imbue(locale_type loc); |
| 187 | locale_type getloc() const; |
| 188 | |
| 189 | // swap: |
| 190 | void swap(basic_regex&); |
| 191 | }; |
| 192 | |
| 193 | typedef basic_regex<char> regex; |
| 194 | typedef basic_regex<wchar_t> wregex; |
| 195 | |
| 196 | template <class charT, class traits> |
| 197 | void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2); |
| 198 | |
| 199 | template <class BidirectionalIterator> |
| 200 | class sub_match |
| 201 | : public pair<BidirectionalIterator, BidirectionalIterator> |
| 202 | { |
| 203 | public: |
| 204 | typedef typename iterator_traits<BidirectionalIterator>::value_type value_type; |
| 205 | typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; |
| 206 | typedef BidirectionalIterator iterator; |
| 207 | typedef basic_string<value_type> string_type; |
| 208 | |
| 209 | bool matched; |
| 210 | |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 211 | constexpr sub_match(); |
| 212 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 213 | difference_type length() const; |
| 214 | operator string_type() const; |
| 215 | string_type str() const; |
| 216 | |
| 217 | int compare(const sub_match& s) const; |
| 218 | int compare(const string_type& s) const; |
| 219 | int compare(const value_type* s) const; |
| 220 | }; |
| 221 | |
| 222 | typedef sub_match<const char*> csub_match; |
| 223 | typedef sub_match<const wchar_t*> wcsub_match; |
| 224 | typedef sub_match<string::const_iterator> ssub_match; |
| 225 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 226 | |
| 227 | template <class BiIter> |
| 228 | bool |
| 229 | operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 230 | |
| 231 | template <class BiIter> |
| 232 | bool |
| 233 | operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); |
| 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, class ST, class SA> |
| 252 | bool |
| 253 | operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 254 | const sub_match<BiIter>& rhs); |
| 255 | |
| 256 | template <class BiIter, class ST, class SA> |
| 257 | bool |
| 258 | operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 259 | const sub_match<BiIter>& rhs); |
| 260 | |
| 261 | template <class BiIter, class ST, class SA> |
| 262 | bool |
| 263 | operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 264 | const sub_match<BiIter>& rhs); |
| 265 | |
| 266 | template <class BiIter, class ST, class SA> |
| 267 | bool |
| 268 | operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 269 | const sub_match<BiIter>& rhs); |
| 270 | |
| 271 | template <class BiIter, class ST, class SA> |
| 272 | bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 273 | const sub_match<BiIter>& rhs); |
| 274 | |
| 275 | template <class BiIter, class ST, class SA> |
| 276 | bool |
| 277 | operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs, |
| 278 | const sub_match<BiIter>& rhs); |
| 279 | |
| 280 | template <class BiIter, class ST, class SA> |
| 281 | bool |
| 282 | operator==(const sub_match<BiIter>& lhs, |
| 283 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 284 | |
| 285 | template <class BiIter, class ST, class SA> |
| 286 | bool |
| 287 | operator!=(const sub_match<BiIter>& lhs, |
| 288 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 289 | |
| 290 | template <class BiIter, class ST, class SA> |
| 291 | bool |
| 292 | operator<(const sub_match<BiIter>& lhs, |
| 293 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 294 | |
| 295 | template <class BiIter, class ST, class SA> |
| 296 | bool operator>(const sub_match<BiIter>& lhs, |
| 297 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 298 | |
| 299 | template <class BiIter, class ST, class SA> |
| 300 | bool |
| 301 | operator>=(const sub_match<BiIter>& lhs, |
| 302 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 303 | |
| 304 | template <class BiIter, class ST, class SA> |
| 305 | bool |
| 306 | operator<=(const sub_match<BiIter>& lhs, |
| 307 | const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs); |
| 308 | |
| 309 | template <class BiIter> |
| 310 | bool |
| 311 | operator==(typename iterator_traits<BiIter>::value_type const* lhs, |
| 312 | const sub_match<BiIter>& rhs); |
| 313 | |
| 314 | template <class BiIter> |
| 315 | bool |
| 316 | operator!=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 317 | const sub_match<BiIter>& rhs); |
| 318 | |
| 319 | template <class BiIter> |
| 320 | bool |
| 321 | operator<(typename iterator_traits<BiIter>::value_type const* lhs, |
| 322 | const sub_match<BiIter>& rhs); |
| 323 | |
| 324 | template <class BiIter> |
| 325 | bool |
| 326 | operator>(typename iterator_traits<BiIter>::value_type const* lhs, |
| 327 | const sub_match<BiIter>& rhs); |
| 328 | |
| 329 | template <class BiIter> |
| 330 | bool |
| 331 | operator>=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 332 | const sub_match<BiIter>& rhs); |
| 333 | |
| 334 | template <class BiIter> |
| 335 | bool |
| 336 | operator<=(typename iterator_traits<BiIter>::value_type const* lhs, |
| 337 | const sub_match<BiIter>& rhs); |
| 338 | |
| 339 | template <class BiIter> |
| 340 | bool |
| 341 | operator==(const sub_match<BiIter>& lhs, |
| 342 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 343 | |
| 344 | template <class BiIter> |
| 345 | bool |
| 346 | operator!=(const sub_match<BiIter>& lhs, |
| 347 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 348 | |
| 349 | template <class BiIter> |
| 350 | bool |
| 351 | operator<(const sub_match<BiIter>& lhs, |
| 352 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 353 | |
| 354 | template <class BiIter> |
| 355 | bool |
| 356 | operator>(const sub_match<BiIter>& lhs, |
| 357 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 358 | |
| 359 | template <class BiIter> |
| 360 | bool |
| 361 | operator>=(const sub_match<BiIter>& lhs, |
| 362 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 363 | |
| 364 | template <class BiIter> |
| 365 | bool |
| 366 | operator<=(const sub_match<BiIter>& lhs, |
| 367 | typename iterator_traits<BiIter>::value_type const* rhs); |
| 368 | |
| 369 | template <class BiIter> |
| 370 | bool |
| 371 | operator==(typename iterator_traits<BiIter>::value_type const& lhs, |
| 372 | const sub_match<BiIter>& rhs); |
| 373 | |
| 374 | template <class BiIter> |
| 375 | bool |
| 376 | operator!=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 377 | const sub_match<BiIter>& rhs); |
| 378 | |
| 379 | template <class BiIter> |
| 380 | bool |
| 381 | operator<(typename iterator_traits<BiIter>::value_type const& lhs, |
| 382 | const sub_match<BiIter>& rhs); |
| 383 | |
| 384 | template <class BiIter> |
| 385 | bool |
| 386 | operator>(typename iterator_traits<BiIter>::value_type const& lhs, |
| 387 | const sub_match<BiIter>& rhs); |
| 388 | |
| 389 | template <class BiIter> |
| 390 | bool |
| 391 | operator>=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 392 | const sub_match<BiIter>& rhs); |
| 393 | |
| 394 | template <class BiIter> |
| 395 | bool |
| 396 | operator<=(typename iterator_traits<BiIter>::value_type const& lhs, |
| 397 | const sub_match<BiIter>& rhs); |
| 398 | |
| 399 | template <class BiIter> |
| 400 | bool |
| 401 | operator==(const sub_match<BiIter>& lhs, |
| 402 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 403 | |
| 404 | template <class BiIter> |
| 405 | bool |
| 406 | operator!=(const sub_match<BiIter>& lhs, |
| 407 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 408 | |
| 409 | template <class BiIter> |
| 410 | bool |
| 411 | operator<(const sub_match<BiIter>& lhs, |
| 412 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 413 | |
| 414 | template <class BiIter> |
| 415 | bool |
| 416 | operator>(const sub_match<BiIter>& lhs, |
| 417 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 418 | |
| 419 | template <class BiIter> |
| 420 | bool |
| 421 | operator>=(const sub_match<BiIter>& lhs, |
| 422 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 423 | |
| 424 | template <class BiIter> |
| 425 | bool |
| 426 | operator<=(const sub_match<BiIter>& lhs, |
| 427 | typename iterator_traits<BiIter>::value_type const& rhs); |
| 428 | |
| 429 | template <class charT, class ST, class BiIter> |
| 430 | basic_ostream<charT, ST>& |
| 431 | operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m); |
| 432 | |
| 433 | template <class BidirectionalIterator, |
| 434 | class Allocator = allocator<sub_match<BidirectionalIterator>>> |
| 435 | class match_results |
| 436 | { |
| 437 | public: |
| 438 | typedef sub_match<BidirectionalIterator> value_type; |
| 439 | typedef const value_type& const_reference; |
Marshall Clow | 103af34 | 2014-02-26 01:56:31 +0000 | [diff] [blame] | 440 | typedef value_type& reference; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 441 | typedef /implementation-defined/ const_iterator; |
| 442 | typedef const_iterator iterator; |
| 443 | typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type; |
| 444 | typedef typename allocator_traits<Allocator>::size_type size_type; |
| 445 | typedef Allocator allocator_type; |
| 446 | typedef typename iterator_traits<BidirectionalIterator>::value_type char_type; |
| 447 | typedef basic_string<char_type> string_type; |
| 448 | |
| 449 | // construct/copy/destroy: |
| 450 | explicit match_results(const Allocator& a = Allocator()); |
| 451 | match_results(const match_results& m); |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 452 | match_results(match_results&& m) noexcept; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 453 | match_results& operator=(const match_results& m); |
| 454 | match_results& operator=(match_results&& m); |
| 455 | ~match_results(); |
| 456 | |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 457 | bool ready() const; |
| 458 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 459 | // size: |
| 460 | size_type size() const; |
| 461 | size_type max_size() const; |
| 462 | bool empty() const; |
| 463 | |
| 464 | // element access: |
| 465 | difference_type length(size_type sub = 0) const; |
| 466 | difference_type position(size_type sub = 0) const; |
| 467 | string_type str(size_type sub = 0) const; |
| 468 | const_reference operator[](size_type n) const; |
| 469 | |
| 470 | const_reference prefix() const; |
| 471 | const_reference suffix() const; |
| 472 | |
| 473 | const_iterator begin() const; |
| 474 | const_iterator end() const; |
| 475 | const_iterator cbegin() const; |
| 476 | const_iterator cend() const; |
| 477 | |
| 478 | // format: |
| 479 | template <class OutputIter> |
| 480 | OutputIter |
| 481 | format(OutputIter out, const char_type* fmt_first, |
| 482 | const char_type* fmt_last, |
| 483 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 484 | template <class OutputIter, class ST, class SA> |
| 485 | OutputIter |
| 486 | format(OutputIter out, const basic_string<char_type, ST, SA>& fmt, |
| 487 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 488 | template <class ST, class SA> |
| 489 | basic_string<char_type, ST, SA> |
| 490 | format(const basic_string<char_type, ST, SA>& fmt, |
| 491 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 492 | string_type |
| 493 | format(const char_type* fmt, |
| 494 | regex_constants::match_flag_type flags = regex_constants::format_default) const; |
| 495 | |
| 496 | // allocator: |
| 497 | allocator_type get_allocator() const; |
| 498 | |
| 499 | // swap: |
| 500 | void swap(match_results& that); |
| 501 | }; |
| 502 | |
| 503 | typedef match_results<const char*> cmatch; |
| 504 | typedef match_results<const wchar_t*> wcmatch; |
| 505 | typedef match_results<string::const_iterator> smatch; |
| 506 | typedef match_results<wstring::const_iterator> wsmatch; |
| 507 | |
| 508 | template <class BidirectionalIterator, class Allocator> |
| 509 | bool |
| 510 | operator==(const match_results<BidirectionalIterator, Allocator>& m1, |
| 511 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 512 | |
| 513 | template <class BidirectionalIterator, class Allocator> |
| 514 | bool |
| 515 | operator!=(const match_results<BidirectionalIterator, Allocator>& m1, |
| 516 | const match_results<BidirectionalIterator, Allocator>& m2); |
| 517 | |
| 518 | template <class BidirectionalIterator, class Allocator> |
| 519 | void |
| 520 | swap(match_results<BidirectionalIterator, Allocator>& m1, |
| 521 | match_results<BidirectionalIterator, Allocator>& m2); |
| 522 | |
| 523 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 524 | bool |
| 525 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 526 | match_results<BidirectionalIterator, Allocator>& m, |
| 527 | const basic_regex<charT, traits>& e, |
| 528 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 529 | |
| 530 | template <class BidirectionalIterator, class charT, class traits> |
| 531 | bool |
| 532 | regex_match(BidirectionalIterator first, BidirectionalIterator last, |
| 533 | const basic_regex<charT, traits>& e, |
| 534 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 535 | |
| 536 | template <class charT, class Allocator, class traits> |
| 537 | bool |
| 538 | regex_match(const charT* str, match_results<const charT*, Allocator>& m, |
| 539 | const basic_regex<charT, traits>& e, |
| 540 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 541 | |
| 542 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 543 | bool |
| 544 | regex_match(const basic_string<charT, ST, SA>& s, |
| 545 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 546 | const basic_regex<charT, traits>& e, |
| 547 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 548 | |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 549 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 550 | bool |
| 551 | regex_match(const basic_string<charT, ST, SA>&& s, |
| 552 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 553 | const basic_regex<charT, traits>& e, |
| 554 | regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 |
| 555 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 556 | template <class charT, class traits> |
| 557 | bool |
| 558 | regex_match(const charT* str, const basic_regex<charT, traits>& e, |
| 559 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 560 | |
| 561 | template <class ST, class SA, class charT, class traits> |
| 562 | bool |
| 563 | regex_match(const basic_string<charT, ST, SA>& s, |
| 564 | const basic_regex<charT, traits>& e, |
| 565 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 566 | |
| 567 | template <class BidirectionalIterator, class Allocator, class charT, class traits> |
| 568 | bool |
| 569 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 570 | match_results<BidirectionalIterator, Allocator>& m, |
| 571 | const basic_regex<charT, traits>& e, |
| 572 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 573 | |
| 574 | template <class BidirectionalIterator, class charT, class traits> |
| 575 | bool |
| 576 | regex_search(BidirectionalIterator first, BidirectionalIterator last, |
| 577 | const basic_regex<charT, traits>& e, |
| 578 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 579 | |
| 580 | template <class charT, class Allocator, class traits> |
| 581 | bool |
| 582 | regex_search(const charT* str, match_results<const charT*, Allocator>& m, |
| 583 | const basic_regex<charT, traits>& e, |
| 584 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 585 | |
| 586 | template <class charT, class traits> |
| 587 | bool |
| 588 | regex_search(const charT* str, const basic_regex<charT, traits>& e, |
| 589 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 590 | |
| 591 | template <class ST, class SA, class charT, class traits> |
| 592 | bool |
| 593 | regex_search(const basic_string<charT, ST, SA>& s, |
| 594 | const basic_regex<charT, traits>& e, |
| 595 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 596 | |
| 597 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 598 | bool |
| 599 | regex_search(const basic_string<charT, ST, SA>& s, |
| 600 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 601 | const basic_regex<charT, traits>& e, |
| 602 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 603 | |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 604 | template <class ST, class SA, class Allocator, class charT, class traits> |
| 605 | bool |
| 606 | regex_search(const basic_string<charT, ST, SA>&& s, |
| 607 | match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m, |
| 608 | const basic_regex<charT, traits>& e, |
| 609 | regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14 |
| 610 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 611 | template <class OutputIterator, class BidirectionalIterator, |
| 612 | class traits, class charT, class ST, class SA> |
| 613 | OutputIterator |
| 614 | regex_replace(OutputIterator out, |
| 615 | BidirectionalIterator first, BidirectionalIterator last, |
| 616 | const basic_regex<charT, traits>& e, |
| 617 | const basic_string<charT, ST, SA>& fmt, |
| 618 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 619 | |
| 620 | template <class OutputIterator, class BidirectionalIterator, |
| 621 | class traits, class charT> |
| 622 | OutputIterator |
| 623 | regex_replace(OutputIterator out, |
| 624 | BidirectionalIterator first, BidirectionalIterator last, |
| 625 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 626 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 627 | |
| 628 | template <class traits, class charT, class ST, class SA, class FST, class FSA>> |
| 629 | basic_string<charT, ST, SA> |
| 630 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 631 | const basic_regex<charT, traits>& e, |
| 632 | const basic_string<charT, FST, FSA>& fmt, |
| 633 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 634 | |
| 635 | template <class traits, class charT, class ST, class SA> |
| 636 | basic_string<charT, ST, SA> |
| 637 | regex_replace(const basic_string<charT, ST, SA>& s, |
| 638 | const basic_regex<charT, traits>& e, const charT* fmt, |
| 639 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 640 | |
| 641 | template <class traits, class charT, class ST, class SA> |
| 642 | basic_string<charT> |
| 643 | regex_replace(const charT* s, |
| 644 | const basic_regex<charT, traits>& e, |
| 645 | const basic_string<charT, ST, SA>& fmt, |
| 646 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 647 | |
| 648 | template <class traits, class charT> |
| 649 | basic_string<charT> |
| 650 | regex_replace(const charT* s, |
| 651 | const basic_regex<charT, traits>& e, |
| 652 | const charT* fmt, |
| 653 | regex_constants::match_flag_type flags = regex_constants::match_default); |
| 654 | |
| 655 | template <class BidirectionalIterator, |
| 656 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 657 | class traits = regex_traits<charT>> |
| 658 | class regex_iterator |
| 659 | { |
| 660 | public: |
| 661 | typedef basic_regex<charT, traits> regex_type; |
| 662 | typedef match_results<BidirectionalIterator> value_type; |
| 663 | typedef ptrdiff_t difference_type; |
| 664 | typedef const value_type* pointer; |
| 665 | typedef const value_type& reference; |
| 666 | typedef forward_iterator_tag iterator_category; |
| 667 | |
| 668 | regex_iterator(); |
| 669 | regex_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 670 | const regex_type& re, |
| 671 | regex_constants::match_flag_type m = regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 672 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 673 | const regex_type&& __re, |
| 674 | regex_constants::match_flag_type __m |
| 675 | = regex_constants::match_default) = delete; // C++14 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 676 | regex_iterator(const regex_iterator&); |
| 677 | regex_iterator& operator=(const regex_iterator&); |
| 678 | |
| 679 | bool operator==(const regex_iterator&) const; |
| 680 | bool operator!=(const regex_iterator&) const; |
| 681 | |
| 682 | const value_type& operator*() const; |
| 683 | const value_type* operator->() const; |
| 684 | |
| 685 | regex_iterator& operator++(); |
| 686 | regex_iterator operator++(int); |
| 687 | }; |
| 688 | |
| 689 | typedef regex_iterator<const char*> cregex_iterator; |
| 690 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 691 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 692 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 693 | |
| 694 | template <class BidirectionalIterator, |
| 695 | class charT = typename iterator_traits< BidirectionalIterator>::value_type, |
| 696 | class traits = regex_traits<charT>> |
| 697 | class regex_token_iterator |
| 698 | { |
| 699 | public: |
| 700 | typedef basic_regex<charT, traits> regex_type; |
| 701 | typedef sub_match<BidirectionalIterator> value_type; |
| 702 | typedef ptrdiff_t difference_type; |
| 703 | typedef const value_type* pointer; |
| 704 | typedef const value_type& reference; |
| 705 | typedef forward_iterator_tag iterator_category; |
| 706 | |
| 707 | regex_token_iterator(); |
| 708 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 709 | const regex_type& re, int submatch = 0, |
| 710 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 711 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 712 | const regex_type&& re, int submatch = 0, |
| 713 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
| 714 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 715 | const regex_type& re, const vector<int>& submatches, |
| 716 | regex_constants::match_flag_type m = regex_constants::match_default); |
| 717 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 718 | const regex_type&& re, const vector<int>& submatches, |
| 719 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
| 720 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 721 | const regex_type& re, initializer_list<int> submatches, |
| 722 | regex_constants::match_flag_type m = regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 723 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 724 | const regex_type&& re, initializer_list<int> submatches, |
| 725 | regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 726 | template <size_t N> |
| 727 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 728 | const regex_type& re, const int (&submatches)[N], |
| 729 | regex_constants::match_flag_type m = regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 730 | template <size_t N> |
| 731 | regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b, |
| 732 | const regex_type& re, const int (&submatches)[N], |
| 733 | regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 734 | regex_token_iterator(const regex_token_iterator&); |
| 735 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 736 | |
| 737 | bool operator==(const regex_token_iterator&) const; |
| 738 | bool operator!=(const regex_token_iterator&) const; |
| 739 | |
| 740 | const value_type& operator*() const; |
| 741 | const value_type* operator->() const; |
| 742 | |
| 743 | regex_token_iterator& operator++(); |
| 744 | regex_token_iterator operator++(int); |
| 745 | }; |
| 746 | |
| 747 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 748 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 749 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 750 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 751 | |
| 752 | } // std |
| 753 | */ |
| 754 | |
| 755 | #include <__config> |
| 756 | #include <stdexcept> |
| 757 | #include <__locale> |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 758 | #include <initializer_list> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 759 | #include <utility> |
| 760 | #include <iterator> |
| 761 | #include <string> |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 762 | #include <memory> |
| 763 | #include <vector> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 764 | #include <deque> |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 765 | |
Howard Hinnant | 66c6f97 | 2011-11-29 16:45:27 +0000 | [diff] [blame] | 766 | #include <__undef_min_max> |
| 767 | |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 768 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 769 | #pragma GCC system_header |
Howard Hinnant | 08e1747 | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 770 | #endif |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 771 | |
| 772 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 773 | |
| 774 | namespace regex_constants |
| 775 | { |
| 776 | |
| 777 | // syntax_option_type |
| 778 | |
| 779 | enum syntax_option_type |
| 780 | { |
| 781 | icase = 1 << 0, |
| 782 | nosubs = 1 << 1, |
| 783 | optimize = 1 << 2, |
| 784 | collate = 1 << 3, |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 785 | ECMAScript = 0, |
| 786 | basic = 1 << 4, |
| 787 | extended = 1 << 5, |
| 788 | awk = 1 << 6, |
| 789 | grep = 1 << 7, |
| 790 | egrep = 1 << 8 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 791 | }; |
| 792 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 793 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 794 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 795 | syntax_option_type |
| 796 | operator~(syntax_option_type __x) |
| 797 | { |
Marshall Clow | 04bd79b | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 798 | return syntax_option_type(~int(__x) & 0x1FF); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 801 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 802 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 803 | syntax_option_type |
| 804 | operator&(syntax_option_type __x, syntax_option_type __y) |
| 805 | { |
| 806 | return syntax_option_type(int(__x) & int(__y)); |
| 807 | } |
| 808 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 809 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 810 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 811 | syntax_option_type |
| 812 | operator|(syntax_option_type __x, syntax_option_type __y) |
| 813 | { |
| 814 | return syntax_option_type(int(__x) | int(__y)); |
| 815 | } |
| 816 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 817 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 818 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 819 | syntax_option_type |
| 820 | operator^(syntax_option_type __x, syntax_option_type __y) |
| 821 | { |
| 822 | return syntax_option_type(int(__x) ^ int(__y)); |
| 823 | } |
| 824 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 825 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 826 | syntax_option_type& |
| 827 | operator&=(syntax_option_type& __x, syntax_option_type __y) |
| 828 | { |
| 829 | __x = __x & __y; |
| 830 | return __x; |
| 831 | } |
| 832 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 833 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 834 | syntax_option_type& |
| 835 | operator|=(syntax_option_type& __x, syntax_option_type __y) |
| 836 | { |
| 837 | __x = __x | __y; |
| 838 | return __x; |
| 839 | } |
| 840 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 841 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 842 | syntax_option_type& |
| 843 | operator^=(syntax_option_type& __x, syntax_option_type __y) |
| 844 | { |
| 845 | __x = __x ^ __y; |
| 846 | return __x; |
| 847 | } |
| 848 | |
| 849 | // match_flag_type |
| 850 | |
| 851 | enum match_flag_type |
| 852 | { |
| 853 | match_default = 0, |
| 854 | match_not_bol = 1 << 0, |
| 855 | match_not_eol = 1 << 1, |
| 856 | match_not_bow = 1 << 2, |
| 857 | match_not_eow = 1 << 3, |
| 858 | match_any = 1 << 4, |
| 859 | match_not_null = 1 << 5, |
| 860 | match_continuous = 1 << 6, |
| 861 | match_prev_avail = 1 << 7, |
| 862 | format_default = 0, |
| 863 | format_sed = 1 << 8, |
| 864 | format_no_copy = 1 << 9, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 865 | format_first_only = 1 << 10, |
| 866 | __no_update_pos = 1 << 11 |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 867 | }; |
| 868 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 869 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 870 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 871 | match_flag_type |
| 872 | operator~(match_flag_type __x) |
| 873 | { |
Marshall Clow | 04bd79b | 2013-03-22 02:13:55 +0000 | [diff] [blame] | 874 | return match_flag_type(~int(__x) & 0x0FFF); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 877 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 878 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 879 | match_flag_type |
| 880 | operator&(match_flag_type __x, match_flag_type __y) |
| 881 | { |
| 882 | return match_flag_type(int(__x) & int(__y)); |
| 883 | } |
| 884 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 885 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 886 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 887 | match_flag_type |
| 888 | operator|(match_flag_type __x, match_flag_type __y) |
| 889 | { |
| 890 | return match_flag_type(int(__x) | int(__y)); |
| 891 | } |
| 892 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 893 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 894 | _LIBCPP_CONSTEXPR |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 895 | match_flag_type |
| 896 | operator^(match_flag_type __x, match_flag_type __y) |
| 897 | { |
| 898 | return match_flag_type(int(__x) ^ int(__y)); |
| 899 | } |
| 900 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 901 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 902 | match_flag_type& |
| 903 | operator&=(match_flag_type& __x, match_flag_type __y) |
| 904 | { |
| 905 | __x = __x & __y; |
| 906 | return __x; |
| 907 | } |
| 908 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 909 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 910 | match_flag_type& |
| 911 | operator|=(match_flag_type& __x, match_flag_type __y) |
| 912 | { |
| 913 | __x = __x | __y; |
| 914 | return __x; |
| 915 | } |
| 916 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 917 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 918 | match_flag_type& |
| 919 | operator^=(match_flag_type& __x, match_flag_type __y) |
| 920 | { |
| 921 | __x = __x ^ __y; |
| 922 | return __x; |
| 923 | } |
| 924 | |
| 925 | enum error_type |
| 926 | { |
| 927 | error_collate = 1, |
| 928 | error_ctype, |
| 929 | error_escape, |
| 930 | error_backref, |
| 931 | error_brack, |
| 932 | error_paren, |
| 933 | error_brace, |
| 934 | error_badbrace, |
| 935 | error_range, |
| 936 | error_space, |
| 937 | error_badrepeat, |
| 938 | error_complexity, |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 939 | error_stack, |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 940 | __re_err_grammar, |
| 941 | __re_err_empty, |
| 942 | __re_err_unknown |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 943 | }; |
| 944 | |
| 945 | } // regex_constants |
| 946 | |
| 947 | class _LIBCPP_EXCEPTION_ABI regex_error |
| 948 | : public runtime_error |
| 949 | { |
| 950 | regex_constants::error_type __code_; |
| 951 | public: |
| 952 | explicit regex_error(regex_constants::error_type __ecode); |
| 953 | virtual ~regex_error() throw(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 954 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 955 | regex_constants::error_type code() const {return __code_;} |
| 956 | }; |
| 957 | |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 958 | template <regex_constants::error_type _Ev> |
| 959 | _LIBCPP_ALWAYS_INLINE |
| 960 | void __throw_regex_error() |
| 961 | { |
| 962 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 963 | throw regex_error(_Ev); |
| 964 | #endif |
| 965 | } |
| 966 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 967 | template <class _CharT> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 968 | struct _LIBCPP_TYPE_VIS_ONLY regex_traits |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 969 | { |
| 970 | public: |
| 971 | typedef _CharT char_type; |
| 972 | typedef basic_string<char_type> string_type; |
| 973 | typedef locale locale_type; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 974 | typedef ctype_base::mask char_class_type; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 975 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 976 | static const char_class_type __regex_word = 0x80; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 977 | private: |
| 978 | locale __loc_; |
| 979 | const ctype<char_type>* __ct_; |
| 980 | const collate<char_type>* __col_; |
| 981 | |
| 982 | public: |
| 983 | regex_traits(); |
| 984 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 985 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 986 | static size_t length(const char_type* __p) |
| 987 | {return char_traits<char_type>::length(__p);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 988 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 989 | char_type translate(char_type __c) const {return __c;} |
| 990 | char_type translate_nocase(char_type __c) const; |
| 991 | template <class _ForwardIterator> |
| 992 | string_type |
| 993 | transform(_ForwardIterator __f, _ForwardIterator __l) const; |
| 994 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 995 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 996 | string_type |
| 997 | transform_primary( _ForwardIterator __f, _ForwardIterator __l) const |
| 998 | {return __transform_primary(__f, __l, char_type());} |
| 999 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1000 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1001 | string_type |
| 1002 | lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const |
| 1003 | {return __lookup_collatename(__f, __l, char_type());} |
| 1004 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1005 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1006 | char_class_type |
| 1007 | lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1008 | bool __icase = false) const |
| 1009 | {return __lookup_classname(__f, __l, __icase, char_type());} |
| 1010 | bool isctype(char_type __c, char_class_type __m) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1011 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1012 | int value(char_type __ch, int __radix) const |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1013 | {return __regex_traits_value(__ch, __radix);} |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1014 | locale_type imbue(locale_type __l); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1015 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1016 | locale_type getloc()const {return __loc_;} |
| 1017 | |
| 1018 | private: |
| 1019 | void __init(); |
| 1020 | |
| 1021 | template <class _ForwardIterator> |
| 1022 | string_type |
| 1023 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 1024 | template <class _ForwardIterator> |
| 1025 | string_type |
| 1026 | __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
| 1027 | |
| 1028 | template <class _ForwardIterator> |
| 1029 | string_type |
| 1030 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const; |
| 1031 | template <class _ForwardIterator> |
| 1032 | string_type |
| 1033 | __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const; |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1034 | |
| 1035 | template <class _ForwardIterator> |
| 1036 | char_class_type |
| 1037 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1038 | bool __icase, char) const; |
| 1039 | template <class _ForwardIterator> |
| 1040 | char_class_type |
| 1041 | __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, |
| 1042 | bool __icase, wchar_t) const; |
| 1043 | |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1044 | static int __regex_traits_value(unsigned char __ch, int __radix); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1045 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1046 | int __regex_traits_value(char __ch, int __radix) const |
| 1047 | {return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);} |
| 1048 | int __regex_traits_value(wchar_t __ch, int __radix) const; |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1049 | }; |
| 1050 | |
| 1051 | template <class _CharT> |
Howard Hinnant | 23fb972 | 2013-03-07 19:38:08 +0000 | [diff] [blame] | 1052 | const typename regex_traits<_CharT>::char_class_type |
| 1053 | regex_traits<_CharT>::__regex_word; |
| 1054 | |
| 1055 | template <class _CharT> |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1056 | regex_traits<_CharT>::regex_traits() |
| 1057 | { |
| 1058 | __init(); |
| 1059 | } |
| 1060 | |
| 1061 | template <class _CharT> |
| 1062 | typename regex_traits<_CharT>::char_type |
| 1063 | regex_traits<_CharT>::translate_nocase(char_type __c) const |
| 1064 | { |
| 1065 | return __ct_->tolower(__c); |
| 1066 | } |
| 1067 | |
| 1068 | template <class _CharT> |
| 1069 | template <class _ForwardIterator> |
| 1070 | typename regex_traits<_CharT>::string_type |
| 1071 | regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const |
| 1072 | { |
| 1073 | string_type __s(__f, __l); |
| 1074 | return __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1075 | } |
| 1076 | |
| 1077 | template <class _CharT> |
| 1078 | void |
| 1079 | regex_traits<_CharT>::__init() |
| 1080 | { |
| 1081 | __ct_ = &use_facet<ctype<char_type> >(__loc_); |
| 1082 | __col_ = &use_facet<collate<char_type> >(__loc_); |
| 1083 | } |
| 1084 | |
| 1085 | template <class _CharT> |
| 1086 | typename regex_traits<_CharT>::locale_type |
| 1087 | regex_traits<_CharT>::imbue(locale_type __l) |
| 1088 | { |
| 1089 | locale __r = __loc_; |
| 1090 | __loc_ = __l; |
| 1091 | __init(); |
| 1092 | return __r; |
| 1093 | } |
| 1094 | |
| 1095 | // transform_primary is very FreeBSD-specific |
| 1096 | |
| 1097 | template <class _CharT> |
| 1098 | template <class _ForwardIterator> |
| 1099 | typename regex_traits<_CharT>::string_type |
| 1100 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1101 | _ForwardIterator __l, char) const |
| 1102 | { |
| 1103 | const string_type __s(__f, __l); |
| 1104 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1105 | switch (__d.size()) |
| 1106 | { |
| 1107 | case 1: |
| 1108 | break; |
| 1109 | case 12: |
| 1110 | __d[11] = __d[3]; |
| 1111 | break; |
| 1112 | default: |
| 1113 | __d.clear(); |
| 1114 | break; |
| 1115 | } |
| 1116 | return __d; |
| 1117 | } |
| 1118 | |
| 1119 | template <class _CharT> |
| 1120 | template <class _ForwardIterator> |
| 1121 | typename regex_traits<_CharT>::string_type |
| 1122 | regex_traits<_CharT>::__transform_primary(_ForwardIterator __f, |
| 1123 | _ForwardIterator __l, wchar_t) const |
| 1124 | { |
| 1125 | const string_type __s(__f, __l); |
| 1126 | string_type __d = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1127 | switch (__d.size()) |
| 1128 | { |
| 1129 | case 1: |
| 1130 | break; |
| 1131 | case 3: |
| 1132 | __d[2] = __d[0]; |
| 1133 | break; |
| 1134 | default: |
| 1135 | __d.clear(); |
| 1136 | break; |
| 1137 | } |
| 1138 | return __d; |
| 1139 | } |
| 1140 | |
| 1141 | // lookup_collatename is very FreeBSD-specific |
| 1142 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1143 | _LIBCPP_FUNC_VIS string __get_collation_name(const char* __s); |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 1144 | |
| 1145 | template <class _CharT> |
| 1146 | template <class _ForwardIterator> |
| 1147 | typename regex_traits<_CharT>::string_type |
| 1148 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1149 | _ForwardIterator __l, char) const |
| 1150 | { |
| 1151 | string_type __s(__f, __l); |
| 1152 | string_type __r; |
| 1153 | if (!__s.empty()) |
| 1154 | { |
| 1155 | __r = __get_collation_name(__s.c_str()); |
| 1156 | if (__r.empty() && __s.size() <= 2) |
| 1157 | { |
| 1158 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1159 | if (__r.size() == 1 || __r.size() == 12) |
| 1160 | __r = __s; |
| 1161 | else |
| 1162 | __r.clear(); |
| 1163 | } |
| 1164 | } |
| 1165 | return __r; |
| 1166 | } |
| 1167 | |
| 1168 | template <class _CharT> |
| 1169 | template <class _ForwardIterator> |
| 1170 | typename regex_traits<_CharT>::string_type |
| 1171 | regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, |
| 1172 | _ForwardIterator __l, wchar_t) const |
| 1173 | { |
| 1174 | string_type __s(__f, __l); |
| 1175 | string __n; |
| 1176 | __n.reserve(__s.size()); |
| 1177 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1178 | __i != __e; ++__i) |
| 1179 | { |
| 1180 | if (static_cast<unsigned>(*__i) >= 127) |
| 1181 | return string_type(); |
| 1182 | __n.push_back(char(*__i)); |
| 1183 | } |
| 1184 | string_type __r; |
| 1185 | if (!__s.empty()) |
| 1186 | { |
| 1187 | __n = __get_collation_name(__n.c_str()); |
| 1188 | if (!__n.empty()) |
| 1189 | __r.assign(__n.begin(), __n.end()); |
| 1190 | else if (__s.size() <= 2) |
| 1191 | { |
| 1192 | __r = __col_->transform(__s.data(), __s.data() + __s.size()); |
| 1193 | if (__r.size() == 1 || __r.size() == 3) |
| 1194 | __r = __s; |
| 1195 | else |
| 1196 | __r.clear(); |
| 1197 | } |
| 1198 | } |
| 1199 | return __r; |
| 1200 | } |
| 1201 | |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1202 | // lookup_classname |
| 1203 | |
Dan Albert | 1757386 | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 1204 | regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS |
| 1205 | __get_classname(const char* __s, bool __icase); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1206 | |
| 1207 | template <class _CharT> |
| 1208 | template <class _ForwardIterator> |
| 1209 | typename regex_traits<_CharT>::char_class_type |
| 1210 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1211 | _ForwardIterator __l, |
| 1212 | bool __icase, char) const |
| 1213 | { |
| 1214 | string_type __s(__f, __l); |
| 1215 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1216 | return __get_classname(__s.c_str(), __icase); |
| 1217 | } |
| 1218 | |
| 1219 | template <class _CharT> |
| 1220 | template <class _ForwardIterator> |
| 1221 | typename regex_traits<_CharT>::char_class_type |
| 1222 | regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, |
| 1223 | _ForwardIterator __l, |
| 1224 | bool __icase, wchar_t) const |
| 1225 | { |
| 1226 | string_type __s(__f, __l); |
| 1227 | __ct_->tolower(&__s[0], &__s[0] + __s.size()); |
| 1228 | string __n; |
| 1229 | __n.reserve(__s.size()); |
| 1230 | for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); |
| 1231 | __i != __e; ++__i) |
| 1232 | { |
| 1233 | if (static_cast<unsigned>(*__i) >= 127) |
| 1234 | return char_class_type(); |
| 1235 | __n.push_back(char(*__i)); |
| 1236 | } |
| 1237 | return __get_classname(__n.c_str(), __icase); |
| 1238 | } |
| 1239 | |
| 1240 | template <class _CharT> |
| 1241 | bool |
| 1242 | regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const |
| 1243 | { |
| 1244 | if (__ct_->is(__m, __c)) |
| 1245 | return true; |
| 1246 | return (__c == '_' && (__m & __regex_word)); |
| 1247 | } |
| 1248 | |
| 1249 | template <class _CharT> |
| 1250 | int |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1251 | regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1252 | { |
| 1253 | if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7' |
| 1254 | return __ch - '0'; |
| 1255 | if (__radix != 8) |
| 1256 | { |
| 1257 | if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9' |
| 1258 | return __ch - '0'; |
| 1259 | if (__radix == 16) |
| 1260 | { |
| 1261 | __ch |= 0x20; // tolower |
| 1262 | if ('a' <= __ch && __ch <= 'f') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 1263 | return __ch - ('a' - 10); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | return -1; |
| 1267 | } |
| 1268 | |
| 1269 | template <class _CharT> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1270 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1271 | int |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1272 | regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1273 | { |
Marshall Clow | 33ae233 | 2013-10-21 15:43:25 +0000 | [diff] [blame] | 1274 | return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix); |
Howard Hinnant | f409d2f | 2010-06-21 21:01:43 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1277 | template <class _CharT> class __node; |
| 1278 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1279 | template <class _BidirectionalIterator> class _LIBCPP_TYPE_VIS_ONLY sub_match; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1280 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1281 | template <class _BidirectionalIterator, |
| 1282 | class _Allocator = allocator<sub_match<_BidirectionalIterator> > > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 1283 | class _LIBCPP_TYPE_VIS_ONLY match_results; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1284 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1285 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1286 | struct __state |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1287 | { |
| 1288 | enum |
| 1289 | { |
| 1290 | __end_state = -1000, |
| 1291 | __consume_input, // -999 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1292 | __begin_marked_expr, // -998 |
| 1293 | __end_marked_expr, // -997 |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1294 | __pop_state, // -996 |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1295 | __accept_and_consume, // -995 |
| 1296 | __accept_but_not_consume, // -994 |
| 1297 | __reject, // -993 |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1298 | __split, |
| 1299 | __repeat |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1300 | }; |
| 1301 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1302 | int __do_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1303 | const _CharT* __first_; |
| 1304 | const _CharT* __current_; |
| 1305 | const _CharT* __last_; |
| 1306 | vector<sub_match<const _CharT*> > __sub_matches_; |
| 1307 | vector<pair<size_t, const _CharT*> > __loop_data_; |
| 1308 | const __node<_CharT>* __node_; |
| 1309 | regex_constants::match_flag_type __flags_; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1310 | bool __at_first_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1311 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1312 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1313 | __state() |
| 1314 | : __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr), |
| 1315 | __node_(nullptr), __flags_() {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1316 | }; |
| 1317 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1318 | // __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1319 | |
| 1320 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1321 | class __node |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1322 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1323 | __node(const __node&); |
| 1324 | __node& operator=(const __node&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1325 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1326 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1327 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1328 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1329 | __node() {} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1330 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1331 | virtual ~__node() {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1332 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1333 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1334 | virtual void __exec(__state&) const {}; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1335 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1336 | virtual void __exec_split(bool, __state&) const {}; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1337 | }; |
| 1338 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1339 | // __end_state |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1340 | |
| 1341 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1342 | class __end_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1343 | : public __node<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1344 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1345 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1346 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1347 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1348 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1349 | __end_state() {} |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1350 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1351 | virtual void __exec(__state&) const; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 1352 | }; |
| 1353 | |
| 1354 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1355 | void |
| 1356 | __end_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1357 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1358 | __s.__do_ = __state::__end_state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1359 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1360 | |
| 1361 | // __has_one_state |
| 1362 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 1363 | template <class _CharT> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1364 | class __has_one_state |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1365 | : public __node<_CharT> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1366 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1367 | __node<_CharT>* __first_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1368 | |
| 1369 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1370 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1371 | explicit __has_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1372 | : __first_(__s) {} |
| 1373 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1374 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1375 | __node<_CharT>* first() const {return __first_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1376 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1377 | __node<_CharT>*& first() {return __first_;} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1378 | }; |
| 1379 | |
| 1380 | // __owns_one_state |
| 1381 | |
| 1382 | template <class _CharT> |
| 1383 | class __owns_one_state |
| 1384 | : public __has_one_state<_CharT> |
| 1385 | { |
| 1386 | typedef __has_one_state<_CharT> base; |
| 1387 | |
| 1388 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1389 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1390 | explicit __owns_one_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1391 | : base(__s) {} |
| 1392 | |
| 1393 | virtual ~__owns_one_state(); |
| 1394 | }; |
| 1395 | |
| 1396 | template <class _CharT> |
| 1397 | __owns_one_state<_CharT>::~__owns_one_state() |
| 1398 | { |
| 1399 | delete this->first(); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1402 | // __empty_state |
| 1403 | |
| 1404 | template <class _CharT> |
| 1405 | class __empty_state |
| 1406 | : public __owns_one_state<_CharT> |
| 1407 | { |
| 1408 | typedef __owns_one_state<_CharT> base; |
| 1409 | |
| 1410 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1411 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1412 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1413 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1414 | explicit __empty_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1415 | : base(__s) {} |
| 1416 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1417 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1418 | }; |
| 1419 | |
| 1420 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1421 | void |
| 1422 | __empty_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1423 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1424 | __s.__do_ = __state::__accept_but_not_consume; |
| 1425 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | // __empty_non_own_state |
| 1429 | |
| 1430 | template <class _CharT> |
| 1431 | class __empty_non_own_state |
| 1432 | : public __has_one_state<_CharT> |
| 1433 | { |
| 1434 | typedef __has_one_state<_CharT> base; |
| 1435 | |
| 1436 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1437 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1438 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1439 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1440 | explicit __empty_non_own_state(__node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1441 | : base(__s) {} |
| 1442 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1443 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1444 | }; |
| 1445 | |
| 1446 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1447 | void |
| 1448 | __empty_non_own_state<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1449 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1450 | __s.__do_ = __state::__accept_but_not_consume; |
| 1451 | __s.__node_ = this->first(); |
| 1452 | } |
| 1453 | |
| 1454 | // __repeat_one_loop |
| 1455 | |
| 1456 | template <class _CharT> |
| 1457 | class __repeat_one_loop |
| 1458 | : public __has_one_state<_CharT> |
| 1459 | { |
| 1460 | typedef __has_one_state<_CharT> base; |
| 1461 | |
| 1462 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1463 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1464 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1465 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1466 | explicit __repeat_one_loop(__node<_CharT>* __s) |
| 1467 | : base(__s) {} |
| 1468 | |
| 1469 | virtual void __exec(__state&) const; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1470 | }; |
| 1471 | |
| 1472 | template <class _CharT> |
| 1473 | void |
| 1474 | __repeat_one_loop<_CharT>::__exec(__state& __s) const |
| 1475 | { |
| 1476 | __s.__do_ = __state::__repeat; |
| 1477 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | // __owns_two_states |
| 1481 | |
| 1482 | template <class _CharT> |
| 1483 | class __owns_two_states |
| 1484 | : public __owns_one_state<_CharT> |
| 1485 | { |
| 1486 | typedef __owns_one_state<_CharT> base; |
| 1487 | |
| 1488 | base* __second_; |
| 1489 | |
| 1490 | public: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1491 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1492 | explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1493 | : base(__s1), __second_(__s2) {} |
| 1494 | |
| 1495 | virtual ~__owns_two_states(); |
| 1496 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1497 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1498 | base* second() const {return __second_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1499 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1500 | base*& second() {return __second_;} |
| 1501 | }; |
| 1502 | |
| 1503 | template <class _CharT> |
| 1504 | __owns_two_states<_CharT>::~__owns_two_states() |
| 1505 | { |
| 1506 | delete __second_; |
| 1507 | } |
| 1508 | |
| 1509 | // __loop |
| 1510 | |
| 1511 | template <class _CharT> |
| 1512 | class __loop |
| 1513 | : public __owns_two_states<_CharT> |
| 1514 | { |
| 1515 | typedef __owns_two_states<_CharT> base; |
| 1516 | |
| 1517 | size_t __min_; |
| 1518 | size_t __max_; |
| 1519 | unsigned __loop_id_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1520 | unsigned __mexp_begin_; |
| 1521 | unsigned __mexp_end_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1522 | bool __greedy_; |
| 1523 | |
| 1524 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1525 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1526 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1527 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1528 | explicit __loop(unsigned __loop_id, |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1529 | __node<_CharT>* __s1, __owns_one_state<_CharT>* __s2, |
| 1530 | unsigned __mexp_begin, unsigned __mexp_end, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1531 | bool __greedy = true, |
| 1532 | size_t __min = 0, |
| 1533 | size_t __max = numeric_limits<size_t>::max()) |
| 1534 | : base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id), |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1535 | __mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end), |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1536 | __greedy_(__greedy) {} |
| 1537 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1538 | virtual void __exec(__state& __s) const; |
| 1539 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1540 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1541 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1542 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1543 | void __init_repeat(__state& __s) const |
| 1544 | { |
| 1545 | __s.__loop_data_[__loop_id_].second = __s.__current_; |
| 1546 | for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i) |
| 1547 | { |
| 1548 | __s.__sub_matches_[__i].first = __s.__last_; |
| 1549 | __s.__sub_matches_[__i].second = __s.__last_; |
| 1550 | __s.__sub_matches_[__i].matched = false; |
| 1551 | } |
| 1552 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1553 | }; |
| 1554 | |
| 1555 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1556 | void |
| 1557 | __loop<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1558 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1559 | if (__s.__do_ == __state::__repeat) |
| 1560 | { |
| 1561 | bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_; |
| 1562 | bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_; |
| 1563 | if (__do_repeat && __do_alt && |
| 1564 | __s.__loop_data_[__loop_id_].second == __s.__current_) |
| 1565 | __do_repeat = false; |
| 1566 | if (__do_repeat && __do_alt) |
| 1567 | __s.__do_ = __state::__split; |
| 1568 | else if (__do_repeat) |
| 1569 | { |
| 1570 | __s.__do_ = __state::__accept_but_not_consume; |
| 1571 | __s.__node_ = this->first(); |
| 1572 | __init_repeat(__s); |
| 1573 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1574 | else |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1575 | { |
| 1576 | __s.__do_ = __state::__accept_but_not_consume; |
| 1577 | __s.__node_ = this->second(); |
| 1578 | } |
| 1579 | } |
| 1580 | else |
| 1581 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1582 | __s.__loop_data_[__loop_id_].first = 0; |
| 1583 | bool __do_repeat = 0 < __max_; |
| 1584 | bool __do_alt = 0 >= __min_; |
| 1585 | if (__do_repeat && __do_alt) |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1586 | __s.__do_ = __state::__split; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 1587 | else if (__do_repeat) |
| 1588 | { |
| 1589 | __s.__do_ = __state::__accept_but_not_consume; |
| 1590 | __s.__node_ = this->first(); |
| 1591 | __init_repeat(__s); |
| 1592 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1593 | else |
| 1594 | { |
| 1595 | __s.__do_ = __state::__accept_but_not_consume; |
| 1596 | __s.__node_ = this->second(); |
| 1597 | } |
| 1598 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1601 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1602 | void |
| 1603 | __loop<_CharT>::__exec_split(bool __second, __state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1604 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1605 | __s.__do_ = __state::__accept_but_not_consume; |
| 1606 | if (__greedy_ != __second) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1607 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1608 | __s.__node_ = this->first(); |
| 1609 | __init_repeat(__s); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1610 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1611 | else |
| 1612 | __s.__node_ = this->second(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1615 | // __alternate |
| 1616 | |
| 1617 | template <class _CharT> |
| 1618 | class __alternate |
| 1619 | : public __owns_two_states<_CharT> |
| 1620 | { |
| 1621 | typedef __owns_two_states<_CharT> base; |
| 1622 | |
| 1623 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1624 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1625 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1626 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1627 | explicit __alternate(__owns_one_state<_CharT>* __s1, |
| 1628 | __owns_one_state<_CharT>* __s2) |
| 1629 | : base(__s1, __s2) {} |
| 1630 | |
| 1631 | virtual void __exec(__state& __s) const; |
| 1632 | virtual void __exec_split(bool __second, __state& __s) const; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1633 | }; |
| 1634 | |
| 1635 | template <class _CharT> |
| 1636 | void |
| 1637 | __alternate<_CharT>::__exec(__state& __s) const |
| 1638 | { |
| 1639 | __s.__do_ = __state::__split; |
| 1640 | } |
| 1641 | |
| 1642 | template <class _CharT> |
| 1643 | void |
| 1644 | __alternate<_CharT>::__exec_split(bool __second, __state& __s) const |
| 1645 | { |
| 1646 | __s.__do_ = __state::__accept_but_not_consume; |
Howard Hinnant | 1371b2e | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1647 | if (__second) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1648 | __s.__node_ = this->second(); |
Howard Hinnant | 1371b2e | 2010-07-22 14:12:20 +0000 | [diff] [blame] | 1649 | else |
| 1650 | __s.__node_ = this->first(); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1653 | // __begin_marked_subexpression |
| 1654 | |
| 1655 | template <class _CharT> |
| 1656 | class __begin_marked_subexpression |
| 1657 | : public __owns_one_state<_CharT> |
| 1658 | { |
| 1659 | typedef __owns_one_state<_CharT> base; |
| 1660 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1661 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1662 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1663 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1664 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1665 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1666 | explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1667 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1668 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1669 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1670 | }; |
| 1671 | |
| 1672 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1673 | void |
| 1674 | __begin_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1675 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1676 | __s.__do_ = __state::__accept_but_not_consume; |
| 1677 | __s.__sub_matches_[__mexp_-1].first = __s.__current_; |
| 1678 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | // __end_marked_subexpression |
| 1682 | |
| 1683 | template <class _CharT> |
| 1684 | class __end_marked_subexpression |
| 1685 | : public __owns_one_state<_CharT> |
| 1686 | { |
| 1687 | typedef __owns_one_state<_CharT> base; |
| 1688 | |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1689 | unsigned __mexp_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1690 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1691 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1692 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1693 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1694 | explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 1695 | : base(__s), __mexp_(__mexp) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1696 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1697 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1698 | }; |
| 1699 | |
| 1700 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1701 | void |
| 1702 | __end_marked_subexpression<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1703 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1704 | __s.__do_ = __state::__accept_but_not_consume; |
| 1705 | __s.__sub_matches_[__mexp_-1].second = __s.__current_; |
| 1706 | __s.__sub_matches_[__mexp_-1].matched = true; |
| 1707 | __s.__node_ = this->first(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1708 | } |
| 1709 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1710 | // __back_ref |
| 1711 | |
| 1712 | template <class _CharT> |
| 1713 | class __back_ref |
| 1714 | : public __owns_one_state<_CharT> |
| 1715 | { |
| 1716 | typedef __owns_one_state<_CharT> base; |
| 1717 | |
| 1718 | unsigned __mexp_; |
| 1719 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1720 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1721 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1722 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1723 | explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) |
| 1724 | : base(__s), __mexp_(__mexp) {} |
| 1725 | |
| 1726 | virtual void __exec(__state&) const; |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1727 | }; |
| 1728 | |
| 1729 | template <class _CharT> |
| 1730 | void |
| 1731 | __back_ref<_CharT>::__exec(__state& __s) const |
| 1732 | { |
| 1733 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1734 | if (__sm.matched) |
| 1735 | { |
| 1736 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1737 | if (__s.__last_ - __s.__current_ >= __len && |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1738 | _VSTD::equal(__sm.first, __sm.second, __s.__current_)) |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 1739 | { |
| 1740 | __s.__do_ = __state::__accept_but_not_consume; |
| 1741 | __s.__current_ += __len; |
| 1742 | __s.__node_ = this->first(); |
| 1743 | } |
| 1744 | else |
| 1745 | { |
| 1746 | __s.__do_ = __state::__reject; |
| 1747 | __s.__node_ = nullptr; |
| 1748 | } |
| 1749 | } |
| 1750 | else |
| 1751 | { |
| 1752 | __s.__do_ = __state::__reject; |
| 1753 | __s.__node_ = nullptr; |
| 1754 | } |
| 1755 | } |
| 1756 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1757 | // __back_ref_icase |
| 1758 | |
| 1759 | template <class _CharT, class _Traits> |
| 1760 | class __back_ref_icase |
| 1761 | : public __owns_one_state<_CharT> |
| 1762 | { |
| 1763 | typedef __owns_one_state<_CharT> base; |
| 1764 | |
| 1765 | _Traits __traits_; |
| 1766 | unsigned __mexp_; |
| 1767 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1768 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1769 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1770 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1771 | explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, |
| 1772 | __node<_CharT>* __s) |
| 1773 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1774 | |
| 1775 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1776 | }; |
| 1777 | |
| 1778 | template <class _CharT, class _Traits> |
| 1779 | void |
| 1780 | __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 1781 | { |
| 1782 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1783 | if (__sm.matched) |
| 1784 | { |
| 1785 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1786 | if (__s.__last_ - __s.__current_ >= __len) |
| 1787 | { |
| 1788 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1789 | { |
| 1790 | if (__traits_.translate_nocase(__sm.first[__i]) != |
| 1791 | __traits_.translate_nocase(__s.__current_[__i])) |
| 1792 | goto __not_equal; |
| 1793 | } |
| 1794 | __s.__do_ = __state::__accept_but_not_consume; |
| 1795 | __s.__current_ += __len; |
| 1796 | __s.__node_ = this->first(); |
| 1797 | } |
| 1798 | else |
| 1799 | { |
| 1800 | __s.__do_ = __state::__reject; |
| 1801 | __s.__node_ = nullptr; |
| 1802 | } |
| 1803 | } |
| 1804 | else |
| 1805 | { |
| 1806 | __not_equal: |
| 1807 | __s.__do_ = __state::__reject; |
| 1808 | __s.__node_ = nullptr; |
| 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | // __back_ref_collate |
| 1813 | |
| 1814 | template <class _CharT, class _Traits> |
| 1815 | class __back_ref_collate |
| 1816 | : public __owns_one_state<_CharT> |
| 1817 | { |
| 1818 | typedef __owns_one_state<_CharT> base; |
| 1819 | |
| 1820 | _Traits __traits_; |
| 1821 | unsigned __mexp_; |
| 1822 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1823 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1824 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1825 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1826 | explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, |
| 1827 | __node<_CharT>* __s) |
| 1828 | : base(__s), __traits_(__traits), __mexp_(__mexp) {} |
| 1829 | |
| 1830 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 1831 | }; |
| 1832 | |
| 1833 | template <class _CharT, class _Traits> |
| 1834 | void |
| 1835 | __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 1836 | { |
| 1837 | sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1]; |
| 1838 | if (__sm.matched) |
| 1839 | { |
| 1840 | ptrdiff_t __len = __sm.second - __sm.first; |
| 1841 | if (__s.__last_ - __s.__current_ >= __len) |
| 1842 | { |
| 1843 | for (ptrdiff_t __i = 0; __i < __len; ++__i) |
| 1844 | { |
| 1845 | if (__traits_.translate(__sm.first[__i]) != |
| 1846 | __traits_.translate(__s.__current_[__i])) |
| 1847 | goto __not_equal; |
| 1848 | } |
| 1849 | __s.__do_ = __state::__accept_but_not_consume; |
| 1850 | __s.__current_ += __len; |
| 1851 | __s.__node_ = this->first(); |
| 1852 | } |
| 1853 | else |
| 1854 | { |
| 1855 | __s.__do_ = __state::__reject; |
| 1856 | __s.__node_ = nullptr; |
| 1857 | } |
| 1858 | } |
| 1859 | else |
| 1860 | { |
| 1861 | __not_equal: |
| 1862 | __s.__do_ = __state::__reject; |
| 1863 | __s.__node_ = nullptr; |
| 1864 | } |
| 1865 | } |
| 1866 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1867 | // __word_boundary |
| 1868 | |
| 1869 | template <class _CharT, class _Traits> |
| 1870 | class __word_boundary |
| 1871 | : public __owns_one_state<_CharT> |
| 1872 | { |
| 1873 | typedef __owns_one_state<_CharT> base; |
| 1874 | |
| 1875 | _Traits __traits_; |
| 1876 | bool __invert_; |
| 1877 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1878 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1879 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1880 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1881 | explicit __word_boundary(const _Traits& __traits, bool __invert, |
| 1882 | __node<_CharT>* __s) |
| 1883 | : base(__s), __traits_(__traits), __invert_(__invert) {} |
| 1884 | |
| 1885 | virtual void __exec(__state&) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1886 | }; |
| 1887 | |
| 1888 | template <class _CharT, class _Traits> |
| 1889 | void |
| 1890 | __word_boundary<_CharT, _Traits>::__exec(__state& __s) const |
| 1891 | { |
| 1892 | bool __is_word_b = false; |
| 1893 | if (__s.__first_ != __s.__last_) |
| 1894 | { |
| 1895 | if (__s.__current_ == __s.__last_) |
| 1896 | { |
| 1897 | if (!(__s.__flags_ & regex_constants::match_not_eow)) |
| 1898 | { |
| 1899 | _CharT __c = __s.__current_[-1]; |
| 1900 | __is_word_b = __c == '_' || |
| 1901 | __traits_.isctype(__c, ctype_base::alnum); |
| 1902 | } |
| 1903 | } |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 1904 | else if (__s.__current_ == __s.__first_ && |
| 1905 | !(__s.__flags_ & regex_constants::match_prev_avail)) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 1906 | { |
| 1907 | if (!(__s.__flags_ & regex_constants::match_not_bow)) |
| 1908 | { |
| 1909 | _CharT __c = *__s.__current_; |
| 1910 | __is_word_b = __c == '_' || |
| 1911 | __traits_.isctype(__c, ctype_base::alnum); |
| 1912 | } |
| 1913 | } |
| 1914 | else |
| 1915 | { |
| 1916 | _CharT __c1 = __s.__current_[-1]; |
| 1917 | _CharT __c2 = *__s.__current_; |
| 1918 | bool __is_c1_b = __c1 == '_' || |
| 1919 | __traits_.isctype(__c1, ctype_base::alnum); |
| 1920 | bool __is_c2_b = __c2 == '_' || |
| 1921 | __traits_.isctype(__c2, ctype_base::alnum); |
| 1922 | __is_word_b = __is_c1_b != __is_c2_b; |
| 1923 | } |
| 1924 | } |
| 1925 | if (__is_word_b != __invert_) |
| 1926 | { |
| 1927 | __s.__do_ = __state::__accept_but_not_consume; |
| 1928 | __s.__node_ = this->first(); |
| 1929 | } |
| 1930 | else |
| 1931 | { |
| 1932 | __s.__do_ = __state::__reject; |
| 1933 | __s.__node_ = nullptr; |
| 1934 | } |
| 1935 | } |
| 1936 | |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1937 | // __l_anchor |
| 1938 | |
| 1939 | template <class _CharT> |
| 1940 | class __l_anchor |
| 1941 | : public __owns_one_state<_CharT> |
| 1942 | { |
| 1943 | typedef __owns_one_state<_CharT> base; |
| 1944 | |
| 1945 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1946 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1947 | |
| 1948 | _LIBCPP_INLINE_VISIBILITY |
| 1949 | __l_anchor(__node<_CharT>* __s) |
| 1950 | : base(__s) {} |
| 1951 | |
| 1952 | virtual void __exec(__state&) const; |
| 1953 | }; |
| 1954 | |
| 1955 | template <class _CharT> |
| 1956 | void |
| 1957 | __l_anchor<_CharT>::__exec(__state& __s) const |
| 1958 | { |
Marshall Clow | 64befb5 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 1959 | if (__s.__at_first_ && __s.__current_ == __s.__first_ && |
| 1960 | !(__s.__flags_ & regex_constants::match_not_bol)) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 1961 | { |
| 1962 | __s.__do_ = __state::__accept_but_not_consume; |
| 1963 | __s.__node_ = this->first(); |
| 1964 | } |
| 1965 | else |
| 1966 | { |
| 1967 | __s.__do_ = __state::__reject; |
| 1968 | __s.__node_ = nullptr; |
| 1969 | } |
| 1970 | } |
| 1971 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1972 | // __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1973 | |
| 1974 | template <class _CharT> |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1975 | class __r_anchor |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1976 | : public __owns_one_state<_CharT> |
| 1977 | { |
| 1978 | typedef __owns_one_state<_CharT> base; |
| 1979 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1980 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1981 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1982 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 1983 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1984 | __r_anchor(__node<_CharT>* __s) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 1985 | : base(__s) {} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1986 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1987 | virtual void __exec(__state&) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1988 | }; |
| 1989 | |
| 1990 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1991 | void |
| 1992 | __r_anchor<_CharT>::__exec(__state& __s) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 1993 | { |
Marshall Clow | 64befb5 | 2015-03-19 17:05:59 +0000 | [diff] [blame] | 1994 | if (__s.__current_ == __s.__last_ && |
| 1995 | !(__s.__flags_ & regex_constants::match_not_eol)) |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 1996 | { |
| 1997 | __s.__do_ = __state::__accept_but_not_consume; |
| 1998 | __s.__node_ = this->first(); |
| 1999 | } |
| 2000 | else |
| 2001 | { |
| 2002 | __s.__do_ = __state::__reject; |
| 2003 | __s.__node_ = nullptr; |
| 2004 | } |
| 2005 | } |
| 2006 | |
| 2007 | // __match_any |
| 2008 | |
| 2009 | template <class _CharT> |
| 2010 | class __match_any |
| 2011 | : public __owns_one_state<_CharT> |
| 2012 | { |
| 2013 | typedef __owns_one_state<_CharT> base; |
| 2014 | |
| 2015 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2016 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2017 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2018 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2019 | __match_any(__node<_CharT>* __s) |
| 2020 | : base(__s) {} |
| 2021 | |
| 2022 | virtual void __exec(__state&) const; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2023 | }; |
| 2024 | |
| 2025 | template <class _CharT> |
| 2026 | void |
| 2027 | __match_any<_CharT>::__exec(__state& __s) const |
| 2028 | { |
| 2029 | if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) |
| 2030 | { |
| 2031 | __s.__do_ = __state::__accept_and_consume; |
| 2032 | ++__s.__current_; |
| 2033 | __s.__node_ = this->first(); |
| 2034 | } |
| 2035 | else |
| 2036 | { |
| 2037 | __s.__do_ = __state::__reject; |
| 2038 | __s.__node_ = nullptr; |
| 2039 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2040 | } |
| 2041 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2042 | // __match_any_but_newline |
| 2043 | |
| 2044 | template <class _CharT> |
| 2045 | class __match_any_but_newline |
| 2046 | : public __owns_one_state<_CharT> |
| 2047 | { |
| 2048 | typedef __owns_one_state<_CharT> base; |
| 2049 | |
| 2050 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2051 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2052 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2053 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2054 | __match_any_but_newline(__node<_CharT>* __s) |
| 2055 | : base(__s) {} |
| 2056 | |
| 2057 | virtual void __exec(__state&) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2058 | }; |
| 2059 | |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2060 | template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const; |
| 2061 | template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const; |
| 2062 | |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2063 | // __match_char |
| 2064 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2065 | template <class _CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2066 | class __match_char |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2067 | : public __owns_one_state<_CharT> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2068 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2069 | typedef __owns_one_state<_CharT> base; |
| 2070 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2071 | _CharT __c_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2072 | |
| 2073 | __match_char(const __match_char&); |
| 2074 | __match_char& operator=(const __match_char&); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2075 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2076 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2077 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2078 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2079 | __match_char(_CharT __c, __node<_CharT>* __s) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2080 | : base(__s), __c_(__c) {} |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2081 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2082 | virtual void __exec(__state&) const; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2083 | }; |
| 2084 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2085 | template <class _CharT> |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2086 | void |
| 2087 | __match_char<_CharT>::__exec(__state& __s) const |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2088 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2089 | if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) |
| 2090 | { |
| 2091 | __s.__do_ = __state::__accept_and_consume; |
| 2092 | ++__s.__current_; |
| 2093 | __s.__node_ = this->first(); |
| 2094 | } |
| 2095 | else |
| 2096 | { |
| 2097 | __s.__do_ = __state::__reject; |
| 2098 | __s.__node_ = nullptr; |
| 2099 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2100 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2101 | |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2102 | // __match_char_icase |
| 2103 | |
| 2104 | template <class _CharT, class _Traits> |
| 2105 | class __match_char_icase |
| 2106 | : public __owns_one_state<_CharT> |
| 2107 | { |
| 2108 | typedef __owns_one_state<_CharT> base; |
| 2109 | |
| 2110 | _Traits __traits_; |
| 2111 | _CharT __c_; |
| 2112 | |
| 2113 | __match_char_icase(const __match_char_icase&); |
| 2114 | __match_char_icase& operator=(const __match_char_icase&); |
| 2115 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2116 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2117 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2118 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2119 | __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2120 | : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {} |
| 2121 | |
| 2122 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2123 | }; |
| 2124 | |
| 2125 | template <class _CharT, class _Traits> |
| 2126 | void |
| 2127 | __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const |
| 2128 | { |
| 2129 | if (__s.__current_ != __s.__last_ && |
| 2130 | __traits_.translate_nocase(*__s.__current_) == __c_) |
| 2131 | { |
| 2132 | __s.__do_ = __state::__accept_and_consume; |
| 2133 | ++__s.__current_; |
| 2134 | __s.__node_ = this->first(); |
| 2135 | } |
| 2136 | else |
| 2137 | { |
| 2138 | __s.__do_ = __state::__reject; |
| 2139 | __s.__node_ = nullptr; |
| 2140 | } |
| 2141 | } |
| 2142 | |
| 2143 | // __match_char_collate |
| 2144 | |
| 2145 | template <class _CharT, class _Traits> |
| 2146 | class __match_char_collate |
| 2147 | : public __owns_one_state<_CharT> |
| 2148 | { |
| 2149 | typedef __owns_one_state<_CharT> base; |
| 2150 | |
| 2151 | _Traits __traits_; |
| 2152 | _CharT __c_; |
| 2153 | |
| 2154 | __match_char_collate(const __match_char_collate&); |
| 2155 | __match_char_collate& operator=(const __match_char_collate&); |
| 2156 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2157 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2158 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2159 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2160 | __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s) |
| 2161 | : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {} |
| 2162 | |
| 2163 | virtual void __exec(__state&) const; |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 2164 | }; |
| 2165 | |
| 2166 | template <class _CharT, class _Traits> |
| 2167 | void |
| 2168 | __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const |
| 2169 | { |
| 2170 | if (__s.__current_ != __s.__last_ && |
| 2171 | __traits_.translate(*__s.__current_) == __c_) |
| 2172 | { |
| 2173 | __s.__do_ = __state::__accept_and_consume; |
| 2174 | ++__s.__current_; |
| 2175 | __s.__node_ = this->first(); |
| 2176 | } |
| 2177 | else |
| 2178 | { |
| 2179 | __s.__do_ = __state::__reject; |
| 2180 | __s.__node_ = nullptr; |
| 2181 | } |
| 2182 | } |
| 2183 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2184 | // __bracket_expression |
| 2185 | |
| 2186 | template <class _CharT, class _Traits> |
| 2187 | class __bracket_expression |
| 2188 | : public __owns_one_state<_CharT> |
| 2189 | { |
| 2190 | typedef __owns_one_state<_CharT> base; |
| 2191 | typedef typename _Traits::string_type string_type; |
| 2192 | |
| 2193 | _Traits __traits_; |
| 2194 | vector<_CharT> __chars_; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2195 | vector<_CharT> __neg_chars_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2196 | vector<pair<string_type, string_type> > __ranges_; |
| 2197 | vector<pair<_CharT, _CharT> > __digraphs_; |
| 2198 | vector<string_type> __equivalences_; |
Dan Albert | 1757386 | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2199 | typename regex_traits<_CharT>::char_class_type __mask_; |
| 2200 | typename regex_traits<_CharT>::char_class_type __neg_mask_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2201 | bool __negate_; |
| 2202 | bool __icase_; |
| 2203 | bool __collate_; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2204 | bool __might_have_digraph_; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2205 | |
| 2206 | __bracket_expression(const __bracket_expression&); |
| 2207 | __bracket_expression& operator=(const __bracket_expression&); |
| 2208 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2209 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2210 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2211 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2212 | __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, |
| 2213 | bool __negate, bool __icase, bool __collate) |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2214 | : base(__s), __traits_(__traits), __mask_(), __neg_mask_(), |
| 2215 | __negate_(__negate), __icase_(__icase), __collate_(__collate), |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2216 | __might_have_digraph_(__traits_.getloc().name() != "C") {} |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2217 | |
| 2218 | virtual void __exec(__state&) const; |
| 2219 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2220 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2221 | bool __negated() const {return __negate_;} |
| 2222 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2223 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2224 | void __add_char(_CharT __c) |
| 2225 | { |
| 2226 | if (__icase_) |
| 2227 | __chars_.push_back(__traits_.translate_nocase(__c)); |
| 2228 | else if (__collate_) |
| 2229 | __chars_.push_back(__traits_.translate(__c)); |
| 2230 | else |
| 2231 | __chars_.push_back(__c); |
| 2232 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2233 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2234 | void __add_neg_char(_CharT __c) |
| 2235 | { |
| 2236 | if (__icase_) |
| 2237 | __neg_chars_.push_back(__traits_.translate_nocase(__c)); |
| 2238 | else if (__collate_) |
| 2239 | __neg_chars_.push_back(__traits_.translate(__c)); |
| 2240 | else |
| 2241 | __neg_chars_.push_back(__c); |
| 2242 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2243 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2244 | void __add_range(string_type __b, string_type __e) |
| 2245 | { |
| 2246 | if (__collate_) |
| 2247 | { |
| 2248 | if (__icase_) |
| 2249 | { |
| 2250 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2251 | __b[__i] = __traits_.translate_nocase(__b[__i]); |
| 2252 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2253 | __e[__i] = __traits_.translate_nocase(__e[__i]); |
| 2254 | } |
| 2255 | else |
| 2256 | { |
| 2257 | for (size_t __i = 0; __i < __b.size(); ++__i) |
| 2258 | __b[__i] = __traits_.translate(__b[__i]); |
| 2259 | for (size_t __i = 0; __i < __e.size(); ++__i) |
| 2260 | __e[__i] = __traits_.translate(__e[__i]); |
| 2261 | } |
| 2262 | __ranges_.push_back(make_pair( |
| 2263 | __traits_.transform(__b.begin(), __b.end()), |
| 2264 | __traits_.transform(__e.begin(), __e.end()))); |
| 2265 | } |
| 2266 | else |
| 2267 | { |
| 2268 | if (__b.size() != 1 || __e.size() != 1) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 2269 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2270 | if (__icase_) |
| 2271 | { |
| 2272 | __b[0] = __traits_.translate_nocase(__b[0]); |
| 2273 | __e[0] = __traits_.translate_nocase(__e[0]); |
| 2274 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2275 | __ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e))); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2276 | } |
| 2277 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2278 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2279 | void __add_digraph(_CharT __c1, _CharT __c2) |
| 2280 | { |
| 2281 | if (__icase_) |
| 2282 | __digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1), |
| 2283 | __traits_.translate_nocase(__c2))); |
| 2284 | else if (__collate_) |
| 2285 | __digraphs_.push_back(make_pair(__traits_.translate(__c1), |
| 2286 | __traits_.translate(__c2))); |
| 2287 | else |
| 2288 | __digraphs_.push_back(make_pair(__c1, __c2)); |
| 2289 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2290 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2291 | void __add_equivalence(const string_type& __s) |
| 2292 | {__equivalences_.push_back(__s);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2293 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 1757386 | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2294 | void __add_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2295 | {__mask_ |= __mask;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2296 | _LIBCPP_INLINE_VISIBILITY |
Dan Albert | 1757386 | 2014-07-29 19:23:39 +0000 | [diff] [blame] | 2297 | void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask) |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2298 | {__neg_mask_ |= __mask;} |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2299 | }; |
| 2300 | |
| 2301 | template <class _CharT, class _Traits> |
| 2302 | void |
| 2303 | __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const |
| 2304 | { |
| 2305 | bool __found = false; |
| 2306 | unsigned __consumed = 0; |
| 2307 | if (__s.__current_ != __s.__last_) |
| 2308 | { |
| 2309 | ++__consumed; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2310 | if (__might_have_digraph_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2311 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2312 | const _CharT* __next = _VSTD::next(__s.__current_); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2313 | if (__next != __s.__last_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2314 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2315 | pair<_CharT, _CharT> __ch2(*__s.__current_, *__next); |
| 2316 | if (__icase_) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2317 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 2318 | __ch2.first = __traits_.translate_nocase(__ch2.first); |
| 2319 | __ch2.second = __traits_.translate_nocase(__ch2.second); |
| 2320 | } |
| 2321 | else if (__collate_) |
| 2322 | { |
| 2323 | __ch2.first = __traits_.translate(__ch2.first); |
| 2324 | __ch2.second = __traits_.translate(__ch2.second); |
| 2325 | } |
| 2326 | if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty()) |
| 2327 | { |
| 2328 | // __ch2 is a digraph in this locale |
| 2329 | ++__consumed; |
| 2330 | for (size_t __i = 0; __i < __digraphs_.size(); ++__i) |
| 2331 | { |
| 2332 | if (__ch2 == __digraphs_[__i]) |
| 2333 | { |
| 2334 | __found = true; |
| 2335 | goto __exit; |
| 2336 | } |
| 2337 | } |
| 2338 | if (__collate_ && !__ranges_.empty()) |
| 2339 | { |
| 2340 | string_type __s2 = __traits_.transform(&__ch2.first, |
| 2341 | &__ch2.first + 2); |
| 2342 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2343 | { |
| 2344 | if (__ranges_[__i].first <= __s2 && |
| 2345 | __s2 <= __ranges_[__i].second) |
| 2346 | { |
| 2347 | __found = true; |
| 2348 | goto __exit; |
| 2349 | } |
| 2350 | } |
| 2351 | } |
| 2352 | if (!__equivalences_.empty()) |
| 2353 | { |
| 2354 | string_type __s2 = __traits_.transform_primary(&__ch2.first, |
| 2355 | &__ch2.first + 2); |
| 2356 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2357 | { |
| 2358 | if (__s2 == __equivalences_[__i]) |
| 2359 | { |
| 2360 | __found = true; |
| 2361 | goto __exit; |
| 2362 | } |
| 2363 | } |
| 2364 | } |
| 2365 | if (__traits_.isctype(__ch2.first, __mask_) && |
| 2366 | __traits_.isctype(__ch2.second, __mask_)) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2367 | { |
| 2368 | __found = true; |
| 2369 | goto __exit; |
| 2370 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2371 | if (!__traits_.isctype(__ch2.first, __neg_mask_) && |
| 2372 | !__traits_.isctype(__ch2.second, __neg_mask_)) |
| 2373 | { |
| 2374 | __found = true; |
| 2375 | goto __exit; |
| 2376 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2377 | goto __exit; |
| 2378 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2379 | } |
| 2380 | } |
| 2381 | // test *__s.__current_ as not a digraph |
| 2382 | _CharT __ch = *__s.__current_; |
| 2383 | if (__icase_) |
| 2384 | __ch = __traits_.translate_nocase(__ch); |
| 2385 | else if (__collate_) |
| 2386 | __ch = __traits_.translate(__ch); |
| 2387 | for (size_t __i = 0; __i < __chars_.size(); ++__i) |
| 2388 | { |
| 2389 | if (__ch == __chars_[__i]) |
| 2390 | { |
| 2391 | __found = true; |
| 2392 | goto __exit; |
| 2393 | } |
| 2394 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2395 | if (!__neg_chars_.empty()) |
| 2396 | { |
| 2397 | for (size_t __i = 0; __i < __neg_chars_.size(); ++__i) |
| 2398 | { |
| 2399 | if (__ch == __neg_chars_[__i]) |
| 2400 | goto __is_neg_char; |
| 2401 | } |
| 2402 | __found = true; |
| 2403 | goto __exit; |
| 2404 | } |
| 2405 | __is_neg_char: |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2406 | if (!__ranges_.empty()) |
| 2407 | { |
| 2408 | string_type __s2 = __collate_ ? |
| 2409 | __traits_.transform(&__ch, &__ch + 1) : |
| 2410 | string_type(1, __ch); |
| 2411 | for (size_t __i = 0; __i < __ranges_.size(); ++__i) |
| 2412 | { |
| 2413 | if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) |
| 2414 | { |
| 2415 | __found = true; |
| 2416 | goto __exit; |
| 2417 | } |
| 2418 | } |
| 2419 | } |
| 2420 | if (!__equivalences_.empty()) |
| 2421 | { |
| 2422 | string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1); |
| 2423 | for (size_t __i = 0; __i < __equivalences_.size(); ++__i) |
| 2424 | { |
| 2425 | if (__s2 == __equivalences_[__i]) |
| 2426 | { |
| 2427 | __found = true; |
| 2428 | goto __exit; |
| 2429 | } |
| 2430 | } |
| 2431 | } |
| 2432 | if (__traits_.isctype(__ch, __mask_)) |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2433 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2434 | __found = true; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2435 | goto __exit; |
| 2436 | } |
| 2437 | if (__neg_mask_ && !__traits_.isctype(__ch, __neg_mask_)) |
| 2438 | { |
| 2439 | __found = true; |
| 2440 | goto __exit; |
| 2441 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2442 | } |
| 2443 | else |
| 2444 | __found = __negate_; // force reject |
| 2445 | __exit: |
| 2446 | if (__found != __negate_) |
| 2447 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2448 | __s.__do_ = __state::__accept_and_consume; |
| 2449 | __s.__current_ += __consumed; |
| 2450 | __s.__node_ = this->first(); |
| 2451 | } |
| 2452 | else |
| 2453 | { |
| 2454 | __s.__do_ = __state::__reject; |
| 2455 | __s.__node_ = nullptr; |
| 2456 | } |
| 2457 | } |
| 2458 | |
Howard Hinnant | 2b1b2d4 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 2459 | template <class _CharT, class _Traits> class __lookahead; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2460 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2461 | template <class _CharT, class _Traits = regex_traits<_CharT> > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 2462 | class _LIBCPP_TYPE_VIS_ONLY basic_regex |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2463 | { |
| 2464 | public: |
| 2465 | // types: |
| 2466 | typedef _CharT value_type; |
| 2467 | typedef regex_constants::syntax_option_type flag_type; |
| 2468 | typedef typename _Traits::locale_type locale_type; |
| 2469 | |
| 2470 | private: |
| 2471 | _Traits __traits_; |
| 2472 | flag_type __flags_; |
| 2473 | unsigned __marked_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2474 | unsigned __loop_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2475 | int __open_count_; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2476 | shared_ptr<__empty_state<_CharT> > __start_; |
| 2477 | __owns_one_state<_CharT>* __end_; |
| 2478 | |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2479 | typedef _VSTD::__state<_CharT> __state; |
| 2480 | typedef _VSTD::__node<_CharT> __node; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2481 | |
| 2482 | public: |
| 2483 | // constants: |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2484 | static const regex_constants::syntax_option_type icase = regex_constants::icase; |
| 2485 | static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs; |
| 2486 | static const regex_constants::syntax_option_type optimize = regex_constants::optimize; |
| 2487 | static const regex_constants::syntax_option_type collate = regex_constants::collate; |
| 2488 | static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript; |
| 2489 | static const regex_constants::syntax_option_type basic = regex_constants::basic; |
| 2490 | static const regex_constants::syntax_option_type extended = regex_constants::extended; |
| 2491 | static const regex_constants::syntax_option_type awk = regex_constants::awk; |
| 2492 | static const regex_constants::syntax_option_type grep = regex_constants::grep; |
| 2493 | static const regex_constants::syntax_option_type egrep = regex_constants::egrep; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2494 | |
| 2495 | // construct/copy/destroy: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2496 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2497 | basic_regex() |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2498 | : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2499 | __end_(0) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2500 | {} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2501 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2502 | explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2503 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2504 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2505 | {__parse(__p, __p + __traits_.length(__p));} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2506 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2507 | basic_regex(const value_type* __p, size_t __len, flag_type __f) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2508 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2509 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2510 | {__parse(__p, __p + __len);} |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2511 | // basic_regex(const basic_regex&) = default; |
| 2512 | // basic_regex(basic_regex&&) = default; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2513 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2514 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2515 | explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p, |
| 2516 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2517 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2518 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2519 | {__parse(__p.begin(), __p.end());} |
| 2520 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2521 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2522 | basic_regex(_ForwardIterator __first, _ForwardIterator __last, |
| 2523 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2524 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2525 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2526 | {__parse(__first, __last);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2527 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2528 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2529 | basic_regex(initializer_list<value_type> __il, |
| 2530 | flag_type __f = regex_constants::ECMAScript) |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2531 | : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2532 | __end_(0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2533 | {__parse(__il.begin(), __il.end());} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2534 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2535 | |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2536 | // ~basic_regex() = default; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2537 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2538 | // basic_regex& operator=(const basic_regex&) = default; |
| 2539 | // basic_regex& operator=(basic_regex&&) = default; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2540 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2541 | basic_regex& operator=(const value_type* __p) |
| 2542 | {return assign(__p);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2543 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2544 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2545 | basic_regex& operator=(initializer_list<value_type> __il) |
| 2546 | {return assign(__il);} |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2547 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2548 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2549 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2550 | basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) |
| 2551 | {return assign(__p);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2552 | |
| 2553 | // assign: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2554 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2555 | basic_regex& assign(const basic_regex& __that) |
| 2556 | {return *this = __that;} |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 2557 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 2558 | _LIBCPP_INLINE_VISIBILITY |
| 2559 | basic_regex& assign(basic_regex&& __that) _NOEXCEPT |
| 2560 | {return *this = _VSTD::move(__that);} |
| 2561 | #endif |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2562 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2563 | basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) |
| 2564 | {return assign(__p, __p + __traits_.length(__p), __f);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2565 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2566 | basic_regex& assign(const value_type* __p, size_t __len, flag_type __f) |
| 2567 | {return assign(__p, __p + __len, __f);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2568 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2569 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2570 | basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s, |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2571 | flag_type __f = regex_constants::ECMAScript) |
| 2572 | {return assign(__s.begin(), __s.end(), __f);} |
| 2573 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2574 | template <class _InputIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2575 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2576 | typename enable_if |
| 2577 | < |
| 2578 | __is_input_iterator <_InputIterator>::value && |
| 2579 | !__is_forward_iterator<_InputIterator>::value, |
| 2580 | basic_regex& |
| 2581 | >::type |
| 2582 | assign(_InputIterator __first, _InputIterator __last, |
| 2583 | flag_type __f = regex_constants::ECMAScript) |
| 2584 | { |
| 2585 | basic_string<_CharT> __t(__first, __last); |
| 2586 | return assign(__t.begin(), __t.end(), __f); |
| 2587 | } |
| 2588 | |
| 2589 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2590 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2591 | void __member_init(flag_type __f) |
| 2592 | { |
| 2593 | __flags_ = __f; |
| 2594 | __marked_count_ = 0; |
| 2595 | __loop_count_ = 0; |
| 2596 | __open_count_ = 0; |
| 2597 | __end_ = nullptr; |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2598 | } |
| 2599 | public: |
| 2600 | |
| 2601 | template <class _ForwardIterator> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2602 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2603 | typename enable_if |
| 2604 | < |
| 2605 | __is_forward_iterator<_ForwardIterator>::value, |
| 2606 | basic_regex& |
| 2607 | >::type |
| 2608 | assign(_ForwardIterator __first, _ForwardIterator __last, |
| 2609 | flag_type __f = regex_constants::ECMAScript) |
| 2610 | { |
Marshall Clow | 083e011 | 2015-01-13 16:49:52 +0000 | [diff] [blame] | 2611 | return assign(basic_regex(__first, __last, __f)); |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2612 | } |
| 2613 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2614 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2615 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2616 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2617 | basic_regex& assign(initializer_list<value_type> __il, |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2618 | flag_type __f = regex_constants::ECMAScript) |
| 2619 | {return assign(__il.begin(), __il.end(), __f);} |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2620 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 2621 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 2622 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2623 | // const operations: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2624 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2625 | unsigned mark_count() const {return __marked_count_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2626 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2627 | flag_type flags() const {return __flags_;} |
| 2628 | |
| 2629 | // locale: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2630 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2631 | locale_type imbue(locale_type __loc) |
| 2632 | { |
| 2633 | __member_init(ECMAScript); |
| 2634 | __start_.reset(); |
| 2635 | return __traits_.imbue(__loc); |
| 2636 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2637 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2638 | locale_type getloc() const {return __traits_.getloc();} |
| 2639 | |
| 2640 | // swap: |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2641 | void swap(basic_regex& __r); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2642 | |
| 2643 | private: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2644 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2645 | unsigned __loop_count() const {return __loop_count_;} |
| 2646 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2647 | template <class _ForwardIterator> |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2648 | _ForwardIterator |
| 2649 | __parse(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2650 | template <class _ForwardIterator> |
| 2651 | _ForwardIterator |
| 2652 | __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2653 | template <class _ForwardIterator> |
| 2654 | _ForwardIterator |
| 2655 | __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2656 | template <class _ForwardIterator> |
| 2657 | _ForwardIterator |
| 2658 | __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2659 | template <class _ForwardIterator> |
| 2660 | _ForwardIterator |
| 2661 | __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2662 | template <class _ForwardIterator> |
| 2663 | _ForwardIterator |
| 2664 | __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last); |
| 2665 | template <class _ForwardIterator> |
| 2666 | _ForwardIterator |
| 2667 | __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2668 | template <class _ForwardIterator> |
| 2669 | _ForwardIterator |
| 2670 | __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last); |
| 2671 | template <class _ForwardIterator> |
| 2672 | _ForwardIterator |
| 2673 | __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2674 | template <class _ForwardIterator> |
| 2675 | _ForwardIterator |
| 2676 | __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last); |
| 2677 | template <class _ForwardIterator> |
| 2678 | _ForwardIterator |
| 2679 | __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last); |
| 2680 | template <class _ForwardIterator> |
| 2681 | _ForwardIterator |
| 2682 | __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2683 | template <class _ForwardIterator> |
| 2684 | _ForwardIterator |
| 2685 | __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last); |
| 2686 | template <class _ForwardIterator> |
| 2687 | _ForwardIterator |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2688 | __parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2689 | __owns_one_state<_CharT>* __s, |
| 2690 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2691 | template <class _ForwardIterator> |
| 2692 | _ForwardIterator |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2693 | __parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2694 | __owns_one_state<_CharT>* __s, |
| 2695 | unsigned __mexp_begin, unsigned __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2696 | template <class _ForwardIterator> |
| 2697 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2698 | __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2699 | template <class _ForwardIterator> |
| 2700 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2701 | __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, |
| 2702 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2703 | template <class _ForwardIterator> |
| 2704 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2705 | __parse_expression_term(_ForwardIterator __first, _ForwardIterator __last, |
| 2706 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2707 | template <class _ForwardIterator> |
| 2708 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2709 | __parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2710 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2711 | template <class _ForwardIterator> |
| 2712 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2713 | __parse_character_class(_ForwardIterator __first, _ForwardIterator __last, |
| 2714 | __bracket_expression<_CharT, _Traits>* __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2715 | template <class _ForwardIterator> |
| 2716 | _ForwardIterator |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2717 | __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, |
| 2718 | basic_string<_CharT>& __col_sym); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 2719 | template <class _ForwardIterator> |
| 2720 | _ForwardIterator |
| 2721 | __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2722 | template <class _ForwardIterator> |
| 2723 | _ForwardIterator |
| 2724 | __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2725 | template <class _ForwardIterator> |
| 2726 | _ForwardIterator |
| 2727 | __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last); |
| 2728 | template <class _ForwardIterator> |
| 2729 | _ForwardIterator |
| 2730 | __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last); |
| 2731 | template <class _ForwardIterator> |
| 2732 | _ForwardIterator |
| 2733 | __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2734 | template <class _ForwardIterator> |
| 2735 | _ForwardIterator |
| 2736 | __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
| 2737 | template <class _ForwardIterator> |
| 2738 | _ForwardIterator |
| 2739 | __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2740 | template <class _ForwardIterator> |
| 2741 | _ForwardIterator |
| 2742 | __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last); |
| 2743 | template <class _ForwardIterator> |
| 2744 | _ForwardIterator |
| 2745 | __parse_alternative(_ForwardIterator __first, _ForwardIterator __last); |
| 2746 | template <class _ForwardIterator> |
| 2747 | _ForwardIterator |
| 2748 | __parse_term(_ForwardIterator __first, _ForwardIterator __last); |
| 2749 | template <class _ForwardIterator> |
| 2750 | _ForwardIterator |
| 2751 | __parse_assertion(_ForwardIterator __first, _ForwardIterator __last); |
| 2752 | template <class _ForwardIterator> |
| 2753 | _ForwardIterator |
| 2754 | __parse_atom(_ForwardIterator __first, _ForwardIterator __last); |
| 2755 | template <class _ForwardIterator> |
| 2756 | _ForwardIterator |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2757 | __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2758 | template <class _ForwardIterator> |
| 2759 | _ForwardIterator |
| 2760 | __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2761 | template <class _ForwardIterator> |
| 2762 | _ForwardIterator |
| 2763 | __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last); |
| 2764 | template <class _ForwardIterator> |
| 2765 | _ForwardIterator |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2766 | __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2767 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2768 | template <class _ForwardIterator> |
| 2769 | _ForwardIterator |
| 2770 | __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 2771 | template <class _ForwardIterator> |
| 2772 | _ForwardIterator |
| 2773 | __parse_grep(_ForwardIterator __first, _ForwardIterator __last); |
| 2774 | template <class _ForwardIterator> |
| 2775 | _ForwardIterator |
| 2776 | __parse_egrep(_ForwardIterator __first, _ForwardIterator __last); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 2777 | template <class _ForwardIterator> |
| 2778 | _ForwardIterator |
| 2779 | __parse_class_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2780 | basic_string<_CharT>& __str, |
| 2781 | __bracket_expression<_CharT, _Traits>* __ml); |
| 2782 | template <class _ForwardIterator> |
| 2783 | _ForwardIterator |
| 2784 | __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, |
| 2785 | basic_string<_CharT>* __str = nullptr); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2786 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2787 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2788 | void __push_l_anchor(); |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 2789 | void __push_r_anchor(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2790 | void __push_match_any(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2791 | void __push_match_any_but_newline(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2792 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 2793 | void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2794 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2795 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2796 | __mexp_begin, __mexp_end);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2797 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2798 | void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s, |
| 2799 | unsigned __mexp_begin = 0, unsigned __mexp_end = 0) |
| 2800 | {__push_loop(__min, numeric_limits<size_t>::max(), __s, |
| 2801 | __mexp_begin, __mexp_end, false);} |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2802 | void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s, |
| 2803 | size_t __mexp_begin = 0, size_t __mexp_end = 0, |
| 2804 | bool __greedy = true); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 2805 | __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 2806 | void __push_char(value_type __c); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 2807 | void __push_back_ref(int __i); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 2808 | void __push_alternation(__owns_one_state<_CharT>* __sa, |
| 2809 | __owns_one_state<_CharT>* __sb); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 2810 | void __push_begin_marked_subexpression(); |
| 2811 | void __push_end_marked_subexpression(unsigned); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 2812 | void __push_empty(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2813 | void __push_word_boundary(bool); |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2814 | void __push_lookahead(const basic_regex&, bool, unsigned); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2815 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2816 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2817 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2818 | __search(const _CharT* __first, const _CharT* __last, |
| 2819 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2820 | regex_constants::match_flag_type __flags) const; |
| 2821 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2822 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2823 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2824 | __match_at_start(const _CharT* __first, const _CharT* __last, |
| 2825 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2826 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2827 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2828 | bool |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 2829 | __match_at_start_ecma(const _CharT* __first, const _CharT* __last, |
| 2830 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2831 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2832 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2833 | bool |
| 2834 | __match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2835 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2836 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2837 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2838 | bool |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2839 | __match_at_start_posix_subs(const _CharT* __first, const _CharT* __last, |
| 2840 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2841 | regex_constants::match_flag_type __flags, bool) const; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2842 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2843 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2844 | friend |
| 2845 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2846 | regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 2847 | regex_constants::match_flag_type); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2848 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2849 | template <class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2850 | friend |
| 2851 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2852 | regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&, |
| 2853 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2854 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2855 | template <class _Bp, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2856 | friend |
| 2857 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2858 | regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2859 | regex_constants::match_flag_type); |
| 2860 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2861 | template <class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2862 | friend |
| 2863 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2864 | regex_search(const _Cp*, const _Cp*, |
| 2865 | const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2866 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2867 | template <class _Cp, class _Ap, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2868 | friend |
| 2869 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2870 | regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2871 | regex_constants::match_flag_type); |
| 2872 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2873 | template <class _ST, class _SA, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2874 | friend |
| 2875 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2876 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 2877 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2878 | regex_constants::match_flag_type __flags); |
| 2879 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2880 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2881 | friend |
| 2882 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2883 | regex_search(const basic_string<_Cp, _ST, _SA>& __s, |
| 2884 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 2885 | const basic_regex<_Cp, _Tp>& __e, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 2886 | regex_constants::match_flag_type __flags); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2887 | |
Howard Hinnant | a9602d5 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 2888 | template <class _Iter, class _Ap, class _Cp, class _Tp> |
| 2889 | friend |
| 2890 | bool |
| 2891 | regex_search(__wrap_iter<_Iter> __first, |
| 2892 | __wrap_iter<_Iter> __last, |
| 2893 | match_results<__wrap_iter<_Iter>, _Ap>& __m, |
| 2894 | const basic_regex<_Cp, _Tp>& __e, |
| 2895 | regex_constants::match_flag_type __flags); |
| 2896 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2897 | template <class, class> friend class __lookahead; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2898 | }; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2899 | |
| 2900 | template <class _CharT, class _Traits> |
Howard Hinnant | 0a69fa1 | 2012-12-12 21:14:28 +0000 | [diff] [blame] | 2901 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase; |
| 2902 | template <class _CharT, class _Traits> |
| 2903 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs; |
| 2904 | template <class _CharT, class _Traits> |
| 2905 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize; |
| 2906 | template <class _CharT, class _Traits> |
| 2907 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate; |
| 2908 | template <class _CharT, class _Traits> |
| 2909 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript; |
| 2910 | template <class _CharT, class _Traits> |
| 2911 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic; |
| 2912 | template <class _CharT, class _Traits> |
| 2913 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended; |
| 2914 | template <class _CharT, class _Traits> |
| 2915 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk; |
| 2916 | template <class _CharT, class _Traits> |
| 2917 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep; |
| 2918 | template <class _CharT, class _Traits> |
| 2919 | const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep; |
| 2920 | |
| 2921 | template <class _CharT, class _Traits> |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2922 | void |
| 2923 | basic_regex<_CharT, _Traits>::swap(basic_regex& __r) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2924 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2925 | using _VSTD::swap; |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2926 | swap(__traits_, __r.__traits_); |
| 2927 | swap(__flags_, __r.__flags_); |
| 2928 | swap(__marked_count_, __r.__marked_count_); |
| 2929 | swap(__loop_count_, __r.__loop_count_); |
| 2930 | swap(__open_count_, __r.__open_count_); |
| 2931 | swap(__start_, __r.__start_); |
| 2932 | swap(__end_, __r.__end_); |
Howard Hinnant | 7026a17 | 2010-08-13 18:11:23 +0000 | [diff] [blame] | 2933 | } |
| 2934 | |
| 2935 | template <class _CharT, class _Traits> |
| 2936 | inline _LIBCPP_INLINE_VISIBILITY |
| 2937 | void |
| 2938 | swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) |
| 2939 | { |
| 2940 | return __x.swap(__y); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2941 | } |
| 2942 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2943 | // __lookahead |
| 2944 | |
| 2945 | template <class _CharT, class _Traits> |
| 2946 | class __lookahead |
| 2947 | : public __owns_one_state<_CharT> |
| 2948 | { |
| 2949 | typedef __owns_one_state<_CharT> base; |
| 2950 | |
| 2951 | basic_regex<_CharT, _Traits> __exp_; |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2952 | unsigned __mexp_; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2953 | bool __invert_; |
| 2954 | |
| 2955 | __lookahead(const __lookahead&); |
| 2956 | __lookahead& operator=(const __lookahead&); |
| 2957 | public: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2958 | typedef _VSTD::__state<_CharT> __state; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2959 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 2960 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2961 | __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp) |
Eric Fiselier | 7cc7106 | 2015-07-22 01:29:41 +0000 | [diff] [blame] | 2962 | : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {} |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2963 | |
| 2964 | virtual void __exec(__state&) const; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2965 | }; |
| 2966 | |
| 2967 | template <class _CharT, class _Traits> |
| 2968 | void |
| 2969 | __lookahead<_CharT, _Traits>::__exec(__state& __s) const |
| 2970 | { |
| 2971 | match_results<const _CharT*> __m; |
| 2972 | __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_); |
| 2973 | bool __matched = __exp_.__match_at_start_ecma(__s.__current_, __s.__last_, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 2974 | __m, |
| 2975 | __s.__flags_ | regex_constants::match_continuous, |
Howard Hinnant | e57b7c4 | 2013-06-28 19:11:23 +0000 | [diff] [blame] | 2976 | __s.__at_first_ && __s.__current_ == __s.__first_); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2977 | if (__matched != __invert_) |
| 2978 | { |
| 2979 | __s.__do_ = __state::__accept_but_not_consume; |
| 2980 | __s.__node_ = this->first(); |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 2981 | for (unsigned __i = 1; __i < __m.size(); ++__i) { |
| 2982 | __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i]; |
| 2983 | } |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2984 | } |
| 2985 | else |
| 2986 | { |
| 2987 | __s.__do_ = __state::__reject; |
| 2988 | __s.__node_ = nullptr; |
| 2989 | } |
| 2990 | } |
| 2991 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2992 | template <class _CharT, class _Traits> |
| 2993 | template <class _ForwardIterator> |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 2994 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 2995 | basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, |
| 2996 | _ForwardIterator __last) |
| 2997 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 2998 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 2999 | unique_ptr<__node> __h(new __end_state<_CharT>); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3000 | __start_.reset(new __empty_state<_CharT>(__h.get())); |
| 3001 | __h.release(); |
| 3002 | __end_ = __start_.get(); |
| 3003 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 3004 | switch (__flags_ & 0x1F0) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3005 | { |
| 3006 | case ECMAScript: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3007 | __first = __parse_ecma_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3008 | break; |
| 3009 | case basic: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3010 | __first = __parse_basic_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3011 | break; |
| 3012 | case extended: |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3013 | case awk: |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3014 | __first = __parse_extended_reg_exp(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3015 | break; |
| 3016 | case grep: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3017 | __first = __parse_grep(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3018 | break; |
| 3019 | case egrep: |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3020 | __first = __parse_egrep(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3021 | break; |
| 3022 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3023 | __throw_regex_error<regex_constants::__re_err_grammar>(); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3024 | } |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 3025 | return __first; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3026 | } |
| 3027 | |
| 3028 | template <class _CharT, class _Traits> |
| 3029 | template <class _ForwardIterator> |
| 3030 | _ForwardIterator |
| 3031 | basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, |
| 3032 | _ForwardIterator __last) |
| 3033 | { |
| 3034 | if (__first != __last) |
| 3035 | { |
| 3036 | if (*__first == '^') |
| 3037 | { |
| 3038 | __push_l_anchor(); |
| 3039 | ++__first; |
| 3040 | } |
| 3041 | if (__first != __last) |
| 3042 | { |
| 3043 | __first = __parse_RE_expression(__first, __last); |
| 3044 | if (__first != __last) |
| 3045 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3046 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3047 | if (__temp == __last && *__first == '$') |
| 3048 | { |
| 3049 | __push_r_anchor(); |
| 3050 | ++__first; |
| 3051 | } |
| 3052 | } |
| 3053 | } |
| 3054 | if (__first != __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3055 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3056 | } |
| 3057 | return __first; |
| 3058 | } |
| 3059 | |
| 3060 | template <class _CharT, class _Traits> |
| 3061 | template <class _ForwardIterator> |
| 3062 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3063 | basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, |
| 3064 | _ForwardIterator __last) |
| 3065 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3066 | __owns_one_state<_CharT>* __sa = __end_; |
| 3067 | _ForwardIterator __temp = __parse_ERE_branch(__first, __last); |
| 3068 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3069 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3070 | __first = __temp; |
| 3071 | while (__first != __last && *__first == '|') |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3072 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3073 | __owns_one_state<_CharT>* __sb = __end_; |
| 3074 | __temp = __parse_ERE_branch(++__first, __last); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3075 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3076 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3077 | __push_alternation(__sa, __sb); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3078 | __first = __temp; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3079 | } |
| 3080 | return __first; |
| 3081 | } |
| 3082 | |
| 3083 | template <class _CharT, class _Traits> |
| 3084 | template <class _ForwardIterator> |
| 3085 | _ForwardIterator |
| 3086 | basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, |
| 3087 | _ForwardIterator __last) |
| 3088 | { |
| 3089 | _ForwardIterator __temp = __parse_ERE_expression(__first, __last); |
| 3090 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3091 | __throw_regex_error<regex_constants::__re_err_empty>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3092 | do |
| 3093 | { |
| 3094 | __first = __temp; |
| 3095 | __temp = __parse_ERE_expression(__first, __last); |
| 3096 | } while (__temp != __first); |
| 3097 | return __first; |
| 3098 | } |
| 3099 | |
| 3100 | template <class _CharT, class _Traits> |
| 3101 | template <class _ForwardIterator> |
| 3102 | _ForwardIterator |
| 3103 | basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, |
| 3104 | _ForwardIterator __last) |
| 3105 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3106 | __owns_one_state<_CharT>* __e = __end_; |
| 3107 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3108 | _ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last); |
| 3109 | if (__temp == __first && __temp != __last) |
| 3110 | { |
| 3111 | switch (*__temp) |
| 3112 | { |
| 3113 | case '^': |
| 3114 | __push_l_anchor(); |
| 3115 | ++__temp; |
| 3116 | break; |
| 3117 | case '$': |
| 3118 | __push_r_anchor(); |
| 3119 | ++__temp; |
| 3120 | break; |
| 3121 | case '(': |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3122 | __push_begin_marked_subexpression(); |
| 3123 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3124 | ++__open_count_; |
| 3125 | __temp = __parse_extended_reg_exp(++__temp, __last); |
| 3126 | if (__temp == __last || *__temp != ')') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3127 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3128 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3129 | --__open_count_; |
| 3130 | ++__temp; |
| 3131 | break; |
| 3132 | } |
| 3133 | } |
| 3134 | if (__temp != __first) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3135 | __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1, |
| 3136 | __marked_count_+1); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3137 | __first = __temp; |
| 3138 | return __first; |
| 3139 | } |
| 3140 | |
| 3141 | template <class _CharT, class _Traits> |
| 3142 | template <class _ForwardIterator> |
| 3143 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3144 | basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, |
| 3145 | _ForwardIterator __last) |
| 3146 | { |
| 3147 | while (true) |
| 3148 | { |
| 3149 | _ForwardIterator __temp = __parse_simple_RE(__first, __last); |
| 3150 | if (__temp == __first) |
| 3151 | break; |
| 3152 | __first = __temp; |
| 3153 | } |
| 3154 | return __first; |
| 3155 | } |
| 3156 | |
| 3157 | template <class _CharT, class _Traits> |
| 3158 | template <class _ForwardIterator> |
| 3159 | _ForwardIterator |
| 3160 | basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, |
| 3161 | _ForwardIterator __last) |
| 3162 | { |
| 3163 | if (__first != __last) |
| 3164 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3165 | __owns_one_state<_CharT>* __e = __end_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3166 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3167 | _ForwardIterator __temp = __parse_nondupl_RE(__first, __last); |
| 3168 | if (__temp != __first) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3169 | __first = __parse_RE_dupl_symbol(__temp, __last, __e, |
| 3170 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3171 | } |
| 3172 | return __first; |
| 3173 | } |
| 3174 | |
| 3175 | template <class _CharT, class _Traits> |
| 3176 | template <class _ForwardIterator> |
| 3177 | _ForwardIterator |
| 3178 | basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, |
| 3179 | _ForwardIterator __last) |
| 3180 | { |
| 3181 | _ForwardIterator __temp = __first; |
| 3182 | __first = __parse_one_char_or_coll_elem_RE(__first, __last); |
| 3183 | if (__temp == __first) |
| 3184 | { |
| 3185 | __temp = __parse_Back_open_paren(__first, __last); |
| 3186 | if (__temp != __first) |
| 3187 | { |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3188 | __push_begin_marked_subexpression(); |
| 3189 | unsigned __temp_count = __marked_count_; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3190 | __first = __parse_RE_expression(__temp, __last); |
| 3191 | __temp = __parse_Back_close_paren(__first, __last); |
| 3192 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3193 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 3194 | __push_end_marked_subexpression(__temp_count); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3195 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3196 | } |
| 3197 | else |
| 3198 | __first = __parse_BACKREF(__first, __last); |
| 3199 | } |
| 3200 | return __first; |
| 3201 | } |
| 3202 | |
| 3203 | template <class _CharT, class _Traits> |
| 3204 | template <class _ForwardIterator> |
| 3205 | _ForwardIterator |
| 3206 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE( |
| 3207 | _ForwardIterator __first, |
| 3208 | _ForwardIterator __last) |
| 3209 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3210 | _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3211 | if (__temp == __first) |
| 3212 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3213 | __temp = __parse_QUOTED_CHAR(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3214 | if (__temp == __first) |
| 3215 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3216 | if (__temp != __last && *__temp == '.') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3217 | { |
| 3218 | __push_match_any(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3219 | ++__temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3220 | } |
| 3221 | else |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3222 | __temp = __parse_bracket_expression(__first, __last); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3223 | } |
| 3224 | } |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3225 | __first = __temp; |
| 3226 | return __first; |
| 3227 | } |
| 3228 | |
| 3229 | template <class _CharT, class _Traits> |
| 3230 | template <class _ForwardIterator> |
| 3231 | _ForwardIterator |
| 3232 | basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE( |
| 3233 | _ForwardIterator __first, |
| 3234 | _ForwardIterator __last) |
| 3235 | { |
| 3236 | _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last); |
| 3237 | if (__temp == __first) |
| 3238 | { |
| 3239 | __temp = __parse_QUOTED_CHAR_ERE(__first, __last); |
| 3240 | if (__temp == __first) |
| 3241 | { |
| 3242 | if (__temp != __last && *__temp == '.') |
| 3243 | { |
| 3244 | __push_match_any(); |
| 3245 | ++__temp; |
| 3246 | } |
| 3247 | else |
| 3248 | __temp = __parse_bracket_expression(__first, __last); |
| 3249 | } |
| 3250 | } |
| 3251 | __first = __temp; |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3252 | return __first; |
| 3253 | } |
| 3254 | |
| 3255 | template <class _CharT, class _Traits> |
| 3256 | template <class _ForwardIterator> |
| 3257 | _ForwardIterator |
| 3258 | basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, |
| 3259 | _ForwardIterator __last) |
| 3260 | { |
| 3261 | if (__first != __last) |
| 3262 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3263 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3264 | if (__temp != __last) |
| 3265 | { |
| 3266 | if (*__first == '\\' && *__temp == '(') |
| 3267 | __first = ++__temp; |
| 3268 | } |
| 3269 | } |
| 3270 | return __first; |
| 3271 | } |
| 3272 | |
| 3273 | template <class _CharT, class _Traits> |
| 3274 | template <class _ForwardIterator> |
| 3275 | _ForwardIterator |
| 3276 | basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, |
| 3277 | _ForwardIterator __last) |
| 3278 | { |
| 3279 | if (__first != __last) |
| 3280 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3281 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3282 | if (__temp != __last) |
| 3283 | { |
| 3284 | if (*__first == '\\' && *__temp == ')') |
| 3285 | __first = ++__temp; |
| 3286 | } |
| 3287 | } |
| 3288 | return __first; |
| 3289 | } |
| 3290 | |
| 3291 | template <class _CharT, class _Traits> |
| 3292 | template <class _ForwardIterator> |
| 3293 | _ForwardIterator |
| 3294 | basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, |
| 3295 | _ForwardIterator __last) |
| 3296 | { |
| 3297 | if (__first != __last) |
| 3298 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3299 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3300 | if (__temp != __last) |
| 3301 | { |
| 3302 | if (*__first == '\\' && *__temp == '{') |
| 3303 | __first = ++__temp; |
| 3304 | } |
| 3305 | } |
| 3306 | return __first; |
| 3307 | } |
| 3308 | |
| 3309 | template <class _CharT, class _Traits> |
| 3310 | template <class _ForwardIterator> |
| 3311 | _ForwardIterator |
| 3312 | basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, |
| 3313 | _ForwardIterator __last) |
| 3314 | { |
| 3315 | if (__first != __last) |
| 3316 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3317 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3318 | if (__temp != __last) |
| 3319 | { |
| 3320 | if (*__first == '\\' && *__temp == '}') |
| 3321 | __first = ++__temp; |
| 3322 | } |
| 3323 | } |
| 3324 | return __first; |
| 3325 | } |
| 3326 | |
| 3327 | template <class _CharT, class _Traits> |
| 3328 | template <class _ForwardIterator> |
| 3329 | _ForwardIterator |
| 3330 | basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, |
| 3331 | _ForwardIterator __last) |
| 3332 | { |
| 3333 | if (__first != __last) |
| 3334 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3335 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3336 | if (__temp != __last) |
| 3337 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 3338 | if (*__first == '\\') |
| 3339 | { |
| 3340 | int __val = __traits_.value(*__temp, 10); |
| 3341 | if (__val >= 1 && __val <= 9) |
| 3342 | { |
| 3343 | __push_back_ref(__val); |
| 3344 | __first = ++__temp; |
| 3345 | } |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3346 | } |
| 3347 | } |
| 3348 | } |
| 3349 | return __first; |
| 3350 | } |
| 3351 | |
| 3352 | template <class _CharT, class _Traits> |
| 3353 | template <class _ForwardIterator> |
| 3354 | _ForwardIterator |
| 3355 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, |
| 3356 | _ForwardIterator __last) |
| 3357 | { |
| 3358 | if (__first != __last) |
| 3359 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3360 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3361 | if (__temp == __last && *__first == '$') |
| 3362 | return __first; |
| 3363 | // Not called inside a bracket |
| 3364 | if (*__first == '.' || *__first == '\\' || *__first == '[') |
| 3365 | return __first; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3366 | __push_char(*__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3367 | ++__first; |
| 3368 | } |
| 3369 | return __first; |
| 3370 | } |
| 3371 | |
| 3372 | template <class _CharT, class _Traits> |
| 3373 | template <class _ForwardIterator> |
| 3374 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3375 | basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, |
| 3376 | _ForwardIterator __last) |
| 3377 | { |
| 3378 | if (__first != __last) |
| 3379 | { |
| 3380 | switch (*__first) |
| 3381 | { |
| 3382 | case '^': |
| 3383 | case '.': |
| 3384 | case '[': |
| 3385 | case '$': |
| 3386 | case '(': |
| 3387 | case '|': |
| 3388 | case '*': |
| 3389 | case '+': |
| 3390 | case '?': |
| 3391 | case '{': |
| 3392 | case '\\': |
| 3393 | break; |
| 3394 | case ')': |
| 3395 | if (__open_count_ == 0) |
| 3396 | { |
| 3397 | __push_char(*__first); |
| 3398 | ++__first; |
| 3399 | } |
| 3400 | break; |
| 3401 | default: |
| 3402 | __push_char(*__first); |
| 3403 | ++__first; |
| 3404 | break; |
| 3405 | } |
| 3406 | } |
| 3407 | return __first; |
| 3408 | } |
| 3409 | |
| 3410 | template <class _CharT, class _Traits> |
| 3411 | template <class _ForwardIterator> |
| 3412 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3413 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, |
| 3414 | _ForwardIterator __last) |
| 3415 | { |
| 3416 | if (__first != __last) |
| 3417 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3418 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3419 | if (__temp != __last) |
| 3420 | { |
| 3421 | if (*__first == '\\') |
| 3422 | { |
| 3423 | switch (*__temp) |
| 3424 | { |
| 3425 | case '^': |
| 3426 | case '.': |
| 3427 | case '*': |
| 3428 | case '[': |
| 3429 | case '$': |
| 3430 | case '\\': |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3431 | __push_char(*__temp); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3432 | __first = ++__temp; |
| 3433 | break; |
| 3434 | } |
| 3435 | } |
| 3436 | } |
| 3437 | } |
| 3438 | return __first; |
| 3439 | } |
| 3440 | |
| 3441 | template <class _CharT, class _Traits> |
| 3442 | template <class _ForwardIterator> |
| 3443 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3444 | basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, |
| 3445 | _ForwardIterator __last) |
| 3446 | { |
| 3447 | if (__first != __last) |
| 3448 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3449 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3450 | if (__temp != __last) |
| 3451 | { |
| 3452 | if (*__first == '\\') |
| 3453 | { |
| 3454 | switch (*__temp) |
| 3455 | { |
| 3456 | case '^': |
| 3457 | case '.': |
| 3458 | case '*': |
| 3459 | case '[': |
| 3460 | case '$': |
| 3461 | case '\\': |
| 3462 | case '(': |
| 3463 | case ')': |
| 3464 | case '|': |
| 3465 | case '+': |
| 3466 | case '?': |
| 3467 | case '{': |
Howard Hinnant | c1ecd97 | 2013-06-28 20:31:05 +0000 | [diff] [blame] | 3468 | case '}': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3469 | __push_char(*__temp); |
| 3470 | __first = ++__temp; |
| 3471 | break; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3472 | default: |
| 3473 | if ((__flags_ & 0x1F0) == awk) |
| 3474 | __first = __parse_awk_escape(++__first, __last); |
| 3475 | break; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3476 | } |
| 3477 | } |
| 3478 | } |
| 3479 | } |
| 3480 | return __first; |
| 3481 | } |
| 3482 | |
| 3483 | template <class _CharT, class _Traits> |
| 3484 | template <class _ForwardIterator> |
| 3485 | _ForwardIterator |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3486 | basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 3487 | _ForwardIterator __last, |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3488 | __owns_one_state<_CharT>* __s, |
| 3489 | unsigned __mexp_begin, |
| 3490 | unsigned __mexp_end) |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3491 | { |
| 3492 | if (__first != __last) |
| 3493 | { |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3494 | if (*__first == '*') |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3495 | { |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 3496 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3497 | ++__first; |
| 3498 | } |
| 3499 | else |
| 3500 | { |
| 3501 | _ForwardIterator __temp = __parse_Back_open_brace(__first, __last); |
| 3502 | if (__temp != __first) |
| 3503 | { |
| 3504 | int __min = 0; |
| 3505 | __first = __temp; |
| 3506 | __temp = __parse_DUP_COUNT(__first, __last, __min); |
| 3507 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3508 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3509 | __first = __temp; |
| 3510 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3511 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3512 | if (*__first != ',') |
| 3513 | { |
| 3514 | __temp = __parse_Back_close_brace(__first, __last); |
| 3515 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3516 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3517 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, |
| 3518 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3519 | __first = __temp; |
| 3520 | } |
| 3521 | else |
| 3522 | { |
| 3523 | ++__first; // consume ',' |
| 3524 | int __max = -1; |
| 3525 | __first = __parse_DUP_COUNT(__first, __last, __max); |
| 3526 | __temp = __parse_Back_close_brace(__first, __last); |
| 3527 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3528 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3529 | if (__max == -1) |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3530 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3531 | else |
| 3532 | { |
| 3533 | if (__max < __min) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3534 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 3535 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, |
| 3536 | true); |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 3537 | } |
| 3538 | __first = __temp; |
| 3539 | } |
| 3540 | } |
| 3541 | } |
| 3542 | } |
| 3543 | return __first; |
| 3544 | } |
| 3545 | |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3546 | template <class _CharT, class _Traits> |
| 3547 | template <class _ForwardIterator> |
| 3548 | _ForwardIterator |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3549 | basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3550 | _ForwardIterator __last, |
| 3551 | __owns_one_state<_CharT>* __s, |
| 3552 | unsigned __mexp_begin, |
| 3553 | unsigned __mexp_end) |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3554 | { |
| 3555 | if (__first != __last) |
| 3556 | { |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3557 | unsigned __grammar = __flags_ & 0x1F0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3558 | switch (*__first) |
| 3559 | { |
| 3560 | case '*': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3561 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3562 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3563 | { |
| 3564 | ++__first; |
| 3565 | __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
| 3566 | } |
| 3567 | else |
| 3568 | __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3569 | break; |
| 3570 | case '+': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3571 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3572 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3573 | { |
| 3574 | ++__first; |
| 3575 | __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
| 3576 | } |
| 3577 | else |
| 3578 | __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3579 | break; |
| 3580 | case '?': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3581 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3582 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3583 | { |
| 3584 | ++__first; |
| 3585 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false); |
| 3586 | } |
| 3587 | else |
| 3588 | __push_loop(0, 1, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3589 | break; |
| 3590 | case '{': |
| 3591 | { |
| 3592 | int __min; |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3593 | _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3594 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3595 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3596 | __first = __temp; |
| 3597 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3598 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3599 | switch (*__first) |
| 3600 | { |
| 3601 | case '}': |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3602 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3603 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3604 | { |
| 3605 | ++__first; |
| 3606 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false); |
| 3607 | } |
| 3608 | else |
| 3609 | __push_loop(__min, __min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3610 | break; |
| 3611 | case ',': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3612 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3613 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3614 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3615 | if (*__first == '}') |
| 3616 | { |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3617 | ++__first; |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3618 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3619 | { |
| 3620 | ++__first; |
| 3621 | __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
| 3622 | } |
| 3623 | else |
| 3624 | __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3625 | } |
| 3626 | else |
| 3627 | { |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3628 | int __max = -1; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3629 | __temp = __parse_DUP_COUNT(__first, __last, __max); |
| 3630 | if (__temp == __first) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3631 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3632 | __first = __temp; |
| 3633 | if (__first == __last || *__first != '}') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3634 | __throw_regex_error<regex_constants::error_brace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3635 | ++__first; |
| 3636 | if (__max < __min) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3637 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | a0d045b | 2010-07-29 00:36:00 +0000 | [diff] [blame] | 3638 | if (__grammar == ECMAScript && __first != __last && *__first == '?') |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 3639 | { |
| 3640 | ++__first; |
| 3641 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false); |
| 3642 | } |
| 3643 | else |
| 3644 | __push_loop(__min, __max, __s, __mexp_begin, __mexp_end); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3645 | } |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 3646 | break; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3647 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3648 | __throw_regex_error<regex_constants::error_badbrace>(); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 3649 | } |
| 3650 | } |
| 3651 | break; |
| 3652 | } |
| 3653 | } |
| 3654 | return __first; |
| 3655 | } |
| 3656 | |
| 3657 | template <class _CharT, class _Traits> |
| 3658 | template <class _ForwardIterator> |
| 3659 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3660 | basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, |
| 3661 | _ForwardIterator __last) |
| 3662 | { |
| 3663 | if (__first != __last && *__first == '[') |
| 3664 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3665 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 3666 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3667 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3668 | bool __negate = false; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3669 | if (*__first == '^') |
| 3670 | { |
| 3671 | ++__first; |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3672 | __negate = true; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3673 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3674 | __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate); |
| 3675 | // __ml owned by *this |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3676 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3677 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3678 | if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']') |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3679 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3680 | __ml->__add_char(']'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3681 | ++__first; |
| 3682 | } |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3683 | __first = __parse_follow_list(__first, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3684 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3685 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3686 | if (*__first == '-') |
| 3687 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3688 | __ml->__add_char('-'); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3689 | ++__first; |
| 3690 | } |
| 3691 | if (__first == __last || *__first != ']') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3692 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3693 | ++__first; |
| 3694 | } |
| 3695 | return __first; |
| 3696 | } |
| 3697 | |
| 3698 | template <class _CharT, class _Traits> |
| 3699 | template <class _ForwardIterator> |
| 3700 | _ForwardIterator |
| 3701 | basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3702 | _ForwardIterator __last, |
| 3703 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3704 | { |
| 3705 | if (__first != __last) |
| 3706 | { |
| 3707 | while (true) |
| 3708 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3709 | _ForwardIterator __temp = __parse_expression_term(__first, __last, |
| 3710 | __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3711 | if (__temp == __first) |
| 3712 | break; |
| 3713 | __first = __temp; |
| 3714 | } |
| 3715 | } |
| 3716 | return __first; |
| 3717 | } |
| 3718 | |
| 3719 | template <class _CharT, class _Traits> |
| 3720 | template <class _ForwardIterator> |
| 3721 | _ForwardIterator |
| 3722 | basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3723 | _ForwardIterator __last, |
| 3724 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3725 | { |
| 3726 | if (__first != __last && *__first != ']') |
| 3727 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3728 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3729 | basic_string<_CharT> __start_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3730 | if (__temp != __last && *__first == '[') |
| 3731 | { |
| 3732 | if (*__temp == '=') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3733 | return __parse_equivalence_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3734 | else if (*__temp == ':') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3735 | return __parse_character_class(++__temp, __last, __ml); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3736 | else if (*__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3737 | __first = __parse_collating_symbol(++__temp, __last, __start_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3738 | } |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3739 | unsigned __grammar = __flags_ & 0x1F0; |
| 3740 | if (__start_range.empty()) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3741 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3742 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3743 | { |
| 3744 | if (__grammar == ECMAScript) |
| 3745 | __first = __parse_class_escape(++__first, __last, __start_range, __ml); |
| 3746 | else |
| 3747 | __first = __parse_awk_escape(++__first, __last, &__start_range); |
| 3748 | } |
| 3749 | else |
| 3750 | { |
| 3751 | __start_range = *__first; |
| 3752 | ++__first; |
| 3753 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3754 | } |
| 3755 | if (__first != __last && *__first != ']') |
| 3756 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3757 | __temp = _VSTD::next(__first); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3758 | if (__temp != __last && *__first == '-' && *__temp != ']') |
| 3759 | { |
| 3760 | // parse a range |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3761 | basic_string<_CharT> __end_range; |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3762 | __first = __temp; |
| 3763 | ++__temp; |
| 3764 | if (__temp != __last && *__first == '[' && *__temp == '.') |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3765 | __first = __parse_collating_symbol(++__temp, __last, __end_range); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3766 | else |
| 3767 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3768 | if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') |
| 3769 | { |
| 3770 | if (__grammar == ECMAScript) |
| 3771 | __first = __parse_class_escape(++__first, __last, |
| 3772 | __end_range, __ml); |
| 3773 | else |
| 3774 | __first = __parse_awk_escape(++__first, __last, |
| 3775 | &__end_range); |
| 3776 | } |
| 3777 | else |
| 3778 | { |
| 3779 | __end_range = *__first; |
| 3780 | ++__first; |
| 3781 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3782 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3783 | __ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range)); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3784 | } |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3785 | else if (!__start_range.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3786 | { |
| 3787 | if (__start_range.size() == 1) |
| 3788 | __ml->__add_char(__start_range[0]); |
| 3789 | else |
| 3790 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
| 3791 | } |
| 3792 | } |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 3793 | else if (!__start_range.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3794 | { |
| 3795 | if (__start_range.size() == 1) |
| 3796 | __ml->__add_char(__start_range[0]); |
| 3797 | else |
| 3798 | __ml->__add_digraph(__start_range[0], __start_range[1]); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3799 | } |
| 3800 | } |
| 3801 | return __first; |
| 3802 | } |
| 3803 | |
| 3804 | template <class _CharT, class _Traits> |
| 3805 | template <class _ForwardIterator> |
| 3806 | _ForwardIterator |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3807 | basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first, |
| 3808 | _ForwardIterator __last, |
| 3809 | basic_string<_CharT>& __str, |
| 3810 | __bracket_expression<_CharT, _Traits>* __ml) |
| 3811 | { |
| 3812 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3813 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3814 | switch (*__first) |
| 3815 | { |
| 3816 | case 0: |
| 3817 | __str = *__first; |
| 3818 | return ++__first; |
| 3819 | case 'b': |
| 3820 | __str = _CharT(8); |
| 3821 | return ++__first; |
| 3822 | case 'd': |
| 3823 | __ml->__add_class(ctype_base::digit); |
| 3824 | return ++__first; |
| 3825 | case 'D': |
| 3826 | __ml->__add_neg_class(ctype_base::digit); |
| 3827 | return ++__first; |
| 3828 | case 's': |
| 3829 | __ml->__add_class(ctype_base::space); |
| 3830 | return ++__first; |
| 3831 | case 'S': |
| 3832 | __ml->__add_neg_class(ctype_base::space); |
| 3833 | return ++__first; |
| 3834 | case 'w': |
| 3835 | __ml->__add_class(ctype_base::alnum); |
| 3836 | __ml->__add_char('_'); |
| 3837 | return ++__first; |
| 3838 | case 'W': |
| 3839 | __ml->__add_neg_class(ctype_base::alnum); |
| 3840 | __ml->__add_neg_char('_'); |
| 3841 | return ++__first; |
| 3842 | } |
| 3843 | __first = __parse_character_escape(__first, __last, &__str); |
| 3844 | return __first; |
| 3845 | } |
| 3846 | |
| 3847 | template <class _CharT, class _Traits> |
| 3848 | template <class _ForwardIterator> |
| 3849 | _ForwardIterator |
| 3850 | basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first, |
| 3851 | _ForwardIterator __last, |
| 3852 | basic_string<_CharT>* __str) |
| 3853 | { |
| 3854 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3855 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3856 | switch (*__first) |
| 3857 | { |
| 3858 | case '\\': |
| 3859 | case '"': |
| 3860 | case '/': |
| 3861 | if (__str) |
| 3862 | *__str = *__first; |
| 3863 | else |
| 3864 | __push_char(*__first); |
| 3865 | return ++__first; |
| 3866 | case 'a': |
| 3867 | if (__str) |
| 3868 | *__str = _CharT(7); |
| 3869 | else |
| 3870 | __push_char(_CharT(7)); |
| 3871 | return ++__first; |
| 3872 | case 'b': |
| 3873 | if (__str) |
| 3874 | *__str = _CharT(8); |
| 3875 | else |
| 3876 | __push_char(_CharT(8)); |
| 3877 | return ++__first; |
| 3878 | case 'f': |
| 3879 | if (__str) |
| 3880 | *__str = _CharT(0xC); |
| 3881 | else |
| 3882 | __push_char(_CharT(0xC)); |
| 3883 | return ++__first; |
| 3884 | case 'n': |
| 3885 | if (__str) |
| 3886 | *__str = _CharT(0xA); |
| 3887 | else |
| 3888 | __push_char(_CharT(0xA)); |
| 3889 | return ++__first; |
| 3890 | case 'r': |
| 3891 | if (__str) |
| 3892 | *__str = _CharT(0xD); |
| 3893 | else |
| 3894 | __push_char(_CharT(0xD)); |
| 3895 | return ++__first; |
| 3896 | case 't': |
| 3897 | if (__str) |
| 3898 | *__str = _CharT(0x9); |
| 3899 | else |
| 3900 | __push_char(_CharT(0x9)); |
| 3901 | return ++__first; |
| 3902 | case 'v': |
| 3903 | if (__str) |
| 3904 | *__str = _CharT(0xB); |
| 3905 | else |
| 3906 | __push_char(_CharT(0xB)); |
| 3907 | return ++__first; |
| 3908 | } |
| 3909 | if ('0' <= *__first && *__first <= '7') |
| 3910 | { |
| 3911 | unsigned __val = *__first - '0'; |
| 3912 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
| 3913 | { |
| 3914 | __val = 8 * __val + *__first - '0'; |
| 3915 | if (++__first != __last && ('0' <= *__first && *__first <= '7')) |
Howard Hinnant | dbc8cf0 | 2013-07-02 17:43:31 +0000 | [diff] [blame] | 3916 | __val = 8 * __val + *__first++ - '0'; |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3917 | } |
| 3918 | if (__str) |
| 3919 | *__str = _CharT(__val); |
| 3920 | else |
| 3921 | __push_char(_CharT(__val)); |
| 3922 | } |
| 3923 | else |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3924 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 3925 | return __first; |
| 3926 | } |
| 3927 | |
| 3928 | template <class _CharT, class _Traits> |
| 3929 | template <class _ForwardIterator> |
| 3930 | _ForwardIterator |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3931 | basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3932 | _ForwardIterator __last, |
| 3933 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3934 | { |
| 3935 | // Found [= |
| 3936 | // This means =] must exist |
| 3937 | value_type _Equal_close[2] = {'=', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3938 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3939 | _Equal_close+2); |
| 3940 | if (__temp == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3941 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3942 | // [__first, __temp) contains all text in [= ... =] |
| 3943 | typedef typename _Traits::string_type string_type; |
| 3944 | string_type __collate_name = |
| 3945 | __traits_.lookup_collatename(__first, __temp); |
| 3946 | if (__collate_name.empty()) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3947 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3948 | string_type __equiv_name = |
| 3949 | __traits_.transform_primary(__collate_name.begin(), |
| 3950 | __collate_name.end()); |
| 3951 | if (!__equiv_name.empty()) |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3952 | __ml->__add_equivalence(__equiv_name); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3953 | else |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3954 | { |
| 3955 | switch (__collate_name.size()) |
| 3956 | { |
| 3957 | case 1: |
| 3958 | __ml->__add_char(__collate_name[0]); |
| 3959 | break; |
| 3960 | case 2: |
| 3961 | __ml->__add_digraph(__collate_name[0], __collate_name[1]); |
| 3962 | break; |
| 3963 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3964 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3965 | } |
| 3966 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3967 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3968 | return __first; |
| 3969 | } |
| 3970 | |
| 3971 | template <class _CharT, class _Traits> |
| 3972 | template <class _ForwardIterator> |
| 3973 | _ForwardIterator |
| 3974 | basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3975 | _ForwardIterator __last, |
| 3976 | __bracket_expression<_CharT, _Traits>* __ml) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3977 | { |
| 3978 | // Found [: |
| 3979 | // This means :] must exist |
| 3980 | value_type _Colon_close[2] = {':', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3981 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3982 | _Colon_close+2); |
| 3983 | if (__temp == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3984 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3985 | // [__first, __temp) contains all text in [: ... :] |
| 3986 | typedef typename _Traits::char_class_type char_class_type; |
| 3987 | char_class_type __class_type = |
| 3988 | __traits_.lookup_classname(__first, __temp, __flags_ & icase); |
| 3989 | if (__class_type == 0) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 3990 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 3991 | __ml->__add_class(__class_type); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3992 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 3993 | return __first; |
| 3994 | } |
| 3995 | |
| 3996 | template <class _CharT, class _Traits> |
| 3997 | template <class _ForwardIterator> |
| 3998 | _ForwardIterator |
| 3999 | basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first, |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4000 | _ForwardIterator __last, |
| 4001 | basic_string<_CharT>& __col_sym) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4002 | { |
| 4003 | // Found [. |
| 4004 | // This means .] must exist |
| 4005 | value_type _Dot_close[2] = {'.', ']'}; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4006 | _ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close, |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4007 | _Dot_close+2); |
| 4008 | if (__temp == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4009 | __throw_regex_error<regex_constants::error_brack>(); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4010 | // [__first, __temp) contains all text in [. ... .] |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4011 | __col_sym = __traits_.lookup_collatename(__first, __temp); |
| 4012 | switch (__col_sym.size()) |
| 4013 | { |
| 4014 | case 1: |
| 4015 | case 2: |
| 4016 | break; |
| 4017 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4018 | __throw_regex_error<regex_constants::error_collate>(); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4019 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4020 | __first = _VSTD::next(__temp, 2); |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4021 | return __first; |
| 4022 | } |
| 4023 | |
| 4024 | template <class _CharT, class _Traits> |
| 4025 | template <class _ForwardIterator> |
| 4026 | _ForwardIterator |
| 4027 | basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, |
| 4028 | _ForwardIterator __last, |
| 4029 | int& __c) |
| 4030 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4031 | if (__first != __last ) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4032 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4033 | int __val = __traits_.value(*__first, 10); |
| 4034 | if ( __val != -1 ) |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4035 | { |
Marshall Clow | 97f50f6 | 2014-01-18 03:40:03 +0000 | [diff] [blame] | 4036 | __c = __val; |
| 4037 | for (++__first; |
| 4038 | __first != __last && ( __val = __traits_.value(*__first, 10)) != -1; |
| 4039 | ++__first) |
| 4040 | { |
| 4041 | __c *= 10; |
| 4042 | __c += __val; |
| 4043 | } |
Howard Hinnant | 0de86b6 | 2010-06-25 20:56:08 +0000 | [diff] [blame] | 4044 | } |
| 4045 | } |
| 4046 | return __first; |
| 4047 | } |
| 4048 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4049 | template <class _CharT, class _Traits> |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4050 | template <class _ForwardIterator> |
| 4051 | _ForwardIterator |
| 4052 | basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, |
| 4053 | _ForwardIterator __last) |
| 4054 | { |
| 4055 | __owns_one_state<_CharT>* __sa = __end_; |
| 4056 | _ForwardIterator __temp = __parse_alternative(__first, __last); |
| 4057 | if (__temp == __first) |
| 4058 | __push_empty(); |
| 4059 | __first = __temp; |
| 4060 | while (__first != __last && *__first == '|') |
| 4061 | { |
| 4062 | __owns_one_state<_CharT>* __sb = __end_; |
| 4063 | __temp = __parse_alternative(++__first, __last); |
| 4064 | if (__temp == __first) |
| 4065 | __push_empty(); |
| 4066 | __push_alternation(__sa, __sb); |
| 4067 | __first = __temp; |
| 4068 | } |
| 4069 | return __first; |
| 4070 | } |
| 4071 | |
| 4072 | template <class _CharT, class _Traits> |
| 4073 | template <class _ForwardIterator> |
| 4074 | _ForwardIterator |
| 4075 | basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, |
| 4076 | _ForwardIterator __last) |
| 4077 | { |
| 4078 | while (true) |
| 4079 | { |
| 4080 | _ForwardIterator __temp = __parse_term(__first, __last); |
| 4081 | if (__temp == __first) |
| 4082 | break; |
| 4083 | __first = __temp; |
| 4084 | } |
| 4085 | return __first; |
| 4086 | } |
| 4087 | |
| 4088 | template <class _CharT, class _Traits> |
| 4089 | template <class _ForwardIterator> |
| 4090 | _ForwardIterator |
| 4091 | basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, |
| 4092 | _ForwardIterator __last) |
| 4093 | { |
| 4094 | _ForwardIterator __temp = __parse_assertion(__first, __last); |
| 4095 | if (__temp == __first) |
| 4096 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4097 | __owns_one_state<_CharT>* __e = __end_; |
| 4098 | unsigned __mexp_begin = __marked_count_; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4099 | __temp = __parse_atom(__first, __last); |
| 4100 | if (__temp != __first) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4101 | __first = __parse_ERE_dupl_symbol(__temp, __last, __e, |
| 4102 | __mexp_begin+1, __marked_count_+1); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4103 | } |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4104 | else |
| 4105 | __first = __temp; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4106 | return __first; |
| 4107 | } |
| 4108 | |
| 4109 | template <class _CharT, class _Traits> |
| 4110 | template <class _ForwardIterator> |
| 4111 | _ForwardIterator |
| 4112 | basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, |
| 4113 | _ForwardIterator __last) |
| 4114 | { |
| 4115 | if (__first != __last) |
| 4116 | { |
| 4117 | switch (*__first) |
| 4118 | { |
| 4119 | case '^': |
| 4120 | __push_l_anchor(); |
| 4121 | ++__first; |
| 4122 | break; |
| 4123 | case '$': |
| 4124 | __push_r_anchor(); |
| 4125 | ++__first; |
| 4126 | break; |
| 4127 | case '\\': |
| 4128 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4129 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4130 | if (__temp != __last) |
| 4131 | { |
| 4132 | if (*__temp == 'b') |
| 4133 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4134 | __push_word_boundary(false); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4135 | __first = ++__temp; |
| 4136 | } |
| 4137 | else if (*__temp == 'B') |
| 4138 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4139 | __push_word_boundary(true); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4140 | __first = ++__temp; |
| 4141 | } |
| 4142 | } |
| 4143 | } |
| 4144 | break; |
| 4145 | case '(': |
| 4146 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4147 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4148 | if (__temp != __last && *__temp == '?') |
| 4149 | { |
| 4150 | if (++__temp != __last) |
| 4151 | { |
| 4152 | switch (*__temp) |
| 4153 | { |
| 4154 | case '=': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4155 | { |
| 4156 | basic_regex __exp; |
| 4157 | __exp.__flags_ = __flags_; |
| 4158 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4159 | unsigned __mexp = __exp.__marked_count_; |
| 4160 | __push_lookahead(_VSTD::move(__exp), false, __marked_count_); |
| 4161 | __marked_count_ += __mexp; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4162 | if (__temp == __last || *__temp != ')') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4163 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4164 | __first = ++__temp; |
| 4165 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4166 | break; |
| 4167 | case '!': |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4168 | { |
| 4169 | basic_regex __exp; |
| 4170 | __exp.__flags_ = __flags_; |
| 4171 | __temp = __exp.__parse(++__temp, __last); |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4172 | unsigned __mexp = __exp.__marked_count_; |
| 4173 | __push_lookahead(_VSTD::move(__exp), true, __marked_count_); |
| 4174 | __marked_count_ += __mexp; |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4175 | if (__temp == __last || *__temp != ')') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4176 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4177 | __first = ++__temp; |
| 4178 | } |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4179 | break; |
| 4180 | } |
| 4181 | } |
| 4182 | } |
| 4183 | } |
| 4184 | break; |
| 4185 | } |
| 4186 | } |
| 4187 | return __first; |
| 4188 | } |
| 4189 | |
| 4190 | template <class _CharT, class _Traits> |
| 4191 | template <class _ForwardIterator> |
| 4192 | _ForwardIterator |
| 4193 | basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, |
| 4194 | _ForwardIterator __last) |
| 4195 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4196 | if (__first != __last) |
| 4197 | { |
| 4198 | switch (*__first) |
| 4199 | { |
| 4200 | case '.': |
| 4201 | __push_match_any_but_newline(); |
| 4202 | ++__first; |
| 4203 | break; |
| 4204 | case '\\': |
| 4205 | __first = __parse_atom_escape(__first, __last); |
| 4206 | break; |
| 4207 | case '[': |
| 4208 | __first = __parse_bracket_expression(__first, __last); |
| 4209 | break; |
| 4210 | case '(': |
| 4211 | { |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4212 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4213 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4214 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4215 | _ForwardIterator __temp = _VSTD::next(__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4216 | if (__temp != __last && *__first == '?' && *__temp == ':') |
| 4217 | { |
| 4218 | ++__open_count_; |
| 4219 | __first = __parse_ecma_exp(++__temp, __last); |
| 4220 | if (__first == __last || *__first != ')') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4221 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4222 | --__open_count_; |
| 4223 | ++__first; |
| 4224 | } |
| 4225 | else |
| 4226 | { |
| 4227 | __push_begin_marked_subexpression(); |
| 4228 | unsigned __temp_count = __marked_count_; |
| 4229 | ++__open_count_; |
| 4230 | __first = __parse_ecma_exp(__first, __last); |
| 4231 | if (__first == __last || *__first != ')') |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4232 | __throw_regex_error<regex_constants::error_paren>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4233 | __push_end_marked_subexpression(__temp_count); |
| 4234 | --__open_count_; |
| 4235 | ++__first; |
| 4236 | } |
| 4237 | } |
| 4238 | break; |
Marshall Clow | 568bd02 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4239 | case '*': |
| 4240 | case '+': |
| 4241 | case '?': |
| 4242 | case '{': |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4243 | __throw_regex_error<regex_constants::error_badrepeat>(); |
Marshall Clow | 568bd02 | 2015-07-23 18:27:51 +0000 | [diff] [blame] | 4244 | break; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4245 | default: |
| 4246 | __first = __parse_pattern_character(__first, __last); |
| 4247 | break; |
| 4248 | } |
| 4249 | } |
| 4250 | return __first; |
| 4251 | } |
| 4252 | |
| 4253 | template <class _CharT, class _Traits> |
| 4254 | template <class _ForwardIterator> |
| 4255 | _ForwardIterator |
| 4256 | basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, |
| 4257 | _ForwardIterator __last) |
| 4258 | { |
| 4259 | if (__first != __last && *__first == '\\') |
| 4260 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4261 | _ForwardIterator __t1 = _VSTD::next(__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4262 | _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last); |
| 4263 | if (__t2 != __t1) |
| 4264 | __first = __t2; |
| 4265 | else |
| 4266 | { |
| 4267 | __t2 = __parse_character_class_escape(__t1, __last); |
| 4268 | if (__t2 != __t1) |
| 4269 | __first = __t2; |
| 4270 | else |
| 4271 | { |
| 4272 | __t2 = __parse_character_escape(__t1, __last); |
| 4273 | if (__t2 != __t1) |
| 4274 | __first = __t2; |
| 4275 | } |
| 4276 | } |
| 4277 | } |
| 4278 | return __first; |
| 4279 | } |
| 4280 | |
| 4281 | template <class _CharT, class _Traits> |
| 4282 | template <class _ForwardIterator> |
| 4283 | _ForwardIterator |
| 4284 | basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, |
| 4285 | _ForwardIterator __last) |
| 4286 | { |
| 4287 | if (__first != __last) |
| 4288 | { |
| 4289 | if (*__first == '0') |
| 4290 | { |
| 4291 | __push_char(_CharT()); |
| 4292 | ++__first; |
| 4293 | } |
| 4294 | else if ('1' <= *__first && *__first <= '9') |
| 4295 | { |
| 4296 | unsigned __v = *__first - '0'; |
| 4297 | for (++__first; '0' <= *__first && *__first <= '9'; ++__first) |
| 4298 | __v = 10 * __v + *__first - '0'; |
| 4299 | if (__v > mark_count()) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4300 | __throw_regex_error<regex_constants::error_backref>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4301 | __push_back_ref(__v); |
| 4302 | } |
| 4303 | } |
| 4304 | return __first; |
| 4305 | } |
| 4306 | |
| 4307 | template <class _CharT, class _Traits> |
| 4308 | template <class _ForwardIterator> |
| 4309 | _ForwardIterator |
| 4310 | basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, |
| 4311 | _ForwardIterator __last) |
| 4312 | { |
| 4313 | if (__first != __last) |
| 4314 | { |
| 4315 | __bracket_expression<_CharT, _Traits>* __ml; |
| 4316 | switch (*__first) |
| 4317 | { |
| 4318 | case 'd': |
| 4319 | __ml = __start_matching_list(false); |
| 4320 | __ml->__add_class(ctype_base::digit); |
| 4321 | ++__first; |
| 4322 | break; |
| 4323 | case 'D': |
| 4324 | __ml = __start_matching_list(true); |
| 4325 | __ml->__add_class(ctype_base::digit); |
| 4326 | ++__first; |
| 4327 | break; |
| 4328 | case 's': |
| 4329 | __ml = __start_matching_list(false); |
| 4330 | __ml->__add_class(ctype_base::space); |
| 4331 | ++__first; |
| 4332 | break; |
| 4333 | case 'S': |
| 4334 | __ml = __start_matching_list(true); |
| 4335 | __ml->__add_class(ctype_base::space); |
| 4336 | ++__first; |
| 4337 | break; |
| 4338 | case 'w': |
| 4339 | __ml = __start_matching_list(false); |
| 4340 | __ml->__add_class(ctype_base::alnum); |
| 4341 | __ml->__add_char('_'); |
| 4342 | ++__first; |
| 4343 | break; |
| 4344 | case 'W': |
| 4345 | __ml = __start_matching_list(true); |
| 4346 | __ml->__add_class(ctype_base::alnum); |
| 4347 | __ml->__add_char('_'); |
| 4348 | ++__first; |
| 4349 | break; |
| 4350 | } |
| 4351 | } |
| 4352 | return __first; |
| 4353 | } |
| 4354 | |
| 4355 | template <class _CharT, class _Traits> |
| 4356 | template <class _ForwardIterator> |
| 4357 | _ForwardIterator |
| 4358 | basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first, |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4359 | _ForwardIterator __last, |
| 4360 | basic_string<_CharT>* __str) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4361 | { |
| 4362 | if (__first != __last) |
| 4363 | { |
| 4364 | _ForwardIterator __t; |
| 4365 | unsigned __sum = 0; |
| 4366 | int __hd; |
| 4367 | switch (*__first) |
| 4368 | { |
| 4369 | case 'f': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4370 | if (__str) |
| 4371 | *__str = _CharT(0xC); |
| 4372 | else |
| 4373 | __push_char(_CharT(0xC)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4374 | ++__first; |
| 4375 | break; |
| 4376 | case 'n': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4377 | if (__str) |
| 4378 | *__str = _CharT(0xA); |
| 4379 | else |
| 4380 | __push_char(_CharT(0xA)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4381 | ++__first; |
| 4382 | break; |
| 4383 | case 'r': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4384 | if (__str) |
| 4385 | *__str = _CharT(0xD); |
| 4386 | else |
| 4387 | __push_char(_CharT(0xD)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4388 | ++__first; |
| 4389 | break; |
| 4390 | case 't': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4391 | if (__str) |
| 4392 | *__str = _CharT(0x9); |
| 4393 | else |
| 4394 | __push_char(_CharT(0x9)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4395 | ++__first; |
| 4396 | break; |
| 4397 | case 'v': |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4398 | if (__str) |
| 4399 | *__str = _CharT(0xB); |
| 4400 | else |
| 4401 | __push_char(_CharT(0xB)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4402 | ++__first; |
| 4403 | break; |
| 4404 | case 'c': |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4405 | if ((__t = _VSTD::next(__first)) != __last) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4406 | { |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4407 | if (('A' <= *__t && *__t <= 'Z') || |
| 4408 | ('a' <= *__t && *__t <= 'z')) |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4409 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4410 | if (__str) |
| 4411 | *__str = _CharT(*__t % 32); |
| 4412 | else |
| 4413 | __push_char(_CharT(*__t % 32)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4414 | __first = ++__t; |
| 4415 | } |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4416 | else |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4417 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4418 | } |
Howard Hinnant | 1e1d051 | 2013-07-15 18:21:11 +0000 | [diff] [blame] | 4419 | else |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4420 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4421 | break; |
| 4422 | case 'u': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4423 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4424 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4425 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4426 | __hd = __traits_.value(*__first, 16); |
| 4427 | if (__hd == -1) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4428 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4429 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4430 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4431 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4432 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4433 | __hd = __traits_.value(*__first, 16); |
| 4434 | if (__hd == -1) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4435 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4436 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4437 | // drop through |
| 4438 | case 'x': |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4439 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4440 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4441 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4442 | __hd = __traits_.value(*__first, 16); |
| 4443 | if (__hd == -1) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4444 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4445 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4446 | ++__first; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 4447 | if (__first == __last) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4448 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4449 | __hd = __traits_.value(*__first, 16); |
| 4450 | if (__hd == -1) |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4451 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | ec3773c | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 4452 | __sum = 16 * __sum + static_cast<unsigned>(__hd); |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4453 | if (__str) |
| 4454 | *__str = _CharT(__sum); |
| 4455 | else |
| 4456 | __push_char(_CharT(__sum)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4457 | ++__first; |
| 4458 | break; |
Marshall Clow | 6b7e692 | 2014-05-21 16:29:50 +0000 | [diff] [blame] | 4459 | case '0': |
| 4460 | if (__str) |
| 4461 | *__str = _CharT(0); |
| 4462 | else |
| 4463 | __push_char(_CharT(0)); |
| 4464 | ++__first; |
| 4465 | break; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4466 | default: |
| 4467 | if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) |
| 4468 | { |
Howard Hinnant | 15476f3 | 2010-07-28 17:35:27 +0000 | [diff] [blame] | 4469 | if (__str) |
| 4470 | *__str = *__first; |
| 4471 | else |
| 4472 | __push_char(*__first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4473 | ++__first; |
| 4474 | } |
Howard Hinnant | 918f2a8 | 2013-06-28 18:57:30 +0000 | [diff] [blame] | 4475 | else |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 4476 | __throw_regex_error<regex_constants::error_escape>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4477 | break; |
| 4478 | } |
| 4479 | } |
| 4480 | return __first; |
| 4481 | } |
| 4482 | |
| 4483 | template <class _CharT, class _Traits> |
| 4484 | template <class _ForwardIterator> |
| 4485 | _ForwardIterator |
| 4486 | basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, |
| 4487 | _ForwardIterator __last) |
| 4488 | { |
| 4489 | if (__first != __last) |
| 4490 | { |
| 4491 | switch (*__first) |
| 4492 | { |
| 4493 | case '^': |
| 4494 | case '$': |
| 4495 | case '\\': |
| 4496 | case '.': |
| 4497 | case '*': |
| 4498 | case '+': |
| 4499 | case '?': |
| 4500 | case '(': |
| 4501 | case ')': |
| 4502 | case '[': |
| 4503 | case ']': |
| 4504 | case '{': |
| 4505 | case '}': |
| 4506 | case '|': |
| 4507 | break; |
| 4508 | default: |
| 4509 | __push_char(*__first); |
| 4510 | ++__first; |
| 4511 | break; |
| 4512 | } |
| 4513 | } |
| 4514 | return __first; |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4515 | } |
| 4516 | |
| 4517 | template <class _CharT, class _Traits> |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4518 | template <class _ForwardIterator> |
| 4519 | _ForwardIterator |
| 4520 | basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, |
| 4521 | _ForwardIterator __last) |
| 4522 | { |
| 4523 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4524 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4525 | if (__t1 != __first) |
| 4526 | __parse_basic_reg_exp(__first, __t1); |
| 4527 | else |
| 4528 | __push_empty(); |
| 4529 | __first = __t1; |
| 4530 | if (__first != __last) |
| 4531 | ++__first; |
| 4532 | while (__first != __last) |
| 4533 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4534 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4535 | __owns_one_state<_CharT>* __sb = __end_; |
| 4536 | if (__t1 != __first) |
| 4537 | __parse_basic_reg_exp(__first, __t1); |
| 4538 | else |
| 4539 | __push_empty(); |
| 4540 | __push_alternation(__sa, __sb); |
| 4541 | __first = __t1; |
| 4542 | if (__first != __last) |
| 4543 | ++__first; |
| 4544 | } |
| 4545 | return __first; |
| 4546 | } |
| 4547 | |
| 4548 | template <class _CharT, class _Traits> |
| 4549 | template <class _ForwardIterator> |
| 4550 | _ForwardIterator |
| 4551 | basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, |
| 4552 | _ForwardIterator __last) |
| 4553 | { |
| 4554 | __owns_one_state<_CharT>* __sa = __end_; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4555 | _ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4556 | if (__t1 != __first) |
| 4557 | __parse_extended_reg_exp(__first, __t1); |
| 4558 | else |
| 4559 | __push_empty(); |
| 4560 | __first = __t1; |
| 4561 | if (__first != __last) |
| 4562 | ++__first; |
| 4563 | while (__first != __last) |
| 4564 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4565 | __t1 = _VSTD::find(__first, __last, _CharT('\n')); |
Howard Hinnant | 856846b | 2010-07-27 19:53:10 +0000 | [diff] [blame] | 4566 | __owns_one_state<_CharT>* __sb = __end_; |
| 4567 | if (__t1 != __first) |
| 4568 | __parse_extended_reg_exp(__first, __t1); |
| 4569 | else |
| 4570 | __push_empty(); |
| 4571 | __push_alternation(__sa, __sb); |
| 4572 | __first = __t1; |
| 4573 | if (__first != __last) |
| 4574 | ++__first; |
| 4575 | } |
| 4576 | return __first; |
| 4577 | } |
| 4578 | |
| 4579 | template <class _CharT, class _Traits> |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4580 | void |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4581 | basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max, |
| 4582 | __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, |
| 4583 | bool __greedy) |
| 4584 | { |
| 4585 | unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first())); |
| 4586 | __end_->first() = nullptr; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4587 | unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_, |
| 4588 | __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, |
| 4589 | __min, __max)); |
| 4590 | __s->first() = nullptr; |
| 4591 | __e1.release(); |
| 4592 | __end_->first() = new __repeat_one_loop<_CharT>(__e2.get()); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4593 | __end_ = __e2->second(); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4594 | __s->first() = __e2.release(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 4595 | ++__loop_count_; |
| 4596 | } |
| 4597 | |
| 4598 | template <class _CharT, class _Traits> |
| 4599 | void |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4600 | basic_regex<_CharT, _Traits>::__push_char(value_type __c) |
| 4601 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4602 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4603 | __end_->first() = new __match_char_icase<_CharT, _Traits> |
| 4604 | (__traits_, __c, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4605 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4606 | __end_->first() = new __match_char_collate<_CharT, _Traits> |
| 4607 | (__traits_, __c, __end_->first()); |
| 4608 | else |
| 4609 | __end_->first() = new __match_char<_CharT>(__c, __end_->first()); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 4610 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4611 | } |
| 4612 | |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4613 | template <class _CharT, class _Traits> |
| 4614 | void |
| 4615 | basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() |
| 4616 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4617 | if (!(__flags_ & nosubs)) |
| 4618 | { |
| 4619 | __end_->first() = |
| 4620 | new __begin_marked_subexpression<_CharT>(++__marked_count_, |
| 4621 | __end_->first()); |
| 4622 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4623 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | template <class _CharT, class _Traits> |
| 4627 | void |
| 4628 | basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) |
| 4629 | { |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 4630 | if (!(__flags_ & nosubs)) |
| 4631 | { |
| 4632 | __end_->first() = |
| 4633 | new __end_marked_subexpression<_CharT>(__sub, __end_->first()); |
| 4634 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4635 | } |
Howard Hinnant | 0dca5fc | 2010-06-30 20:30:19 +0000 | [diff] [blame] | 4636 | } |
| 4637 | |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4638 | template <class _CharT, class _Traits> |
| 4639 | void |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 4640 | basic_regex<_CharT, _Traits>::__push_l_anchor() |
| 4641 | { |
| 4642 | __end_->first() = new __l_anchor<_CharT>(__end_->first()); |
| 4643 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4644 | } |
| 4645 | |
| 4646 | template <class _CharT, class _Traits> |
| 4647 | void |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4648 | basic_regex<_CharT, _Traits>::__push_r_anchor() |
| 4649 | { |
| 4650 | __end_->first() = new __r_anchor<_CharT>(__end_->first()); |
| 4651 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4652 | } |
| 4653 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 4654 | template <class _CharT, class _Traits> |
| 4655 | void |
| 4656 | basic_regex<_CharT, _Traits>::__push_match_any() |
| 4657 | { |
| 4658 | __end_->first() = new __match_any<_CharT>(__end_->first()); |
| 4659 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4660 | } |
Howard Hinnant | 37f9f9c | 2010-07-09 00:15:26 +0000 | [diff] [blame] | 4661 | |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4662 | template <class _CharT, class _Traits> |
| 4663 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4664 | basic_regex<_CharT, _Traits>::__push_match_any_but_newline() |
| 4665 | { |
| 4666 | __end_->first() = new __match_any_but_newline<_CharT>(__end_->first()); |
| 4667 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4668 | } |
| 4669 | |
| 4670 | template <class _CharT, class _Traits> |
| 4671 | void |
Howard Hinnant | 2ade7c2 | 2010-07-22 17:53:24 +0000 | [diff] [blame] | 4672 | basic_regex<_CharT, _Traits>::__push_empty() |
| 4673 | { |
| 4674 | __end_->first() = new __empty_state<_CharT>(__end_->first()); |
| 4675 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4676 | } |
| 4677 | |
| 4678 | template <class _CharT, class _Traits> |
| 4679 | void |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 4680 | basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) |
| 4681 | { |
| 4682 | __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, |
| 4683 | __end_->first()); |
| 4684 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4685 | } |
| 4686 | |
| 4687 | template <class _CharT, class _Traits> |
| 4688 | void |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4689 | basic_regex<_CharT, _Traits>::__push_back_ref(int __i) |
| 4690 | { |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4691 | if (flags() & icase) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4692 | __end_->first() = new __back_ref_icase<_CharT, _Traits> |
| 4693 | (__traits_, __i, __end_->first()); |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4694 | else if (flags() & collate) |
Howard Hinnant | e34f17d | 2010-07-12 19:11:27 +0000 | [diff] [blame] | 4695 | __end_->first() = new __back_ref_collate<_CharT, _Traits> |
| 4696 | (__traits_, __i, __end_->first()); |
| 4697 | else |
| 4698 | __end_->first() = new __back_ref<_CharT>(__i, __end_->first()); |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 4699 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4700 | } |
| 4701 | |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4702 | template <class _CharT, class _Traits> |
Howard Hinnant | aa69808 | 2010-07-16 19:08:36 +0000 | [diff] [blame] | 4703 | void |
| 4704 | basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, |
| 4705 | __owns_one_state<_CharT>* __ea) |
| 4706 | { |
| 4707 | __sa->first() = new __alternate<_CharT>( |
| 4708 | static_cast<__owns_one_state<_CharT>*>(__sa->first()), |
| 4709 | static_cast<__owns_one_state<_CharT>*>(__ea->first())); |
| 4710 | __ea->first() = nullptr; |
| 4711 | __ea->first() = new __empty_state<_CharT>(__end_->first()); |
| 4712 | __end_->first() = nullptr; |
| 4713 | __end_->first() = new __empty_non_own_state<_CharT>(__ea->first()); |
| 4714 | __end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first()); |
| 4715 | } |
| 4716 | |
| 4717 | template <class _CharT, class _Traits> |
Howard Hinnant | 173968a | 2010-07-13 21:48:06 +0000 | [diff] [blame] | 4718 | __bracket_expression<_CharT, _Traits>* |
| 4719 | basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) |
| 4720 | { |
| 4721 | __bracket_expression<_CharT, _Traits>* __r = |
| 4722 | new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(), |
| 4723 | __negate, __flags_ & icase, |
| 4724 | __flags_ & collate); |
| 4725 | __end_->first() = __r; |
| 4726 | __end_ = __r; |
| 4727 | return __r; |
| 4728 | } |
| 4729 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4730 | template <class _CharT, class _Traits> |
| 4731 | void |
| 4732 | basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4733 | bool __invert, |
| 4734 | unsigned __mexp) |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4735 | { |
| 4736 | __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, |
Howard Hinnant | cd59acc | 2013-07-23 16:18:04 +0000 | [diff] [blame] | 4737 | __end_->first(), __mexp); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 4738 | __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first()); |
| 4739 | } |
| 4740 | |
Howard Hinnant | 8c2c18d | 2010-06-24 21:28:00 +0000 | [diff] [blame] | 4741 | typedef basic_regex<char> regex; |
| 4742 | typedef basic_regex<wchar_t> wregex; |
| 4743 | |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4744 | // sub_match |
| 4745 | |
| 4746 | template <class _BidirectionalIterator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 4747 | class _LIBCPP_TYPE_VIS_ONLY sub_match |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4748 | : public pair<_BidirectionalIterator, _BidirectionalIterator> |
| 4749 | { |
| 4750 | public: |
| 4751 | typedef _BidirectionalIterator iterator; |
| 4752 | typedef typename iterator_traits<iterator>::value_type value_type; |
| 4753 | typedef typename iterator_traits<iterator>::difference_type difference_type; |
| 4754 | typedef basic_string<value_type> string_type; |
| 4755 | |
| 4756 | bool matched; |
| 4757 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4758 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 46623a0 | 2012-07-21 01:31:58 +0000 | [diff] [blame] | 4759 | _LIBCPP_CONSTEXPR sub_match() : matched() {} |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 4760 | |
| 4761 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4762 | difference_type length() const |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 4763 | {return matched ? _VSTD::distance(this->first, this->second) : 0;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4764 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4765 | string_type str() const |
| 4766 | {return matched ? string_type(this->first, this->second) : string_type();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4767 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4768 | operator string_type() const |
| 4769 | {return str();} |
| 4770 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4771 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4772 | int compare(const sub_match& __s) const |
| 4773 | {return str().compare(__s.str());} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4774 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4775 | int compare(const string_type& __s) const |
| 4776 | {return str().compare(__s);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 4777 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4778 | int compare(const value_type* __s) const |
| 4779 | {return str().compare(__s);} |
| 4780 | }; |
| 4781 | |
| 4782 | typedef sub_match<const char*> csub_match; |
| 4783 | typedef sub_match<const wchar_t*> wcsub_match; |
| 4784 | typedef sub_match<string::const_iterator> ssub_match; |
| 4785 | typedef sub_match<wstring::const_iterator> wssub_match; |
| 4786 | |
| 4787 | template <class _BiIter> |
| 4788 | inline _LIBCPP_INLINE_VISIBILITY |
| 4789 | bool |
| 4790 | operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4791 | { |
| 4792 | return __x.compare(__y) == 0; |
| 4793 | } |
| 4794 | |
| 4795 | template <class _BiIter> |
| 4796 | inline _LIBCPP_INLINE_VISIBILITY |
| 4797 | bool |
| 4798 | operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4799 | { |
| 4800 | return !(__x == __y); |
| 4801 | } |
| 4802 | |
| 4803 | template <class _BiIter> |
| 4804 | inline _LIBCPP_INLINE_VISIBILITY |
| 4805 | bool |
| 4806 | operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4807 | { |
| 4808 | return __x.compare(__y) < 0; |
| 4809 | } |
| 4810 | |
| 4811 | template <class _BiIter> |
| 4812 | inline _LIBCPP_INLINE_VISIBILITY |
| 4813 | bool |
| 4814 | operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4815 | { |
| 4816 | return !(__y < __x); |
| 4817 | } |
| 4818 | |
| 4819 | template <class _BiIter> |
| 4820 | inline _LIBCPP_INLINE_VISIBILITY |
| 4821 | bool |
| 4822 | operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4823 | { |
| 4824 | return !(__x < __y); |
| 4825 | } |
| 4826 | |
| 4827 | template <class _BiIter> |
| 4828 | inline _LIBCPP_INLINE_VISIBILITY |
| 4829 | bool |
| 4830 | operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) |
| 4831 | { |
| 4832 | return __y < __x; |
| 4833 | } |
| 4834 | |
| 4835 | template <class _BiIter, class _ST, class _SA> |
| 4836 | inline _LIBCPP_INLINE_VISIBILITY |
| 4837 | bool |
| 4838 | operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4839 | const sub_match<_BiIter>& __y) |
| 4840 | { |
Marshall Clow | e3e7054 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 4841 | return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4842 | } |
| 4843 | |
| 4844 | template <class _BiIter, class _ST, class _SA> |
| 4845 | inline _LIBCPP_INLINE_VISIBILITY |
| 4846 | bool |
| 4847 | operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4848 | const sub_match<_BiIter>& __y) |
| 4849 | { |
| 4850 | return !(__x == __y); |
| 4851 | } |
| 4852 | |
| 4853 | template <class _BiIter, class _ST, class _SA> |
| 4854 | inline _LIBCPP_INLINE_VISIBILITY |
| 4855 | bool |
| 4856 | operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4857 | const sub_match<_BiIter>& __y) |
| 4858 | { |
Marshall Clow | e3e7054 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 4859 | return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4860 | } |
| 4861 | |
| 4862 | template <class _BiIter, class _ST, class _SA> |
| 4863 | inline _LIBCPP_INLINE_VISIBILITY |
| 4864 | bool |
| 4865 | operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4866 | const sub_match<_BiIter>& __y) |
| 4867 | { |
| 4868 | return __y < __x; |
| 4869 | } |
| 4870 | |
| 4871 | template <class _BiIter, class _ST, class _SA> |
| 4872 | inline _LIBCPP_INLINE_VISIBILITY |
| 4873 | bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4874 | const sub_match<_BiIter>& __y) |
| 4875 | { |
| 4876 | return !(__x < __y); |
| 4877 | } |
| 4878 | |
| 4879 | template <class _BiIter, class _ST, class _SA> |
| 4880 | inline _LIBCPP_INLINE_VISIBILITY |
| 4881 | bool |
| 4882 | operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x, |
| 4883 | const sub_match<_BiIter>& __y) |
| 4884 | { |
| 4885 | return !(__y < __x); |
| 4886 | } |
| 4887 | |
| 4888 | template <class _BiIter, class _ST, class _SA> |
| 4889 | inline _LIBCPP_INLINE_VISIBILITY |
| 4890 | bool |
| 4891 | operator==(const sub_match<_BiIter>& __x, |
| 4892 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4893 | { |
Marshall Clow | e3e7054 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 4894 | return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | template <class _BiIter, class _ST, class _SA> |
| 4898 | inline _LIBCPP_INLINE_VISIBILITY |
| 4899 | bool |
| 4900 | operator!=(const sub_match<_BiIter>& __x, |
| 4901 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4902 | { |
| 4903 | return !(__x == __y); |
| 4904 | } |
| 4905 | |
| 4906 | template <class _BiIter, class _ST, class _SA> |
| 4907 | inline _LIBCPP_INLINE_VISIBILITY |
| 4908 | bool |
| 4909 | operator<(const sub_match<_BiIter>& __x, |
| 4910 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4911 | { |
Marshall Clow | e3e7054 | 2014-12-15 23:57:56 +0000 | [diff] [blame] | 4912 | return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0; |
Howard Hinnant | cd85b9e | 2010-06-29 18:37:43 +0000 | [diff] [blame] | 4913 | } |
| 4914 | |
| 4915 | template <class _BiIter, class _ST, class _SA> |
| 4916 | inline _LIBCPP_INLINE_VISIBILITY |
| 4917 | bool operator>(const sub_match<_BiIter>& __x, |
| 4918 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4919 | { |
| 4920 | return __y < __x; |
| 4921 | } |
| 4922 | |
| 4923 | template <class _BiIter, class _ST, class _SA> |
| 4924 | inline _LIBCPP_INLINE_VISIBILITY |
| 4925 | bool |
| 4926 | operator>=(const sub_match<_BiIter>& __x, |
| 4927 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4928 | { |
| 4929 | return !(__x < __y); |
| 4930 | } |
| 4931 | |
| 4932 | template <class _BiIter, class _ST, class _SA> |
| 4933 | inline _LIBCPP_INLINE_VISIBILITY |
| 4934 | bool |
| 4935 | operator<=(const sub_match<_BiIter>& __x, |
| 4936 | const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) |
| 4937 | { |
| 4938 | return !(__y < __x); |
| 4939 | } |
| 4940 | |
| 4941 | template <class _BiIter> |
| 4942 | inline _LIBCPP_INLINE_VISIBILITY |
| 4943 | bool |
| 4944 | operator==(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4945 | const sub_match<_BiIter>& __y) |
| 4946 | { |
| 4947 | return __y.compare(__x) == 0; |
| 4948 | } |
| 4949 | |
| 4950 | template <class _BiIter> |
| 4951 | inline _LIBCPP_INLINE_VISIBILITY |
| 4952 | bool |
| 4953 | operator!=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4954 | const sub_match<_BiIter>& __y) |
| 4955 | { |
| 4956 | return !(__x == __y); |
| 4957 | } |
| 4958 | |
| 4959 | template <class _BiIter> |
| 4960 | inline _LIBCPP_INLINE_VISIBILITY |
| 4961 | bool |
| 4962 | operator<(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4963 | const sub_match<_BiIter>& __y) |
| 4964 | { |
| 4965 | return __y.compare(__x) > 0; |
| 4966 | } |
| 4967 | |
| 4968 | template <class _BiIter> |
| 4969 | inline _LIBCPP_INLINE_VISIBILITY |
| 4970 | bool |
| 4971 | operator>(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4972 | const sub_match<_BiIter>& __y) |
| 4973 | { |
| 4974 | return __y < __x; |
| 4975 | } |
| 4976 | |
| 4977 | template <class _BiIter> |
| 4978 | inline _LIBCPP_INLINE_VISIBILITY |
| 4979 | bool |
| 4980 | operator>=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4981 | const sub_match<_BiIter>& __y) |
| 4982 | { |
| 4983 | return !(__x < __y); |
| 4984 | } |
| 4985 | |
| 4986 | template <class _BiIter> |
| 4987 | inline _LIBCPP_INLINE_VISIBILITY |
| 4988 | bool |
| 4989 | operator<=(typename iterator_traits<_BiIter>::value_type const* __x, |
| 4990 | const sub_match<_BiIter>& __y) |
| 4991 | { |
| 4992 | return !(__y < __x); |
| 4993 | } |
| 4994 | |
| 4995 | template <class _BiIter> |
| 4996 | inline _LIBCPP_INLINE_VISIBILITY |
| 4997 | bool |
| 4998 | operator==(const sub_match<_BiIter>& __x, |
| 4999 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5000 | { |
| 5001 | return __x.compare(__y) == 0; |
| 5002 | } |
| 5003 | |
| 5004 | template <class _BiIter> |
| 5005 | inline _LIBCPP_INLINE_VISIBILITY |
| 5006 | bool |
| 5007 | operator!=(const sub_match<_BiIter>& __x, |
| 5008 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5009 | { |
| 5010 | return !(__x == __y); |
| 5011 | } |
| 5012 | |
| 5013 | template <class _BiIter> |
| 5014 | inline _LIBCPP_INLINE_VISIBILITY |
| 5015 | bool |
| 5016 | operator<(const sub_match<_BiIter>& __x, |
| 5017 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5018 | { |
| 5019 | return __x.compare(__y) < 0; |
| 5020 | } |
| 5021 | |
| 5022 | template <class _BiIter> |
| 5023 | inline _LIBCPP_INLINE_VISIBILITY |
| 5024 | bool |
| 5025 | operator>(const sub_match<_BiIter>& __x, |
| 5026 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5027 | { |
| 5028 | return __y < __x; |
| 5029 | } |
| 5030 | |
| 5031 | template <class _BiIter> |
| 5032 | inline _LIBCPP_INLINE_VISIBILITY |
| 5033 | bool |
| 5034 | operator>=(const sub_match<_BiIter>& __x, |
| 5035 | typename iterator_traits<_BiIter>::value_type const* __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, |
| 5044 | typename iterator_traits<_BiIter>::value_type const* __y) |
| 5045 | { |
| 5046 | return !(__y < __x); |
| 5047 | } |
| 5048 | |
| 5049 | template <class _BiIter> |
| 5050 | inline _LIBCPP_INLINE_VISIBILITY |
| 5051 | bool |
| 5052 | operator==(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5053 | const sub_match<_BiIter>& __y) |
| 5054 | { |
| 5055 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5056 | return __y.compare(string_type(1, __x)) == 0; |
| 5057 | } |
| 5058 | |
| 5059 | template <class _BiIter> |
| 5060 | inline _LIBCPP_INLINE_VISIBILITY |
| 5061 | bool |
| 5062 | operator!=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5063 | const sub_match<_BiIter>& __y) |
| 5064 | { |
| 5065 | return !(__x == __y); |
| 5066 | } |
| 5067 | |
| 5068 | template <class _BiIter> |
| 5069 | inline _LIBCPP_INLINE_VISIBILITY |
| 5070 | bool |
| 5071 | operator<(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5072 | const sub_match<_BiIter>& __y) |
| 5073 | { |
| 5074 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5075 | return __y.compare(string_type(1, __x)) > 0; |
| 5076 | } |
| 5077 | |
| 5078 | template <class _BiIter> |
| 5079 | inline _LIBCPP_INLINE_VISIBILITY |
| 5080 | bool |
| 5081 | operator>(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5082 | const sub_match<_BiIter>& __y) |
| 5083 | { |
| 5084 | return __y < __x; |
| 5085 | } |
| 5086 | |
| 5087 | template <class _BiIter> |
| 5088 | inline _LIBCPP_INLINE_VISIBILITY |
| 5089 | bool |
| 5090 | operator>=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5091 | const sub_match<_BiIter>& __y) |
| 5092 | { |
| 5093 | return !(__x < __y); |
| 5094 | } |
| 5095 | |
| 5096 | template <class _BiIter> |
| 5097 | inline _LIBCPP_INLINE_VISIBILITY |
| 5098 | bool |
| 5099 | operator<=(typename iterator_traits<_BiIter>::value_type const& __x, |
| 5100 | const sub_match<_BiIter>& __y) |
| 5101 | { |
| 5102 | return !(__y < __x); |
| 5103 | } |
| 5104 | |
| 5105 | template <class _BiIter> |
| 5106 | inline _LIBCPP_INLINE_VISIBILITY |
| 5107 | bool |
| 5108 | operator==(const sub_match<_BiIter>& __x, |
| 5109 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5110 | { |
| 5111 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5112 | return __x.compare(string_type(1, __y)) == 0; |
| 5113 | } |
| 5114 | |
| 5115 | template <class _BiIter> |
| 5116 | inline _LIBCPP_INLINE_VISIBILITY |
| 5117 | bool |
| 5118 | operator!=(const sub_match<_BiIter>& __x, |
| 5119 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5120 | { |
| 5121 | return !(__x == __y); |
| 5122 | } |
| 5123 | |
| 5124 | template <class _BiIter> |
| 5125 | inline _LIBCPP_INLINE_VISIBILITY |
| 5126 | bool |
| 5127 | operator<(const sub_match<_BiIter>& __x, |
| 5128 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5129 | { |
| 5130 | typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type; |
| 5131 | return __x.compare(string_type(1, __y)) < 0; |
| 5132 | } |
| 5133 | |
| 5134 | template <class _BiIter> |
| 5135 | inline _LIBCPP_INLINE_VISIBILITY |
| 5136 | bool |
| 5137 | operator>(const sub_match<_BiIter>& __x, |
| 5138 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5139 | { |
| 5140 | return __y < __x; |
| 5141 | } |
| 5142 | |
| 5143 | template <class _BiIter> |
| 5144 | inline _LIBCPP_INLINE_VISIBILITY |
| 5145 | bool |
| 5146 | operator>=(const sub_match<_BiIter>& __x, |
| 5147 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5148 | { |
| 5149 | return !(__x < __y); |
| 5150 | } |
| 5151 | |
| 5152 | template <class _BiIter> |
| 5153 | inline _LIBCPP_INLINE_VISIBILITY |
| 5154 | bool |
| 5155 | operator<=(const sub_match<_BiIter>& __x, |
| 5156 | typename iterator_traits<_BiIter>::value_type const& __y) |
| 5157 | { |
| 5158 | return !(__y < __x); |
| 5159 | } |
| 5160 | |
| 5161 | template <class _CharT, class _ST, class _BiIter> |
| 5162 | inline _LIBCPP_INLINE_VISIBILITY |
| 5163 | basic_ostream<_CharT, _ST>& |
| 5164 | operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) |
| 5165 | { |
| 5166 | return __os << __m.str(); |
| 5167 | } |
| 5168 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5169 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5170 | class _LIBCPP_TYPE_VIS_ONLY match_results |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5171 | { |
| 5172 | public: |
| 5173 | typedef _Allocator allocator_type; |
| 5174 | typedef sub_match<_BidirectionalIterator> value_type; |
| 5175 | private: |
| 5176 | typedef vector<value_type, allocator_type> __container_type; |
| 5177 | |
| 5178 | __container_type __matches_; |
| 5179 | value_type __unmatched_; |
| 5180 | value_type __prefix_; |
| 5181 | value_type __suffix_; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5182 | bool __ready_; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5183 | public: |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5184 | _BidirectionalIterator __position_start_; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5185 | typedef const value_type& const_reference; |
Marshall Clow | 103af34 | 2014-02-26 01:56:31 +0000 | [diff] [blame] | 5186 | typedef value_type& reference; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5187 | typedef typename __container_type::const_iterator const_iterator; |
| 5188 | typedef const_iterator iterator; |
| 5189 | typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; |
| 5190 | typedef typename allocator_traits<allocator_type>::size_type size_type; |
| 5191 | typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type; |
| 5192 | typedef basic_string<char_type> string_type; |
| 5193 | |
| 5194 | // construct/copy/destroy: |
| 5195 | explicit match_results(const allocator_type& __a = allocator_type()); |
| 5196 | // match_results(const match_results&) = default; |
| 5197 | // match_results& operator=(const match_results&) = default; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5198 | // match_results(match_results&& __m) = default; |
| 5199 | // match_results& operator=(match_results&& __m) = default; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5200 | // ~match_results() = default; |
| 5201 | |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5202 | _LIBCPP_INLINE_VISIBILITY |
| 5203 | bool ready() const {return __ready_;} |
| 5204 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5205 | // size: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5206 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5207 | size_type size() const {return __matches_.size();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5208 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5209 | size_type max_size() const {return __matches_.max_size();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5210 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5211 | bool empty() const {return size() == 0;} |
| 5212 | |
| 5213 | // element access: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5214 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5215 | difference_type length(size_type __sub = 0) const |
| 5216 | {return (*this)[__sub].length();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5217 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5218 | difference_type position(size_type __sub = 0) const |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5219 | {return _VSTD::distance(__position_start_, (*this)[__sub].first);} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5220 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5221 | string_type str(size_type __sub = 0) const |
| 5222 | {return (*this)[__sub].str();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5223 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5224 | const_reference operator[](size_type __n) const |
| 5225 | {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;} |
| 5226 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5227 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5228 | const_reference prefix() const {return __prefix_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5229 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5230 | const_reference suffix() const {return __suffix_;} |
| 5231 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5232 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c6fe8ca | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5233 | const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5234 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5235 | const_iterator end() const {return __matches_.end();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5236 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c6fe8ca | 2011-10-08 14:36:16 +0000 | [diff] [blame] | 5237 | const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5238 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5239 | const_iterator cend() const {return __matches_.end();} |
| 5240 | |
| 5241 | // format: |
| 5242 | template <class _OutputIter> |
| 5243 | _OutputIter |
| 5244 | format(_OutputIter __out, const char_type* __fmt_first, |
| 5245 | const char_type* __fmt_last, |
| 5246 | regex_constants::match_flag_type __flags = regex_constants::format_default) const; |
| 5247 | template <class _OutputIter, class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5248 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5249 | _OutputIter |
| 5250 | format(_OutputIter __out, const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5251 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5252 | {return format(__out, __fmt.data(), __fmt.data() + __fmt.size(), __flags);} |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5253 | template <class _ST, class _SA> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5254 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5255 | basic_string<char_type, _ST, _SA> |
| 5256 | format(const basic_string<char_type, _ST, _SA>& __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5257 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5258 | { |
| 5259 | basic_string<char_type, _ST, _SA> __r; |
| 5260 | format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), |
| 5261 | __flags); |
| 5262 | return __r; |
| 5263 | } |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5264 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5265 | string_type |
| 5266 | format(const char_type* __fmt, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5267 | regex_constants::match_flag_type __flags = regex_constants::format_default) const |
| 5268 | { |
| 5269 | string_type __r; |
| 5270 | format(back_inserter(__r), __fmt, |
| 5271 | __fmt + char_traits<char_type>::length(__fmt), __flags); |
| 5272 | return __r; |
| 5273 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5274 | |
| 5275 | // allocator: |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5276 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5277 | allocator_type get_allocator() const {return __matches_.get_allocator();} |
| 5278 | |
| 5279 | // swap: |
| 5280 | void swap(match_results& __m); |
| 5281 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5282 | template <class _Bp, class _Ap> |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 5283 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5284 | void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5285 | const match_results<_Bp, _Ap>& __m, bool __no_update_pos) |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5286 | { |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5287 | _Bp __mf = __m.prefix().first; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5288 | __matches_.resize(__m.size()); |
| 5289 | for (size_type __i = 0; __i < __matches_.size(); ++__i) |
| 5290 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5291 | __matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first)); |
| 5292 | __matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5293 | __matches_[__i].matched = __m[__i].matched; |
| 5294 | } |
| 5295 | __unmatched_.first = __l; |
| 5296 | __unmatched_.second = __l; |
| 5297 | __unmatched_.matched = false; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5298 | __prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first)); |
| 5299 | __prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5300 | __prefix_.matched = __m.prefix().matched; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5301 | __suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first)); |
| 5302 | __suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second)); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5303 | __suffix_.matched = __m.suffix().matched; |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5304 | if (!__no_update_pos) |
| 5305 | __position_start_ = __prefix_.first; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5306 | __ready_ = __m.ready(); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5307 | } |
| 5308 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5309 | private: |
| 5310 | void __init(unsigned __s, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5311 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5312 | bool __no_update_pos = false); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5313 | |
| 5314 | template <class, class> friend class basic_regex; |
| 5315 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5316 | template <class _Bp, class _Ap, class _Cp, class _Tp> |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5317 | friend |
| 5318 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5319 | regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5320 | regex_constants::match_flag_type); |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5321 | |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5322 | template <class _Bp, class _Ap> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5323 | friend |
| 5324 | bool |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5325 | operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5326 | |
Howard Hinnant | e9de5ff | 2010-07-27 22:20:32 +0000 | [diff] [blame] | 5327 | template <class, class> friend class __lookahead; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5328 | }; |
| 5329 | |
| 5330 | template <class _BidirectionalIterator, class _Allocator> |
| 5331 | match_results<_BidirectionalIterator, _Allocator>::match_results( |
| 5332 | const allocator_type& __a) |
| 5333 | : __matches_(__a), |
| 5334 | __unmatched_(), |
| 5335 | __prefix_(), |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5336 | __suffix_(), |
Eric Fiselier | 7cc7106 | 2015-07-22 01:29:41 +0000 | [diff] [blame] | 5337 | __ready_(false), |
| 5338 | __position_start_() |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5339 | { |
| 5340 | } |
| 5341 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5342 | template <class _BidirectionalIterator, class _Allocator> |
| 5343 | void |
| 5344 | match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5345 | _BidirectionalIterator __f, _BidirectionalIterator __l, |
| 5346 | bool __no_update_pos) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5347 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5348 | __unmatched_.first = __l; |
| 5349 | __unmatched_.second = __l; |
| 5350 | __unmatched_.matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5351 | __matches_.assign(__s, __unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5352 | __prefix_.first = __f; |
| 5353 | __prefix_.second = __f; |
| 5354 | __prefix_.matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5355 | __suffix_ = __unmatched_; |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5356 | if (!__no_update_pos) |
| 5357 | __position_start_ = __prefix_.first; |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5358 | __ready_ = true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5359 | } |
| 5360 | |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5361 | template <class _BidirectionalIterator, class _Allocator> |
| 5362 | template <class _OutputIter> |
| 5363 | _OutputIter |
| 5364 | match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __out, |
| 5365 | const char_type* __fmt_first, const char_type* __fmt_last, |
| 5366 | regex_constants::match_flag_type __flags) const |
| 5367 | { |
| 5368 | if (__flags & regex_constants::format_sed) |
| 5369 | { |
| 5370 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5371 | { |
| 5372 | if (*__fmt_first == '&') |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5373 | __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5374 | __out); |
| 5375 | else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) |
| 5376 | { |
| 5377 | ++__fmt_first; |
| 5378 | if ('0' <= *__fmt_first && *__fmt_first <= '9') |
| 5379 | { |
| 5380 | size_t __i = *__fmt_first - '0'; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5381 | __out = _VSTD::copy(__matches_[__i].first, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5382 | __matches_[__i].second, __out); |
| 5383 | } |
| 5384 | else |
| 5385 | { |
| 5386 | *__out = *__fmt_first; |
| 5387 | ++__out; |
| 5388 | } |
| 5389 | } |
| 5390 | else |
| 5391 | { |
| 5392 | *__out = *__fmt_first; |
| 5393 | ++__out; |
| 5394 | } |
| 5395 | } |
| 5396 | } |
| 5397 | else |
| 5398 | { |
| 5399 | for (; __fmt_first != __fmt_last; ++__fmt_first) |
| 5400 | { |
| 5401 | if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) |
| 5402 | { |
| 5403 | switch (__fmt_first[1]) |
| 5404 | { |
| 5405 | case '$': |
| 5406 | *__out = *++__fmt_first; |
| 5407 | ++__out; |
| 5408 | break; |
| 5409 | case '&': |
| 5410 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5411 | __out = _VSTD::copy(__matches_[0].first, __matches_[0].second, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5412 | __out); |
| 5413 | break; |
| 5414 | case '`': |
| 5415 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5416 | __out = _VSTD::copy(__prefix_.first, __prefix_.second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5417 | break; |
| 5418 | case '\'': |
| 5419 | ++__fmt_first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5420 | __out = _VSTD::copy(__suffix_.first, __suffix_.second, __out); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5421 | break; |
| 5422 | default: |
| 5423 | if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5424 | { |
| 5425 | ++__fmt_first; |
| 5426 | size_t __i = *__fmt_first - '0'; |
| 5427 | if (__fmt_first + 1 != __fmt_last && |
| 5428 | '0' <= __fmt_first[1] && __fmt_first[1] <= '9') |
| 5429 | { |
| 5430 | ++__fmt_first; |
| 5431 | __i = 10 * __i + *__fmt_first - '0'; |
| 5432 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5433 | __out = _VSTD::copy(__matches_[__i].first, |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5434 | __matches_[__i].second, __out); |
| 5435 | } |
| 5436 | else |
| 5437 | { |
| 5438 | *__out = *__fmt_first; |
| 5439 | ++__out; |
| 5440 | } |
| 5441 | break; |
| 5442 | } |
| 5443 | } |
| 5444 | else |
| 5445 | { |
| 5446 | *__out = *__fmt_first; |
| 5447 | ++__out; |
| 5448 | } |
| 5449 | } |
| 5450 | } |
| 5451 | return __out; |
| 5452 | } |
| 5453 | |
| 5454 | template <class _BidirectionalIterator, class _Allocator> |
| 5455 | void |
| 5456 | match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) |
| 5457 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5458 | using _VSTD::swap; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5459 | swap(__matches_, __m.__matches_); |
| 5460 | swap(__unmatched_, __m.__unmatched_); |
| 5461 | swap(__prefix_, __m.__prefix_); |
| 5462 | swap(__suffix_, __m.__suffix_); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5463 | swap(__position_start_, __m.__position_start_); |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5464 | swap(__ready_, __m.__ready_); |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5465 | } |
| 5466 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5467 | typedef match_results<const char*> cmatch; |
| 5468 | typedef match_results<const wchar_t*> wcmatch; |
| 5469 | typedef match_results<string::const_iterator> smatch; |
| 5470 | typedef match_results<wstring::const_iterator> wsmatch; |
| 5471 | |
| 5472 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5473 | bool |
| 5474 | operator==(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5475 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5476 | { |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5477 | if (__x.__ready_ != __y.__ready_) |
| 5478 | return false; |
| 5479 | if (!__x.__ready_) |
| 5480 | return true; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5481 | return __x.__matches_ == __y.__matches_ && |
| 5482 | __x.__prefix_ == __y.__prefix_ && |
Howard Hinnant | 31aaf55 | 2010-12-08 21:07:55 +0000 | [diff] [blame] | 5483 | __x.__suffix_ == __y.__suffix_; |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5484 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5485 | |
| 5486 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5487 | inline _LIBCPP_INLINE_VISIBILITY |
| 5488 | bool |
| 5489 | operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5490 | const match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5491 | { |
| 5492 | return !(__x == __y); |
| 5493 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5494 | |
| 5495 | template <class _BidirectionalIterator, class _Allocator> |
Howard Hinnant | 27405f9 | 2010-08-14 18:14:02 +0000 | [diff] [blame] | 5496 | inline _LIBCPP_INLINE_VISIBILITY |
| 5497 | void |
| 5498 | swap(match_results<_BidirectionalIterator, _Allocator>& __x, |
| 5499 | match_results<_BidirectionalIterator, _Allocator>& __y) |
| 5500 | { |
| 5501 | __x.swap(__y); |
| 5502 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5503 | |
| 5504 | // regex_search |
| 5505 | |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5506 | template <class _CharT, class _Traits> |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5507 | template <class _Allocator> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5508 | bool |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5509 | basic_regex<_CharT, _Traits>::__match_at_start_ecma( |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5510 | const _CharT* __first, const _CharT* __last, |
| 5511 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5512 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5513 | { |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5514 | vector<__state> __states; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5515 | __node* __st = __start_.get(); |
| 5516 | if (__st) |
| 5517 | { |
Marshall Clow | 5e56c30 | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5518 | sub_match<const _CharT*> __unmatched; |
| 5519 | __unmatched.first = __last; |
| 5520 | __unmatched.second = __last; |
| 5521 | __unmatched.matched = false; |
| 5522 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5523 | __states.push_back(__state()); |
| 5524 | __states.back().__do_ = 0; |
| 5525 | __states.back().__first_ = __first; |
| 5526 | __states.back().__current_ = __first; |
| 5527 | __states.back().__last_ = __last; |
Marshall Clow | 5e56c30 | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5528 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5529 | __states.back().__loop_data_.resize(__loop_count()); |
| 5530 | __states.back().__node_ = __st; |
| 5531 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5532 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5533 | do |
| 5534 | { |
| 5535 | __state& __s = __states.back(); |
| 5536 | if (__s.__node_) |
| 5537 | __s.__node_->__exec(__s); |
| 5538 | switch (__s.__do_) |
| 5539 | { |
| 5540 | case __state::__end_state: |
| 5541 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5542 | __m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5543 | __m.__matches_[0].matched = true; |
| 5544 | for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i) |
| 5545 | __m.__matches_[__i+1] = __s.__sub_matches_[__i]; |
| 5546 | return true; |
| 5547 | case __state::__accept_and_consume: |
| 5548 | case __state::__repeat: |
| 5549 | case __state::__accept_but_not_consume: |
| 5550 | break; |
| 5551 | case __state::__split: |
| 5552 | { |
| 5553 | __state __snext = __s; |
| 5554 | __s.__node_->__exec_split(true, __s); |
| 5555 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5556 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5557 | } |
| 5558 | break; |
| 5559 | case __state::__reject: |
| 5560 | __states.pop_back(); |
| 5561 | break; |
| 5562 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 5563 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5564 | break; |
Howard Hinnant | d444470 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 5565 | |
Howard Hinnant | 17615b0 | 2010-07-27 01:25:38 +0000 | [diff] [blame] | 5566 | } |
| 5567 | } while (!__states.empty()); |
| 5568 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5569 | return false; |
| 5570 | } |
| 5571 | |
| 5572 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5573 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5574 | bool |
| 5575 | basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs( |
| 5576 | const _CharT* __first, const _CharT* __last, |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5577 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5578 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5579 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5580 | deque<__state> __states; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5581 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5582 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5583 | __node* __st = __start_.get(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5584 | if (__st) |
| 5585 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5586 | __states.push_back(__state()); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5587 | __states.back().__do_ = 0; |
| 5588 | __states.back().__first_ = __first; |
| 5589 | __states.back().__current_ = __first; |
| 5590 | __states.back().__last_ = __last; |
| 5591 | __states.back().__loop_data_.resize(__loop_count()); |
| 5592 | __states.back().__node_ = __st; |
| 5593 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5594 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5595 | bool __matched = false; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5596 | do |
| 5597 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5598 | __state& __s = __states.back(); |
| 5599 | if (__s.__node_) |
| 5600 | __s.__node_->__exec(__s); |
| 5601 | switch (__s.__do_) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5602 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5603 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5604 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5605 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5606 | __matched = true; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5607 | if (__highest_j == _Np) |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5608 | __states.clear(); |
| 5609 | else |
| 5610 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5611 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5612 | case __state::__consume_input: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5613 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5614 | case __state::__accept_and_consume: |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5615 | __states.push_front(_VSTD::move(__s)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5616 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5617 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5618 | case __state::__repeat: |
| 5619 | case __state::__accept_but_not_consume: |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5620 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5621 | case __state::__split: |
| 5622 | { |
| 5623 | __state __snext = __s; |
| 5624 | __s.__node_->__exec_split(true, __s); |
| 5625 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5626 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5627 | } |
| 5628 | break; |
| 5629 | case __state::__reject: |
| 5630 | __states.pop_back(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5631 | break; |
| 5632 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 5633 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5634 | break; |
| 5635 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5636 | } while (!__states.empty()); |
Howard Hinnant | 68025ed | 2010-07-14 15:45:11 +0000 | [diff] [blame] | 5637 | if (__matched) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5638 | { |
| 5639 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5640 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5641 | __m.__matches_[0].matched = true; |
| 5642 | return true; |
| 5643 | } |
| 5644 | } |
| 5645 | return false; |
| 5646 | } |
| 5647 | |
| 5648 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5649 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5650 | bool |
| 5651 | basic_regex<_CharT, _Traits>::__match_at_start_posix_subs( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5652 | const _CharT* __first, const _CharT* __last, |
| 5653 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5654 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5655 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5656 | vector<__state> __states; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5657 | __state __best_state; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5658 | ptrdiff_t __j = 0; |
| 5659 | ptrdiff_t __highest_j = 0; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5660 | ptrdiff_t _Np = _VSTD::distance(__first, __last); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5661 | __node* __st = __start_.get(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5662 | if (__st) |
| 5663 | { |
Marshall Clow | 5e56c30 | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5664 | sub_match<const _CharT*> __unmatched; |
| 5665 | __unmatched.first = __last; |
| 5666 | __unmatched.second = __last; |
| 5667 | __unmatched.matched = false; |
| 5668 | |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5669 | __states.push_back(__state()); |
| 5670 | __states.back().__do_ = 0; |
| 5671 | __states.back().__first_ = __first; |
| 5672 | __states.back().__current_ = __first; |
| 5673 | __states.back().__last_ = __last; |
Marshall Clow | 5e56c30 | 2015-01-28 22:22:35 +0000 | [diff] [blame] | 5674 | __states.back().__sub_matches_.resize(mark_count(), __unmatched); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5675 | __states.back().__loop_data_.resize(__loop_count()); |
| 5676 | __states.back().__node_ = __st; |
| 5677 | __states.back().__flags_ = __flags; |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5678 | __states.back().__at_first_ = __at_first; |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5679 | const _CharT* __current = __first; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5680 | bool __matched = false; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5681 | do |
| 5682 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5683 | __state& __s = __states.back(); |
| 5684 | if (__s.__node_) |
| 5685 | __s.__node_->__exec(__s); |
| 5686 | switch (__s.__do_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5687 | { |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5688 | case __state::__end_state: |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5689 | if (!__matched || __highest_j < __s.__current_ - __s.__first_) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5690 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5691 | __highest_j = __s.__current_ - __s.__first_; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5692 | __best_state = __s; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5693 | } |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5694 | __matched = true; |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 5695 | if (__highest_j == _Np) |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5696 | __states.clear(); |
| 5697 | else |
| 5698 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5699 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5700 | case __state::__accept_and_consume: |
Howard Hinnant | cba352d | 2010-07-12 18:16:05 +0000 | [diff] [blame] | 5701 | __j += __s.__current_ - __current; |
| 5702 | __current = __s.__current_; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5703 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5704 | case __state::__repeat: |
| 5705 | case __state::__accept_but_not_consume: |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5706 | break; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5707 | case __state::__split: |
| 5708 | { |
| 5709 | __state __snext = __s; |
| 5710 | __s.__node_->__exec_split(true, __s); |
| 5711 | __snext.__node_->__exec_split(false, __snext); |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5712 | __states.push_back(_VSTD::move(__snext)); |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5713 | } |
| 5714 | break; |
| 5715 | case __state::__reject: |
| 5716 | __states.pop_back(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5717 | break; |
| 5718 | default: |
Marshall Clow | 2576c29 | 2015-07-28 13:30:47 +0000 | [diff] [blame^] | 5719 | __throw_regex_error<regex_constants::__re_err_unknown>(); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5720 | break; |
| 5721 | } |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5722 | } while (!__states.empty()); |
| 5723 | if (__matched) |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5724 | { |
| 5725 | __m.__matches_[0].first = __first; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5726 | __m.__matches_[0].second = _VSTD::next(__first, __highest_j); |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5727 | __m.__matches_[0].matched = true; |
Howard Hinnant | ac30386 | 2010-07-12 15:51:17 +0000 | [diff] [blame] | 5728 | for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i) |
| 5729 | __m.__matches_[__i+1] = __best_state.__sub_matches_[__i]; |
Howard Hinnant | e77aa5e | 2010-07-08 17:43:58 +0000 | [diff] [blame] | 5730 | return true; |
| 5731 | } |
| 5732 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5733 | return false; |
| 5734 | } |
| 5735 | |
| 5736 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5737 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5738 | bool |
| 5739 | basic_regex<_CharT, _Traits>::__match_at_start( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5740 | const _CharT* __first, const _CharT* __last, |
| 5741 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5742 | regex_constants::match_flag_type __flags, bool __at_first) const |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5743 | { |
Howard Hinnant | ad2a7ab | 2010-07-27 17:24:17 +0000 | [diff] [blame] | 5744 | if ((__flags_ & 0x1F0) == ECMAScript) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5745 | return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5746 | if (mark_count() == 0) |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5747 | return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |
| 5748 | return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first); |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5749 | } |
| 5750 | |
| 5751 | template <class _CharT, class _Traits> |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5752 | template <class _Allocator> |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5753 | bool |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5754 | basic_regex<_CharT, _Traits>::__search( |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5755 | const _CharT* __first, const _CharT* __last, |
| 5756 | match_results<const _CharT*, _Allocator>& __m, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5757 | regex_constants::match_flag_type __flags) const |
| 5758 | { |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5759 | __m.__init(1 + mark_count(), __first, __last, |
| 5760 | __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 7670f7d | 2013-07-09 17:29:09 +0000 | [diff] [blame] | 5761 | if (__match_at_start(__first, __last, __m, __flags, |
| 5762 | !(__flags & regex_constants::__no_update_pos))) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5763 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5764 | __m.__prefix_.second = __m[0].first; |
| 5765 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5766 | __m.__suffix_.first = __m[0].second; |
| 5767 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5768 | return true; |
| 5769 | } |
Howard Hinnant | 8daa733 | 2010-07-29 01:15:27 +0000 | [diff] [blame] | 5770 | if (__first != __last && !(__flags & regex_constants::match_continuous)) |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5771 | { |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 5772 | __flags |= regex_constants::match_prev_avail; |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5773 | for (++__first; __first != __last; ++__first) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5774 | { |
Howard Hinnant | f3dcca0 | 2010-07-29 15:17:28 +0000 | [diff] [blame] | 5775 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 41fb6e1 | 2011-03-26 20:02:27 +0000 | [diff] [blame] | 5776 | if (__match_at_start(__first, __last, __m, __flags, false)) |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5777 | { |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5778 | __m.__prefix_.second = __m[0].first; |
| 5779 | __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second; |
| 5780 | __m.__suffix_.first = __m[0].second; |
| 5781 | __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second; |
| 5782 | return true; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5783 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5784 | __m.__matches_.assign(__m.size(), __m.__unmatched_); |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5785 | } |
| 5786 | } |
Howard Hinnant | f8ce459 | 2010-07-07 19:14:52 +0000 | [diff] [blame] | 5787 | __m.__matches_.clear(); |
| 5788 | return false; |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5789 | } |
| 5790 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5791 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5792 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5793 | bool |
| 5794 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5795 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5796 | const basic_regex<_CharT, _Traits>& __e, |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5797 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5798 | { |
Howard Hinnant | e840208 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 5799 | int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0; |
| 5800 | basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5801 | match_results<const _CharT*> __mc; |
Howard Hinnant | e840208 | 2013-07-11 15:32:55 +0000 | [diff] [blame] | 5802 | bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5803 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5804 | return __r; |
| 5805 | } |
| 5806 | |
Howard Hinnant | a9602d5 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 5807 | template <class _Iter, class _Allocator, class _CharT, class _Traits> |
| 5808 | inline _LIBCPP_INLINE_VISIBILITY |
| 5809 | bool |
| 5810 | regex_search(__wrap_iter<_Iter> __first, |
| 5811 | __wrap_iter<_Iter> __last, |
| 5812 | match_results<__wrap_iter<_Iter>, _Allocator>& __m, |
| 5813 | const basic_regex<_CharT, _Traits>& __e, |
| 5814 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5815 | { |
| 5816 | match_results<const _CharT*> __mc; |
| 5817 | bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags); |
| 5818 | __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos); |
| 5819 | return __r; |
| 5820 | } |
| 5821 | |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5822 | template <class _Allocator, class _CharT, class _Traits> |
| 5823 | inline _LIBCPP_INLINE_VISIBILITY |
| 5824 | bool |
| 5825 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5826 | match_results<const _CharT*, _Allocator>& __m, |
| 5827 | const basic_regex<_CharT, _Traits>& __e, |
| 5828 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5829 | { |
Howard Hinnant | 9b80f2b | 2010-06-30 17:22:19 +0000 | [diff] [blame] | 5830 | return __e.__search(__first, __last, __m, __flags); |
| 5831 | } |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5832 | |
| 5833 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5834 | inline _LIBCPP_INLINE_VISIBILITY |
| 5835 | bool |
| 5836 | regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5837 | const basic_regex<_CharT, _Traits>& __e, |
| 5838 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5839 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5840 | basic_string<_CharT> __s(__first, __last); |
| 5841 | match_results<const _CharT*> __mc; |
| 5842 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
| 5843 | } |
| 5844 | |
| 5845 | template <class _CharT, class _Traits> |
| 5846 | inline _LIBCPP_INLINE_VISIBILITY |
| 5847 | bool |
| 5848 | regex_search(const _CharT* __first, const _CharT* __last, |
| 5849 | const basic_regex<_CharT, _Traits>& __e, |
| 5850 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5851 | { |
| 5852 | match_results<const _CharT*> __mc; |
| 5853 | return __e.__search(__first, __last, __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5854 | } |
| 5855 | |
| 5856 | template <class _CharT, class _Allocator, class _Traits> |
| 5857 | inline _LIBCPP_INLINE_VISIBILITY |
| 5858 | bool |
| 5859 | regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5860 | const basic_regex<_CharT, _Traits>& __e, |
| 5861 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5862 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5863 | return __e.__search(__str, __str + _Traits::length(__str), __m, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | template <class _CharT, class _Traits> |
| 5867 | inline _LIBCPP_INLINE_VISIBILITY |
| 5868 | bool |
| 5869 | regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5870 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5871 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5872 | match_results<const _CharT*> __m; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5873 | return _VSTD::regex_search(__str, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5874 | } |
| 5875 | |
| 5876 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5877 | inline _LIBCPP_INLINE_VISIBILITY |
| 5878 | bool |
| 5879 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5880 | const basic_regex<_CharT, _Traits>& __e, |
| 5881 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5882 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5883 | match_results<const _CharT*> __mc; |
| 5884 | return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5885 | } |
| 5886 | |
| 5887 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5888 | inline _LIBCPP_INLINE_VISIBILITY |
| 5889 | bool |
| 5890 | regex_search(const basic_string<_CharT, _ST, _SA>& __s, |
| 5891 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5892 | const basic_regex<_CharT, _Traits>& __e, |
| 5893 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5894 | { |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5895 | match_results<const _CharT*> __mc; |
| 5896 | bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5897 | __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos); |
Howard Hinnant | 22ce0b4 | 2010-07-14 21:14:52 +0000 | [diff] [blame] | 5898 | return __r; |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5899 | } |
| 5900 | |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 5901 | #if _LIBCPP_STD_VER > 11 |
| 5902 | template <class _ST, class _SA, class _Ap, class _Cp, class _Tp> |
| 5903 | bool |
| 5904 | regex_search(const basic_string<_Cp, _ST, _SA>&& __s, |
| 5905 | match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&, |
| 5906 | const basic_regex<_Cp, _Tp>& __e, |
| 5907 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
| 5908 | #endif |
| 5909 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5910 | // regex_match |
| 5911 | |
| 5912 | template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits> |
| 5913 | bool |
| 5914 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5915 | match_results<_BidirectionalIterator, _Allocator>& __m, |
| 5916 | const basic_regex<_CharT, _Traits>& __e, |
| 5917 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5918 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5919 | bool __r = _VSTD::regex_search(__first, __last, __m, __e, |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5920 | __flags | regex_constants::match_continuous); |
| 5921 | if (__r) |
| 5922 | { |
| 5923 | __r = !__m.suffix().matched; |
| 5924 | if (!__r) |
| 5925 | __m.__matches_.clear(); |
| 5926 | } |
| 5927 | return __r; |
| 5928 | } |
| 5929 | |
| 5930 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 5931 | inline _LIBCPP_INLINE_VISIBILITY |
| 5932 | bool |
| 5933 | regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last, |
| 5934 | const basic_regex<_CharT, _Traits>& __e, |
| 5935 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5936 | { |
| 5937 | match_results<_BidirectionalIterator> __m; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5938 | return _VSTD::regex_match(__first, __last, __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | template <class _CharT, class _Allocator, class _Traits> |
| 5942 | inline _LIBCPP_INLINE_VISIBILITY |
| 5943 | bool |
| 5944 | regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m, |
| 5945 | const basic_regex<_CharT, _Traits>& __e, |
| 5946 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5947 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5948 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5949 | } |
| 5950 | |
| 5951 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5952 | inline _LIBCPP_INLINE_VISIBILITY |
| 5953 | bool |
| 5954 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 5955 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5956 | const basic_regex<_CharT, _Traits>& __e, |
| 5957 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5958 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5959 | return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5960 | } |
| 5961 | |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 5962 | #if _LIBCPP_STD_VER > 11 |
| 5963 | template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits> |
| 5964 | inline _LIBCPP_INLINE_VISIBILITY |
| 5965 | bool |
| 5966 | regex_match(const basic_string<_CharT, _ST, _SA>&& __s, |
| 5967 | match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m, |
| 5968 | const basic_regex<_CharT, _Traits>& __e, |
| 5969 | regex_constants::match_flag_type __flags = regex_constants::match_default) = delete; |
| 5970 | #endif |
| 5971 | |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5972 | template <class _CharT, class _Traits> |
| 5973 | inline _LIBCPP_INLINE_VISIBILITY |
| 5974 | bool |
| 5975 | regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e, |
| 5976 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5977 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5978 | return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5979 | } |
| 5980 | |
| 5981 | template <class _ST, class _SA, class _CharT, class _Traits> |
| 5982 | inline _LIBCPP_INLINE_VISIBILITY |
| 5983 | bool |
| 5984 | regex_match(const basic_string<_CharT, _ST, _SA>& __s, |
| 5985 | const basic_regex<_CharT, _Traits>& __e, |
| 5986 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 5987 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 5988 | return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags); |
Howard Hinnant | 7e9d84b | 2010-06-30 00:21:42 +0000 | [diff] [blame] | 5989 | } |
| 5990 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5991 | // regex_iterator |
| 5992 | |
| 5993 | template <class _BidirectionalIterator, |
| 5994 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 5995 | class _Traits = regex_traits<_CharT> > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 5996 | class _LIBCPP_TYPE_VIS_ONLY regex_iterator |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 5997 | { |
| 5998 | public: |
| 5999 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6000 | typedef match_results<_BidirectionalIterator> value_type; |
| 6001 | typedef ptrdiff_t difference_type; |
| 6002 | typedef const value_type* pointer; |
| 6003 | typedef const value_type& reference; |
| 6004 | typedef forward_iterator_tag iterator_category; |
| 6005 | |
| 6006 | private: |
| 6007 | _BidirectionalIterator __begin_; |
| 6008 | _BidirectionalIterator __end_; |
| 6009 | const regex_type* __pregex_; |
| 6010 | regex_constants::match_flag_type __flags_; |
| 6011 | value_type __match_; |
| 6012 | |
| 6013 | public: |
| 6014 | regex_iterator(); |
| 6015 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6016 | const regex_type& __re, |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6017 | regex_constants::match_flag_type __m |
| 6018 | = regex_constants::match_default); |
| 6019 | #if _LIBCPP_STD_VER > 11 |
| 6020 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6021 | const regex_type&& __re, |
| 6022 | regex_constants::match_flag_type __m |
| 6023 | = regex_constants::match_default) = delete; |
| 6024 | #endif |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6025 | |
| 6026 | bool operator==(const regex_iterator& __x) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6027 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6028 | bool operator!=(const regex_iterator& __x) const {return !(*this == __x);} |
| 6029 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6030 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6031 | reference operator*() const {return __match_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6032 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6033 | pointer operator->() const {return &__match_;} |
| 6034 | |
| 6035 | regex_iterator& operator++(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6036 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6037 | regex_iterator operator++(int) |
| 6038 | { |
| 6039 | regex_iterator __t(*this); |
| 6040 | ++(*this); |
| 6041 | return __t; |
| 6042 | } |
| 6043 | }; |
| 6044 | |
| 6045 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6046 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator() |
| 6047 | : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() |
| 6048 | { |
| 6049 | } |
| 6050 | |
| 6051 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6052 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6053 | regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6054 | const regex_type& __re, regex_constants::match_flag_type __m) |
| 6055 | : __begin_(__a), |
| 6056 | __end_(__b), |
| 6057 | __pregex_(&__re), |
| 6058 | __flags_(__m) |
| 6059 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6060 | _VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_); |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6064 | bool |
| 6065 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6066 | operator==(const regex_iterator& __x) const |
| 6067 | { |
| 6068 | if (__match_.empty() && __x.__match_.empty()) |
| 6069 | return true; |
| 6070 | if (__match_.empty() || __x.__match_.empty()) |
| 6071 | return false; |
| 6072 | return __begin_ == __x.__begin_ && |
| 6073 | __end_ == __x.__end_ && |
| 6074 | __pregex_ == __x.__pregex_ && |
| 6075 | __flags_ == __x.__flags_ && |
| 6076 | __match_[0] == __x.__match_[0]; |
| 6077 | } |
| 6078 | |
| 6079 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6080 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6081 | regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6082 | { |
| 6083 | __flags_ |= regex_constants::__no_update_pos; |
| 6084 | _BidirectionalIterator __start = __match_[0].second; |
Howard Hinnant | a9602d5 | 2013-06-29 23:45:43 +0000 | [diff] [blame] | 6085 | if (__match_.empty()) |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6086 | { |
| 6087 | if (__start == __end_) |
| 6088 | { |
| 6089 | __match_ = value_type(); |
| 6090 | return *this; |
| 6091 | } |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6092 | else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_, |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6093 | __flags_ | regex_constants::match_not_null | |
| 6094 | regex_constants::match_continuous)) |
| 6095 | return *this; |
| 6096 | else |
| 6097 | ++__start; |
| 6098 | } |
| 6099 | __flags_ |= regex_constants::match_prev_avail; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6100 | if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6101 | __match_ = value_type(); |
| 6102 | return *this; |
| 6103 | } |
| 6104 | |
| 6105 | typedef regex_iterator<const char*> cregex_iterator; |
| 6106 | typedef regex_iterator<const wchar_t*> wcregex_iterator; |
| 6107 | typedef regex_iterator<string::const_iterator> sregex_iterator; |
| 6108 | typedef regex_iterator<wstring::const_iterator> wsregex_iterator; |
| 6109 | |
| 6110 | // regex_token_iterator |
| 6111 | |
| 6112 | template <class _BidirectionalIterator, |
| 6113 | class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type, |
| 6114 | class _Traits = regex_traits<_CharT> > |
Howard Hinnant | 0f678bd | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 6115 | class _LIBCPP_TYPE_VIS_ONLY regex_token_iterator |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6116 | { |
| 6117 | public: |
| 6118 | typedef basic_regex<_CharT, _Traits> regex_type; |
| 6119 | typedef sub_match<_BidirectionalIterator> value_type; |
| 6120 | typedef ptrdiff_t difference_type; |
| 6121 | typedef const value_type* pointer; |
| 6122 | typedef const value_type& reference; |
| 6123 | typedef forward_iterator_tag iterator_category; |
| 6124 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6125 | private: |
| 6126 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position; |
| 6127 | |
| 6128 | _Position __position_; |
| 6129 | const value_type* __result_; |
| 6130 | value_type __suffix_; |
| 6131 | ptrdiff_t _N_; |
| 6132 | vector<int> __subs_; |
| 6133 | |
| 6134 | public: |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6135 | regex_token_iterator(); |
| 6136 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6137 | const regex_type& __re, int __submatch = 0, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6138 | regex_constants::match_flag_type __m = |
| 6139 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6140 | #if _LIBCPP_STD_VER > 11 |
| 6141 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6142 | const regex_type&& __re, int __submatch = 0, |
| 6143 | regex_constants::match_flag_type __m = |
| 6144 | regex_constants::match_default) = delete; |
| 6145 | #endif |
| 6146 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6147 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6148 | const regex_type& __re, const vector<int>& __submatches, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6149 | regex_constants::match_flag_type __m = |
| 6150 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6151 | #if _LIBCPP_STD_VER > 11 |
| 6152 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6153 | const regex_type&& __re, const vector<int>& __submatches, |
| 6154 | regex_constants::match_flag_type __m = |
| 6155 | regex_constants::match_default) = delete; |
| 6156 | #endif |
| 6157 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6158 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6159 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6160 | const regex_type& __re, |
| 6161 | initializer_list<int> __submatches, |
| 6162 | regex_constants::match_flag_type __m = |
| 6163 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6164 | |
| 6165 | #if _LIBCPP_STD_VER > 11 |
| 6166 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6167 | const regex_type&& __re, |
| 6168 | initializer_list<int> __submatches, |
| 6169 | regex_constants::match_flag_type __m = |
| 6170 | regex_constants::match_default) = delete; |
| 6171 | #endif |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6172 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6173 | template <size_t _Np> |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6174 | regex_token_iterator(_BidirectionalIterator __a, |
| 6175 | _BidirectionalIterator __b, |
| 6176 | const regex_type& __re, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6177 | const int (&__submatches)[_Np], |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6178 | regex_constants::match_flag_type __m = |
| 6179 | regex_constants::match_default); |
Marshall Clow | e0f8672 | 2014-02-19 21:21:11 +0000 | [diff] [blame] | 6180 | #if _LIBCPP_STD_VER > 11 |
| 6181 | template <std::size_t _Np> |
| 6182 | regex_token_iterator(_BidirectionalIterator __a, |
| 6183 | _BidirectionalIterator __b, |
| 6184 | const regex_type&& __re, |
| 6185 | const int (&__submatches)[_Np], |
| 6186 | regex_constants::match_flag_type __m = |
| 6187 | regex_constants::match_default) = delete; |
| 6188 | #endif |
| 6189 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6190 | regex_token_iterator(const regex_token_iterator&); |
| 6191 | regex_token_iterator& operator=(const regex_token_iterator&); |
| 6192 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6193 | bool operator==(const regex_token_iterator& __x) const; |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6194 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6195 | bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);} |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6196 | |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6197 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6198 | const value_type& operator*() const {return *__result_;} |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6199 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6200 | const value_type* operator->() const {return __result_;} |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6201 | |
| 6202 | regex_token_iterator& operator++(); |
Howard Hinnant | aef07cb | 2010-09-23 15:13:20 +0000 | [diff] [blame] | 6203 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6204 | regex_token_iterator operator++(int) |
| 6205 | { |
| 6206 | regex_token_iterator __t(*this); |
| 6207 | ++(*this); |
| 6208 | return __t; |
| 6209 | } |
| 6210 | |
| 6211 | private: |
| 6212 | void __init(_BidirectionalIterator __a, _BidirectionalIterator __b); |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6213 | void __establish_result () { |
| 6214 | if (__subs_[_N_] == -1) |
| 6215 | __result_ = &__position_->prefix(); |
| 6216 | else |
| 6217 | __result_ = &(*__position_)[__subs_[_N_]]; |
| 6218 | } |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6219 | }; |
| 6220 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6221 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6222 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6223 | regex_token_iterator() |
| 6224 | : __result_(nullptr), |
| 6225 | __suffix_(), |
| 6226 | _N_(0) |
| 6227 | { |
| 6228 | } |
| 6229 | |
| 6230 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6231 | void |
| 6232 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6233 | __init(_BidirectionalIterator __a, _BidirectionalIterator __b) |
| 6234 | { |
| 6235 | if (__position_ != _Position()) |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6236 | __establish_result (); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6237 | else if (__subs_[_N_] == -1) |
| 6238 | { |
| 6239 | __suffix_.matched = true; |
| 6240 | __suffix_.first = __a; |
| 6241 | __suffix_.second = __b; |
| 6242 | __result_ = &__suffix_; |
| 6243 | } |
| 6244 | else |
| 6245 | __result_ = nullptr; |
| 6246 | } |
| 6247 | |
| 6248 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6249 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6250 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6251 | const regex_type& __re, int __submatch, |
| 6252 | regex_constants::match_flag_type __m) |
| 6253 | : __position_(__a, __b, __re, __m), |
| 6254 | _N_(0), |
| 6255 | __subs_(1, __submatch) |
| 6256 | { |
| 6257 | __init(__a, __b); |
| 6258 | } |
| 6259 | |
| 6260 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6261 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6262 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6263 | const regex_type& __re, const vector<int>& __submatches, |
| 6264 | regex_constants::match_flag_type __m) |
| 6265 | : __position_(__a, __b, __re, __m), |
| 6266 | _N_(0), |
| 6267 | __subs_(__submatches) |
| 6268 | { |
| 6269 | __init(__a, __b); |
| 6270 | } |
| 6271 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6272 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 6273 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6274 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6275 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6276 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6277 | const regex_type& __re, |
| 6278 | initializer_list<int> __submatches, |
| 6279 | regex_constants::match_flag_type __m) |
| 6280 | : __position_(__a, __b, __re, __m), |
| 6281 | _N_(0), |
| 6282 | __subs_(__submatches) |
| 6283 | { |
| 6284 | __init(__a, __b); |
| 6285 | } |
| 6286 | |
Howard Hinnant | e3e3291 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 6287 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 6288 | |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6289 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6290 | template <size_t _Np> |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6291 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6292 | regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b, |
| 6293 | const regex_type& __re, |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6294 | const int (&__submatches)[_Np], |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6295 | regex_constants::match_flag_type __m) |
| 6296 | : __position_(__a, __b, __re, __m), |
| 6297 | _N_(0), |
Howard Hinnant | 9996844 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 6298 | __subs_(__submatches, __submatches + _Np) |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6299 | { |
| 6300 | __init(__a, __b); |
| 6301 | } |
| 6302 | |
| 6303 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6304 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6305 | regex_token_iterator(const regex_token_iterator& __x) |
| 6306 | : __position_(__x.__position_), |
| 6307 | __result_(__x.__result_), |
| 6308 | __suffix_(__x.__suffix_), |
| 6309 | _N_(__x._N_), |
| 6310 | __subs_(__x.__subs_) |
| 6311 | { |
| 6312 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 72fe0ae | 2014-01-13 17:47:08 +0000 | [diff] [blame] | 6313 | __result_ = &__suffix_; |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6314 | else if ( __result_ != nullptr ) |
| 6315 | __establish_result (); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6316 | } |
| 6317 | |
| 6318 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6319 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6320 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6321 | operator=(const regex_token_iterator& __x) |
| 6322 | { |
| 6323 | if (this != &__x) |
| 6324 | { |
| 6325 | __position_ = __x.__position_; |
| 6326 | if (__x.__result_ == &__x.__suffix_) |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6327 | __result_ = &__suffix_; |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6328 | else |
| 6329 | __result_ = __x.__result_; |
| 6330 | __suffix_ = __x.__suffix_; |
| 6331 | _N_ = __x._N_; |
| 6332 | __subs_ = __x.__subs_; |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6333 | |
| 6334 | if ( __result_ != nullptr && __result_ != &__suffix_ ) |
| 6335 | __establish_result(); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6336 | } |
| 6337 | return *this; |
| 6338 | } |
| 6339 | |
| 6340 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6341 | bool |
| 6342 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>:: |
| 6343 | operator==(const regex_token_iterator& __x) const |
| 6344 | { |
| 6345 | if (__result_ == nullptr && __x.__result_ == nullptr) |
| 6346 | return true; |
| 6347 | if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && |
| 6348 | __suffix_ == __x.__suffix_) |
| 6349 | return true; |
| 6350 | if (__result_ == nullptr || __x.__result_ == nullptr) |
| 6351 | return false; |
| 6352 | if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_) |
| 6353 | return false; |
| 6354 | return __position_ == __x.__position_ && _N_ == __x._N_ && |
| 6355 | __subs_ == __x.__subs_; |
| 6356 | } |
| 6357 | |
| 6358 | template <class _BidirectionalIterator, class _CharT, class _Traits> |
| 6359 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>& |
| 6360 | regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() |
| 6361 | { |
| 6362 | _Position __prev = __position_; |
| 6363 | if (__result_ == &__suffix_) |
| 6364 | __result_ = nullptr; |
| 6365 | else if (_N_ + 1 < __subs_.size()) |
| 6366 | { |
| 6367 | ++_N_; |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6368 | __establish_result(); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6369 | } |
| 6370 | else |
| 6371 | { |
| 6372 | _N_ = 0; |
| 6373 | ++__position_; |
| 6374 | if (__position_ != _Position()) |
Marshall Clow | 0efd9dc | 2014-01-09 18:25:57 +0000 | [diff] [blame] | 6375 | __establish_result(); |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6376 | else |
| 6377 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6378 | if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() |
Howard Hinnant | 262b779 | 2010-08-17 20:42:03 +0000 | [diff] [blame] | 6379 | && __prev->suffix().length() != 0) |
| 6380 | { |
| 6381 | __suffix_.matched = true; |
| 6382 | __suffix_.first = __prev->suffix().first; |
| 6383 | __suffix_.second = __prev->suffix().second; |
| 6384 | __result_ = &__suffix_; |
| 6385 | } |
| 6386 | else |
| 6387 | __result_ = nullptr; |
| 6388 | } |
| 6389 | } |
| 6390 | return *this; |
| 6391 | } |
| 6392 | |
Howard Hinnant | a712c72 | 2010-08-16 20:21:16 +0000 | [diff] [blame] | 6393 | typedef regex_token_iterator<const char*> cregex_token_iterator; |
| 6394 | typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; |
| 6395 | typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; |
| 6396 | typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; |
| 6397 | |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6398 | // regex_replace |
| 6399 | |
| 6400 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6401 | class _Traits, class _CharT> |
| 6402 | _OutputIterator |
| 6403 | regex_replace(_OutputIterator __out, |
| 6404 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6405 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6406 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6407 | { |
| 6408 | typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter; |
| 6409 | _Iter __i(__first, __last, __e, __flags); |
| 6410 | _Iter __eof; |
| 6411 | if (__i == __eof) |
| 6412 | { |
| 6413 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6414 | __out = _VSTD::copy(__first, __last, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6415 | } |
| 6416 | else |
| 6417 | { |
| 6418 | sub_match<_BidirectionalIterator> __lm; |
| 6419 | for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) |
| 6420 | { |
| 6421 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6422 | __out = _VSTD::copy(__i->prefix().first, __i->prefix().second, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6423 | __out = __i->format(__out, __fmt, __fmt + __len, __flags); |
| 6424 | __lm = __i->suffix(); |
| 6425 | if (__flags & regex_constants::format_first_only) |
| 6426 | break; |
| 6427 | } |
| 6428 | if (!(__flags & regex_constants::format_no_copy)) |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6429 | __out = _VSTD::copy(__lm.first, __lm.second, __out); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6430 | } |
| 6431 | return __out; |
| 6432 | } |
| 6433 | |
| 6434 | template <class _OutputIterator, class _BidirectionalIterator, |
| 6435 | class _Traits, class _CharT, class _ST, class _SA> |
| 6436 | inline _LIBCPP_INLINE_VISIBILITY |
| 6437 | _OutputIterator |
| 6438 | regex_replace(_OutputIterator __out, |
| 6439 | _BidirectionalIterator __first, _BidirectionalIterator __last, |
| 6440 | const basic_regex<_CharT, _Traits>& __e, |
| 6441 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6442 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6443 | { |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6444 | return _VSTD::regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags); |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6445 | } |
| 6446 | |
| 6447 | template <class _Traits, class _CharT, class _ST, class _SA, class _FST, |
| 6448 | class _FSA> |
| 6449 | inline _LIBCPP_INLINE_VISIBILITY |
| 6450 | basic_string<_CharT, _ST, _SA> |
| 6451 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6452 | const basic_regex<_CharT, _Traits>& __e, |
| 6453 | const basic_string<_CharT, _FST, _FSA>& __fmt, |
| 6454 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6455 | { |
| 6456 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6457 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6458 | __fmt.c_str(), __flags); |
| 6459 | return __r; |
| 6460 | } |
| 6461 | |
| 6462 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6463 | inline _LIBCPP_INLINE_VISIBILITY |
| 6464 | basic_string<_CharT, _ST, _SA> |
| 6465 | regex_replace(const basic_string<_CharT, _ST, _SA>& __s, |
| 6466 | const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt, |
| 6467 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6468 | { |
| 6469 | basic_string<_CharT, _ST, _SA> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6470 | _VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6471 | __fmt, __flags); |
| 6472 | return __r; |
| 6473 | } |
| 6474 | |
| 6475 | template <class _Traits, class _CharT, class _ST, class _SA> |
| 6476 | inline _LIBCPP_INLINE_VISIBILITY |
| 6477 | basic_string<_CharT> |
| 6478 | regex_replace(const _CharT* __s, |
| 6479 | const basic_regex<_CharT, _Traits>& __e, |
| 6480 | const basic_string<_CharT, _ST, _SA>& __fmt, |
| 6481 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6482 | { |
| 6483 | basic_string<_CharT> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6484 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6485 | __s + char_traits<_CharT>::length(__s), __e, |
| 6486 | __fmt.c_str(), __flags); |
| 6487 | return __r; |
| 6488 | } |
| 6489 | |
| 6490 | template <class _Traits, class _CharT> |
| 6491 | inline _LIBCPP_INLINE_VISIBILITY |
| 6492 | basic_string<_CharT> |
| 6493 | regex_replace(const _CharT* __s, |
| 6494 | const basic_regex<_CharT, _Traits>& __e, |
| 6495 | const _CharT* __fmt, |
| 6496 | regex_constants::match_flag_type __flags = regex_constants::match_default) |
| 6497 | { |
| 6498 | basic_string<_CharT> __r; |
Howard Hinnant | 0949eed | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 6499 | _VSTD::regex_replace(back_inserter(__r), __s, |
Howard Hinnant | a8d7759 | 2010-08-18 00:13:08 +0000 | [diff] [blame] | 6500 | __s + char_traits<_CharT>::length(__s), __e, |
| 6501 | __fmt, __flags); |
| 6502 | return __r; |
| 6503 | } |
| 6504 | |
Howard Hinnant | 3257c98 | 2010-06-17 00:34:59 +0000 | [diff] [blame] | 6505 | _LIBCPP_END_NAMESPACE_STD |
| 6506 | |
| 6507 | #endif // _LIBCPP_REGEX |